@native-sdk/cli 0.7.1 → 0.8.0
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/build/app.zig +273 -65
- package/build/ts_run.mjs +6 -8
- package/build.zig +341 -361
- package/native-sdk.d.ts +6 -3
- package/package.json +13 -11
- package/packages/core/compile-surface/core.ts +559 -0
- package/packages/core/package-lock.json +375 -12
- package/packages/core/package.json +9 -6
- package/packages/core/scripts/compiler_typecheck.mjs +58 -0
- package/packages/core/scripts/gen_case_tables.mjs +130 -0
- package/packages/core/scripts/gen_declarations.mjs +97 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +108 -0
- package/packages/core/scripts/stage_external_core.mjs +148 -0
- package/packages/core/sdk/core.d.ts +363 -0
- package/packages/core/sdk/events.d.ts +65 -0
- package/packages/core/sdk/text.d.ts +51 -0
- package/packages/core/src/checker.ts +3 -3
- package/packages/core/src/cli.ts +40 -38
- package/packages/core/src/contract.ts +749 -0
- package/packages/core/src/devhost.ts +4 -3
- package/packages/core/src/diagnostics.ts +5 -7
- package/packages/core/src/{transpile.ts → frontend.ts} +38 -50
- package/packages/core/src/infer.ts +1 -1
- package/packages/core/src/typed_ast.ts +16 -15
- package/packages/core/src/wyhash.ts +79 -0
- package/skill-data/native-ui/SKILL.md +4 -2
- package/skill-data/ts-core/SKILL.md +29 -29
- package/src/platform/macos/appkit_host.m +51 -3
- package/src/platform/types.zig +4 -0
- package/src/platform/windows/gpu_surface_renderer.cpp +2280 -0
- package/src/platform/windows/gpu_surface_renderer.h +86 -0
- package/src/platform/windows/root.zig +298 -20
- package/src/platform/windows/webview2_host.cpp +343 -33
- package/src/primitives/canvas/code.zig +50 -0
- package/src/primitives/canvas/code_tests.zig +174 -1
- package/src/primitives/canvas/frame.zig +45 -1
- package/src/primitives/canvas/gpu.zig +6 -0
- package/src/primitives/canvas/render_tests.zig +93 -0
- package/src/primitives/canvas/root.zig +2 -0
- package/src/primitives/canvas/serialization.zig +150 -21
- package/src/primitives/canvas/themes/geist.zig +51 -5
- package/src/primitives/canvas/tokens.zig +33 -4
- package/src/primitives/canvas/ui.zig +52 -7
- package/src/primitives/canvas/ui_markup.zig +38 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +28 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_view.zig +28 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +10 -2
- package/src/primitives/canvas/ui_schema.zig +5 -0
- package/src/primitives/canvas/ui_schema_tests.zig +4 -3
- package/src/primitives/canvas/ui_tests.zig +14 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +513 -13
- package/src/primitives/canvas/widget_invalidation.zig +11 -1
- package/src/primitives/canvas/widget_layout.zig +260 -21
- package/src/primitives/canvas/widget_metrics.zig +45 -9
- package/src/primitives/canvas/widget_render.zig +220 -70
- package/src/primitives/canvas/widget_render_controls.zig +79 -21
- package/src/primitives/canvas/widget_render_style.zig +52 -8
- package/src/primitives/canvas/widget_text_input.zig +2 -0
- package/src/primitives/canvas/widgets.zig +53 -2
- package/src/runtime/canvas_frame.zig +60 -7
- package/src/runtime/canvas_frame_invalidation_tests.zig +80 -0
- package/src/runtime/canvas_frame_packet_tests.zig +83 -9
- package/src/runtime/canvas_frame_patch_tests.zig +16 -0
- package/src/runtime/canvas_images.zig +8 -2
- package/src/runtime/canvas_widget_clipboard_tests.zig +1 -1
- package/src/runtime/canvas_widget_runtime.zig +11 -8
- package/src/runtime/effects.zig +6 -0
- package/src/runtime/effects_tests.zig +30 -0
- package/src/runtime/gpu_surface_events.zig +38 -7
- package/src/runtime/media_surface_tests.zig +1 -1
- package/src/runtime/runtime_event_tests.zig +74 -0
- package/src/runtime/ts_core_host.zig +38 -38
- package/src/runtime/ts_ui_app.zig +12 -12
- package/src/runtime/ui_app.zig +10 -8
- package/src/runtime/ui_app_tests.zig +67 -0
- package/src/runtime/view.zig +6 -0
- package/src/runtime/view_canvas.zig +15 -0
- package/src/runtime/view_widget_text.zig +6 -4
- package/src/runtime/window_view_runtime.zig +1 -0
- package/src/tooling/manifest.zig +32 -0
- package/src/tooling/raw_manifest.zig +4 -0
- package/src/tooling/templates.zig +34 -26
- package/src/tooling/ts_core.zig +55 -34
- package/src/tooling/verbs.zig +1 -1
- package/tools/corewire/core_abi.zig +169 -0
- package/tools/corewire/emit.zig +2418 -0
- package/tools/corewire/emit_facade.zig +3984 -0
- package/tools/corewire/emit_profile.zig +501 -0
- package/tools/corewire/main.zig +561 -0
- package/tools/corewire/shim_rt.zig +632 -0
- package/tools/corewire/sidecar.zig +2507 -0
- package/packages/core/rt/rt.zig +0 -1986
- package/packages/core/src/emitter.ts +0 -11898
package/native-sdk.d.ts
CHANGED
|
@@ -178,7 +178,10 @@ export type NativeSdkViewKind =
|
|
|
178
178
|
| "progress_indicator"
|
|
179
179
|
| "progressIndicator";
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
/** Concrete backend reported by GPU surface view and frame state. */
|
|
182
|
+
export type NativeSdkGpuSurfaceBackend = "none" | "metal" | "direct2d" | "software";
|
|
183
|
+
/** Portable backend request accepted when creating a GPU surface. */
|
|
184
|
+
export type NativeSdkGpuSurfaceBackendRequest = "metal" | "software";
|
|
182
185
|
export type NativeSdkGpuSurfacePixelFormat = "none" | "bgra8_unorm";
|
|
183
186
|
export type NativeSdkGpuSurfacePresentMode = "none" | "timer";
|
|
184
187
|
export type NativeSdkGpuSurfaceAlphaMode = "none" | "opaque" | "premultiplied";
|
|
@@ -327,8 +330,8 @@ export interface NativeSdkCreateNativeViewOptions extends NativeSdkCreateViewBas
|
|
|
327
330
|
kind: NativeSdkNativeViewKind;
|
|
328
331
|
frame?: NativeSdkRect;
|
|
329
332
|
url?: never;
|
|
330
|
-
/** Only valid for gpu_surface views.
|
|
331
|
-
gpuBackend?:
|
|
333
|
+
/** Only valid for gpu_surface views. Omit to use the first supported backend. */
|
|
334
|
+
gpuBackend?: NativeSdkGpuSurfaceBackendRequest;
|
|
332
335
|
/** Only valid for gpu_surface views. */
|
|
333
336
|
gpuPixelFormat?: NativeSdkGpuSurfacePixelFormat;
|
|
334
337
|
/** Only valid for gpu_surface views. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@native-sdk/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -19,9 +19,11 @@
|
|
|
19
19
|
"app.zon",
|
|
20
20
|
"packages/core/src",
|
|
21
21
|
"packages/core/sdk",
|
|
22
|
-
"packages/core/
|
|
22
|
+
"packages/core/compile-surface",
|
|
23
|
+
"packages/core/scripts",
|
|
23
24
|
"packages/core/package.json",
|
|
24
25
|
"packages/core/package-lock.json",
|
|
26
|
+
"tools/corewire",
|
|
25
27
|
"third_party/webview2",
|
|
26
28
|
"native-sdk.d.ts",
|
|
27
29
|
"README.md",
|
|
@@ -29,17 +31,17 @@
|
|
|
29
31
|
],
|
|
30
32
|
"dependencies": {
|
|
31
33
|
"@typescript/old": "npm:typescript@6.0.3",
|
|
32
|
-
"
|
|
34
|
+
"scriptc": "0.0.22"
|
|
33
35
|
},
|
|
34
36
|
"optionalDependencies": {
|
|
35
|
-
"@native-sdk/cli-darwin-arm64": "0.
|
|
36
|
-
"@native-sdk/cli-darwin-x64": "0.
|
|
37
|
-
"@native-sdk/cli-linux-arm64-gnu": "0.
|
|
38
|
-
"@native-sdk/cli-linux-arm64-musl": "0.
|
|
39
|
-
"@native-sdk/cli-linux-x64-gnu": "0.
|
|
40
|
-
"@native-sdk/cli-linux-x64-musl": "0.
|
|
41
|
-
"@native-sdk/cli-win32-arm64": "0.
|
|
42
|
-
"@native-sdk/cli-win32-x64": "0.
|
|
37
|
+
"@native-sdk/cli-darwin-arm64": "0.8.0",
|
|
38
|
+
"@native-sdk/cli-darwin-x64": "0.8.0",
|
|
39
|
+
"@native-sdk/cli-linux-arm64-gnu": "0.8.0",
|
|
40
|
+
"@native-sdk/cli-linux-arm64-musl": "0.8.0",
|
|
41
|
+
"@native-sdk/cli-linux-x64-gnu": "0.8.0",
|
|
42
|
+
"@native-sdk/cli-linux-x64-musl": "0.8.0",
|
|
43
|
+
"@native-sdk/cli-win32-arm64": "0.8.0",
|
|
44
|
+
"@native-sdk/cli-win32-x64": "0.8.0"
|
|
43
45
|
},
|
|
44
46
|
"repository": {
|
|
45
47
|
"type": "git",
|
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
// The compiled-core stage's restatement of @native-sdk/core: the SAME
|
|
2
|
+
// inert Cmd/Sub data values the reference module's factories build
|
|
3
|
+
// (packages/core/sdk/core.ts — the transpiler lane lowers references by
|
|
4
|
+
// identity and never runs that module's code), restated inside an
|
|
5
|
+
// external toolchain's static surface: no overloaded members, no
|
|
6
|
+
// generic value instantiation — the routing/arm-name rigor those
|
|
7
|
+
// generics carry is tsc's job in the authoring lane, and the paired
|
|
8
|
+
// e2e batteries hold every produced byte to the transpiler lane's
|
|
9
|
+
// output. Every external-compile stage copies this ONE file in as its
|
|
10
|
+
// ./sdk/core.ts: the fixture driver (tests/compiled-core/build_core.sh)
|
|
11
|
+
// and the product lane's stager (packages/core/scripts/
|
|
12
|
+
// stage_external_core.mjs) alike.
|
|
13
|
+
|
|
14
|
+
export function asciiBytes(s: string): Uint8Array {
|
|
15
|
+
const out = new Uint8Array(s.length);
|
|
16
|
+
for (let i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type Msgish = { readonly kind: string };
|
|
21
|
+
|
|
22
|
+
export interface EnvMsg<M extends Msgish> {
|
|
23
|
+
readonly env: string;
|
|
24
|
+
readonly msg: M["kind"];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type AudioState = "loaded" | "position" | "completed" | "failed" | "rejected" | "spectrum";
|
|
28
|
+
export type VideoState = "loaded" | "position" | "completed" | "failed" | "rejected";
|
|
29
|
+
export type ImageState =
|
|
30
|
+
| "loaded"
|
|
31
|
+
| "rejected"
|
|
32
|
+
| "not_found"
|
|
33
|
+
| "io_failed"
|
|
34
|
+
| "connect_failed"
|
|
35
|
+
| "tls_failed"
|
|
36
|
+
| "protocol_failed"
|
|
37
|
+
| "timed_out"
|
|
38
|
+
| "http_status"
|
|
39
|
+
| "cancelled"
|
|
40
|
+
| "too_large"
|
|
41
|
+
| "unsupported"
|
|
42
|
+
| "decode_failed"
|
|
43
|
+
| "registry_full"
|
|
44
|
+
| "alloc_failed";
|
|
45
|
+
export type ChannelState = "data" | "closed" | "rejected";
|
|
46
|
+
export type PtyState = "output" | "exit";
|
|
47
|
+
export type PtyExitReason = "exited" | "signaled" | "cancelled" | "rejected" | "spawn_failed";
|
|
48
|
+
|
|
49
|
+
export type HostScalar = number | boolean | Uint8Array;
|
|
50
|
+
export type HostRecord = { readonly [field: string]: HostScalar };
|
|
51
|
+
|
|
52
|
+
export interface RequestRoute<M extends Msgish> {
|
|
53
|
+
readonly key?: string;
|
|
54
|
+
readonly ok: M["kind"];
|
|
55
|
+
readonly err: M["kind"];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface WriteRoute<M extends Msgish> {
|
|
59
|
+
readonly key?: string;
|
|
60
|
+
readonly ok: M["kind"];
|
|
61
|
+
readonly err: M["kind"];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface FetchRoute<M extends Msgish> {
|
|
65
|
+
readonly key?: string;
|
|
66
|
+
readonly ok: M["kind"];
|
|
67
|
+
readonly err: M["kind"];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface SpawnRoute<M extends Msgish> {
|
|
71
|
+
readonly key?: string;
|
|
72
|
+
readonly stdin?: Uint8Array;
|
|
73
|
+
readonly line?: M["kind"];
|
|
74
|
+
readonly exit: M["kind"];
|
|
75
|
+
readonly err: M["kind"];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface SpawnCollectRoute<M extends Msgish> {
|
|
79
|
+
readonly key?: string;
|
|
80
|
+
readonly stdin?: Uint8Array;
|
|
81
|
+
readonly collect: true;
|
|
82
|
+
readonly exit: M["kind"];
|
|
83
|
+
readonly err: M["kind"];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface AudioSource {
|
|
87
|
+
readonly path?: Uint8Array;
|
|
88
|
+
readonly url?: Uint8Array;
|
|
89
|
+
readonly cachePath?: Uint8Array;
|
|
90
|
+
readonly expectedBytes?: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface AudioRoute<M extends Msgish> {
|
|
94
|
+
readonly event: M["kind"];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface VideoSource {
|
|
98
|
+
readonly surface: number;
|
|
99
|
+
readonly path?: Uint8Array;
|
|
100
|
+
readonly url?: Uint8Array;
|
|
101
|
+
readonly autoplay?: boolean;
|
|
102
|
+
readonly loop?: boolean;
|
|
103
|
+
readonly muted?: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface VideoRoute<M extends Msgish> {
|
|
107
|
+
readonly event: M["kind"];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ImageSource {
|
|
111
|
+
readonly path?: Uint8Array;
|
|
112
|
+
readonly url?: Uint8Array;
|
|
113
|
+
readonly cachePath?: Uint8Array;
|
|
114
|
+
readonly expectedBytes?: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface ImageRoute<M extends Msgish> {
|
|
118
|
+
readonly event: M["kind"];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface ChannelRoute<M extends Msgish> {
|
|
122
|
+
readonly event: M["kind"];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface PtyRoute<M extends Msgish> {
|
|
126
|
+
readonly key?: string;
|
|
127
|
+
readonly cols?: number;
|
|
128
|
+
readonly rows?: number;
|
|
129
|
+
readonly term?: string;
|
|
130
|
+
readonly event: M["kind"];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export type FetchMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
|
|
134
|
+
|
|
135
|
+
export interface FetchSpec {
|
|
136
|
+
readonly url: Uint8Array;
|
|
137
|
+
readonly method?: FetchMethod;
|
|
138
|
+
readonly headers?: { readonly [name: string]: string | Uint8Array };
|
|
139
|
+
readonly body?: Uint8Array;
|
|
140
|
+
readonly timeoutMs?: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// The inert command data — the reference module's Cmd<M> union with
|
|
144
|
+
/// the type parameter erased (M constrains only the factories' arm-name
|
|
145
|
+
/// checking, never the data).
|
|
146
|
+
export type CmdData =
|
|
147
|
+
| { readonly op: "none" }
|
|
148
|
+
| { readonly op: "persist" }
|
|
149
|
+
| { readonly op: "now"; readonly msgKind: string }
|
|
150
|
+
| { readonly op: "host"; readonly name: string; readonly args: readonly number[] }
|
|
151
|
+
| { readonly op: "host_bytes"; readonly name: string; readonly payload: Uint8Array }
|
|
152
|
+
| {
|
|
153
|
+
readonly op: "request";
|
|
154
|
+
readonly name: string;
|
|
155
|
+
readonly key: string;
|
|
156
|
+
readonly okKind: string;
|
|
157
|
+
readonly errKind: string;
|
|
158
|
+
readonly payload: Uint8Array;
|
|
159
|
+
}
|
|
160
|
+
| { readonly op: "cancel"; readonly key: string }
|
|
161
|
+
| {
|
|
162
|
+
readonly op: "read_file";
|
|
163
|
+
readonly key: string;
|
|
164
|
+
readonly okKind: string;
|
|
165
|
+
readonly errKind: string;
|
|
166
|
+
readonly path: Uint8Array;
|
|
167
|
+
}
|
|
168
|
+
| {
|
|
169
|
+
readonly op: "write_file";
|
|
170
|
+
readonly key: string;
|
|
171
|
+
readonly okKind: string;
|
|
172
|
+
readonly errKind: string;
|
|
173
|
+
readonly path: Uint8Array;
|
|
174
|
+
readonly bytes: Uint8Array;
|
|
175
|
+
}
|
|
176
|
+
| {
|
|
177
|
+
readonly op: "fetch";
|
|
178
|
+
readonly key: string;
|
|
179
|
+
readonly okKind: string;
|
|
180
|
+
readonly errKind: string;
|
|
181
|
+
readonly method: FetchMethod;
|
|
182
|
+
readonly timeoutMs: number;
|
|
183
|
+
readonly url: Uint8Array;
|
|
184
|
+
readonly headers: readonly { readonly name: string; readonly value: string | Uint8Array }[];
|
|
185
|
+
readonly body: Uint8Array;
|
|
186
|
+
}
|
|
187
|
+
| { readonly op: "clip_write"; readonly bytes: Uint8Array }
|
|
188
|
+
| { readonly op: "clip_read"; readonly key: string; readonly okKind: string; readonly errKind: string }
|
|
189
|
+
| { readonly op: "delay"; readonly key: string; readonly afterMs: number; readonly msgKind: string }
|
|
190
|
+
| {
|
|
191
|
+
readonly op: "spawn";
|
|
192
|
+
readonly key: string;
|
|
193
|
+
readonly lineKind: string;
|
|
194
|
+
readonly exitKind: string;
|
|
195
|
+
readonly errKind: string;
|
|
196
|
+
readonly collect: boolean;
|
|
197
|
+
readonly argv: readonly Uint8Array[];
|
|
198
|
+
readonly stdin: Uint8Array;
|
|
199
|
+
}
|
|
200
|
+
| {
|
|
201
|
+
readonly op: "audio_play";
|
|
202
|
+
readonly key: string;
|
|
203
|
+
readonly eventKind: string;
|
|
204
|
+
readonly path: Uint8Array;
|
|
205
|
+
readonly url: Uint8Array;
|
|
206
|
+
readonly cachePath: Uint8Array;
|
|
207
|
+
readonly expectedBytes: number;
|
|
208
|
+
}
|
|
209
|
+
| {
|
|
210
|
+
readonly op: "audio_ctl";
|
|
211
|
+
readonly key: string;
|
|
212
|
+
readonly verb: "pause" | "resume" | "stop" | "seek" | "volume";
|
|
213
|
+
readonly value: number;
|
|
214
|
+
}
|
|
215
|
+
| {
|
|
216
|
+
readonly op: "video_load";
|
|
217
|
+
readonly key: string;
|
|
218
|
+
readonly eventKind: string;
|
|
219
|
+
readonly surface: number;
|
|
220
|
+
readonly path: Uint8Array;
|
|
221
|
+
readonly url: Uint8Array;
|
|
222
|
+
readonly autoplay: boolean;
|
|
223
|
+
readonly loop: boolean;
|
|
224
|
+
readonly muted: boolean;
|
|
225
|
+
}
|
|
226
|
+
| {
|
|
227
|
+
readonly op: "video_ctl";
|
|
228
|
+
readonly key: string;
|
|
229
|
+
readonly verb: "play" | "pause" | "stop" | "seek" | "volume" | "muted" | "loop";
|
|
230
|
+
readonly value: number;
|
|
231
|
+
}
|
|
232
|
+
| { readonly op: "window_show"; readonly label: string }
|
|
233
|
+
| { readonly op: "quit_app" }
|
|
234
|
+
| {
|
|
235
|
+
readonly op: "image_load";
|
|
236
|
+
readonly id: number;
|
|
237
|
+
readonly eventKind: string;
|
|
238
|
+
readonly path: Uint8Array;
|
|
239
|
+
readonly url: Uint8Array;
|
|
240
|
+
readonly cachePath: Uint8Array;
|
|
241
|
+
readonly expectedBytes: number;
|
|
242
|
+
}
|
|
243
|
+
| { readonly op: "image_cancel"; readonly id: number }
|
|
244
|
+
| { readonly op: "image_unregister"; readonly id: number }
|
|
245
|
+
| { readonly op: "channel_open"; readonly key: number; readonly eventKind: string }
|
|
246
|
+
| { readonly op: "channel_close"; readonly key: number }
|
|
247
|
+
| {
|
|
248
|
+
readonly op: "pty_spawn";
|
|
249
|
+
readonly key: string;
|
|
250
|
+
readonly eventKind: string;
|
|
251
|
+
readonly cols: number;
|
|
252
|
+
readonly rows: number;
|
|
253
|
+
readonly term: string;
|
|
254
|
+
readonly argv: readonly Uint8Array[];
|
|
255
|
+
}
|
|
256
|
+
| { readonly op: "pty_write"; readonly key: string; readonly bytes: Uint8Array }
|
|
257
|
+
| { readonly op: "pty_resize"; readonly key: string; readonly cols: number; readonly rows: number }
|
|
258
|
+
| { readonly op: "pty_kill"; readonly key: string }
|
|
259
|
+
| { readonly op: "batch"; readonly cmds: readonly CmdData[] };
|
|
260
|
+
|
|
261
|
+
export type Cmd<M extends Msgish> = CmdData;
|
|
262
|
+
|
|
263
|
+
/// The wire encoding of a host record payload — byte-identical to the
|
|
264
|
+
/// reference module's hostRecordBytes (fields sorted by name, no field
|
|
265
|
+
/// headers; number -> f64 LE, boolean -> one byte, bytes -> u32 LE
|
|
266
|
+
/// length + bytes).
|
|
267
|
+
export function hostRecordBytes(payload: HostRecord): Uint8Array {
|
|
268
|
+
const names = Object.keys(payload).sort();
|
|
269
|
+
let len = 0;
|
|
270
|
+
for (const n of names) {
|
|
271
|
+
const v = payload[n]!;
|
|
272
|
+
if (typeof v === "number") len += 8;
|
|
273
|
+
else if (typeof v === "boolean") len += 1;
|
|
274
|
+
else len += 4 + v.length;
|
|
275
|
+
}
|
|
276
|
+
const out = new Uint8Array(len);
|
|
277
|
+
let off = 0;
|
|
278
|
+
for (const n of names) {
|
|
279
|
+
const v = payload[n]!;
|
|
280
|
+
if (typeof v === "number") {
|
|
281
|
+
const buf = Buffer.alloc(8);
|
|
282
|
+
buf.writeDoubleLE(v, 0);
|
|
283
|
+
for (let i = 0; i < 8; i++) out[off + i] = buf[i]!;
|
|
284
|
+
off += 8;
|
|
285
|
+
} else if (typeof v === "boolean") {
|
|
286
|
+
out[off] = v ? 1 : 0;
|
|
287
|
+
off += 1;
|
|
288
|
+
} else {
|
|
289
|
+
out[off] = v.length % 256;
|
|
290
|
+
out[off + 1] = Math.floor(v.length / 256) % 256;
|
|
291
|
+
out[off + 2] = Math.floor(v.length / 65536) % 256;
|
|
292
|
+
out[off + 3] = Math.floor(v.length / 16777216) % 256;
|
|
293
|
+
off += 4;
|
|
294
|
+
for (let i = 0; i < v.length; i++) out[off + i] = v[i]!;
|
|
295
|
+
off += v.length;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/// A host command by name — the reference module's overloaded `host`
|
|
302
|
+
/// restated as the raw-bytes form (the whole corpus's usage; overloads,
|
|
303
|
+
/// rest-args, and the `Uint8Array | HostRecord` runtime discrimination
|
|
304
|
+
/// all sit outside the static surface). The record and scalar-args
|
|
305
|
+
/// forms stay reachable through `hostRecord`/`hostArgs`, byte-identical
|
|
306
|
+
/// data either way.
|
|
307
|
+
function hostCmd(name: string, payload: Uint8Array): CmdData {
|
|
308
|
+
return { op: "host_bytes", name, payload: payload };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function hostRecord(name: string, payload: HostRecord): CmdData {
|
|
312
|
+
return { op: "host_bytes", name, payload: hostRecordBytes(payload) };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export function hostArgs(name: string, args: readonly number[]): CmdData {
|
|
316
|
+
return { op: "host", name, args };
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export const Cmd = {
|
|
320
|
+
none: { op: "none" } as CmdData,
|
|
321
|
+
|
|
322
|
+
persist(): CmdData {
|
|
323
|
+
return { op: "persist" };
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
now(msgKind: string): CmdData {
|
|
327
|
+
return { op: "now", msgKind };
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
host: hostCmd,
|
|
331
|
+
|
|
332
|
+
request(name: string, payload: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
|
|
333
|
+
return {
|
|
334
|
+
op: "request",
|
|
335
|
+
name,
|
|
336
|
+
key: route.key ?? "",
|
|
337
|
+
okKind: route.ok,
|
|
338
|
+
errKind: route.err,
|
|
339
|
+
payload: payload,
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
cancel(key: string): CmdData {
|
|
344
|
+
return { op: "cancel", key };
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
readFile(path: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
|
|
348
|
+
return { op: "read_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path };
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
writeFile(path: Uint8Array, bytes: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
|
|
352
|
+
return { op: "write_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
fetch(spec: FetchSpec, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
|
|
356
|
+
const names = Object.keys(spec.headers ?? {}).sort();
|
|
357
|
+
const headers: { readonly name: string; readonly value: string | Uint8Array }[] = [];
|
|
358
|
+
for (const n of names) {
|
|
359
|
+
headers.push({ name: n, value: spec.headers![n]! });
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
op: "fetch",
|
|
363
|
+
key: route.key ?? "",
|
|
364
|
+
okKind: route.ok,
|
|
365
|
+
errKind: route.err,
|
|
366
|
+
method: spec.method ?? "GET",
|
|
367
|
+
timeoutMs: spec.timeoutMs ?? 0,
|
|
368
|
+
url: spec.url,
|
|
369
|
+
headers: headers,
|
|
370
|
+
body: spec.body ?? new Uint8Array(0),
|
|
371
|
+
};
|
|
372
|
+
},
|
|
373
|
+
|
|
374
|
+
clipboardWrite(bytes: Uint8Array): CmdData {
|
|
375
|
+
return { op: "clip_write", bytes };
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
clipboardRead(route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
|
|
379
|
+
return { op: "clip_read", key: route.key ?? "", okKind: route.ok, errKind: route.err };
|
|
380
|
+
},
|
|
381
|
+
|
|
382
|
+
delay(key: string, ms: number, msgKind: string): CmdData {
|
|
383
|
+
return { op: "delay", key, afterMs: ms, msgKind };
|
|
384
|
+
},
|
|
385
|
+
|
|
386
|
+
spawn(
|
|
387
|
+
argv: readonly Uint8Array[],
|
|
388
|
+
route: { readonly key?: string; readonly stdin?: Uint8Array; readonly line?: string; readonly collect?: boolean; readonly exit: string; readonly err: string },
|
|
389
|
+
): CmdData {
|
|
390
|
+
const collect = route.collect === true;
|
|
391
|
+
return {
|
|
392
|
+
op: "spawn",
|
|
393
|
+
key: route.key ?? "",
|
|
394
|
+
lineKind: collect ? "" : (route.line ?? ""),
|
|
395
|
+
exitKind: route.exit,
|
|
396
|
+
errKind: route.err,
|
|
397
|
+
collect,
|
|
398
|
+
argv,
|
|
399
|
+
stdin: route.stdin ?? new Uint8Array(0),
|
|
400
|
+
};
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
audioPlay(key: string, source: AudioSource, route: { readonly event: string }): CmdData {
|
|
404
|
+
return {
|
|
405
|
+
op: "audio_play",
|
|
406
|
+
key,
|
|
407
|
+
eventKind: route.event,
|
|
408
|
+
path: source.path ?? new Uint8Array(0),
|
|
409
|
+
url: source.url ?? new Uint8Array(0),
|
|
410
|
+
cachePath: source.cachePath ?? new Uint8Array(0),
|
|
411
|
+
expectedBytes: source.expectedBytes ?? 0,
|
|
412
|
+
};
|
|
413
|
+
},
|
|
414
|
+
|
|
415
|
+
audioPause(key: string): CmdData {
|
|
416
|
+
return { op: "audio_ctl", key, verb: "pause", value: 0 };
|
|
417
|
+
},
|
|
418
|
+
|
|
419
|
+
audioResume(key: string): CmdData {
|
|
420
|
+
return { op: "audio_ctl", key, verb: "resume", value: 0 };
|
|
421
|
+
},
|
|
422
|
+
|
|
423
|
+
audioStop(key: string): CmdData {
|
|
424
|
+
return { op: "audio_ctl", key, verb: "stop", value: 0 };
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
audioSeek(key: string, ms: number): CmdData {
|
|
428
|
+
return { op: "audio_ctl", key, verb: "seek", value: ms };
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
audioSetVolume(key: string, volume: number): CmdData {
|
|
432
|
+
return { op: "audio_ctl", key, verb: "volume", value: volume };
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
videoLoad(key: string, source: VideoSource, route: { readonly event: string }): CmdData {
|
|
436
|
+
return {
|
|
437
|
+
op: "video_load",
|
|
438
|
+
key,
|
|
439
|
+
eventKind: route.event,
|
|
440
|
+
surface: source.surface,
|
|
441
|
+
path: source.path ?? new Uint8Array(0),
|
|
442
|
+
url: source.url ?? new Uint8Array(0),
|
|
443
|
+
autoplay: source.autoplay ?? true,
|
|
444
|
+
loop: source.loop ?? false,
|
|
445
|
+
muted: source.muted ?? false,
|
|
446
|
+
};
|
|
447
|
+
},
|
|
448
|
+
|
|
449
|
+
videoPlay(key: string): CmdData {
|
|
450
|
+
return { op: "video_ctl", key, verb: "play", value: 0 };
|
|
451
|
+
},
|
|
452
|
+
|
|
453
|
+
videoPause(key: string): CmdData {
|
|
454
|
+
return { op: "video_ctl", key, verb: "pause", value: 0 };
|
|
455
|
+
},
|
|
456
|
+
|
|
457
|
+
videoStop(key: string): CmdData {
|
|
458
|
+
return { op: "video_ctl", key, verb: "stop", value: 0 };
|
|
459
|
+
},
|
|
460
|
+
|
|
461
|
+
videoSeek(key: string, ms: number): CmdData {
|
|
462
|
+
return { op: "video_ctl", key, verb: "seek", value: ms };
|
|
463
|
+
},
|
|
464
|
+
|
|
465
|
+
videoSetVolume(key: string, volume: number): CmdData {
|
|
466
|
+
return { op: "video_ctl", key, verb: "volume", value: volume };
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
videoSetMuted(key: string, muted: boolean): CmdData {
|
|
470
|
+
return { op: "video_ctl", key, verb: "muted", value: muted ? 1 : 0 };
|
|
471
|
+
},
|
|
472
|
+
|
|
473
|
+
videoSetLoop(key: string, loop: boolean): CmdData {
|
|
474
|
+
return { op: "video_ctl", key, verb: "loop", value: loop ? 1 : 0 };
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
showWindow(label: string): CmdData {
|
|
478
|
+
return { op: "window_show", label };
|
|
479
|
+
},
|
|
480
|
+
|
|
481
|
+
quitApp(): CmdData {
|
|
482
|
+
return { op: "quit_app" };
|
|
483
|
+
},
|
|
484
|
+
|
|
485
|
+
imageLoad(id: number, source: ImageSource, route: { readonly event: string }): CmdData {
|
|
486
|
+
return {
|
|
487
|
+
op: "image_load",
|
|
488
|
+
id,
|
|
489
|
+
eventKind: route.event,
|
|
490
|
+
path: source.path ?? new Uint8Array(0),
|
|
491
|
+
url: source.url ?? new Uint8Array(0),
|
|
492
|
+
cachePath: source.cachePath ?? new Uint8Array(0),
|
|
493
|
+
expectedBytes: source.expectedBytes ?? 0,
|
|
494
|
+
};
|
|
495
|
+
},
|
|
496
|
+
|
|
497
|
+
imageCancel(id: number): CmdData {
|
|
498
|
+
return { op: "image_cancel", id };
|
|
499
|
+
},
|
|
500
|
+
|
|
501
|
+
imageUnregister(id: number): CmdData {
|
|
502
|
+
return { op: "image_unregister", id };
|
|
503
|
+
},
|
|
504
|
+
|
|
505
|
+
channelOpen(key: number, route: { readonly event: string }): CmdData {
|
|
506
|
+
return { op: "channel_open", key, eventKind: route.event };
|
|
507
|
+
},
|
|
508
|
+
|
|
509
|
+
channelClose(key: number): CmdData {
|
|
510
|
+
return { op: "channel_close", key };
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
ptySpawn(argv: readonly Uint8Array[], route: { readonly key?: string; readonly cols?: number; readonly rows?: number; readonly term?: string; readonly event: string }): CmdData {
|
|
514
|
+
return {
|
|
515
|
+
op: "pty_spawn",
|
|
516
|
+
key: route.key ?? "",
|
|
517
|
+
eventKind: route.event,
|
|
518
|
+
cols: route.cols ?? 80,
|
|
519
|
+
rows: route.rows ?? 24,
|
|
520
|
+
term: route.term ?? "",
|
|
521
|
+
argv,
|
|
522
|
+
};
|
|
523
|
+
},
|
|
524
|
+
|
|
525
|
+
ptyWrite(key: string, bytes: Uint8Array): CmdData {
|
|
526
|
+
return { op: "pty_write", key, bytes };
|
|
527
|
+
},
|
|
528
|
+
|
|
529
|
+
ptyResize(key: string, cols: number, rows: number): CmdData {
|
|
530
|
+
return { op: "pty_resize", key, cols, rows };
|
|
531
|
+
},
|
|
532
|
+
|
|
533
|
+
ptyKill(key: string): CmdData {
|
|
534
|
+
return { op: "pty_kill", key };
|
|
535
|
+
},
|
|
536
|
+
|
|
537
|
+
batch(cmds: readonly CmdData[]): CmdData {
|
|
538
|
+
return { op: "batch", cmds };
|
|
539
|
+
},
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
export type SubData =
|
|
543
|
+
| { readonly op: "none" }
|
|
544
|
+
| { readonly op: "timer"; readonly key: string; readonly everyMs: number; readonly msgKind: string }
|
|
545
|
+
| { readonly op: "batch"; readonly subs: readonly SubData[] };
|
|
546
|
+
|
|
547
|
+
export type Sub<M extends Msgish> = SubData;
|
|
548
|
+
|
|
549
|
+
export const Sub = {
|
|
550
|
+
none: { op: "none" } as SubData,
|
|
551
|
+
|
|
552
|
+
timer(key: string, everyMs: number, msgKind: string): SubData {
|
|
553
|
+
return { op: "timer", key, everyMs, msgKind };
|
|
554
|
+
},
|
|
555
|
+
|
|
556
|
+
batch(subs: readonly SubData[]): SubData {
|
|
557
|
+
return { op: "batch", subs };
|
|
558
|
+
},
|
|
559
|
+
};
|