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

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 +1220 -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,112 @@
1
+ import type { CanonicalSource } from '../ir.ts'
2
+ import type { TimeRange } from './document.ts'
3
+ import type { Member } from './server.ts'
4
+ import type { SpeechEngineInfo } from './speech.ts'
5
+ import type { Finding } from './checks.ts'
6
+
7
+ export const TRANSCRIPTION_REQUEST_MAX_BYTES = 32 << 10
8
+
9
+ export interface TranscriptionCapabilities {
10
+ source: CanonicalSource
11
+ available: boolean
12
+ status: 'available' | 'unavailable' | 'unknown'
13
+ reason?: 'speech-unavailable' | 'engine-unavailable' | 'audio-unavailable' | 'services-unavailable'
14
+ /** Provider declaration and local configuration are known; authentication/recognition is not verified. */
15
+ verification: 'configuration-only'
16
+ findings?: Finding[]
17
+ engines: SpeechEngineInfo[]
18
+ range: 'whole-asset'
19
+ limits: { audioBytes: number, durationMs: number, tasks: number, requestBytes: number }
20
+ }
21
+
22
+ /** A confirmed recognition request; no script, clip or voice selection is changed. */
23
+ export interface DocumentTranscriptionRequest {
24
+ intent: string
25
+ source: CanonicalSource
26
+ assetId: string
27
+ audioSha256: string
28
+ engine: string
29
+ lang?: string
30
+ hints?: string[]
31
+ confirmed: true
32
+ }
33
+
34
+ /** Agent input excludes host confirmation; HTTP and Node validate the confirmed form below. */
35
+ export const DOCUMENT_TRANSCRIPTION_INPUT_SCHEMA = {
36
+ type: 'object', additionalProperties: false,
37
+ properties: {
38
+ intent: { type: 'string', pattern: '^[A-Za-z\\d_-]{16,128}$' },
39
+ source: { type: 'object', additionalProperties: false, properties: { documentId: { type: 'string', minLength: 1, maxLength: 200 }, version: { type: 'string', pattern: '^[a-f\\d]{20}$' }, fingerprint: { type: 'string', pattern: '^[a-f\\d]{16}$' } }, required: ['documentId', 'version', 'fingerprint'] },
40
+ assetId: { type: 'string', minLength: 1, maxLength: 200 },
41
+ audioSha256: { type: 'string', pattern: '^[a-f\\d]{64}$' },
42
+ engine: { type: 'string', minLength: 1, maxLength: 128 },
43
+ lang: { type: 'string', minLength: 1, maxLength: 64 },
44
+ hints: { type: 'array', maxItems: 100, items: { type: 'string', maxLength: 200 } },
45
+ },
46
+ required: ['intent', 'source', 'assetId', 'audioSha256', 'engine'],
47
+ } as const
48
+
49
+ export const DOCUMENT_TRANSCRIPTION_REQUEST_SCHEMA = {
50
+ ...DOCUMENT_TRANSCRIPTION_INPUT_SCHEMA,
51
+ properties: { ...DOCUMENT_TRANSCRIPTION_INPUT_SCHEMA.properties, confirmed: { const: true } },
52
+ required: [...DOCUMENT_TRANSCRIPTION_INPUT_SCHEMA.required, 'confirmed'],
53
+ } as const
54
+
55
+ export interface TranscriptionRevision {
56
+ transcriptionId: string
57
+ revision: string
58
+ createdAt: string
59
+ source: CanonicalSource
60
+ audio: { assetId: string, sha256: string, sourceRange: TimeRange }
61
+ request: { engine: string, provider: string, local: boolean, lang?: string, hints: string[], fingerprint: string }
62
+ result: {
63
+ lang: string
64
+ text: string
65
+ segments: { id: string, text: string, startMs?: number, endMs?: number, words?: { text: string, startMs: number, endMs: number }[] }[]
66
+ }
67
+ timing: 'words' | 'segments' | 'none'
68
+ warnings: string[]
69
+ }
70
+
71
+ export type TranscriptionTaskState = 'queued' | 'running' | 'cancelling' | 'cancelled' | 'done' | 'failed'
72
+ export interface TranscriptionTask {
73
+ kind: 'transcription'
74
+ id: string
75
+ intent: string
76
+ document: string
77
+ source: CanonicalSource
78
+ audio: { assetId: string, sha256: string }
79
+ sequence: number
80
+ state: TranscriptionTaskState
81
+ current: boolean
82
+ staleReason?: 'document-changed' | 'document-unavailable' | 'audio-changed'
83
+ progress: { phase: 'queued' | 'recognizing' | 'saving' | 'finished' }
84
+ createdAt: string
85
+ startedAt?: string
86
+ finishedAt?: string
87
+ result?: { transcriptionId: string, revision: string }
88
+ error?: string
89
+ }
90
+
91
+ export interface TranscriptionCancellation { intent: string, state: TranscriptionTaskState, task?: TranscriptionTask }
92
+ export interface TranscriptionListAnswer {
93
+ tasks: TranscriptionTask[]
94
+ issues: { id: string, code: string }[]
95
+ truncated?: true
96
+ }
97
+
98
+ /** Workspace-owned authoring capability, shared by HTTP and agent adapters. */
99
+ export interface DocumentTranscriptions {
100
+ capabilities(document: string, member: Member): Promise<TranscriptionCapabilities>
101
+ start(document: string, request: DocumentTranscriptionRequest, member: Member, signal?: AbortSignal): Promise<TranscriptionTask>
102
+ list(document: string, member: Member): Promise<TranscriptionListAnswer>
103
+ get(document: string, query: { id: string } | { intent: string }, member: Member): Promise<TranscriptionTask>
104
+ readResult(document: string, id: string, revision: string, member: Member): Promise<TranscriptionRevision>
105
+ /** Rechecks current canonical source and the exact original audio, without recognizing it again. */
106
+ verifyResult(document: string, id: string, revision: string, source: CanonicalSource, member: Member): Promise<TranscriptionRevision>
107
+ cancel(document: string, query: { id: string } | { intent: string }, member: Member): Promise<TranscriptionCancellation>
108
+ /** Checks a start with the same path, without storing a task or calling the provider, so an agent asks only for one that would run. */
109
+ checkStart(document: string, request: DocumentTranscriptionRequest, member: Member, signal?: AbortSignal): Promise<void>
110
+ /** Undefined when there is something to cancel; otherwise the unchanged state that cancel would report. */
111
+ checkCancel(document: string, query: { id: string } | { intent: string }, member: Member): Promise<TranscriptionCancellation | undefined>
112
+ }
@@ -0,0 +1,97 @@
1
+ import type { SpeechEngineInfo, SpeechVoice, VoiceCatalog } from './speech.ts'
2
+ import type { CanonicalSource } from '../ir.ts'
3
+ import { defineService } from './service.ts'
4
+
5
+ /** A step number is usable only with the structure binding returned by the current snapshot. */
6
+ export interface VoiceTarget { section: string, step: number, binding: string }
7
+ export type VoiceScope = { kind: 'document' } | { kind: 'page', section: string } | { kind: 'step', target: VoiceTarget } | { kind: 'steps', targets: VoiceTarget[] }
8
+ export interface StepVoiceOverride extends VoiceTarget { voice: SpeechVoice }
9
+ export interface VoiceOverrides { pages: Record<string, SpeechVoice>, steps: StepVoiceOverride[] }
10
+ export interface ResolvedVoice {
11
+ target: VoiceTarget
12
+ voice?: SpeechVoice
13
+ inheritedFrom: 'step' | 'page' | 'document' | 'unset'
14
+ override?: SpeechVoice
15
+ editable: boolean
16
+ reason?: 'cue-step' | 'step-binding-stale' | 'recording-unavailable'
17
+ }
18
+ /** Registered by the actual lecture plugin implementation, never inferred from authored configuration. */
19
+ export const VOICEOVER = defineService<{ version: 1, preview: true }>('presmium.voiceover')
20
+ export interface VoiceoverCapability {
21
+ available: boolean
22
+ reason?: 'not-configured' | 'voice-unset' | 'step-binding-stale' | 'speech-unavailable' | 'voice-unavailable' | 'catalog-unavailable'
23
+ providers: SpeechEngineInfo[]
24
+ defaultEngine?: string
25
+ }
26
+ export interface VoiceoverStepStatus {
27
+ target: VoiceTarget
28
+ stepId?: string
29
+ state: 'ready' | 'missing' | 'blocked' | 'empty'
30
+ utterances: number
31
+ cached: number
32
+ reason?: string
33
+ }
34
+ export interface VoiceoverSnapshot {
35
+ revision: string
36
+ source: CanonicalSource
37
+ capability: VoiceoverCapability
38
+ steps: VoiceoverStepStatus[]
39
+ jobs: VoiceoverJob[]
40
+ /** Real speech units whose source cannot yet be assigned to one full-document step. */
41
+ unboundByPage?: { section: string, state: VoiceoverStepStatus['state'], utterances: number, cached: number, reason?: string }[]
42
+ }
43
+ export type VoiceoverJobState = 'queued' | 'running' | 'cancelling' | 'cancelled' | 'done' | 'failed' | 'stale'
44
+ export interface VoiceoverJob {
45
+ id: string
46
+ sequence: number
47
+ /** Client-owned generation intent, available before the job response is delivered. */
48
+ intent: string
49
+ revision: string
50
+ source: CanonicalSource
51
+ scope: VoiceScope
52
+ state: VoiceoverJobState
53
+ total: number
54
+ completed: number
55
+ failed: number
56
+ createdAt: string
57
+ startedAt?: string
58
+ finishedAt?: string
59
+ error?: string
60
+ }
61
+ export interface VoiceoverRequest { intent: string, revision: string, source: CanonicalSource, scope: VoiceScope, confirmed: boolean }
62
+ /** Cancellation can precede admission; a pre-admission refusal is not a fabricated job. */
63
+ export interface VoiceoverCancellation { intent: string, state: VoiceoverJobState, job?: VoiceoverJob }
64
+ export interface VoicePreviewRequest {
65
+ revision: string
66
+ source: CanonicalSource
67
+ voice: SpeechVoice
68
+ mode: 'sample' | 'step'
69
+ target?: VoiceTarget
70
+ confirmed: boolean
71
+ quote: string
72
+ }
73
+ export type VoicePreviewQuery = Omit<VoicePreviewRequest, 'confirmed' | 'quote' | 'source'>
74
+ export interface VoicePreviewQuote extends VoicePreviewQuery {
75
+ source: CanonicalSource
76
+ text: string
77
+ provider: string
78
+ local: boolean
79
+ cached: boolean
80
+ quote: string
81
+ }
82
+ export interface VoicePreviewAnswer {
83
+ revision: string
84
+ source: CanonicalSource
85
+ voice: SpeechVoice
86
+ text: string
87
+ cached: boolean
88
+ key: string
89
+ audio: string
90
+ duration: number
91
+ provider: string
92
+ }
93
+ export interface VoiceCatalogAnswer {
94
+ engines: SpeechEngineInfo[]
95
+ catalog: VoiceCatalog
96
+ engine?: string
97
+ }
@@ -0,0 +1,68 @@
1
+ import type { CanonicalSource } from '../ir.ts'
2
+ import type { Member } from './server.ts'
3
+ import type { VoiceoverCancellation, VoiceoverJob, VoiceoverRequest, VoiceoverSnapshot, VoicePreviewAnswer, VoicePreviewQuery, VoicePreviewQuote, VoicePreviewRequest } from './voice.ts'
4
+ import { defineService } from './service.ts'
5
+
6
+ export interface VoiceoverStatusQuery { source?: CanonicalSource, revision?: string }
7
+ export type VoiceoverStart = Omit<VoiceoverRequest, 'confirmed'>
8
+ export type VoicePreviewStart = Omit<VoicePreviewRequest, 'confirmed'>
9
+ export type VoicePreviewCheck = VoicePreviewQuery & { source?: CanonicalSource }
10
+ export type VoiceoverJobQuery = { id: string } | { intent: string }
11
+ export interface VoiceoverProgress { completed: number, failed: number, error?: string }
12
+ export interface VoiceoverRunResult extends VoiceoverProgress { state: 'done' | 'failed' | 'stale' | 'cancelled' }
13
+ /** A claim on the existing generation lock. Dispose after execution or failed admission. */
14
+ export interface PreparedVoiceover {
15
+ source: CanonicalSource
16
+ revision: string
17
+ scope: VoiceoverStart['scope']
18
+ total: number
19
+ run(signal: AbortSignal, progress: (value: VoiceoverProgress) => void): Promise<VoiceoverRunResult>
20
+ dispose(): void
21
+ }
22
+ export interface VoicePreviewMedia extends Omit<VoicePreviewAnswer, 'audio'> { bytes: Uint8Array, mediaType: string }
23
+ /** Stateless plugin execution. The host owns intents and jobs; discovery creates neither. */
24
+ export interface VoiceoverExecution {
25
+ status(query: VoiceoverStatusQuery, signal: AbortSignal): Promise<Omit<VoiceoverSnapshot, 'jobs'>>
26
+ prepare(request: VoiceoverStart, signal: AbortSignal): Promise<PreparedVoiceover>
27
+ quote(query: VoicePreviewCheck, signal: AbortSignal): Promise<VoicePreviewQuote>
28
+ preview(request: VoicePreviewStart, signal: AbortSignal): Promise<VoicePreviewMedia>
29
+ }
30
+ export const VOICEOVER_EXECUTION = defineService<VoiceoverExecution>('presmium.voiceoverExecution')
31
+
32
+ export interface VoiceoverObservation extends VoiceoverCancellation { error?: string, current?: boolean | 'unknown' }
33
+ export interface VoiceoverJobsAnswer { document: string, jobs: (VoiceoverJob & { current: boolean | 'unknown' })[], idempotency: 'process', limits: { intents: number, recentJobs: number } }
34
+ export interface VoicePreviewResource extends Omit<VoicePreviewAnswer, 'audio'> { id: string, mediaType: string, byteLength: number, sha256: string }
35
+ export interface VoicePreviewResourceData { resource: VoicePreviewResource, bytes: Uint8Array }
36
+ /** Shared author entry. Adapters obtain spending approval; model input cannot supply confirmation. */
37
+ export interface DocumentVoiceTasks {
38
+ snapshot(document: string, query: VoiceoverStatusQuery, member: Member, signal?: AbortSignal): Promise<VoiceoverSnapshot>
39
+ listJobs(document: string, member: Member): Promise<VoiceoverJobsAnswer>
40
+ getJob(document: string, query: VoiceoverJobQuery, member: Member): Promise<VoiceoverObservation>
41
+ start(document: string, request: VoiceoverStart, member: Member, signal?: AbortSignal): Promise<VoiceoverJob>
42
+ cancel(document: string, query: VoiceoverJobQuery, member: Member): Promise<VoiceoverCancellation>
43
+ quotePreview(document: string, query: VoicePreviewCheck, member: Member, signal?: AbortSignal): Promise<VoicePreviewQuote>
44
+ preview(document: string, request: VoicePreviewStart, member: Member, signal?: AbortSignal): Promise<VoicePreviewResource>
45
+ readPreview(document: string, id: string, member: Member): Promise<VoicePreviewResourceData>
46
+ }
47
+ export const DOCUMENT_VOICE_TASKS = defineService<DocumentVoiceTasks>('presmium.documentVoiceTasks')
48
+
49
+ const source = { type: 'object', additionalProperties: false, properties: { documentId: { type: 'string', minLength: 1, maxLength: 200 }, version: { type: 'string', pattern: '^[a-f\\d]{20}$' }, fingerprint: { type: 'string', pattern: '^[a-f\\d]{16}$' } }, required: ['documentId', 'version', 'fingerprint'] } as const
50
+ const revision = { type: 'string', pattern: '^[a-f\\d]{16}$' } as const
51
+ const target = { type: 'object', additionalProperties: false, properties: { section: { type: 'string', minLength: 1, maxLength: 200 }, step: { type: 'integer', minimum: 0 }, binding: revision }, required: ['section', 'step', 'binding'] } as const
52
+ const scope = { oneOf: [
53
+ { type: 'object', additionalProperties: false, properties: { kind: { const: 'document' } }, required: ['kind'] },
54
+ { type: 'object', additionalProperties: false, properties: { kind: { const: 'page' }, section: target.properties.section }, required: ['kind', 'section'] },
55
+ { type: 'object', additionalProperties: false, properties: { kind: { const: 'step' }, target }, required: ['kind', 'target'] },
56
+ { type: 'object', additionalProperties: false, properties: { kind: { const: 'steps' }, targets: { type: 'array', items: target, minItems: 1, maxItems: 500 } }, required: ['kind', 'targets'] },
57
+ ] } as const
58
+ const intent = { type: 'string', pattern: '^[A-Za-z\\d_-]{16,128}$' } as const
59
+ export const VOICEOVER_STATUS_SCHEMA = { type: 'object', additionalProperties: false, properties: { source, revision } } as const
60
+ export const VOICEOVER_START_SCHEMA = { type: 'object', additionalProperties: false, properties: { intent, source, revision, scope }, required: ['intent', 'source', 'revision', 'scope'] } as const
61
+ export const VOICEOVER_JOB_QUERY_SCHEMA = { oneOf: [
62
+ { type: 'object', additionalProperties: false, properties: { id: { type: 'string', pattern: '^[a-f\\d]{8}-[a-f\\d]{4}-[a-f\\d]{4}-[a-f\\d]{4}-[a-f\\d]{12}$' } }, required: ['id'] },
63
+ { type: 'object', additionalProperties: false, properties: { intent }, required: ['intent'] },
64
+ ] } as const
65
+ const voice = { type: 'object', additionalProperties: false, properties: { voice: { type: 'string', minLength: 1, maxLength: 200 }, engine: { type: 'string', minLength: 1, maxLength: 200 }, rate: { type: 'number', exclusiveMinimum: 0 }, style: { type: 'string', maxLength: 200 } }, required: ['voice'] } as const
66
+ const preview = { revision, source, voice, mode: { enum: ['sample', 'step'] }, target } as const
67
+ export const VOICE_PREVIEW_CHECK_SCHEMA = { type: 'object', additionalProperties: false, properties: preview, required: ['revision', 'voice', 'mode'], allOf: [{ if: { properties: { mode: { const: 'step' } } }, then: { required: ['target'] } }] } as const
68
+ export const VOICE_PREVIEW_START_SCHEMA = { type: 'object', additionalProperties: false, properties: { ...preview, quote: { type: 'string', pattern: '^[a-f\\d]{64}$' } }, required: ['source', 'revision', 'voice', 'mode', 'quote'], allOf: VOICE_PREVIEW_CHECK_SCHEMA.allOf } as const