@lincyaw/workbench 0.2.0-rc.12 → 0.2.0-rc.121

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.
Files changed (124) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -4
  3. package/src/AgentActivityBar.tsx +25 -0
  4. package/src/MediaClipEditor.tsx +7 -6
  5. package/src/StepProductionEditor.tsx +16 -7
  6. package/src/agent-activity-messages.ts +14 -0
  7. package/src/agent-activity.ts +38 -0
  8. package/src/approvals.tsx +6 -1
  9. package/src/audio-recording-messages.ts +5 -5
  10. package/src/audio-recording.ts +27 -5
  11. package/src/authoring-client.ts +10 -10
  12. package/src/authoring-draft-fragment.ts +3 -1
  13. package/src/authoring-window.ts +100 -0
  14. package/src/base-controls.tsx +28 -7
  15. package/src/body-draft-actions.ts +60 -0
  16. package/src/caption-timing-drafts.ts +20 -3
  17. package/src/caption-timing-messages.ts +2 -2
  18. package/src/caption-timing.ts +2 -2
  19. package/src/component-draft-actions.ts +1 -1
  20. package/src/component-properties.ts +3 -3
  21. package/src/component-property-drafts.ts +6 -6
  22. package/src/components.tsx +43 -38
  23. package/src/container-layout.ts +21 -0
  24. package/src/context.tsx +5 -3
  25. package/src/diagnostics.ts +1 -1
  26. package/src/document-draft-store.ts +45 -18
  27. package/src/document-drafts.ts +30 -21
  28. package/src/document-editing.ts +485 -0
  29. package/src/document-editor/BlockNoteSurface.tsx +40 -14
  30. package/src/document-editor/CommentComposer.tsx +24 -0
  31. package/src/document-editor/ComponentMaterials.tsx +4 -10
  32. package/src/document-editor/ComponentPropertiesDialog.tsx +12 -12
  33. package/src/document-editor/DocumentBlockFallback.tsx +4 -3
  34. package/src/document-editor/DocumentBlockPreview.tsx +11 -4
  35. package/src/document-editor/DocumentComments.tsx +87 -17
  36. package/src/document-editor/DocumentEditor.tsx +66 -14
  37. package/src/document-editor/DocumentStepNarration.tsx +39 -27
  38. package/src/document-editor/NarrationEditor.tsx +55 -21
  39. package/src/document-editor/NewCommentDrafts.tsx +120 -37
  40. package/src/document-editor/PlaceComment.tsx +252 -0
  41. package/src/document-editor/agent-targets.ts +34 -0
  42. package/src/document-editor/blocknote-messages.ts +2 -0
  43. package/src/document-editor/comment-draft-actions.ts +40 -20
  44. package/src/document-editor/comment-draft-inspection.ts +2 -2
  45. package/src/document-editor/comment-drafts.ts +75 -27
  46. package/src/document-editor/comments.ts +34 -14
  47. package/src/document-editor/component-label.ts +11 -0
  48. package/src/document-editor/file-input.ts +2 -2
  49. package/src/document-editor/focus.ts +0 -2
  50. package/src/document-editor/inline.ts +1 -0
  51. package/src/document-editor/insertion-place.ts +60 -0
  52. package/src/document-editor/messages.ts +3 -3
  53. package/src/document-editor/narration-schema.tsx +12 -6
  54. package/src/document-editor/narration.ts +19 -3
  55. package/src/document-editor/page-body.ts +60 -0
  56. package/src/document-editor/popover.tsx +4 -2
  57. package/src/document-editor/projection.ts +21 -19
  58. package/src/document-editor/rich-text.ts +3 -2
  59. package/src/document-editor/selection.ts +13 -0
  60. package/src/document-editor/style.css +8 -3
  61. package/src/document-editor/table-identities.ts +2 -1
  62. package/src/document-preview.ts +3 -2
  63. package/src/document-production.ts +492 -0
  64. package/src/document-return-point.ts +2 -2
  65. package/src/document-session.ts +216 -67
  66. package/src/document-timing-drafts.ts +26 -6
  67. package/src/effective-settings.ts +12 -0
  68. package/src/history.ts +5 -5
  69. package/src/import-messages.ts +40 -0
  70. package/src/index.ts +11 -5
  71. package/src/jobs.ts +1 -1
  72. package/src/mcp-settings-messages.ts +39 -0
  73. package/src/media-drafts.ts +43 -1
  74. package/src/messages.ts +39 -18
  75. package/src/outline.ts +5 -5
  76. package/src/panels/DocumentImportDialog.tsx +59 -0
  77. package/src/panels/DocumentNarrationPanel.tsx +2 -2
  78. package/src/panels/DocumentView.tsx +106 -77
  79. package/src/panels/DocumentVoiceDialog.tsx +29 -12
  80. package/src/panels/DocumentVoiceField.tsx +3 -2
  81. package/src/panels/ExportPanel.tsx +2 -10
  82. package/src/panels/HistoryPanel.tsx +36 -10
  83. package/src/panels/HomePanel.tsx +12 -1
  84. package/src/panels/McpSettingsPanel.tsx +86 -0
  85. package/src/panels/PageDeleteDialog.tsx +4 -4
  86. package/src/panels/PageRenameDialog.tsx +1 -1
  87. package/src/panels/PreviewPanel.tsx +4 -7
  88. package/src/panels/ProductionCaptionSize.tsx +20 -0
  89. package/src/panels/ProductionCaptionTiming.tsx +12 -9
  90. package/src/panels/ProductionMediaClips.tsx +25 -9
  91. package/src/panels/ProductionPanel.tsx +21 -17
  92. package/src/panels/ProductionRecording.tsx +86 -9
  93. package/src/panels/ProductionRecordingRange.tsx +26 -23
  94. package/src/panels/ProductionTimeline.tsx +6 -1
  95. package/src/panels/ProductionTranscription.tsx +8 -6
  96. package/src/panels/SourceDocumentPanel.tsx +24 -40
  97. package/src/panels/SpeechSettingsPanel.tsx +2 -2
  98. package/src/panels/TranscriptionAdoption.tsx +42 -36
  99. package/src/panels/VoiceCloneDialog.tsx +2 -1
  100. package/src/panels/VoicePreviewDialog.tsx +1 -1
  101. package/src/panels/VoiceScopeField.tsx +2 -2
  102. package/src/panels/VoiceoverDialog.tsx +11 -10
  103. package/src/places.ts +1 -36
  104. package/src/preview-playback.ts +1 -1
  105. package/src/production-draft-actions.ts +37 -0
  106. package/src/production-messages.ts +6 -0
  107. package/src/production-playback.ts +1 -1
  108. package/src/production-voice-playback.ts +3 -2
  109. package/src/recording-adoption.ts +4 -4
  110. package/src/sha256.ts +9 -0
  111. package/src/speech-settings-messages.ts +6 -6
  112. package/src/step-production.ts +4 -4
  113. package/src/styles.css +43 -92
  114. package/src/transcription-drafts.ts +124 -0
  115. package/src/use-recording-adoption.ts +5 -4
  116. package/src/voice-drafts.ts +32 -8
  117. package/src/voice-messages.ts +9 -9
  118. package/src/voiceover-jobs.ts +1 -1
  119. package/src/workbench-state.ts +159 -0
  120. package/src/workbench.ts +323 -956
  121. package/src/workspace-client.ts +41 -12
  122. package/src/assistant-mascot.ts +0 -62
  123. package/src/mascot-preference.ts +0 -37
  124. package/src/panels/ChangeTrail.tsx +0 -79
@@ -1,6 +1,6 @@
1
- import { useEffect, useRef, useState } from 'react'
1
+ import { useEffect, useMemo, useRef } from 'react'
2
2
  import { hasRole } from '@lincyaw/kernel'
3
- import { PmButton, PmNotice, PmSelect, PmSkeleton } from '../components.tsx'
3
+ import { PmButton, PmNotice, PmSkeleton } from '../components.tsx'
4
4
  import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
5
5
  import { DocumentEditor } from '../document-editor/DocumentEditor.tsx'
6
6
  import { DOCUMENT_EDITOR_MESSAGES } from '../document-editor/messages.ts'
@@ -9,13 +9,15 @@ import { DocumentBlockPreview } from '../document-editor/DocumentBlockPreview.ts
9
9
  import { nativeEditingCursor } from '../document-editor/selection.ts'
10
10
  import { hasBlockPreview } from '../document-editor/projection.ts'
11
11
  import type { NativeDocumentEditor } from '../document-editor/schema.tsx'
12
- import { isAgentChanging } from '../workbench.ts'
13
- import { EditorChangeTrail } from './ChangeTrail.tsx'
12
+ import { isAgentChanging } from '../workbench-state.ts'
13
+ import { effectiveOf } from '../effective-settings.ts'
14
14
 
15
15
  /** Source editing is available before the first successful runtime compilation. */
16
- export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void }) {
16
+ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onOpenComments }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void, onOpenComments?(): void }) {
17
17
  const workbench = useWorkbench(), t = useMessages()
18
18
  const source = useWorkbenchState(state => state.authoring)
19
+ const activities = useWorkbenchState(state => state.agentActivities)
20
+ const agentActivities = useMemo(() => activities?.filter(activity => activity.document === source?.directory), [activities, source?.directory])
19
21
  const sourceAcknowledged = () => {
20
22
  const current = workbench.getState().authoring
21
23
  return Boolean(current && current.identity === source?.identity && current.reset === source?.reset
@@ -26,23 +28,16 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
26
28
  const navigation = useWorkbenchState(state => state.documentNavigation)
27
29
  const readOnly = useWorkbenchState(state => state.mode !== 'editing' || workbench.client.capabilities?.readOnly === true || Boolean(state.authoring?.member && !hasRole(state.authoring.member, 'editor')) || Boolean(state.authoring?.loading) || isAgentChanging(state))
28
30
  const container = useRef<HTMLElement>(null)
29
- const sheet = useRef<HTMLDivElement>(null)
30
31
  const consumedNavigation = useRef<string>()
31
32
  const bodyEditor = useRef<NativeDocumentEditor>()
32
33
  const editingPosition = useRef<{ nativeBlockId: string, sectionId: string, position: number, editor: NativeDocumentEditor, identity: string, reset: number | undefined }>()
33
34
  const cancelReading = useRef<() => void>()
34
- const [selectedDraft, setSelectedDraft] = useState('')
35
- const drafts = source?.recoveryDrafts ?? []
36
- const draftKey = (value: { id: string, revision: number, token: string }) => JSON.stringify([value.id, value.revision, value.token])
37
- const draft = drafts.find(value => draftKey(value) === selectedDraft)
38
- useEffect(() => { setSelectedDraft('') }, [source?.identity])
39
- const recoveryDisabled = readOnly || source?.saving || source?.composing || source?.recovering
40
35
  useEffect(() => {
41
36
  const element = container.current
42
- if (element && source?.identity && source.content) return workbench.attachDocumentViewport(element, source.identity)
37
+ if (element && source?.identity && source.content) return workbench.editing.attachViewport(element, source.identity)
43
38
  }, [workbench, source?.identity, Boolean(source?.content)])
44
39
  // The editor applies `readOnly` while committing, so it is editable by the time this runs.
45
- useEffect(() => { if (!readOnly) workbench.documentEditorEditable() }, [workbench, readOnly])
40
+ useEffect(() => { if (!readOnly) workbench.editing.editorEditable() }, [workbench, readOnly])
46
41
  useEffect(() => {
47
42
  if (!navigation) return
48
43
  const request = JSON.stringify([source?.identity, navigation.request])
@@ -71,7 +66,7 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
71
66
  const viewport = measure(), state = workbench.getState()
72
67
  if (gesture.generation !== state.documentPositionToken || !sameGeometry(gesture.viewport, viewport) || gesture.viewport.top !== viewport.top) return
73
68
  if (!state.authoring?.loading && !isAgentChanging(state)) {
74
- const field = workbench.focusedDocumentField(), root = field?.editor.prosemirrorView.dom.getRootNode()
69
+ const field = workbench.editing.focusedField(), root = field?.editor.prosemirrorView.dom.getRootNode()
75
70
  if (field && root instanceof ShadowRoot && element.contains(root.host)) {
76
71
  try {
77
72
  const point = field.editor.prosemirrorView.coordsAtPos(field.editor.prosemirrorState.selection.head), bounds = element.getBoundingClientRect()
@@ -115,17 +110,17 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
115
110
  const scroll = (event: Event) => {
116
111
  const viewport = measure(), previous = baseline
117
112
  baseline = viewport
118
- if (workbench.consumeDocumentReturnScroll(element)) { cancel(); return }
113
+ if (workbench.editing.consumeReturnScroll(element)) { cancel(); return }
119
114
  // Native scroll chaining from an iframe has no parent wheel event.
120
115
  if (!event.isTrusted) return
121
116
  if (!sameGeometry(previous, viewport)) { cancel(); return }
122
117
  if (viewport.top === previous.top) return
123
- workbench.documentInteraction()
118
+ workbench.editing.interact()
124
119
  queue(viewport)
125
120
  }
126
121
  const interact = (event: Event) => {
127
122
  if (!event.isTrusted) return
128
- workbench.documentInteraction()
123
+ workbench.editing.interact()
129
124
  baseline = measure()
130
125
  queue(baseline)
131
126
  }
@@ -136,7 +131,7 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
136
131
  if (['Home', 'End'].includes(event.key) && target instanceof HTMLElement && target.isContentEditable && !event.ctrlKey && !event.metaKey) return
137
132
  interact(event)
138
133
  }
139
- const pointer = () => { cancel(); workbench.documentInteraction() }
134
+ const pointer = () => { cancel(); workbench.editing.interact() }
140
135
  element.addEventListener('scroll', scroll, { passive: true })
141
136
  element.addEventListener('wheel', interact, { passive: true })
142
137
  element.addEventListener('touchmove', interact, { passive: true })
@@ -156,29 +151,17 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
156
151
  const error = source?.error === 'document-version-changed' || source?.error === 'document-identity-changed' ? messages.conflict
157
152
  : source?.error ? messages.saveFailure : undefined
158
153
  return <section ref={container} className="pmw-source-document" aria-label={t.documentEditor} aria-busy={source?.loading || undefined}>
159
- {Boolean(positionFailure || source?.storageFailure || source?.recoveryReadFailure || source?.restored || error || drafts.length || source?.recoveryChanged) && <div className="pmw-source-document__notices">
154
+ {Boolean(positionFailure || source?.storageFailure || source?.restored || error) && <div className="pmw-source-document__notices">
160
155
  {positionFailure && <PmNotice tone="warn">{t.documentPositionRemoved}</PmNotice>}
161
- {Boolean(source?.storageFailure || source?.recoveryReadFailure) && <PmNotice tone="warn">{source?.storageFailure ? t.narrationRecoveryUnavailable : t.documentDraftUnreadable}</PmNotice>}
162
- {Boolean(drafts.length || source?.recoveryChanged) && <PmNotice tone="accent"><div className="pmw-source-document__recovery">
163
- <span>{source?.recoveryChanged ? t.documentDraftChanged : t.documentDraftFound}</span>
164
- <PmSelect label={t.documentDraftSelect} value={draft ? selectedDraft : ''} disabled={Boolean(recoveryDisabled)} onChange={event => setSelectedDraft(event.currentTarget.value)}>
165
- <option value="">{t.documentDraftChoose}</option>
166
- {drafts.map((value, index) => <option key={draftKey(value)} value={draftKey(value)}>{t.documentDraftOption(index + 1, new Intl.DateTimeFormat(locale, { month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' }).format(value.updatedAt), value.source)}</option>)}
167
- </PmSelect>
168
- <div className="pmw-source-document__recovery-actions">
169
- <PmButton small variant="primary" disabled={!draft || Boolean(recoveryDisabled)} onClick={() => { if (draft && source?.identity) void workbench.recoverDocumentDraft(draft, source.identity) }}>{t.documentDraftRestore}</PmButton>
170
- <PmButton small disabled={!draft || Boolean(recoveryDisabled)} onClick={() => { if (draft && source?.identity) workbench.forgetDocumentDraft(draft, source.identity) }}>{t.narrationDiscard}</PmButton>
171
- </div>
172
- </div></PmNotice>}
173
- {source?.restored && !error && <PmNotice tone="accent"><span>{messages.restored}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton><PmButton small onClick={() => void workbench.discardDocument()}>{t.narrationDiscard}</PmButton></span></PmNotice>}
174
- {error && <PmNotice tone="danger"><span>{error}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton>{source?.dirty && <PmButton small onClick={() => void workbench.discardDocument()}>{t.narrationDiscard}</PmButton>}</span></PmNotice>}
156
+ {source?.storageFailure && <PmNotice tone="warn">{t.narrationRecoveryUnavailable}</PmNotice>}
157
+ {source?.restored && !error && <PmNotice tone="accent" action={<><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton><PmButton small onClick={() => void workbench.discardDocument()}>{t.narrationDiscard}</PmButton></>}>{messages.restored}</PmNotice>}
158
+ {error && <PmNotice tone="danger" action={<><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton>{source?.dirty && <PmButton small onClick={() => void workbench.discardDocument()}>{t.narrationDiscard}</PmButton>}</>}>{error}</PmNotice>}
175
159
  </div>}
176
160
  {source?.issues.length ? <div className="pmw-source-document__diagnostics"><PmNotice tone="warn"><details><summary>{messages.diagnostics(source.issues.length)}</summary><ul>{source.issues.map((issue, index) => <li key={`${issue.path}:${index}`}><code>{issue.path}</code> {issue.message}</li>)}</ul></details></PmNotice></div> : null}
177
161
  {!source?.content || !source.identity ? source?.loading
178
162
  ? <div className="pmw-source-document__sheet pmw-source-document__sheet--loading"><PmSkeleton label={messages.loading} /></div>
179
- : <PmNotice tone="warn"><span>{messages.unavailable}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton></span></PmNotice> : <div ref={sheet} className="pmw-source-document__sheet">
180
- <EditorChangeTrail sheet={sheet} />
181
- <DocumentEditor acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
163
+ : <PmNotice tone="warn" action={<PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton>}>{messages.unavailable}</PmNotice> : <div className="pmw-source-document__sheet">
164
+ <DocumentEditor agentActivities={agentActivities} acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} onOpenComments={onOpenComments} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} inherited={source.inherited} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
182
165
  getDocumentVersion={() => { const current = workbench.getState().authoring; return current && current.identity === source.identity && current.reset === source.reset ? current.version : undefined }} reset={source.reset} locale={locale} readOnly={readOnly}
183
166
  uploadImage={(file, signal) => workbench.importDocumentImage(file, source.identity!, signal)}
184
167
  getPositionToken={() => workbench.getState().documentPositionToken}
@@ -194,13 +177,14 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
194
177
  nodeViews={{ renderBlock: id => {
195
178
  const block = source.content?.blocks[id]
196
179
  if (!block || !source.content) return undefined
197
- const fallback = <DocumentBlockFallback block={block} document={source.content} locale={locale} />
198
- return hasBlockPreview(block, source.content) ? <DocumentBlockPreview blockId={id} fallback={fallback} /> : fallback
180
+ const effective = effectiveOf(source.content, source.inherited)
181
+ const fallback = <DocumentBlockFallback block={block} document={effective} locale={locale} />
182
+ return hasBlockPreview(block, effective.metadata.plugins) ? <DocumentBlockPreview blockId={id} fallback={fallback} /> : fallback
199
183
  } }}
200
184
  commentsPortal={commentsPortal} onChange={document => workbench.recordDocument(document)} onReady={(editor, commands) => {
201
185
  bodyEditor.current = editor
202
186
  editingPosition.current = undefined
203
- workbench.attachDocumentEditor(editor, commands, { identity: source.identity!, reset: source.reset })
187
+ workbench.editing.attachEditor(editor, commands, { identity: source.identity!, reset: source.reset })
204
188
  }}
205
189
  onEditingPosition={(position, editor) => {
206
190
  const state = workbench.getState(), current = state.authoring
@@ -53,11 +53,11 @@ export function SpeechSettingsPanel() {
53
53
  {settings && <p>{t.source[settings.source]}</p>}
54
54
  <PmInput type="password" label={t.key} hint={t.keyHint} placeholder={settings?.configured ? t.keySaved : t.keyPlaceholder} value={key} disabled={disabled} autoComplete="new-password" spellCheck={false} maxLength={8192} onChange={event => { dirty.current = Boolean(event.target.value.trim() || appId.trim()); setKey(event.target.value); setStatus(undefined) }} />
55
55
  <PmInput label={t.appId} hint={t.appIdHint} placeholder={settings?.appIdConfigured ? t.keySaved : t.appIdPlaceholder} value={appId} disabled={disabled} autoComplete="off" inputMode="numeric" spellCheck={false} maxLength={32} onChange={event => { dirty.current = Boolean(event.target.value.trim() || key.trim()); setAppId(event.target.value); setStatus(undefined) }} />
56
- <div className="pmw-speech-settings__actions"><PmButton variant="accent" loading={busy} disabled={disabled || !key.trim() && !settings?.configured} onClick={() => void save()}>{t.save}</PmButton><PmButton disabled={busy || loading || dirty.current} onClick={() => void load(true)}>{t.check}</PmButton></div>
56
+ <div className="pmw-speech-settings__actions"><PmButton small variant="primary" loading={busy} disabled={disabled || !key.trim() && !settings?.configured} onClick={() => void save()}>{t.save}</PmButton><PmButton small variant="text" disabled={busy || loading || dirty.current} onClick={() => void load(true)}>{t.check}</PmButton></div>
57
57
  </div></PmCard>
58
58
  <PmNotice>{t.verification}</PmNotice>
59
59
  <p>{t.privacy}</p>
60
- <div className="pmw-speech-settings__actions"><a className="pm-ui-link" href="https://console.volcengine.com/speech/new/setting/apikeys" target="_blank" rel="noreferrer">{t.console}</a>{settings?.stored && <PmButton small variant="ghost" disabled={disabled} onClick={() => setConfirm(true)}>{t.remove}</PmButton>}</div>
60
+ <div className="pmw-speech-settings__actions"><a className="pm-ui-link" href="https://console.volcengine.com/speech/new/setting/apikeys" target="_blank" rel="noreferrer">{t.console}</a>{settings?.stored && <PmButton small variant="text" disabled={disabled} onClick={() => setConfirm(true)}>{t.remove}</PmButton>}</div>
61
61
  </div>
62
62
  <PmDialog open={confirm} label={t.removeTitle} closeLabel={t.cancel} busy={busy} onClose={() => setConfirm(false)} description={t.removeHint} footer={<><PmButton disabled={busy} onClick={() => setConfirm(false)}>{t.cancel}</PmButton><PmButton variant="danger" loading={busy} onClick={() => void save(true)}>{t.remove}</PmButton></>} />
63
63
  </section>
@@ -1,30 +1,19 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react'
2
- import { prepareTranscriptionAdoption } from '@lincyaw/kernel'
3
- import type { CanonicalSource, NarrationNode, TeachingDocument, TranscriptionRevision, TranscriptionAdoptionDraft, TranscriptionAdoptionPart, TranscriptionAdoptionPlan } from '@lincyaw/kernel'
2
+ import { prepareTranscriptionAdoption, randomUUID } from '@lincyaw/kernel'
3
+ import type { CanonicalSource, NarrationNode, PresmiumDocument, TranscriptionRevision, TranscriptionAdoptionDraft, TranscriptionAdoptionPart, TranscriptionAdoptionPlan } from '@lincyaw/kernel'
4
4
  import { PmBadge, PmButton, PmDialog, PmField, PmNotice, PmSelect, PmTextarea } from '../components.tsx'
5
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
6
6
  import { NarrationEditor } from '../document-editor/NarrationEditor.tsx'
7
- import { narrationToNative } from '../document-editor/narration.ts'
7
+ import { narrationToNative, nativeToNarration } from '../document-editor/narration.ts'
8
8
  import type { NativeNarrationEditor } from '../document-editor/narration-schema.tsx'
9
9
  import { TRANSCRIPTION_MESSAGES } from '../transcription-messages.ts'
10
+ import { transcriptionCorrectionKey } from '../transcription-drafts.ts'
11
+ import type { TranscriptionCorrection as Draft } from '../transcription-drafts.ts'
10
12
 
11
- interface Props { identity: string, candidate: TranscriptionRevision, document: TeachingDocument, sectionId: string, stepId: string, disabled: boolean }
12
- interface Draft { id: string, revision: number, nodes?: NarrationNode[], discarded: string[], shared: 'fork' | 'edit-shared', baseVersion?: string, applied?: boolean }
13
+ interface Props { identity: string, candidate: TranscriptionRevision, document: PresmiumDocument, sectionId: string, stepId: string, disabled: boolean }
13
14
  const ordered = (value: unknown): unknown => Array.isArray(value) ? value.map(ordered) : value && typeof value === 'object' ? Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered((value as Record<string, unknown>)[key])])) : value
14
15
  const same = (a: unknown, b: unknown) => JSON.stringify(ordered(a)) === JSON.stringify(ordered(b))
15
16
  const displayed = (nodes: readonly NarrationNode[]) => nodes.map(node => node.type === 'text' ? node.text : node.type === 'pronunciation' ? node.display : '').join('')
16
- function restore(key: string): { draft: Draft, failed: boolean } {
17
- const fallback = () => ({ draft: { id: crypto.randomUUID(), revision: 0, discarded: [], shared: 'fork' as const }, failed: false })
18
- try {
19
- const raw = localStorage.getItem(key)
20
- if (!raw) return fallback()
21
- const value = JSON.parse(raw)
22
- if (!value || typeof value.id !== 'string' || !Number.isSafeInteger(value.revision) || value.revision < 0 || !Array.isArray(value.discarded) || !value.discarded.every((key: unknown) => typeof key === 'string') || !['fork', 'edit-shared'].includes(value.shared)
23
- || value.baseVersion !== undefined && typeof value.baseVersion !== 'string' || value.applied !== undefined && typeof value.applied !== 'boolean'
24
- || value.nodes !== undefined && (!Array.isArray(value.nodes) || !value.nodes.every((node: NarrationNode) => 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')))) throw new Error('invalid-draft')
25
- return { draft: value, failed: false }
26
- } catch { return { ...fallback(), failed: true } }
27
- }
28
17
 
29
18
  export function TranscriptionAdoption(props: Props) {
30
19
  const locale = useWorkbenchState(state => state.locale), t = TRANSCRIPTION_MESSAGES[locale]
@@ -41,11 +30,27 @@ export function TranscriptionAdoption(props: Props) {
41
30
 
42
31
  function AdoptionTarget({ identity, candidate, document, sectionId, stepId, disabled, narrationId, segments }: Props & { narrationId?: string, segments: string[] }) {
43
32
  const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), t = TRANSCRIPTION_MESSAGES[locale], source = useWorkbenchState(state => state.authoring)
44
- const key = `presmium.transcription-draft.v1:${JSON.stringify([identity, candidate.transcriptionId, candidate.revision, stepId, narrationId, segments])}`
45
- const [restored] = useState(() => restore(key)), [draft, setDraft] = useState(restored.draft), latest = useRef(draft)
33
+ const correctionTarget = useMemo(() => ({ identity, candidate: { id: candidate.transcriptionId, revision: candidate.revision }, stepId, narrationId, segmentIds: segments }), [identity, candidate.transcriptionId, candidate.revision, stepId, narrationId, JSON.stringify(segments)])
34
+ const correctionKey = transcriptionCorrectionKey(correctionTarget), key = `presmium.transcription-draft.v1:${correctionKey}`
35
+ const [restored] = useState(() => workbench.production.transcriptionCorrection(correctionTarget)), [draft, setDraft] = useState(restored.draft), latest = useRef(draft)
46
36
  const [storageFailed, setStorageFailed] = useState(restored.failed), [composing, setComposing] = useState(false)
47
37
  const [plan, setPlan] = useState<TranscriptionAdoptionPlan>(), [reviewing, setReviewing] = useState(false), [applying, setApplying] = useState(false), [open, setOpen] = useState(false), [failure, setFailure] = useState<string>(), [status, setStatus] = useState<string>()
48
- const editor = useRef<NativeNarrationEditor>(), generation = useRef(0)
38
+ const editor = useRef<NativeNarrationEditor>(), generation = useRef(0), interaction = useRef({ composing: false, pending: false }), unavailable = useRef(false)
39
+ unavailable.current = disabled || reviewing || applying || open
40
+ useEffect(() => workbench.production.registerDraftView({ identity, kind: 'transcription', has: target => target === correctionKey,
41
+ blocked: () => interaction.current.composing || interaction.current.pending || unavailable.current,
42
+ clear: () => {
43
+ generation.current++
44
+ const value = workbench.production.transcriptionCorrection(correctionTarget)
45
+ latest.current = value.draft; setDraft(value.draft); setStorageFailed(value.failed)
46
+ setPlan(undefined); setOpen(false); setFailure(undefined); setStatus(undefined)
47
+ } }), [workbench, identity, correctionKey])
48
+ useEffect(() => { workbench.refreshAuthoringClientControls() }, [workbench, disabled, reviewing, applying, open])
49
+ const busy = (value: boolean) => { interaction.current.pending = value; workbench.refreshAuthoringClientControls() }
50
+ const composition = (value: boolean) => {
51
+ if (interaction.current.composing === value) return
52
+ interaction.current.composing = value; setComposing(value); workbench.refreshAuthoringClientControls()
53
+ }
49
54
  useEffect(() => () => { generation.current++ }, [])
50
55
  const binding: CanonicalSource = { documentId: document.id, version: source?.version ?? '', fingerprint: source?.fingerprint ?? '' }
51
56
  const references = narrationId ? Object.values(document.steps).filter(step => step.narrationIds.includes(narrationId)).map(step => step.id) : []
@@ -76,46 +81,47 @@ function AdoptionTarget({ identity, candidate, document, sectionId, stepId, disa
76
81
  generation.current++
77
82
  const next = { ...latest.current, ...patch, revision: latest.current.revision + 1, applied: false }
78
83
  latest.current = next; setDraft(next); setPlan(undefined); setFailure(undefined); setStatus(undefined)
79
- try { localStorage.setItem(key, JSON.stringify(next)); setStorageFailed(false) } catch { setStorageFailed(true) }
84
+ setStorageFailed(!workbench.production.keepTranscriptionCorrection(correctionTarget, next))
80
85
  }
81
86
  const pause = () => { workbench.stopAuditions(); void workbench.pausePlayback().catch(() => {}) }
82
87
  const preview = async () => {
83
88
  const now = workbench.getState().authoring
84
89
  if (disabled || reviewing || applying || composing || !sourceReady || !now?.version || !now.fingerprint || parsed.invalid) return
85
90
  pause()
86
- if (latest.current.baseVersion && latest.current.baseVersion !== now.version) change({ id: crypto.randomUUID(), baseVersion: now.version })
91
+ if (latest.current.baseVersion && latest.current.baseVersion !== now.version) change({ id: randomUUID(), baseVersion: now.version })
87
92
  else if (!latest.current.baseVersion) change({ baseVersion: now.version })
88
93
  const value = latest.current, request = ++generation.current, normalized = content()
89
94
  const retainsOriginal = references.length > 1 && value.shared === 'fork'
90
95
  const removeCueTimings = atoms.filter(atom => value.discarded.includes(atom.key) && atom.node.type === 'cue' && !retainsOriginal && Object.hasOwn(document.production.cueTimings ?? {}, atom.node.id)).map(atom => (atom.node as Extract<NarrationNode, { type: 'cue' }>).id)
91
96
  const sent: TranscriptionAdoptionDraft = { id: value.id, source: { documentId: document.id, version: now.version, fingerprint: now.fingerprint }, candidate: { id: candidate.transcriptionId, revision: candidate.revision }, draftRevision: value.revision, targets: [{ ...target, content: normalized.parts, discardAtoms: value.discarded.filter(key => atoms.some(atom => atom.key === key)) }], ...removeCueTimings.length ? { removeCueTimings } : {} }
92
- setReviewing(true); setFailure(undefined)
97
+ busy(true); setReviewing(true); setFailure(undefined)
93
98
  try {
94
- const answer = await workbench.planDocumentTranscription(sent, { identity, version: now.version })
99
+ const answer = await workbench.production.planTranscription(sent, { identity, version: now.version })
95
100
  if (request !== generation.current || latest.current.revision !== sent.draftRevision) return
96
101
  setPlan(answer); setOpen(true)
97
102
  } catch { if (request === generation.current) setFailure(t.previewFailed) }
98
- finally { setReviewing(false) }
103
+ finally { busy(false); setReviewing(false) }
99
104
  }
100
105
  const apply = async () => {
101
106
  if (!plan?.planId || !planCurrent || plan.conflicts.length || plan.draftRevision !== latest.current.revision || composing || applying || !sourceReady) return
102
- const sent = plan, planId = plan.planId
103
- setApplying(true); setFailure(undefined)
107
+ const sent = plan, planId = plan.planId, expected = latest.current, request = ++generation.current
108
+ busy(true); setApplying(true); setFailure(undefined)
104
109
  try {
105
- const answer = await workbench.adoptDocumentTranscription({ planId, source: sent.source, candidate: sent.candidate, draftRevision: sent.draftRevision }, { identity, version: sent.source.version })
106
- if (latest.current.id === sent.changeId && latest.current.revision === sent.draftRevision) {
107
- const next: Draft = { ...latest.current, id: crypto.randomUUID(), revision: 0, discarded: [], baseVersion: answer.version, applied: true }
108
- latest.current = next; setDraft(next)
109
- try { localStorage.setItem(key, JSON.stringify(next)); setStorageFailed(false) } catch { setStorageFailed(true) }
110
- }
110
+ const answer = await workbench.production.adoptTranscription({ planId, source: sent.source, candidate: sent.candidate, draftRevision: sent.draftRevision }, { identity, version: sent.source.version })
111
+ const next: Draft = { ...expected, id: randomUUID(), revision: 0, discarded: [], baseVersion: answer.version, applied: true }
112
+ const completed = workbench.production.completeTranscriptionCorrection(correctionTarget, expected, next)
113
+ if (request !== generation.current) return
114
+ if (completed) { latest.current = next; setDraft(next) }
115
+ setStorageFailed(!completed)
111
116
  setPlan(undefined); setOpen(false); setStatus(t.adopted)
112
117
  } catch { setFailure(t.applyFailed) }
113
- finally { setApplying(false) }
118
+ finally { busy(false); setApplying(false) }
114
119
  }
115
120
  if (!displayed(nodes).trim() && !atoms.length) return <span>{t.empty}</span>
116
121
  return <>
117
- <PmField label={t.text} group><NarrationEditor identity={key} narrationId={original?.outputNarrationId ?? draft.id} content={nodes} getContent={() => latest.current.nodes ?? nodes} locale={locale} advanced={false} readOnly={disabled || applying}
118
- onReady={value => { editor.current = value }} onComposition={setComposing} onFocus={pause} onChange={value => {
122
+ <PmField label={t.text} group><NarrationEditor identity={key} fieldId={original?.outputNarrationId ?? draft.id} content={nodes} getContent={() => latest.current.nodes ?? nodes} locale={locale} advanced={false} readOnly={disabled || applying}
123
+ toNative={value => narrationToNative(original?.outputNarrationId ?? draft.id, value)} fromNative={nativeToNarration}
124
+ onReady={value => { editor.current = value }} onComposition={composition} onFocus={pause} onChange={value => {
119
125
  const used = new Set<string>()
120
126
  for (const node of value) { const atom = atoms.find(atom => !used.has(atom.key) && same(atom.node, node)); if (atom) used.add(atom.key) }
121
127
  change({ nodes: value, discarded: latest.current.discarded.filter(key => !used.has(key)) })
@@ -40,9 +40,10 @@ function RecordingSlot({ label, hint, value, disabled, onChange }: { label: stri
40
40
  const capturing = ['requesting', 'recording', 'stopping'].includes(state.phase)
41
41
  const start = () => {
42
42
  setFailure(undefined)
43
- void recording.start(async () => {
43
+ void recording.start(async signal => {
44
44
  workbench.stopAuditions()
45
45
  await workbench.pausePlayback()
46
+ signal.throwIfAborted()
46
47
  return workbench.registerAudioCapture(() => recording.stop())
47
48
  })
48
49
  }
@@ -57,7 +57,7 @@ export function VoicePreviewDialog({ quote, snapshot, onClose, onRecheck }: { qu
57
57
  <PmButton small onClick={close}>{t.close}</PmButton>
58
58
  {changed && onRecheck && <PmButton small onClick={recheck}>{t.recheck}</PmButton>}
59
59
  {active ? <PmButton small onClick={() => audition.current?.stop()}>{t.stop}</PmButton>
60
- : <PmButton small variant="accent" disabled={changed || !audition.current} onClick={confirm}>{t.confirmPreview}</PmButton>}
60
+ : <PmButton small variant="primary" disabled={changed || !audition.current} onClick={confirm}>{t.confirmPreview}</PmButton>}
61
61
  </>}>
62
62
  <div className="pmw-operation">
63
63
  <PmField label={t.provider}><span>{quote.provider}</span></PmField>
@@ -1,4 +1,4 @@
1
- import type { TeachingDocument } from '@lincyaw/kernel'
1
+ import type { PresmiumDocument } from '@lincyaw/kernel'
2
2
  import { PmButton, PmField, PmSegmented } from '../components.tsx'
3
3
  import { useWorkbenchState } from '../context.tsx'
4
4
  import type { DocumentVoiceScope } from '../document-voices.ts'
@@ -6,7 +6,7 @@ import { PRODUCTION_MESSAGES } from '../production-messages.ts'
6
6
  import { VOICE_MESSAGES } from '../voice-messages.ts'
7
7
 
8
8
  /** Scope selection uses authored IDs and stays available before runtime compilation. */
9
- export function VoiceScopeField({ document, stepId, value, disabled, onChange }: { document: TeachingDocument, stepId: string, value: DocumentVoiceScope, disabled?: boolean, onChange(value: DocumentVoiceScope): void }) {
9
+ export function VoiceScopeField({ document, stepId, value, disabled, onChange }: { document: PresmiumDocument, stepId: string, value: DocumentVoiceScope, disabled?: boolean, onChange(value: DocumentVoiceScope): void }) {
10
10
  const locale = useWorkbenchState(state => state.locale), t = VOICE_MESSAGES[locale], p = PRODUCTION_MESSAGES[locale]
11
11
  const sectionId = document.steps[stepId]?.sectionId
12
12
  return <>
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react'
2
2
  import { speechEngineId } from '@lincyaw/kernel'
3
- import type { TeachingDocument, VoiceoverJob, VoiceoverSnapshot, VoiceScope } from '@lincyaw/kernel'
3
+ import type { PresmiumDocument, VoiceoverJob, VoiceoverSnapshot, VoiceScope } from '@lincyaw/kernel'
4
4
  import { PmButton, PmDialog, PmField, PmNotice } from '../components.tsx'
5
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
6
6
  import { documentVoiceStepIds, resolveDocumentStepVoice } from '../document-voices.ts'
@@ -8,10 +8,11 @@ import type { DocumentVoiceScope } from '../document-voices.ts'
8
8
  import { VOICE_MESSAGES, voiceFailure } from '../voice-messages.ts'
9
9
  import { prepareVoiceSnapshot, runtimeVoiceScope, voiceSnapshotCurrent } from '../voice-snapshot.ts'
10
10
  import type { VoiceSnapshot } from '../voice-snapshot.ts'
11
- import { isAgentChanging } from '../workbench.ts'
11
+ import { isAgentChanging } from '../workbench-state.ts'
12
12
  import { VoiceScopeField } from './VoiceScopeField.tsx'
13
+ import { effectiveOf } from '../effective-settings.ts'
13
14
 
14
- interface CheckedVoice { snapshot: VoiceSnapshot, document: TeachingDocument }
15
+ interface CheckedVoice { snapshot: VoiceSnapshot, document: PresmiumDocument }
15
16
  interface OwnedJob { directory: string }
16
17
  const NO_JOBS: VoiceoverJob[] = []
17
18
  const active = (job: VoiceoverJob) => ['queued', 'running', 'cancelling'].includes(job.state)
@@ -110,7 +111,7 @@ export function VoiceoverDialog({ stepId, onClose }: { stepId: string, onClose()
110
111
  const selection = useMemo(() => {
111
112
  if (!checked || !status) return undefined
112
113
  try {
113
- const ids = documentVoiceStepIds(checked.document, scope), wanted = new Set(ids)
114
+ const ids = documentVoiceStepIds(checked.document, scope), wanted = new Set(ids), effective = effectiveOf(checked.document, source?.inherited)
114
115
  const steps = status.steps.filter(value => {
115
116
  const page = checked.snapshot.ir.sections.find(page => page.id === value.target.section)
116
117
  return page?.stepIds?.[value.target.step] !== undefined && wanted.has(page.stepIds[value.target.step]!)
@@ -122,17 +123,17 @@ export function VoiceoverDialog({ stepId, onClose }: { stepId: string, onClose()
122
123
  const missing = units.filter(value => value.state === 'missing').reduce((sum, value) => sum + value.utterances - value.cached, 0)
123
124
  const blocked = units.filter(value => value.state === 'blocked').reduce((sum, value) => sum + value.utterances - value.cached, 0)
124
125
  const providers = status.capability.providers.filter(provider => ids.some(id => {
125
- const value = resolveDocumentStepVoice(checked.document, id).value
126
+ const value = resolveDocumentStepVoice(effective, id).value
126
127
  return value?.type === 'tts' && provider.id === speechEngineId(value.voice.engine ?? status.capability.defaultEngine ?? '')
127
128
  }))
128
129
  const text = ids.flatMap(id => checked.document.steps[id]!.narrationIds.map(narrationId => checked.document.narrations[narrationId]!.content.map(node => node.type === 'text' ? node.text : node.type === 'pronunciation' ? node.spoken : '').join(''))).join('\n\n')
129
- const voices = [...new Map(ids.flatMap(id => { const value = resolveDocumentStepVoice(checked.document, id).value; return value?.type === 'tts' ? [[JSON.stringify(value.voice), value.voice] as const] : [] })).values()]
130
- const silent = ids.filter(id => resolveDocumentStepVoice(checked.document, id).value?.type === 'none').length
131
- const unset = ids.some(id => resolveDocumentStepVoice(checked.document, id).value === undefined)
130
+ const voices = [...new Map(ids.flatMap(id => { const value = resolveDocumentStepVoice(effective, id).value; return value?.type === 'tts' ? [[JSON.stringify(value.voice), value.voice] as const] : [] })).values()]
131
+ const silent = ids.filter(id => resolveDocumentStepVoice(effective, id).value?.type === 'none').length
132
+ const unset = ids.some(id => resolveDocumentStepVoice(effective, id).value === undefined)
132
133
  const reasons = [...new Set(units.filter(value => value.state === 'blocked').flatMap(value => value.reason && !(value.reason === 'voice-unset' && silent && !unset) ? [value.reason] : []))]
133
134
  return { cached, missing, blocked, providers, voices, silent, reasons, text, hasUnbound: !unbound.length && (status.unboundByPage ?? []).some(value => pages.has(value.section) && value.utterances > 0) }
134
135
  } catch { return undefined }
135
- }, [checked, status, scope])
136
+ }, [checked, status, scope, source?.inherited])
136
137
  const hasScopeJob = useMemo(() => {
137
138
  if (!checked) return false
138
139
  try {
@@ -188,7 +189,7 @@ export function VoiceoverDialog({ stepId, onClose }: { stepId: string, onClose()
188
189
  return <PmDialog open label={t.generation} closeLabel={closeLabel} onClose={close} footer={<>
189
190
  <PmButton small onClick={close}>{closeLabel}</PmButton>
190
191
  <PmButton small loading={loading} disabled={submitting} onClick={() => setAttempt(value => value + 1)}>{changed ? t.recheck : t.refresh}</PmButton>
191
- <PmButton small variant="accent" loading={submitting} disabled={loading || changed || readOnly || hasActive || !selection?.missing || !selection.providers.length || !status?.capability.available} onClick={() => void start()}>{t.confirmGenerate}</PmButton>
192
+ <PmButton small variant="primary" loading={submitting} disabled={loading || changed || readOnly || hasActive || !selection?.missing || !selection.providers.length || !status?.capability.available} onClick={() => void start()}>{t.confirmGenerate}</PmButton>
192
193
  </>}>
193
194
  <div className="pmw-operation">
194
195
  {(source?.content || checked?.document) && <VoiceScopeField document={checked?.document ?? source!.content!} stepId={stepId} value={scope} disabled={loading || submitting || readOnly} onChange={chooseScope} />}
package/src/places.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { irBlocks } from '@lincyaw/kernel'
2
- import type { IRDocument, PreviewAnchor, ReviewChange, SourcePos, TeachingDocument } from '@lincyaw/kernel'
2
+ import type { IRDocument, PreviewAnchor, ReviewChange, SourcePos } from '@lincyaw/kernel'
3
3
 
4
4
  const CHANGED_PLACES = 100
5
5
 
@@ -65,38 +65,3 @@ export function changedPlaces(doc: IRDocument, changes: readonly ReviewChange[])
65
65
  }
66
66
  return [...places.values()].slice(0, CHANGED_PLACES)
67
67
  }
68
-
69
- /**
70
- * The places that differ between two versions of a document: each block whose content changed or that is new (with
71
- * its page), each page whose title changed or that is new, and the block of each step whose narration or settings
72
- * changed, at most CHANGED_PLACES.
73
- */
74
- export function changedBlocks(before: TeachingDocument, after: TeachingDocument): PreviewAnchor[] {
75
- const places: PreviewAnchor[] = []
76
- const visit = (section: string, ids: readonly string[]) => {
77
- for (const id of ids) {
78
- const block = after.blocks[id]
79
- if (!block) continue
80
- if (JSON.stringify(block) !== JSON.stringify(before.blocks[id])) places.push({ section, block: id })
81
- if ('children' in block && Array.isArray(block.children)) visit(section, block.children as string[])
82
- }
83
- }
84
- for (const id of after.sectionOrder) {
85
- const section = after.sections[id]
86
- if (!section) continue
87
- if (before.sections[id]?.title !== section.title) places.push({ section: id })
88
- visit(id, section.children)
89
- }
90
- // A changed step, or a changed narration of it, shows at the block the step plays (else at its page).
91
- const seen = new Set(places.map(place => `${place.section}\0${place.block ?? ''}`))
92
- for (const step of Object.values(after.steps)) {
93
- const narrated = step.narrationIds.some(id => JSON.stringify(after.narrations[id]) !== JSON.stringify(before.narrations[id]))
94
- if (!narrated && JSON.stringify(step) === JSON.stringify(before.steps[step.id])) continue
95
- // the component the step plays, where its narration shows, else any block it shows
96
- const block = step.visuals.find(visual => after.blocks[visual.blockId]?.type === 'component')?.blockId ?? step.visuals.find(visual => visual.visible)?.blockId ?? step.visuals[0]?.blockId
97
- const place = { section: step.sectionId, ...block ? { block } : {} }
98
- const key = `${place.section}\0${place.block ?? ''}`
99
- if (!seen.has(key)) { seen.add(key); places.push(place) }
100
- }
101
- return places.slice(0, CHANGED_PLACES)
102
- }
@@ -1,5 +1,5 @@
1
1
  import type { PreviewReport } from '@lincyaw/kernel'
2
- import type { PreviewSink } from './workbench.ts'
2
+ import type { PreviewSink } from './workbench-state.ts'
3
3
 
4
4
  interface PlaybackContext { document?: string, scope: number, sinks: ReadonlySet<PreviewSink> }
5
5
  interface PendingPause {
@@ -0,0 +1,37 @@
1
+ import type { AuthoringClientAction, AuthoringClientActionResult } from '@lincyaw/kernel'
2
+ import { authoringDraftFragment, draftContentHash } from './authoring-draft-fragment.ts'
3
+ import type { DocumentProduction } from './document-production.ts'
4
+
5
+ /** Explicit reads use the native pending values; discard never submits production changes. */
6
+ export async function executeProductionDraftAction(owner: DocumentProduction, action: Extract<AuthoringClientAction, { type: `production-drafts.${string}` }>, signal: AbortSignal, owned: () => void, fits: (value: AuthoringClientActionResult) => boolean): Promise<AuthoringClientActionResult> {
7
+ const snapshot = owner.productionDraftSnapshot()
8
+ const guard = () => { signal.throwIfAborted(); owned(); snapshot.guard() }
9
+ const values = await Promise.all(snapshot.candidates.map(async candidate => ({ candidate, metadata: { ...candidate.metadata, draft: await draftContentHash(JSON.stringify([snapshot.stamp, candidate.key])) } })))
10
+ guard()
11
+ if (action.type === 'production-drafts.inspect') {
12
+ const token = await draftContentHash(JSON.stringify([snapshot.coverage, values.map(value => value.metadata)]))
13
+ guard()
14
+ if (action.cursor && action.cursor.token !== token) throw new Error('client-production-drafts-changed')
15
+ const start = action.cursor ? values.findIndex(value => value.metadata.draft === action.cursor!.after) + 1 : 0
16
+ if (action.cursor && !start) throw new Error('client-production-drafts-changed')
17
+ const result: Extract<AuthoringClientActionResult, { type: 'production-drafts.inspect' }> = { type: action.type, family: 'production', coverage: snapshot.coverage, token, drafts: [] }
18
+ for (const value of values.slice(start, start + (action.limit ?? 10))) {
19
+ const next = { ...result, drafts: [...result.drafts, value.metadata], ...start + result.drafts.length + 1 < values.length ? { next: { after: value.metadata.draft, token } } : {} }
20
+ if (!fits(next)) break
21
+ result.drafts.push(value.metadata)
22
+ }
23
+ if (start < values.length && !result.drafts.length) throw new Error('client-production-metadata-too-large')
24
+ if (start + result.drafts.length < values.length) result.next = { after: result.drafts.at(-1)!.draft, token }
25
+ if (!fits(result)) throw new Error('client-production-metadata-too-large')
26
+ guard(); return result
27
+ }
28
+ const selected = values.filter(value => value.metadata.draft === action.draft)
29
+ if (selected.length !== 1) throw new Error('client-production-drafts-changed')
30
+ const candidate = selected[0]!.candidate
31
+ if (action.type === 'production-drafts.read') return authoringDraftFragment({ text: JSON.stringify({ kind: candidate.metadata.kind, stepId: candidate.metadata.stepId, ...candidate.metadata.field ? { field: candidate.metadata.field } : {}, value: candidate.value }),
32
+ base: { type: action.type, family: 'production', draft: action.draft, format: 'presmium-production-draft-json-v1' }, offset: action.offset, maxChars: action.maxChars }, guard, fits)
33
+ const result: AuthoringClientActionResult = { type: action.type, family: 'production', draft: action.draft, discarded: true }
34
+ if (!fits(result)) throw new Error('client-production-result-too-large')
35
+ guard(); candidate.discard(); signal.throwIfAborted(); owned()
36
+ return result
37
+ }
@@ -57,6 +57,9 @@ const zh = {
57
57
  alignmentStatus: { manual: '手动时间', words: '词时码', proportional: '比例估时', none: '未对齐' },
58
58
  segmentStatus: { recorded: '原音频', cached: '已有配音', silent: '静音', missing: '配音待生成', blocked: '暂不可用' },
59
59
  waveformLoading: '正在加载波形…', waveformUnavailable: '波形不可用', stepNumber: (index: number) => `步骤 ${index + 1}`,
60
+ notInLecture: '不在讲授中', notInLectureHint: '这一页的内容都限定在其他形态,又没有讲稿与音频,讲授视频中没有这一页。',
61
+ notInLectureStep: '这一步不在讲授中:它的内容都限定在其他形态,又没有讲稿与音频。',
62
+ captionSize: '字幕大小', captionSizeHint: '整个文稿的字幕:放映中显示的与导出视频中烧录的都按这个大小。',
60
63
  timelineLabels: { position: '位置', seconds: '秒', seek: '播放头位置', zoomIn: '放大时间线', zoomOut: '缩小时间线', fit: '适配本页', estimated: '估计时长', unknown: '时长未知', loading: '正在加载时间线…', empty: '当前页暂无时间线片段', seekHint: '选择步骤,或用时间尺、方向键和精确时间定位;定位会先暂停播放。', invalidPosition: '请输入本页时长范围内的秒数。' },
61
64
  failures: {
62
65
  'production-source-changed': '文稿已更新,旧播放请求已停止。请重新准备当前版本。',
@@ -129,6 +132,9 @@ export const PRODUCTION_MESSAGES: Record<Locale, typeof zh> = {
129
132
  alignmentStatus: { manual: 'Manual timing', words: 'Word timing', proportional: 'Proportional timing', none: 'Unaligned' },
130
133
  segmentStatus: { recorded: 'Original audio', cached: 'Voiceover cached', silent: 'Silent', missing: 'Voiceover needed', blocked: 'Unavailable' },
131
134
  waveformLoading: 'Loading waveform…', waveformUnavailable: 'Waveform unavailable', stepNumber: index => `Step ${index + 1}`,
135
+ notInLecture: 'Not in the lecture', notInLectureHint: 'Everything on this page is limited to other forms and it has no script or audio, so the lecture video leaves it out.',
136
+ notInLectureStep: 'This step is not in the lecture: everything on it is limited to other forms and it has no script or audio.',
137
+ captionSize: 'Caption size', captionSizeHint: 'For the whole document: captions shown in the presentation and burned into an exported video use this size.',
132
138
  timelineLabels: { position: 'Position', seconds: 'seconds', seek: 'Playhead position', zoomIn: 'Zoom In Timeline', zoomOut: 'Zoom Out Timeline', fit: 'Fit Page', estimated: 'Estimated duration', unknown: 'Unknown duration', loading: 'Loading the timeline…', empty: 'This page has no timeline segments', seekHint: 'Select a step, or use the ruler, arrow keys, or an exact time to seek. Seeking pauses playback first.', invalidPosition: 'Enter a time in seconds within this page’s duration.' },
133
139
  failures: {
134
140
  'production-source-changed': 'The document changed and the old playback request stopped. Prepare the current version.',
@@ -1,6 +1,6 @@
1
1
  import type { PreviewReport, ProductionBinding, ProductionPlaybackCommand, ProductionPlaybackState } from '@lincyaw/kernel'
2
2
  import { sameProductionBinding } from '@lincyaw/kernel'
3
- import type { PreviewSink } from './workbench.ts'
3
+ import type { PreviewSink } from './workbench-state.ts'
4
4
 
5
5
  interface Context {
6
6
  document?: string
@@ -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, WorkbenchState } from './workbench.ts'
8
- import { isAgentChanging } from './workbench.ts'
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
 
@@ -1,4 +1,4 @@
1
- import type { DocumentAnswer, DocumentRecordingAdoption, TeachingDocument, VoiceSource } from '@lincyaw/kernel'
1
+ import type { DocumentAnswer, DocumentRecordingAdoption, PresmiumDocument, VoiceSource } from '@lincyaw/kernel'
2
2
 
3
3
  const same = (a: unknown, b: unknown): boolean => {
4
4
  if (a === b) return true
@@ -7,13 +7,13 @@ const same = (a: unknown, b: unknown): boolean => {
7
7
  const left = a as Record<string, unknown>, right = b as Record<string, unknown>, keys = Object.keys(left)
8
8
  return keys.length === Object.keys(right).length && keys.every(key => Object.hasOwn(right, key) && same(left[key], right[key]))
9
9
  }
10
- function source(document: TeachingDocument, stepId: string): VoiceSource | undefined {
10
+ function source(document: PresmiumDocument, stepId: string): VoiceSource | undefined {
11
11
  const step = document.steps[stepId]
12
12
  return step && (document.production.stepOverrides[stepId]?.voiceSource ?? document.production.sectionOverrides?.[step.sectionId]?.voiceSource ?? document.production.defaults.voiceSource)
13
13
  }
14
14
 
15
15
  /** Accept only the submitted recording delta; later author input remains the sole local draft. */
16
- export function reconcileRecordingAdoption(request: DocumentRecordingAdoption, before: TeachingDocument, answer: DocumentAnswer, current: TeachingDocument): TeachingDocument | undefined {
16
+ export function reconcileRecordingAdoption(request: DocumentRecordingAdoption, before: PresmiumDocument, answer: DocumentAnswer, current: PresmiumDocument): PresmiumDocument | undefined {
17
17
  if (before.id !== request.source.documentId || current.id !== before.id || answer.content.id !== before.id) return
18
18
  const step = before.steps[request.stepId], asset = before.assets[request.assetId]
19
19
  if (!step || asset?.kind !== 'audio') return
@@ -25,7 +25,7 @@ export function reconcileRecordingAdoption(request: DocumentRecordingAdoption, b
25
25
  const content = structuredClone(current), localAsset = content.assets[asset.id]
26
26
  const assetUnchanged = same(localAsset, asset) || same(localAsset, expected.assets[asset.id])
27
27
  if (assetUnchanged) content.assets[asset.id]!.fingerprint = `sha256:${request.sha256}`
28
- const own = (document: TeachingDocument) => document.production.stepOverrides[step.id]?.voiceSource
28
+ const own = (document: PresmiumDocument) => document.production.stepOverrides[step.id]?.voiceSource
29
29
  if (assetUnchanged && content.steps[step.id] && same(own(current), own(before)) && same(source(current, step.id), source(before, step.id))) {
30
30
  content.production.stepOverrides[step.id] = { ...content.production.stepOverrides[step.id], voiceSource: voice }
31
31
  }
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
+ }