@lincyaw/kernel 0.0.0-stage → 1.0.0-rc.1

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 (128) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +32 -2
  3. package/package.json +41 -3
  4. package/src/access.ts +18 -0
  5. package/src/anchors.ts +58 -0
  6. package/src/authoring.ts +56 -0
  7. package/src/blocks.ts +19 -0
  8. package/src/checks.ts +35 -0
  9. package/src/component-code.ts +6 -0
  10. package/src/contracts/agent.ts +76 -0
  11. package/src/contracts/anchors.ts +46 -0
  12. package/src/contracts/authoring-actions.ts +60 -0
  13. package/src/contracts/authoring-clients.ts +213 -0
  14. package/src/contracts/authoring.ts +180 -0
  15. package/src/contracts/checks.ts +29 -0
  16. package/src/contracts/classroom.ts +49 -0
  17. package/src/contracts/diagnostics.ts +37 -0
  18. package/src/contracts/document-audio.ts +150 -0
  19. package/src/contracts/document-comments.ts +31 -0
  20. package/src/contracts/document-history.ts +63 -0
  21. package/src/contracts/document-image.ts +32 -0
  22. package/src/contracts/document-reads.ts +57 -0
  23. package/src/contracts/document-voice.ts +44 -0
  24. package/src/contracts/document.ts +240 -0
  25. package/src/contracts/execution.ts +118 -0
  26. package/src/contracts/locale.ts +3 -0
  27. package/src/contracts/offline.ts +2 -0
  28. package/src/contracts/operations.ts +8 -0
  29. package/src/contracts/plugin.ts +183 -0
  30. package/src/contracts/presenter-panels.ts +17 -0
  31. package/src/contracts/preview.ts +386 -0
  32. package/src/contracts/production-assets.ts +61 -0
  33. package/src/contracts/production.ts +109 -0
  34. package/src/contracts/projects.ts +59 -0
  35. package/src/contracts/server.ts +108 -0
  36. package/src/contracts/service.ts +8 -0
  37. package/src/contracts/speech-settings.ts +16 -0
  38. package/src/contracts/speech.ts +149 -0
  39. package/src/contracts/steps.ts +15 -0
  40. package/src/contracts/transcription-adoption.ts +79 -0
  41. package/src/contracts/transcription.ts +112 -0
  42. package/src/contracts/voice.ts +97 -0
  43. package/src/contracts/voiceover-execution.ts +68 -0
  44. package/src/contracts/workspace.ts +458 -0
  45. package/src/contracts.ts +35 -0
  46. package/src/diagnostics.ts +7 -0
  47. package/src/document-authoring-actions.ts +47 -0
  48. package/src/document-caption-timings.ts +64 -0
  49. package/src/document-colors.ts +25 -0
  50. package/src/document-comments.ts +118 -0
  51. package/src/document-components.ts +251 -0
  52. package/src/document-operations.ts +132 -0
  53. package/src/document-pages.ts +215 -0
  54. package/src/document-reads.ts +81 -0
  55. package/src/document-schema.ts +85 -0
  56. package/src/document-voices.ts +153 -0
  57. package/src/document.ts +252 -0
  58. package/src/durations.ts +7 -0
  59. package/src/errors.ts +15 -0
  60. package/src/events.ts +32 -0
  61. package/src/execution.ts +25 -0
  62. package/src/fingerprint.ts +31 -0
  63. package/src/follow.ts +33 -0
  64. package/src/git.ts +12 -0
  65. package/src/html.ts +41 -0
  66. package/src/index.ts +82 -0
  67. package/src/ir.ts +367 -0
  68. package/src/jupyter-kernel.ts +9 -0
  69. package/src/kernel.ts +190 -0
  70. package/src/keyboard.ts +43 -0
  71. package/src/locale.ts +13 -0
  72. package/src/lock.ts +81 -0
  73. package/src/logging.ts +11 -0
  74. package/src/lower-myst.ts +312 -0
  75. package/src/node/assets.ts +23 -0
  76. package/src/node/authoring-actions.ts +50 -0
  77. package/src/node/authoring-clients.ts +14 -0
  78. package/src/node/document-audio.ts +22 -0
  79. package/src/node/document-history.ts +11 -0
  80. package/src/node/document-image.ts +8 -0
  81. package/src/node/document-reads.ts +10 -0
  82. package/src/node/document-voice.ts +7 -0
  83. package/src/node/ffmpeg.ts +29 -0
  84. package/src/node/file-version.ts +6 -0
  85. package/src/node/fonts.ts +22 -0
  86. package/src/node/index.ts +29 -0
  87. package/src/node/installed-packages.ts +11 -0
  88. package/src/node/lines.ts +24 -0
  89. package/src/node/locale.ts +7 -0
  90. package/src/node/network.ts +11 -0
  91. package/src/node/operator-speech.ts +91 -0
  92. package/src/node/packages.ts +74 -0
  93. package/src/node/paths.ts +7 -0
  94. package/src/node/projects.ts +7 -0
  95. package/src/node/resources.ts +86 -0
  96. package/src/node/revision.ts +6 -0
  97. package/src/node/run-directory.ts +70 -0
  98. package/src/node/strip-types.mjs +15 -0
  99. package/src/node/transcription-adoption.ts +9 -0
  100. package/src/node/transcription.ts +10 -0
  101. package/src/node/voiceover-routes.ts +73 -0
  102. package/src/node/voiceover.ts +199 -0
  103. package/src/page-source.ts +359 -0
  104. package/src/parameters.ts +81 -0
  105. package/src/preview-edit.ts +18 -0
  106. package/src/preview-events.ts +57 -0
  107. package/src/preview-frame.ts +1220 -0
  108. package/src/props.ts +17 -0
  109. package/src/published.ts +11 -0
  110. package/src/push-stream.ts +67 -0
  111. package/src/reading.ts +96 -0
  112. package/src/recording.ts +38 -0
  113. package/src/renderer-components.ts +30 -0
  114. package/src/requests.ts +28 -0
  115. package/src/responses.ts +49 -0
  116. package/src/run-outputs.ts +15 -0
  117. package/src/runner.py +454 -0
  118. package/src/services.ts +146 -0
  119. package/src/slides.ts +36 -0
  120. package/src/speech-words.ts +76 -0
  121. package/src/speech.ts +13 -0
  122. package/src/step-keys.ts +38 -0
  123. package/src/steps.ts +7 -0
  124. package/src/transcription-adoption.ts +105 -0
  125. package/src/uri-decoding.ts +8 -0
  126. package/src/urls.ts +13 -0
  127. package/src/views.ts +47 -0
  128. package/src/voice.ts +86 -0
@@ -0,0 +1,118 @@
1
+ import type { Logger, Unsubscribe } from './plugin.ts'
2
+ import { defineService } from './service.ts'
3
+
4
+ export interface RunRequest {
5
+ lang: string
6
+ code: string
7
+ args?: Record<string, string>
8
+ stdin?: string
9
+ timeoutMs?: number
10
+ files?: Record<string, string>
11
+ executor?: string
12
+ session?: string
13
+ place?: { section: string, block: string }
14
+ }
15
+
16
+ export type RunOutput =
17
+ | { output_type: 'stream', name: 'stdout' | 'stderr', text: string }
18
+ | { output_type: 'display_data' | 'execute_result', data: Record<string, unknown>, metadata?: Record<string, unknown> }
19
+ | { output_type: 'error', ename: string, evalue: string, traceback: string[] }
20
+
21
+ export interface RunResult {
22
+ ok: boolean
23
+ stdout: string
24
+ stderr: string
25
+ exitCode: number | null
26
+ durationMs: number
27
+ timedOut: boolean
28
+ source: 'live' | 'recorded'
29
+ executorId: string
30
+ outputs?: RunOutput[]
31
+ }
32
+
33
+ export interface RunContext {
34
+ env: Readonly<Record<string, string>>
35
+ sandbox?: ProcessSandbox
36
+ lang?: string
37
+ }
38
+
39
+ export interface SandboxRun {
40
+ argv: string[]
41
+ files: Record<string, string | Uint8Array>
42
+ collect: string[]
43
+ env: Readonly<Record<string, string>>
44
+ read: string[]
45
+ timeoutMs: number
46
+ signal?: AbortSignal
47
+ }
48
+
49
+ export interface SandboxResult {
50
+ exitCode: number | null
51
+ stdout: string
52
+ stderr: string
53
+ files: Record<string, Uint8Array>
54
+ }
55
+
56
+ export interface ProcessSandbox {
57
+ readonly kind: string
58
+ run(request: SandboxRun): Promise<SandboxResult>
59
+ }
60
+
61
+ export const PROCESS_SANDBOX = defineService<ProcessSandbox>('presmium.processSandbox')
62
+
63
+ export interface Executor {
64
+ readonly id: string
65
+ readonly runsIn?: 'browser' | 'machine'
66
+ supports(lang: string): boolean
67
+ run(request: RunRequest, signal?: AbortSignal, ctx?: RunContext): Promise<RunResult>
68
+ fingerprint?(lang: string): string | Promise<string>
69
+ revision?(lang: string): string | Promise<string>
70
+ endSession?(session: string): Promise<void>
71
+ params?(lang: string): ParamsDisplay | undefined
72
+ }
73
+
74
+ export interface ParamsDisplay {
75
+ labels: Record<string, string>
76
+ fields?: string[]
77
+ summary?(args: Record<string, string>): string
78
+ }
79
+
80
+ export interface ExecutorRouter extends Executor {
81
+ register(executor: Executor, priority?: number): Unsubscribe
82
+ list(): Executor[]
83
+ }
84
+
85
+ export const EXECUTOR = defineService<ExecutorRouter>('presmium.executor')
86
+
87
+ export type EnvironmentAuth = 'none' | 'env' | 'proxy' | 'prompt' | 'hub'
88
+
89
+ export interface EnvironmentSpec {
90
+ kind: string
91
+ url?: string
92
+ kernel?: string
93
+ languages?: string[]
94
+ auth?: EnvironmentAuth
95
+ /** Operator-defined JupyterHub environment profile; images and resource limits stay on the Hub. */
96
+ profile?: string
97
+ image?: string
98
+ path?: string
99
+ [option: string]: unknown
100
+ }
101
+
102
+ export interface ExecuteConfig {
103
+ env?: string
104
+ environments?: Record<string, EnvironmentSpec>
105
+ rerun?: 'environment'
106
+ }
107
+
108
+ export interface EnvironmentContext {
109
+ deckDir: string
110
+ workspaceRoot: string
111
+ secret(name: string): string | undefined
112
+ log: Logger
113
+ }
114
+
115
+ export interface EnvironmentProvider {
116
+ create(name: string, spec: EnvironmentSpec, ctx: EnvironmentContext): Executor | Promise<Executor>
117
+ probe?(name: string, spec: EnvironmentSpec, ctx: EnvironmentContext): Promise<string | undefined>
118
+ }
@@ -0,0 +1,3 @@
1
+ export type Locale = 'zh-CN' | 'en'
2
+
3
+ export const DEFAULT_LANG = 'zh-CN'
@@ -0,0 +1,2 @@
1
+ /** The requests a page sends the web form's service worker, with a MessageChannel port for the answer. */
2
+ export const OFFLINE_REQUESTS = { runtimes: 'presmium:offline-runtimes', save: 'presmium:save-offline' } as const
@@ -0,0 +1,8 @@
1
+ export interface Operation {
2
+ type: string
3
+ data: Record<string, unknown>
4
+ }
5
+
6
+ export type TrackEvent = [t: number, type: string, data: Record<string, unknown>]
7
+
8
+ export type UtteranceAnchor = [utterance: string, offset: number]
@@ -0,0 +1,183 @@
1
+ import type { CanonicalSource, DirectiveSpec, IRDocument, IRPass, Renderer, RendererContribution, RoleSpec } from '../ir.ts'
2
+ import type { AgentTool } from './agent.ts'
3
+ import type { AnchorResolver, AnchorString } from './anchors.ts'
4
+ import type { Check, CheckContext } from './checks.ts'
5
+ import type { EnvironmentProvider, EnvironmentSpec, Executor } from './execution.ts'
6
+ import type { NodeServiceContext, ServerContext, ServerContribution } from './server.ts'
7
+ import type { Locale } from './locale.ts'
8
+ import type { ServiceToken } from './service.ts'
9
+
10
+ export const KERNEL_VERSION = '1.0.0'
11
+
12
+ export type Capability = 'fs' | 'network' | 'exec' | 'git'
13
+
14
+ export interface ServiceRequirement {
15
+ token: ServiceToken<unknown>
16
+ optional?: boolean
17
+ }
18
+
19
+ export interface PluginManifest {
20
+ id: string
21
+ /** The name readers and authors see (the startup report), in both interface languages; the id is never shown. */
22
+ name?: Record<Locale, string>
23
+ version: string
24
+ kernel: string
25
+ provides?: ServiceToken<unknown>[]
26
+ requires?: ServiceRequirement[]
27
+ capabilities?: Capability[]
28
+ }
29
+
30
+ export type PresentationMode = 'slides' | 'document'
31
+
32
+ export interface Logger {
33
+ debug(...args: unknown[]): void
34
+ info(...args: unknown[]): void
35
+ warn(...args: unknown[]): void
36
+ error(...args: unknown[]): void
37
+ }
38
+
39
+ export type Unsubscribe = () => void
40
+
41
+ export interface DomainEvent<Type extends string = string, Payload = unknown> {
42
+ type: Type
43
+ payload: Payload
44
+ }
45
+
46
+ export interface EventBus {
47
+ emit(event: DomainEvent): void
48
+ on<E extends DomainEvent>(type: E['type'], handler: (event: E) => void): Unsubscribe
49
+ }
50
+
51
+ export interface PluginContext {
52
+ config: Record<string, unknown>
53
+ mode: PresentationMode
54
+ provide<T>(token: ServiceToken<T>, implementation: T): void
55
+ get<T>(token: ServiceToken<T>): T
56
+ tryGet<T>(token: ServiceToken<T>): T | undefined
57
+ events: EventBus
58
+ log: Logger
59
+ environments?: Readonly<Record<string, EnvironmentSpec>>
60
+ }
61
+
62
+ export interface PluginDefinition {
63
+ manifest: PluginManifest
64
+ /** Opt in only when dispose stops every resource and this definition can run setup again. */
65
+ restartable?: boolean
66
+ setup(ctx: PluginContext): void | Promise<void>
67
+ /** Also called after setup fails; releases resources acquired during partial initialization. */
68
+ dispose?(): void | Promise<void>
69
+ }
70
+
71
+ export type PluginStatus = 'started' | 'degraded' | 'disabled' | 'failed'
72
+
73
+ export interface PluginReport {
74
+ id: string
75
+ name?: Record<Locale, string>
76
+ status: PluginStatus
77
+ reason?: string
78
+ missing?: string[]
79
+ }
80
+
81
+ export interface StartReport {
82
+ order: string[]
83
+ plugins: PluginReport[]
84
+ cycles: string[][]
85
+ }
86
+
87
+ export type KernelEvent =
88
+ | DomainEvent<'kernel.plugin.started', { id: string }>
89
+ | DomainEvent<'kernel.plugin.degraded', { id: string; missing: string[] }>
90
+ | DomainEvent<'kernel.plugin.disabled', { id: string; reason: string }>
91
+ | DomainEvent<'kernel.plugin.failed', { id: string; error: string }>
92
+
93
+ /**
94
+ * A heavy output of a document that the plugin makes on request, as a job of the workspace service (the slides as a PDF,
95
+ * the lecture as a video): the job shows its progress and log, and keeps the files for the author and the AI.
96
+ */
97
+ export interface Exporter {
98
+ /** Unique among the outputs of a document, renderers' ids included (e.g. `pdf`, `video`). */
99
+ id: string
100
+ /** What the author sees, by language (`zh-CN`, `en`). */
101
+ label: Record<string, string>
102
+ /** Whether the document can be exported so (e.g. it has the slides form); every document when left out. */
103
+ available?(doc: IRDocument, config: Record<string, unknown>): boolean
104
+ run(ctx: ExportContext): Promise<ExportOutput>
105
+ }
106
+
107
+ export interface ExportContext {
108
+ deckDir: string
109
+ workspaceRoot: string
110
+ /** The exact canonical source from which the requested compilation was derived. */
111
+ source?: CanonicalSource
112
+ /** The plugin's configuration in the document (`presmium.<plugin id>`). */
113
+ config: Record<string, unknown>
114
+ /** An empty directory, the job's own, for the files. */
115
+ outDir: string
116
+ /** Aborted when the author cancels the job: the exporter stops its processes and rejects. */
117
+ signal: AbortSignal
118
+ /** Where the job is: a phase, and how far through it. */
119
+ progress(phase: string, done?: number, total?: number): void
120
+ /** A line of the job's log (a tool's output, a step). */
121
+ log(line: string): void
122
+ /** What the one who asked for the export chose, as the exporter documents it (`presmium-export`'s `--with-clicks`). */
123
+ options: Record<string, unknown>
124
+ /**
125
+ * Builds the document with renderer `renderer` (at the root path, with `config` over the document's configuration of
126
+ * the renderer) and gives the directory of its output, the job's own: an exporter of the slides prints them from it.
127
+ */
128
+ build(renderer: string, config?: Record<string, unknown>): Promise<string>
129
+ }
130
+
131
+ export interface ExportOutput {
132
+ /** The files made, below `outDir`, the one to show first. */
133
+ files: string[]
134
+ /** The WebVTT captions of the first file (a video), by language, among `files`. */
135
+ captions?: Record<string, string>
136
+ warnings?: string[]
137
+ }
138
+
139
+ /**
140
+ * Files of an installed package that a plugin's browser code loads while it runs (Pyodide, the WASI runtimes): served
141
+ * below the document's site path at `<base><prefix><file>` and copied there into a built site.
142
+ */
143
+ export interface RuntimeAssets {
144
+ name: string
145
+ /** The directory below the document's site path, e.g. `pyodide/`. */
146
+ prefix: string
147
+ /** The files that are served, with their content types. */
148
+ types: Readonly<Record<string, string>>
149
+ /** The files a build copies; default: all that are served. */
150
+ emitted?: readonly string[]
151
+ /** The path of a file on disk. */
152
+ source(file: string): string
153
+ }
154
+
155
+ export interface PresmiumNodePlugin {
156
+ id: string
157
+ version?: string
158
+ kernel?: string
159
+ resolvers?: AnchorResolver[]
160
+ checks?: Check[]
161
+ anchors?(ctx: CheckContext): AnchorString[] | Promise<AnchorString[]>
162
+ directives?: DirectiveSpec[]
163
+ passes?: IRPass[]
164
+ executors?: Executor[]
165
+ renderer?: Renderer
166
+ rendererExtensions?: Record<string, RendererContribution>
167
+ /** The files the plugin's browser code loads while it runs (a language runtime), for the document's configuration of the plugin. */
168
+ assets?(ctx: { deckDir: string, workspaceRoot: string, config: Record<string, unknown> }): RuntimeAssets[]
169
+ /**
170
+ * The virtual modules of the plugin's browser code whose content depends on the document (e.g. the list of its scene
171
+ * files), by id, with their source. The viewer app, prebuilt once for all documents, gets them from the document's own
172
+ * bundle, built with this source. Only their default export is read there.
173
+ */
174
+ documentModules?(ctx: { deckDir: string, workspaceRoot: string, config: Record<string, unknown> }): Record<string, string>
175
+ /** The heavy outputs the plugin makes on request, as jobs of the workspace service. */
176
+ exporters?: Exporter[]
177
+ services?(ctx: NodeServiceContext): [ServiceToken<unknown>, unknown][]
178
+ environments?: Record<string, EnvironmentProvider>
179
+ server?(ctx: ServerContext): ServerContribution | Promise<ServerContribution>
180
+ roles?: RoleSpec[]
181
+ tools?: AgentTool[]
182
+ operator?: boolean
183
+ }
@@ -0,0 +1,17 @@
1
+ import type { Unsubscribe } from './plugin.ts'
2
+ import { defineService } from './service.ts'
3
+
4
+ export interface PresenterPanel {
5
+ id: string
6
+ title: string
7
+ component: unknown
8
+ order?: number
9
+ }
10
+
11
+ export interface PresenterPanels {
12
+ register(panel: PresenterPanel): Unsubscribe
13
+ list(): PresenterPanel[]
14
+ subscribe(listener: () => void): Unsubscribe
15
+ }
16
+
17
+ export const PRESENTER_PANELS = defineService<PresenterPanels>('presmium.presenterPanels')