@lincyaw/kernel 1.0.0-rc.0 → 1.0.0-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +7 -7
  2. package/package.json +6 -2
  3. package/src/access.ts +18 -0
  4. package/src/anchors.ts +5 -1
  5. package/src/authoring.ts +56 -0
  6. package/src/blocks.ts +0 -8
  7. package/src/component-code.ts +6 -0
  8. package/src/contracts/agent.ts +5 -82
  9. package/src/contracts/anchors.ts +46 -0
  10. package/src/contracts/authoring-actions.ts +60 -0
  11. package/src/contracts/authoring-clients.ts +213 -0
  12. package/src/contracts/authoring.ts +180 -0
  13. package/src/contracts/checks.ts +29 -0
  14. package/src/contracts/classroom.ts +49 -0
  15. package/src/contracts/diagnostics.ts +37 -0
  16. package/src/contracts/document-audio.ts +150 -0
  17. package/src/contracts/document-comments.ts +31 -0
  18. package/src/contracts/document-history.ts +63 -0
  19. package/src/contracts/document-image.ts +32 -0
  20. package/src/contracts/document-reads.ts +57 -0
  21. package/src/contracts/document-voice.ts +44 -0
  22. package/src/contracts/document.ts +240 -0
  23. package/src/contracts/execution.ts +4 -5
  24. package/src/contracts/locale.ts +3 -0
  25. package/src/contracts/offline.ts +2 -0
  26. package/src/contracts/plugin.ts +183 -0
  27. package/src/contracts/presenter-panels.ts +17 -0
  28. package/src/contracts/preview.ts +305 -310
  29. package/src/contracts/production-assets.ts +61 -0
  30. package/src/contracts/production.ts +109 -0
  31. package/src/contracts/projects.ts +59 -0
  32. package/src/contracts/server.ts +1 -51
  33. package/src/contracts/speech-settings.ts +16 -0
  34. package/src/contracts/speech.ts +82 -70
  35. package/src/contracts/steps.ts +15 -0
  36. package/src/contracts/transcription-adoption.ts +79 -0
  37. package/src/contracts/transcription.ts +112 -0
  38. package/src/contracts/voice.ts +97 -0
  39. package/src/contracts/voiceover-execution.ts +68 -0
  40. package/src/contracts/workspace.ts +458 -0
  41. package/src/contracts.ts +28 -278
  42. package/src/diagnostics.ts +7 -0
  43. package/src/document-authoring-actions.ts +47 -0
  44. package/src/document-caption-timings.ts +64 -0
  45. package/src/document-colors.ts +25 -0
  46. package/src/document-comments.ts +118 -0
  47. package/src/document-components.ts +251 -0
  48. package/src/document-operations.ts +132 -0
  49. package/src/document-pages.ts +215 -0
  50. package/src/document-reads.ts +81 -0
  51. package/src/document-schema.ts +85 -0
  52. package/src/document-voices.ts +153 -0
  53. package/src/document.ts +252 -0
  54. package/src/durations.ts +7 -0
  55. package/src/errors.ts +8 -0
  56. package/src/execution.ts +5 -1
  57. package/src/fingerprint.ts +1 -1
  58. package/src/follow.ts +26 -30
  59. package/src/git.ts +1 -1
  60. package/src/index.ts +66 -13
  61. package/src/ir.ts +54 -5
  62. package/src/jupyter-kernel.ts +9 -0
  63. package/src/kernel.ts +38 -25
  64. package/src/keyboard.ts +43 -0
  65. package/src/locale.ts +13 -0
  66. package/src/lock.ts +4 -8
  67. package/src/logging.ts +1 -1
  68. package/src/{markdown.ts → lower-myst.ts} +2 -1
  69. package/src/node/assets.ts +23 -0
  70. package/src/node/authoring-actions.ts +50 -0
  71. package/src/node/authoring-clients.ts +14 -0
  72. package/src/node/document-audio.ts +22 -0
  73. package/src/node/document-history.ts +11 -0
  74. package/src/node/document-image.ts +8 -0
  75. package/src/node/document-reads.ts +10 -0
  76. package/src/node/document-voice.ts +7 -0
  77. package/src/node/ffmpeg.ts +29 -0
  78. package/src/node/file-version.ts +6 -0
  79. package/src/node/fonts.ts +22 -0
  80. package/src/node/index.ts +29 -133
  81. package/src/node/installed-packages.ts +11 -0
  82. package/src/node/lines.ts +24 -0
  83. package/src/node/locale.ts +7 -0
  84. package/src/node/network.ts +11 -0
  85. package/src/node/operator-speech.ts +91 -0
  86. package/src/node/packages.ts +74 -0
  87. package/src/node/paths.ts +7 -0
  88. package/src/node/projects.ts +7 -0
  89. package/src/node/resources.ts +86 -0
  90. package/src/node/revision.ts +6 -0
  91. package/src/node/run-directory.ts +70 -0
  92. package/src/node/transcription-adoption.ts +9 -0
  93. package/src/node/transcription.ts +10 -0
  94. package/src/node/voiceover-routes.ts +73 -0
  95. package/src/node/voiceover.ts +199 -0
  96. package/src/page-source.ts +359 -0
  97. package/src/parameters.ts +81 -0
  98. package/src/preview-edit.ts +18 -0
  99. package/src/preview-events.ts +57 -0
  100. package/src/preview-frame.ts +1234 -0
  101. package/src/props.ts +17 -0
  102. package/src/push-stream.ts +67 -0
  103. package/src/reading.ts +12 -7
  104. package/src/recording.ts +38 -0
  105. package/src/renderer-components.ts +30 -0
  106. package/src/responses.ts +49 -0
  107. package/src/run-outputs.ts +15 -0
  108. package/src/runner.py +3 -3
  109. package/src/services.ts +6 -6
  110. package/src/slides.ts +36 -0
  111. package/src/speech-words.ts +76 -0
  112. package/src/speech.ts +13 -0
  113. package/src/step-keys.ts +38 -0
  114. package/src/steps.ts +7 -0
  115. package/src/transcription-adoption.ts +105 -0
  116. package/src/uri-decoding.ts +8 -0
  117. package/src/urls.ts +13 -0
  118. package/src/views.ts +47 -0
  119. package/src/voice.ts +86 -0
@@ -0,0 +1,458 @@
1
+ import type { IRDocument } from '../ir.ts'
2
+ import type { TeachingDocument, DocumentEditOperation, DocumentIssue } from './document.ts'
3
+ import type { Focus } from './agent.ts'
4
+ import type { Finding } from './checks.ts'
5
+ import type { Member } from './server.ts'
6
+ import { defineService } from './service.ts'
7
+
8
+ export type ReviewChangeKind = 'added' | 'modified' | 'deleted'
9
+
10
+ export interface ReviewChange {
11
+ path: string
12
+ kind: ReviewChangeKind
13
+ binary: boolean
14
+ added: number
15
+ removed: number
16
+ diff?: string
17
+ }
18
+
19
+ export interface ReviewStep {
20
+ id: string
21
+ label: string
22
+ tool?: string
23
+ at: string
24
+ changes: ReviewChange[]
25
+ }
26
+
27
+ export interface ChangeReview {
28
+ readonly root: string
29
+ readonly visibility: 'immediate' | 'on-commit'
30
+ step(label: string, tool?: string): Promise<ReviewStep>
31
+ steps(): readonly ReviewStep[]
32
+ diff(): Promise<ReviewChange[]>
33
+ restoreTo?(stepId: string): Promise<void>
34
+ accept(reject?: string[]): Promise<string[]>
35
+ rollback(): Promise<void>
36
+ close(): Promise<void>
37
+ }
38
+
39
+ export interface ChangeReviewService {
40
+ readonly engine: string
41
+ open(options: { document: string, task: string, member: Member }): Promise<ChangeReview>
42
+ }
43
+
44
+ export const CHANGE_REVIEW = defineService<ChangeReviewService>('presmium.changeReview')
45
+
46
+ export interface RevisionOrigin {
47
+ kind: 'agent' | 'document' | 'editor'
48
+ task?: string
49
+ member?: Member
50
+ }
51
+
52
+ export interface Revision {
53
+ id: string
54
+ message: string
55
+ author: string
56
+ date: string
57
+ origin: RevisionOrigin
58
+ files: string[]
59
+ revertedBy?: string
60
+ }
61
+
62
+ export type RevertResult = { ok: true, revision: Revision } | { ok: false, conflicts: string[] }
63
+
64
+ export interface RevisionService {
65
+ commit(change: { files: string[], message: string, origin: RevisionOrigin }): Promise<Revision | undefined>
66
+ history(filter?: { document?: string, task?: string, limit?: number }): Promise<Revision[]>
67
+ revert(id: string, member: Member): Promise<RevertResult>
68
+ }
69
+
70
+ export const REVISIONS = defineService<RevisionService>('presmium.revisions')
71
+
72
+ export interface DocumentLockService {
73
+ claim(document: string, holder: string): (() => void) | undefined
74
+ holder(document: string): string | undefined
75
+ }
76
+
77
+ export const DOCUMENT_LOCKS = defineService<DocumentLockService>('presmium.documentLocks')
78
+
79
+ export type DocumentFileChange =
80
+ | { path: string, content: Uint8Array, executable?: boolean, at?: number }
81
+ | { path: string, link: string }
82
+ | { path: string, remove: true }
83
+
84
+ export interface DocumentFiles {
85
+ write(changes: DocumentFileChange[]): Promise<void>
86
+ }
87
+
88
+ export const DOCUMENT_FILES = defineService<DocumentFiles>('presmium.documentFiles')
89
+
90
+ /** A document as lists show it: its directory (its identity), title, description, language and tags. */
91
+ export interface DocumentSummary {
92
+ dir: string
93
+ title: string
94
+ description?: string
95
+ lang?: string
96
+ tags?: string[]
97
+ }
98
+
99
+ /** @experimental The workspace service's answer to `documents`. */
100
+ export interface DocumentsAnswer {
101
+ title: string
102
+ documents: DocumentSummary[]
103
+ templates: string[]
104
+ git: boolean
105
+ branch?: string
106
+ uncommitted?: number
107
+ single: boolean
108
+ }
109
+
110
+ /** @experimental */
111
+ export type DocumentOperation =
112
+ | { op: 'create', dir: string, title?: string, template?: string }
113
+ | { op: 'rename', dir: string, to: string }
114
+ | { op: 'copy', dir: string, to: string, title?: string }
115
+ | { op: 'delete', dir: string }
116
+
117
+ /** @experimental A document operation as its commit records it. */
118
+ export type RevisionOperation =
119
+ | { op: 'create', dir: string }
120
+ | { op: 'delete', dir: string }
121
+ | { op: 'rename', dir: string, to: string }
122
+ | { op: 'copy', dir: string, to: string }
123
+
124
+ /** @experimental */
125
+ export interface OperationAnswer {
126
+ revision?: Revision
127
+ dir?: string
128
+ }
129
+
130
+ /** @experimental A revision as the history lists it; reverting a revert is a redo. */
131
+ export interface HistoryRevision extends Revision {
132
+ operation?: RevisionOperation
133
+ reverts?: string
134
+ redo?: true
135
+ /** Derived from the entire history, independent of the displayed page. */
136
+ undone?: boolean
137
+ revertible?: false
138
+ revertTarget?: string
139
+ }
140
+
141
+ /** @experimental The history of a document, newest first, and the revisions the next undo and redo take back. */
142
+ export interface RevisionsAnswer {
143
+ revisions: HistoryRevision[]
144
+ historyBinding?: import('./document-history.ts').DocumentHistoryBinding
145
+ nextOffset?: number
146
+ previousOffset?: number
147
+ loading?: boolean
148
+ /** The revision `history/undo` reverts. */
149
+ undo?: string
150
+ /** The revision `history/redo` reverts: the latest undo. */
151
+ redo?: string
152
+ }
153
+
154
+ /** @experimental */
155
+ export interface LockedAnswer {
156
+ error: string
157
+ locked: { document: string, holder: string }
158
+ }
159
+
160
+ /** @experimental A file of the workspace that the workbench can open. */
161
+ export interface SourceFile {
162
+ path: string
163
+ binary?: true
164
+ }
165
+
166
+ /** @experimental */
167
+ export interface FilesAnswer {
168
+ document: string
169
+ home: boolean
170
+ documents?: string[]
171
+ files: SourceFile[]
172
+ truncated?: true
173
+ }
174
+
175
+ /** @experimental */
176
+ export interface SourceAnswer {
177
+ path: string
178
+ content: string
179
+ version: string
180
+ }
181
+
182
+ /** The editable authority, available without building a runtime preview. */
183
+ export interface DocumentAnswer {
184
+ document: string
185
+ version: string
186
+ /** FNV-1a-64 of the exact authoritative bytes used to match a runtime snapshot. */
187
+ fingerprint: string
188
+ content: TeachingDocument
189
+ issues: DocumentIssue[]
190
+ }
191
+
192
+ /** Both author UIs and agents use this versioned submission boundary. */
193
+ export interface DocumentChange {
194
+ id: string
195
+ baseDocumentVersion: string
196
+ replacement?: TeachingDocument
197
+ operations?: DocumentEditOperation[]
198
+ fileChanges?: SourceTransactionChange[]
199
+ }
200
+
201
+ export interface DocumentChangeAnswer extends DocumentAnswer {
202
+ changeId: string
203
+ files: { path: string, version: string }[]
204
+ commit?: Revision
205
+ }
206
+
207
+ export const DOCUMENT_IMAGE_MAX_BYTES = 8 << 20
208
+ export const DOCUMENT_IMAGE_MEDIA_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/svg+xml', 'image/bmp'] as const
209
+ /** Multipart image import: this header and the original file share one source transaction. */
210
+ export interface DocumentImageImport { id: string, baseDocumentVersion: string }
211
+ export interface DocumentImageImportAnswer extends DocumentChangeAnswer { assetId: string, dimensions: { width: number, height: number } }
212
+
213
+ export interface DocumentEvent { document: string, version: string, valid: boolean, issues: DocumentIssue[], projectRevision?: string }
214
+
215
+ /** @experimental A saved source file; in a git workspace the save is a revision of its own. */
216
+ export interface SavedAnswer {
217
+ version: string
218
+ revision?: Revision
219
+ }
220
+
221
+ /** @experimental A fresh page-removal check; confirmation applies only to this source version. */
222
+ export interface PageDeletePlan {
223
+ document: string
224
+ section: string
225
+ revision: string
226
+ source: { path: string, version: string }
227
+ counts: { steps: number, blocks: number, narration: number }
228
+ last: boolean
229
+ allowed: boolean
230
+ reason?: string
231
+ references?: { document: string, section: string, block?: string }[]
232
+ }
233
+
234
+ /** @experimental Removes one page or retains an empty page when it was the last one. */
235
+ export interface PageDeleteRequest { section: string, revision: string, base: string }
236
+ export interface PageDeleteAnswer { document: string, selected: string, retainedEmpty: boolean, sourceVersion: string, irRevision: string, commit?: Revision }
237
+
238
+ /** @experimental One version-checked file in an authoring transaction; null creates a new file exclusively. */
239
+ export interface SourceTransactionChange {
240
+ path: string
241
+ content: string
242
+ base: string | null
243
+ }
244
+
245
+ /** @experimental Files saved together as one revision, or left unchanged together on failure. */
246
+ export interface SourceTransactionAnswer {
247
+ versions: { path: string, version: string }[]
248
+ revision?: Revision
249
+ }
250
+
251
+ /** @experimental */
252
+ export interface ConflictAnswer {
253
+ error: string
254
+ conflict: { version: string, content: string }
255
+ }
256
+
257
+ /** @experimental The body of a failed request to the workspace service. */
258
+ export interface ErrorAnswer {
259
+ error?: string
260
+ detail?: string
261
+ title?: string
262
+ conflict?: { version: string, content: string }
263
+ locked?: { document: string, holder: string }
264
+ exists?: true
265
+ ignored?: string[]
266
+ /** With `preview-preparing` (503): when to ask again. */
267
+ retryAfterMs?: number
268
+ }
269
+
270
+ /** @experimental */
271
+ export type UncommittedKind = 'added' | 'modified' | 'deleted'
272
+
273
+ /** @experimental */
274
+ export interface UncommittedFile {
275
+ path: string
276
+ kind: UncommittedKind
277
+ added?: number
278
+ removed?: number
279
+ }
280
+
281
+ /** @experimental */
282
+ export interface ChangesAnswer {
283
+ files: UncommittedFile[]
284
+ }
285
+
286
+ /** @experimental */
287
+ export interface CommitAnswer {
288
+ revision?: Revision
289
+ paths: string[]
290
+ }
291
+
292
+ /** Source syntax supported by the compiler that produced an answer, independent of authored metadata. */
293
+ export interface SourceCapabilities {
294
+ unicodePageTargets?: true
295
+ }
296
+
297
+ /** @experimental The compiled document with its IR revision. */
298
+ export interface IrAnswer {
299
+ document: string
300
+ revision: string
301
+ doc: IRDocument
302
+ diagnostics: Finding[]
303
+ sourceCapabilities?: SourceCapabilities
304
+ /** FNV-1a-64 of the exact authoring JSON text, including BOM; workspace-relative source paths. */
305
+ sourceFingerprints?: Record<string, string>
306
+ /** Workspace authoring endpoints available beside this compilation. */
307
+ authoring?: { deletePage?: true }
308
+ }
309
+
310
+ /** @experimental Sent on `ir/events` after each compilation. */
311
+ export interface IrEvent {
312
+ document: string
313
+ revision: string
314
+ diagnostics: { errors: number, warnings: number }
315
+ files: string[]
316
+ }
317
+
318
+ /** @experimental The renderer a preview shows. */
319
+ export type PreviewRenderer = 'web' | 'slides'
320
+
321
+ /** @experimental The dev servers' addresses for a document's previews. */
322
+ export interface PreviewAnswer {
323
+ document: string
324
+ web: string
325
+ slides?: string
326
+ }
327
+
328
+ /** @experimental What a document can be made into: its renderers and its plugins' exporters. */
329
+ export interface OutputTarget {
330
+ id: string
331
+ kind: 'render' | 'export'
332
+ /** By language; a renderer's id when its plugin gave none. */
333
+ label: Record<string, string>
334
+ }
335
+
336
+ /** @experimental */
337
+ export type JobState = 'queued' | 'running' | 'done' | 'failed' | 'cancelled'
338
+
339
+ /** @experimental A file a job made, below the job's address. */
340
+ export interface JobFile {
341
+ path: string
342
+ size: number
343
+ /** Its media type, by its extension. */
344
+ type: string
345
+ }
346
+
347
+ /** The exact saved authoring entry a build is requested from; independent of its derived IR revision. */
348
+ export interface JobSource {
349
+ version: string
350
+ fingerprint: string
351
+ }
352
+
353
+ /** An author's explicit request to render/export an acknowledged document version. */
354
+ export interface StartJobRequest {
355
+ target: string
356
+ source: JobSource
357
+ }
358
+
359
+ /** @experimental A build or an export of a document, run by the workspace service one at a time. */
360
+ export interface CompileJob {
361
+ id: string
362
+ /** Grows with each change of the job: of two copies, a client keeps the one with the greater. */
363
+ sequence: number
364
+ document: string
365
+ target: string
366
+ kind: OutputTarget['kind']
367
+ state: JobState
368
+ /** Host UI hint only; the server still authorizes every cancellation. Omission preserves the local host's behavior. */
369
+ canCancel?: boolean
370
+ /** The derived IR revision captured for this output; not the authoring document's save version. */
371
+ revision: string
372
+ /** Absent only in historical jobs created before source confirmation was recorded. */
373
+ source?: JobSource
374
+ /** Fingerprint of the additional files captured for this output, used for reuse checks. */
375
+ inputFingerprint?: string
376
+ /** Taken from an earlier job of the same target and revision. */
377
+ cached?: boolean
378
+ progress?: { phase: string, done?: number, total?: number }
379
+ createdAt: string
380
+ startedAt?: string
381
+ finishedAt?: string
382
+ /** The address its files are below (`<url><path>`). */
383
+ url: string
384
+ files: JobFile[]
385
+ /** The file to open first: a site's page, the video, the PDF. */
386
+ main?: string
387
+ /** The WebVTT captions of the main file (a video), by language. */
388
+ captions?: Record<string, string>
389
+ error?: string
390
+ warnings: string[]
391
+ /** The last lines of its log. */
392
+ log: string[]
393
+ }
394
+
395
+ /** @experimental The documents' builds and exports as jobs, as a host offers them (the workspace service). */
396
+ export interface OutputJobs {
397
+ /** What the document can be made into. */
398
+ targets(document: string): Promise<OutputTarget[]>
399
+ /** The jobs of the document (all, without one), newest first. */
400
+ list(document?: string): CompileJob[]
401
+ /** Confirms the optional saved source, then captures a fresh compilation. Reuse also requires identical source and inputs. */
402
+ start(document: string, target: string, source?: JobSource): Promise<CompileJob>
403
+ /** Runs start's checks without starting anything: the job start would reuse, or undefined when it would queue a new one. */
404
+ check(document: string, target: string, source?: JobSource): Promise<CompileJob | undefined>
405
+ /** Settles once the job has ended. */
406
+ wait(id: string): Promise<CompileJob>
407
+ cancel(id: string): CompileJob | undefined
408
+ }
409
+
410
+ /** @experimental */
411
+ export interface JobsAnswer {
412
+ targets: OutputTarget[]
413
+ jobs: CompileJob[]
414
+ }
415
+
416
+ /** @experimental */
417
+ /** Trusted author of this workspace connection; absence grants no native comment rights. */
418
+ export interface WorkbenchAnswer {
419
+ member?: Member
420
+ mcp: string
421
+ root?: string
422
+ }
423
+
424
+ /** @experimental */
425
+ export interface FocusAnswer {
426
+ document?: string
427
+ focus: Focus[] | null
428
+ reported?: string
429
+ }
430
+
431
+ /** @experimental The state of a change review as the workspace service shows it. */
432
+ export interface ReviewSnapshot {
433
+ id: string
434
+ document: string
435
+ engine: string
436
+ session: string
437
+ holder: string
438
+ turns: { from: number, to: number }
439
+ running: boolean
440
+ mode: 'required' | 'auto'
441
+ opened: string
442
+ steps: ReviewStep[]
443
+ changes: ReviewChange[]
444
+ }
445
+
446
+ /** @experimental */
447
+ export interface ReviewEnd {
448
+ outcome: 'accepted' | 'rejected' | 'rolled-back' | 'empty'
449
+ revision?: Revision
450
+ files: string[]
451
+ }
452
+
453
+ /** @experimental Sent on the `review` stream: the document's current review, or how it ended. */
454
+ export interface ReviewUpdate {
455
+ document: string
456
+ review?: ReviewSnapshot
457
+ ended?: ReviewEnd
458
+ }