@lincyaw/kernel 1.0.0-rc.6 → 1.0.0-rc.60
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/README.md +1 -1
- package/package.json +4 -2
- package/src/authoring.ts +2 -0
- package/src/contracts/authoring-actions.ts +3 -3
- package/src/contracts/authoring-clients.ts +94 -6
- package/src/contracts/authoring-windows.ts +47 -0
- package/src/contracts/authoring.ts +1 -1
- package/src/contracts/capture.ts +148 -0
- package/src/contracts/document-audio.ts +8 -6
- package/src/contracts/document-image.ts +7 -5
- package/src/contracts/document-voice.ts +35 -2
- package/src/contracts/document.ts +16 -1
- package/src/contracts/media-uploads.ts +28 -0
- package/src/contracts/plugin.ts +1 -3
- package/src/contracts/preview.ts +3 -3
- package/src/contracts/projects.ts +4 -1
- package/src/contracts/speech-settings.ts +13 -0
- package/src/contracts/speech.ts +16 -0
- package/src/contracts/voiceover-execution.ts +25 -1
- package/src/contracts/workspace-changes.ts +27 -0
- package/src/contracts/workspace-review.ts +39 -0
- package/src/contracts/workspace-source.ts +38 -0
- package/src/contracts/workspace.ts +2 -0
- package/src/contracts.ts +6 -0
- package/src/document-authoring-actions.ts +23 -4
- package/src/document-caption-scale.ts +17 -0
- package/src/document-comments.ts +30 -37
- package/src/document-components.ts +4 -12
- package/src/document-narrations.ts +57 -0
- package/src/document-operations.ts +32 -2
- package/src/document-pages.ts +8 -1
- package/src/document-places.ts +92 -0
- package/src/document-schema.ts +3 -3
- package/src/document.ts +13 -1
- package/src/embed.ts +26 -0
- package/src/escape-html.ts +4 -0
- package/src/html.ts +1 -4
- package/src/index.ts +15 -6
- package/src/ir.ts +23 -48
- package/src/lower-myst.ts +3 -12
- package/src/myst-marks.ts +15 -0
- package/src/node/authoring-actions.ts +3 -1
- package/src/node/authoring-windows.ts +11 -0
- package/src/node/document-voice.ts +6 -2
- package/src/node/fonts.ts +6 -3
- package/src/node/index.ts +9 -3
- package/src/node/operator-speech.ts +4 -0
- package/src/node/packages.ts +25 -0
- package/src/node/service-state.ts +52 -0
- package/src/node/workspace-changes.ts +7 -0
- package/src/node/workspace-review.ts +9 -0
- package/src/node/workspace-source.ts +10 -0
- package/src/preview-events.ts +6 -4
- package/src/preview-frame-connect.ts +1105 -0
- package/src/preview-frame.ts +30 -1120
- package/src/random-uuid.ts +8 -0
- package/src/stale-module.ts +15 -0
package/src/node/fonts.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs'
|
|
1
|
+
import { readFileSync, realpathSync } from 'node:fs'
|
|
2
2
|
import { createRequire, findPackageJSON } from 'node:module'
|
|
3
3
|
|
|
4
4
|
export const FONT_LICENSE = 'presmium/fonts/LICENSE'
|
|
@@ -10,8 +10,11 @@ const FONT_COPYRIGHTS: Record<string, string> = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function fontLicense(from: string | URL): string {
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
13
|
+
const found = findPackageJSON('@lincyaw/host', from)
|
|
14
|
+
if (!found) throw new Error('@lincyaw/host is not installed')
|
|
15
|
+
// findPackageJSON keeps the symlinked path; the fonts are host's own dependencies, which an isolated store (pnpm's
|
|
16
|
+
// global store) puts beside the real package, so they are resolved from there.
|
|
17
|
+
const manifest = realpathSync(found)
|
|
15
18
|
const { dependencies = {} } = JSON.parse(readFileSync(manifest, 'utf8')) as { dependencies?: Record<string, string> }
|
|
16
19
|
const require = createRequire(manifest)
|
|
17
20
|
const files = Object.keys(dependencies).filter(name => name.startsWith('@fontsource/')).sort().map((name) => {
|
package/src/node/index.ts
CHANGED
|
@@ -5,12 +5,12 @@ export { validateDocumentOutlineQuery, validateDocumentPartQuery } from './docum
|
|
|
5
5
|
export { DOCUMENT_AUTHORING_ACTION_SCHEMA, DOCUMENT_AUTHORING_ACTION_APPLY_SCHEMA, DOCUMENT_AUTHORING_ACTION_IMPACT_SCHEMA, validateDocumentAuthoringAction, validateDocumentAuthoringActionReference, validateDocumentAuthoringActionImpact } from './authoring-actions.ts'
|
|
6
6
|
export { validateDocumentTranscriptionRequest } from './transcription.ts'
|
|
7
7
|
export { validateDocumentRecordingAdoption, validateDocumentAudioInspect, validateDocumentWorkspaceAudioImport, validateDocumentWorkspaceAudioInspect, validateDocumentMediaClipValidation, validateDocumentMediaClipEdit, validateDocumentProductionPlanQuery } from './document-audio.ts'
|
|
8
|
-
export { validateDocumentVoiceCatalogQuery } from './document-voice.ts'
|
|
8
|
+
export { validateDocumentVoiceCatalogQuery, validateDocumentVoiceClone, validateDocumentVoiceCloneQuery } from './document-voice.ts'
|
|
9
9
|
export { createVoiceoverOwner, VoiceoverOperationError, validateVoiceoverStart, validateVoiceoverStatus, validateVoiceoverJobQuery, validateVoicePreviewCheck, validateVoicePreviewStart } from './voiceover.ts'
|
|
10
10
|
export { createVoiceoverRoutes } from './voiceover-routes.ts'
|
|
11
11
|
export { validateTranscriptionAdoptionDraft, validateTranscriptionAdoptionApply } from './transcription-adoption.ts'
|
|
12
12
|
export { FONT_LICENSE, fontLicense } from './fonts.ts'
|
|
13
|
-
export { findPackageBin, importSpecifier, literalGlob, packageOf, playwrightChromium, TYPESCRIPT_IMPORT } from './packages.ts'
|
|
13
|
+
export { findPackageBin, importSpecifier, literalGlob, packageExport, packageOf, playwrightChromium, TYPESCRIPT_IMPORT } from './packages.ts'
|
|
14
14
|
export { ffmpegInstallCommand, findFfmpeg } from './ffmpeg.ts'
|
|
15
15
|
export type { Ffmpeg } from './ffmpeg.ts'
|
|
16
16
|
export { bracketIPv6, lanAddresses } from './network.ts'
|
|
@@ -23,7 +23,13 @@ export { findInstalledPackage } from './installed-packages.ts'
|
|
|
23
23
|
export { directSandbox, minimalRunEnv, RUN_REQUEST_FILE, RUN_RESULT_PREFIX, runResultFile } from './run-directory.ts'
|
|
24
24
|
export { validateDocumentHistoryQuery, validateDocumentHistoryRead, validateDocumentHistoryChange } from './document-history.ts'
|
|
25
25
|
export { validateAuthoringClientRequest, validateAuthoringClientQuery, validateAuthoringClientRequestQuery, validateAuthoringClientOpen, validateAuthoringClientReport, validateAuthoringClientAcknowledgement, validateAuthoringClientLease } from './authoring-clients.ts'
|
|
26
|
+
export { validateAuthoringWindowHandle, validateAuthoringWindowRequest, validateAuthoringWindowOpen, validateAuthoringWindowReport, validateAuthoringWindowAcknowledgement } from './authoring-windows.ts'
|
|
26
27
|
export { validateProjectPlan, validateProjectApply } from './projects.ts'
|
|
27
28
|
export { validateDocumentWorkspaceImageInspect, validateDocumentWorkspaceImageImport } from './document-image.ts'
|
|
28
29
|
export { systemLocale } from './locale.ts'
|
|
29
|
-
export { OperatorSpeechSettings, operatorSpeechSecrets, SpeechSettingsError } from './operator-speech.ts'
|
|
30
|
+
export { OperatorSpeechSettings, operatorSpeechSecrets, SpeechSettingsError, validateSpeechSettingsChange } from './operator-speech.ts'
|
|
31
|
+
export { devStateFile, readServiceState, removeServiceState, serveStateDir } from './service-state.ts'
|
|
32
|
+
export type { ServiceState } from './service-state.ts'
|
|
33
|
+
export { validateWorkspaceReviewQuery, validateWorkspaceReviewChange } from './workspace-review.ts'
|
|
34
|
+
export { validateSourceList, validateSourceRead, validateSourceEdit } from './workspace-source.ts'
|
|
35
|
+
export { validateChangesQuery, validateWorkspaceChangesRequest } from './workspace-changes.ts'
|
|
@@ -2,10 +2,14 @@ import { createRequire } from 'node:module'
|
|
|
2
2
|
import { randomUUID } from 'node:crypto'
|
|
3
3
|
import { constants, closeSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
4
4
|
import { dirname, join } from 'node:path'
|
|
5
|
+
import { Validator } from '@cfworker/json-schema'
|
|
6
|
+
import { SPEECH_SETTINGS_CHANGE_SCHEMA } from '../contracts/speech-settings.ts'
|
|
5
7
|
import type { SpeechSettingsAnswer, SpeechSettingsChange } from '../contracts/speech-settings.ts'
|
|
6
8
|
|
|
7
9
|
const KEY = 'PRESMIUM_SPEECH_VOLCENGINE_KEY', APPID = 'PRESMIUM_SPEECH_VOLCENGINE_APPID'
|
|
8
10
|
const MAX_BYTES = 16384
|
|
11
|
+
const settingsChangeValidator = new Validator(structuredClone(SPEECH_SETTINGS_CHANGE_SCHEMA), '2020-12', false)
|
|
12
|
+
export const validateSpeechSettingsChange = (value: unknown): value is SpeechSettingsChange => settingsChangeValidator.validate(value).valid
|
|
9
13
|
const lockfile = createRequire(import.meta.url)('proper-lockfile') as { lock(file: string, options: { realpath: boolean, retries: number }): Promise<() => Promise<void>> }
|
|
10
14
|
interface Stored { version: 1, revision: string, key?: string, appId?: string }
|
|
11
15
|
const empty = (): Stored => ({ version: 1, revision: 'none' })
|
package/src/node/packages.ts
CHANGED
|
@@ -2,6 +2,31 @@ import { existsSync, readFileSync } from 'node:fs'
|
|
|
2
2
|
import { createRequire, findPackageJSON } from 'node:module'
|
|
3
3
|
import { dirname, isAbsolute, join, relative, sep } from 'node:path'
|
|
4
4
|
import { pathToFileURL } from 'node:url'
|
|
5
|
+
import { exports as resolveExports } from 'resolve.exports'
|
|
6
|
+
|
|
7
|
+
/** Resolve a public package export with Node or browser conditions, retaining package-relative target validation. */
|
|
8
|
+
export function packageExport(pkg: { name?: unknown, exports?: unknown }, dir: string, subpath: string, options: { browser?: boolean } = {}): string | undefined {
|
|
9
|
+
let targets: string[] | void
|
|
10
|
+
try {
|
|
11
|
+
targets = resolveExports(pkg as Parameters<typeof resolveExports>[0], subpath, options)
|
|
12
|
+
} catch {
|
|
13
|
+
return undefined
|
|
14
|
+
}
|
|
15
|
+
if (!targets?.length) return undefined
|
|
16
|
+
const base = pathToFileURL(`${dir}/`)
|
|
17
|
+
for (const target of targets) {
|
|
18
|
+
const path = target.split(/[?#]/, 1)[0]!
|
|
19
|
+
if (!path.startsWith('./') || /%2f|%5c/i.test(path)) continue
|
|
20
|
+
try {
|
|
21
|
+
const segments = path.slice(2).split(/[\\/]/).map(decodeURIComponent)
|
|
22
|
+
if (segments.some(segment => /^(?:\.{1,2}|node_modules)$/i.test(segment))) continue
|
|
23
|
+
if (new URL(target, base).href.startsWith(base.href)) return target
|
|
24
|
+
} catch {
|
|
25
|
+
// An export array may contain another valid package-relative target.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`${subpath} has no valid package-relative target`)
|
|
29
|
+
}
|
|
5
30
|
|
|
6
31
|
export const TYPESCRIPT_IMPORT: readonly string[] = ['--import', new URL('./strip-types.mjs', import.meta.url).href]
|
|
7
32
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { readFileSync, rmSync } from 'node:fs'
|
|
3
|
+
import { homedir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { isRecord } from '../errors.ts'
|
|
6
|
+
|
|
7
|
+
/** What a running Presmium server records for local clients: its address, its MCP endpoint and token, its process. */
|
|
8
|
+
export interface ServiceState {
|
|
9
|
+
url: string
|
|
10
|
+
mcp: string
|
|
11
|
+
token: string
|
|
12
|
+
pid: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The state directory of the workspace service (`presmium serve`, and the one `presmium studio` starts) of `root`. */
|
|
16
|
+
export function serveStateDir(root: string, env: NodeJS.ProcessEnv = process.env): string {
|
|
17
|
+
const base = env.XDG_CACHE_HOME || join(homedir(), '.cache')
|
|
18
|
+
return join(base, 'presmium', 'serve', createHash('sha256').update(root).digest('hex').slice(0, 16))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The state file `presmium dev` writes beside the document it previews. */
|
|
22
|
+
export function devStateFile(deckDir: string): string {
|
|
23
|
+
return join(deckDir, '.presmium', 'server.json')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const alive = (pid: number): boolean => {
|
|
27
|
+
try {
|
|
28
|
+
process.kill(pid, 0)
|
|
29
|
+
return true
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return (error as NodeJS.ErrnoException).code === 'EPERM'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The state of the server that wrote `file`, while that process runs. */
|
|
36
|
+
export function readServiceState(file: string): ServiceState | undefined {
|
|
37
|
+
try {
|
|
38
|
+
const state: unknown = JSON.parse(readFileSync(file, 'utf8'))
|
|
39
|
+
if (!isRecord(state) || typeof state.url !== 'string' || typeof state.mcp !== 'string' || typeof state.token !== 'string' || typeof state.pid !== 'number') return undefined
|
|
40
|
+
return alive(state.pid) ? { url: state.url, mcp: state.mcp, token: state.token, pid: state.pid } : undefined
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Removes `file` when it is still this process's: a server that stopped leaves no address behind. */
|
|
47
|
+
export function removeServiceState(file: string, pid = process.pid): void {
|
|
48
|
+
try {
|
|
49
|
+
const state: unknown = JSON.parse(readFileSync(file, 'utf8'))
|
|
50
|
+
if (isRecord(state) && state.pid === pid) rmSync(file, { force: true })
|
|
51
|
+
} catch {}
|
|
52
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Validator } from '@cfworker/json-schema'
|
|
2
|
+
import type { Schema } from '@cfworker/json-schema'
|
|
3
|
+
import { CHANGES_QUERY_SCHEMA, CHANGES_REQUEST_SCHEMA } from '../contracts/workspace-changes.ts'
|
|
4
|
+
import type { ChangesQuery, WorkspaceChangesRequest } from '../contracts/workspace-changes.ts'
|
|
5
|
+
const query = new Validator(CHANGES_QUERY_SCHEMA as unknown as Schema), change = new Validator(CHANGES_REQUEST_SCHEMA as unknown as Schema)
|
|
6
|
+
export const validateChangesQuery = (value: unknown): value is ChangesQuery => query.validate(value).valid
|
|
7
|
+
export const validateWorkspaceChangesRequest = (value: unknown): value is WorkspaceChangesRequest => change.validate(value).valid
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Validator } from '@cfworker/json-schema'
|
|
2
|
+
import type { Schema } from '@cfworker/json-schema'
|
|
3
|
+
import { WORKSPACE_REVIEW_CHANGE_SCHEMA, WORKSPACE_REVIEW_QUERY_SCHEMA } from '../contracts/workspace-review.ts'
|
|
4
|
+
import type { WorkspaceReviewChange, WorkspaceReviewQuery } from '../contracts/workspace-review.ts'
|
|
5
|
+
|
|
6
|
+
const query = new Validator(WORKSPACE_REVIEW_QUERY_SCHEMA as unknown as Schema)
|
|
7
|
+
const change = new Validator(WORKSPACE_REVIEW_CHANGE_SCHEMA as unknown as Schema)
|
|
8
|
+
export const validateWorkspaceReviewQuery = (value: unknown): value is WorkspaceReviewQuery => query.validate(value).valid
|
|
9
|
+
export const validateWorkspaceReviewChange = (value: unknown): value is WorkspaceReviewChange => change.validate(value).valid
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Validator } from '@cfworker/json-schema'
|
|
2
|
+
import type { Schema } from '@cfworker/json-schema'
|
|
3
|
+
import { SOURCE_EDIT_SCHEMA, SOURCE_LIST_SCHEMA, SOURCE_READ_SCHEMA } from '../contracts/workspace-source.ts'
|
|
4
|
+
import type { SourceEdit, SourceListQuery, SourceReadQuery } from '../contracts/workspace-source.ts'
|
|
5
|
+
const list = new Validator(SOURCE_LIST_SCHEMA as unknown as Schema)
|
|
6
|
+
const read = new Validator(SOURCE_READ_SCHEMA as unknown as Schema)
|
|
7
|
+
const edit = new Validator(SOURCE_EDIT_SCHEMA as unknown as Schema)
|
|
8
|
+
export const validateSourceList = (value: unknown): value is SourceListQuery => list.validate(value).valid
|
|
9
|
+
export const validateSourceRead = (value: unknown): value is SourceReadQuery => read.validate(value).valid
|
|
10
|
+
export const validateSourceEdit = (value: unknown): value is SourceEdit => edit.validate(value).valid
|
package/src/preview-events.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PREVIEW_EVENTS_PARAM, previewEnvelope } from './contracts/preview.ts'
|
|
2
2
|
import type { PreviewCommand, PreviewEventSubscription, PreviewEventTarget, PreviewEventMessage } from './contracts/preview.ts'
|
|
3
|
-
import { previewNonce } from './preview-frame.ts'
|
|
3
|
+
import { parentOrigins, previewNonce } from './preview-frame.ts'
|
|
4
|
+
import { randomUUID } from './random-uuid.ts'
|
|
4
5
|
|
|
5
6
|
/** Uses the existing preview-ready handshake, origin fence and nonce; never opens a network connection. */
|
|
6
7
|
export interface PreviewEvents {
|
|
@@ -14,11 +15,12 @@ export function createPreviewEvents(origins: readonly string[], document: string
|
|
|
14
15
|
if (typeof window === 'undefined' || window.parent === window || !origins.length || new URL(location.href).searchParams.get(PREVIEW_EVENTS_PARAM) !== 'shared') return
|
|
15
16
|
const nonce = previewNonce()
|
|
16
17
|
if (!nonce) return
|
|
17
|
-
const connection =
|
|
18
|
+
const connection = randomUUID()
|
|
18
19
|
const readers = new Map<string, { target: PreviewEventTarget, received(message: PreviewEventMessage): void }>()
|
|
19
20
|
let ready = false, stopped = false, parked = false
|
|
21
|
+
const targets = parentOrigins(origins)
|
|
20
22
|
const post = (message: Parameters<typeof previewEnvelope>[1]) => {
|
|
21
|
-
if (!stopped) for (const origin of
|
|
23
|
+
if (!stopped) for (const origin of targets) window.parent.postMessage(previewEnvelope(nonce, message), origin)
|
|
22
24
|
}
|
|
23
25
|
const subscribe = (id: string, target: PreviewEventTarget) => post({ type: 'events-subscribe', connection, id, target })
|
|
24
26
|
const park = () => {
|
|
@@ -35,7 +37,7 @@ export function createPreviewEvents(origins: readonly string[], document: string
|
|
|
35
37
|
connection,
|
|
36
38
|
subscribe(target, received) {
|
|
37
39
|
if (stopped || target.document !== document) return () => {}
|
|
38
|
-
const id =
|
|
40
|
+
const id = randomUUID()
|
|
39
41
|
readers.set(id, { target, received })
|
|
40
42
|
if (ready && !parked) subscribe(id, target)
|
|
41
43
|
return () => { if (readers.delete(id)) post({ type: 'events-unsubscribe', connection, id }) }
|