@runtimed/node 0.1.1 → 0.2.2

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 CHANGED
@@ -24,12 +24,24 @@ async function main() {
24
24
  const session = await createNotebook({
25
25
  runtime: "python",
26
26
  workingDir: process.cwd(),
27
+ // Record these before the first cell runs.
28
+ dependencies: ["numpy", "matplotlib"],
29
+ description: "plotting smoke test",
27
30
  });
28
31
 
29
32
  try {
30
33
  console.log("daemon socket:", defaultSocketPath());
31
34
 
32
- const result = await session.runCell("sum(range(10))");
35
+ await session.syncEnvironment();
36
+
37
+ const result = await session.runCell(`
38
+ import numpy as np
39
+ import matplotlib.pyplot as plt
40
+
41
+ x = np.linspace(0, 6.28, 200)
42
+ plt.plot(x, np.sin(x))
43
+ plt.show()
44
+ `);
33
45
  console.log(result.status);
34
46
  console.log(result.outputs);
35
47
 
@@ -45,19 +57,62 @@ main().catch((error) => {
45
57
  });
46
58
  ```
47
59
 
60
+ ## Notebook Dependencies
61
+
62
+ `createNotebook()` accepts `dependencies` so agent code can declare packages
63
+ up-front instead of failing the first import and retrying after `addDependencies()`.
64
+ When `packageManager` is omitted, the daemon/user environment choice remains in
65
+ charge. Later dependency edits also infer the manager from the running kernel,
66
+ inline notebook metadata (`uv`, then `conda`, then `pixi`), or detected project
67
+ file, falling back to UV for fresh Python notebooks with no other signal. Pass
68
+ the native binding's `PackageManager` string enum (`"uv"`, `"conda"`, or
69
+ `"pixi"`) only when you need to target a specific metadata section.
70
+ `description` can be used as a human-readable peer label for agent-created
71
+ sessions.
72
+
48
73
  ## API Surface
49
74
 
50
75
  - `defaultSocketPath()` returns the socket path for the current nteract channel
51
76
  or the `RUNTIMED_SOCKET_PATH` override.
52
77
  - `socketPathForChannel("stable" | "nightly")` returns a channel-specific
53
78
  daemon socket path.
54
- - `createNotebook(options)` creates a notebook and starts a runtime.
55
- - `openNotebook(notebookId, options)` connects to an existing notebook.
79
+ - `listActiveNotebooks(options)` lists active daemon notebook rooms.
80
+ - `createNotebook(options)` creates a notebook and records optional first-call dependencies.
81
+ - `openNotebook(notebookId, options)` connects to an existing daemon notebook.
82
+ - `openNotebookPath(path, options)` opens a notebook file through the daemon.
83
+ - `showNotebook(options)` opens an active notebook or path in nteract Desktop,
84
+ returning a structured `opened: false` response in headless environments.
85
+ - `shutdownNotebook(notebookId, options)` shuts down a notebook room by ID.
56
86
  - `getExecutionResult(executionId, options)` reads a result by execution ID.
87
+ - `Session.listCells()` and `Session.getCell(cellId)` inspect notebook cells.
88
+ - `Session.createCell(source, options)`, `Session.setCell(cellId, options)`,
89
+ `Session.deleteCell(cellId)`, and `Session.moveCell(cellId, options)` provide
90
+ direct notebook editing without MCP JSON round-trips.
91
+ - `Session.executeCell(cellId, options)` runs an existing code cell.
92
+ - `Session.showNotebook()` opens the session in nteract Desktop when a display
93
+ is available.
94
+ - `Session.interruptKernel()`, `Session.shutdownKernel()`, and
95
+ `Session.restartKernel()` manage the running kernel.
96
+ - `Session.shutdownNotebook()` shuts down this notebook room and closes the session.
57
97
  - `Session.runCell(source, options)` creates, runs, and waits for a cell.
58
98
  - `Session.queueCell(source, options)` queues a cell and returns IDs.
59
99
  - `Session.waitForExecution(executionId, options)` waits for queued work.
60
- - `Session.addUvDependency(spec)` records a UV dependency for the notebook.
100
+ Pass `onUpdate(progress)` to receive resolved output snapshots while the
101
+ execution is still running.
102
+ - `Session.runtimeState$`, `Session.executionTransitions$`,
103
+ `Session.cellChanges$`, `Session.broadcasts$`, and `Session.sessionStatus$`
104
+ expose the same projected event families used by the browser sync engine.
105
+ - `Session.addDependency(spec, { packageManager })` /
106
+ `Session.addDependencies(specs, { packageManager })` and
107
+ `Session.removeDependency(spec, { packageManager })` /
108
+ `Session.removeDependencies(specs, { packageManager })` edit notebook
109
+ dependency metadata for UV, Conda, or Pixi. Omit `packageManager` to follow
110
+ the notebook's running/configured manager. Batch variants use one CRDT
111
+ metadata transaction.
112
+ - `Session.getDependencyStatus()` returns dependency metadata, fingerprint, and
113
+ trust state in one call.
114
+ - `Session.getRuntimeStatus()` returns kernel lifecycle, activity, env source,
115
+ and startup error details.
61
116
  - `Session.syncEnvironment()` installs recorded notebook dependencies.
62
117
  - `Session.saveNotebook(path?)` saves the notebook.
63
118
  - `Session.close()` releases the daemon connection.
@@ -74,6 +129,22 @@ cargo xtask dev-daemon
74
129
  Published nteract desktop builds manage their own daemon. Set
75
130
  `RUNTIMED_SOCKET_PATH` when you need to connect to a specific daemon instance.
76
131
 
132
+ ## Development Smoke Test
133
+
134
+ After building the native binding, run the daemon-backed API smoke test with:
135
+
136
+ ```bash
137
+ RUNTIMED_SOCKET_PATH=/path/to/runtimed.sock pnpm --dir packages/runtimed-node smoke:api
138
+ ```
139
+
140
+ When testing an out-of-tree N-API build, point the smoke script at it:
141
+
142
+ ```bash
143
+ RUNTIMED_NODE_SMOKE_MODULE=/tmp/runtimed-node-napi-check/index.cjs \
144
+ RUNTIMED_SOCKET_PATH=/path/to/runtimed.sock \
145
+ pnpm --dir packages/runtimed-node smoke:api
146
+ ```
147
+
77
148
  ## Platform Packages
78
149
 
79
150
  The platform packages are implementation details and should normally be
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtimed/node",
3
- "version": "0.1.1",
3
+ "version": "0.2.2",
4
4
  "description": "Node.js bindings for controlling nteract runtimed notebooks and Python kernels.",
5
5
  "type": "module",
6
6
  "license": "BSD-3-Clause",
@@ -35,6 +35,8 @@
35
35
  "README.md",
36
36
  "src/index.cjs",
37
37
  "src/index.d.ts",
38
+ "src/session.cjs",
39
+ "src/napi-observables.cjs",
38
40
  "src/binding.cjs",
39
41
  "src/binding.d.ts"
40
42
  ],
@@ -46,10 +48,14 @@
46
48
  "x86_64-pc-windows-msvc"
47
49
  ]
48
50
  },
51
+ "dependencies": {
52
+ "rxjs": "^7.8.2",
53
+ "runtimed": "0.2.4"
54
+ },
49
55
  "optionalDependencies": {
50
- "@runtimed/node-darwin-arm64": "0.1.1",
51
- "@runtimed/node-linux-x64-gnu": "0.1.1",
52
- "@runtimed/node-win32-x64-msvc": "0.1.1"
56
+ "@runtimed/node-darwin-arm64": "0.2.2",
57
+ "@runtimed/node-linux-x64-gnu": "0.2.2",
58
+ "@runtimed/node-win32-x64-msvc": "0.2.2"
53
59
  },
54
60
  "publishConfig": {
55
61
  "access": "public"
@@ -63,6 +69,7 @@
63
69
  "build:debug": "napi build --platform --js binding.cjs --dts binding.d.ts --manifest-path ../../crates/runtimed-node/Cargo.toml --output-dir src",
64
70
  "pack:platform:dry-run": "node scripts/assemble-platform-package.mjs --pack-dry-run",
65
71
  "pack:dry-run": "pnpm pack --dry-run",
66
- "smoke": "node -e \"const m = require('./src/index.cjs'); console.log('defaultSocketPath:', m.defaultSocketPath());\""
72
+ "smoke": "node -e \"const m = require('./src/index.cjs'); console.log('defaultSocketPath:', m.defaultSocketPath());\"",
73
+ "smoke:api": "node scripts/smoke-api.cjs"
67
74
  }
68
75
  }
package/src/binding.cjs CHANGED
@@ -77,8 +77,8 @@ function requireNative() {
77
77
  try {
78
78
  const binding = require('@runtimed/node-android-arm64')
79
79
  const bindingPackageVersion = require('@runtimed/node-android-arm64/package.json').version
80
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
82
  }
83
83
  return binding
84
84
  } catch (e) {
@@ -93,8 +93,8 @@ function requireNative() {
93
93
  try {
94
94
  const binding = require('@runtimed/node-android-arm-eabi')
95
95
  const bindingPackageVersion = require('@runtimed/node-android-arm-eabi/package.json').version
96
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
98
  }
99
99
  return binding
100
100
  } catch (e) {
@@ -114,8 +114,8 @@ function requireNative() {
114
114
  try {
115
115
  const binding = require('@runtimed/node-win32-x64-gnu')
116
116
  const bindingPackageVersion = require('@runtimed/node-win32-x64-gnu/package.json').version
117
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
119
  }
120
120
  return binding
121
121
  } catch (e) {
@@ -130,8 +130,8 @@ function requireNative() {
130
130
  try {
131
131
  const binding = require('@runtimed/node-win32-x64-msvc')
132
132
  const bindingPackageVersion = require('@runtimed/node-win32-x64-msvc/package.json').version
133
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
135
  }
136
136
  return binding
137
137
  } catch (e) {
@@ -147,8 +147,8 @@ function requireNative() {
147
147
  try {
148
148
  const binding = require('@runtimed/node-win32-ia32-msvc')
149
149
  const bindingPackageVersion = require('@runtimed/node-win32-ia32-msvc/package.json').version
150
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
152
  }
153
153
  return binding
154
154
  } catch (e) {
@@ -163,8 +163,8 @@ function requireNative() {
163
163
  try {
164
164
  const binding = require('@runtimed/node-win32-arm64-msvc')
165
165
  const bindingPackageVersion = require('@runtimed/node-win32-arm64-msvc/package.json').version
166
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
168
  }
169
169
  return binding
170
170
  } catch (e) {
@@ -182,8 +182,8 @@ function requireNative() {
182
182
  try {
183
183
  const binding = require('@runtimed/node-darwin-universal')
184
184
  const bindingPackageVersion = require('@runtimed/node-darwin-universal/package.json').version
185
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
187
  }
188
188
  return binding
189
189
  } catch (e) {
@@ -198,8 +198,8 @@ function requireNative() {
198
198
  try {
199
199
  const binding = require('@runtimed/node-darwin-x64')
200
200
  const bindingPackageVersion = require('@runtimed/node-darwin-x64/package.json').version
201
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
203
  }
204
204
  return binding
205
205
  } catch (e) {
@@ -214,8 +214,8 @@ function requireNative() {
214
214
  try {
215
215
  const binding = require('@runtimed/node-darwin-arm64')
216
216
  const bindingPackageVersion = require('@runtimed/node-darwin-arm64/package.json').version
217
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
219
  }
220
220
  return binding
221
221
  } catch (e) {
@@ -234,8 +234,8 @@ function requireNative() {
234
234
  try {
235
235
  const binding = require('@runtimed/node-freebsd-x64')
236
236
  const bindingPackageVersion = require('@runtimed/node-freebsd-x64/package.json').version
237
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
239
  }
240
240
  return binding
241
241
  } catch (e) {
@@ -250,8 +250,8 @@ function requireNative() {
250
250
  try {
251
251
  const binding = require('@runtimed/node-freebsd-arm64')
252
252
  const bindingPackageVersion = require('@runtimed/node-freebsd-arm64/package.json').version
253
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
255
  }
256
256
  return binding
257
257
  } catch (e) {
@@ -271,8 +271,8 @@ function requireNative() {
271
271
  try {
272
272
  const binding = require('@runtimed/node-linux-x64-musl')
273
273
  const bindingPackageVersion = require('@runtimed/node-linux-x64-musl/package.json').version
274
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
276
  }
277
277
  return binding
278
278
  } catch (e) {
@@ -287,8 +287,8 @@ function requireNative() {
287
287
  try {
288
288
  const binding = require('@runtimed/node-linux-x64-gnu')
289
289
  const bindingPackageVersion = require('@runtimed/node-linux-x64-gnu/package.json').version
290
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
292
  }
293
293
  return binding
294
294
  } catch (e) {
@@ -305,8 +305,8 @@ function requireNative() {
305
305
  try {
306
306
  const binding = require('@runtimed/node-linux-arm64-musl')
307
307
  const bindingPackageVersion = require('@runtimed/node-linux-arm64-musl/package.json').version
308
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
310
  }
311
311
  return binding
312
312
  } catch (e) {
@@ -321,8 +321,8 @@ function requireNative() {
321
321
  try {
322
322
  const binding = require('@runtimed/node-linux-arm64-gnu')
323
323
  const bindingPackageVersion = require('@runtimed/node-linux-arm64-gnu/package.json').version
324
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
326
  }
327
327
  return binding
328
328
  } catch (e) {
@@ -339,8 +339,8 @@ function requireNative() {
339
339
  try {
340
340
  const binding = require('@runtimed/node-linux-arm-musleabihf')
341
341
  const bindingPackageVersion = require('@runtimed/node-linux-arm-musleabihf/package.json').version
342
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
344
  }
345
345
  return binding
346
346
  } catch (e) {
@@ -355,8 +355,8 @@ function requireNative() {
355
355
  try {
356
356
  const binding = require('@runtimed/node-linux-arm-gnueabihf')
357
357
  const bindingPackageVersion = require('@runtimed/node-linux-arm-gnueabihf/package.json').version
358
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
360
  }
361
361
  return binding
362
362
  } catch (e) {
@@ -373,8 +373,8 @@ function requireNative() {
373
373
  try {
374
374
  const binding = require('@runtimed/node-linux-loong64-musl')
375
375
  const bindingPackageVersion = require('@runtimed/node-linux-loong64-musl/package.json').version
376
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
378
  }
379
379
  return binding
380
380
  } catch (e) {
@@ -389,8 +389,8 @@ function requireNative() {
389
389
  try {
390
390
  const binding = require('@runtimed/node-linux-loong64-gnu')
391
391
  const bindingPackageVersion = require('@runtimed/node-linux-loong64-gnu/package.json').version
392
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
394
  }
395
395
  return binding
396
396
  } catch (e) {
@@ -407,8 +407,8 @@ function requireNative() {
407
407
  try {
408
408
  const binding = require('@runtimed/node-linux-riscv64-musl')
409
409
  const bindingPackageVersion = require('@runtimed/node-linux-riscv64-musl/package.json').version
410
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
412
  }
413
413
  return binding
414
414
  } catch (e) {
@@ -423,8 +423,8 @@ function requireNative() {
423
423
  try {
424
424
  const binding = require('@runtimed/node-linux-riscv64-gnu')
425
425
  const bindingPackageVersion = require('@runtimed/node-linux-riscv64-gnu/package.json').version
426
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
428
  }
429
429
  return binding
430
430
  } catch (e) {
@@ -440,8 +440,8 @@ function requireNative() {
440
440
  try {
441
441
  const binding = require('@runtimed/node-linux-ppc64-gnu')
442
442
  const bindingPackageVersion = require('@runtimed/node-linux-ppc64-gnu/package.json').version
443
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
445
  }
446
446
  return binding
447
447
  } catch (e) {
@@ -456,8 +456,8 @@ function requireNative() {
456
456
  try {
457
457
  const binding = require('@runtimed/node-linux-s390x-gnu')
458
458
  const bindingPackageVersion = require('@runtimed/node-linux-s390x-gnu/package.json').version
459
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
461
  }
462
462
  return binding
463
463
  } catch (e) {
@@ -476,8 +476,8 @@ function requireNative() {
476
476
  try {
477
477
  const binding = require('@runtimed/node-openharmony-arm64')
478
478
  const bindingPackageVersion = require('@runtimed/node-openharmony-arm64/package.json').version
479
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
481
  }
482
482
  return binding
483
483
  } catch (e) {
@@ -492,8 +492,8 @@ function requireNative() {
492
492
  try {
493
493
  const binding = require('@runtimed/node-openharmony-x64')
494
494
  const bindingPackageVersion = require('@runtimed/node-openharmony-x64/package.json').version
495
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
497
  }
498
498
  return binding
499
499
  } catch (e) {
@@ -508,8 +508,8 @@ function requireNative() {
508
508
  try {
509
509
  const binding = require('@runtimed/node-openharmony-arm')
510
510
  const bindingPackageVersion = require('@runtimed/node-openharmony-arm/package.json').version
511
- if (bindingPackageVersion !== '0.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
- throw new Error(`Native binding package version mismatch, expected 0.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '0.2.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 0.2.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
@@ -576,11 +576,17 @@ if (!nativeBinding) {
576
576
  }
577
577
 
578
578
  module.exports = nativeBinding
579
+ module.exports.EventSubscription = nativeBinding.EventSubscription
579
580
  module.exports.Session = nativeBinding.Session
580
581
  module.exports.createNotebook = nativeBinding.createNotebook
581
582
  module.exports.defaultSocketPath = nativeBinding.defaultSocketPath
582
583
  module.exports.getExecutionResult = nativeBinding.getExecutionResult
584
+ module.exports.listActiveNotebooks = nativeBinding.listActiveNotebooks
583
585
  module.exports.openNotebook = nativeBinding.openNotebook
586
+ module.exports.openNotebookPath = nativeBinding.openNotebookPath
587
+ module.exports.PackageManager = nativeBinding.PackageManager
584
588
  module.exports.readParquetFile = nativeBinding.readParquetFile
589
+ module.exports.showNotebook = nativeBinding.showNotebook
590
+ module.exports.shutdownNotebook = nativeBinding.shutdownNotebook
585
591
  module.exports.socketPathForChannel = nativeBinding.socketPathForChannel
586
592
  module.exports.summarizeParquetFile = nativeBinding.summarizeParquetFile
package/src/binding.d.ts CHANGED
@@ -1,9 +1,39 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+ /** A live event subscription returned by `Session.on*` methods. */
4
+ export declare class EventSubscription {
5
+ /** Stop delivering events to the callback. */
6
+ dispose(): void
7
+ }
8
+
3
9
  /** A connected notebook session. */
4
10
  export declare class Session {
5
11
  /** The notebook ID (always a UUID). */
6
12
  get notebookId(): string
13
+ /** Subscribe to RuntimeStateDoc snapshots. Callback receives a JSON string. */
14
+ onRuntimeState(callback: (arg0: string) => void): EventSubscription
15
+ /** Subscribe to execution lifecycle transitions. Callback receives a JSON string. */
16
+ onExecutionTransition(callback: (arg0: string) => void): EventSubscription
17
+ /**
18
+ * Subscribe to resolved progress snapshots for one execution.
19
+ *
20
+ * Callback receives the same JSON shape as `CellResult`, emitted whenever
21
+ * the RuntimeStateDoc entry for the execution changes. The subscription
22
+ * ends after an authoritative terminal snapshot, including kernel
23
+ * failure/close.
24
+ */
25
+ onExecutionProgress(executionId: string, cellId: string | undefined | null, callback: (arg0: string) => void): EventSubscription
26
+ /**
27
+ * Subscribe to notebook document changes. Callback receives a JSON string.
28
+ *
29
+ * The native handle currently reports `null` as a full-materialization
30
+ * marker, matching the browser SyncEngine's no-changeset fallback.
31
+ */
32
+ onCellChange(callback: (arg0: string) => void): EventSubscription
33
+ /** Subscribe to comm broadcasts. Callback receives a JSON string. */
34
+ onBroadcast(callback: (arg0: string) => void): EventSubscription
35
+ /** Subscribe to handshake/readiness status updates. Callback receives a JSON string. */
36
+ onSessionStatus(callback: (arg0: string) => void): EventSubscription
7
37
  /**
8
38
  * Save the notebook to disk. If a path is given, saves to that path
9
39
  * (creating the file if needed). Otherwise saves to the original location.
@@ -11,11 +41,39 @@ export declare class Session {
11
41
  saveNotebook(path?: string | undefined | null): Promise<void>
12
42
  /** Close the session and release the underlying connection. */
13
43
  close(): Promise<void>
44
+ /**
45
+ * Add dependencies to the selected package manager in one CRDT transaction.
46
+ * When no manager is provided, the running/configured notebook manager is used.
47
+ * Call `syncEnvironment()` or restart the kernel to install them.
48
+ */
49
+ addDependencies(packages: Array<string>, options?: DependencyEditOptions | undefined | null): Promise<void>
50
+ /**
51
+ * Add a dependency to the selected package manager.
52
+ * When no manager is provided, the running/configured notebook manager is used.
53
+ * Call `syncEnvironment()` or restart the kernel to install it.
54
+ */
55
+ addDependency(pkg: string, options?: DependencyEditOptions | undefined | null): Promise<void>
56
+ /**
57
+ * Remove dependencies from the selected package manager in one CRDT transaction.
58
+ * When no manager is provided, the running/configured notebook manager is used.
59
+ * Returns the number of dependencies removed.
60
+ */
61
+ removeDependencies(packages: Array<string>, options?: DependencyEditOptions | undefined | null): Promise<number>
62
+ /**
63
+ * Remove a dependency from the selected package manager.
64
+ * When no manager is provided, the running/configured notebook manager is used.
65
+ * Returns true if a dependency was removed.
66
+ */
67
+ removeDependency(pkg: string, options?: DependencyEditOptions | undefined | null): Promise<boolean>
14
68
  /**
15
69
  * Add a UV dependency to the notebook (e.g. `"matplotlib>=3.8"`).
16
70
  * Call `syncEnvironment()` or restart the kernel to install it.
17
71
  */
18
72
  addUvDependency(pkg: string): Promise<void>
73
+ /** Get runtime/kernel state, including lifecycle error details. */
74
+ getRuntimeStatus(): Promise<RuntimeStatus>
75
+ /** Get dependency metadata, fingerprint, and current trust state. */
76
+ getDependencyStatus(): Promise<DependencyStatus>
19
77
  /** Get the current dependency fingerprint for diagnostics. */
20
78
  dependencyFingerprint(): Promise<string | null>
21
79
  /** Approve and sign the current dependency metadata. */
@@ -26,6 +84,23 @@ export declare class Session {
26
84
  * Returns once the install finishes.
27
85
  */
28
86
  syncEnvironment(): Promise<void>
87
+ /** Return all cells in notebook order. */
88
+ listCells(): Promise<Array<JsCellSnapshot>>
89
+ /** Return one cell by ID, or null if it does not exist. */
90
+ getCell(cellId: string): Promise<JsCellSnapshot | null>
91
+ /** Create a cell without executing it. Returns the new cell ID. */
92
+ createCell(source: string, options?: CreateCellOptions | undefined | null): Promise<string>
93
+ /** Replace a cell's source and/or type. Returns true if the cell existed. */
94
+ setCell(cellId: string, options: SetCellOptions): Promise<boolean>
95
+ /** Delete a cell. Returns true if the cell existed. */
96
+ deleteCell(cellId: string): Promise<boolean>
97
+ /**
98
+ * Move a cell after another cell, or to the beginning when omitted/null.
99
+ * Returns the new position string.
100
+ */
101
+ moveCell(cellId: string, options?: MoveCellOptions | undefined | null): Promise<string>
102
+ /** Execute an existing code cell and wait for terminal outputs. */
103
+ executeCell(cellId: string, options?: ExecuteCellOptions | undefined | null): Promise<CellResult>
29
104
  /**
30
105
  * Execute a source string as a new cell. Starts the kernel on demand.
31
106
  * Returns the cell's outputs once execution is terminal.
@@ -33,10 +108,36 @@ export declare class Session {
33
108
  runCell(source: string, options?: RunCellOptions | undefined | null): Promise<CellResult>
34
109
  /** Queue a source string as a new cell without waiting for execution. */
35
110
  queueCell(source: string, options?: QueueCellOptions | undefined | null): Promise<QueuedExecution>
111
+ /** Interrupt the currently executing cell. */
112
+ interruptKernel(): Promise<boolean>
113
+ /** Shutdown the running kernel. Returns false when no kernel is running. */
114
+ shutdownKernel(): Promise<boolean>
115
+ /** Restart the kernel, clearing in-memory state while preserving notebook dependencies. */
116
+ restartKernel(): Promise<boolean>
117
+ /** Shutdown this notebook's kernel and evict its daemon room. */
118
+ shutdownNotebook(): Promise<boolean>
119
+ /**
120
+ * Open this notebook in nteract Desktop. In headless environments, returns
121
+ * `opened: false` with a reason instead of failing.
122
+ */
123
+ showNotebook(): Promise<ShowNotebookResult>
36
124
  /** Wait for an already-queued execution in this live session. */
37
125
  waitForExecution(executionId: string, options?: WaitExecutionOptions | undefined | null): Promise<CellResult>
38
126
  }
39
127
 
128
+ /** An active notebook room reported by the daemon. */
129
+ export interface ActiveNotebook {
130
+ notebookId: string
131
+ activePeers: number
132
+ hadPeers: boolean
133
+ hasKernel: boolean
134
+ kernelType?: string
135
+ envSource?: string
136
+ kernelStatus?: string
137
+ ephemeral: boolean
138
+ notebookPath?: string
139
+ }
140
+
40
141
  /** Result of running a cell. */
41
142
  export interface CellResult {
42
143
  cellId: string
@@ -48,6 +149,21 @@ export interface CellResult {
48
149
  outputs: Array<JsOutput>
49
150
  }
50
151
 
152
+ /** Conda dependency metadata. */
153
+ export interface CondaDependencyStatus {
154
+ dependencies: Array<string>
155
+ channels: Array<string>
156
+ python?: string
157
+ }
158
+
159
+ /** Options for `Session.createCell()`. */
160
+ export interface CreateCellOptions {
161
+ /** Cell source type: `"code"` (default), `"markdown"`, or `"raw"`. */
162
+ cellType?: string
163
+ /** Insert after this cell, or omit to insert at the beginning. */
164
+ afterCellId?: string
165
+ }
166
+
51
167
  /** Create a new (ephemeral) notebook against the daemon. */
52
168
  export declare function createNotebook(options?: CreateNotebookOptions | undefined | null): Promise<Session>
53
169
 
@@ -61,6 +177,16 @@ export interface CreateNotebookOptions {
61
177
  socketPath?: string
62
178
  /** Actor label for presence / Automerge provenance. */
63
179
  peerLabel?: string
180
+ /** Human-readable session description. Used as the peer label when `peerLabel` is omitted. */
181
+ description?: string
182
+ /**
183
+ * Packages to record before the kernel starts (for example `["numpy", "matplotlib"]`).
184
+ * Python notebooks use the selected package manager; Deno notebooks treat these as
185
+ * runtime-native import dependencies.
186
+ */
187
+ dependencies?: Array<string>
188
+ /** Package manager for Python dependencies. Defaults to the daemon/user setting. */
189
+ packageManager?: PackageManager
64
190
  }
65
191
 
66
192
  /**
@@ -71,6 +197,40 @@ export interface CreateNotebookOptions {
71
197
  */
72
198
  export declare function defaultSocketPath(): string
73
199
 
200
+ /** Options for dependency edit methods. */
201
+ export interface DependencyEditOptions {
202
+ /**
203
+ * Dependency manager to edit. Defaults to the running/configured manager,
204
+ * falling back to UV for fresh Python notebooks.
205
+ */
206
+ packageManager?: PackageManager
207
+ }
208
+
209
+ /** Notebook dependency metadata and trust/runtime status. */
210
+ export interface DependencyStatus {
211
+ uv?: UvDependencyStatus
212
+ conda?: CondaDependencyStatus
213
+ pixi?: PixiDependencyStatus
214
+ fingerprint?: string
215
+ trust: DependencyTrustStatus
216
+ }
217
+
218
+ /** Notebook trust state for dependency metadata. */
219
+ export interface DependencyTrustStatus {
220
+ status?: string
221
+ needsApproval?: boolean
222
+ approvedUvDependencies: Array<string>
223
+ approvedCondaDependencies: Array<string>
224
+ approvedPixiDependencies: Array<string>
225
+ approvedPixiPypiDependencies: Array<string>
226
+ }
227
+
228
+ /** Options for `Session.executeCell()`. */
229
+ export interface ExecuteCellOptions {
230
+ /** Max milliseconds to wait for execution. Default 120_000 (2 min). */
231
+ timeoutMs?: number
232
+ }
233
+
74
234
  /** Read a terminal execution result from the daemon's durable execution store. */
75
235
  export declare function getExecutionResult(executionId: string, options?: GetExecutionResultOptions | undefined | null): Promise<CellResult>
76
236
 
@@ -80,6 +240,18 @@ export interface GetExecutionResultOptions {
80
240
  socketPath?: string
81
241
  }
82
242
 
243
+ /** A notebook cell snapshot. */
244
+ export interface JsCellSnapshot {
245
+ id: string
246
+ cellType: string
247
+ position: string
248
+ source: string
249
+ /** JSON-encoded metadata object. */
250
+ metadataJson: string
251
+ /** Legacy execution count as stored in the notebook doc. */
252
+ executionCount?: string
253
+ }
254
+
83
255
  /** One output from a cell. `data` values are: `{ type: "text"|"binary"|"json", value: ... }`. */
84
256
  export interface JsOutput {
85
257
  outputType: string
@@ -95,13 +267,47 @@ export interface JsOutput {
95
267
  blobPathsJson?: string
96
268
  }
97
269
 
270
+ /** List active notebook rooms from the daemon. */
271
+ export declare function listActiveNotebooks(options?: ListActiveNotebooksOptions | undefined | null): Promise<Array<ActiveNotebook>>
272
+
273
+ /** Options for top-level `listActiveNotebooks()`. */
274
+ export interface ListActiveNotebooksOptions {
275
+ /** Override daemon socket path (otherwise uses `defaultSocketPath()`). */
276
+ socketPath?: string
277
+ }
278
+
279
+ /** Options for `Session.moveCell()`. */
280
+ export interface MoveCellOptions {
281
+ /** Move after this cell, or omit/null to move to the beginning. */
282
+ afterCellId?: string
283
+ }
284
+
98
285
  /** Open an existing notebook by ID. */
99
286
  export declare function openNotebook(notebookId: string, options?: OpenNotebookOptions | undefined | null): Promise<Session>
100
287
 
101
- /** Options for `openNotebook()`. */
288
+ /** Options for `openNotebook()` and `openNotebookPath()`. */
102
289
  export interface OpenNotebookOptions {
103
290
  socketPath?: string
104
291
  peerLabel?: string
292
+ /** Human-readable session description. Used as the peer label when `peerLabel` is omitted. */
293
+ description?: string
294
+ }
295
+
296
+ /** Open an existing notebook file by path. */
297
+ export declare function openNotebookPath(path: string, options?: OpenNotebookOptions | undefined | null): Promise<Session>
298
+
299
+ /**
300
+ * Package manager for Python notebook dependencies.
301
+ *
302
+ * This mirrors `notebook_protocol::connection::PackageManager` at the N-API
303
+ * boundary. We cannot attach `#[napi]` to the protocol crate's external enum,
304
+ * and that enum intentionally includes an `Unknown(String)` wire-compatibility
305
+ * variant that should not be exposed as a typed JavaScript option.
306
+ */
307
+ export declare const enum PackageManager {
308
+ Uv = 'uv',
309
+ Conda = 'conda',
310
+ Pixi = 'pixi'
105
311
  }
106
312
 
107
313
  export interface ParquetColumnInfo {
@@ -128,6 +334,14 @@ export interface ParquetSummaryResult {
128
334
  columns: Array<ParquetColumnInfo>
129
335
  }
130
336
 
337
+ /** Pixi dependency metadata. */
338
+ export interface PixiDependencyStatus {
339
+ dependencies: Array<string>
340
+ pypiDependencies: Array<string>
341
+ channels: Array<string>
342
+ python?: string
343
+ }
344
+
131
345
  /** Options for `Session.queueCell()`. */
132
346
  export interface QueueCellOptions {
133
347
  /** Cell source type: `"code"` (default), `"markdown"`, or `"raw"`. */
@@ -154,6 +368,62 @@ export interface RunCellOptions {
154
368
  cellType?: string
155
369
  }
156
370
 
371
+ /** Runtime/kernel status from RuntimeStateDoc. */
372
+ export interface RuntimeStatus {
373
+ status: string
374
+ lifecycle: string
375
+ activity?: string
376
+ startingPhase: string
377
+ name: string
378
+ language: string
379
+ envSource: string
380
+ runtimeAgentId: string
381
+ errorReason?: string
382
+ errorDetails?: string
383
+ }
384
+
385
+ /** Options for `Session.setCell()`. */
386
+ export interface SetCellOptions {
387
+ /** New source text. Omit to leave unchanged. */
388
+ source?: string
389
+ /** New cell source type. Omit to leave unchanged. */
390
+ cellType?: string
391
+ }
392
+
393
+ /**
394
+ * Open a notebook in nteract Desktop by active notebook ID or file path.
395
+ * In headless environments, returns `opened: false` with a reason instead of failing.
396
+ */
397
+ export declare function showNotebook(options?: ShowNotebookOptions | undefined | null): Promise<ShowNotebookResult>
398
+
399
+ /** Options for top-level `showNotebook()`. */
400
+ export interface ShowNotebookOptions {
401
+ /** Override daemon socket path (otherwise uses `defaultSocketPath()`). */
402
+ socketPath?: string
403
+ /** Active notebook UUID to open in the app. */
404
+ notebookId?: string
405
+ /** File path to open in the app. If both path and notebookId are provided, path wins. */
406
+ path?: string
407
+ }
408
+
409
+ /** Result of asking nteract Desktop to show a notebook. */
410
+ export interface ShowNotebookResult {
411
+ notebookId?: string
412
+ path?: string
413
+ opened: boolean
414
+ reason?: string
415
+ warning?: string
416
+ }
417
+
418
+ /** Shutdown a notebook's kernel and evict its daemon room by notebook ID. */
419
+ export declare function shutdownNotebook(notebookId: string, options?: ShutdownNotebookOptions | undefined | null): Promise<boolean>
420
+
421
+ /** Options for top-level `shutdownNotebook()`. */
422
+ export interface ShutdownNotebookOptions {
423
+ /** Override daemon socket path (otherwise uses `defaultSocketPath()`). */
424
+ socketPath?: string
425
+ }
426
+
157
427
  /**
158
428
  * Return the daemon socket path for a specific channel ("stable" or
159
429
  * "nightly"). Ignores `RUNTIMED_SOCKET_PATH`.
@@ -163,6 +433,12 @@ export declare function socketPathForChannel(channel: string): string
163
433
  /** Summarize a parquet file from a local blob/file path. */
164
434
  export declare function summarizeParquetFile(filePath: string): ParquetSummaryResult
165
435
 
436
+ /** UV dependency metadata. */
437
+ export interface UvDependencyStatus {
438
+ dependencies: Array<string>
439
+ requiresPython?: string
440
+ }
441
+
166
442
  /** Options for `Session.waitForExecution()`. */
167
443
  export interface WaitExecutionOptions {
168
444
  /** Cell ID to use when reporting kernel failures before terminal state syncs. */
package/src/index.cjs CHANGED
@@ -8,5 +8,20 @@
8
8
  "use strict";
9
9
 
10
10
  const binding = require("./binding.cjs");
11
+ const { Session } = require("./session.cjs");
11
12
 
12
- module.exports = binding;
13
+ async function createNotebook(options) {
14
+ return new Session(await binding.createNotebook(options));
15
+ }
16
+
17
+ async function openNotebook(notebookId, options) {
18
+ return new Session(await binding.openNotebook(notebookId, options));
19
+ }
20
+
21
+ module.exports = {
22
+ ...binding,
23
+ createNotebook,
24
+ openNotebook,
25
+ NativeSession: binding.Session,
26
+ Session,
27
+ };
package/src/index.d.ts CHANGED
@@ -1,7 +1,203 @@
1
- /**
2
- * @runtimed/node — Node.js bindings for the runtimed daemon.
3
- *
4
- * This file re-exports the types generated by napi-rs into binding.d.ts.
5
- */
1
+ import type { Observable } from "rxjs";
2
+ import type { ExecutionTransition, RuntimeState, SessionStatus } from "runtimed";
6
3
 
7
- export * from "./binding.cjs";
4
+ export type RuntimeKind = "python" | "deno" | (string & {});
5
+ export type PackageManager = "uv" | "conda" | "pixi";
6
+
7
+ export const PackageManager: {
8
+ readonly Uv: "uv";
9
+ readonly Conda: "conda";
10
+ readonly Pixi: "pixi";
11
+ };
12
+
13
+ export interface CreateNotebookOptions {
14
+ runtime?: RuntimeKind;
15
+ workingDir?: string;
16
+ socketPath?: string;
17
+ peerLabel?: string;
18
+ description?: string;
19
+ dependencies?: string[];
20
+ packageManager?: PackageManager;
21
+ }
22
+
23
+ export interface OpenNotebookOptions {
24
+ socketPath?: string;
25
+ peerLabel?: string;
26
+ description?: string;
27
+ }
28
+
29
+ export interface RunCellOptions {
30
+ timeoutMs?: number;
31
+ cellType?: "code" | "markdown" | "raw";
32
+ onUpdate?: (progress: CellResult) => void;
33
+ }
34
+
35
+ export interface QueueCellOptions {
36
+ cellType?: "code" | "markdown" | "raw";
37
+ }
38
+
39
+ export interface DependencyEditOptions {
40
+ packageManager?: PackageManager;
41
+ }
42
+
43
+ export interface WaitExecutionOptions {
44
+ cellId?: string;
45
+ timeoutMs?: number;
46
+ onUpdate?: (progress: CellResult) => void;
47
+ }
48
+
49
+ export interface QueuedExecution {
50
+ cellId: string;
51
+ executionId: string;
52
+ }
53
+
54
+ export interface JsOutput {
55
+ outputType: string;
56
+ name?: string;
57
+ text?: string;
58
+ dataJson?: string;
59
+ ename?: string;
60
+ evalue?: string;
61
+ traceback?: string[];
62
+ executionCount?: number;
63
+ blobUrlsJson?: string;
64
+ blobPathsJson?: string;
65
+ }
66
+
67
+ export interface CellResult {
68
+ cellId: string;
69
+ executionId: string;
70
+ executionCount?: number;
71
+ status:
72
+ | "done"
73
+ | "error"
74
+ | "timeout"
75
+ | "kernel_error"
76
+ | "kernel_failed"
77
+ | "closed"
78
+ | "queued"
79
+ | "running"
80
+ | (string & {});
81
+ success: boolean;
82
+ outputs: JsOutput[];
83
+ }
84
+
85
+ export interface EventSubscription {
86
+ dispose(): void;
87
+ }
88
+
89
+ export interface CellSnapshot {
90
+ id: string;
91
+ cellType: string;
92
+ position: string;
93
+ source: string;
94
+ metadataJson: string;
95
+ executionCount?: string;
96
+ }
97
+
98
+ export interface CreateCellOptions {
99
+ cellType?: "code" | "markdown" | "raw";
100
+ afterCellId?: string | null;
101
+ }
102
+
103
+ export interface SetCellOptions {
104
+ source?: string;
105
+ cellType?: "code" | "markdown" | "raw";
106
+ }
107
+
108
+ export interface RuntimeStatus {
109
+ status: string;
110
+ lifecycle: string;
111
+ activity?: string;
112
+ startingPhase: string;
113
+ name: string;
114
+ language: string;
115
+ envSource: string;
116
+ runtimeAgentId: string;
117
+ errorReason?: string;
118
+ errorDetails?: string;
119
+ }
120
+
121
+ export interface DependencyStatus {
122
+ uv?: {
123
+ dependencies: string[];
124
+ requiresPython?: string;
125
+ };
126
+ conda?: {
127
+ dependencies: string[];
128
+ channels: string[];
129
+ python?: string;
130
+ };
131
+ pixi?: {
132
+ dependencies: string[];
133
+ pypiDependencies: string[];
134
+ channels: string[];
135
+ python?: string;
136
+ };
137
+ fingerprint?: string;
138
+ trust?: unknown;
139
+ }
140
+
141
+ export class Session {
142
+ readonly notebookId: string;
143
+ readonly runtimeState$: Observable<RuntimeState>;
144
+ readonly executionTransitions$: Observable<ExecutionTransition>;
145
+ readonly cellChanges$: Observable<null>;
146
+ readonly broadcasts$: Observable<unknown>;
147
+ readonly sessionStatus$: Observable<SessionStatus>;
148
+
149
+ queueCell(source: string, options?: QueueCellOptions): Promise<QueuedExecution>;
150
+ waitForExecution(executionId: string, options?: WaitExecutionOptions): Promise<CellResult>;
151
+ runCell(source: string, options?: RunCellOptions): Promise<CellResult>;
152
+ saveNotebook(path?: string): Promise<void>;
153
+ listCells(): Promise<CellSnapshot[]>;
154
+ getCell(cellId: string): Promise<CellSnapshot | null>;
155
+ createCell(source: string, options?: CreateCellOptions): Promise<string>;
156
+ setCell(cellId: string, options: SetCellOptions): Promise<boolean>;
157
+ deleteCell(cellId: string): Promise<boolean>;
158
+ moveCell(cellId: string, afterCellId?: string | null): Promise<string>;
159
+ executeCell(cellId: string, options?: { timeoutMs?: number }): Promise<CellResult>;
160
+ showNotebook(): Promise<unknown>;
161
+ interruptKernel(): Promise<void>;
162
+ shutdownKernel(): Promise<void>;
163
+ restartKernel(): Promise<void>;
164
+ shutdownNotebook(): Promise<boolean>;
165
+ addDependency(pkg: string, options?: DependencyEditOptions): Promise<void>;
166
+ addDependencies(packages: string[], options?: DependencyEditOptions): Promise<void>;
167
+ removeDependency(pkg: string, options?: DependencyEditOptions): Promise<boolean>;
168
+ removeDependencies(packages: string[], options?: DependencyEditOptions): Promise<number>;
169
+ getDependencyStatus(): Promise<DependencyStatus>;
170
+ getRuntimeStatus(): Promise<RuntimeStatus>;
171
+ dependencyFingerprint(): Promise<string | null>;
172
+ approveTrust(observedHeads?: string[]): Promise<void>;
173
+ syncEnvironment(): Promise<void>;
174
+ close(): Promise<void>;
175
+ }
176
+
177
+ export const NativeSession: unknown;
178
+
179
+ export function defaultSocketPath(): string;
180
+ export function socketPathForChannel(channel: "stable" | "nightly"): string;
181
+ export function createNotebook(options?: CreateNotebookOptions): Promise<Session>;
182
+ export function openNotebook(notebookId: string, options?: OpenNotebookOptions): Promise<Session>;
183
+ export function getExecutionResult(
184
+ executionId: string,
185
+ options?: { socketPath?: string },
186
+ ): Promise<CellResult>;
187
+
188
+ export function readParquetFile(
189
+ filePath: string,
190
+ offset: number,
191
+ limit: number,
192
+ ): {
193
+ columns: string[];
194
+ rows: string[][];
195
+ totalRows: number;
196
+ offset: number;
197
+ };
198
+
199
+ export function summarizeParquetFile(filePath: string): {
200
+ numRows: number;
201
+ numBytes: number;
202
+ columns: Array<{ name: string; dataType: string; nullCount: number; statsJson: string }>;
203
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ function parseJsonEvent(json) {
4
+ return typeof json === "string" ? JSON.parse(json) : json;
5
+ }
6
+
7
+ module.exports = {
8
+ parseJsonEvent,
9
+ };
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ const { Subject } = require("rxjs");
4
+ const { parseJsonEvent } = require("./napi-observables.cjs");
5
+
6
+ class Session {
7
+ constructor(nativeSession) {
8
+ this._native = nativeSession;
9
+ this._subscriptions = [];
10
+ this._runtimeStateSubject = new Subject();
11
+ this._executionTransitionsSubject = new Subject();
12
+ this._cellChangesSubject = new Subject();
13
+ this._broadcastsSubject = new Subject();
14
+ this._sessionStatusSubject = new Subject();
15
+ this.runtimeState$ = this._runtimeStateSubject.asObservable();
16
+ this.executionTransitions$ = this._executionTransitionsSubject.asObservable();
17
+ this.cellChanges$ = this._cellChangesSubject.asObservable();
18
+ this.broadcasts$ = this._broadcastsSubject.asObservable();
19
+ this.sessionStatus$ = this._sessionStatusSubject.asObservable();
20
+
21
+ if (typeof nativeSession.onRuntimeState === "function") {
22
+ this._subscriptions.push(
23
+ nativeSession.onRuntimeState((json) =>
24
+ this._runtimeStateSubject.next(parseJsonEvent(json)),
25
+ ),
26
+ );
27
+ }
28
+ if (typeof nativeSession.onCellChange === "function") {
29
+ this._subscriptions.push(
30
+ nativeSession.onCellChange((json) => this._cellChangesSubject.next(parseJsonEvent(json))),
31
+ );
32
+ }
33
+ if (typeof nativeSession.onBroadcast === "function") {
34
+ this._subscriptions.push(
35
+ nativeSession.onBroadcast((json) => this._broadcastsSubject.next(parseJsonEvent(json))),
36
+ );
37
+ }
38
+ if (typeof nativeSession.onSessionStatus === "function") {
39
+ this._subscriptions.push(
40
+ nativeSession.onSessionStatus((json) =>
41
+ this._sessionStatusSubject.next(parseJsonEvent(json)),
42
+ ),
43
+ );
44
+ }
45
+ if (typeof nativeSession.onExecutionTransition === "function") {
46
+ this._subscriptions.push(
47
+ nativeSession.onExecutionTransition((json) =>
48
+ this._executionTransitionsSubject.next(parseJsonEvent(json)),
49
+ ),
50
+ );
51
+ }
52
+ }
53
+
54
+ get notebookId() {
55
+ return this._native.notebookId;
56
+ }
57
+
58
+ queueCell(source, options) {
59
+ return this._native.queueCell(source, options);
60
+ }
61
+
62
+ async waitForExecution(executionId, options = {}) {
63
+ const { onUpdate, ...nativeOptions } = options ?? {};
64
+ const cellId = nativeOptions.cellId;
65
+ let progressSubscription = null;
66
+ if (typeof onUpdate === "function" && typeof this._native.onExecutionProgress === "function") {
67
+ progressSubscription = this._native.onExecutionProgress(
68
+ executionId,
69
+ cellId ?? null,
70
+ (json) => {
71
+ onUpdate(parseJsonEvent(json));
72
+ },
73
+ );
74
+ }
75
+
76
+ try {
77
+ return await this._native.waitForExecution(executionId, nativeOptions);
78
+ } finally {
79
+ progressSubscription?.dispose?.();
80
+ }
81
+ }
82
+
83
+ async runCell(source, options = {}) {
84
+ if (typeof options?.onUpdate !== "function") {
85
+ return this._native.runCell(source, options);
86
+ }
87
+ const queued = await this.queueCell(source, options);
88
+ return this.waitForExecution(queued.executionId, {
89
+ ...options,
90
+ cellId: queued.cellId,
91
+ });
92
+ }
93
+
94
+ saveNotebook(path) {
95
+ return this._native.saveNotebook(path);
96
+ }
97
+
98
+ listCells() {
99
+ return this._native.listCells();
100
+ }
101
+
102
+ getCell(cellId) {
103
+ return this._native.getCell(cellId);
104
+ }
105
+
106
+ createCell(source, options) {
107
+ return this._native.createCell(source, options);
108
+ }
109
+
110
+ setCell(cellId, options) {
111
+ return this._native.setCell(cellId, options);
112
+ }
113
+
114
+ deleteCell(cellId) {
115
+ return this._native.deleteCell(cellId);
116
+ }
117
+
118
+ moveCell(cellId, afterCellId) {
119
+ return this._native.moveCell(cellId, { afterCellId: afterCellId ?? null });
120
+ }
121
+
122
+ executeCell(cellId, options) {
123
+ return this._native.executeCell(cellId, options);
124
+ }
125
+
126
+ showNotebook() {
127
+ return this._native.showNotebook();
128
+ }
129
+
130
+ interruptKernel() {
131
+ return this._native.interruptKernel();
132
+ }
133
+
134
+ shutdownKernel() {
135
+ return this._native.shutdownKernel();
136
+ }
137
+
138
+ restartKernel() {
139
+ return this._native.restartKernel();
140
+ }
141
+
142
+ shutdownNotebook() {
143
+ return this._native.shutdownNotebook();
144
+ }
145
+
146
+ addDependency(pkg, options) {
147
+ return this._native.addDependency(pkg, normalizeDependencyOptions(options));
148
+ }
149
+
150
+ addDependencies(packages, options) {
151
+ return this._native.addDependencies(
152
+ normalizePackages(packages),
153
+ normalizeDependencyOptions(options),
154
+ );
155
+ }
156
+
157
+ removeDependency(pkg, options) {
158
+ return this._native.removeDependency(pkg, normalizeDependencyOptions(options));
159
+ }
160
+
161
+ removeDependencies(packages, options) {
162
+ return this._native.removeDependencies(
163
+ normalizePackages(packages),
164
+ normalizeDependencyOptions(options),
165
+ );
166
+ }
167
+
168
+ getDependencyStatus() {
169
+ return this._native.getDependencyStatus();
170
+ }
171
+
172
+ getRuntimeStatus() {
173
+ return this._native.getRuntimeStatus();
174
+ }
175
+
176
+ dependencyFingerprint() {
177
+ return this._native.dependencyFingerprint();
178
+ }
179
+
180
+ approveTrust(observedHeads) {
181
+ return this._native.approveTrust(observedHeads);
182
+ }
183
+
184
+ syncEnvironment() {
185
+ return this._native.syncEnvironment();
186
+ }
187
+
188
+ close() {
189
+ for (const subscription of this._subscriptions.splice(0)) {
190
+ subscription?.dispose?.();
191
+ }
192
+ this._runtimeStateSubject.complete();
193
+ this._executionTransitionsSubject.complete();
194
+ this._cellChangesSubject.complete();
195
+ this._broadcastsSubject.complete();
196
+ this._sessionStatusSubject.complete();
197
+ return this._native.close();
198
+ }
199
+ }
200
+
201
+ function normalizePackages(packages) {
202
+ if (!Array.isArray(packages)) {
203
+ throw new TypeError("packages must be an array of dependency specifiers");
204
+ }
205
+ return Array.from(new Set(packages.map((pkg) => String(pkg).trim()).filter(Boolean)));
206
+ }
207
+
208
+ function normalizeDependencyOptions(options) {
209
+ if (!options?.packageManager) {
210
+ return undefined;
211
+ }
212
+ return { packageManager: options.packageManager };
213
+ }
214
+
215
+ module.exports = {
216
+ Session,
217
+ };