@lincyaw/workbench 0.2.0-rc.5 → 0.2.0-rc.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -4
- package/src/MediaClipEditor.tsx +1 -1
- package/src/audio-recording.ts +27 -5
- package/src/authoring-client.ts +10 -10
- package/src/authoring-draft-fragment.ts +3 -1
- package/src/body-draft-actions.ts +60 -0
- package/src/component-property-drafts.ts +5 -5
- package/src/components.tsx +10 -28
- package/src/context.tsx +2 -1
- package/src/diagnostics.ts +1 -1
- package/src/document-draft-store.ts +45 -18
- package/src/document-drafts.ts +28 -19
- package/src/document-editing.ts +484 -0
- package/src/document-editor/BlockNoteSurface.tsx +25 -9
- package/src/document-editor/ComponentMaterials.tsx +3 -9
- package/src/document-editor/ComponentPropertiesDialog.tsx +4 -4
- package/src/document-editor/DocumentBlockPreview.tsx +4 -2
- package/src/document-editor/DocumentComments.tsx +58 -9
- package/src/document-editor/DocumentEditor.tsx +44 -7
- package/src/document-editor/DocumentStepNarration.tsx +30 -25
- package/src/document-editor/NarrationEditor.tsx +54 -20
- package/src/document-editor/NewCommentDrafts.tsx +4 -3
- package/src/document-editor/PlaceComment.tsx +150 -0
- package/src/document-editor/comment-drafts.ts +16 -14
- package/src/document-editor/comments.ts +30 -10
- package/src/document-editor/component-label.ts +11 -0
- package/src/document-editor/file-input.ts +2 -2
- package/src/document-editor/focus.ts +0 -2
- package/src/document-editor/insertion-place.ts +60 -0
- package/src/document-editor/messages.ts +3 -3
- package/src/document-editor/narration-schema.tsx +12 -6
- package/src/document-editor/narration.ts +19 -3
- package/src/document-editor/page-body.ts +60 -0
- package/src/document-editor/projection.ts +2 -2
- package/src/document-editor/rich-text.ts +3 -2
- package/src/document-editor/selection.ts +13 -0
- package/src/document-editor/style.css +12 -1
- package/src/document-editor/table-identities.ts +2 -1
- package/src/document-production.ts +331 -0
- package/src/document-session.ts +190 -51
- package/src/history.ts +3 -3
- package/src/index.ts +5 -5
- package/src/jobs.ts +1 -1
- package/src/messages.ts +19 -4
- package/src/panels/DocumentView.tsx +66 -26
- package/src/panels/DocumentVoiceDialog.tsx +2 -2
- package/src/panels/DocumentVoiceField.tsx +1 -1
- package/src/panels/ExportPanel.tsx +1 -6
- package/src/panels/HistoryPanel.tsx +1 -1
- package/src/panels/PageDeleteDialog.tsx +4 -4
- package/src/panels/PageRenameDialog.tsx +1 -1
- package/src/panels/PreviewPanel.tsx +1 -4
- package/src/panels/ProductionCaptionSize.tsx +20 -0
- package/src/panels/ProductionCaptionTiming.tsx +7 -7
- package/src/panels/ProductionMediaClips.tsx +6 -5
- package/src/panels/ProductionPanel.tsx +8 -4
- package/src/panels/ProductionRecording.tsx +86 -9
- package/src/panels/ProductionRecordingRange.tsx +4 -4
- package/src/panels/ProductionTimeline.tsx +6 -1
- package/src/panels/ProductionTranscription.tsx +5 -4
- package/src/panels/SourceDocumentPanel.tsx +12 -15
- package/src/panels/TranscriptionAdoption.tsx +9 -8
- package/src/panels/VoiceCloneDialog.tsx +2 -1
- package/src/panels/VoiceoverDialog.tsx +1 -1
- package/src/places.ts +1 -36
- package/src/preview-playback.ts +1 -1
- package/src/production-messages.ts +6 -0
- package/src/production-playback.ts +1 -1
- package/src/production-voice-playback.ts +3 -2
- package/src/sha256.ts +9 -0
- package/src/styles.css +16 -41
- package/src/use-recording-adoption.ts +2 -2
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +157 -0
- package/src/workbench.ts +177 -943
- package/src/workspace-client.ts +6 -5
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
package/src/document-session.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { hasRole, validateDocument } from '@lincyaw/kernel'
|
|
2
|
-
import type { DocumentAnswer, DocumentChangeAnswer, DocumentImageImportAnswer, DocumentIssue, Member, TeachingDocument } from '@lincyaw/kernel'
|
|
1
|
+
import { hasRole, isRecord, randomUUID, validateDocument } from '@lincyaw/kernel'
|
|
2
|
+
import type { CanonicalSource, ClientBodyDraftReference, DocumentAnswer, DocumentChangeAnswer, DocumentImageImportAnswer, DocumentIssue, Member, TeachingDocument } from '@lincyaw/kernel'
|
|
3
3
|
import { WorkspaceServerError } from './workspace-client.ts'
|
|
4
4
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
5
|
+
import { waitForDraft } from './document-draft-store.ts'
|
|
5
6
|
import { DocumentDrafts } from './document-drafts.ts'
|
|
7
|
+
import { sha256 } from './sha256.ts'
|
|
6
8
|
import type { DocumentDraftChoice, DocumentDraftCommit, DocumentDraftReference, StoredDocumentDraft } from './document-drafts.ts'
|
|
7
9
|
|
|
8
10
|
export interface DocumentSessionState {
|
|
@@ -28,12 +30,16 @@ export interface DocumentSessionState {
|
|
|
28
30
|
recoveryDrafts?: DocumentDraftChoice[]
|
|
29
31
|
recoveryChanged?: boolean
|
|
30
32
|
}
|
|
33
|
+
export interface DocumentDraftOperation { signal: AbortSignal, guard(): void, source: CanonicalSource, localDraft?: true }
|
|
34
|
+
export interface BodyDraftCandidate { draft: DocumentDraftReference & { current: boolean }, content: TeachingDocument, storage: 'durable' | 'rescue' | 'session', updatedAt: number, baseVersion: string, composing: boolean, pendingSubmission: boolean }
|
|
31
35
|
interface Slot {
|
|
36
|
+
observedSource?: CanonicalSource
|
|
32
37
|
state: DocumentSessionState
|
|
33
38
|
read: number
|
|
34
39
|
compositions: Set<string>
|
|
35
40
|
input: number
|
|
36
41
|
baseHash: string
|
|
42
|
+
baseContent: TeachingDocument
|
|
37
43
|
storage: string
|
|
38
44
|
drafts: DocumentDrafts
|
|
39
45
|
backup?: DocumentDraftCommit
|
|
@@ -54,6 +60,7 @@ interface Slot {
|
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
const serialize = (value: unknown) => JSON.stringify(value, (_, entry) => entry && typeof entry === 'object' && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).sort(([a], [b]) => a.localeCompare(b))) : entry)
|
|
63
|
+
const sameSource = (a: CanonicalSource | undefined, b: CanonicalSource) => a?.documentId === b.documentId && a.version === b.version && a.fingerprint === b.fingerprint
|
|
57
64
|
/** Non-body authoring changes keep native selection, comment drafts and body history. */
|
|
58
65
|
function keepsEditorContent(before: TeachingDocument, after: TeachingDocument): boolean {
|
|
59
66
|
const editing = ({ assets: _assets, production: _production, comments: _comments, definitions: _definitions, ...document }: TeachingDocument) => {
|
|
@@ -88,10 +95,21 @@ function keepsEditorContent(before: TeachingDocument, after: TeachingDocument):
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
async function digest(value: TeachingDocument): Promise<string> {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
return sha256(serialize(value))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Replay pending author input on a newer saved document; an overlapping value belongs to the author. */
|
|
102
|
+
function rebaseDocument(base: TeachingDocument, local: TeachingDocument, remote: TeachingDocument): TeachingDocument {
|
|
103
|
+
const merge = (before: unknown, author: unknown, saved: unknown): unknown => {
|
|
104
|
+
if (serialize(author) === serialize(before)) return structuredClone(saved)
|
|
105
|
+
if (serialize(saved) === serialize(before) || serialize(author) === serialize(saved)) return structuredClone(author)
|
|
106
|
+
if (isRecord(before) && isRecord(author) && isRecord(saved)) return Object.fromEntries([...new Set([...Object.keys(before), ...Object.keys(author), ...Object.keys(saved)])]
|
|
107
|
+
.map(key => [key, merge(before[key], author[key], saved[key])] as const).filter(([, value]) => value !== undefined))
|
|
108
|
+
return structuredClone(author)
|
|
109
|
+
}
|
|
110
|
+
const merged = validateDocument(merge(base, local, remote))
|
|
111
|
+
// A structural conflict is one document operation: preserve the author's valid complete document.
|
|
112
|
+
return merged.document && !merged.issues.some(issue => issue.severity === 'error') ? merged.document : structuredClone(local)
|
|
95
113
|
}
|
|
96
114
|
|
|
97
115
|
/** One source actor per document. Runtime compilation and iframe lifecycle never own its input. */
|
|
@@ -142,7 +160,7 @@ export class DocumentSession {
|
|
|
142
160
|
const baseHash = await digest(answer.content)
|
|
143
161
|
if (this.#disposed || this.#active !== directory || opening !== this.#opening) return
|
|
144
162
|
const drafts = new DocumentDrafts(() => { if (slot && !this.#disposed) void this.#readDrafts(slot) })
|
|
145
|
-
slot = { input: 0, read: 0, compositions: new Set(), drafts, baseHash, storage: `presmium.document.v1:${JSON.stringify([info.root, answer.content.id])}`, state: { directory, member: info.member, identity: JSON.stringify([info.root, answer.content.id]), content: answer.content, version: answer.version, fingerprint: answer.fingerprint, loading: true, dirty: false, saving: false, restored: false, composing: false, storageFailure: false, reset: 0, issues: answer.issues } }
|
|
163
|
+
slot = { observedSource: this.#source(answer), input: 0, read: 0, compositions: new Set(), drafts, baseHash, baseContent: structuredClone(answer.content), storage: `presmium.document.v1:${JSON.stringify([info.root, answer.content.id])}`, state: { directory, member: info.member, identity: JSON.stringify([info.root, answer.content.id]), content: answer.content, version: answer.version, fingerprint: answer.fingerprint, loading: true, dirty: false, saving: false, restored: false, composing: false, storageFailure: false, reset: 0, issues: answer.issues } }
|
|
146
164
|
this.#slots.set(directory, slot)
|
|
147
165
|
await this.#restore(slot, answer)
|
|
148
166
|
} else {
|
|
@@ -193,23 +211,76 @@ export class DocumentSession {
|
|
|
193
211
|
for (const changed of slot.saveWaiters ?? []) changed()
|
|
194
212
|
if (this.#active === slot.state.directory && this.#slots.get(slot.state.directory) === slot) this.#changed({ ...slot.state })
|
|
195
213
|
}
|
|
214
|
+
bodyDraftRevision(): number { const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active); return slot?.drafts.revision ?? 0 }
|
|
215
|
+
bodyDraftCapabilities(): { read: boolean, mutate: boolean, current: boolean } {
|
|
216
|
+
const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active)
|
|
217
|
+
const read = Boolean(slot?.state.identity && slot.state.content && slot.state.version && !slot.state.loading && !this.#disposed)
|
|
218
|
+
return { read, mutate: Boolean(read && slot && !this.#readOnly(slot) && !slot.state.composing && !slot.flight && !slot.assetFlight && !slot.state.recovering),
|
|
219
|
+
current: Boolean(slot && (slot.state.dirty || slot.state.restored || slot.state.composing || slot.state.error)) }
|
|
220
|
+
}
|
|
221
|
+
async readBodyDrafts(signal: AbortSignal, selected?: ClientBodyDraftReference): Promise<{ candidates: BodyDraftCandidate[], coverage: 'stored-and-session' | 'partial', guard(): void }> {
|
|
222
|
+
const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active)
|
|
223
|
+
if (!slot || !this.bodyDraftCapabilities().read || !slot.state.identity || !slot.state.content || !slot.state.version) throw new Error('client-body-drafts-unavailable')
|
|
224
|
+
const identity = slot.state.identity, documentId = slot.state.content.id, input = slot.input, read = slot.read, content = slot.state.content, version = slot.state.version,
|
|
225
|
+
revision = slot.drafts.revision, composing = slot.state.composing, source = JSON.stringify(slot.observedSource), own = slot.draft, flight = slot.flight, assetFlight = slot.assetFlight
|
|
226
|
+
const guard = () => {
|
|
227
|
+
signal.throwIfAborted()
|
|
228
|
+
if (this.#disposed || this.#active !== slot.state.directory || this.#slots.get(slot.state.directory) !== slot || slot.state.identity !== identity
|
|
229
|
+
|| slot.input !== input || slot.read !== read || slot.state.content !== content || slot.state.version !== version || slot.state.composing !== composing
|
|
230
|
+
|| JSON.stringify(slot.observedSource) !== source || slot.draft !== own || slot.flight !== flight || slot.assetFlight !== assetFlight || slot.drafts.revision !== revision) throw new Error('client-body-drafts-changed')
|
|
231
|
+
}
|
|
232
|
+
guard()
|
|
233
|
+
const stored = await slot.drafts.read(identity, documentId, signal)
|
|
234
|
+
guard()
|
|
235
|
+
let candidates: BodyDraftCandidate[] = stored.records.filter(record => !(record.owned && record.id === slot.draft?.id)).map(record => ({
|
|
236
|
+
draft: { id: record.id, revision: record.revision, token: record.token, current: false }, content: record.content, storage: record.source,
|
|
237
|
+
updatedAt: record.updatedAt, baseVersion: record.baseVersion, composing: Boolean(record.composing), pendingSubmission: false,
|
|
238
|
+
}))
|
|
239
|
+
if (this.bodyDraftCapabilities().current) {
|
|
240
|
+
const token = await sha256(JSON.stringify({ domain: 'body-current', identity, id: slot.draft?.id ?? 'current', content, version, input, composing, pendingHash: slot.pendingHash }))
|
|
241
|
+
guard()
|
|
242
|
+
candidates.push({ draft: { id: slot.draft?.id ?? 'current', revision: input + 1, token, current: true }, content: structuredClone(content),
|
|
243
|
+
storage: stored.records.some(record => record.source === 'durable' && record.owned && record.id === slot.draft?.id && record.revision === slot.draft.revision && record.baseVersion === version && Boolean(record.composing) === composing && JSON.stringify(record.content) === JSON.stringify(content)) ? 'durable' : 'session', updatedAt: slot.draft?.updatedAt ?? 0,
|
|
244
|
+
baseVersion: version, composing, pendingSubmission: Boolean(flight || assetFlight) })
|
|
245
|
+
}
|
|
246
|
+
candidates.sort((a, b) => a.draft.token.localeCompare(b.draft.token))
|
|
247
|
+
if (selected) {
|
|
248
|
+
candidates = candidates.filter(value => value.draft.token === selected)
|
|
249
|
+
if (candidates.length !== 1) throw new Error('client-body-drafts-changed')
|
|
250
|
+
}
|
|
251
|
+
guard()
|
|
252
|
+
return { candidates, coverage: stored.failed ? 'partial' : 'stored-and-session', guard }
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
#source(answer: DocumentAnswer): CanonicalSource { return { documentId: answer.content.id, version: answer.version, fingerprint: answer.fingerprint } }
|
|
256
|
+
canonicalSource(): CanonicalSource | undefined { const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active); return slot?.observedSource && { ...slot.observedSource } }
|
|
257
|
+
#checkOperation(operation?: DocumentDraftOperation, answer?: DocumentAnswer): void {
|
|
258
|
+
operation?.signal.throwIfAborted(); operation?.guard()
|
|
259
|
+
if (operation && !operation.localDraft && answer && !sameSource(this.#source(answer), operation.source)) throw new Error('client-source-changed')
|
|
260
|
+
}
|
|
196
261
|
#error(error: unknown): string { return error instanceof WorkspaceServerError ? error.answer.error ?? 'document-request-failed' : 'document-disconnected' }
|
|
197
262
|
#readOnly(slot: Slot): boolean { return this.#client.capabilities?.readOnly === true || Boolean(slot.state.member && !hasRole(slot.state.member, 'editor')) }
|
|
198
263
|
#issues(error: unknown): DocumentIssue[] { const value = error instanceof WorkspaceServerError ? (error.answer as { issues?: DocumentIssue[] }).issues : undefined; return Array.isArray(value) ? value : [] }
|
|
199
264
|
|
|
200
|
-
async refresh(directory = this.#active): Promise<void> {
|
|
265
|
+
async refresh(directory = this.#active, operation?: DocumentDraftOperation): Promise<void> {
|
|
201
266
|
if (directory === undefined) return
|
|
202
267
|
const slot = this.#slots.get(directory)
|
|
203
268
|
if (!slot) { if (directory === this.#active) await this.open(directory); return }
|
|
204
|
-
if (slot.flight || slot.assetFlight) { slot.refreshed = true; return }
|
|
205
|
-
const read = ++slot.read, current = () =>
|
|
269
|
+
if (slot.flight || slot.assetFlight) { slot.refreshed = true; if (operation) throw new Error('client-body-drafts-changed'); return }
|
|
270
|
+
const read = ++slot.read, current = () => {
|
|
271
|
+
const matches = slot.read === read && this.#slots.get(directory) === slot
|
|
272
|
+
if (operation && !matches) throw new Error('client-body-drafts-changed')
|
|
273
|
+
return matches
|
|
274
|
+
}
|
|
206
275
|
try {
|
|
207
|
-
const answer = await this.#client.readDocument(directory)
|
|
276
|
+
const answer = await this.#client.readDocument(directory, operation?.signal)
|
|
208
277
|
if (!current()) return
|
|
209
|
-
if (slot.flight || slot.assetFlight) { slot.refreshed = true; return }
|
|
210
|
-
|
|
278
|
+
if (slot.flight || slot.assetFlight) { slot.refreshed = true; if (operation) throw new Error('client-body-drafts-changed'); return }
|
|
279
|
+
this.#checkOperation(operation, answer)
|
|
280
|
+
await this.#adopt(slot, answer, () => { this.#checkOperation(operation); return current() })
|
|
211
281
|
if (current()) { this.#persist(slot); this.#emit(slot); void this.#readDrafts(slot) }
|
|
212
282
|
} catch (error) {
|
|
283
|
+
if (operation) throw error
|
|
213
284
|
if (current()) { slot.state = { ...slot.state, error: this.#error(error), issues: this.#issues(error) }; this.#emit(slot) }
|
|
214
285
|
}
|
|
215
286
|
}
|
|
@@ -217,6 +288,7 @@ export class DocumentSession {
|
|
|
217
288
|
async #adopt(slot: Slot, answer: DocumentAnswer, current = () => true): Promise<void> {
|
|
218
289
|
if (!current()) return
|
|
219
290
|
if (answer.content.id !== slot.state.content?.id) { slot.state = { ...slot.state, error: 'document-identity-changed' }; return }
|
|
291
|
+
slot.observedSource = this.#source(answer)
|
|
220
292
|
if (answer.version === slot.state.version) {
|
|
221
293
|
if (answer.fingerprint !== slot.state.fingerprint) slot.state = { ...slot.state, fingerprint: answer.fingerprint, issues: answer.issues }
|
|
222
294
|
return
|
|
@@ -235,11 +307,20 @@ export class DocumentSession {
|
|
|
235
307
|
slot.baseHash = remoteHash; slot.pendingHash = undefined
|
|
236
308
|
slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, error: undefined, issues: answer.issues }
|
|
237
309
|
} else if (remoteHash === slot.baseHash) slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, issues: answer.issues }
|
|
238
|
-
else
|
|
310
|
+
else if (!slot.state.composing) {
|
|
311
|
+
const content = rebaseDocument(slot.baseContent, slot.state.content!, answer.content)
|
|
312
|
+
const reset = slot.state.reset + (keepsEditorContent(slot.state.content!, content) ? 0 : 1)
|
|
313
|
+
slot.baseHash = remoteHash
|
|
314
|
+
slot.pendingHash = undefined
|
|
315
|
+
slot.state = { ...slot.state, content, reset, version: answer.version, fingerprint: answer.fingerprint, error: undefined, dirty: true, issues: answer.issues }
|
|
316
|
+
}
|
|
317
|
+
if (slot.state.version === answer.version) slot.baseContent = structuredClone(answer.content)
|
|
239
318
|
return
|
|
240
319
|
}
|
|
241
320
|
const reset = slot.state.reset + (keepsEditorContent(slot.state.content!, answer.content) ? 0 : 1)
|
|
242
321
|
slot.baseHash = remoteHash
|
|
322
|
+
slot.baseContent = structuredClone(answer.content)
|
|
323
|
+
slot.observedSource = this.#source(answer)
|
|
243
324
|
slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, content: answer.content, reset, error: undefined, issues: answer.issues }
|
|
244
325
|
}
|
|
245
326
|
|
|
@@ -283,33 +364,51 @@ export class DocumentSession {
|
|
|
283
364
|
this.#persist(slot); this.#emit(slot)
|
|
284
365
|
}
|
|
285
366
|
|
|
286
|
-
async #save(slot: Slot, immediate = false): Promise<void> {
|
|
367
|
+
async #save(slot: Slot, immediate = false, operation?: DocumentDraftOperation): Promise<void> {
|
|
287
368
|
if (immediate) { clearTimeout(slot.timer); slot.timer = undefined }
|
|
288
369
|
else if (slot.timer !== undefined) return
|
|
289
370
|
if (this.#readOnly(slot) || slot.flight || slot.assetFlight || !slot.state.dirty || slot.state.composing || slot.state.restored || slot.state.error || !slot.state.content || !slot.state.version) return
|
|
371
|
+
const check = () => {
|
|
372
|
+
this.#checkOperation(operation)
|
|
373
|
+
if (operation && (slot.state.version !== operation.source.version || !sameSource(slot.observedSource, operation.source))) throw new Error('client-source-changed')
|
|
374
|
+
}
|
|
375
|
+
check()
|
|
290
376
|
slot.read++
|
|
291
|
-
const flight = { id:
|
|
377
|
+
const flight = { id: randomUUID(), input: slot.input, content: structuredClone(slot.state.content), baseVersion: slot.state.version, hash: undefined as string | undefined }
|
|
292
378
|
slot.flight = flight
|
|
379
|
+
let completed = false
|
|
293
380
|
slot.state = { ...slot.state, saving: true }; this.#emit(slot)
|
|
294
381
|
try {
|
|
295
382
|
flight.hash = await digest(flight.content)
|
|
383
|
+
check()
|
|
384
|
+
if (operation && (slot.input !== flight.input || slot.state.composing)) throw new Error('client-body-drafts-changed')
|
|
296
385
|
slot.pendingHash = flight.hash
|
|
297
386
|
this.#persist(slot)
|
|
298
|
-
const answer = await this.#client.changeDocument(slot.state.directory, { id: flight.id, baseDocumentVersion: flight.baseVersion, replacement: flight.content })
|
|
387
|
+
const answer = await this.#client.changeDocument(slot.state.directory, { id: flight.id, baseDocumentVersion: flight.baseVersion, replacement: flight.content }, operation?.signal)
|
|
299
388
|
if (answer.changeId !== flight.id || answer.document !== slot.state.directory || answer.content.id !== flight.content.id) throw new Error('document-confirmation')
|
|
300
389
|
this.#ack(slot, flight, answer)
|
|
390
|
+
completed = true
|
|
301
391
|
} catch (error) {
|
|
302
|
-
|
|
392
|
+
if (!operation && this.#error(error) === 'document-version-changed' && !slot.state.composing) {
|
|
393
|
+
try {
|
|
394
|
+
await this.#adopt(slot, await this.#client.readDocument(slot.state.directory))
|
|
395
|
+
slot.state = { ...slot.state, saving: false }
|
|
396
|
+
} catch (refreshError) { slot.state = { ...slot.state, saving: false, error: this.#error(refreshError), issues: this.#issues(refreshError) } }
|
|
397
|
+
} else slot.state = { ...slot.state, saving: false, error: this.#error(error), issues: this.#issues(error) }
|
|
398
|
+
if (operation) { slot.state = { ...slot.state, restored: true }; throw error }
|
|
303
399
|
} finally {
|
|
304
400
|
if (slot.flight === flight) slot.flight = undefined
|
|
305
401
|
this.#persist(slot); this.#emit(slot)
|
|
306
402
|
void this.#readDrafts(slot)
|
|
307
|
-
if (slot.refreshed) { slot.refreshed = false; await this.refresh(slot.state.directory) }
|
|
308
|
-
if (!slot.state.error) void this.#save(slot)
|
|
403
|
+
if (slot.refreshed && (!operation || completed)) { slot.refreshed = false; await this.refresh(slot.state.directory) }
|
|
404
|
+
if (!operation && !slot.state.error) void this.#save(slot)
|
|
405
|
+
else if (operation && completed && slot.input !== flight.input && !slot.state.error) this.#schedule(slot)
|
|
309
406
|
}
|
|
310
407
|
}
|
|
311
408
|
#ack(slot: Slot, flight: NonNullable<Slot['flight']>, answer: DocumentChangeAnswer): void {
|
|
409
|
+
slot.observedSource = this.#source(answer)
|
|
312
410
|
slot.baseHash = flight.hash!
|
|
411
|
+
slot.baseContent = structuredClone(answer.content)
|
|
313
412
|
slot.pendingHash = undefined
|
|
314
413
|
const same = slot.input === flight.input
|
|
315
414
|
slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, ...(same ? { content: answer.content } : {}), dirty: !same, saving: false, error: undefined, issues: answer.issues }
|
|
@@ -328,6 +427,8 @@ export class DocumentSession {
|
|
|
328
427
|
const same = slot.input === input, content = same ? answer.content : structuredClone(current)
|
|
329
428
|
if (!same) for (const [id, asset] of added) content.assets[id] = structuredClone(asset)
|
|
330
429
|
slot.baseHash = baseHash
|
|
430
|
+
slot.baseContent = structuredClone(answer.content)
|
|
431
|
+
slot.observedSource = this.#source(answer)
|
|
331
432
|
slot.state = { ...slot.state, content, version: answer.version, fingerprint: answer.fingerprint, dirty: !same, error: undefined, issues: answer.issues }
|
|
332
433
|
return true
|
|
333
434
|
}
|
|
@@ -342,7 +443,9 @@ export class DocumentSession {
|
|
|
342
443
|
const checked = validateDocument(content)
|
|
343
444
|
if (!checked.document || checked.issues.some(issue => issue.severity === 'error')) return false
|
|
344
445
|
slot.baseHash = baseHash
|
|
446
|
+
slot.baseContent = structuredClone(answer.content)
|
|
345
447
|
slot.pendingHash = undefined
|
|
448
|
+
slot.observedSource = this.#source(answer)
|
|
346
449
|
slot.state = { ...slot.state, content: structuredClone(checked.document), version: answer.version, fingerprint: answer.fingerprint,
|
|
347
450
|
dirty: slot.input !== input || slot.state.composing || serialize(content) !== serialize(answer.content), error: undefined, issues: answer.issues }
|
|
348
451
|
return true
|
|
@@ -406,7 +509,7 @@ export class DocumentSession {
|
|
|
406
509
|
const before = structuredClone(slot.state.content), input = slot.input, version = slot.state.version
|
|
407
510
|
let request = this.#imageImports.get(file)
|
|
408
511
|
if (!request || request.identity !== identity || request.version !== version) {
|
|
409
|
-
request = { identity, version, id:
|
|
512
|
+
request = { identity, version, id: randomUUID() }
|
|
410
513
|
this.#imageImports.set(file, request)
|
|
411
514
|
}
|
|
412
515
|
const read = ++slot.read
|
|
@@ -443,39 +546,58 @@ export class DocumentSession {
|
|
|
443
546
|
}
|
|
444
547
|
}
|
|
445
548
|
|
|
446
|
-
async retry(): Promise<void> {
|
|
549
|
+
async retry(operation?: DocumentDraftOperation): Promise<void> {
|
|
447
550
|
if (this.#disposed || this.#active === undefined) return
|
|
448
551
|
const slot = this.#slots.get(this.#active)
|
|
449
552
|
if (!slot) { await this.open(this.#active); return }
|
|
450
553
|
if (slot.flight || slot.assetFlight || slot.state.composing) return
|
|
451
|
-
|
|
452
|
-
slot.state =
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
554
|
+
this.#checkOperation(operation)
|
|
555
|
+
const previousError = slot.state.error, restored = slot.state.restored, input = slot.input
|
|
556
|
+
if (!operation) slot.state = { ...slot.state, restored: false, error: undefined }
|
|
557
|
+
try {
|
|
558
|
+
await this.refresh(slot.state.directory, operation)
|
|
559
|
+
this.#checkOperation(operation)
|
|
560
|
+
if (operation && slot.input !== input) throw new Error('client-body-drafts-changed')
|
|
561
|
+
if (operation) slot.state = { ...slot.state, restored: false, error: undefined }
|
|
562
|
+
if (slot.state.error) { if (!previousError) this.#emit(slot); return }
|
|
563
|
+
await this.#save(slot, true, operation)
|
|
564
|
+
} catch (error) {
|
|
565
|
+
if (operation && slot.input === input && this.#slots.get(slot.state.directory) === slot) { slot.state = { ...slot.state, restored: restored || slot.state.restored, error: slot.state.error ?? previousError }; this.#emit(slot) }
|
|
566
|
+
throw error
|
|
567
|
+
}
|
|
456
568
|
}
|
|
457
|
-
async discard(): Promise<void> {
|
|
569
|
+
async discard(operation?: DocumentDraftOperation): Promise<boolean | void> {
|
|
458
570
|
const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active)
|
|
459
571
|
if (!slot || slot.flight || slot.assetFlight || slot.state.composing) return
|
|
572
|
+
const pendingSave = slot.timer !== undefined
|
|
573
|
+
clearTimeout(slot.timer); slot.timer = undefined
|
|
574
|
+
let discarded = false
|
|
460
575
|
const directory = slot.state.directory, identity = slot.state.identity, documentId = slot.state.content?.id, input = slot.input, read = ++slot.read
|
|
461
|
-
const current = () => !this.#disposed && this.#slots.get(directory) === slot && slot.read === read && slot.input === input
|
|
462
|
-
&& slot.state.identity === identity && !slot.state.composing && !slot.flight && !slot.assetFlight
|
|
576
|
+
const current = () => { this.#checkOperation(operation); return !this.#disposed && this.#slots.get(directory) === slot && slot.read === read && slot.input === input
|
|
577
|
+
&& slot.state.identity === identity && !slot.state.composing && !slot.flight && !slot.assetFlight }
|
|
463
578
|
try {
|
|
464
|
-
const answer = await this.#client.readDocument(directory)
|
|
579
|
+
const answer = await this.#client.readDocument(directory, operation?.signal)
|
|
465
580
|
if (!current()) return
|
|
466
581
|
if (answer.document !== directory || answer.content.id !== documentId) {
|
|
467
582
|
slot.state = { ...slot.state, error: 'document-identity-changed' }; this.#emit(slot)
|
|
468
583
|
return
|
|
469
584
|
}
|
|
585
|
+
this.#checkOperation(operation, answer)
|
|
470
586
|
const baseHash = await digest(answer.content)
|
|
587
|
+
this.#checkOperation(operation)
|
|
471
588
|
if (!current()) return
|
|
589
|
+
slot.observedSource = this.#source(answer)
|
|
590
|
+
discarded = true
|
|
472
591
|
slot.input++; slot.baseHash = baseHash
|
|
473
592
|
slot.pendingHash = undefined
|
|
474
593
|
slot.compositions.clear()
|
|
475
594
|
slot.state = { ...slot.state, content: answer.content, version: answer.version, fingerprint: answer.fingerprint, dirty: false, restored: false, composing: false, reset: slot.state.reset + 1, error: undefined, issues: answer.issues }
|
|
476
595
|
this.#persist(slot); this.#emit(slot)
|
|
596
|
+
if (operation && slot.backup) await waitForDraft(slot.backup.done, operation.signal)
|
|
477
597
|
void this.#readDrafts(slot)
|
|
478
|
-
|
|
598
|
+
return true
|
|
599
|
+
} catch (error) { if (operation) throw error; if (current()) { slot.state = { ...slot.state, error: this.#error(error) }; this.#emit(slot) } }
|
|
600
|
+
finally { if (!discarded && pendingSave && this.#slots.get(directory) === slot && slot.input === input && slot.timer === undefined) this.#schedule(slot) }
|
|
479
601
|
}
|
|
480
602
|
async flush(signal?: AbortSignal): Promise<void> {
|
|
481
603
|
signal?.throwIfAborted()
|
|
@@ -584,7 +706,7 @@ export class DocumentSession {
|
|
|
584
706
|
}
|
|
585
707
|
|
|
586
708
|
/** Selecting a candidate never writes the source or replaces this tab's only snapshot. */
|
|
587
|
-
async recoverDraft(value: DocumentDraftReference): Promise<void> {
|
|
709
|
+
async recoverDraft(value: DocumentDraftReference, request?: DocumentDraftOperation): Promise<'restored' | 'already-saved' | void> {
|
|
588
710
|
const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active)
|
|
589
711
|
if (slot && this.#readOnly(slot)) return
|
|
590
712
|
if (!slot?.state.identity || !slot.state.content || slot.state.loading || slot.flight || slot.assetFlight || slot.state.composing || this.#disposed) return
|
|
@@ -594,47 +716,61 @@ export class DocumentSession {
|
|
|
594
716
|
clearTimeout(slot.timer); slot.timer = undefined
|
|
595
717
|
let adopted = false
|
|
596
718
|
let protectedRecord: { id?: string, revision?: number } | undefined
|
|
597
|
-
const current = () => !this.#disposed && this.#active === slot.state.directory && this.#slots.get(slot.state.directory) === slot && slot.state.identity === identity && slot.read === read && slot.input === input && slot.recoveryOperation === operation
|
|
598
|
-
&& !slot.state.composing && !slot.flight && !slot.assetFlight && (!protectedRecord || slot.draft?.id === protectedRecord.id && slot.draft?.revision === protectedRecord.revision)
|
|
719
|
+
const current = () => { this.#checkOperation(request); return !this.#disposed && this.#active === slot.state.directory && this.#slots.get(slot.state.directory) === slot && slot.state.identity === identity && slot.read === read && slot.input === input && slot.recoveryOperation === operation
|
|
720
|
+
&& !slot.state.composing && !slot.flight && !slot.assetFlight && (!protectedRecord || slot.draft?.id === protectedRecord.id && slot.draft?.revision === protectedRecord.revision) }
|
|
599
721
|
slot.state = { ...slot.state, recovering: true, recoveryChanged: false }; this.#emit(slot)
|
|
600
722
|
try {
|
|
723
|
+
this.#checkOperation(request)
|
|
601
724
|
if (!this.#persist(slot)) { this.#emit(slot); return }
|
|
602
725
|
const backup = slot.backup
|
|
603
|
-
if (backup && await backup.done !== 'committed') return
|
|
726
|
+
if (backup && await waitForDraft(backup.done, request?.signal) !== 'committed') return
|
|
604
727
|
if (!current()) return
|
|
605
728
|
protectedRecord = { id: slot.draft?.id, revision: slot.draft?.revision }
|
|
606
|
-
const candidate = (await slot.drafts.read(identity, documentId)).records.find(record => record.id === value.id && record.revision === value.revision && record.token === value.token)
|
|
729
|
+
const candidate = (await slot.drafts.read(identity, documentId, request?.signal)).records.find(record => record.id === value.id && record.revision === value.revision && record.token === value.token)
|
|
607
730
|
if (!current()) return
|
|
731
|
+
this.#checkOperation(request)
|
|
608
732
|
if (!candidate) { slot.state = { ...slot.state, recoveryChanged: true }; return }
|
|
609
|
-
const answer = await this.#client.readDocument(slot.state.directory)
|
|
733
|
+
const answer = await this.#client.readDocument(slot.state.directory, request?.signal)
|
|
610
734
|
if (!current()) return
|
|
611
735
|
if (answer.document !== slot.state.directory || answer.content.id !== documentId) { slot.state = { ...slot.state, error: 'document-identity-changed' }; return }
|
|
612
|
-
|
|
736
|
+
this.#checkOperation(request, answer)
|
|
737
|
+
slot.observedSource = this.#source(answer)
|
|
738
|
+
// Older LAN HTTP drafts stored canonical JSON in place of a SHA-256 fingerprint.
|
|
739
|
+
const [localHash, remoteHash, candidateBaseHash, pendingHash] = await Promise.all([
|
|
740
|
+
digest(candidate.content), digest(answer.content),
|
|
741
|
+
candidate.baseHash.startsWith('json:') ? sha256(candidate.baseHash.slice(5)) : candidate.baseHash,
|
|
742
|
+
candidate.pendingHash?.startsWith('json:') ? sha256(candidate.pendingHash.slice(5)) : candidate.pendingHash,
|
|
743
|
+
])
|
|
613
744
|
if (!current()) return
|
|
745
|
+
this.#checkOperation(request)
|
|
614
746
|
const origins = [...new Map([...(candidate.origins ?? []), { id: candidate.id, revision: candidate.revision, token: candidate.token }].map(value => [JSON.stringify([value.id, value.revision, value.token]), value])).values()]
|
|
615
747
|
if (localHash === remoteHash && !candidate.composing) {
|
|
616
|
-
const settled = await slot.drafts.settle(identity, origins)
|
|
748
|
+
const settled = await slot.drafts.settle(identity, origins, request && { ...request, guard: () => { if (!current()) throw new Error('client-body-drafts-changed') } })
|
|
617
749
|
if (!current()) return
|
|
618
750
|
slot.persistFailure = !settled
|
|
619
|
-
return
|
|
751
|
+
if (!settled) return
|
|
752
|
+
return 'already-saved'
|
|
620
753
|
}
|
|
621
|
-
const conflict = answer.version !== candidate.baseVersion && remoteHash !==
|
|
622
|
-
const version = remoteHash ===
|
|
623
|
-
const baseHash = remoteHash ===
|
|
754
|
+
const conflict = answer.version !== candidate.baseVersion && remoteHash !== candidateBaseHash && remoteHash !== pendingHash
|
|
755
|
+
const version = remoteHash === pendingHash || remoteHash === candidateBaseHash ? answer.version : candidate.baseVersion
|
|
756
|
+
const baseHash = remoteHash === pendingHash ? remoteHash : candidateBaseHash
|
|
624
757
|
const record = await slot.drafts.fork(identity, { content: candidate.content, baseVersion: version, baseHash, input: input + 1,
|
|
625
|
-
pendingHash
|
|
758
|
+
pendingHash, composing: Boolean(candidate.composing), origins }, request && { ...request, guard: () => { if (!current()) throw new Error('client-body-drafts-changed') } })
|
|
626
759
|
if (!current()) { if (record) slot.drafts.archive(record); return }
|
|
627
760
|
if (!record) { slot.persistFailure = true; slot.state = { ...slot.state, storageFailure: true }; return }
|
|
628
761
|
clearTimeout(slot.timer); slot.timer = undefined
|
|
762
|
+
this.#checkOperation(request)
|
|
629
763
|
if (slot.draft) slot.drafts.archive(slot.draft)
|
|
630
|
-
slot.input = input + 1; slot.baseHash = baseHash; slot.pendingHash =
|
|
764
|
+
slot.input = input + 1; slot.baseHash = baseHash; slot.pendingHash = pendingHash; slot.draft = record; slot.draftOrigins = origins
|
|
631
765
|
slot.backup = undefined; slot.persistFailure = false
|
|
632
766
|
adopted = true
|
|
633
767
|
slot.compositions.clear()
|
|
634
768
|
slot.state = { ...slot.state, content: candidate.content, version, fingerprint: answer.fingerprint, dirty: true, restored: true, composing: false,
|
|
635
769
|
backupPending: false, storageFailure: slot.legacyFailure === 'write', reset: slot.state.reset + 1,
|
|
636
770
|
error: conflict ? 'document-version-changed' : candidate.composing ? 'document-composition-interrupted' : undefined, issues: answer.issues }
|
|
771
|
+
return 'restored'
|
|
637
772
|
} catch (error) {
|
|
773
|
+
if (request) throw error
|
|
638
774
|
if (current()) slot.state = { ...slot.state, error: this.#error(error), issues: this.#issues(error) }
|
|
639
775
|
} finally {
|
|
640
776
|
if (!this.#disposed && this.#slots.get(slot.state.directory) === slot && slot.state.identity === identity && slot.recoveryOperation === operation) {
|
|
@@ -644,25 +780,28 @@ export class DocumentSession {
|
|
|
644
780
|
}
|
|
645
781
|
}
|
|
646
782
|
|
|
647
|
-
async forgetDraft(value: DocumentDraftReference): Promise<void> {
|
|
783
|
+
async forgetDraft(value: DocumentDraftReference, request?: DocumentDraftOperation): Promise<boolean | void> {
|
|
648
784
|
const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active)
|
|
649
785
|
if (!slot?.state.identity || !slot.state.content || slot.state.recovering || slot.flight || slot.assetFlight || slot.state.composing || this.#disposed) return
|
|
650
786
|
const identity = slot.state.identity, documentId = slot.state.content.id, input = slot.input, read = slot.read
|
|
651
787
|
const operation = slot.recoveryOperation = (slot.recoveryOperation ?? 0) + 1
|
|
652
|
-
const current = () => !this.#disposed && this.#active === slot.state.directory && this.#slots.get(slot.state.directory) === slot && slot.state.identity === identity && slot.input === input && slot.read === read && slot.recoveryOperation === operation && !slot.state.composing && !slot.flight && !slot.assetFlight
|
|
788
|
+
const current = () => { this.#checkOperation(request); return !this.#disposed && this.#active === slot.state.directory && this.#slots.get(slot.state.directory) === slot && slot.state.identity === identity && slot.input === input && slot.read === read && slot.recoveryOperation === operation && !slot.state.composing && !slot.flight && !slot.assetFlight }
|
|
653
789
|
slot.state = { ...slot.state, recovering: true }; this.#emit(slot)
|
|
654
790
|
try {
|
|
655
|
-
|
|
791
|
+
this.#checkOperation(request)
|
|
792
|
+
const candidate = (await slot.drafts.read(identity, documentId, request?.signal)).records.find(record => record.id === value.id && record.revision === value.revision && record.token === value.token)
|
|
656
793
|
if (!current()) return
|
|
794
|
+
this.#checkOperation(request)
|
|
657
795
|
if (candidate?.owned && candidate.id === slot.draft?.id) return
|
|
658
796
|
if (!candidate) slot.state = { ...slot.state, recoveryChanged: true }
|
|
659
797
|
else {
|
|
660
|
-
const settled = await slot.drafts.settle(identity, [value])
|
|
798
|
+
const settled = await slot.drafts.settle(identity, [value], request && { ...request, guard: () => { if (!current()) throw new Error('client-body-drafts-changed') } })
|
|
661
799
|
if (!current()) return
|
|
662
800
|
slot.persistFailure = !settled
|
|
663
801
|
slot.state = { ...slot.state, recoveryChanged: false, storageFailure: Boolean(slot.persistFailure || slot.legacyFailure === 'write') }
|
|
802
|
+
return settled
|
|
664
803
|
}
|
|
665
|
-
} catch { if (current()) { slot.persistFailure = true; slot.state = { ...slot.state, storageFailure: true } } }
|
|
804
|
+
} catch (error) { if (request) throw error; if (current()) { slot.persistFailure = true; slot.state = { ...slot.state, storageFailure: true } } }
|
|
666
805
|
finally {
|
|
667
806
|
if (!this.#disposed && this.#slots.get(slot.state.directory) === slot && slot.state.identity === identity && slot.recoveryOperation === operation) {
|
|
668
807
|
slot.state = { ...slot.state, recovering: false }; this.#emit(slot); void this.#readDrafts(slot)
|
package/src/history.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { errorMessage } from '@lincyaw/kernel'
|
|
1
|
+
import { errorMessage, randomUUID } from '@lincyaw/kernel'
|
|
2
2
|
import type { RevertResult, ReviewChange, ReviewSnapshot, ReviewUpdate } from '@lincyaw/kernel'
|
|
3
|
-
import type { WorkbenchStore } from './workbench.ts'
|
|
3
|
+
import type { WorkbenchStore } from './workbench-state.ts'
|
|
4
4
|
import { WorkspaceServerError } from './workspace-client.ts'
|
|
5
5
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
6
6
|
|
|
@@ -129,7 +129,7 @@ export class DocumentHistory {
|
|
|
129
129
|
#change(which: 'undo' | 'redo' | 'revertRevision', expect: string | undefined): Promise<boolean> {
|
|
130
130
|
const binding = this.#store.state.history?.historyBinding
|
|
131
131
|
if (!binding || !expect) return Promise.resolve(false)
|
|
132
|
-
const request = { id:
|
|
132
|
+
const request = { id: randomUUID(), ...binding, expect }
|
|
133
133
|
return this.#run(dir => this.#client[which](dir, request))
|
|
134
134
|
}
|
|
135
135
|
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { DocumentEditing } from './document-editing.ts'
|
|
2
|
+
export { DocumentProduction } from './document-production.ts'
|
|
1
3
|
export * from './components.tsx'
|
|
2
4
|
export { PmSchemaForm, schemaFormPropertyNames } from './schema-form/PmSchemaForm.tsx'
|
|
3
5
|
export type { PmSchemaFormProps } from './schema-form/PmSchemaForm.tsx'
|
|
@@ -14,8 +16,9 @@ export { findPlaceAtLine, findPlaceSource } from './places.ts'
|
|
|
14
16
|
export type { PlaceWithSource } from './places.ts'
|
|
15
17
|
export { connectPreview } from './preview.ts'
|
|
16
18
|
export type { PreviewConnection, PreviewHandlers } from './preview.ts'
|
|
17
|
-
export { documentDirFor, hasSlides,
|
|
18
|
-
export
|
|
19
|
+
export { documentDirFor, hasSlides, Workbench } from './workbench.ts'
|
|
20
|
+
export { isAgentChanging, selectedDocument } from './workbench-state.ts'
|
|
21
|
+
export type { AgentAnswer, AgentRequest, Pointer, PreviewSink, SaveState, WebView, WorkbenchMode, WorkbenchState } from './workbench-state.ts'
|
|
19
22
|
export { OperationLog } from './telemetry.ts'
|
|
20
23
|
export type { OperationBatch, OperationValue } from './telemetry.ts'
|
|
21
24
|
export { isObservedWorkspaceFailure, workspaceClient, WorkspaceServerError } from './workspace-client.ts'
|
|
@@ -26,9 +29,6 @@ export { HistoryPanel } from './panels/HistoryPanel.tsx'
|
|
|
26
29
|
export type { HistoryPanelProps, HistoryRevisionAction } from './panels/HistoryPanel.tsx'
|
|
27
30
|
export { HomePanel } from './panels/HomePanel.tsx'
|
|
28
31
|
export { WorkbenchApprovals } from './approvals.tsx'
|
|
29
|
-
export { assistantMascotAction, useAssistantMascot } from './assistant-mascot.ts'
|
|
30
|
-
export type { AssistantActivity } from './assistant-mascot.ts'
|
|
31
|
-
export { mascotEnabled, setMascotEnabled, useMascotEnabled } from './mascot-preference.ts'
|
|
32
32
|
export { PreviewPanel } from './panels/PreviewPanel.tsx'
|
|
33
33
|
export { SpeechSettingsPanel } from './panels/SpeechSettingsPanel.tsx'
|
|
34
34
|
export { SPEECH_SETTINGS_MESSAGES } from './speech-settings-messages.ts'
|
package/src/jobs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorMessage } from '@lincyaw/kernel'
|
|
2
2
|
import type { CompileJob, JobSource } from '@lincyaw/kernel'
|
|
3
|
-
import type { WorkbenchStore } from './workbench.ts'
|
|
3
|
+
import type { WorkbenchStore } from './workbench-state.ts'
|
|
4
4
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
5
5
|
|
|
6
6
|
/** Of two copies of a job (an event and an answer cross on the way), the one of the later change. */
|
package/src/messages.ts
CHANGED
|
@@ -12,6 +12,11 @@ export interface AgentPlace {
|
|
|
12
12
|
|
|
13
13
|
// A Latin word or a number set after Chinese text is spaced from it (docs/glossary.md 2).
|
|
14
14
|
const spaced = (text: string) => (/^[A-Za-z0-9]/.test(text) ? ` ${text}` : text)
|
|
15
|
+
// The start of a passage, enough to recognize it.
|
|
16
|
+
const excerpt = (text: string, length: number) => [...text].length > length ? `${[...text].slice(0, length).join('').trimEnd()}…` : text
|
|
17
|
+
|
|
18
|
+
/** Where on a page the author asks for new content: after a passage (its text, '' for content without text), at the start (none) or at the end. */
|
|
19
|
+
interface AgentInsertion { after?: string, end: boolean }
|
|
15
20
|
|
|
16
21
|
// Names of commands follow Microsoft Word's (撤消/Undo, 新建批注/New Comment, 版本历史/Version History…).
|
|
17
22
|
const zh = {
|
|
@@ -325,11 +330,11 @@ const zh = {
|
|
|
325
330
|
'history-result-no-longer-current': '之前的结果已不是当前版本,请查看最新的历史。',
|
|
326
331
|
'authoring-review-required': '有修改等待你审阅,请先接受或放弃。',
|
|
327
332
|
} as Record<string, string>,
|
|
328
|
-
agentWorking: 'AI 正在修改文稿…',
|
|
329
333
|
agentWaiting: (n: number) => `AI 修改了 ${n} 处内容,要接受这些修改吗?`,
|
|
330
334
|
accept: '接受',
|
|
331
335
|
reject: '拒绝',
|
|
332
|
-
problems: (n: number) =>
|
|
336
|
+
problems: (n: number) => `文稿有 ${n} 个问题需要处理。`,
|
|
337
|
+
problemsTitle: '文稿中的问题',
|
|
333
338
|
fixWithAi: '用 AI 修复',
|
|
334
339
|
fixing: '正在发送给 AI…',
|
|
335
340
|
fixFailed: (reason: string) => `无法发送给 AI。${reason}`,
|
|
@@ -356,6 +361,11 @@ const zh = {
|
|
|
356
361
|
place.quote ? `\n原文:“${place.quote}”` : '',
|
|
357
362
|
].join('')).filter(Boolean),
|
|
358
363
|
].join('\n\n'),
|
|
364
|
+
animationRequest: (page: number, title: string, place: AgentInsertion) => {
|
|
365
|
+
const at = `第 ${page} 页${title ? `“${title}”` : ''}`
|
|
366
|
+
return place.end ? `在${at}的末尾加一个动画:` : place.after === undefined ? `在${at}的开头加一个动画:`
|
|
367
|
+
: place.after ? `在${at}中“${excerpt(place.after, 16)}”这一段之后加一个动画:` : `在${at}的这个位置加一个动画:`
|
|
368
|
+
},
|
|
359
369
|
commentsRequest: (comments: (AgentPlace & { text: string })[]) => [
|
|
360
370
|
comments.length === 1 ? '我在文稿上写了一条批注:' : `我在文稿上写了 ${comments.length} 条批注:`,
|
|
361
371
|
...comments.map((comment, i) => [
|
|
@@ -689,11 +699,11 @@ const en: WorkbenchMessages = {
|
|
|
689
699
|
'history-result-no-longer-current': 'The earlier result is no longer the current version. Review the latest history.',
|
|
690
700
|
'authoring-review-required': 'Changes are waiting for your review. Accept or discard them first.',
|
|
691
701
|
},
|
|
692
|
-
agentWorking: 'The AI is editing the document…',
|
|
693
702
|
agentWaiting: (n: number) => `The AI changed ${n} file${n === 1 ? '' : 's'}. Accept the changes?`,
|
|
694
703
|
accept: 'Accept',
|
|
695
704
|
reject: 'Reject',
|
|
696
|
-
problems: (n: number) =>
|
|
705
|
+
problems: (n: number) => `The document has ${n} problem${n === 1 ? '' : 's'} to fix.`,
|
|
706
|
+
problemsTitle: 'Problems in the Document',
|
|
697
707
|
fixWithAi: 'Fix with AI',
|
|
698
708
|
fixing: 'Sending to the AI…',
|
|
699
709
|
fixFailed: (reason: string) => `Couldn’t send to the AI. ${reason}`,
|
|
@@ -720,6 +730,11 @@ const en: WorkbenchMessages = {
|
|
|
720
730
|
place.quote ? `\nText: “${place.quote}”` : '',
|
|
721
731
|
].join('')).filter(Boolean),
|
|
722
732
|
].join('\n\n'),
|
|
733
|
+
animationRequest: (page: number, title: string, place: AgentInsertion) => {
|
|
734
|
+
const at = `page ${page}${title ? `, “${title}”` : ''}`
|
|
735
|
+
return place.end ? `Add an animation at the end of ${at}: ` : place.after === undefined ? `Add an animation at the start of ${at}: `
|
|
736
|
+
: place.after ? `Add an animation on ${at}, after the paragraph “${excerpt(place.after, 40)}”: ` : `Add an animation at this point on ${at}: `
|
|
737
|
+
},
|
|
723
738
|
commentsRequest: (comments: (AgentPlace & { text: string })[]) => [
|
|
724
739
|
comments.length === 1 ? 'I left a comment on the document:' : `I left ${comments.length} comments on the document:`,
|
|
725
740
|
...comments.map((comment, i) => [
|