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

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @lincyaw/kernel
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Presmium's shared kernel: the IR and the plugin contracts, the service registry, anchors and checks. Plain TypeScript, used by the compiler, the renderers, the IR runtime and every plugin.
4
+
5
+ Part of [Presmium](https://github.com/Lincyaw/presmium), which turns lectures written in MyST Markdown into web pages, slides, Jupyter notebooks and narrated lectures.
6
+
7
+ ## Install
8
+
9
+ Plugins declare it as a peer dependency, so they share the application's copy:
10
+
11
+ ```json
12
+ "peerDependencies": { "@lincyaw/kernel": "^1.0.0" }
13
+ ```
14
+
15
+ ## Entries
16
+
17
+ - `@lincyaw/kernel`: the contracts (`PresmiumNodePlugin`, `PluginDefinition`, `DirectiveSpec`, `IRPass`, `Renderer`, `RenderContext`, `Check`, the service tokens), the IR types (`IRDocument` and its nodes), `KERNEL_VERSION`, `IR_VERSION`, and plain helpers such as `docBlocks`, `withProp`, `deckLocale`, `json` and `problem`.
18
+ - `@lincyaw/kernel/contracts`, `@lincyaw/kernel/ir`: the contracts or the IR types alone.
19
+ - `@lincyaw/kernel/reading`: plain functions that read compiled documents (`chapters`, `blockText`, `narrationAt`, `tokenize`).
20
+ - `@lincyaw/kernel/node`: helpers for Node code: `copyPublished` (its other exports are internal).
21
+ - `@lincyaw/kernel/runner.py`: the shared Python runner of the executors.
22
+
23
+ ## Versions
24
+
25
+ `KERNEL_VERSION` is the version of the plugin contract, separate from the package version: 1.0.0 in Presmium 1.0, a minor version higher for each compatible addition to the contract, a major version (and a major version of the packages) for an incompatible change. Plugins declare `kernel: '^1.0.0'`, which any Presmium 1.x satisfies; a plugin whose range excludes it is not loaded. `IR_VERSION` is the version of the IR's JSON format.
26
+
27
+ ## Documentation
28
+
29
+ - [Plugin guide](https://github.com/Lincyaw/presmium/blob/main/site/plugins/lecture.en.md)
30
+
31
+ ## License
32
+
33
+ Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@lincyaw/kernel",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-rc.0",
4
+ "description": "Presmium's shared kernel: the IR and plugin contracts, the service registry, anchors and checks",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Lincyaw/presmium.git",
9
+ "directory": "packages/kernel"
10
+ },
11
+ "homepage": "https://github.com/Lincyaw/presmium/tree/main/packages/kernel#readme",
12
+ "bugs": "https://github.com/Lincyaw/presmium/issues",
13
+ "keywords": [
14
+ "presmium",
15
+ "ir"
16
+ ],
17
+ "type": "module",
18
+ "engines": {
19
+ "node": ">=22.19"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "exports": {
25
+ ".": "./src/index.ts",
26
+ "./contracts": "./src/contracts.ts",
27
+ "./ir": "./src/ir.ts",
28
+ "./node": "./src/node/index.ts",
29
+ "./reading": "./src/reading.ts",
30
+ "./runner.py": "./src/runner.py"
31
+ },
32
+ "files": [
33
+ "src"
34
+ ],
35
+ "dependencies": {
36
+ "@types/semver": "^7.8.0",
37
+ "parse5": "7.3.0",
38
+ "semver": "^7.8.5"
39
+ }
6
40
  }
package/src/anchors.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type { AnchorResolver, AnchorResolverRegistry, Resolution } from './contracts.ts'
2
+ import { errorMessage } from './errors.ts'
3
+
4
+ const SCHEME = /^[a-z][a-z0-9+.-]*$/i
5
+
6
+ export interface ParsedAnchor {
7
+ scheme: string
8
+ target: string
9
+ }
10
+
11
+ export function parseAnchor(anchor: string): ParsedAnchor | undefined {
12
+ const colon = anchor.indexOf(':')
13
+ const scheme = anchor.slice(0, colon)
14
+ const target = anchor.slice(colon + 1)
15
+ if (colon < 0 || !SCHEME.test(scheme) || target.trim() === '') return undefined
16
+ return { scheme, target }
17
+ }
18
+
19
+ function lost(message: string): Resolution {
20
+ return { status: 'lost', message }
21
+ }
22
+
23
+ export function createAnchorResolverRegistry(resolvers: AnchorResolver[] = []): AnchorResolverRegistry {
24
+ const byScheme = new Map<string, AnchorResolver>()
25
+ const registry: AnchorResolverRegistry = {
26
+ register(resolver) {
27
+ if (!SCHEME.test(resolver.scheme)) throw new Error(`invalid anchor scheme "${resolver.scheme}"`)
28
+ if (byScheme.has(resolver.scheme)) throw new Error(`anchor scheme "${resolver.scheme}" is already registered`)
29
+ byScheme.set(resolver.scheme, resolver)
30
+ return () => {
31
+ if (byScheme.get(resolver.scheme) === resolver) byScheme.delete(resolver.scheme)
32
+ }
33
+ },
34
+ async resolve(anchor, src, recorded, ref) {
35
+ const parsed = parseAnchor(anchor)
36
+ if (!parsed) return lost(`malformed anchor "${anchor}": expected scheme:target`)
37
+ const resolver = byScheme.get(parsed.scheme)
38
+ if (!resolver) {
39
+ const known = registry.schemes().join(', ') || 'none'
40
+ return lost(`unknown anchor scheme "${parsed.scheme}" in "${anchor}" (registered schemes: ${known})`)
41
+ }
42
+ try {
43
+ return await resolver.resolve(anchor, src, recorded, ref)
44
+ } catch (error) {
45
+ return lost(`resolver "${parsed.scheme}" failed on "${anchor}": ${errorMessage(error)}`)
46
+ }
47
+ },
48
+ schemes() {
49
+ return [...byScheme.keys()]
50
+ },
51
+ }
52
+ for (const resolver of resolvers) registry.register(resolver)
53
+ return registry
54
+ }
package/src/blocks.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { IRBlock, IRDocument, IRNode, IRSection, MdastNode } from './ir.ts'
2
+
3
+ export function* irBlocks(blocks: readonly IRBlock[]): Generator<IRBlock> {
4
+ for (const block of blocks) {
5
+ yield block
6
+ if (block.node.type === 'component' && block.node.children) yield* irBlocks(block.node.children)
7
+ }
8
+ }
9
+
10
+ export function* docBlocks(doc: IRDocument): Generator<{ section: IRSection, block: IRBlock }> {
11
+ for (const section of doc.sections) {
12
+ for (const block of irBlocks(section.blocks)) yield { section, block }
13
+ }
14
+ }
15
+
16
+ export function nodeMdast(node: IRNode): MdastNode[] {
17
+ if (node.type === 'markdown') return [node.mdast]
18
+ return node.type === 'component' && node.fallback ? [node.fallback] : []
19
+ }
20
+
21
+ export function withProp(props: Record<string, unknown>, path: string, value: unknown): Record<string, unknown> {
22
+ const [key = '', ...rest] = path.split('.')
23
+ if (rest.length === 0) return { ...props, [key]: value }
24
+ const inner = props[key]
25
+ const object = inner !== null && typeof inner === 'object' && !Array.isArray(inner) ? inner as Record<string, unknown> : {}
26
+ return { ...props, [key]: withProp(object, rest.join('.'), value) }
27
+ }
package/src/checks.ts ADDED
@@ -0,0 +1,35 @@
1
+ import type { Check, CheckContext, Finding, Unsubscribe } from './contracts.ts'
2
+ import { errorMessage } from './errors.ts'
3
+
4
+ export class CheckRegistry {
5
+ #checks = new Map<string, Check>()
6
+
7
+ constructor(checks: Check[] = []) {
8
+ for (const check of checks) this.register(check)
9
+ }
10
+
11
+ register(check: Check): Unsubscribe {
12
+ if (this.#checks.has(check.id)) throw new Error(`check ${check.id} is already registered`)
13
+ this.#checks.set(check.id, check)
14
+ return () => {
15
+ if (this.#checks.get(check.id) === check) this.#checks.delete(check.id)
16
+ }
17
+ }
18
+
19
+ list(): Check[] {
20
+ return [...this.#checks.values()]
21
+ }
22
+
23
+ async run(ctx: CheckContext): Promise<Finding[]> {
24
+ const results = await Promise.all(this.list().map(check => runIsolated(check, ctx)))
25
+ return results.flat()
26
+ }
27
+ }
28
+
29
+ async function runIsolated(check: Check, ctx: CheckContext): Promise<Finding[]> {
30
+ try {
31
+ return await check.run(ctx)
32
+ } catch (error) {
33
+ return [{ checkId: check.id, severity: 'error', message: `check ${check.id} crashed: ${errorMessage(error)}` }]
34
+ }
35
+ }
@@ -0,0 +1,153 @@
1
+ import type { Member } from './server.ts'
2
+ import { defineService } from './service.ts'
3
+ import type { ServiceToken } from './service.ts'
4
+
5
+ export interface SourceRange { file: string, startLine: number, endLine: number }
6
+
7
+ /** @experimental */
8
+ export interface Focus {
9
+ id: string
10
+ from: 'source' | 'web' | 'slides'
11
+ document: string
12
+ source: SourceRange
13
+ excerpt: string
14
+ section?: string
15
+ block?: string
16
+ step?: number
17
+ quote?: string
18
+ }
19
+
20
+ /** @experimental */
21
+ export interface FocusReport {
22
+ id: string
23
+ from: Focus['from']
24
+ section?: string
25
+ block?: string
26
+ step?: number
27
+ quote?: string
28
+ source?: SourceRange
29
+ }
30
+
31
+ export interface AgentContext {
32
+ document: string
33
+ section?: string
34
+ step?: number
35
+ block?: string
36
+ view?: string
37
+ selection?: string
38
+ source?: SourceRange
39
+ focus?: Focus[]
40
+ }
41
+
42
+ export interface Citation {
43
+ label: string
44
+ section: string
45
+ step?: number
46
+ block?: string
47
+ }
48
+
49
+ export interface AskClient {
50
+ provider(): string | undefined
51
+ ask(question: string, context: AgentContext, signal?: AbortSignal): AsyncIterable<string>
52
+ }
53
+
54
+ export const ASK = defineService<AskClient>('presmium.ask')
55
+
56
+ export type AgentToolKind = 'read' | 'operate' | 'spend'
57
+
58
+ export interface AgentToolContext {
59
+ document: string
60
+ member: Member
61
+ service<T>(token: ServiceToken<T>): T | undefined
62
+ signal: AbortSignal
63
+ }
64
+
65
+ export interface AgentTool {
66
+ name: string
67
+ description: string
68
+ input: Record<string, unknown>
69
+ kind: AgentToolKind
70
+ run(input: Record<string, unknown>, ctx: AgentToolContext): Promise<unknown>
71
+ }
72
+
73
+ export type ReviewChangeKind = 'added' | 'modified' | 'deleted'
74
+
75
+ export interface ReviewChange {
76
+ path: string
77
+ kind: ReviewChangeKind
78
+ binary: boolean
79
+ added: number
80
+ removed: number
81
+ diff?: string
82
+ }
83
+
84
+ export interface ReviewStep {
85
+ id: string
86
+ label: string
87
+ tool?: string
88
+ at: string
89
+ changes: ReviewChange[]
90
+ }
91
+
92
+ export interface ChangeReview {
93
+ readonly root: string
94
+ readonly visibility: 'immediate' | 'on-commit'
95
+ step(label: string, tool?: string): Promise<ReviewStep>
96
+ steps(): readonly ReviewStep[]
97
+ diff(): Promise<ReviewChange[]>
98
+ restoreTo?(stepId: string): Promise<void>
99
+ accept(reject?: string[]): Promise<string[]>
100
+ rollback(): Promise<void>
101
+ close(): Promise<void>
102
+ }
103
+
104
+ export interface ChangeReviewService {
105
+ readonly engine: string
106
+ open(options: { document: string, task: string, member: Member }): Promise<ChangeReview>
107
+ }
108
+
109
+ export const CHANGE_REVIEW = defineService<ChangeReviewService>('presmium.changeReview')
110
+
111
+ export interface RevisionOrigin {
112
+ kind: 'agent' | 'document' | 'editor'
113
+ task?: string
114
+ member?: Member
115
+ }
116
+
117
+ export interface Revision {
118
+ id: string
119
+ message: string
120
+ author: string
121
+ date: string
122
+ origin: RevisionOrigin
123
+ files: string[]
124
+ revertedBy?: string
125
+ }
126
+
127
+ export type RevertResult = { ok: true, revision: Revision } | { ok: false, conflicts: string[] }
128
+
129
+ export interface RevisionService {
130
+ commit(change: { files: string[], message: string, origin: RevisionOrigin }): Promise<Revision | undefined>
131
+ history(filter?: { document?: string, task?: string, limit?: number }): Promise<Revision[]>
132
+ revert(id: string, member: Member): Promise<RevertResult>
133
+ }
134
+
135
+ export const REVISIONS = defineService<RevisionService>('presmium.revisions')
136
+
137
+ export interface DocumentLockService {
138
+ claim(document: string, holder: string): (() => void) | undefined
139
+ holder(document: string): string | undefined
140
+ }
141
+
142
+ export const DOCUMENT_LOCKS = defineService<DocumentLockService>('presmium.documentLocks')
143
+
144
+ export type DocumentFileChange =
145
+ | { path: string, content: Uint8Array, executable?: boolean, at?: number }
146
+ | { path: string, link: string }
147
+ | { path: string, remove: true }
148
+
149
+ export interface DocumentFiles {
150
+ write(changes: DocumentFileChange[]): Promise<void>
151
+ }
152
+
153
+ export const DOCUMENT_FILES = defineService<DocumentFiles>('presmium.documentFiles')
@@ -0,0 +1,119 @@
1
+ import type { Logger, Unsubscribe } from '../contracts.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
+ }
14
+
15
+ export type RunOutput =
16
+ | { output_type: 'stream', name: 'stdout' | 'stderr', text: string }
17
+ | { output_type: 'display_data' | 'execute_result', data: Record<string, unknown>, metadata?: Record<string, unknown> }
18
+ | { output_type: 'error', ename: string, evalue: string, traceback: string[] }
19
+
20
+ export interface RunResult {
21
+ ok: boolean
22
+ stdout: string
23
+ stderr: string
24
+ exitCode: number | null
25
+ durationMs: number
26
+ timedOut: boolean
27
+ source: 'live' | 'recorded'
28
+ executorId: string
29
+ outputs?: RunOutput[]
30
+ }
31
+
32
+ export interface RunContext {
33
+ env: Readonly<Record<string, string>>
34
+ sandbox?: ProcessSandbox
35
+ lang?: string
36
+ }
37
+
38
+ export interface SandboxRun {
39
+ argv: string[]
40
+ files: Record<string, string | Uint8Array>
41
+ collect: string[]
42
+ env: Readonly<Record<string, string>>
43
+ read: string[]
44
+ timeoutMs: number
45
+ signal?: AbortSignal
46
+ }
47
+
48
+ export interface SandboxResult {
49
+ exitCode: number | null
50
+ stdout: string
51
+ stderr: string
52
+ files: Record<string, Uint8Array>
53
+ }
54
+
55
+ export interface ProcessSandbox {
56
+ readonly kind: string
57
+ run(request: SandboxRun): Promise<SandboxResult>
58
+ }
59
+
60
+ export const PROCESS_SANDBOX = defineService<ProcessSandbox>('presmium.processSandbox')
61
+
62
+ export interface Executor {
63
+ readonly id: string
64
+ readonly runsIn?: 'browser' | 'machine'
65
+ supports(lang: string): boolean
66
+ run(request: RunRequest, signal?: AbortSignal, ctx?: RunContext): Promise<RunResult>
67
+ fingerprint?(lang: string): string | Promise<string>
68
+ revision?(lang: string): string | Promise<string>
69
+ endSession?(session: string): Promise<void>
70
+ params?(lang: string): ParamsDisplay | undefined
71
+ }
72
+
73
+ export interface ParamsDisplay {
74
+ labels: Record<string, string>
75
+ fields?: string[]
76
+ summary?(args: Record<string, string>): string
77
+ }
78
+
79
+ export interface ExecutorRouter extends Executor {
80
+ register(executor: Executor, priority?: number): Unsubscribe
81
+ list(): Executor[]
82
+ }
83
+
84
+ export const EXECUTOR = defineService<ExecutorRouter>('presmium.executor')
85
+
86
+ export type EnvironmentAuth = 'none' | 'env' | 'proxy' | 'prompt' | 'hub'
87
+
88
+ export interface EnvironmentSpec {
89
+ kind: string
90
+ url?: string
91
+ kernel?: string
92
+ languages?: string[]
93
+ auth?: EnvironmentAuth
94
+ image?: string
95
+ path?: string
96
+ [option: string]: unknown
97
+ }
98
+
99
+ export interface ExecuteConfig {
100
+ env?: string
101
+ environments?: Record<string, EnvironmentSpec>
102
+ rerun?: 'environment'
103
+ }
104
+
105
+ export function environmentExecutor(name: string): string {
106
+ return `presmium.env.${name}`
107
+ }
108
+
109
+ export interface EnvironmentContext {
110
+ deckDir: string
111
+ workspaceRoot: string
112
+ secret(name: string): string | undefined
113
+ log: Logger
114
+ }
115
+
116
+ export interface EnvironmentProvider {
117
+ create(name: string, spec: EnvironmentSpec, ctx: EnvironmentContext): Executor | Promise<Executor>
118
+ probe?(name: string, spec: EnvironmentSpec, ctx: EnvironmentContext): Promise<string | undefined>
119
+ }
@@ -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]