@simular-ai/simulang-js 5.5.0 → 6.0.1
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/CLAUDE.md +30 -4
- package/examples/README.md +3 -1
- package/examples/ask.mjs +76 -0
- package/examples/log-window.mjs +12 -8
- package/index.d.ts +75 -63
- package/index.js +53 -52
- package/package.json +13 -11
- package/wrapped.d.ts +25 -0
- package/wrapped.js +139 -0
package/CLAUDE.md
CHANGED
|
@@ -31,6 +31,28 @@ restatement elsewhere.
|
|
|
31
31
|
screen is 3840×2160 in these coordinates. Image and screenshot dimensions
|
|
32
32
|
are likewise in physical pixels.
|
|
33
33
|
|
|
34
|
+
## Logging is on by default
|
|
35
|
+
|
|
36
|
+
`import '@simular-ai/simulang-js'` auto-installs a stderr logger sink — no
|
|
37
|
+
explicit `initLogger()` call required. Records from simulang-rs (clipboard
|
|
38
|
+
reads/writes, keyboard input, app launches, window state changes, …) show
|
|
39
|
+
up on the host process's stderr formatted as `[level] message`. The Rust
|
|
40
|
+
`target` (module path, e.g. `simulang_rs::common::clipboard`) is omitted
|
|
41
|
+
from the default format to keep terminal output readable; install a
|
|
42
|
+
custom callback via `initLogger(cb)` to access it on the record payload.
|
|
43
|
+
|
|
44
|
+
Filter resolution: `RUST_LOG` if set, otherwise `simulang_rs=info,warn` —
|
|
45
|
+
info-level records from simulang's own actions, warn-level from every
|
|
46
|
+
other crate. Override at any time with `initLogger(...)`:
|
|
47
|
+
|
|
48
|
+
- `initLogger(null, 'off')` — silence everything
|
|
49
|
+
- `initLogger(null, 'simulang_rs=debug,warn')` — bump verbosity
|
|
50
|
+
- `initLogger(cb)` — forward records to a JS callback (log window, file
|
|
51
|
+
appender, pino/winston, Electron renderer over IPC, …) instead of stderr
|
|
52
|
+
|
|
53
|
+
`initLogger` atomically swaps both the sink and the filter on every call,
|
|
54
|
+
so it composes cleanly with the auto-install.
|
|
55
|
+
|
|
34
56
|
## Live log viewer (optional)
|
|
35
57
|
|
|
36
58
|
`@simular-ai/simulang-log-viewer` is a **human-facing aid**: a floating,
|
|
@@ -52,7 +74,8 @@ else, also shown inside the window) toggles "grab mode": pressing it once
|
|
|
52
74
|
turns click-through off, pauses execution, and makes the window draggable;
|
|
53
75
|
pressing it again restores click-through and resumes.
|
|
54
76
|
|
|
55
|
-
|
|
77
|
+
Re-route records into the window via `initLogger` (overriding the
|
|
78
|
+
default stderr sink) and respect the pause inside automation loops:
|
|
56
79
|
|
|
57
80
|
```js
|
|
58
81
|
import { initLogger } from '@simular-ai/simulang-js'
|
|
@@ -66,12 +89,15 @@ initLogger((rec) => win.log(`[${rec.level}] [${rec.target}] ${rec.message}`), 'i
|
|
|
66
89
|
await win.waitIfPaused()
|
|
67
90
|
```
|
|
68
91
|
|
|
92
|
+
(The simpler way is to `import '@simular-ai/simulang-log-viewer'` for its
|
|
93
|
+
side effect — the package's auto-install entry point spawns the window,
|
|
94
|
+
registers the pause hook, and calls `initLogger` for you.)
|
|
95
|
+
|
|
69
96
|
The second argument to `initLogger` is a filter spec in the `RUST_LOG`
|
|
70
97
|
environment-variable syntax used by Rust's `env_logger` / `log` crates —
|
|
71
98
|
e.g. `'info'` for a global level, `'simulang_rs=debug,warn'` for per-module
|
|
72
|
-
scoping.
|
|
73
|
-
|
|
74
|
-
`index.d.ts` for the full grammar.
|
|
99
|
+
scoping. See `initLogger`'s JSDoc in `index.d.ts` for the full grammar
|
|
100
|
+
and the auto-install default.
|
|
75
101
|
|
|
76
102
|
Other methods: `clear()` drops displayed messages, `isPaused` getter for a
|
|
77
103
|
non-blocking check, `close()` to shut the viewer (also automatic on parent
|
package/examples/README.md
CHANGED
|
@@ -31,6 +31,7 @@ node screenshot.mjs
|
|
|
31
31
|
| `chrome_google_search_button.mjs` | Opens google.com in Chrome and locates the search button by _concept text_, using BoW Jaccard scoring over `overallDescription`. |
|
|
32
32
|
| `open-app.mjs` | Opens an app, lists its windows, snapshots its accessibility tree. |
|
|
33
33
|
| `loopback.mjs` | Plays an audio file while capturing system audio, then transcribes it. |
|
|
34
|
+
| `ask.mjs` | Drives the `AskModel` LLM primitive through prompt-only, text-only, image-only, and text + multi-image calls, using a real ax-tree snapshot and back-to-back screenshots as context. |
|
|
34
35
|
| `logger.mjs` | Forwards Rust `log` records to a JS callback (env_logger-style filter spec). |
|
|
35
36
|
| `log-window.mjs` | Pipes Rust `log::*!` records into a floating, always-on-top log window. Requires the optional [`@simular-ai/simulang-log-viewer`](../README.md#3-optional--install-the-log-viewer) peer dep. |
|
|
36
37
|
|
|
@@ -40,8 +41,9 @@ Unlike a sandboxed library call, most of these examples perform **real actions**
|
|
|
40
41
|
|
|
41
42
|
- `keyboard.mjs` and `google_search.mjs` synthesize keystrokes — make sure the intended window is focused, or text will land somewhere unexpected.
|
|
42
43
|
- `clipboard.mjs` overwrites your current clipboard contents (it restores them at the end).
|
|
43
|
-
- `screenshot.mjs`, `google_search.mjs`, and `
|
|
44
|
+
- `screenshot.mjs`, `google_search.mjs`, `loopback.mjs`, and `ask.mjs` capture your screen or system audio.
|
|
44
45
|
- `system.mjs` and `google_search.mjs` launch a browser window.
|
|
46
|
+
- `ask.mjs` and `loopback.mjs` send screen captures / audio to a remote LLM provider — make sure the configured provider is one you're OK sharing that content with. Set `OPENROUTER_API_KEY` (or drop a custom provider config under `~/.config/simulang/providers/`) before running `ask.mjs`.
|
|
45
47
|
|
|
46
48
|
### Required OS permissions
|
|
47
49
|
|
package/examples/ask.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Run: node examples/ask.mjs
|
|
2
|
+
//
|
|
3
|
+
// Drive `AskModel` through its four input shapes — prompt-only, text-only,
|
|
4
|
+
// image-only, and text + multiple images — using a real accessibility-tree
|
|
5
|
+
// snapshot of the foreground window as text context and back-to-back
|
|
6
|
+
// screen captures as images.
|
|
7
|
+
//
|
|
8
|
+
// This is the JS analog of `simulang-rs/examples/ask_about_screenshot.rs`.
|
|
9
|
+
//
|
|
10
|
+
// Requirements:
|
|
11
|
+
// - A configured ask provider (the bundled `openrouter` provider needs
|
|
12
|
+
// `OPENROUTER_API_KEY`; see PROVIDERS.md for alternatives)
|
|
13
|
+
// - Screen recording permission (for the screenshots)
|
|
14
|
+
// - Accessibility permission (for the ax-tree snapshot)
|
|
15
|
+
|
|
16
|
+
import { AccessibilityTree, AskModel, Screen, ariaRoleToString, screenshotFull } from '@simular-ai/simulang-js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Render an `AccessibilityNodeJs` subtree as an indented Playwright-style
|
|
20
|
+
* aria snapshot (mirrors `WindowTrait::snapshot()` in simulang-rs).
|
|
21
|
+
*
|
|
22
|
+
* @param {import('@simular-ai/simulang-js').AccessibilityNodeJs} node
|
|
23
|
+
* @param {number} [depth]
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
function snapshotToString(node, depth = 0) {
|
|
27
|
+
const indent = ' '.repeat(depth)
|
|
28
|
+
let line = `${indent}- ${ariaRoleToString(node.role)}`
|
|
29
|
+
if (node.name) line += ` ${JSON.stringify(node.name)}`
|
|
30
|
+
if (node.value) line += `: ${JSON.stringify(node.value)}`
|
|
31
|
+
const childLines = node.children.map((c) => snapshotToString(c, depth + 1))
|
|
32
|
+
return [line, ...childLines].join('\n')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const aliases = AskModel.availableAliases()
|
|
36
|
+
if (aliases.length === 0) {
|
|
37
|
+
console.error(
|
|
38
|
+
'No LLM model is reachable. Set OPENROUTER_API_KEY (or drop a custom provider config under ~/.config/simulang/providers/) and try again.',
|
|
39
|
+
)
|
|
40
|
+
process.exit(1)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const model = AskModel.default()
|
|
44
|
+
console.log(`Using ask model ${JSON.stringify(model.name)}`)
|
|
45
|
+
console.log(`Available aliases: ${aliases.join(', ')}\n`)
|
|
46
|
+
|
|
47
|
+
// 1. Prompt-only — no context at all.
|
|
48
|
+
const pong = model.ask('Reply with just the word PONG.')
|
|
49
|
+
console.log(`[prompt only] -> ${JSON.stringify(pong)}\n`)
|
|
50
|
+
|
|
51
|
+
// 2. Text-only — ground the model on a real accessibility-tree snapshot of
|
|
52
|
+
// whatever window is currently in the foreground.
|
|
53
|
+
const tree = AccessibilityTree.fromForeground()
|
|
54
|
+
const axSnapshot = snapshotToString(tree.snapshot())
|
|
55
|
+
console.log(`Snapshotted foreground window: ${JSON.stringify(tree.windowTitle)}`)
|
|
56
|
+
const summary = model.ask('Summarize this UI in one sentence and list any buttons that look clickable.', axSnapshot)
|
|
57
|
+
console.log(`[text only]\n${summary}\n`)
|
|
58
|
+
|
|
59
|
+
// 3. Image-only — full screenshot of the main display.
|
|
60
|
+
const shotA = screenshotFull(true, Screen.mainScreen())
|
|
61
|
+
shotA.shrink(1024, 1024)
|
|
62
|
+
shotA.compress(80)
|
|
63
|
+
const description = model.ask('Describe what is on screen in one sentence.', null, [shotA])
|
|
64
|
+
console.log(`[image only]\n${description}\n`)
|
|
65
|
+
|
|
66
|
+
// 4. Text + multiple images — capture a second screenshot back-to-back and
|
|
67
|
+
// ask the model to compare them with the ax-tree snapshot for context.
|
|
68
|
+
const shotB = screenshotFull(true, Screen.mainScreen())
|
|
69
|
+
shotB.shrink(1024, 1024)
|
|
70
|
+
shotB.compress(80)
|
|
71
|
+
const diff = model.ask(
|
|
72
|
+
'These two screenshots were taken back-to-back. Did anything change between them? Be specific.',
|
|
73
|
+
axSnapshot,
|
|
74
|
+
[shotA, shotB],
|
|
75
|
+
)
|
|
76
|
+
console.log(`[text + 2 images]\n${diff}`)
|
package/examples/log-window.mjs
CHANGED
|
@@ -26,29 +26,33 @@ win.spawn()
|
|
|
26
26
|
|
|
27
27
|
// `'info'` mirrors `RUST_LOG=info`. Use e.g. `'simulang_rs=debug,warn'` to
|
|
28
28
|
// scope per-module. Omit the second argument to fall back to `RUST_LOG`.
|
|
29
|
+
//
|
|
30
|
+
// `win.log` already mirrors every line to the host's stderr internally,
|
|
31
|
+
// so a single call here gets the record into both the floating viewer
|
|
32
|
+
// and the terminal — no extra `console.log` needed.
|
|
29
33
|
initLogger((rec) => {
|
|
30
|
-
|
|
31
|
-
console.log(line)
|
|
32
|
-
win.log(line)
|
|
34
|
+
win.log(`[${rec.level}] ${rec.message}`)
|
|
33
35
|
}, 'info')
|
|
34
36
|
|
|
35
37
|
// Run a few simulang-js calls so there's actually something to look at.
|
|
36
|
-
|
|
38
|
+
// Each call emits its own `[info]` record via `initLogger` above, so the
|
|
39
|
+
// `win.log` lines below stick to script-level milestones rather than
|
|
40
|
+
// re-narrating every call.
|
|
41
|
+
win.log('clipboard + screenshot demo')
|
|
37
42
|
try {
|
|
38
43
|
const cb = new Clipboard()
|
|
39
44
|
const previous = cb.setString('hello from simulang-js')
|
|
40
|
-
|
|
45
|
+
cb.getString()
|
|
41
46
|
if (previous !== null) cb.setString(previous)
|
|
42
47
|
|
|
43
|
-
win.log('--- starting screenshot demo ---')
|
|
44
48
|
const shot = screenshotFull(true, Screen.mainScreen())
|
|
45
49
|
shot.shrink(640, 480)
|
|
46
|
-
win.log(`captured ${shot.base64().length} bytes
|
|
50
|
+
win.log(`screenshot captured: ${shot.base64().length} bytes base64`)
|
|
47
51
|
} catch (err) {
|
|
48
52
|
win.log(`demo failed: ${err instanceof Error ? err.message : String(err)}`)
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
win.log('
|
|
55
|
+
win.log('holding window open for 30s, press the grab hotkey to pause')
|
|
52
56
|
await new Promise((resolve) => setTimeout(resolve, 30_000))
|
|
53
57
|
// In real automation, scatter `await win.waitIfPaused()` between actions
|
|
54
58
|
// so the script yields whenever the user has grabbed the window.
|
package/index.d.ts
CHANGED
|
@@ -87,13 +87,7 @@ export declare class AccessibilityNode {
|
|
|
87
87
|
* against each node's `overallDescription`
|
|
88
88
|
* - `threshold` – minimum score to keep a node
|
|
89
89
|
*/
|
|
90
|
-
scoredSearch(
|
|
91
|
-
order: TraversalOrder,
|
|
92
|
-
maxNodes: number,
|
|
93
|
-
collapseStructural: boolean,
|
|
94
|
-
query: string,
|
|
95
|
-
threshold: number,
|
|
96
|
-
): Array<AccessibilityNode>
|
|
90
|
+
scoredSearch(order: TraversalOrder, maxNodes: number, collapseStructural: boolean, query: string, threshold: number): Array<AccessibilityNode>
|
|
97
91
|
/** Invoke / click the element (button, link, menu item). */
|
|
98
92
|
activate(): void
|
|
99
93
|
/** Set the text value of the element (textbox, combobox, …). */
|
|
@@ -189,14 +183,7 @@ export declare class AccessibilityTree {
|
|
|
189
183
|
* Clears existing refs; returned nodes carry `refId` values usable
|
|
190
184
|
* with action methods (`activate`, `setValue`, …).
|
|
191
185
|
*/
|
|
192
|
-
find(
|
|
193
|
-
order: TraversalOrder,
|
|
194
|
-
role?: AriaRole | undefined | null,
|
|
195
|
-
name?: string | undefined | null,
|
|
196
|
-
visibleOnly?: boolean | undefined | null,
|
|
197
|
-
maxResults?: number | undefined | null,
|
|
198
|
-
collapseStructural?: boolean | undefined | null,
|
|
199
|
-
): Array<AccessibilityNodeJs>
|
|
186
|
+
find(order: TraversalOrder, role?: AriaRole | undefined | null, name?: string | undefined | null, visibleOnly?: boolean | undefined | null, maxResults?: number | undefined | null, collapseStructural?: boolean | undefined | null): Array<AccessibilityNodeJs>
|
|
200
187
|
}
|
|
201
188
|
|
|
202
189
|
/** Represents an application that can be opened. */
|
|
@@ -227,12 +214,54 @@ export declare class App {
|
|
|
227
214
|
* When `wait_for_load_complete` is true, this blocks for a short, fixed
|
|
228
215
|
* delay to allow the app or URL to become responsive before returning.
|
|
229
216
|
*/
|
|
230
|
-
open(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
217
|
+
open(url: string | undefined | null, focusPolicy: FocusPolicy, visibility: Visibility, waitForLoadComplete: boolean): Instance
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* A free-form chat-completions LLM (optionally vision-capable) — the JS
|
|
222
|
+
* analogue of the `ask` primitive.
|
|
223
|
+
*
|
|
224
|
+
* Given a `prompt`, optional accessibility/structural `text`, and zero or
|
|
225
|
+
* more `images`, [`AskModel.ask`] returns the model's response as a plain
|
|
226
|
+
* string. The wire format is OpenAI-compatible chat completions, so any
|
|
227
|
+
* provider config that points at such an endpoint works.
|
|
228
|
+
*/
|
|
229
|
+
export declare class AskModel {
|
|
230
|
+
/**
|
|
231
|
+
* First LLM model advertised by the first LLM-capable provider in the
|
|
232
|
+
* loaded configuration whose credentials are currently available.
|
|
233
|
+
* Throws if no provider in the loaded config advertises an LLM service.
|
|
234
|
+
*/
|
|
235
|
+
static default(): AskModel
|
|
236
|
+
/**
|
|
237
|
+
* Resolve a model alias against the loaded config (e.g.
|
|
238
|
+
* `"openrouter_gpt_4o_mini"` from the bundled `openrouter` provider, or
|
|
239
|
+
* any alias declared by a user provider). Throws if the alias is unknown.
|
|
240
|
+
*/
|
|
241
|
+
static byAlias(alias: string): AskModel
|
|
242
|
+
/**
|
|
243
|
+
* Every LLM model alias accepted by `byAlias` on this machine,
|
|
244
|
+
* deduplicated and sorted alphabetically. Use to discover what aliases
|
|
245
|
+
* the loaded config (bundled defaults plus any user provider files)
|
|
246
|
+
* advertises.
|
|
247
|
+
*/
|
|
248
|
+
static availableAliases(): Array<string>
|
|
249
|
+
/** The wire-level model identifier sent in the request body. */
|
|
250
|
+
get name(): string
|
|
251
|
+
/**
|
|
252
|
+
* Ask the model a question, optionally grounded in accessibility text
|
|
253
|
+
* and/or images.
|
|
254
|
+
*
|
|
255
|
+
* - `prompt`: the question or task to answer.
|
|
256
|
+
* - `text`: optional accessibility-tree (or any) text included as
|
|
257
|
+
* structural context. Pass `null` / omit to skip.
|
|
258
|
+
* - `images`: zero or more images to attach. Each is encoded as a
|
|
259
|
+
* base64 data URL and sent as an `image_url` chat content part. Pass
|
|
260
|
+
* `null` / omit for none.
|
|
261
|
+
*
|
|
262
|
+
* Returns the trimmed assistant response on success.
|
|
263
|
+
*/
|
|
264
|
+
ask(prompt: string, text?: string | undefined | null, images?: Array<Image> | undefined | null): string
|
|
236
265
|
}
|
|
237
266
|
|
|
238
267
|
/**
|
|
@@ -559,13 +588,7 @@ export declare class Instance {
|
|
|
559
588
|
* methods (`activate`, `setValue`, …) directly on them, walk children
|
|
560
589
|
* with `.children()`, or render a snapshot with `.snapshot()`.
|
|
561
590
|
*/
|
|
562
|
-
scoredSearch(
|
|
563
|
-
order: TraversalOrder,
|
|
564
|
-
maxNodes: number,
|
|
565
|
-
collapseStructural: boolean,
|
|
566
|
-
query: string,
|
|
567
|
-
threshold: number,
|
|
568
|
-
): Array<AccessibilityNode>
|
|
591
|
+
scoredSearch(order: TraversalOrder, maxNodes: number, collapseStructural: boolean, query: string, threshold: number): Array<AccessibilityNode>
|
|
569
592
|
}
|
|
570
593
|
|
|
571
594
|
/**
|
|
@@ -1042,13 +1065,7 @@ export declare class Window {
|
|
|
1042
1065
|
* methods (`activate`, `setValue`, …) directly on them, walk children
|
|
1043
1066
|
* with `.children()`, or render a snapshot with `.snapshot()`.
|
|
1044
1067
|
*/
|
|
1045
|
-
scoredSearch(
|
|
1046
|
-
order: TraversalOrder,
|
|
1047
|
-
maxNodes: number,
|
|
1048
|
-
collapseStructural: boolean,
|
|
1049
|
-
query: string,
|
|
1050
|
-
threshold: number,
|
|
1051
|
-
): Array<AccessibilityNode>
|
|
1068
|
+
scoredSearch(order: TraversalOrder, maxNodes: number, collapseStructural: boolean, query: string, threshold: number): Array<AccessibilityNode>
|
|
1052
1069
|
}
|
|
1053
1070
|
|
|
1054
1071
|
export interface AccessibilityNodeJs {
|
|
@@ -1161,7 +1178,7 @@ export declare enum AriaRole {
|
|
|
1161
1178
|
TreeItem = 84,
|
|
1162
1179
|
Treegrid = 85,
|
|
1163
1180
|
Video = 86,
|
|
1164
|
-
Window = 87
|
|
1181
|
+
Window = 87
|
|
1165
1182
|
}
|
|
1166
1183
|
|
|
1167
1184
|
/**
|
|
@@ -1195,20 +1212,20 @@ export declare enum Button {
|
|
|
1195
1212
|
ScrollUp = 5,
|
|
1196
1213
|
ScrollDown = 6,
|
|
1197
1214
|
ScrollLeft = 7,
|
|
1198
|
-
ScrollRight = 8
|
|
1215
|
+
ScrollRight = 8
|
|
1199
1216
|
}
|
|
1200
1217
|
|
|
1201
1218
|
/** Specifies if coordinates are relative or absolute. */
|
|
1202
1219
|
export declare enum Coordinate {
|
|
1203
1220
|
Abs = 0,
|
|
1204
|
-
Rel = 1
|
|
1221
|
+
Rel = 1
|
|
1205
1222
|
}
|
|
1206
1223
|
|
|
1207
1224
|
/** The direction of a button event. */
|
|
1208
1225
|
export declare enum Direction {
|
|
1209
1226
|
Press = 0,
|
|
1210
1227
|
Release = 1,
|
|
1211
|
-
Click = 2
|
|
1228
|
+
Click = 2
|
|
1212
1229
|
}
|
|
1213
1230
|
|
|
1214
1231
|
/** Enables the accessibility tree for the frontmost application. */
|
|
@@ -1222,7 +1239,7 @@ export declare enum FocusPolicy {
|
|
|
1222
1239
|
*/
|
|
1223
1240
|
DoNotSteal = 0,
|
|
1224
1241
|
/** Allow the launched app to become active/frontmost. */
|
|
1225
|
-
Steal = 1
|
|
1242
|
+
Steal = 1
|
|
1226
1243
|
}
|
|
1227
1244
|
|
|
1228
1245
|
export declare function hasScreenCapturePermission(): boolean
|
|
@@ -1230,16 +1247,25 @@ export declare function hasScreenCapturePermission(): boolean
|
|
|
1230
1247
|
/**
|
|
1231
1248
|
* Initialize the logger.
|
|
1232
1249
|
*
|
|
1250
|
+
* **You usually don't need to call this.** The package's `main` entry
|
|
1251
|
+
* (`wrapped.js`) calls `initLogger()` with no arguments on first
|
|
1252
|
+
* evaluation, so simply `import '@simular-ai/simulang-js'` is enough to
|
|
1253
|
+
* see `[level] message` records on stderr. Call this directly
|
|
1254
|
+
* only when you want to *override* that default — to forward records to
|
|
1255
|
+
* a JS callback, change the filter spec, or silence everything.
|
|
1256
|
+
*
|
|
1233
1257
|
* - **No callback** (`initLogger()` or `initLogger(null, spec)`): records
|
|
1234
|
-
* are formatted as `[level]
|
|
1258
|
+
* are formatted as `[level] message` and written to stderr.
|
|
1235
1259
|
* - **With a callback** (`initLogger(cb, spec)`): records are forwarded to
|
|
1236
1260
|
* the JS callback via a non-blocking, unref'd threadsafe function. Use
|
|
1237
1261
|
* this for GUI panels, file appenders, or routing through a logging
|
|
1238
1262
|
* library like pino. The unref'd dispatch means the logger does not keep
|
|
1239
1263
|
* the Node event loop alive on its own.
|
|
1240
1264
|
*
|
|
1241
|
-
* Omit `spec` to read `RUST_LOG` (
|
|
1242
|
-
*
|
|
1265
|
+
* Omit `spec` to read `RUST_LOG` (falls back to `"simulang_rs=info,warn"`
|
|
1266
|
+
* when `RUST_LOG` is unset — info-level records from simulang's own
|
|
1267
|
+
* actions, warn-level from every other crate). Pass an explicit `spec`
|
|
1268
|
+
* to override `RUST_LOG`. Syntax is identical to `RUST_LOG`:
|
|
1243
1269
|
*
|
|
1244
1270
|
* - `"info"` — global level
|
|
1245
1271
|
* - `"simulang_rs=debug,warn"` — per-module override + default
|
|
@@ -1257,10 +1283,7 @@ export declare function hasScreenCapturePermission(): boolean
|
|
|
1257
1283
|
* on forever. The callback itself runs on the Node main thread; the
|
|
1258
1284
|
* non-blocking dispatch from Rust is what creates the recursion risk.
|
|
1259
1285
|
*/
|
|
1260
|
-
export declare function initLogger(
|
|
1261
|
-
cb?: ((arg: JsLogRecord) => unknown) | undefined | null,
|
|
1262
|
-
spec?: string | undefined | null,
|
|
1263
|
-
): void
|
|
1286
|
+
export declare function initLogger(cb?: (((arg: JsLogRecord) => unknown)) | undefined | null, spec?: string | undefined | null): void
|
|
1264
1287
|
|
|
1265
1288
|
/** A single log entry forwarded to the JS callback. */
|
|
1266
1289
|
export interface JsLogRecord {
|
|
@@ -1628,19 +1651,14 @@ export declare enum Key {
|
|
|
1628
1651
|
/** Use `key_unicode` to provide the character. */
|
|
1629
1652
|
Unicode = 290,
|
|
1630
1653
|
/** Use `key_other` to provide the raw key value. */
|
|
1631
|
-
Other = 291
|
|
1654
|
+
Other = 291
|
|
1632
1655
|
}
|
|
1633
1656
|
|
|
1634
1657
|
/** Convert a string representation into a `Key`. */
|
|
1635
1658
|
export declare function keyFromString(value: string): Key
|
|
1636
1659
|
|
|
1637
1660
|
/** Legacy helper used by Electron to open an app or URL. */
|
|
1638
|
-
export declare function legacyOpen(
|
|
1639
|
-
app: string | undefined | null,
|
|
1640
|
-
url: string | undefined | null,
|
|
1641
|
-
focusPolicy: FocusPolicy,
|
|
1642
|
-
visibility: Visibility,
|
|
1643
|
-
): void
|
|
1661
|
+
export declare function legacyOpen(app: string | undefined | null, url: string | undefined | null, focusPolicy: FocusPolicy, visibility: Visibility): void
|
|
1644
1662
|
|
|
1645
1663
|
/** Legacy helper used by Electron to capture a screenshot as base64. */
|
|
1646
1664
|
export declare function legacyTakeScreenshot(needsCompression: boolean, shrinkTo1080P: boolean): string
|
|
@@ -1654,13 +1672,7 @@ export declare function legacyTakeScreenshot(needsCompression: boolean, shrinkTo
|
|
|
1654
1672
|
export declare function readFile(path: string): string
|
|
1655
1673
|
|
|
1656
1674
|
/** Takes the screenshot of a cropped region of the workspace. */
|
|
1657
|
-
export declare function screenshotCropped(
|
|
1658
|
-
x: number,
|
|
1659
|
-
y: number,
|
|
1660
|
-
width: number,
|
|
1661
|
-
height: number,
|
|
1662
|
-
hideCursor: boolean,
|
|
1663
|
-
): Screenshot
|
|
1675
|
+
export declare function screenshotCropped(x: number, y: number, width: number, height: number, hideCursor: boolean): Screenshot
|
|
1664
1676
|
|
|
1665
1677
|
/** Takes the screenshot of the entire selected screen */
|
|
1666
1678
|
export declare function screenshotFull(hideCursor: boolean, screen: Screen): Screenshot
|
|
@@ -1670,7 +1682,7 @@ export declare enum TraversalOrder {
|
|
|
1670
1682
|
/** Pre-order depth-first (each node before its descendants). */
|
|
1671
1683
|
DepthFirst = 0,
|
|
1672
1684
|
/** Level-order breadth-first (parents before children). */
|
|
1673
|
-
BreadthFirst = 1
|
|
1685
|
+
BreadthFirst = 1
|
|
1674
1686
|
}
|
|
1675
1687
|
|
|
1676
1688
|
/** Visibility behavior when opening an application. */
|
|
@@ -1678,7 +1690,7 @@ export declare enum Visibility {
|
|
|
1678
1690
|
/** Launch hidden when supported by the platform. */
|
|
1679
1691
|
Hidden = 0,
|
|
1680
1692
|
/** Launch in a visible state. */
|
|
1681
|
-
Show = 1
|
|
1693
|
+
Show = 1
|
|
1682
1694
|
}
|
|
1683
1695
|
|
|
1684
1696
|
/**
|
package/index.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('@simular-ai/simulang-js-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('@simular-ai/simulang-js-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
80
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('@simular-ai/simulang-js-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
96
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('@simular-ai/simulang-js-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
117
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('@simular-ai/simulang-js-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
133
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('@simular-ai/simulang-js-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
150
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('@simular-ai/simulang-js-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
166
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('@simular-ai/simulang-js-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
185
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('@simular-ai/simulang-js-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
201
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('@simular-ai/simulang-js-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
217
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('@simular-ai/simulang-js-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
237
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('@simular-ai/simulang-js-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
253
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
274
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
290
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
308
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
324
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
342
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
358
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
376
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
392
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
410
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
426
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
443
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('@simular-ai/simulang-js-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
459
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('@simular-ai/simulang-js-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
479
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('@simular-ai/simulang-js-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
495
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 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('@simular-ai/simulang-js-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('@simular-ai/simulang-js-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
511
|
+
if (bindingPackageVersion !== '6.0.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 6.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
|
@@ -579,6 +579,7 @@ module.exports = nativeBinding
|
|
|
579
579
|
module.exports.AccessibilityNode = nativeBinding.AccessibilityNode
|
|
580
580
|
module.exports.AccessibilityTree = nativeBinding.AccessibilityTree
|
|
581
581
|
module.exports.App = nativeBinding.App
|
|
582
|
+
module.exports.AskModel = nativeBinding.AskModel
|
|
582
583
|
module.exports.AudioOutput = nativeBinding.AudioOutput
|
|
583
584
|
module.exports.Clipboard = nativeBinding.Clipboard
|
|
584
585
|
module.exports.Directory = nativeBinding.Directory
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simular-ai/simulang-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Node.js bindings for simulang-rs",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "./
|
|
5
|
+
"main": "wrapped.js",
|
|
6
|
+
"types": "./wrapped.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"types": "./
|
|
10
|
-
"default": "./
|
|
9
|
+
"types": "./wrapped.d.ts",
|
|
10
|
+
"default": "./wrapped.js"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"files": [
|
|
35
35
|
"index.d.ts",
|
|
36
36
|
"index.js",
|
|
37
|
+
"wrapped.d.ts",
|
|
38
|
+
"wrapped.js",
|
|
37
39
|
"CLAUDE.md",
|
|
38
40
|
"bin/init-claude.mjs",
|
|
39
41
|
"bin/postinstall-hint.mjs",
|
|
@@ -114,11 +116,11 @@
|
|
|
114
116
|
"arrowParens": "always"
|
|
115
117
|
},
|
|
116
118
|
"optionalDependencies": {
|
|
117
|
-
"@simular-ai/simulang-js-win32-x64-msvc": "
|
|
118
|
-
"@simular-ai/simulang-js-win32-arm64-msvc": "
|
|
119
|
-
"@simular-ai/simulang-js-darwin-x64": "
|
|
120
|
-
"@simular-ai/simulang-js-darwin-arm64": "
|
|
121
|
-
"@simular-ai/simulang-js-linux-x64-gnu": "
|
|
122
|
-
"@simular-ai/simulang-js-linux-arm64-gnu": "
|
|
119
|
+
"@simular-ai/simulang-js-win32-x64-msvc": "6.0.1",
|
|
120
|
+
"@simular-ai/simulang-js-win32-arm64-msvc": "6.0.1",
|
|
121
|
+
"@simular-ai/simulang-js-darwin-x64": "6.0.1",
|
|
122
|
+
"@simular-ai/simulang-js-darwin-arm64": "6.0.1",
|
|
123
|
+
"@simular-ai/simulang-js-linux-x64-gnu": "6.0.1",
|
|
124
|
+
"@simular-ai/simulang-js-linux-arm64-gnu": "6.0.1"
|
|
123
125
|
}
|
|
124
126
|
}
|
package/wrapped.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-authored entry that re-exports the napi-generated bindings from
|
|
3
|
+
* `index.d.ts` and adds the `setPauseHook` API used by
|
|
4
|
+
* `@simular-ai/simulang-log-viewer` to weave pause-handshake behavior
|
|
5
|
+
* through every simulang-js call.
|
|
6
|
+
*
|
|
7
|
+
* The package's `types` field points here. `index.d.ts` stays as the
|
|
8
|
+
* napi-rs codegen output (and the source of truth for the public API
|
|
9
|
+
* surface that auto-docs and Claude skills consume).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export * from './index'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Register a function to be called synchronously before every
|
|
16
|
+
* simulang-js method or free function executes. Used by
|
|
17
|
+
* `@simular-ai/simulang-log-viewer` to make the log window's
|
|
18
|
+
* pause/grab-hotkey state transparently affect every simulang-js call.
|
|
19
|
+
* Pass `null` to clear.
|
|
20
|
+
*
|
|
21
|
+
* The hook runs on the calling thread, before delegating to the
|
|
22
|
+
* native binding. It must not call back into simulang-js — that would
|
|
23
|
+
* recurse.
|
|
24
|
+
*/
|
|
25
|
+
export declare function setPauseHook(fn: (() => void) | null): void
|
package/wrapped.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Re-export the napi bindings, but with a global pause hook woven into
|
|
2
|
+
// every callable. Set the hook via `setPauseHook(fn)`; clear with `null`.
|
|
3
|
+
// While set, the hook runs synchronously before every method or
|
|
4
|
+
// free-function call delegates to the native binding — that lets
|
|
5
|
+
// `@simular-ai/simulang-log-viewer` make its grab/pause state apply to
|
|
6
|
+
// every simulang-js call transparently, without forcing user code to
|
|
7
|
+
// switch import paths or add awaits.
|
|
8
|
+
//
|
|
9
|
+
// The package's `main` points here, so `import '@simular-ai/simulang-js'`
|
|
10
|
+
// resolves to this wrapper. The napi-rs codegen still owns `index.js`
|
|
11
|
+
// and `index.d.ts` verbatim — auto-doc and Claude-skill tooling that
|
|
12
|
+
// reads those files keeps working unchanged.
|
|
13
|
+
//
|
|
14
|
+
// Wrapping happens once at module load against `index.js`'s own
|
|
15
|
+
// exports, so any new function or class added to the napi crate is
|
|
16
|
+
// picked up automatically as long as `napi build` emits it through
|
|
17
|
+
// the generated `index.js`.
|
|
18
|
+
|
|
19
|
+
module.exports = require('./index.js')
|
|
20
|
+
const binding = module.exports
|
|
21
|
+
|
|
22
|
+
let pauseHook = null
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Register a function to call synchronously before every simulang-js
|
|
26
|
+
* method or free function executes. Pass `null` to clear. The hook
|
|
27
|
+
* must not call back into simulang-js — that would recurse.
|
|
28
|
+
*/
|
|
29
|
+
function setPauseHook(fn) {
|
|
30
|
+
pauseHook = typeof fn === 'function' ? fn : null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function wrap(orig) {
|
|
34
|
+
return function pauseAware(...args) {
|
|
35
|
+
if (pauseHook) pauseHook()
|
|
36
|
+
return orig.apply(this, args)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Patch instance methods in place on the prototype. napi-rs emits these
|
|
41
|
+
// as writable+configurable properties, so direct assignment works and
|
|
42
|
+
// every existing or future instance — wherever the class is imported
|
|
43
|
+
// from — sees the wrapped method through prototype lookup.
|
|
44
|
+
function patchPrototype(klass) {
|
|
45
|
+
for (const name of Object.getOwnPropertyNames(klass.prototype)) {
|
|
46
|
+
if (name === 'constructor') continue
|
|
47
|
+
const desc = Object.getOwnPropertyDescriptor(klass.prototype, name)
|
|
48
|
+
// Skip accessor properties (getters/setters): reading a property
|
|
49
|
+
// shouldn't trigger pause-wait. Only wrap method-valued slots.
|
|
50
|
+
if (typeof desc?.value !== 'function') continue
|
|
51
|
+
klass.prototype[name] = wrap(desc.value)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const RESERVED_STATIC_KEYS = new Set(['length', 'name', 'prototype'])
|
|
56
|
+
|
|
57
|
+
// Static methods on napi-rs classes are non-writable AND non-configurable,
|
|
58
|
+
// so direct assignment fails and Proxy invariants forbid returning a
|
|
59
|
+
// different value through `get`. We work around it by exporting a thin
|
|
60
|
+
// subclass that redefines the statics as writable properties; the
|
|
61
|
+
// subclass's own prototype chain delegates everything else to the
|
|
62
|
+
// original class.
|
|
63
|
+
//
|
|
64
|
+
// `[Symbol.hasInstance]` is overridden so that instances returned by
|
|
65
|
+
// the underlying napi factories (which carry the original prototype, not
|
|
66
|
+
// the subclass's) still satisfy `inst instanceof WrappedKlass`.
|
|
67
|
+
function wrapStatics(klass) {
|
|
68
|
+
const statics = []
|
|
69
|
+
for (const name of Object.getOwnPropertyNames(klass)) {
|
|
70
|
+
if (RESERVED_STATIC_KEYS.has(name)) continue
|
|
71
|
+
const desc = Object.getOwnPropertyDescriptor(klass, name)
|
|
72
|
+
if (typeof desc?.value !== 'function') continue
|
|
73
|
+
statics.push([name, wrap(desc.value)])
|
|
74
|
+
}
|
|
75
|
+
if (statics.length === 0) return klass
|
|
76
|
+
|
|
77
|
+
class Wrapped extends klass {
|
|
78
|
+
static [Symbol.hasInstance](inst) {
|
|
79
|
+
return inst instanceof klass
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Plain assignment (`Wrapped[name] = wrapped`) walks the prototype
|
|
83
|
+
// chain and silently fails when it finds the inherited non-writable
|
|
84
|
+
// static. defineProperty bypasses the chain and installs an own,
|
|
85
|
+
// shadowing slot.
|
|
86
|
+
for (const [name, wrapped] of statics) {
|
|
87
|
+
Object.defineProperty(Wrapped, name, {
|
|
88
|
+
value: wrapped,
|
|
89
|
+
writable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
enumerable: false,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
// Preserve `name` for stack traces / `toString()` output.
|
|
95
|
+
Object.defineProperty(Wrapped, 'name', { value: klass.name, configurable: true })
|
|
96
|
+
return Wrapped
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// napi-rs classes carry either instance methods on the prototype (beyond
|
|
100
|
+
// `constructor`) or static methods on the class itself, or both. Plain
|
|
101
|
+
// free function exports have neither. Enums are plain objects.
|
|
102
|
+
//
|
|
103
|
+
// The static-method check has to look for function-VALUED own properties
|
|
104
|
+
// specifically, not just any own property beyond the reserved set: Node
|
|
105
|
+
// 24's `napi_create_function` installs legacy `arguments` and `caller`
|
|
106
|
+
// slots on every napi-emitted function object (Node 25+ does not), and
|
|
107
|
+
// without the function-value filter those would make every free function
|
|
108
|
+
// (`keyFromString`, `ariaRoleToString`, …) misclassify as a class and
|
|
109
|
+
// silently bypass the `wrap(fn)` branch — pause hooks never firing for
|
|
110
|
+
// free-function calls is exactly what that bug looked like.
|
|
111
|
+
function isClass(value) {
|
|
112
|
+
if (typeof value !== 'function' || !value.prototype) return false
|
|
113
|
+
if (Object.getOwnPropertyNames(value.prototype).length > 1) return true
|
|
114
|
+
for (const name of Object.getOwnPropertyNames(value)) {
|
|
115
|
+
if (RESERVED_STATIC_KEYS.has(name)) continue
|
|
116
|
+
const desc = Object.getOwnPropertyDescriptor(value, name)
|
|
117
|
+
if (typeof desc?.value === 'function') return true
|
|
118
|
+
}
|
|
119
|
+
return false
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for (const key of Object.keys(binding)) {
|
|
123
|
+
const value = binding[key]
|
|
124
|
+
if (isClass(value)) {
|
|
125
|
+
patchPrototype(value)
|
|
126
|
+
module.exports[key] = wrapStatics(value)
|
|
127
|
+
} else if (typeof value === 'function') {
|
|
128
|
+
module.exports[key] = wrap(value)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
module.exports.setPauseHook = setPauseHook
|
|
132
|
+
|
|
133
|
+
// Auto-install the stderr logger sink so simulang-rs `log::*!` records
|
|
134
|
+
// (clipboard reads/writes, keyboard input, app launches, window state,
|
|
135
|
+
// etc.) are visible in the terminal as soon as `import
|
|
136
|
+
// '@simular-ai/simulang-js'` evaluates — no explicit `initLogger()` call
|
|
137
|
+
// required. Without this, the `log` crate has no logger registered at
|
|
138
|
+
// all, so every `log::*!` is a silent no-op regardless of `RUST_LOG`.
|
|
139
|
+
binding.initLogger()
|