@lincyaw/workbench 0.2.0-rc.8 → 0.2.0-rc.81
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 +5 -4
- package/src/MediaClipEditor.tsx +4 -3
- package/src/StepProductionEditor.tsx +13 -4
- package/src/approvals.tsx +6 -1
- package/src/audio-recording.ts +27 -5
- package/src/authoring-client.ts +10 -10
- package/src/authoring-draft-fragment.ts +3 -1
- package/src/authoring-window.ts +100 -0
- package/src/body-draft-actions.ts +60 -0
- package/src/caption-timing-drafts.ts +18 -1
- package/src/component-property-drafts.ts +5 -5
- package/src/components.tsx +22 -31
- package/src/context.tsx +5 -3
- package/src/diagnostics.ts +1 -1
- package/src/document-draft-store.ts +45 -18
- package/src/document-drafts.ts +28 -19
- package/src/document-editing.ts +484 -0
- package/src/document-editor/BlockNoteSurface.tsx +25 -9
- package/src/document-editor/ComponentMaterials.tsx +3 -9
- package/src/document-editor/ComponentPropertiesDialog.tsx +4 -4
- package/src/document-editor/DocumentBlockPreview.tsx +4 -2
- package/src/document-editor/DocumentComments.tsx +85 -14
- package/src/document-editor/DocumentEditor.tsx +44 -7
- package/src/document-editor/DocumentStepNarration.tsx +33 -25
- package/src/document-editor/NarrationEditor.tsx +54 -20
- package/src/document-editor/NewCommentDrafts.tsx +114 -31
- package/src/document-editor/PlaceComment.tsx +228 -0
- package/src/document-editor/comment-draft-actions.ts +40 -20
- package/src/document-editor/comment-draft-inspection.ts +2 -2
- package/src/document-editor/comment-drafts.ts +73 -25
- package/src/document-editor/comments.ts +30 -10
- package/src/document-editor/component-label.ts +11 -0
- package/src/document-editor/file-input.ts +2 -2
- package/src/document-editor/focus.ts +0 -2
- package/src/document-editor/insertion-place.ts +60 -0
- package/src/document-editor/messages.ts +3 -3
- package/src/document-editor/narration-schema.tsx +12 -6
- package/src/document-editor/narration.ts +19 -3
- package/src/document-editor/page-body.ts +60 -0
- package/src/document-editor/projection.ts +2 -2
- package/src/document-editor/rich-text.ts +3 -2
- package/src/document-editor/selection.ts +13 -0
- package/src/document-editor/style.css +12 -1
- package/src/document-editor/table-identities.ts +2 -1
- package/src/document-production.ts +491 -0
- package/src/document-session.ts +202 -56
- package/src/document-timing-drafts.ts +22 -2
- package/src/history.ts +5 -5
- package/src/index.ts +6 -5
- package/src/jobs.ts +1 -1
- package/src/media-drafts.ts +43 -1
- package/src/messages.ts +31 -14
- package/src/panels/DocumentView.tsx +71 -28
- package/src/panels/DocumentVoiceDialog.tsx +25 -9
- package/src/panels/DocumentVoiceField.tsx +1 -1
- package/src/panels/ExportPanel.tsx +1 -6
- package/src/panels/HistoryPanel.tsx +32 -2
- package/src/panels/PageDeleteDialog.tsx +4 -4
- package/src/panels/PageRenameDialog.tsx +1 -1
- package/src/panels/PreviewPanel.tsx +1 -4
- package/src/panels/ProductionCaptionSize.tsx +20 -0
- package/src/panels/ProductionCaptionTiming.tsx +12 -9
- package/src/panels/ProductionMediaClips.tsx +23 -7
- package/src/panels/ProductionPanel.tsx +8 -4
- package/src/panels/ProductionRecording.tsx +86 -9
- package/src/panels/ProductionRecordingRange.tsx +21 -19
- package/src/panels/ProductionTimeline.tsx +6 -1
- package/src/panels/ProductionTranscription.tsx +5 -4
- package/src/panels/SourceDocumentPanel.tsx +16 -36
- package/src/panels/TranscriptionAdoption.tsx +40 -34
- package/src/panels/VoiceCloneDialog.tsx +2 -1
- package/src/panels/VoiceoverDialog.tsx +1 -1
- package/src/places.ts +1 -36
- package/src/preview-playback.ts +1 -1
- package/src/production-draft-actions.ts +37 -0
- package/src/production-messages.ts +6 -0
- package/src/production-playback.ts +1 -1
- package/src/production-voice-playback.ts +3 -2
- package/src/sha256.ts +9 -0
- package/src/styles.css +21 -43
- package/src/transcription-drafts.ts +124 -0
- package/src/use-recording-adoption.ts +2 -2
- package/src/voice-drafts.ts +32 -8
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +157 -0
- package/src/workbench.ts +258 -951
- package/src/workspace-client.ts +21 -11
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -4,8 +4,9 @@ import type { ProductionPlan, ProductionPlaybackPosition, VoiceoverJob } from '@
|
|
|
4
4
|
import { useWorkbench, useWorkbenchState } from './context.tsx'
|
|
5
5
|
import { prepareVoiceSnapshot, voiceSnapshotCurrent } from './voice-snapshot.ts'
|
|
6
6
|
import { voiceFailure } from './voice-messages.ts'
|
|
7
|
-
import type { Workbench
|
|
8
|
-
import {
|
|
7
|
+
import type { Workbench } from './workbench.ts'
|
|
8
|
+
import type { WorkbenchState } from './workbench-state.ts'
|
|
9
|
+
import { isAgentChanging } from './workbench-state.ts'
|
|
9
10
|
|
|
10
11
|
const running = (job: VoiceoverJob) => ['queued', 'running', 'cancelling'].includes(job.state)
|
|
11
12
|
|
package/src/sha256.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { sha256 as hash } from '@noble/hashes/sha2.js'
|
|
2
|
+
import { bytesToHex } from '@noble/hashes/utils.js'
|
|
3
|
+
|
|
4
|
+
/** The same SHA-256 fingerprint on HTTPS, localhost and LAN HTTP. */
|
|
5
|
+
export async function sha256(value: string | ArrayBuffer): Promise<string> {
|
|
6
|
+
const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : new Uint8Array(value)
|
|
7
|
+
const subtle = globalThis.crypto?.subtle
|
|
8
|
+
return bytesToHex(subtle ? new Uint8Array(await subtle.digest('SHA-256', bytes)) : hash(bytes))
|
|
9
|
+
}
|
package/src/styles.css
CHANGED
|
@@ -265,20 +265,24 @@
|
|
|
265
265
|
color: var(--pm-color-danger);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
.pmw-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
.pmw-problems__details ul {
|
|
275
|
-
margin: var(--pm-space-1) 0 0;
|
|
268
|
+
.pmw-problems__list {
|
|
269
|
+
display: flex;
|
|
270
|
+
flex-direction: column;
|
|
271
|
+
gap: var(--pm-space-3);
|
|
272
|
+
margin: 0;
|
|
276
273
|
padding-left: var(--pm-space-4);
|
|
277
|
-
font-family: var(--pm-font-mono);
|
|
278
|
-
font-size: var(--pm-text-xs);
|
|
279
274
|
overflow-wrap: anywhere;
|
|
280
275
|
}
|
|
281
276
|
|
|
277
|
+
.pmw-problems__list p {
|
|
278
|
+
margin: 0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.pmw-problems__hint {
|
|
282
|
+
color: var(--pm-color-muted);
|
|
283
|
+
font-size: var(--pm-text-sm);
|
|
284
|
+
}
|
|
285
|
+
|
|
282
286
|
.pmw-document__body {
|
|
283
287
|
display: flex;
|
|
284
288
|
flex: 1;
|
|
@@ -717,6 +721,11 @@
|
|
|
717
721
|
justify-self: start;
|
|
718
722
|
}
|
|
719
723
|
|
|
724
|
+
.pmw-version__actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: var(--pm-space-2); }
|
|
725
|
+
.pmw-history-group { display: grid; gap: var(--pm-space-2); }
|
|
726
|
+
.pmw-history-group__header { display: flex; align-items: center; gap: var(--pm-space-2); padding-inline: var(--pm-space-3); }
|
|
727
|
+
.pmw-toolbar__history { display: inline-flex; align-items: center; gap: var(--pm-space-1); }
|
|
728
|
+
|
|
720
729
|
/* Above the video: its file. */
|
|
721
730
|
|
|
722
731
|
|
|
@@ -820,17 +829,6 @@
|
|
|
820
829
|
accent-color: var(--pm-color-accent);
|
|
821
830
|
}
|
|
822
831
|
|
|
823
|
-
/* The kitten above the bar, as far along it as the job has come (`--pmw-job-done`, 0 to 1), never past its ends. */
|
|
824
|
-
.pmw-job__runner {
|
|
825
|
-
display: block;
|
|
826
|
-
margin-left: calc((100% - var(--pm-size-mascot-sm)) * var(--pmw-job-done));
|
|
827
|
-
line-height: 0;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
.pmw-job__runner:empty {
|
|
831
|
-
display: none;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
832
|
.pmw-job__error {
|
|
835
833
|
margin: 0;
|
|
836
834
|
color: var(--pm-color-danger);
|
|
@@ -928,10 +926,9 @@
|
|
|
928
926
|
.pmw-document__source[hidden] { display: none; }
|
|
929
927
|
.pmw-source-document { flex: 1; min-width: 0; min-height: 0; overflow: auto; padding: var(--pm-space-5); background: var(--pm-color-canvas); }
|
|
930
928
|
.pmw-source-document__notices { position: sticky; inset-block-start: 0; z-index: var(--pm-z-site-header); display: grid; gap: var(--pm-space-3); margin-block-end: var(--pm-space-3); }
|
|
931
|
-
.pmw-source-document__recovery { display: grid; gap: var(--pm-space-2); min-width: 0; }
|
|
932
|
-
.pmw-source-document__recovery-actions { display: flex; flex-wrap: wrap; gap: var(--pm-space-2); }
|
|
933
929
|
.pmw-source-document__diagnostics { margin-block-end: var(--pm-space-3); }
|
|
934
|
-
|
|
930
|
+
/* Its end margin is the editor's own end area, which fills the rest of the sheet and takes the presses below the last block. */
|
|
931
|
+
.pmw-source-document__sheet { display: flex; flex-direction: column; max-width: var(--pm-sheet-width); min-height: 100%; margin-inline: auto; padding-block-start: var(--pm-space-4); background: var(--pm-color-surface); box-shadow: var(--pm-shadow-page); }
|
|
935
932
|
/* Opening: the page's own margins, so that the placeholder lines sit where the text will. */
|
|
936
933
|
.pmw-source-document__sheet--loading { box-sizing: border-box; padding: var(--pm-space-10) var(--pm-space-12); }
|
|
937
934
|
.pmw-voice__filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--pm-space-3); }
|
|
@@ -1004,22 +1001,3 @@
|
|
|
1004
1001
|
.pmw-approvals .pmw-muted { margin: 0; }
|
|
1005
1002
|
.pmw-approvals__detail { max-height: 30vh; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
1006
1003
|
.pmw-approvals__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--pm-space-2); }
|
|
1007
|
-
|
|
1008
|
-
/* The kitten walking over the preview to the blocks the AI changed: its ground line meets the block's lower left. */
|
|
1009
|
-
.pmw-change-trail {
|
|
1010
|
-
position: absolute;
|
|
1011
|
-
top: 0;
|
|
1012
|
-
left: 0;
|
|
1013
|
-
z-index: 1;
|
|
1014
|
-
pointer-events: none;
|
|
1015
|
-
transform: translate(calc(var(--pmw-trail-x) - 45%), calc(var(--pmw-trail-y) - 89%));
|
|
1016
|
-
transition: transform var(--pm-duration-walk) linear, opacity var(--pm-duration-slow);
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
.pmw-change-trail[data-phase='done'] {
|
|
1020
|
-
opacity: 0.9;
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
.pmw-change-trail__facing[data-facing='left'] {
|
|
1024
|
-
transform: scaleX(-1);
|
|
1025
|
-
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isRecord, randomUUID } from '@lincyaw/kernel'
|
|
2
|
+
import type { NarrationNode, TranscriptionAdoptionDraft } from '@lincyaw/kernel'
|
|
3
|
+
|
|
4
|
+
export interface TranscriptionCorrection { id: string, revision: number, nodes?: NarrationNode[], discarded: string[], shared: 'fork' | 'edit-shared', baseVersion?: string, applied?: boolean }
|
|
5
|
+
export interface TranscriptionCorrectionTarget { identity: string, candidate: TranscriptionAdoptionDraft['candidate'], stepId: string, narrationId?: string, segmentIds: string[] }
|
|
6
|
+
interface Entry { target: TranscriptionCorrectionTarget, draft?: TranscriptionCorrection, raw?: string | null, failed: boolean, corrupt: boolean }
|
|
7
|
+
const prefix = 'presmium.transcription-draft.v1:'
|
|
8
|
+
export const transcriptionCorrectionKey = (target: TranscriptionCorrectionTarget): string => JSON.stringify([target.identity, target.candidate.id, target.candidate.revision, target.stepId, target.narrationId ?? null, target.segmentIds])
|
|
9
|
+
const fresh = (): TranscriptionCorrection => ({ id: randomUUID(), revision: 0, discarded: [], shared: 'fork' })
|
|
10
|
+
function valid(value: unknown): value is TranscriptionCorrection {
|
|
11
|
+
return isRecord(value) && typeof value.id === 'string' && Number.isSafeInteger(value.revision) && Number(value.revision) >= 0 && Array.isArray(value.discarded) && value.discarded.every(key => typeof key === 'string') && ['fork', 'edit-shared'].includes(String(value.shared))
|
|
12
|
+
&& (value.baseVersion === undefined || typeof value.baseVersion === 'string') && (value.applied === undefined || typeof value.applied === 'boolean')
|
|
13
|
+
&& (value.nodes === undefined || Array.isArray(value.nodes) && value.nodes.every(node => isRecord(node) && (node.type === 'text' && typeof node.text === 'string' || node.type === 'pronunciation' && typeof node.display === 'string' && typeof node.spoken === 'string' || node.type === 'cue' && typeof node.id === 'string' && typeof node.action === 'string')))
|
|
14
|
+
}
|
|
15
|
+
function parseTarget(key: string): TranscriptionCorrectionTarget | undefined {
|
|
16
|
+
try {
|
|
17
|
+
const value: unknown = JSON.parse(key)
|
|
18
|
+
if (!Array.isArray(value) || value.length !== 6) return
|
|
19
|
+
const [identity, id, revision, stepId, narrationId, segmentIds] = value
|
|
20
|
+
if (typeof identity !== 'string' || typeof id !== 'string' || typeof revision !== 'string' || typeof stepId !== 'string' || narrationId !== null && typeof narrationId !== 'string' || !Array.isArray(segmentIds) || !segmentIds.every(id => typeof id === 'string')) return
|
|
21
|
+
return { identity, candidate: { id, revision }, stepId, ...narrationId !== null ? { narrationId } : {}, segmentIds }
|
|
22
|
+
} catch { return }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The native correction bank uses its existing localStorage keys; no MCP copy or provider result is changed. */
|
|
26
|
+
export class TranscriptionCorrections {
|
|
27
|
+
readonly #entries = new Map<string, Entry>()
|
|
28
|
+
#load(target: TranscriptionCorrectionTarget): Entry {
|
|
29
|
+
const key = transcriptionCorrectionKey(target), known = this.#entries.get(key)
|
|
30
|
+
if (known) return known
|
|
31
|
+
const entry: Entry = { target: structuredClone(target), failed: false, corrupt: false }
|
|
32
|
+
this.#entries.set(key, entry)
|
|
33
|
+
try {
|
|
34
|
+
entry.raw = localStorage.getItem(prefix + key)
|
|
35
|
+
if (entry.raw !== null) {
|
|
36
|
+
const value: unknown = JSON.parse(entry.raw)
|
|
37
|
+
if (!valid(value)) throw new Error('invalid-draft')
|
|
38
|
+
entry.draft = value
|
|
39
|
+
}
|
|
40
|
+
} catch { entry.failed = true; entry.corrupt = entry.raw != null }
|
|
41
|
+
return entry
|
|
42
|
+
}
|
|
43
|
+
read(target: TranscriptionCorrectionTarget): { draft: TranscriptionCorrection, failed: boolean } {
|
|
44
|
+
const entry = this.#load(target)
|
|
45
|
+
// A reopened native form adopts another window's saved value, retaining failed local input.
|
|
46
|
+
try {
|
|
47
|
+
const raw = localStorage.getItem(prefix + transcriptionCorrectionKey(target))
|
|
48
|
+
if (raw !== entry.raw && !(entry.failed && entry.draft)) {
|
|
49
|
+
const value: unknown = raw === null ? undefined : JSON.parse(raw)
|
|
50
|
+
if (value !== undefined && !valid(value)) throw new Error('invalid-draft')
|
|
51
|
+
entry.raw = raw; entry.draft = value as TranscriptionCorrection | undefined; entry.failed = false; entry.corrupt = false
|
|
52
|
+
} else if (raw !== entry.raw) entry.failed = true
|
|
53
|
+
} catch { entry.failed = true }
|
|
54
|
+
return { draft: entry.draft ? structuredClone(entry.draft) : fresh(), failed: entry.failed }
|
|
55
|
+
}
|
|
56
|
+
keep(target: TranscriptionCorrectionTarget, draft: TranscriptionCorrection): boolean {
|
|
57
|
+
if (!valid(draft)) throw new Error('invalid-draft')
|
|
58
|
+
const entry = this.#load(target), key = prefix + transcriptionCorrectionKey(target)
|
|
59
|
+
entry.draft = structuredClone(draft)
|
|
60
|
+
try {
|
|
61
|
+
if (entry.raw === undefined || localStorage.getItem(key) !== entry.raw) throw new Error('changed-draft')
|
|
62
|
+
if (entry.corrupt && entry.raw != null) localStorage.setItem(key + ':unreadable', entry.raw)
|
|
63
|
+
const raw = JSON.stringify(draft)
|
|
64
|
+
localStorage.setItem(key, raw)
|
|
65
|
+
entry.raw = raw; entry.failed = false; entry.corrupt = false
|
|
66
|
+
return true
|
|
67
|
+
} catch { entry.failed = true; return false }
|
|
68
|
+
}
|
|
69
|
+
/** A completed native adoption cannot retire input changed in another form/window while it ran. */
|
|
70
|
+
complete(target: TranscriptionCorrectionTarget, expected: TranscriptionCorrection, next: TranscriptionCorrection): boolean {
|
|
71
|
+
const key = transcriptionCorrectionKey(target), entry = this.#entries.get(key)
|
|
72
|
+
if (!entry || entry.corrupt || JSON.stringify(entry.draft) !== JSON.stringify(expected)) return false
|
|
73
|
+
try {
|
|
74
|
+
if (entry.raw === undefined || localStorage.getItem(prefix + key) !== entry.raw) return false
|
|
75
|
+
const raw = JSON.stringify(next)
|
|
76
|
+
localStorage.setItem(prefix + key, raw)
|
|
77
|
+
entry.raw = raw; entry.draft = structuredClone(next); entry.failed = false
|
|
78
|
+
return true
|
|
79
|
+
} catch { entry.failed = true; return false }
|
|
80
|
+
}
|
|
81
|
+
discard(key: string, expected: TranscriptionCorrection): boolean {
|
|
82
|
+
const entry = this.#entries.get(key)
|
|
83
|
+
if (!entry || entry.corrupt || JSON.stringify(entry.draft) !== JSON.stringify(expected)) return false
|
|
84
|
+
try {
|
|
85
|
+
if (entry.raw === undefined || localStorage.getItem(prefix + key) !== entry.raw) return false
|
|
86
|
+
localStorage.removeItem(prefix + key)
|
|
87
|
+
this.#entries.delete(key)
|
|
88
|
+
return true
|
|
89
|
+
} catch { entry.failed = true; return false }
|
|
90
|
+
}
|
|
91
|
+
snapshot(identity: string) {
|
|
92
|
+
const keys = new Set([...this.#entries].filter(([, entry]) => entry.target.identity === identity).map(([key]) => key))
|
|
93
|
+
let partial = false
|
|
94
|
+
const head = prefix + JSON.stringify([identity]).slice(0, -1) + ','
|
|
95
|
+
try {
|
|
96
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
97
|
+
const key = localStorage.key(i)
|
|
98
|
+
if (key?.startsWith(head) && !key.endsWith(':unreadable')) keys.add(key.slice(prefix.length))
|
|
99
|
+
}
|
|
100
|
+
} catch { partial = true }
|
|
101
|
+
const entries: { key: string, target: TranscriptionCorrectionTarget, draft: TranscriptionCorrection, persisted: boolean }[] = [], observed: [string, string | null][] = []
|
|
102
|
+
for (const key of keys) {
|
|
103
|
+
const target = parseTarget(key)
|
|
104
|
+
if (!target || target.identity !== identity) { partial = true; continue }
|
|
105
|
+
const entry = this.#load(target)
|
|
106
|
+
let persisted = false
|
|
107
|
+
try {
|
|
108
|
+
const raw = localStorage.getItem(prefix + key)
|
|
109
|
+
observed.push([key, raw])
|
|
110
|
+
persisted = !entry.failed && !entry.corrupt && raw === entry.raw
|
|
111
|
+
if (raw !== entry.raw) partial = true
|
|
112
|
+
} catch { partial = true }
|
|
113
|
+
if (entry.corrupt || entry.raw === undefined) partial = true
|
|
114
|
+
if (entry.draft && !entry.draft.applied) entries.push({ key, target: structuredClone(target), draft: structuredClone(entry.draft), persisted })
|
|
115
|
+
}
|
|
116
|
+
return { entries, partial, guard: () => {
|
|
117
|
+
for (const [key, raw] of observed) {
|
|
118
|
+
try { if (localStorage.getItem(prefix + key) === raw) continue } catch { /* Cannot verify the same persisted input. */ }
|
|
119
|
+
throw new Error('client-production-drafts-changed')
|
|
120
|
+
}
|
|
121
|
+
} }
|
|
122
|
+
}
|
|
123
|
+
close(): void { this.#entries.clear() }
|
|
124
|
+
}
|
|
@@ -58,13 +58,13 @@ export function useRecordingAdoption({ identity, sectionId, stepId, active, disa
|
|
|
58
58
|
if (!owns()) return
|
|
59
59
|
const source = workbench.getState().authoring
|
|
60
60
|
if (!source?.version || !source.fingerprint || !source.content || source.identity !== identity || source.dirty || source.saving || source.composing || source.restored || source.error) throw new Error('production-source-changed')
|
|
61
|
-
const expected = { identity, version: source.version }, inspection = await workbench.
|
|
61
|
+
const expected = { identity, version: source.version }, inspection = await workbench.production.inspectAudio(target.assetId, expected, controller.signal)
|
|
62
62
|
if (!owns()) return
|
|
63
63
|
const canonical = { documentId: source.content.id, version: source.version, fingerprint: source.fingerprint }, previous = retry.current
|
|
64
64
|
sent = previous && previous.source.documentId === canonical.documentId && previous.source.version === canonical.version && previous.source.fingerprint === canonical.fingerprint && previous.stepId === target.stepId && previous.assetId === target.assetId && previous.sha256 === inspection.inspection.sha256
|
|
65
65
|
? previous : { id: requestId(), source: canonical, stepId: target.stepId, assetId: target.assetId, sha256: inspection.inspection.sha256 }
|
|
66
66
|
retry.current = sent; submitted.current = sent
|
|
67
|
-
await workbench.
|
|
67
|
+
await workbench.production.adoptRecording(sent, expected, controller.signal)
|
|
68
68
|
if (!owns()) return
|
|
69
69
|
if (retry.current === sent) retry.current = undefined
|
|
70
70
|
setFailure(undefined)
|
package/src/voice-drafts.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { WorkspaceClient } from './workspace-client.ts'
|
|
|
5
5
|
|
|
6
6
|
export interface VoiceDraft { version: string, scope: DocumentVoiceScope, source: VoiceSource | null, replaceOverrides: boolean, rateInput?: string }
|
|
7
7
|
export type VoiceDraftStorageStatus = 'available' | 'unavailable' | 'corrupt'
|
|
8
|
-
interface StoredDraft { draft?: VoiceDraft, status: VoiceDraftStorageStatus, unreadable?: string }
|
|
8
|
+
interface StoredDraft { draft?: VoiceDraft, status: VoiceDraftStorageStatus, unreadable?: string, raw?: string | null }
|
|
9
9
|
const drafts = new WeakMap<WorkspaceClient, Map<string, StoredDraft>>()
|
|
10
10
|
const keyOf = (identity: string, stepId: string) => JSON.stringify([identity, stepId])
|
|
11
11
|
const storageKey = (key: string) => `presmium.voice-draft.v2:${key}`
|
|
@@ -36,6 +36,7 @@ function load(client: WorkspaceClient, key: string): StoredDraft {
|
|
|
36
36
|
known.set(key, entry)
|
|
37
37
|
try {
|
|
38
38
|
const raw = sessionStorage.getItem(storageKey(key))
|
|
39
|
+
entry.raw = raw
|
|
39
40
|
if (raw !== null) {
|
|
40
41
|
entry.unreadable = raw
|
|
41
42
|
const value: unknown = JSON.parse(raw)
|
|
@@ -64,7 +65,9 @@ export function keepVoiceDraft(client: WorkspaceClient, identity: string, stepId
|
|
|
64
65
|
entry.draft = structuredClone(value)
|
|
65
66
|
try {
|
|
66
67
|
if (entry.unreadable !== undefined) sessionStorage.setItem(`${storageKey(key)}:unreadable`, entry.unreadable)
|
|
67
|
-
|
|
68
|
+
const raw = JSON.stringify(entry.draft)
|
|
69
|
+
sessionStorage.setItem(storageKey(key), raw)
|
|
70
|
+
entry.raw = raw
|
|
68
71
|
entry.status = 'available'; delete entry.unreadable
|
|
69
72
|
return true
|
|
70
73
|
} catch { entry.status = 'unavailable'; return false }
|
|
@@ -76,14 +79,35 @@ export function clearVoiceDraft(client: WorkspaceClient, identity: string, stepI
|
|
|
76
79
|
if (expected && JSON.stringify(entry.draft) !== JSON.stringify(expected)) return false
|
|
77
80
|
try {
|
|
78
81
|
const raw = sessionStorage.getItem(storageKey(key))
|
|
79
|
-
if (expected && raw !==
|
|
80
|
-
let persisted: unknown
|
|
81
|
-
try { persisted = JSON.parse(raw) } catch { entry.status = 'corrupt'; entry.unreadable = raw; return false }
|
|
82
|
-
if (!valid(persisted)) { entry.status = 'corrupt'; entry.unreadable = raw; return false }
|
|
83
|
-
if (JSON.stringify(persisted) !== JSON.stringify(expected)) return false
|
|
84
|
-
}
|
|
82
|
+
if (expected && (entry.unreadable !== undefined || raw !== entry.raw)) return false
|
|
85
83
|
sessionStorage.removeItem(storageKey(key))
|
|
84
|
+
entry.raw = null
|
|
86
85
|
delete entry.draft; delete entry.unreadable; entry.status = 'available'
|
|
87
86
|
return true
|
|
88
87
|
} catch { entry.status = 'unavailable'; return false }
|
|
89
88
|
}
|
|
89
|
+
|
|
90
|
+
/** Enumerate this native bank, including offscreen forms; callers receive no second persisted copy. */
|
|
91
|
+
export function voiceDraftSnapshot(client: WorkspaceClient, identity: string): { entries: { stepId: string, value: VoiceDraft, persisted: boolean }[], partial: boolean } {
|
|
92
|
+
const keys = new Set([...store(client).keys()].filter(key => key.startsWith(`${JSON.stringify([identity]).slice(0, -1)},`)))
|
|
93
|
+
let partial = false
|
|
94
|
+
try {
|
|
95
|
+
const prefix = `presmium.voice-draft.v2:${JSON.stringify([identity]).slice(0, -1)},`
|
|
96
|
+
for (let index = 0; index < sessionStorage.length; index++) {
|
|
97
|
+
const key = sessionStorage.key(index)
|
|
98
|
+
if (key?.startsWith(prefix) && !key.endsWith(':unreadable')) keys.add(key.slice('presmium.voice-draft.v2:'.length))
|
|
99
|
+
}
|
|
100
|
+
} catch { partial = true }
|
|
101
|
+
const entries: { stepId: string, value: VoiceDraft, persisted: boolean }[] = []
|
|
102
|
+
for (const key of keys) {
|
|
103
|
+
let target: unknown
|
|
104
|
+
try { target = JSON.parse(key) } catch { partial = true; continue }
|
|
105
|
+
if (!Array.isArray(target) || target.length !== 2 || target[0] !== identity || typeof target[1] !== 'string') { partial = true; continue }
|
|
106
|
+
const entry = load(client, key)
|
|
107
|
+
let persisted = false
|
|
108
|
+
try { const raw = sessionStorage.getItem(storageKey(key)); persisted = entry.status === 'available' && raw === entry.raw; if (raw !== entry.raw) partial = true } catch { partial = true }
|
|
109
|
+
if (entry.status === 'corrupt' || entry.raw === undefined) partial = true
|
|
110
|
+
if (entry.draft) entries.push({ stepId: target[1], value: structuredClone(entry.draft), persisted })
|
|
111
|
+
}
|
|
112
|
+
return { entries, partial }
|
|
113
|
+
}
|
package/src/voiceover-jobs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorMessage } from '@lincyaw/kernel'
|
|
2
2
|
import type { VoiceoverJob } 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
|
const active = (job: VoiceoverJob) => ['queued', 'running', 'cancelling'].includes(job.state)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { CanonicalSource, DiagnosticSnapshot, DocumentsAnswer, FocusReport, IrAnswer, JobsAnswer, PreviewAnchor, PreviewAnswer, PreviewCommand, PreviewPoint, PreviewPosition, PreviewRect, PreviewRenderer, ProductionPlan, ProductionPlaybackState, ReviewSnapshot, RevisionsAnswer, UncommittedFile, VoiceoverJob } from '@lincyaw/kernel'
|
|
2
|
+
import type { DocumentSessionState } from './document-session.ts'
|
|
3
|
+
import type { Locale } from './messages.ts'
|
|
4
|
+
|
|
5
|
+
/** `editing`: the canonical document is edited in the parent; `viewing`: a derived snapshot is presented. */
|
|
6
|
+
export type WorkbenchMode = 'editing' | 'viewing'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* How the web form is shown: as a page or as its presentation, whose controls can play a configured lecture.
|
|
10
|
+
* Both share one preview page and switch in place with `go.view`.
|
|
11
|
+
*/
|
|
12
|
+
export type WebView = 'document' | 'present'
|
|
13
|
+
|
|
14
|
+
/** A playback key pressed in a preview that the workbench plays: Space, and the left and right arrows. */
|
|
15
|
+
export type PlaybackKey = 'play-pause' | 'previous' | 'next'
|
|
16
|
+
|
|
17
|
+
/** What the author points at in the document: a block (or a section), or a passage selected in it. */
|
|
18
|
+
export interface Pointer {
|
|
19
|
+
target: PreviewAnchor
|
|
20
|
+
step?: number
|
|
21
|
+
/** The selected passage. */
|
|
22
|
+
quote?: string
|
|
23
|
+
/** Its box in the preview's viewport; none while it is out of sight. */
|
|
24
|
+
rect?: PreviewRect
|
|
25
|
+
obstacles?: PreviewRect[]
|
|
26
|
+
point?: PreviewPoint
|
|
27
|
+
/** Its text can be edited in place. */
|
|
28
|
+
isEditable: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type SaveState =
|
|
32
|
+
| { kind: 'idle' }
|
|
33
|
+
| { kind: 'saving' }
|
|
34
|
+
| { kind: 'saved', at: string }
|
|
35
|
+
| { kind: 'locked' }
|
|
36
|
+
| { kind: 'failed', message: string }
|
|
37
|
+
|
|
38
|
+
/** A request for the agent of the conversation: its text and what it is about. */
|
|
39
|
+
export interface AgentRequest {
|
|
40
|
+
text: string
|
|
41
|
+
focus: FocusReport[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A request for the author to finish and send in the conversation, and what it is about: the host only shows it. */
|
|
45
|
+
export interface AgentDraft {
|
|
46
|
+
text: string
|
|
47
|
+
focus: FocusReport[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Where the host put a request: the conversation's session and the request's id, which its user message carries. */
|
|
51
|
+
export interface AgentAnswer {
|
|
52
|
+
session: string
|
|
53
|
+
request: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface WorkbenchState {
|
|
57
|
+
locale: Locale
|
|
58
|
+
authoring?: DocumentSessionState
|
|
59
|
+
/** Unaccepted numeric form input is retained separately from saved canonical timing. */
|
|
60
|
+
hasDocumentTimingDrafts?: boolean
|
|
61
|
+
documentTimingDraftStorageFailure?: boolean
|
|
62
|
+
captionTimingDraftSteps?: string[]
|
|
63
|
+
captionTimingDraftStorageFailure?: boolean
|
|
64
|
+
isDark: boolean
|
|
65
|
+
documents?: DocumentsAnswer
|
|
66
|
+
documentsFailure?: string
|
|
67
|
+
/** The workspace's routes answer 404: `@lincyaw/dsh` is turned off on the plugins page. */
|
|
68
|
+
isBundleDisabled?: boolean
|
|
69
|
+
document?: string
|
|
70
|
+
ir?: IrAnswer
|
|
71
|
+
mode: WorkbenchMode
|
|
72
|
+
previewRenderer: PreviewRenderer
|
|
73
|
+
/** In the web form: the page or the presentation, both in the same page, switched without loading it again. */
|
|
74
|
+
webView: WebView
|
|
75
|
+
previewReload: number
|
|
76
|
+
preview?: PreviewAnswer
|
|
77
|
+
previewFailure?: string
|
|
78
|
+
/** The IR revision the preview shows. */
|
|
79
|
+
previewIrRevision?: string
|
|
80
|
+
isPreparingPresentation?: boolean
|
|
81
|
+
presentationFailure?: string
|
|
82
|
+
presentationSnapshot?: { version: string, fingerprint: string, revision: string, project: number }
|
|
83
|
+
productionPlan?: ProductionPlan
|
|
84
|
+
productionPlayback?: ProductionPlaybackState
|
|
85
|
+
productionFailure?: string
|
|
86
|
+
voiceoverJobs?: VoiceoverJob[]
|
|
87
|
+
voiceoverJobsFailure?: string
|
|
88
|
+
/** A cache refresh that actually changed the current production binding; it never starts playback. */
|
|
89
|
+
voiceoverCacheRefresh?: { source: CanonicalSource, revision: string, sequence: number }
|
|
90
|
+
/** Changes when an acknowledged preview connection is attached or detached, including same-revision reloads. */
|
|
91
|
+
previewConnection: number
|
|
92
|
+
/** Where the preview is: the section the author reads, or the slide and its step. */
|
|
93
|
+
position?: PreviewPosition
|
|
94
|
+
/** Changes on every position intent, including A → B → A, without changing the source. */
|
|
95
|
+
documentPositionToken: string
|
|
96
|
+
/** Explicit author navigation, distinct from the player's passive cursor and frame reload reports. */
|
|
97
|
+
productionNavigationVersion: number
|
|
98
|
+
documentPositionIntent: 'seek' | 'pause'
|
|
99
|
+
/** An explicit source navigation request; scrolling updates position without issuing another request. */
|
|
100
|
+
documentNavigation?: { section: string, block?: string, request: string }
|
|
101
|
+
documentPositionFailure?: 'removed'
|
|
102
|
+
isCreatingPage?: boolean
|
|
103
|
+
isEditingPage?: boolean
|
|
104
|
+
editorHistory?: EditorHistoryState
|
|
105
|
+
isHistoryPreparing?: boolean
|
|
106
|
+
pageEditFailure?: string
|
|
107
|
+
diagnostics?: DiagnosticSnapshot
|
|
108
|
+
isDiagnosticsUnavailable: boolean
|
|
109
|
+
canRepairDiagnostics: boolean
|
|
110
|
+
isRepairingDiagnostics: boolean
|
|
111
|
+
diagnosticsRepairFailure?: string
|
|
112
|
+
pointer?: Pointer
|
|
113
|
+
save: SaveState
|
|
114
|
+
/** What the conversation's agent is told the author points at. */
|
|
115
|
+
focus: FocusReport[]
|
|
116
|
+
isFocusPending: boolean
|
|
117
|
+
focusFailure?: string
|
|
118
|
+
review?: ReviewSnapshot
|
|
119
|
+
history?: RevisionsAnswer
|
|
120
|
+
/** Files changed elsewhere and not yet in the history. */
|
|
121
|
+
outside?: UncommittedFile[]
|
|
122
|
+
historyFailure?: string
|
|
123
|
+
isHistoryBusy: boolean
|
|
124
|
+
isAsking: boolean
|
|
125
|
+
askFailure?: string
|
|
126
|
+
/** What the document can be made into, and its builds and exports (the author's and the AI's). */
|
|
127
|
+
jobs?: JobsAnswer
|
|
128
|
+
jobsFailure?: string
|
|
129
|
+
voiceServiceVersion?: number
|
|
130
|
+
jobPreparing?: { target: string, canCancel: boolean }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface PreviewSink {
|
|
134
|
+
readonly generation?: number
|
|
135
|
+
readonly capabilities?: readonly PreviewCommand['type'][]
|
|
136
|
+
send(command: PreviewCommand): void
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface EditorHistoryState { section: string, undo: boolean, redo: boolean, field?: boolean }
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
/** The workbench's state as its parts read and change it. */
|
|
143
|
+
export interface WorkbenchStore {
|
|
144
|
+
readonly state: WorkbenchState
|
|
145
|
+
set(patch: Partial<WorkbenchState>): void
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The document the conversation works on: none when no document is open. */
|
|
149
|
+
export function selectedDocument(state: WorkbenchState): string | null {
|
|
150
|
+
return state.document ?? null
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Whether the AI is changing the workspace now, or its change waits for the author. */
|
|
154
|
+
export function isAgentChanging(state: WorkbenchState): boolean {
|
|
155
|
+
return Boolean(state.review?.engine === 'git' && (state.review.running || state.review.changes.length > 0))
|
|
156
|
+
}
|
|
157
|
+
|