@lincyaw/workbench 0.2.0-rc.122 → 0.2.0-rc.124
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 +4 -4
- package/src/StepProductionEditor.tsx +13 -8
- package/src/components.tsx +1 -1
- package/src/context.tsx +19 -6
- package/src/document-editor/DocumentStepNarration.tsx +4 -2
- package/src/document-editor/references.tsx +42 -22
- package/src/document-session.ts +5 -3
- package/src/document-tree.ts +35 -3
- package/src/knowledge-components.tsx +64 -16
- package/src/knowledge.css +46 -0
- package/src/messages.ts +10 -0
- package/src/panels/DocumentPeekPanel.tsx +190 -0
- package/src/panels/DocumentView.tsx +12 -3
- package/src/panels/DocumentVoiceField.tsx +2 -2
- package/src/panels/MaterialsDialog.tsx +67 -0
- package/src/panels/ProductionCaptionSize.tsx +2 -2
- package/src/panels/ReferencesPanel.tsx +6 -3
- package/src/panels/WorkspaceHome.tsx +18 -2
- package/src/panels/WorkspaceSidebar.tsx +2 -2
- package/src/styles.css +19 -0
- package/src/tree-messages.ts +48 -2
- package/src/workbench-state.ts +8 -0
- package/src/workbench.ts +48 -1
- package/src/workspace-client.ts +14 -4
package/src/tree-messages.ts
CHANGED
|
@@ -63,6 +63,8 @@ export const DOCUMENT_TREE_MESSAGES = {
|
|
|
63
63
|
trashHint: '移到回收站的文稿连同其子文稿保存在这里,可以还原。',
|
|
64
64
|
restore: '还原',
|
|
65
65
|
restored: (title: string) => `已还原“${title}”`,
|
|
66
|
+
restoredToTop: (title: string, parent: 'trashed' | 'missing') => parent === 'trashed' ? `已还原“${title}”。它的上级文稿在回收站中,所以放在了顶层。` : `已还原“${title}”。它原来的上级文稿已不存在,所以放在了顶层。`,
|
|
67
|
+
parentTrashed: '上级文稿也在回收站中,单独还原时放在顶层',
|
|
66
68
|
deletePermanently: '永久删除…',
|
|
67
69
|
deletePermanentlyTitle: '永久删除',
|
|
68
70
|
deleteConfirm: (title: string) => `永久删除“${title}”及其子文稿?此操作无法撤消。`,
|
|
@@ -102,6 +104,11 @@ export const DOCUMENT_TREE_MESSAGES = {
|
|
|
102
104
|
previewMissing: '这份文稿已删除。',
|
|
103
105
|
previewTrashed: '这份文稿在回收站中。',
|
|
104
106
|
open: '打开',
|
|
107
|
+
openOnSide: '在右侧打开',
|
|
108
|
+
peekLabel: '右侧的文稿',
|
|
109
|
+
peekLoading: '正在加载文稿…',
|
|
110
|
+
peekFailed: '无法加载这份文稿。',
|
|
111
|
+
peekEmpty: '这份文稿还没有内容。',
|
|
105
112
|
missingDocument: '文稿已删除',
|
|
106
113
|
linkHeading: (query: string) => query ? `链接到文稿 · 输入“${query}”` : '链接到文稿',
|
|
107
114
|
createChildAndLink: (query: string) => `新建子文稿“${query}”并链接`,
|
|
@@ -135,7 +142,23 @@ export const DOCUMENT_TREE_MESSAGES = {
|
|
|
135
142
|
copyFailed: '无法复制链接,请重试。',
|
|
136
143
|
blankDocument: '空白文稿',
|
|
137
144
|
blankDocumentHint: '从标题开始写,随时添加页面和动画',
|
|
138
|
-
importHint: '
|
|
145
|
+
importHint: '把已有的文件转成文稿',
|
|
146
|
+
fromMaterials: '从来源材料写作',
|
|
147
|
+
fromMaterialsHint: '选择 PDF、Word、PowerPoint、图片或文本文件,由 AI 写成一份新文稿',
|
|
148
|
+
fromMaterialsNeedsModel: 'AI 助手还没有模型。设置模型之后,AI 才能根据来源材料写文稿。',
|
|
149
|
+
materialsDescription: 'Presmium 新建一份文稿,把来源材料保存在它的文件夹中,再发送给 AI,由它根据材料写出标题、页面与正文。写好之前可以随时在对话中补充要求。',
|
|
150
|
+
materialsChoose: '选择文件',
|
|
151
|
+
materialsSelected: (count: number) => `已选择 ${count} 个文件`,
|
|
152
|
+
materialsLimits: (files: number, mebibytes: number) => `最多 ${files} 个文件,合计 ${mebibytes} MiB。`,
|
|
153
|
+
materialsNote: '想要怎样的文稿(可选)',
|
|
154
|
+
materialsNotePlaceholder: '例如:给研究生的 20 分钟报告,每页一个要点',
|
|
155
|
+
materialsSubmit: '新建并发送给 AI',
|
|
156
|
+
materialsSent: '已新建文稿,AI 正在根据来源材料写作。',
|
|
157
|
+
materialsNotSent: '已新建文稿并保存了来源材料,但请求没有发给 AI。',
|
|
158
|
+
materialsFailed: '无法保存来源材料。新建的文稿已移到回收站,请重试。',
|
|
159
|
+
materialsLimit: (files: number, mebibytes: number) => `来源材料超过 ${files} 个文件或合计 ${mebibytes} MiB 的限制,请减少文件后重试。`,
|
|
160
|
+
brokenReferences: (places: number, documents: number) => `${places} 处引用的目标已删除或在回收站中${documents > 1 ? `,分布在 ${documents} 份文稿中` : ''}。`,
|
|
161
|
+
brokenSynced: (places: number, documents: number) => `${places} 个同步块的原内容已删除或在回收站中${documents > 1 ? `,分布在 ${documents} 份文稿中` : ''}。`,
|
|
139
162
|
needsAttention: '需要处理',
|
|
140
163
|
treeIssues: (count: number) => `${count} 份文稿的上级无效,暂时显示在顶层。请把它们移到正确的位置。`,
|
|
141
164
|
show: '查看',
|
|
@@ -210,6 +233,8 @@ export const DOCUMENT_TREE_MESSAGES = {
|
|
|
210
233
|
trashHint: 'Documents moved to the trash stay here with their child documents until you restore or delete them.',
|
|
211
234
|
restore: 'Restore',
|
|
212
235
|
restored: (title: string) => `Restored “${title}”.`,
|
|
236
|
+
restoredToTop: (title: string, parent: 'trashed' | 'missing') => parent === 'trashed' ? `Restored “${title}” to the top level because its parent document is in the trash.` : `Restored “${title}” to the top level because its parent document no longer exists.`,
|
|
237
|
+
parentTrashed: 'Its parent document is also in the trash; restored alone, it goes to the top level',
|
|
213
238
|
deletePermanently: 'Delete Permanently…',
|
|
214
239
|
deletePermanentlyTitle: 'Delete Permanently',
|
|
215
240
|
deleteConfirm: (title: string) => `Delete “${title}” and its child documents permanently? You can’t undo this.`,
|
|
@@ -249,6 +274,11 @@ export const DOCUMENT_TREE_MESSAGES = {
|
|
|
249
274
|
previewMissing: 'This document was deleted.',
|
|
250
275
|
previewTrashed: 'This document is in the trash.',
|
|
251
276
|
open: 'Open',
|
|
277
|
+
openOnSide: 'Open on the Side',
|
|
278
|
+
peekLabel: 'Document on the Side',
|
|
279
|
+
peekLoading: 'Loading the document…',
|
|
280
|
+
peekFailed: 'Couldn’t load this document.',
|
|
281
|
+
peekEmpty: 'This document has no content yet.',
|
|
252
282
|
missingDocument: 'Deleted document',
|
|
253
283
|
linkHeading: (query: string) => query ? `Link to Document · “${query}”` : 'Link to Document',
|
|
254
284
|
createChildAndLink: (query: string) => `New Child Document “${query}” and Link`,
|
|
@@ -282,7 +312,23 @@ export const DOCUMENT_TREE_MESSAGES = {
|
|
|
282
312
|
copyFailed: 'Couldn’t copy the link. Try again.',
|
|
283
313
|
blankDocument: 'Blank Document',
|
|
284
314
|
blankDocumentHint: 'Start from a title and add pages and animations as you go',
|
|
285
|
-
importHint: '
|
|
315
|
+
importHint: 'Turn files you already have into documents',
|
|
316
|
+
fromMaterials: 'Write from Source Material',
|
|
317
|
+
fromMaterialsHint: 'Choose PDF, Word, PowerPoint, picture, or text files, and the AI writes a new document from them',
|
|
318
|
+
fromMaterialsNeedsModel: 'The AI Assistant has no model yet. Set one up, and the AI can write documents from source material.',
|
|
319
|
+
materialsDescription: 'Presmium creates a new document, keeps your source material in its folder, and has the AI write the title, pages, and text from it. You can add to the request in the chat at any time.',
|
|
320
|
+
materialsChoose: 'Choose Files',
|
|
321
|
+
materialsSelected: (count: number) => `${count} ${count === 1 ? 'file' : 'files'} selected`,
|
|
322
|
+
materialsLimits: (files: number, mebibytes: number) => `Up to ${files} files and ${mebibytes} MiB in total.`,
|
|
323
|
+
materialsNote: 'What you want (optional)',
|
|
324
|
+
materialsNotePlaceholder: 'For example: a 20-minute talk for graduate students, one point per page',
|
|
325
|
+
materialsSubmit: 'Create and Send to AI',
|
|
326
|
+
materialsSent: 'Created the document. The AI is writing it from your source material.',
|
|
327
|
+
materialsNotSent: 'Created the document and kept the source material, but the request didn’t reach the AI.',
|
|
328
|
+
materialsFailed: 'Couldn’t save the source material. The new document was moved to the trash. Try again.',
|
|
329
|
+
materialsLimit: (files: number, mebibytes: number) => `The source material is over the limit of ${files} files or ${mebibytes} MiB in total. Choose fewer files and try again.`,
|
|
330
|
+
brokenReferences: (places: number, documents: number) => `${places} ${places === 1 ? 'reference points' : 'references point'} to content that was deleted or is in the trash${documents > 1 ? `, in ${documents} documents` : ''}.`,
|
|
331
|
+
brokenSynced: (places: number, documents: number) => `${places} ${places === 1 ? 'synced block shows' : 'synced blocks show'} content that was deleted or is in the trash${documents > 1 ? `, in ${documents} documents` : ''}.`,
|
|
286
332
|
needsAttention: 'Needs Attention',
|
|
287
333
|
treeIssues: (count: number) => `${count} ${count === 1 ? 'document has an invalid parent and is' : 'documents have an invalid parent and are'} shown at the top level for now. Move them where they belong.`,
|
|
288
334
|
show: 'Show',
|
package/src/workbench-state.ts
CHANGED
|
@@ -75,8 +75,12 @@ export interface WorkbenchState {
|
|
|
75
75
|
renamingDocument?: string
|
|
76
76
|
/** Documents opened recently in this browser, the latest first. */
|
|
77
77
|
recentDocuments?: import('./document-tree.ts').RecentDocument[]
|
|
78
|
+
/** What needs attention across the workspace: references and synced blocks whose target is gone or in the trash. */
|
|
79
|
+
workspaceAttention?: import('@lincyaw/kernel/contracts').WorkspaceAttention
|
|
78
80
|
/** Changes when cached reference previews and synced block sources are forgotten. */
|
|
79
81
|
documentLinksGeneration?: number
|
|
82
|
+
/** The document (and its page or block) shown read-only in the right pane beside the open one. */
|
|
83
|
+
documentPeek?: import('./document-tree.ts').DocumentPlace
|
|
80
84
|
/** The one message at the bottom that says what an operation did. */
|
|
81
85
|
toast?: import('./knowledge-components.tsx').ToastMessage
|
|
82
86
|
/** The workspace's routes answer 404: `@lincyaw/dsh` is turned off on the plugins page. */
|
|
@@ -138,6 +142,10 @@ export interface WorkbenchState {
|
|
|
138
142
|
isHistoryBusy: boolean
|
|
139
143
|
isAsking: boolean
|
|
140
144
|
askFailure?: string
|
|
145
|
+
/** A conversation's agent takes requests (`onAgentRequest`). */
|
|
146
|
+
canAskAgent?: boolean
|
|
147
|
+
/** Whether the agent has a model to run with, as the host says (`setAgentReadiness`); unknown until it does. */
|
|
148
|
+
agentReadiness?: 'ready' | 'missing' | 'unknown'
|
|
141
149
|
/** What the document can be made into, and its builds and exports (the author's and the AI's). */
|
|
142
150
|
jobs?: JobsAnswer
|
|
143
151
|
jobsFailure?: string
|
package/src/workbench.ts
CHANGED
|
@@ -44,6 +44,7 @@ import type { ProductionBinding, ProductionPlan, ProductionPlaybackCommand, Prod
|
|
|
44
44
|
import { workspaceClient, WorkspaceServerError } from './workspace-client.ts'
|
|
45
45
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
46
46
|
import { DocumentTreeActions } from './document-tree.ts'
|
|
47
|
+
import { DOCUMENT_TREE_MESSAGES } from './tree-messages.ts'
|
|
47
48
|
import type { AuthoringClientAction, AuthoringClientActionType, AuthoringClientActionResult, AuthoringClientSnapshot } from '@lincyaw/kernel'
|
|
48
49
|
import { PRODUCTION_PLAYBACK_RATES } from '@lincyaw/kernel'
|
|
49
50
|
|
|
@@ -89,6 +90,7 @@ const DOCUMENT_RESET = {
|
|
|
89
90
|
review: undefined, history: undefined, outside: undefined, historyFailure: undefined, isHistoryBusy: false, askFailure: undefined,
|
|
90
91
|
jobs: undefined, jobsFailure: undefined, jobPreparing: undefined,
|
|
91
92
|
voiceoverJobs: undefined, voiceoverJobsFailure: undefined, voiceoverCacheRefresh: undefined,
|
|
93
|
+
documentPeek: undefined,
|
|
92
94
|
} satisfies Partial<WorkbenchState>
|
|
93
95
|
|
|
94
96
|
/** A free directory for a new document called `title`, beside most of the existing ones. */
|
|
@@ -137,6 +139,7 @@ export class Workbench {
|
|
|
137
139
|
readonly #voiceover: VoiceoverJobs
|
|
138
140
|
readonly #askers = new Set<(request: AgentRequest) => Promise<AgentAnswer | void>>()
|
|
139
141
|
readonly #drafters = new Set<(draft: AgentDraft) => void | Promise<void>>()
|
|
142
|
+
#openAgentSetup?: () => void
|
|
140
143
|
readonly #previewSinks = new Set<PreviewSink>()
|
|
141
144
|
readonly #playbackKeys = new Set<(command: PlaybackKey) => void>()
|
|
142
145
|
#unsubscribeIr?: () => void
|
|
@@ -353,7 +356,24 @@ export class Workbench {
|
|
|
353
356
|
/** The host's way to hand a request to the conversation's agent. */
|
|
354
357
|
onAgentRequest = (asker: (request: AgentRequest) => Promise<AgentAnswer | void>): (() => void) => {
|
|
355
358
|
this.#askers.add(asker)
|
|
356
|
-
|
|
359
|
+
this.#set({ canAskAgent: true })
|
|
360
|
+
return () => {
|
|
361
|
+
this.#askers.delete(asker)
|
|
362
|
+
this.#set({ canAskAgent: this.#askers.size > 0 })
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** The host's word on whether the agent has a model to run with, and its way to open the model setup. */
|
|
367
|
+
setAgentReadiness(readiness: 'ready' | 'missing' | 'unknown', openSetup?: () => void): void {
|
|
368
|
+
this.#openAgentSetup = openSetup
|
|
369
|
+
if (this.#state.agentReadiness !== readiness) this.#set({ agentReadiness: readiness })
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Opens the host's model setup; false when the host offers none. */
|
|
373
|
+
openAgentSetup(): boolean {
|
|
374
|
+
if (!this.#openAgentSetup) return false
|
|
375
|
+
this.#openAgentSetup()
|
|
376
|
+
return true
|
|
357
377
|
}
|
|
358
378
|
|
|
359
379
|
/** The host's way to put a request in the conversation's composer for the author to finish; nothing is sent. */
|
|
@@ -474,6 +494,33 @@ export class Workbench {
|
|
|
474
494
|
return answer
|
|
475
495
|
}
|
|
476
496
|
|
|
497
|
+
/**
|
|
498
|
+
* A new document written by the AI from the author's source material: creates it at the end of the top level, keeps
|
|
499
|
+
* the files in its folder, opens it and hands the conversation's agent the request. A document whose files could not
|
|
500
|
+
* be added goes to the trash again. Answers the new document's ID and whether the request was sent.
|
|
501
|
+
*/
|
|
502
|
+
async writeFromMaterials(files: readonly File[], note: string, signal?: AbortSignal): Promise<{ document: string, asked: boolean }> {
|
|
503
|
+
if (!this.client.addDocumentMaterials || !this.tree.available) throw new Error('document-materials-unavailable')
|
|
504
|
+
const roots = this.#state.documentTree?.roots
|
|
505
|
+
const created = await this.client.operateTree!({ type: 'create', title: DOCUMENT_TREE_MESSAGES[this.#state.locale].untitled, parent: null, after: roots?.at(-1) ?? null }, signal)
|
|
506
|
+
const id = created.created
|
|
507
|
+
if (!id) throw new Error('document-materials-unavailable')
|
|
508
|
+
await Promise.all([this.tree.load(), this.loadDocuments()])
|
|
509
|
+
const dir = this.tree.dirOf(id)
|
|
510
|
+
let added: string[]
|
|
511
|
+
try {
|
|
512
|
+
if (dir === undefined) throw new Error('document-materials-document')
|
|
513
|
+
added = (await this.client.addDocumentMaterials(dir, files, signal)).files
|
|
514
|
+
} catch (error) {
|
|
515
|
+
await this.tree.operate({ type: 'trash', id }).catch(() => undefined)
|
|
516
|
+
throw error
|
|
517
|
+
}
|
|
518
|
+
this.#record('document.materials', { 'presmium.document': id, 'presmium.files': added.join('\n') })
|
|
519
|
+
await this.tree.openPlace({ document: id })
|
|
520
|
+
const asked = await this.askAgent(this.#messages.materialsRequest(added, note), [])
|
|
521
|
+
return { document: id, asked }
|
|
522
|
+
}
|
|
523
|
+
|
|
477
524
|
/** Upgrades the workspace's documents to the current format, then refreshes the document list. */
|
|
478
525
|
async migrateWorkspace(): Promise<import('@lincyaw/kernel').WorkspaceMigrationAnswer> {
|
|
479
526
|
if (!this.client.migrateWorkspace) throw new Error('workspace-migrate-unavailable')
|
package/src/workspace-client.ts
CHANGED
|
@@ -17,7 +17,7 @@ import type { DocumentTranscriptionRequest, TranscriptionCapabilities, Transcrip
|
|
|
17
17
|
import { randomUUID } from '@lincyaw/kernel'
|
|
18
18
|
import type { ReferenceTarget } from '@lincyaw/kernel'
|
|
19
19
|
// The contract's DocumentTree is the workspace's answer; the kernel's root also names its own tree builder DocumentTree.
|
|
20
|
-
import type { DocumentLinks, DocumentPreview, DocumentSearchHit, DocumentTree, EmbedSource, TreeOperation, TreeOperationResult } from '@lincyaw/kernel/contracts'
|
|
20
|
+
import type { DocumentLinks, DocumentPreview, DocumentSearchHit, DocumentTree, EmbedSource, TreeOperation, TreeOperationResult, WorkspaceAttention } from '@lincyaw/kernel/contracts'
|
|
21
21
|
|
|
22
22
|
/** A change of the host's pending approvals that this author may answer. */
|
|
23
23
|
export type ApprovalEvent =
|
|
@@ -83,6 +83,8 @@ export interface WorkspaceClient {
|
|
|
83
83
|
subscribeRequests?(listener: (event: WorkspaceRequestEvent) => void): () => void
|
|
84
84
|
readDocuments(document?: string): Promise<DocumentsAnswer>
|
|
85
85
|
importDocuments?(files: readonly File[], signal?: AbortSignal): Promise<import('@lincyaw/kernel').DocumentImportAnswer>
|
|
86
|
+
/** Keeps the files as the document's source material, in its folder, recorded as one revision. */
|
|
87
|
+
addDocumentMaterials?(document: string, files: readonly File[], signal?: AbortSignal): Promise<import('@lincyaw/kernel').DocumentMaterialsAnswer>
|
|
86
88
|
/** Converts the workspace's documents to the current format, one revision per document. */
|
|
87
89
|
migrateWorkspace?(): Promise<import('@lincyaw/kernel').WorkspaceMigrationAnswer>
|
|
88
90
|
/** The workspace's document tree and trash (absent for a host without one). */
|
|
@@ -92,8 +94,10 @@ export interface WorkspaceClient {
|
|
|
92
94
|
searchDocuments?(query: string, limit?: number, signal?: AbortSignal): Promise<DocumentSearchHit[]>
|
|
93
95
|
readDocumentPreview?(target: ReferenceTarget, signal?: AbortSignal): Promise<DocumentPreview>
|
|
94
96
|
readEmbedSource?(source: { document: string, block: string }, signal?: AbortSignal): Promise<EmbedSource>
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
+
/** References and synced blocks across the workspace whose target is gone or in the trash. */
|
|
98
|
+
readAttention?(signal?: AbortSignal): Promise<WorkspaceAttention>
|
|
99
|
+
/** Each change of the workspace's document tree (created, moved, renamed, trashed, restored), and of what `readAttention` answers. */
|
|
100
|
+
subscribeTree?(changed: (kind: 'tree' | 'attention') => void, failed?: () => void): () => void
|
|
97
101
|
planProjectChange(request: ProjectPlanRequest): Promise<ProjectPlan>
|
|
98
102
|
operateDocument(operation: ProjectOperation, planned?: ProjectPlan): Promise<OperationAnswer>
|
|
99
103
|
readSource(document: string, path: string): Promise<SourceAnswer>
|
|
@@ -391,6 +395,11 @@ export function workspaceClient(base = 'api/presmium/', subscription?: Workspace
|
|
|
391
395
|
for (const file of files) body.append('files', file, file.name)
|
|
392
396
|
return call(url('documents/import'), { method: 'POST', body, signal })
|
|
393
397
|
},
|
|
398
|
+
addDocumentMaterials: (document, files, signal) => {
|
|
399
|
+
const body = new FormData()
|
|
400
|
+
for (const file of files) body.append('files', file, file.name)
|
|
401
|
+
return call(url('document/materials', document), { method: 'POST', body, signal })
|
|
402
|
+
},
|
|
394
403
|
migrateWorkspace: () => call(url('workspace/migrate'), { method: 'POST' }),
|
|
395
404
|
readTree: signal => call(url('tree'), { signal }),
|
|
396
405
|
operateTree: (operation, signal) => post(url('tree/operation'), operation, signal),
|
|
@@ -403,7 +412,8 @@ export function workspaceClient(base = 'api/presmium/', subscription?: Workspace
|
|
|
403
412
|
const routes = new URL(base, globalThis.document.baseURI)
|
|
404
413
|
return answer.assets ? { ...answer, assets: Object.fromEntries(Object.entries(answer.assets).map(([id, address]) => [id, new URL(address, routes).href])) } : answer
|
|
405
414
|
},
|
|
406
|
-
|
|
415
|
+
readAttention: signal => call(url('tree/attention'), { signal }),
|
|
416
|
+
subscribeTree: (changed, failed) => subscribe<{ type?: string }>(url('tree/events', ''), 'tree', data => changed(data?.type === 'attention' ? 'attention' : 'tree'), failed),
|
|
407
417
|
readSource: (document, path) => call(url('source', document, { path })),
|
|
408
418
|
saveSource: (document, path, content, base, message) => post(url('source', document), { path, content, base, ...message ? { message } : {} }),
|
|
409
419
|
saveSourceTransaction: (document, changes, message) => post(url('source/transaction', document), { changes, ...message ? { message } : {} }),
|