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 (under /project). */
9export interface VfsFile {
10 /** Project-relative path, e.g. 'scripts/demo.m'. */
11 path: string;
12 content: Uint8Array;
13}
15export interface RunRequest {
16 type: 'run';
17 /** Source of the file being run (possibly unsaved editor contents). */
18 code: string;
19 /** Project-relative path of the file being run. */
20 mainFileName: string;
21 /** Every project file, as bytes, for the virtual file system. */
22 vfsFiles: VfsFile[];
23 /** Every other project .m file, as text, callable as functions. */
24 workspaceFiles: WorkspaceFile[];
25}
27export interface VfsChanges {
28 created: { path: string; content: Uint8Array }[];
29 modified: { path: string; content: Uint8Array }[];
30 deleted: string[];
31}
33export type WorkerResponse =
34 | { type: 'output'; text: string }
35 | { type: 'drawnow'; plotInstructions: PlotInstruction[] }
36 | { type: 'done'; plotInstructions: PlotInstruction[]; vfsChanges?: VfsChanges }
37 | { type: 'error'; message: string; vfsChanges?: VfsChanges };