@a10k/iridium-dev-server 0.0.2 → 0.0.4
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 +5 -3
- package/lib/define-module.js +4 -3
- package/lib/mcp.js +1 -1
- package/lib/notebooks.js +7 -5
- package/lib/viewer.js +4 -2
- package/package.json +2 -2
- package/skill/SKILL.md +1 -1
package/Readme.md
CHANGED
|
@@ -4,7 +4,7 @@ Local dev server for working with Observable notebooks: edit them in [Iridium](h
|
|
|
4
4
|
|
|
5
5
|
> Published on npm as `@a10k/iridium-dev-server` (previously `@wishyoulization/iridium-dev-server`).
|
|
6
6
|
|
|
7
|
-
Cells are compiled by Observable's own engine, [Notebook Kit](https://observablehq.com/notebook-kit/kit): classic Observable JavaScript (`viewof`, `mutable`, `import {x} from "@user/notebook"`, `require(…)`) and plain JavaScript cells (several statements, `const` declarations, `npm:` imports, `display(…)`), as in Observable Notebooks 2.0.
|
|
7
|
+
Cells are compiled by Observable's own engine, [Notebook Kit](https://observablehq.com/notebook-kit/kit): classic Observable JavaScript (`viewof`, `mutable`, `import {x} from "@user/notebook"`, `require(…)`) and plain JavaScript cells (several statements, `const` declarations, `npm:` imports, `display(…)`), as in Observable Notebooks 2.0. Plain JavaScript cells may use TypeScript syntax (type annotations, interfaces): the types are removed and the cell runs as plain JavaScript, without type checking.
|
|
8
8
|
|
|
9
9
|
It also includes an [MCP](https://modelcontextprotocol.io) server and a skill, so AI assistants such as Claude can build notebooks with you, live, in the tab you're watching.
|
|
10
10
|
|
|
@@ -63,6 +63,8 @@ import { points } from "./my-data.js"
|
|
|
63
63
|
|
|
64
64
|
Paths resolve against the page (the server root), so `./my-data.js` is the compiled `my-data` notebook. Save the imported notebook first so its module is up to date. Names without a path (`@d3/color-legend`, or a notebook id) still load from observablehq.com, and full URLs are imported as written.
|
|
65
65
|
|
|
66
|
+
Other relative URLs in cells and in the `head` option (`fetch("./data.json")`, `<img src="./libs/logo.svg">`, `<link href="./libs/index.css">`) also resolve against the server root, so files in the `static` or `compiled` folders work with `./` paths. `FileAttachment("x")` reads from the notebook's own files folder (`<notebooks>/<name>/`).
|
|
67
|
+
|
|
66
68
|
## Notebook list API
|
|
67
69
|
|
|
68
70
|
`GET /api/notebooks?q=&page=1&per_page=25&sort=name|modified` returns the notebooks whose name or title contains `q` (any case), one page at a time. For example, with `my-notebook` and `my-data` saved, `GET /api/notebooks?q=my` returns:
|
|
@@ -173,7 +175,7 @@ Notebooks are saved in Notebook Kit's HTML format (`<name>.html`), the open form
|
|
|
173
175
|
</notebook>
|
|
174
176
|
```
|
|
175
177
|
|
|
176
|
-
- Classic Observable JavaScript cells are stored as `application/vnd.observable.javascript`, plain JavaScript cells as `module
|
|
178
|
+
- Classic Observable JavaScript cells are stored as `application/vnd.observable.javascript`, plain JavaScript cells as `module`, TypeScript cells as `text/x-typescript` (Observable Desktop's `ts` mode). Pinned cells (editor visible) have `pinned`.
|
|
177
179
|
- Markdown, HTML, TeX and Graphviz cells from Observable Desktop open as the equivalent `md`/`html`/`tex`/`dot` template and are saved back in their own mode. Other modes (SQL, Python, …) can't run in Iridium but are kept unchanged.
|
|
178
180
|
- **Legacy `.ojs` notebooks** are still read. The first save writes `<name>.html` next to it; from then on the `.html` file is used. The `.ojs` file is left untouched, so delete it once you're happy with the conversion.
|
|
179
181
|
|
|
@@ -194,7 +196,7 @@ runtime.module(define, Inspector.into(document.body));
|
|
|
194
196
|
|
|
195
197
|
- Works with `@observablehq/runtime` 5.9+ (runtime 5 includes the standard library and `fileAttachments`, so `new Runtime()` is enough) and 6 as above.
|
|
196
198
|
- Every named cell is passed to `observer(name)`, so you can pick cells to render by name.
|
|
197
|
-
- Plain JavaScript cells: each `display(…)` call in a run goes to its own observer; top-level declarations are named variables.
|
|
199
|
+
- Plain JavaScript and TypeScript cells: each `display(…)` call in a run goes to its own observer; top-level declarations are named variables.
|
|
198
200
|
- Built-ins specific to Notebook Kit (such as the sample datasets like `penguins`) aren't in `@observablehq/stdlib`; provide them yourself if an embedded notebook uses them.
|
|
199
201
|
|
|
200
202
|
## Configuration
|
package/lib/define-module.js
CHANGED
|
@@ -50,9 +50,10 @@ const defineCell = (record, index) => {
|
|
|
50
50
|
let runtimeInputs = inputs.map(classicName);
|
|
51
51
|
const lines = [];
|
|
52
52
|
|
|
53
|
-
// Plain JavaScript cells may call display()/view(): give
|
|
53
|
+
// Plain JavaScript and TypeScript cells may call display()/view(): give
|
|
54
|
+
// them the shim. In
|
|
54
55
|
// Observable JavaScript those are ordinary names (e.g. an imported view).
|
|
55
|
-
const usesDisplay = record.mode
|
|
56
|
+
const usesDisplay = record.mode !== 'ojs' && (inputs.includes('display') || inputs.includes('view'));
|
|
56
57
|
if (usesDisplay) {
|
|
57
58
|
const shim = `display${index}`;
|
|
58
59
|
lines.push(` const ${shim} = cellDisplay(observer);`);
|
|
@@ -115,7 +116,7 @@ const fileAttachments = ({ folder, names = [] } = {}) =>
|
|
|
115
116
|
|
|
116
117
|
export const compileModule = (cells, { name, files } = {}) => {
|
|
117
118
|
const definitions = cells
|
|
118
|
-
.filter((cell) => !cell.mode || ['ojs', 'js', 'md', 'html', 'tex', 'dot'].includes(cell.mode))
|
|
119
|
+
.filter((cell) => !cell.mode || ['ojs', 'js', 'ts', 'md', 'html', 'tex', 'dot'].includes(cell.mode))
|
|
119
120
|
.map((cell, index) => defineCell(compileCell(String(cell.sourceCode ?? '')), index + 1));
|
|
120
121
|
return `// Compiled by iridium-dev-server${name ? ` from ${name}` : ''}. Do not edit.
|
|
121
122
|
${HELPERS}
|
package/lib/mcp.js
CHANGED
|
@@ -12,7 +12,7 @@ The tools work on the notebook open in the user's browser tab, as if the user we
|
|
|
12
12
|
|
|
13
13
|
Edits are unsaved until saved, like the user's own edits (unsaved_changes in results). Save only when the user asks you to. Address cells by id or by the name they define (cell: "data"). For small changes to a long cell, edit_cell with replace: [{old, new}] patches its code instead of resending it. To open a notebook in a particular browser, pass browser (e.g. "Google Chrome") to create_notebook or open_notebook.
|
|
14
14
|
|
|
15
|
-
Cells are Observable JavaScript: \`name = expression\`, \`name = { ...; return value; }\` blocks, \`viewof x = Inputs.range([0, 10])\`, \`mutable x = 0\`, generators (yield), \`import {chart} from "@d3/bar-chart"\` from observablehq.com, \`md\\\`...\\\`\` and \`html\\\`...\\\`\` for text and markup. Cells react to each other by name in any order; each named cell is defined once. Plain JavaScript cells also work (several statements, \`const\` declarations shared with other cells, \`import {x} from "npm:pkg"\`, \`display(value)\`). Built-ins include d3, Plot, Inputs, htl, _ (lodash), md, html, svg, tex, dot, mermaid, DuckDBClient, FileAttachment, width, now, invalidation, Generators, require. Prefer Plot for charts and Inputs for controls, and use \`width\` for responsive sizes.`;
|
|
15
|
+
Cells are Observable JavaScript: \`name = expression\`, \`name = { ...; return value; }\` blocks, \`viewof x = Inputs.range([0, 10])\`, \`mutable x = 0\`, generators (yield), \`import {chart} from "@d3/bar-chart"\` from observablehq.com, \`md\\\`...\\\`\` and \`html\\\`...\\\`\` for text and markup. Cells react to each other by name in any order; each named cell is defined once. Plain JavaScript cells also work (several statements, \`const\` declarations shared with other cells, \`import {x} from "npm:pkg"\`, \`display(value)\`), and may use TypeScript syntax (types are stripped, not checked). Built-ins include d3, Plot, Inputs, htl, _ (lodash), md, html, svg, tex, dot, mermaid, DuckDBClient, FileAttachment, width, now, invalidation, Generators, require. Prefer Plot for charts and Inputs for controls, and use \`width\` for responsive sizes.`;
|
|
16
16
|
|
|
17
17
|
const text = (value) => ({
|
|
18
18
|
content: [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value, null, 2) }],
|
package/lib/notebooks.js
CHANGED
|
@@ -40,8 +40,9 @@ export const notebookPath = (dir, name) => {
|
|
|
40
40
|
// --- Cell types -------------------------------------------------------------
|
|
41
41
|
|
|
42
42
|
// Same rule as Iridium (src/compile.js): Observable JavaScript first, plain
|
|
43
|
-
// JavaScript if it is not valid Observable JavaScript
|
|
44
|
-
// plain JavaScript. Cells that compile as
|
|
43
|
+
// JavaScript if it is not valid Observable JavaScript, then TypeScript;
|
|
44
|
+
// npm:/jsr: imports are plain JavaScript. Cells that compile as none of these
|
|
45
|
+
// are kept as Observable JS.
|
|
45
46
|
const PACKAGE_IMPORT = /\bfrom\s*(["'])(npm|jsr):/;
|
|
46
47
|
export const cellMode = (source) => {
|
|
47
48
|
const compiles = (mode) => {
|
|
@@ -55,6 +56,7 @@ export const cellMode = (source) => {
|
|
|
55
56
|
if (PACKAGE_IMPORT.test(source) && compiles('js')) return 'js';
|
|
56
57
|
if (compiles('ojs')) return 'ojs';
|
|
57
58
|
if (compiles('js')) return 'js';
|
|
59
|
+
if (compiles('ts')) return 'ts';
|
|
58
60
|
return 'ojs';
|
|
59
61
|
};
|
|
60
62
|
|
|
@@ -85,9 +87,9 @@ export const readNotebookMeta = (path) => {
|
|
|
85
87
|
|
|
86
88
|
const readHtml = (html) =>
|
|
87
89
|
deserialize(html, { parser: new window.DOMParser() }).cells.map(({ id, value, mode, pinned }) => {
|
|
88
|
-
if (mode === 'ojs' || mode === 'js') return { id, pin: pinned, sourceCode: value };
|
|
90
|
+
if (mode === 'ojs' || mode === 'js' || mode === 'ts') return { id, pin: pinned, sourceCode: value };
|
|
89
91
|
const tag = TEMPLATE_TAGS[mode];
|
|
90
|
-
// Other modes (SQL, Python,
|
|
92
|
+
// Other modes (SQL, Python, …) can't run in Iridium; keep them
|
|
91
93
|
// as they are so saving doesn't lose them.
|
|
92
94
|
return { id, pin: pinned, mode, sourceCode: tag ? toTemplate(tag, value) : value };
|
|
93
95
|
});
|
|
@@ -125,7 +127,7 @@ const toKitCell = ({ id, pin, sourceCode, mode }, index) => {
|
|
|
125
127
|
if (tag) {
|
|
126
128
|
const inner = fromTemplate(tag, value);
|
|
127
129
|
if (inner != null) return { ...cell, mode, value: inner };
|
|
128
|
-
} else if (mode && mode !== 'ojs' && mode !== 'js') {
|
|
130
|
+
} else if (mode && mode !== 'ojs' && mode !== 'js' && mode !== 'ts') {
|
|
129
131
|
return { ...cell, mode, value }; // unsupported mode: saved back unchanged
|
|
130
132
|
}
|
|
131
133
|
return { ...cell, mode: cellMode(value), value };
|
package/lib/viewer.js
CHANGED
|
@@ -6,8 +6,6 @@ export const viewerPage = ({ name, iridiumBase, filesBase, head }) => `<!DOCTYPE
|
|
|
6
6
|
<head>
|
|
7
7
|
<meta charset="utf-8" />
|
|
8
8
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
9
|
-
<!-- FileAttachment("x") resolves against the base URL: the notebook's files folder. -->
|
|
10
|
-
<base href="${filesBase}" />
|
|
11
9
|
<!-- The tab's connection to the server: macOS-style green dot when connected, grey otherwise. -->
|
|
12
10
|
<link rel="icon" id="iridium-status" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6.5' fill='%23c8c8c8' stroke='%23a6a6a6'/%3E%3C/svg%3E" />
|
|
13
11
|
<title>${name.replace(/[<&]/g, '')} · Iridium</title>
|
|
@@ -35,6 +33,10 @@ export const viewerPage = ({ name, iridiumBase, filesBase, head }) => `<!DOCTYPE
|
|
|
35
33
|
};
|
|
36
34
|
|
|
37
35
|
// This page edits one notebook, named by the URL.
|
|
36
|
+
// FileAttachment("x") is in the notebook's files folder. No <base>, so
|
|
37
|
+
// other relative URLs (fetch, img, head links) resolve against the
|
|
38
|
+
// server root, next to the notebooks.
|
|
39
|
+
Iridium.files_base = ${json(filesBase)};
|
|
38
40
|
Iridium.get_recent = () => name;
|
|
39
41
|
Iridium.set_recent = () => {};
|
|
40
42
|
Iridium.list = () => post('/list', {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a10k/iridium-dev-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Local dev server for working with Observable notebooks.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node": ">=22"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@a10k/iridium": "~0.0.
|
|
27
|
+
"@a10k/iridium": "~0.0.4",
|
|
28
28
|
"@koa/bodyparser": "^6.1.0",
|
|
29
29
|
"@koa/cors": "^5.0.0",
|
|
30
30
|
"@koa/router": "^15.7.1",
|
package/skill/SKILL.md
CHANGED
|
@@ -71,7 +71,7 @@ import {Legend} from "@d3/color-legend" // reuse cells from notebooks
|
|
|
71
71
|
|
|
72
72
|
Rules: one cell per name; cells can reference each other in any order; a cell is an expression, `name = expression`, or a `{ … return … }` block. Use `viewof name = Inputs.*(…)` for controls (the cell's value is the input's value). `this` is the cell's previous value.
|
|
73
73
|
|
|
74
|
-
**Plain JavaScript cells** also work (as in Observable Notebooks 2.0): several statements, top-level `const`/`let`/`function` shared with other cells, `import {x} from "npm:package"`, and `display(value)` to show output.
|
|
74
|
+
**Plain JavaScript cells** also work (as in Observable Notebooks 2.0): several statements, top-level `const`/`let`/`function` shared with other cells, `import {x} from "npm:package"`, and `display(value)` to show output. These cells may also use TypeScript syntax (`const n: number = 1`, `interface P { x: number }`); types are stripped, not checked.
|
|
75
75
|
|
|
76
76
|
```js
|
|
77
77
|
import {csvParse} from "npm:d3-dsv";
|