JerryI / wolfram-js-frontend

Dynamic Notebook Environment for Wolfram Language written in Javascript
https://jerryi.github.io/wljs-docs/
GNU General Public License v3.0
307 stars 13 forks source link

Headless mode (sort of). Execute cells / dynamics from any page on the internet using local wolfram server #34

Closed JerryI closed 8 months ago

JerryI commented 1 year ago

The original idea was suggested by one of the developers - @KirillBelovTest

  1. Allow notebook to be exported as .html or whatever web format (already done)
  2. Bring interactivity to the page if user has wolframscript installed (or frontend)
  3. Use urlprotocol to connect to the Kernel using secure websockets
  4. Evaluate cells and etc (without saving) them from the page
userrand commented 1 year ago

Do you mean like selecting text in the wolfram documentation or on stackexchange right clicking on the selected text and selecting evaluate wolfram code from the right click menu? Injecting javascript from a server into a page sounds like something a web extension could do but I am not sure. I never built a web extension.

JerryI commented 1 year ago

I was thinking publishing notebooks as HTML files or React components (or any other way) like one can do now, but bringing possibility to evaluate cells in the notebook using websockets, connected to the locally running Wolfram Kernel.

Imagine, you wrote a blog with an inset of some of your calculations or whatever. In general user can see the static data, plots (sometimes can even drag sliders and etc). Then, on attempt to do something with those cells a website uses so-called custom url protocol (file://, vscode://, mailto:// ...). Most apps uses it to send a mail to the corresponding email address, when a user click on link or opens a VSCode or some messenger app you have or AppStore or Windows Store, so it is quite common nowadays. But now, we will register a custom url protocol used to open a wolframscript session with a single file, that will run a local server and will attach to the webpage you are looking at. Therefore, you can run cells, see the result, while actual page is hosted somewhere else and the provider doest even know anything about what you are doing. Because all magic is done in a preloaded static HTML page with javascript running on its side. No extensions needed, just a page with and a single link that kicks a wolframscript.

So just to check out someone's work, you just need to open a page with it, press Shift-Enter and see the results.

The problem is to register this protocol, however, since now I am shipping frontend as real executable desktop app, It won't be a problem to do all this stuff during the installation procedure.

I've seen something similar with python code pages a long time ago. But since it is an open-source thing, they recently managed to recompile an entire Python interpreter to run it inside a browser (webassembly). But, it's a different story ;)

However, you idea will also be possible with a sort of extension, that needs to be written (that's might be a problem). You are right.

userrand commented 1 year ago

Cool I see so it's for sharing notebooks made with the app and uploaded to the web like maybe kind of like how you would share an interactive Jupyter book https://jupyterbook.org/en/stable/interactive/interactive.html or the wolfram web demos https://demonstrations.wolfram.com/ but for an entire notebook without using wolfram cloud with its limitations on how much resources you can use (If I remember correctly). That could indeed be nice for collaborations.

JerryI commented 1 year ago

Yes, something like this. In principle one can also already run everything in a browser using wljs-interpreter . However, it does support only numerical computations and quite limited. Only if one can write a transpiler (compiler) from pure WL code to it, but it is very cumbersome task and requires tons of work.

userrand commented 1 year ago

Probably the future autonomous language models will be able to translate from the Wolfram Language to your syntax with a few examples of the intended syntax, documentation, and tests that they can generate and try (probably will need to be multimodal with vision). People can then tweak to their liking.

The translation task with expected outputs sounds straight forward enough that an upgrade to Open AI's code interpreter with added vision might be able to do it with a few examples of the intended outputs (although the costs for analysing images and repeated debugging might be significant).

I still plan on working on implementing some graph related functions but I am not sure if I should wait as the code seems to be unstable at the moment and I might loose time trying to understand the current code.

JerryI commented 1 year ago

I still plan on working on implementing some graph related functions but I am not sure if I should wait as the code seems to be unstable at the moment and I might loose time trying to understand the current code.

The GUI for plugins management is almost ready, the tutorial will come shortly after. So it is isolated system with its API, you actually do not need to know how it works inside to write plugins / whatever Screenshot 2023-08-29 at 16 04 09