@lincyaw/kernel 1.0.0-rc.1 → 1.0.0-rc.100
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/README.md +1 -1
- package/package.json +4 -2
- package/src/authoring.ts +3 -1
- package/src/contracts/agent-activity.ts +18 -0
- package/src/contracts/authoring-actions.ts +3 -3
- package/src/contracts/authoring-clients.ts +94 -6
- package/src/contracts/authoring-windows.ts +47 -0
- package/src/contracts/authoring.ts +1 -1
- package/src/contracts/capture.ts +174 -0
- package/src/contracts/document-audio.ts +8 -6
- package/src/contracts/document-image.ts +7 -5
- package/src/contracts/document-voice.ts +42 -2
- package/src/contracts/document.ts +18 -1
- package/src/contracts/media-uploads.ts +28 -0
- package/src/contracts/plugin.ts +1 -3
- package/src/contracts/preview.ts +3 -3
- package/src/contracts/projects.ts +4 -1
- package/src/contracts/speech-settings.ts +13 -0
- package/src/contracts/speech.ts +16 -0
- package/src/contracts/voiceover-execution.ts +25 -1
- package/src/contracts/workspace-changes.ts +27 -0
- package/src/contracts/workspace-review.ts +39 -0
- package/src/contracts/workspace-source.ts +38 -0
- package/src/contracts/workspace.ts +3 -0
- package/src/contracts.ts +7 -0
- package/src/document-authoring-actions.ts +23 -4
- package/src/document-caption-scale.ts +17 -0
- package/src/document-caption-timings.ts +2 -0
- package/src/document-comments.ts +30 -37
- package/src/document-components.ts +4 -12
- package/src/document-narrations.ts +57 -0
- package/src/document-operations.ts +32 -2
- package/src/document-pages.ts +8 -1
- package/src/document-places.ts +92 -0
- package/src/document-schema.ts +4 -4
- package/src/document.ts +13 -1
- package/src/embed.ts +26 -0
- package/src/escape-html.ts +4 -0
- package/src/html.ts +1 -4
- package/src/index.ts +16 -6
- package/src/ir.ts +23 -48
- package/src/lower-myst.ts +3 -12
- package/src/myst-marks.ts +15 -0
- package/src/node/authoring-actions.ts +3 -1
- package/src/node/authoring-windows.ts +11 -0
- package/src/node/document-voice.ts +6 -2
- package/src/node/fonts.ts +6 -3
- package/src/node/index.ts +11 -3
- package/src/node/operator-speech.ts +4 -0
- package/src/node/packages.ts +25 -0
- package/src/node/service-lease.ts +34 -0
- package/src/node/service-state.ts +67 -0
- package/src/node/workspace-changes.ts +7 -0
- package/src/node/workspace-review.ts +9 -0
- package/src/node/workspace-source.ts +10 -0
- package/src/preview-events.ts +6 -4
- package/src/preview-frame-connect.ts +1105 -0
- package/src/preview-frame.ts +32 -1119
- package/src/production-captions.ts +9 -0
- package/src/random-uuid.ts +8 -0
- package/src/stale-module.ts +15 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { CanonicalSource } from '../ir.ts'
|
|
2
|
+
import type { Schema } from '@cfworker/json-schema'
|
|
2
3
|
import type { Finding } from './checks.ts'
|
|
3
4
|
import type { Member } from './server.ts'
|
|
4
|
-
import type { SpeechEngineInfo } from './speech.ts'
|
|
5
|
+
import type { SpeechEngineInfo, VoiceCloneRequest, VoiceCloneStatus } from './speech.ts'
|
|
5
6
|
import type { VoiceCatalogAnswer, VoiceoverCancellation } from './voice.ts'
|
|
6
7
|
import type { DocumentVoiceTasks, VoiceoverJobQuery, VoiceoverStart, VoicePreviewStart } from './voiceover-execution.ts'
|
|
8
|
+
import { MEDIA_LOCATION_PROPERTIES } from './media-uploads.ts'
|
|
7
9
|
|
|
8
10
|
export interface DocumentVoiceCapabilities {
|
|
9
11
|
document: string
|
|
@@ -16,13 +18,30 @@ export interface DocumentVoiceCapabilities {
|
|
|
16
18
|
preview: boolean
|
|
17
19
|
engines: SpeechEngineInfo[]
|
|
18
20
|
defaultEngine?: string
|
|
19
|
-
actions: { status: boolean, list: true, get: true, start: boolean, cancel: true, quotePreview: boolean, preview: boolean, readPreview: true }
|
|
21
|
+
actions: { status: boolean, list: true, get: true, start: boolean, cancel: true, quotePreview: boolean, preview: boolean, readPreview: true, clone?: boolean, cloneStatus?: boolean }
|
|
20
22
|
tasks: { idempotency: 'process', limits: { intents: number, recentJobs: number, concurrent: number, quotes: number, quoteLifetimeMs: number, previewBytes: number, previewResources: number, retainedPreviewBytes: number } }
|
|
21
23
|
findings?: Finding[]
|
|
22
24
|
}
|
|
23
25
|
export interface DocumentVoiceCatalogQuery { source?: CanonicalSource, engine?: string, lang?: string }
|
|
24
26
|
export interface DocumentVoiceCatalogAnswer extends VoiceCatalogAnswer { document: string, source: CanonicalSource, findings?: Finding[] }
|
|
25
27
|
|
|
28
|
+
export const VOICE_CLONE_MAX_AUDIO_BYTES = 10 << 20
|
|
29
|
+
export type DocumentVoiceCloneAudio = string | { upload: string }
|
|
30
|
+
/** Scoped workspace paths or ready uploads; the service fixes their bytes before spending approval. */
|
|
31
|
+
export type DocumentVoiceCloneRequest = Omit<VoiceCloneRequest, 'sample' | 'consent'> & {
|
|
32
|
+
source?: CanonicalSource
|
|
33
|
+
sample: DocumentVoiceCloneAudio
|
|
34
|
+
consent: { speaker: string, scope: string, statement: DocumentVoiceCloneAudio }
|
|
35
|
+
}
|
|
36
|
+
export interface DocumentVoiceCloneQuery { engine?: string, voice: string }
|
|
37
|
+
/** A process-local capability for this call, never a model argument or a retained plan. */
|
|
38
|
+
export interface PreparedVoiceClone {
|
|
39
|
+
engine: string
|
|
40
|
+
voice: string
|
|
41
|
+
start(signal?: AbortSignal): Promise<VoiceCloneStatus>
|
|
42
|
+
close(): void
|
|
43
|
+
}
|
|
44
|
+
|
|
26
45
|
/** Shared voice discovery and explicitly authorized tasks; discovery never compiles or synthesizes. */
|
|
27
46
|
export interface DocumentVoiceAuthoring extends DocumentVoiceTasks {
|
|
28
47
|
capabilities(document: string, member: Member, signal?: AbortSignal): Promise<DocumentVoiceCapabilities>
|
|
@@ -32,6 +51,12 @@ export interface DocumentVoiceAuthoring extends DocumentVoiceTasks {
|
|
|
32
51
|
checkPreview(document: string, request: VoicePreviewStart, member: Member, signal?: AbortSignal): Promise<void>
|
|
33
52
|
/** Undefined when there is something to cancel; otherwise the unchanged state that cancel would report. */
|
|
34
53
|
checkCancel(document: string, query: VoiceoverJobQuery, member: Member): Promise<VoiceoverCancellation | undefined>
|
|
54
|
+
prepareClone?(document: string, request: DocumentVoiceCloneRequest, member: Member, signal?: AbortSignal): Promise<PreparedVoiceClone>
|
|
55
|
+
/** Trusted host preparation uses the same bounded native bank; references never enter model arguments. */
|
|
56
|
+
prepareCloneReference?(document: string, request: DocumentVoiceCloneRequest, member: Member, signal?: AbortSignal): Promise<{ id: string, engine: string, voice: string }>
|
|
57
|
+
runPreparedClone?(document: string, id: string, request: DocumentVoiceCloneRequest, member: Member, signal?: AbortSignal): Promise<VoiceCloneStatus>
|
|
58
|
+
releasePreparedClone?(document: string, id: string, member: Member): boolean
|
|
59
|
+
cloneStatus?(document: string, query: DocumentVoiceCloneQuery, member: Member, signal?: AbortSignal): Promise<VoiceCloneStatus>
|
|
35
60
|
}
|
|
36
61
|
|
|
37
62
|
export const DOCUMENT_VOICE_CATALOG_SCHEMA = {
|
|
@@ -42,3 +67,18 @@ export const DOCUMENT_VOICE_CATALOG_SCHEMA = {
|
|
|
42
67
|
lang: { type: 'string', minLength: 1, maxLength: 100 },
|
|
43
68
|
},
|
|
44
69
|
} as const
|
|
70
|
+
|
|
71
|
+
const cloneText = { type: 'string', minLength: 1, maxLength: 200 } as const
|
|
72
|
+
const cloneAudio: Schema = { oneOf: [{ type: 'string', minLength: 1, maxLength: 1024 }, { type: 'object', additionalProperties: false, properties: { upload: MEDIA_LOCATION_PROPERTIES.upload }, required: ['upload'] }] }
|
|
73
|
+
export const DOCUMENT_VOICE_CLONE_QUERY_SCHEMA: Schema = {
|
|
74
|
+
type: 'object', additionalProperties: false, properties: { engine: cloneText, voice: cloneText }, required: ['voice'],
|
|
75
|
+
}
|
|
76
|
+
export const DOCUMENT_VOICE_CLONE_SCHEMA: Schema = {
|
|
77
|
+
type: 'object', additionalProperties: false,
|
|
78
|
+
properties: {
|
|
79
|
+
source: structuredClone(DOCUMENT_VOICE_CATALOG_SCHEMA.properties.source) as unknown as Schema, engine: cloneText, voice: cloneText,
|
|
80
|
+
sample: cloneAudio,
|
|
81
|
+
consent: { type: 'object', additionalProperties: false, properties: { speaker: cloneText, scope: { type: 'string', minLength: 1, maxLength: 2000 }, statement: cloneAudio }, required: ['speaker', 'scope', 'statement'] },
|
|
82
|
+
lang: { type: 'string', minLength: 1, maxLength: 100 }, text: { type: 'string', maxLength: 4000 },
|
|
83
|
+
}, required: ['voice', 'sample', 'consent'],
|
|
84
|
+
}
|
|
@@ -163,6 +163,8 @@ export interface StepProduction {
|
|
|
163
163
|
narrationStart?: 'with-animation' | 'after-animation'
|
|
164
164
|
minimumHoldMs?: number
|
|
165
165
|
trailingPauseMs?: number
|
|
166
|
+
/** Show captions without changing the narration, voiceover or timing; inherited, default true. */
|
|
167
|
+
captionVisible?: boolean
|
|
166
168
|
voiceSource?: VoiceSource
|
|
167
169
|
}
|
|
168
170
|
export interface ProductionDefaults extends StepProduction {}
|
|
@@ -194,11 +196,24 @@ export interface Production {
|
|
|
194
196
|
cueTimings?: Record<string, { pauseMs: number }>
|
|
195
197
|
/** Stale mappings remain inspectable but never retime audio or replace changed narration. */
|
|
196
198
|
captionTimings?: Record<StepId, CaptionTiming>
|
|
199
|
+
/** How large the captions are, in the presentation and burned into a lecture video; absent is the default size. */
|
|
200
|
+
captions?: CaptionStyle
|
|
197
201
|
mediaClips: MediaClip[]
|
|
198
202
|
}
|
|
203
|
+
/** `scale` multiplies the captions' default size, from `CAPTION_SCALE_MIN` to `CAPTION_SCALE_MAX` (Studio offers tenths). */
|
|
204
|
+
export interface CaptionStyle { scale: number }
|
|
205
|
+
export const CAPTION_SCALE_MIN = 0.7
|
|
206
|
+
export const CAPTION_SCALE_MAX = 1.6
|
|
199
207
|
|
|
200
208
|
/** A stable rich-text/code ID, or `page:${sectionId}` reserved for an existing section title. */
|
|
201
209
|
export interface DocumentTextPoint { blockId: string, offset: number }
|
|
210
|
+
export interface DocumentTextAnchor { from: DocumentTextPoint, to: DocumentTextPoint }
|
|
211
|
+
/** A stable block, optionally at one step that renders it; the step belongs to the block's section. */
|
|
212
|
+
export interface DocumentPlaceAnchor { blockId: BlockId, stepId?: StepId }
|
|
213
|
+
export type DocumentThreadAnchor = DocumentTextAnchor | DocumentPlaceAnchor
|
|
214
|
+
/** A text range and a place are disjoint shapes; read the shape instead of guessing from offsets. */
|
|
215
|
+
export const isDocumentTextAnchor = (anchor: DocumentThreadAnchor | undefined): anchor is DocumentTextAnchor => Boolean(anchor && 'from' in anchor && 'to' in anchor)
|
|
216
|
+
export const isDocumentPlaceAnchor = (anchor: DocumentThreadAnchor | undefined): anchor is DocumentPlaceAnchor => Boolean(anchor && 'blockId' in anchor && !('from' in anchor))
|
|
202
217
|
export interface DocumentComment {
|
|
203
218
|
id: string
|
|
204
219
|
type: 'comment'
|
|
@@ -220,7 +235,7 @@ export interface DocumentThread {
|
|
|
220
235
|
resolvedBy?: string
|
|
221
236
|
metadata?: JsonObject
|
|
222
237
|
deletedAt?: string
|
|
223
|
-
anchor?:
|
|
238
|
+
anchor?: DocumentThreadAnchor
|
|
224
239
|
comments: DocumentComment[]
|
|
225
240
|
}
|
|
226
241
|
|
|
@@ -236,5 +251,7 @@ export type DocumentEditOperation =
|
|
|
236
251
|
| { type: 'updateSection', sectionId: SectionId, title?: string, layout?: Layout }
|
|
237
252
|
| { type: 'setStepState', stepId: StepId, visuals: VisualState[], inherits?: StepId }
|
|
238
253
|
| { type: 'setNarration', narration: Narration, stepId?: StepId, index?: number }
|
|
254
|
+
| { type: 'removeNarration', stepId: StepId, narrationId: NarrationId }
|
|
255
|
+
| { type: 'setStepNarrations', stepId: StepId, narrationIds: NarrationId[] }
|
|
239
256
|
| { type: 'setTiming', stepId?: StepId, sectionId?: SectionId, value: StepProduction }
|
|
240
257
|
| { type: 'replaceAsset', asset: Asset }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Member } from './server.ts'
|
|
2
|
+
|
|
3
|
+
export const MEDIA_UPLOAD_PATH = '/__presmium/presmium.media-upload'
|
|
4
|
+
export const MEDIA_UPLOAD_KINDS = ['image', 'audio'] as const
|
|
5
|
+
export type MediaUploadKind = typeof MEDIA_UPLOAD_KINDS[number]
|
|
6
|
+
export interface MediaUpload {
|
|
7
|
+
upload: string
|
|
8
|
+
kind: MediaUploadKind
|
|
9
|
+
url: string
|
|
10
|
+
expiresAt: string
|
|
11
|
+
maxBytes: number
|
|
12
|
+
state: 'empty' | 'uploading' | 'ready'
|
|
13
|
+
name?: string
|
|
14
|
+
byteLength?: number
|
|
15
|
+
}
|
|
16
|
+
/** Temporary input only; canonical imports retain their existing authoring permission and transaction. */
|
|
17
|
+
export interface DocumentMediaUploads {
|
|
18
|
+
prepare(document: string, kind: MediaUploadKind, member: Member): Promise<MediaUpload>
|
|
19
|
+
status(document: string, upload: string, member: Member): Promise<MediaUpload>
|
|
20
|
+
}
|
|
21
|
+
export type DocumentMediaLocation = { path: string, upload?: never } | { upload: string, path?: never }
|
|
22
|
+
export type DocumentMediaFile = ({ path: string, upload?: never, name?: never } | { upload: string, name: string, path?: never }) & { sha256: string, byteLength: number }
|
|
23
|
+
export const MEDIA_LOCATION_PROPERTIES = { path: { type: 'string', minLength: 1, maxLength: 1024, description: 'Workspace-relative path to a regular file within the selected document, including its directory prefix; for document papers/re-search, use papers/re-search/figures/result.png. Workspace cache files outside that document are unavailable; stage the file inside the document or use a ready upload reference.' }, upload: { type: 'string', pattern: '^[a-f0-9]{64}$' } } as const
|
|
24
|
+
export const MEDIA_LOCATION_CHOICES = [{ required: ['path'], not: { required: ['upload'] } }, { required: ['upload'], not: { required: ['path'] } }] as const
|
|
25
|
+
export const mediaFileSchema = (maxBytes: number) => ({ type: 'object', additionalProperties: false,
|
|
26
|
+
properties: { ...MEDIA_LOCATION_PROPERTIES, name: { type: 'string', minLength: 1, maxLength: 200 }, sha256: { type: 'string', pattern: '^[a-f\\d]{64}$' }, byteLength: { type: 'integer', minimum: 1, maximum: maxBytes } },
|
|
27
|
+
required: ['sha256', 'byteLength'], oneOf: [{ required: ['path'], not: { anyOf: [{ required: ['upload'] }, { required: ['name'] }] } }, { required: ['upload', 'name'], not: { required: ['path'] } }],
|
|
28
|
+
} as const)
|
package/src/contracts/plugin.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CanonicalSource,
|
|
1
|
+
import type { CanonicalSource, IRDocument, IRPass, Renderer, RendererContribution } from '../ir.ts'
|
|
2
2
|
import type { AgentTool } from './agent.ts'
|
|
3
3
|
import type { AnchorResolver, AnchorString } from './anchors.ts'
|
|
4
4
|
import type { Check, CheckContext } from './checks.ts'
|
|
@@ -159,7 +159,6 @@ export interface PresmiumNodePlugin {
|
|
|
159
159
|
resolvers?: AnchorResolver[]
|
|
160
160
|
checks?: Check[]
|
|
161
161
|
anchors?(ctx: CheckContext): AnchorString[] | Promise<AnchorString[]>
|
|
162
|
-
directives?: DirectiveSpec[]
|
|
163
162
|
passes?: IRPass[]
|
|
164
163
|
executors?: Executor[]
|
|
165
164
|
renderer?: Renderer
|
|
@@ -177,7 +176,6 @@ export interface PresmiumNodePlugin {
|
|
|
177
176
|
services?(ctx: NodeServiceContext): [ServiceToken<unknown>, unknown][]
|
|
178
177
|
environments?: Record<string, EnvironmentProvider>
|
|
179
178
|
server?(ctx: ServerContext): ServerContribution | Promise<ServerContribution>
|
|
180
|
-
roles?: RoleSpec[]
|
|
181
179
|
tools?: AgentTool[]
|
|
182
180
|
operator?: boolean
|
|
183
181
|
}
|
package/src/contracts/preview.ts
CHANGED
|
@@ -10,6 +10,9 @@ export const PREVIEW_PARAM = 'presmium-preview'
|
|
|
10
10
|
/** The workbench's appearance when it loads a preview (`dark` or `light`), so that the page's first paint matches it. */
|
|
11
11
|
export const PREVIEW_APPEARANCE_PARAM = 'presmium-appearance'
|
|
12
12
|
|
|
13
|
+
/** `?captions=off` starts a presentation with its captions off (a reader turns them on again with the captions button). */
|
|
14
|
+
export const CAPTIONS_PARAM = 'captions'
|
|
15
|
+
|
|
13
16
|
export const PREVIEW_REVISION = 'presmiumRevision'
|
|
14
17
|
|
|
15
18
|
export const AUTHOR_MARKS_CLASS = 'pm-author-marks'
|
|
@@ -201,8 +204,6 @@ export type PreviewReport =
|
|
|
201
204
|
| { type: 'selection', selection: (PreviewAnchor & { text: string, rect?: PreviewRect, obstacles?: PreviewRect[] }) | null }
|
|
202
205
|
/** Where the picked block or the selection is after the page scrolled or resized; null when it is out of sight. */
|
|
203
206
|
| { type: 'rect', rect: PreviewRect | null, obstacles?: PreviewRect[] }
|
|
204
|
-
/** Where the blocks the AI changed are in the preview's viewport while they blink, and again as the page scrolls (at most 16). */
|
|
205
|
-
| { type: 'flashed', rects: PreviewRect[] }
|
|
206
207
|
| { type: 'editing', target: PreviewAnchor, active: boolean }
|
|
207
208
|
/** The text of a block edited in place, before and after (its `textContent`); sent only when it changed. */
|
|
208
209
|
| { type: 'edited', target: PreviewAnchor, before: string, after: string, request?: number, revision?: string, binding?: string }
|
|
@@ -371,7 +372,6 @@ export function toPreviewReport(data: unknown, nonce: string): PreviewReport | u
|
|
|
371
372
|
? { type: 'selection', selection: { ...toAnchor(selected), text: selected.text, ...selected.rect ? { rect: toRect(selected.rect as PreviewRect) } : {}, ...selected.obstacles !== undefined ? { obstacles: (selected.obstacles as PreviewRect[]).map(toRect) } : {} } }
|
|
372
373
|
: undefined
|
|
373
374
|
}
|
|
374
|
-
case 'flashed': return Array.isArray(m.rects) && m.rects.length <= 16 && m.rects.every(rect) ? { type: 'flashed', rects: (m.rects as PreviewRect[]).map(toRect) } : undefined
|
|
375
375
|
case 'rect': return (m.rect === null || rect(m.rect)) && optional(m.obstacles, obstacles) ? { type: 'rect', rect: m.rect === null ? null : toRect(m.rect), ...m.obstacles !== undefined ? { obstacles: (m.obstacles as PreviewRect[]).map(toRect) } : {} } : undefined
|
|
376
376
|
case 'editing': return anchor(m.target) && typeof m.active === 'boolean' ? { type: 'editing', target: toAnchor(m.target), active: m.active } : undefined
|
|
377
377
|
case 'edited': return anchor(m.target) && text(m.before) && text(m.after) && m.before.length <= MAX_EDITED && m.after.length <= MAX_EDITED && editedRequest(m) ? { type: 'edited', target: toAnchor(m.target), before: m.before, after: m.after, ...m.request === undefined ? {} : { request: m.request as number, revision: m.revision as string, binding: m.binding as string } } : undefined
|
|
@@ -10,6 +10,8 @@ export type ProjectOperation = DocumentOperation | { op: 'retitle', dir: string,
|
|
|
10
10
|
export interface ProjectCaller { member: Member, origin: 'editor' | 'agent', boundDocument?: string }
|
|
11
11
|
export interface ProjectObservation { snapshot?: string, configuration: string }
|
|
12
12
|
export interface ProjectCapabilities {
|
|
13
|
+
templates?: string[]
|
|
14
|
+
nextTemplatesOffset?: number
|
|
13
15
|
available: boolean
|
|
14
16
|
actions: Record<ProjectOperation['op'], { available: boolean, reasons: string[] }>
|
|
15
17
|
reasons: string[]
|
|
@@ -45,7 +47,7 @@ export interface ProjectApplied extends OperationAnswer {
|
|
|
45
47
|
}
|
|
46
48
|
/** Directory management borrows the Web writer; metadata retitle borrows canonical document CAS. */
|
|
47
49
|
export interface ProjectAuthoring {
|
|
48
|
-
capabilities(caller: ProjectCaller): Promise<ProjectCapabilities>
|
|
50
|
+
capabilities(caller: ProjectCaller, query?: { templatesOffset?: number }): Promise<ProjectCapabilities>
|
|
49
51
|
plan(request: ProjectPlanRequest, caller: ProjectCaller): Promise<ProjectPlan>
|
|
50
52
|
readPlan(request: ProjectApply, caller: ProjectCaller): Promise<ProjectPlan>
|
|
51
53
|
apply(request: ProjectApply, caller: ProjectCaller, signal?: AbortSignal): Promise<ProjectApplied>
|
|
@@ -57,3 +59,4 @@ export const PROJECT_PLAN_SCHEMA = { type: 'object', additionalProperties: false
|
|
|
57
59
|
id: text, operation: { oneOf: [operation('create', { title: text, template: text }, []), operation('copy', { to: text, title: text }, ['to']), operation('rename', { to: text }, ['to']), operation('delete', {}, []), operation('retitle', { title: text }, ['title'])] },
|
|
58
60
|
} } as const
|
|
59
61
|
export const PROJECT_APPLY_SCHEMA = { type: 'object', additionalProperties: false, required: ['planId', 'digest'], properties: { planId: text, digest: { type: 'string', pattern: '^[a-f0-9]{64}$' }, confirmDeletion: { const: true } } } as const
|
|
62
|
+
export const PROJECT_CAPABILITIES_SCHEMA = { type: 'object', additionalProperties: false, properties: { templatesOffset: { type: 'integer', minimum: 0 } } } as const
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Schema } from '@cfworker/json-schema'
|
|
2
|
+
|
|
1
3
|
/** Operator configuration is separate from document voice choices. Secret values are write-only. */
|
|
2
4
|
export interface SpeechSettingsAnswer {
|
|
3
5
|
provider: 'volcengine'
|
|
@@ -14,3 +16,14 @@ export interface SpeechSettingsAnswer {
|
|
|
14
16
|
export type SpeechSettingsChange =
|
|
15
17
|
| { action: 'save', revision: string, apiKey?: string, appId?: string }
|
|
16
18
|
| { action: 'clear', revision: string }
|
|
19
|
+
|
|
20
|
+
export interface SpeechSettings {
|
|
21
|
+
read(): SpeechSettingsAnswer
|
|
22
|
+
change(change: SpeechSettingsChange): Promise<SpeechSettingsAnswer>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const SPEECH_SETTINGS_CHANGE_SCHEMA: Schema = {
|
|
26
|
+
type: 'object', additionalProperties: false,
|
|
27
|
+
properties: { action: { enum: ['save', 'clear'] }, revision: { type: 'string', maxLength: 200 }, apiKey: { type: 'string', maxLength: 8192 }, appId: { type: 'string', maxLength: 32 } },
|
|
28
|
+
required: ['action', 'revision'],
|
|
29
|
+
}
|
package/src/contracts/speech.ts
CHANGED
|
@@ -103,6 +103,15 @@ export interface VoiceCloneStatus {
|
|
|
103
103
|
message?: string
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
export interface SpeechCachePrune {
|
|
107
|
+
/** Entries some request uses. */
|
|
108
|
+
kept: number
|
|
109
|
+
/** Entries no request uses, with the bytes of their files. */
|
|
110
|
+
unused: { key: string, bytes: number }[]
|
|
111
|
+
/** Whether the unused entries were deleted. */
|
|
112
|
+
removed: boolean
|
|
113
|
+
}
|
|
114
|
+
|
|
106
115
|
export interface TranscriptionRequest {
|
|
107
116
|
engine?: string
|
|
108
117
|
audio: Blob
|
|
@@ -124,6 +133,13 @@ export interface SpeechService {
|
|
|
124
133
|
cached?(key: string, signal?: AbortSignal): Promise<Synthesis | undefined>
|
|
125
134
|
alignWords?(key: string, options: { lang: string, transcribe?: boolean }, signal?: AbortSignal): Promise<SpeechWord[] | undefined>
|
|
126
135
|
pruneLock?(keep: ReadonlySet<string>): Promise<number>
|
|
136
|
+
/**
|
|
137
|
+
* The document's cached audio that no request of `keep` (every sentence the document says) uses: kept is any entry
|
|
138
|
+
* made for the same request under any configuration of the voice service. With `remove`, deletes the unused entries
|
|
139
|
+
* with their alignments and speech lock entries. Throws `speech-prune-engine-unknown` when a request names no engine
|
|
140
|
+
* and no default engine is configured, since its entries cannot be told apart then.
|
|
141
|
+
*/
|
|
142
|
+
pruneCache?(keep: readonly SynthesisRequest[], options?: { remove?: boolean, signal?: AbortSignal }): Promise<SpeechCachePrune>
|
|
127
143
|
transcribe(request: TranscriptionRequest, signal?: AbortSignal): Promise<Transcript>
|
|
128
144
|
/** Registers the consent, then starts training; only for the document's owner. Absent: the service cannot clone. */
|
|
129
145
|
cloneVoice?(request: VoiceCloneRequest, signal?: AbortSignal): Promise<VoiceCloneStatus>
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import type { CanonicalSource } from '../ir.ts'
|
|
2
2
|
import type { Member } from './server.ts'
|
|
3
|
-
import type {
|
|
3
|
+
import type { SpeechVoice, SynthesisRequest } from './speech.ts'
|
|
4
|
+
import type { VoiceoverCancellation, VoiceoverJob, VoiceoverRequest, VoiceoverSnapshot, VoicePreviewAnswer, VoicePreviewQuery, VoicePreviewQuote, VoicePreviewRequest, VoiceTarget } from './voice.ts'
|
|
4
5
|
import { defineService } from './service.ts'
|
|
5
6
|
|
|
6
7
|
export interface VoiceoverStatusQuery { source?: CanonicalSource, revision?: string }
|
|
8
|
+
export interface VoiceoverSentencesQuery extends VoiceoverStatusQuery {
|
|
9
|
+
/** Answer as if this were the document's default voice: sentences that inherit the default, or have no voice, use it. */
|
|
10
|
+
defaultVoice?: SpeechVoice
|
|
11
|
+
}
|
|
12
|
+
/** One sentence that a document-scope generation processes, in reading order. */
|
|
13
|
+
export interface VoiceoverSentence {
|
|
14
|
+
section: string
|
|
15
|
+
step: number
|
|
16
|
+
stepId?: string
|
|
17
|
+
/** The step binding for a `steps` scope; absent when the sentence cannot be generated by step (it crosses steps). */
|
|
18
|
+
target?: VoiceTarget
|
|
19
|
+
/** The spoken text, which the voice service receives (and a cloud provider charges for). */
|
|
20
|
+
text: string
|
|
21
|
+
/** The exact synthesis request; absent when the sentence has no usable voice. */
|
|
22
|
+
request?: SynthesisRequest
|
|
23
|
+
/** Exact audio for the request is in the speech cache. */
|
|
24
|
+
cached: boolean
|
|
25
|
+
/** Why it cannot be generated now: no voice, or the voice service or voice is unavailable. */
|
|
26
|
+
reason?: string
|
|
27
|
+
}
|
|
28
|
+
export interface VoiceoverSentences { source: CanonicalSource, revision: string, sentences: VoiceoverSentence[] }
|
|
7
29
|
export type VoiceoverStart = Omit<VoiceoverRequest, 'confirmed'>
|
|
8
30
|
export type VoicePreviewStart = Omit<VoicePreviewRequest, 'confirmed'>
|
|
9
31
|
export type VoicePreviewCheck = VoicePreviewQuery & { source?: CanonicalSource }
|
|
@@ -23,6 +45,8 @@ export interface VoicePreviewMedia extends Omit<VoicePreviewAnswer, 'audio'> { b
|
|
|
23
45
|
/** Stateless plugin execution. The host owns intents and jobs; discovery creates neither. */
|
|
24
46
|
export interface VoiceoverExecution {
|
|
25
47
|
status(query: VoiceoverStatusQuery, signal: AbortSignal): Promise<Omit<VoiceoverSnapshot, 'jobs'>>
|
|
48
|
+
/** Every sentence with its request and cache state; reads the cache and the voice catalog, never generates. */
|
|
49
|
+
sentences?(query: VoiceoverSentencesQuery, signal: AbortSignal): Promise<VoiceoverSentences>
|
|
26
50
|
prepare(request: VoiceoverStart, signal: AbortSignal): Promise<PreparedVoiceover>
|
|
27
51
|
quote(query: VoicePreviewCheck, signal: AbortSignal): Promise<VoicePreviewQuote>
|
|
28
52
|
preview(request: VoicePreviewStart, signal: AbortSignal): Promise<VoicePreviewMedia>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Member } from './server.ts'
|
|
2
|
+
import type { Revision, UncommittedFile } from './workspace.ts'
|
|
3
|
+
export const CHANGES_MAX_REQUEST_CHARS = 1 << 20
|
|
4
|
+
export const CHANGES_MAX_RESPONSE_CHARS = 7168
|
|
5
|
+
export const CHANGES_MAX_FILES = 16_384
|
|
6
|
+
export const CHANGES_MAX_BYTES = 512 << 20
|
|
7
|
+
export interface ChangesCaller { member: Member, origin: 'editor' | 'agent', boundDocument?: string, confirmed?: boolean }
|
|
8
|
+
export interface ChangesQuery { document?: string, offset?: number, snapshot?: string }
|
|
9
|
+
export interface WorkspaceChangesAnswer { available: boolean, files: (UncommittedFile & { unsupported?: true })[], snapshot?: string, nextOffset?: number }
|
|
10
|
+
export type WorkspaceChangesRequest = { document?: string, paths?: string[], snapshot?: string } & (
|
|
11
|
+
| { action: 'commit', message: string }
|
|
12
|
+
| { action: 'discard', confirm: true }
|
|
13
|
+
)
|
|
14
|
+
export interface WorkspaceChangesResult { action: 'commit' | 'discard', files: number, refreshed?: false, revision?: Revision, committed?: boolean }
|
|
15
|
+
export interface PreparedWorkspaceChanges { readonly paths: readonly string[], change(signal?: AbortSignal): Promise<WorkspaceChangesResult> }
|
|
16
|
+
export interface WorkspaceChanges {
|
|
17
|
+
list(query: ChangesQuery, caller: ChangesCaller): Promise<WorkspaceChangesAnswer>
|
|
18
|
+
prepare(request: WorkspaceChangesRequest, caller: ChangesCaller): Promise<PreparedWorkspaceChanges>
|
|
19
|
+
}
|
|
20
|
+
const document = { type: 'string', maxLength: 500 } as const
|
|
21
|
+
const snapshot = { type: 'string', pattern: '^[a-f0-9]{64}$' } as const
|
|
22
|
+
const paths = { type: 'array', minItems: 1, maxItems: CHANGES_MAX_FILES, uniqueItems: true, items: { type: 'string', minLength: 1, maxLength: 500 } } as const
|
|
23
|
+
export const CHANGES_QUERY_SCHEMA = { type: 'object', additionalProperties: false, properties: { document, snapshot, offset: { type: 'integer', minimum: 0 } } } as const
|
|
24
|
+
export const CHANGES_REQUEST_SCHEMA = { oneOf: [
|
|
25
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'message'], properties: { document, paths, snapshot, action: { const: 'commit' }, message: { type: 'string', minLength: 1, maxLength: 4000 } } },
|
|
26
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'confirm'], properties: { document, paths, snapshot, action: { const: 'discard' }, confirm: { const: true } } },
|
|
27
|
+
] } as const
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Member } from './server.ts'
|
|
2
|
+
import type { ReviewChange, ReviewStep } from './workspace.ts'
|
|
3
|
+
|
|
4
|
+
export const WORKSPACE_REVIEW_MAX_REQUEST_CHARS = 8192
|
|
5
|
+
export const WORKSPACE_REVIEW_MAX_RESPONSE_CHARS = 7168
|
|
6
|
+
export const WORKSPACE_REVIEW_FRAGMENT_CHARS = 4000
|
|
7
|
+
export interface WorkspaceReviewQuery { part?: 'summary' | 'files' | 'steps' | 'diff', path?: string, step?: string, offset?: number, snapshot?: string }
|
|
8
|
+
export interface WorkspaceReviewSummary { id: string, document: string, running: boolean, mode: 'required' | 'auto', files: number, steps: number }
|
|
9
|
+
export interface WorkspaceReviewAnswer {
|
|
10
|
+
review: WorkspaceReviewSummary | null
|
|
11
|
+
snapshot?: string
|
|
12
|
+
files?: Omit<ReviewChange, 'diff'>[]
|
|
13
|
+
steps?: (Omit<ReviewStep, 'changes'> & { files: number })[]
|
|
14
|
+
nextOffset?: number
|
|
15
|
+
diff?: { path: string, step?: string, text: string, offset: number, totalChars: number, sha256: string }
|
|
16
|
+
}
|
|
17
|
+
export type WorkspaceReviewChange =
|
|
18
|
+
| { action: 'accept', snapshot: string, reject?: string[], message?: string }
|
|
19
|
+
| { action: 'reject', snapshot: string, paths?: string[], confirm: true }
|
|
20
|
+
| { action: 'restore', snapshot: string, step: string, confirm: true }
|
|
21
|
+
export interface WorkspaceReviewChanged { outcome: 'accepted' | 'rejected' | 'restored' | 'updated' | 'empty', revision?: string, files?: number, remainingFiles?: number }
|
|
22
|
+
/** Workspace publication authority; document-scoped agent credentials must never receive this service. */
|
|
23
|
+
export interface WorkspaceReview {
|
|
24
|
+
read(query: WorkspaceReviewQuery, member: Member): Promise<WorkspaceReviewAnswer>
|
|
25
|
+
check(change: WorkspaceReviewChange, member: Member): Promise<void>
|
|
26
|
+
change(change: WorkspaceReviewChange, member: Member, signal?: AbortSignal): Promise<WorkspaceReviewChanged>
|
|
27
|
+
}
|
|
28
|
+
const path = { type: 'string', minLength: 1, maxLength: 500 } as const
|
|
29
|
+
const snapshot = { type: 'string', pattern: '^[a-f0-9]{64}$' } as const
|
|
30
|
+
const step = { type: 'string', minLength: 1, maxLength: 100 } as const
|
|
31
|
+
const paths = { type: 'array', minItems: 1, maxItems: 200, uniqueItems: true, items: path } as const
|
|
32
|
+
export const WORKSPACE_REVIEW_QUERY_SCHEMA = { type: 'object', additionalProperties: false, properties: {
|
|
33
|
+
part: { enum: ['summary', 'files', 'steps', 'diff'] }, path, step, offset: { type: 'integer', minimum: 0 }, snapshot,
|
|
34
|
+
} } as const
|
|
35
|
+
export const WORKSPACE_REVIEW_CHANGE_SCHEMA = { oneOf: [
|
|
36
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'snapshot'], properties: { action: { const: 'accept' }, snapshot, reject: paths, message: { type: 'string', minLength: 1, maxLength: 4000 } } },
|
|
37
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'snapshot', 'confirm'], properties: { action: { const: 'reject' }, snapshot, paths, confirm: { const: true } } },
|
|
38
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'snapshot', 'step', 'confirm'], properties: { action: { const: 'restore' }, snapshot, step, confirm: { const: true } } },
|
|
39
|
+
] } as const
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Member } from './server.ts'
|
|
2
|
+
import type { SourceFile } from './workspace.ts'
|
|
3
|
+
|
|
4
|
+
export const SOURCE_MAX_BYTES = 2 << 20
|
|
5
|
+
export const SOURCE_MAX_FILES = 16
|
|
6
|
+
export const SOURCE_MAX_REQUEST_CHARS = SOURCE_MAX_BYTES * 3 + 8192
|
|
7
|
+
export const SOURCE_MAX_RESPONSE_CHARS = 7168
|
|
8
|
+
export const SOURCE_FRAGMENT_CHARS = 4000
|
|
9
|
+
/** Supplied by an adapter, never accepted as model arguments. */
|
|
10
|
+
export interface SourceCaller { member: Member, boundDocument?: string, confirmed?: boolean, origin: 'editor' | 'agent' }
|
|
11
|
+
export interface SourceListQuery { document?: string, query?: string, offset?: number, snapshot?: string }
|
|
12
|
+
export interface SourceListAnswer { files: SourceFile[], snapshot: string, nextOffset?: number, truncated?: true }
|
|
13
|
+
export interface SourceReadQuery { document?: string, path: string, offset?: number, version?: string }
|
|
14
|
+
export interface SourceReadAnswer { path: string, version: string, text: string, offset: number, totalChars: number, nextOffset?: number }
|
|
15
|
+
export type SourceEditFile = { path: string, version?: string } & ({ content: string, create?: true } | { find: string, replace: string })
|
|
16
|
+
export type SourceEdit = ({ document?: string } & SourceEditFile) | { document?: string, edits: SourceEditFile[] }
|
|
17
|
+
export interface SourceSaved { saved: true, changed: boolean, path?: string, files?: number, revision?: string, current?: false }
|
|
18
|
+
export interface PreparedSourceEdit { change(signal?: AbortSignal): Promise<SourceSaved> }
|
|
19
|
+
/** Current source editor scope and transaction owner; invalid IR is readable and repairable. */
|
|
20
|
+
export interface WorkspaceSource {
|
|
21
|
+
list(query: SourceListQuery, caller: SourceCaller): Promise<SourceListAnswer>
|
|
22
|
+
read(query: SourceReadQuery, caller: SourceCaller): Promise<SourceReadAnswer>
|
|
23
|
+
prepare(edit: SourceEdit, caller: SourceCaller): Promise<PreparedSourceEdit>
|
|
24
|
+
}
|
|
25
|
+
const document = { type: 'string', maxLength: 500 } as const
|
|
26
|
+
const path = { type: 'string', minLength: 1, maxLength: 500 } as const
|
|
27
|
+
const version = { type: 'string', pattern: '^[a-f0-9]{20}$' } as const
|
|
28
|
+
const offset = { type: 'integer', minimum: 0 } as const
|
|
29
|
+
export const SOURCE_LIST_SCHEMA = { type: 'object', additionalProperties: false, properties: { document, query: { type: 'string', maxLength: 200 }, offset, snapshot: { type: 'string', pattern: '^[a-f0-9]{64}$' } } } as const
|
|
30
|
+
export const SOURCE_READ_SCHEMA = { type: 'object', additionalProperties: false, required: ['path'], properties: { document, path, offset, version } } as const
|
|
31
|
+
const fileSchema = { oneOf: [
|
|
32
|
+
{ type: 'object', additionalProperties: false, required: ['path', 'content'], properties: { path, version, content: { type: 'string', maxLength: SOURCE_MAX_BYTES }, create: { const: true } } },
|
|
33
|
+
{ type: 'object', additionalProperties: false, required: ['path', 'find', 'replace'], properties: { path, version, find: { type: 'string', minLength: 1, maxLength: SOURCE_MAX_BYTES }, replace: { type: 'string', maxLength: SOURCE_MAX_BYTES } } },
|
|
34
|
+
] } as const
|
|
35
|
+
export const SOURCE_EDIT_SCHEMA = { oneOf: [
|
|
36
|
+
...fileSchema.oneOf.map(schema => ({ ...schema, properties: { document, ...schema.properties } })),
|
|
37
|
+
{ type: 'object', additionalProperties: false, required: ['edits'], properties: { document, edits: { type: 'array', minItems: 1, maxItems: SOURCE_MAX_FILES, items: fileSchema } } },
|
|
38
|
+
] } as const
|
|
@@ -94,6 +94,8 @@ export interface DocumentSummary {
|
|
|
94
94
|
description?: string
|
|
95
95
|
lang?: string
|
|
96
96
|
tags?: string[]
|
|
97
|
+
/** Whether its metadata asks for a presentation (`renderers.slides`), which a site serves below its pages. */
|
|
98
|
+
slides?: boolean
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
/** @experimental The workspace service's answer to `documents`. */
|
|
@@ -237,6 +239,7 @@ export interface PageDeleteAnswer { document: string, selected: string, retained
|
|
|
237
239
|
|
|
238
240
|
/** @experimental One version-checked file in an authoring transaction; null creates a new file exclusively. */
|
|
239
241
|
export interface SourceTransactionChange {
|
|
242
|
+
/** Workspace-relative, including the selected document directory for document-scoped changes. */
|
|
240
243
|
path: string
|
|
241
244
|
content: string
|
|
242
245
|
base: string | null
|
package/src/contracts.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './contracts/agent.ts'
|
|
2
|
+
export * from './contracts/agent-activity.ts'
|
|
2
3
|
export * from './contracts/authoring.ts'
|
|
4
|
+
export * from './contracts/capture.ts'
|
|
3
5
|
export * from './contracts/document-reads.ts'
|
|
4
6
|
export * from './contracts/anchors.ts'
|
|
5
7
|
export * from './contracts/checks.ts'
|
|
@@ -22,6 +24,9 @@ export * from './contracts/server.ts'
|
|
|
22
24
|
export * from './contracts/service.ts'
|
|
23
25
|
export * from './contracts/speech.ts'
|
|
24
26
|
export * from './contracts/speech-settings.ts'
|
|
27
|
+
export * from './contracts/workspace-review.ts'
|
|
28
|
+
export * from './contracts/workspace-source.ts'
|
|
29
|
+
export * from './contracts/workspace-changes.ts'
|
|
25
30
|
export * from './contracts/transcription.ts'
|
|
26
31
|
export * from './contracts/transcription-adoption.ts'
|
|
27
32
|
export * from './contracts/voice.ts'
|
|
@@ -31,5 +36,7 @@ export * from './contracts/document-comments.ts'
|
|
|
31
36
|
export * from './contracts/authoring-actions.ts'
|
|
32
37
|
export * from './contracts/document-history.ts'
|
|
33
38
|
export * from './contracts/authoring-clients.ts'
|
|
39
|
+
export * from './contracts/authoring-windows.ts'
|
|
34
40
|
export * from './contracts/projects.ts'
|
|
35
41
|
export * from './contracts/document-image.ts'
|
|
42
|
+
export * from './contracts/media-uploads.ts'
|
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
import { applyDocumentCaptionTiming } from './document-caption-timings.ts'
|
|
2
|
+
import { captionScale, changeDocumentCaptionScale } from './document-caption-scale.ts'
|
|
2
3
|
import { hasRole } from './access.ts'
|
|
3
|
-
import { applyDocumentCommentAction, DocumentCommentError, validateDocumentCommentAnchor } from './document-comments.ts'
|
|
4
|
+
import { applyDocumentCommentAction, degradeDocumentCommentAnchor, DocumentCommentError, validateDocumentCommentAnchor } from './document-comments.ts'
|
|
5
|
+
import { documentAnchorKey } from './document-places.ts'
|
|
4
6
|
import { changeDocumentVoice, documentVoiceStepIds, previewDocumentVoiceChange } from './document-voices.ts'
|
|
5
7
|
import { applyDocumentComponentAction } from './document-components.ts'
|
|
6
8
|
import type { DocumentAuthoringAction, DocumentAuthoringActionEffect } from './contracts/authoring-actions.ts'
|
|
7
9
|
import type { DocumentCommentContext } from './contracts/document-comments.ts'
|
|
8
10
|
import type { TeachingDocument } from './contracts/document.ts'
|
|
9
11
|
|
|
12
|
+
export function enableDocumentProduction(document: TeachingDocument): TeachingDocument {
|
|
13
|
+
const plugins = [...new Set([...(document.metadata.plugins ?? []), '@lincyaw/addon-lecture', '@lincyaw/addon-speech'])]
|
|
14
|
+
if (JSON.stringify(plugins) === JSON.stringify(document.metadata.plugins) && document.metadata.renderers?.lecture) return document
|
|
15
|
+
return { ...document, metadata: { ...document.metadata, plugins, renderers: { ...document.metadata.renderers, lecture: document.metadata.renderers?.lecture ?? {} } } }
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
/** Fixed context is supplied by the owning adapter exactly once per semantic plan. */
|
|
11
19
|
export function applyDocumentAuthoringAction(document: TeachingDocument, action: DocumentAuthoringAction, context: DocumentCommentContext): { content: TeachingDocument, effect: DocumentAuthoringActionEffect } {
|
|
12
20
|
if (!context.member || !hasRole(context.member, 'editor')) throw new DocumentCommentError(403, 'authoring-permission-denied')
|
|
21
|
+
if (action.type === 'production.enable') {
|
|
22
|
+
const content = enableDocumentProduction(document)
|
|
23
|
+
return { content, effect: { kind: 'production', value: { enabled: true, changed: content !== document } } }
|
|
24
|
+
}
|
|
25
|
+
if (action.type === 'caption.scale.set') {
|
|
26
|
+
const content = changeDocumentCaptionScale(document, action.scale)
|
|
27
|
+
return { content, effect: { kind: 'caption-scale', value: { scale: captionScale(content.production), changed: content !== document } } }
|
|
28
|
+
}
|
|
13
29
|
if (action.type === 'component.parameters.patch' || action.type === 'component.step-parameters.patch' || action.type === 'component.step-parameters.reset' || action.type === 'component.definition.use') {
|
|
14
30
|
const { content, effect } = applyDocumentComponentAction(document, action)
|
|
15
31
|
return { content, effect: { kind: 'component', value: effect } }
|
|
@@ -29,17 +45,20 @@ export function applyDocumentAuthoringAction(document: TeachingDocument, action:
|
|
|
29
45
|
return { content, effect: { kind: 'voice', scope: action.scope.kind, value: previewDocumentVoiceChange(document, action.scope, action.source, { replaceOverrides: action.replaceOverrides }), recordings } }
|
|
30
46
|
}
|
|
31
47
|
if (action.type === 'comment.create') validateDocumentCommentAnchor(document, action.anchor ?? undefined)
|
|
32
|
-
let source = document.comments ?? {}, detached = false
|
|
48
|
+
let source = document.comments ?? {}, detached = false, degraded = false
|
|
33
49
|
if (action.type !== 'comment.create' && Object.hasOwn(source, action.threadId)) {
|
|
34
50
|
const thread = source[action.threadId]!
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
const anchor = degradeDocumentCommentAnchor(document, thread.anchor)
|
|
52
|
+
if (thread.anchor && !anchor) {
|
|
37
53
|
const { anchor: _anchor, ...unanchored } = thread
|
|
38
54
|
source = { ...source, [thread.id]: unanchored }; detached = true
|
|
55
|
+
} else if (anchor && documentAnchorKey(anchor) !== documentAnchorKey(thread.anchor)) {
|
|
56
|
+
source = { ...source, [thread.id]: { ...thread, anchor } }; degraded = true
|
|
39
57
|
}
|
|
40
58
|
}
|
|
41
59
|
const { threads, effect } = applyDocumentCommentAction(source, action, context)
|
|
42
60
|
if (detached) { effect.anchorDetached = true; effect.changed = true }
|
|
61
|
+
else if (degraded) effect.changed = true
|
|
43
62
|
const content = { ...document }
|
|
44
63
|
if (Object.keys(threads).length) content.comments = threads
|
|
45
64
|
else delete content.comments
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CAPTION_SCALE_MAX, CAPTION_SCALE_MIN } from './contracts/document.ts'
|
|
2
|
+
import type { Production, TeachingDocument } from './contracts/document.ts'
|
|
3
|
+
|
|
4
|
+
/** The caption size a document sets (`production.captions.scale`); 1 when it sets none or one out of range. */
|
|
5
|
+
export function captionScale(production: Pick<Production, 'captions'> | undefined): number {
|
|
6
|
+
const scale = production?.captions?.scale
|
|
7
|
+
return typeof scale === 'number' && scale >= CAPTION_SCALE_MIN && scale <= CAPTION_SCALE_MAX ? scale : 1
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Sets the caption size, kept in range and rounded to a tenth; the default size 1 removes the setting. */
|
|
11
|
+
export function changeDocumentCaptionScale(document: TeachingDocument, scale: number): TeachingDocument {
|
|
12
|
+
if (!Number.isFinite(scale)) throw new Error('document-caption-scale')
|
|
13
|
+
const value = Math.round(Math.min(CAPTION_SCALE_MAX, Math.max(CAPTION_SCALE_MIN, scale)) * 10) / 10
|
|
14
|
+
if (value === captionScale(document.production)) return document
|
|
15
|
+
const { captions: _captions, ...production } = document.production
|
|
16
|
+
return { ...document, production: value === 1 ? production : { ...production, captions: { scale: value } } }
|
|
17
|
+
}
|
|
@@ -18,6 +18,8 @@ export function captionSourceFingerprint(document: TeachingDocument, stepId: str
|
|
|
18
18
|
const step = document.steps[stepId]
|
|
19
19
|
if (!step) throw new DocumentCaptionTimingError(404, 'caption-step-missing')
|
|
20
20
|
const timing = { ...document.production.defaults, ...document.production.sectionOverrides?.[step.sectionId], ...document.production.stepOverrides[stepId] }
|
|
21
|
+
// Visibility changes neither text nor alignment; restoring captions reuses the same reviewed map.
|
|
22
|
+
delete timing.captionVisible
|
|
21
23
|
return fnv1a64(JSON.stringify({ document: document.id, stepId, sectionId: step.sectionId, lang: document.metadata.lang, timing,
|
|
22
24
|
narrations: step.narrationIds.map(id => ({ id, content: document.narrations[id]?.content,
|
|
23
25
|
start: document.production.stepOverrides[stepId]?.narrationStart ?? document.production.narrationOverrides?.[id]?.narrationStart ?? timing.narrationStart })),
|