@lincyaw/workbench 0.2.0-rc.119 → 0.2.0-rc.120

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 (48) hide show
  1. package/README.md +1 -1
  2. package/package.json +4 -4
  3. package/src/StepProductionEditor.tsx +2 -2
  4. package/src/caption-timing-drafts.ts +2 -2
  5. package/src/caption-timing.ts +2 -2
  6. package/src/component-draft-actions.ts +1 -1
  7. package/src/component-properties.ts +3 -3
  8. package/src/component-property-drafts.ts +1 -1
  9. package/src/document-drafts.ts +2 -2
  10. package/src/document-editing.ts +7 -6
  11. package/src/document-editor/ComponentMaterials.tsx +2 -2
  12. package/src/document-editor/ComponentPropertiesDialog.tsx +2 -2
  13. package/src/document-editor/DocumentBlockFallback.tsx +4 -3
  14. package/src/document-editor/DocumentComments.tsx +2 -2
  15. package/src/document-editor/DocumentEditor.tsx +10 -7
  16. package/src/document-editor/DocumentStepNarration.tsx +4 -3
  17. package/src/document-editor/agent-targets.ts +2 -2
  18. package/src/document-editor/comment-drafts.ts +4 -4
  19. package/src/document-editor/comments.ts +7 -7
  20. package/src/document-editor/inline.ts +1 -0
  21. package/src/document-editor/messages.ts +2 -2
  22. package/src/document-editor/projection.ts +19 -17
  23. package/src/document-preview.ts +3 -2
  24. package/src/document-production.ts +7 -6
  25. package/src/document-return-point.ts +2 -2
  26. package/src/document-session.ts +19 -16
  27. package/src/document-timing-drafts.ts +4 -4
  28. package/src/effective-settings.ts +12 -0
  29. package/src/messages.ts +6 -0
  30. package/src/outline.ts +5 -5
  31. package/src/panels/DocumentVoiceDialog.tsx +4 -3
  32. package/src/panels/DocumentVoiceField.tsx +2 -1
  33. package/src/panels/HomePanel.tsx +1 -0
  34. package/src/panels/ProductionCaptionSize.tsx +2 -2
  35. package/src/panels/ProductionMediaClips.tsx +2 -2
  36. package/src/panels/ProductionPanel.tsx +3 -2
  37. package/src/panels/ProductionRecordingRange.tsx +3 -2
  38. package/src/panels/ProductionTranscription.tsx +4 -3
  39. package/src/panels/SourceDocumentPanel.tsx +5 -3
  40. package/src/panels/TranscriptionAdoption.tsx +2 -2
  41. package/src/panels/VoiceScopeField.tsx +2 -2
  42. package/src/panels/VoiceoverDialog.tsx +9 -8
  43. package/src/recording-adoption.ts +4 -4
  44. package/src/speech-settings-messages.ts +1 -1
  45. package/src/step-production.ts +4 -4
  46. package/src/use-recording-adoption.ts +3 -2
  47. package/src/workbench.ts +14 -6
  48. package/src/workspace-client.ts +3 -0
@@ -1,13 +1,14 @@
1
1
  import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
2
- import type { DocumentTranscriptionRequest, TeachingDocument, TranscriptionCapabilities, TranscriptionListAnswer, TranscriptionRevision, TranscriptionTask } from '@lincyaw/kernel'
2
+ import type { DocumentTranscriptionRequest, PresmiumDocument, TranscriptionCapabilities, TranscriptionListAnswer, TranscriptionRevision, TranscriptionTask } from '@lincyaw/kernel'
3
3
  import { randomUUID } from '@lincyaw/kernel'
4
4
  import { PmBadge, PmButton, PmCard, PmDialog, PmField, PmIconButton, PmNotice, PmSelect } from '../components.tsx'
5
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
6
6
  import { documentTranscriptionSession } from '../transcription-session.ts'
7
7
  import { TRANSCRIPTION_MESSAGES, transcriptionFailure } from '../transcription-messages.ts'
8
8
  import { TranscriptionAdoption } from './TranscriptionAdoption.tsx'
9
+ import { effectiveOf } from '../effective-settings.ts'
9
10
 
10
- interface Props { identity: string, directory: string, document: TeachingDocument, sectionId: string, stepId: string, disabled: boolean, active: boolean, selectedAsset?: { id: string, revision: number }, onSelectAsset(): void }
11
+ interface Props { identity: string, directory: string, document: PresmiumDocument, sectionId: string, stepId: string, disabled: boolean, active: boolean, selectedAsset?: { id: string, revision: number }, onSelectAsset(): void }
11
12
 
12
13
  /** ASR creates material; a separate, source-bound review is the only script write. */
13
14
  export function ProductionTranscription({ identity, directory, document, sectionId, stepId, disabled, active, selectedAsset, onSelectAsset }: Props) {
@@ -95,7 +96,7 @@ export function ProductionTranscription({ identity, directory, document, section
95
96
  try {
96
97
  const expected = { identity, version: now.version }, audio = await workbench.production.inspectAudio(assetId, expected, controller.signal)
97
98
  if (!current() || controller.signal.aborted) return
98
- const request: DocumentTranscriptionRequest = { intent: `transcription_${randomUUID()}`, source: { documentId: now.content.id, version: now.version, fingerprint: now.fingerprint }, assetId, audioSha256: audio.inspection.sha256, engine, lang: now.content.metadata.lang, confirmed: true }
99
+ const request: DocumentTranscriptionRequest = { intent: `transcription_${randomUUID()}`, source: { documentId: now.content.id, version: now.version, fingerprint: now.fingerprint }, assetId, audioSha256: audio.inspection.sha256, engine, lang: effectiveOf(now.content, now.inherited).metadata.lang, confirmed: true }
99
100
  await session.start(request, () => workbench.production.startTranscription(request, expected))
100
101
  } catch (error) { if (current() && !controller.signal.aborted) setFailure(transcriptionFailure(error, locale)) }
101
102
  finally { if (inspectionRequest.current === controller) { inspectionRequest.current = undefined; if (current()) setInspecting(false) } }
@@ -10,6 +10,7 @@ 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
12
  import { isAgentChanging } from '../workbench-state.ts'
13
+ import { effectiveOf } from '../effective-settings.ts'
13
14
 
14
15
  /** Source editing is available before the first successful runtime compilation. */
15
16
  export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onOpenComments }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void, onOpenComments?(): void }) {
@@ -160,7 +161,7 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onO
160
161
  {!source?.content || !source.identity ? source?.loading
161
162
  ? <div className="pmw-source-document__sheet pmw-source-document__sheet--loading"><PmSkeleton label={messages.loading} /></div>
162
163
  : <PmNotice tone="warn" action={<PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton>}>{messages.unavailable}</PmNotice> : <div className="pmw-source-document__sheet">
163
- <DocumentEditor agentActivities={agentActivities} acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} onOpenComments={onOpenComments} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
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)}
164
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}
165
166
  uploadImage={(file, signal) => workbench.importDocumentImage(file, source.identity!, signal)}
166
167
  getPositionToken={() => workbench.getState().documentPositionToken}
@@ -176,8 +177,9 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onO
176
177
  nodeViews={{ renderBlock: id => {
177
178
  const block = source.content?.blocks[id]
178
179
  if (!block || !source.content) return undefined
179
- const fallback = <DocumentBlockFallback block={block} document={source.content} locale={locale} />
180
- 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
181
183
  } }}
182
184
  commentsPortal={commentsPortal} onChange={document => workbench.recordDocument(document)} onReady={(editor, commands) => {
183
185
  bodyEditor.current = editor
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react'
2
2
  import { prepareTranscriptionAdoption, randomUUID } from '@lincyaw/kernel'
3
- import type { CanonicalSource, NarrationNode, TeachingDocument, TranscriptionRevision, TranscriptionAdoptionDraft, TranscriptionAdoptionPart, TranscriptionAdoptionPlan } 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'
@@ -10,7 +10,7 @@ import { TRANSCRIPTION_MESSAGES } from '../transcription-messages.ts'
10
10
  import { transcriptionCorrectionKey } from '../transcription-drafts.ts'
11
11
  import type { TranscriptionCorrection as Draft } from '../transcription-drafts.ts'
12
12
 
13
- interface Props { identity: string, candidate: TranscriptionRevision, document: TeachingDocument, sectionId: string, stepId: string, disabled: boolean }
13
+ interface Props { identity: string, candidate: TranscriptionRevision, document: PresmiumDocument, sectionId: string, stepId: string, disabled: boolean }
14
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
15
15
  const same = (a: unknown, b: unknown) => JSON.stringify(ordered(a)) === JSON.stringify(ordered(b))
16
16
  const displayed = (nodes: readonly NarrationNode[]) => nodes.map(node => node.type === 'text' ? node.text : node.type === 'pronunciation' ? node.display : '').join('')
@@ -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'
@@ -10,8 +10,9 @@ import { prepareVoiceSnapshot, runtimeVoiceScope, voiceSnapshotCurrent } from '.
10
10
  import type { VoiceSnapshot } from '../voice-snapshot.ts'
11
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 {
@@ -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
  }
@@ -10,7 +10,7 @@ const zh = {
10
10
  source: { saved: '使用本机保存的密钥', environment: '使用启动环境中的密钥', none: '尚未配置密钥' },
11
11
  configured: '已配置,尚未验证服务权限', unconfigured: '未配置',
12
12
  verification: '检查配置仅检查已保存的本机设置,服务权限在播放或试听时验证。请先开通语音合成服务;播放会按需生成并缓存配音,可能产生服务费用。',
13
- privacy: '密钥仅保存在本机此工作区的服务配置中,不写入讲义。',
13
+ privacy: '密钥仅保存在本机此工作区的服务配置中,不写入文稿。',
14
14
  check: '检查', save: '保存', saved: '语音服务已保存,无需重启。', checked: '本机配置可用。请通过试听验证服务权限。',
15
15
  remove: '清除密钥', removeTitle: '清除语音服务密钥', removeHint: '清除本机保存的密钥后恢复启动环境中的配置;讲稿、音色选择和已有配音保留。', cancel: '取消',
16
16
  cleared: '已清除本机保存的密钥。', retry: '重试', loading: '正在加载语音服务设置…',
@@ -1,4 +1,4 @@
1
- import type { StepProduction, TeachingDocument } from '@lincyaw/kernel'
1
+ import type { StepProduction, PresmiumDocument } from '@lincyaw/kernel'
2
2
 
3
3
  export const STEP_TIMING_KEYS = ['narrationStart', 'minimumHoldMs', 'trailingPauseMs'] as const
4
4
  export type StepTimingKey = typeof STEP_TIMING_KEYS[number]
@@ -9,7 +9,7 @@ export type StepDurationKey = 'minimumHoldMs' | 'trailingPauseMs'
9
9
  export interface StepDurationDraft { text: string, error: boolean, review?: boolean }
10
10
 
11
11
  /** The source is author intent; an absent value is not a fabricated playback default. */
12
- export function stepTimingValue<K extends StepTimingKey>(document: TeachingDocument, stepId: string, key: K): { value: StepProduction[K], source: ProductionSource } {
12
+ export function stepTimingValue<K extends StepTimingKey>(document: PresmiumDocument, stepId: string, key: K): { value: StepProduction[K], source: ProductionSource } {
13
13
  const production = document.production, step = document.steps[stepId]
14
14
  const layers = [[production.stepOverrides[stepId], 'step'], [step && production.sectionOverrides?.[step.sectionId], 'section'], [production.defaults, 'document']] as const
15
15
  for (const [settings, source] of layers) if (settings?.[key] !== undefined) return { value: settings[key], source }
@@ -17,7 +17,7 @@ export function stepTimingValue<K extends StepTimingKey>(document: TeachingDocum
17
17
  }
18
18
 
19
19
  /** Migrated narration defaults are inherited until this step explicitly overrides its start. */
20
- export function stepNarrationStarts(document: TeachingDocument, stepId: string) {
20
+ export function stepNarrationStarts(document: PresmiumDocument, stepId: string) {
21
21
  const inherited = stepTimingValue(document, stepId, 'narrationStart')
22
22
  return (document.steps[stepId]?.narrationIds ?? []).map(id => ({ id,
23
23
  value: inherited.source === 'step' ? inherited.value : document.production.narrationOverrides?.[id]?.narrationStart ?? inherited.value,
@@ -26,7 +26,7 @@ export function stepNarrationStarts(document: TeachingDocument, stepId: string)
26
26
  }
27
27
 
28
28
  /** Patches only author-owned timing; voice, cues, media and other steps retain their source values. */
29
- export function changeStepTiming(document: TeachingDocument, stepId: string, patch: StepTimingPatch): TeachingDocument {
29
+ export function changeStepTiming(document: PresmiumDocument, stepId: string, patch: StepTimingPatch): PresmiumDocument {
30
30
  const step = document.steps[stepId]
31
31
  if (!step || !document.sections[step.sectionId]?.stepOrder.includes(stepId)) return document
32
32
  for (const key of Object.keys(patch)) if (!STEP_TIMING_KEYS.includes(key as StepTimingKey)) throw new Error('document-production-key')
@@ -2,10 +2,11 @@ import { useEffect, useRef, useState } from 'react'
2
2
  import type { DocumentRecordingAdoption } from '@lincyaw/kernel'
3
3
  import type { DocumentSessionState } from './document-session.ts'
4
4
  import { useWorkbench, useWorkbenchState } from './context.tsx'
5
+ import { effectiveOf } from './effective-settings.ts'
5
6
 
6
7
  const requestId = () => `recording_${[...crypto.getRandomValues(new Uint8Array(16))].map(value => value.toString(16).padStart(2, '0')).join('')}`
7
8
  function applied(source: DocumentSessionState | undefined, request: DocumentRecordingAdoption): boolean {
8
- const document = source?.content, step = document?.steps[request.stepId]
9
+ const document = effectiveOf(source?.content, source?.inherited), step = document?.steps[request.stepId]
9
10
  const voice = step && (document.production.stepOverrides[step.id]?.voiceSource ?? document.production.sectionOverrides?.[step.sectionId]?.voiceSource ?? document.production.defaults.voiceSource)
10
11
  return Boolean(document?.id === request.source.documentId && voice?.type === 'recording' && voice.assetId === request.assetId && document.assets[request.assetId]?.fingerprint === `sha256:${request.sha256}`)
11
12
  }
@@ -18,7 +19,7 @@ export function useRecordingAdoption({ identity, sectionId, stepId, active, disa
18
19
  const [selection, setSelection] = useState<string>(), [busy, setBusy] = useState(false), [failure, setFailure] = useState<string>()
19
20
  const owner = useRef({ active: false, revision: 0 }), request = useRef<AbortController>(), retry = useRef<DocumentRecordingAdoption>(), submitted = useRef<DocumentRecordingAdoption>(), reported = useRef<string>()
20
21
  const latest = useRef({ sectionId, stepId, active, onAdopted }); latest.current = { sectionId, stepId, active, onAdopted }
21
- const document = source?.identity === identity ? source.content : undefined
22
+ const document = source?.identity === identity ? effectiveOf(source.content, source.inherited) : undefined
22
23
  const effective = document && (document.production.stepOverrides[stepId]?.voiceSource ?? document.production.sectionOverrides?.[sectionId]?.voiceSource ?? document.production.defaults.voiceSource)
23
24
  const selected = selection ?? candidateAssetId ?? (effective?.type === 'recording' ? effective.assetId : '')
24
25
  const assets = Object.values(document?.assets ?? {}).filter(asset => asset.kind === 'audio')
package/src/workbench.ts CHANGED
@@ -2,7 +2,7 @@ import { DocumentProduction } from './document-production.ts'
2
2
  import { DocumentEditing } from './document-editing.ts'
3
3
  import { isAgentChanging } from './workbench-state.ts'
4
4
  import type { AgentAnswer, AgentDraft, AgentRequest, PlaybackKey, Pointer, PreviewSink, WebView, WorkbenchMode, WorkbenchState, WorkbenchStore } from './workbench-state.ts'
5
- import { enableDocumentProduction, randomUUID } from '@lincyaw/kernel'
5
+ import { enableDocumentProduction, randomUUID, DOCUMENT_ENTRY } from '@lincyaw/kernel'
6
6
  import type { ProjectOperation, ProjectPlan, AuthoringWindowSnapshot, AuthoringWindowAction, AuthoringWindowRequest, AuthoringWindowRequestResult } from '@lincyaw/kernel'
7
7
  import { CommentDraftBank } from './document-editor/comment-drafts.ts'
8
8
  import { ComponentPropertyDrafts } from './component-property-drafts.ts'
@@ -22,7 +22,7 @@ import { documentRecordingActive, disposeDocumentRecordings } from './audio-reco
22
22
  import type { DocumentSessionState } from './document-session.ts'
23
23
  import type { DocumentDraftReference } from './document-drafts.ts'
24
24
  import type { DocumentReturnPoint } from './document-return-point.ts'
25
- import type { DocumentChangeAnswer, TeachingDocument } from '@lincyaw/kernel'
25
+ import type { DocumentChangeAnswer, PresmiumDocument } from '@lincyaw/kernel'
26
26
  import type { DocumentInsertionPlace } from './document-editor/insertion-place.ts'
27
27
  import type { CanonicalSource, VoiceoverJob } from '@lincyaw/kernel'
28
28
  import { compileDocumentPreview, readPreviewWhenReady, waitForPreviewRequest } from './document-preview.ts'
@@ -467,6 +467,14 @@ export class Workbench {
467
467
  return answer
468
468
  }
469
469
 
470
+ /** Upgrades the workspace's documents to the current format, then refreshes the document list. */
471
+ async migrateWorkspace(): Promise<import('@lincyaw/kernel').WorkspaceMigrationAnswer> {
472
+ if (!this.client.migrateWorkspace) throw new Error('workspace-migrate-unavailable')
473
+ const answer = await this.client.migrateWorkspace()
474
+ await this.loadDocuments()
475
+ return answer
476
+ }
477
+
470
478
  /** Makes a document called `title` from the template, in a directory of its own; answers the directory. */
471
479
  async createDocument(title: string, template?: string): Promise<string> {
472
480
  const taken = this.#state.documents?.documents.map(doc => doc.dir) ?? []
@@ -661,7 +669,7 @@ export class Workbench {
661
669
  controller.signal.throwIfAborted()
662
670
  const ir = snapshot.ir
663
671
  if (!current()) return false
664
- const entry = directory ? `${directory}/lecture.json` : 'lecture.json'
672
+ const entry = directory ? `${directory}/${DOCUMENT_ENTRY}` : DOCUMENT_ENTRY
665
673
  if (!unchanged() || ir.revision !== snapshot.revision || ir.sourceFingerprints?.[entry] !== fingerprint
666
674
  || ir.doc.source?.version !== version || ir.doc.source.fingerprint !== fingerprint) throw new Error('presentation-source-changed')
667
675
  if (ir.diagnostics.some(finding => finding.severity === 'error')) throw new Error('document-preview-compile-failed')
@@ -1139,7 +1147,7 @@ export class Workbench {
1139
1147
  stopAuditions(): void { this.#playback.stopAuditions() }
1140
1148
 
1141
1149
  /** The latest source actor value, scoped to the field/editor that captured its identity. */
1142
- getDocument(identity?: string): TeachingDocument | undefined {
1150
+ getDocument(identity?: string): PresmiumDocument | undefined {
1143
1151
  const source = this.#state.authoring
1144
1152
  if (!source || source.loading || source.directory !== this.#state.document || identity !== undefined && identity !== source.identity) return undefined
1145
1153
  return source.content
@@ -1192,7 +1200,7 @@ export class Workbench {
1192
1200
  if (scope !== this.#documentScope || this.#state.authoring?.identity !== expected.identity) throw new Error('component-source-changed')
1193
1201
  return remember(answer)
1194
1202
  } catch (error) {
1195
- const current = this.#state.authoring, file = plan.files.find(value => value.path === (source.directory ? `${source.directory}/lecture.json` : 'lecture.json'))
1203
+ const current = this.#state.authoring, file = plan.files.find(value => value.path === (source.directory ? `${source.directory}/${DOCUMENT_ENTRY}` : DOCUMENT_ENTRY))
1196
1204
  // commitExternal has independently read and reconciled this exact predicted canonical version.
1197
1205
  if (scope === this.#documentScope && current?.identity === expected.identity && current.content && current.version && current.fingerprint && !current.error
1198
1206
  && file?.version === current.version && current.version !== plan.source.version) {
@@ -1207,7 +1215,7 @@ export class Workbench {
1207
1215
  throw error
1208
1216
  }
1209
1217
  }
1210
- recordDocument(content: TeachingDocument): void { if (!isAgentChanging(this.#state)) this.#documentSession.record(content) }
1218
+ recordDocument(content: PresmiumDocument): void { if (!isAgentChanging(this.#state)) this.#documentSession.record(content) }
1211
1219
  documentComposition(composing: boolean, owner = 'body', identity?: string): void { this.#documentSession.composition(composing, owner, identity) }
1212
1220
  retryDocument(): Promise<void> { return this.#documentSession.retry() }
1213
1221
  discardDocument(): Promise<void> { return this.#documentSession.discard().then(() => {}) }
@@ -80,6 +80,8 @@ export interface WorkspaceClient {
80
80
  subscribeRequests?(listener: (event: WorkspaceRequestEvent) => void): () => void
81
81
  readDocuments(document?: string): Promise<DocumentsAnswer>
82
82
  importDocuments?(files: readonly File[], signal?: AbortSignal): Promise<import('@lincyaw/kernel').DocumentImportAnswer>
83
+ /** Converts the workspace's documents to the current format, one revision per document. */
84
+ migrateWorkspace?(): Promise<import('@lincyaw/kernel').WorkspaceMigrationAnswer>
83
85
  planProjectChange(request: ProjectPlanRequest): Promise<ProjectPlan>
84
86
  operateDocument(operation: ProjectOperation, planned?: ProjectPlan): Promise<OperationAnswer>
85
87
  readSource(document: string, path: string): Promise<SourceAnswer>
@@ -377,6 +379,7 @@ export function workspaceClient(base = 'api/presmium/', subscription?: Workspace
377
379
  for (const file of files) body.append('files', file, file.name)
378
380
  return call(url('documents/import'), { method: 'POST', body, signal })
379
381
  },
382
+ migrateWorkspace: () => call(url('workspace/migrate'), { method: 'POST' }),
380
383
  readSource: (document, path) => call(url('source', document, { path })),
381
384
  saveSource: (document, path, content, base, message) => post(url('source', document), { path, content, base, ...message ? { message } : {} }),
382
385
  saveSourceTransaction: (document, changes, message) => post(url('source/transaction', document), { changes, ...message ? { message } : {} }),