/ concept-collection / numbl-web-ide
Sign in
concept-collection / numbl-web-ide
numbl-web-ide / src / numbl / protocol.ts
40 lines · 1.5 KBBlameHistoryRaw
1import type { PlotInstruction, WorkspaceFile } from 'numbl';
3// Message protocol between the app and the numbl web worker — a minimal
4// version of numbl's own numbl-worker protocol (which is not published on
5// npm): one "run" request in, streamed output/drawnow messages out, ending
6// with "done" or "error".
8/** A raw file placed into the run's virtual file system. */
9export interface VfsFile {
10 /** Project-relative path ('scripts/demo.m' → /project) or an absolute
11 * VFS path such as '/system/mip/...'. */
12 path: string;
13 content: Uint8Array;
16export interface RunRequest {
17 type: 'run';
18 /** Source of the file being run (possibly unsaved editor contents). */
19 code: string;
20 /** Project-relative path of the file being run. */
21 mainFileName: string;
22 /** Every project + system file, as bytes, for the virtual file system. */
23 vfsFiles: VfsFile[];
24 /** Every other project + system .m file, as text, callable as functions. */
25 workspaceFiles: WorkspaceFile[];
26 /** Extra search paths (e.g. the mip core package directory). */
27 searchPaths?: string[];
30export interface VfsChanges {
31 created: { path: string; content: Uint8Array }[];
32 modified: { path: string; content: Uint8Array }[];
33 deleted: string[];
36export type WorkerResponse =
37 | { type: 'output'; text: string }
38 | { type: 'drawnow'; plotInstructions: PlotInstruction[] }
39 | { type: 'done'; plotInstructions: PlotInstruction[]; vfsChanges?: VfsChanges }
40 | { type: 'error'; message: string; vfsChanges?: VfsChanges };
moveopenescclose