@jetpack-desktop/client 0.0.0-stage → 0.1.2-beta.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/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ JetPack (`@jetpack-desktop/client` and `jetpack-wasm`) is dual-licensed under either:
2
+
3
+ - Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
4
+ - MIT License (http://opensource.org/licenses/MIT)
5
+
6
+ at your option.
7
+
8
+ ---
9
+
10
+ MIT License
11
+
12
+ Copyright (c) 2026 JetPack Contributors
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,82 @@
1
- # Temporary Holding Version
1
+ # `@jetpack-desktop/client`
2
+
3
+ High-level TypeScript/JavaScript SDK with bundled `jetpack-wasm` WebAssembly bindings for interacting with local sandboxed JetPack workers from browser web applications, complete with an auto-mounted Shadow-DOM [`JetPackControlBar`](https://jetpack-desktop.github.io/sdk/frontend/api-reference) and [`JetPackLogTerminal`](https://jetpack-desktop.github.io/sdk/frontend/api-reference).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @jetpack-desktop/client
9
+ ```
10
+
11
+ Compiled `jetpack-wasm` bindings (`jetpack_wasm.js` + `jetpack_wasm_bg.wasm`) are bundled inside `@jetpack-desktop/client` and loaded automatically by `JetPackAppClient.connectAndEnsureApp()` with zero manual WASM path configuration in Vite, Rollup, and modern ESM bundlers.
12
+
13
+ If you need direct low-level access to `WasmClientIdentity` or `JetPackWasmClient`, import from `@jetpack-desktop/client/wasm`:
14
+
15
+ ```ts
16
+ import initWasm, { JetPackWasmClient, WasmClientIdentity } from '@jetpack-desktop/client/wasm';
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { JetPackAppClient } from '@jetpack-desktop/client';
23
+
24
+ const client = new JetPackAppClient();
25
+
26
+ await client.connectAndEnsureApp({
27
+ appId: 'io.jetpack.media-converter',
28
+ daemonPort: 9470,
29
+ controlBar: {
30
+ appName: 'FFmpeg Media Converter',
31
+ warnOnUnsavedWork: () => hasActiveUnsavedWork(),
32
+ stopConfirmMessage: 'Transcoding is in progress. Stopping will lose unsaved work.',
33
+ onBeforeStop: async () => true,
34
+ },
35
+ onProgress: (prog) => {
36
+ console.log(`[${prog.stage}] ${prog.percent}% - ${prog.message}`);
37
+ },
38
+ });
39
+
40
+ const unsub = client.onStream('media.transcode.progress', (payload, ctx) => {
41
+ console.log('Stream frame', ctx.opcode, ctx.correlationId, payload.byteLength);
42
+ });
43
+
44
+ const reply = await client.request(
45
+ 'media.list_files',
46
+ { filter: 'mp4' },
47
+ new Uint8Array(0),
48
+ );
49
+
50
+ console.log('Reply opcode:', reply.opcode, 'bytes:', reply.payload.byteLength);
51
+
52
+ // Optionally stop the worker explicitly (also wired to the Control Bar "Stop" button)
53
+ // await client.stopApp();
54
+
55
+ unsub();
56
+ client.destroy(); // Closes WebSocket and unmounts JetPackControlBar
57
+ ```
58
+
59
+ ## Features
60
+
61
+ - **Zero-Config Bundled WASM**: Ships compiled `jetpack-wasm` (`X25519`, `Ed25519`, `ChaCha20-Poly1305`, MsgPack framing) inside the package (`@jetpack-desktop/client/wasm`), while still allowing `wasmModule`, `wasmModulePath`, and `wasmBinaryOrUrl` overrides.
62
+ - **`JetPackAppClient<TOpcodes>`**: Automatic `jetpack://pair` onboarding, `SignedAppCatalog` provisioning, worker launch/attachment, correlated `request()`, and wildcard `onStream()`. Pass `JetPackOpcodeMap` generated by `jetpack codegen` for strict compile-time checking while preserving 100% backwards compatibility for untyped `new JetPackAppClient()` usage.
63
+ - **`JetPackControlBar`**: Isolated inside an open `ShadowRoot`, auto-mounted at the top of the page during `connectAndEnsureApp()` (pass `controlBar: false` to opt out). Renders the JetPack brand mark, app name, live status pill (`Connecting`, `Running`, `Stopped`, `Error`), `"Control Center"` link, and `"Stop"` action with a built-in unsaved-work confirmation modal.
64
+ - **`JetPackLogTerminal`**: Auto-mounted bottom drawer when Developer Mode is active on the daemon, streaming sanitized `logs.entry` frames.
65
+
66
+ ## Typed Opcode Contracts (`jetpack codegen`)
67
+
68
+ Generate `jetpack-env.d.ts` from your Python worker AST (`@opcode` / Pydantic `BaseModel` / `TypedDict` / `@dataclass`) and pass `JetPackOpcodeMap` as the generic parameter:
69
+
70
+ ```ts
71
+ import { JetPackAppClient } from '@jetpack-desktop/client';
72
+ import type { JetPackOpcodeMap } from './jetpack-env';
73
+
74
+ const typedClient = new JetPackAppClient<JetPackOpcodeMap>();
75
+ await typedClient.connectAndEnsureApp({ appId: 'com.dev.my-worker', daemonPort: 9470 });
76
+
77
+ // Compile-time verified by tsc: opcode name, meta fields, and binary Uint8Array requirements
78
+ const reply = await typedClient.request('audio.transcribe', { language: 'en' }, audioBytes);
79
+ ```
80
+
81
+ See the [JetPack Documentation](https://jetpack-desktop.github.io/sdk/frontend/quickstart) and [AI Agents & MCP Integration](https://jetpack-desktop.github.io/guide/ai-agents) guides for `llms-full.txt`, `jetpack init`, and `jetpack mcp` setup.
2
82
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
@@ -0,0 +1,122 @@
1
+ import { JetPackControlBar } from './control-bar.js';
2
+ import { JetPackLogTerminal } from './log-terminal.js';
3
+ import { type AppWorkerStoppedEvent, type ConnectAndEnsureAppOptions, type DefaultOpcodeMap, type LogEntry, type LogsSubscribeOkResponse, type OpcodeConstraint, type OpcodeRequestArgs, type OpcodeResponseFor, type OpcodeStreamPayloadFor, type StreamCallback, type WasmClientLike, type WasmIdentityLike, type WorkerResponse, type WorkerStopReason } from './types.js';
4
+ export declare const DEFAULT_JETPACK_DOWNLOAD_URL = "https://github.com/jetpack-desktop/releases/releases/latest";
5
+ /**
6
+ * High-level SDK client wrapping `jetpack-wasm` (`WasmClientIdentity` + `JetPackWasmClient`)
7
+ * to provide automatic `jetpack://pair` onboarding, catalog/install/launch orchestration,
8
+ * correlated `request()` RPCs, multiplexed `onStream()` subscriptions, and an auto-mounted
9
+ * Shadow-DOM `JetPackControlBar`.
10
+ *
11
+ * Optionally pass a codegen-generated `JetPackOpcodeMap` generic parameter
12
+ * (`new JetPackAppClient<JetPackOpcodeMap>()`) for compile-time opcode, metadata,
13
+ * binary payload, and stream contract enforcement.
14
+ */
15
+ export declare class JetPackAppClient<TOpcodes extends OpcodeConstraint<TOpcodes> = DefaultOpcodeMap> {
16
+ private wasmClient;
17
+ private identity;
18
+ private appId;
19
+ private lastPairingUri;
20
+ private closed;
21
+ private workerRunning;
22
+ private lastStopReason;
23
+ private ensureWorkerPromise;
24
+ private lastProgressCallback;
25
+ private resetVolumesOnRelaunch;
26
+ private initializedWasmModules;
27
+ private streamListeners;
28
+ private workerStoppedListeners;
29
+ private workerStartedListeners;
30
+ private inFlightRequests;
31
+ private controlBar;
32
+ private logTerminal;
33
+ /** Returns `true` when an authenticated daemon session is open and bound to an app. */
34
+ isConnected(): boolean;
35
+ /** Returns `true` when the session is connected and the app worker is currently active. */
36
+ isWorkerRunning(): boolean;
37
+ /** Returns the most recent worker stop reason observed on this session, if stopped. */
38
+ getLastStopReason(): WorkerStopReason | null;
39
+ /** Returns the currently ensured `appId`, or `null` if disconnected. */
40
+ getAppId(): string | null;
41
+ /** Returns the active `WasmClientIdentity` instance, if initialized. */
42
+ getIdentity(): WasmIdentityLike | null;
43
+ /** Returns the last generated `jetpack://pair?...` URI if pairing was triggered. */
44
+ getLastPairingUri(): string | null;
45
+ /** Returns the underlying `JetPackWasmClient` instance for advanced control-plane calls. */
46
+ getRawClient(): WasmClientLike | null;
47
+ /** Returns the auto-mounted `JetPackControlBar` instance, or `null` when disabled or headless. */
48
+ getControlBar(): JetPackControlBar | null;
49
+ /** Returns the Developer Mode `JetPackLogTerminal` instance, or `null` when disabled or unmounted. */
50
+ getLogTerminal(): JetPackLogTerminal | null;
51
+ /**
52
+ * Registers a callback invoked when the daemon reports `"app.worker.stopped"` for this app
53
+ * (e.g. idle timeout, manual Stop, or unexpected process exit). Returns an unsubscribe closure.
54
+ */
55
+ onWorkerStopped(callback: (event: AppWorkerStoppedEvent) => void): () => void;
56
+ /**
57
+ * Registers a callback invoked when `ensureWorkerRunning()` successfully launches or wakes
58
+ * the worker for this app (including via the `JetPackControlBar` `"Relaunch"` button or
59
+ * transparent `request()` auto-wake). Returns an unsubscribe closure.
60
+ */
61
+ onWorkerStarted(callback: (event: {
62
+ app_id: string;
63
+ }) => void): () => void;
64
+ /**
65
+ * Ensures the sandboxed worker for the connected app is running, relaunching it via
66
+ * `launch_app` if it was stopped due to idle timeout or user termination. Concurrent calls
67
+ * share a single in-flight launch operation.
68
+ */
69
+ ensureWorkerRunning(): Promise<void>;
70
+ /**
71
+ * Connects to the local JetPack daemon (triggering `jetpack://pair` approval if unpaired),
72
+ * verifies `appId` is installed (pulling from `SignedAppCatalog` with progress if absent),
73
+ * ensures the worker process is running inside its sandbox, and mounts `JetPackControlBar`
74
+ * in browser DOM environments unless `controlBar: false`.
75
+ */
76
+ connectAndEnsureApp(options: ConnectAndEnsureAppOptions): Promise<this>;
77
+ /**
78
+ * Stops the active sandboxed worker process via `terminate_app(appId)` while keeping
79
+ * any mounted `JetPackControlBar` visible with `'Stopped'` status.
80
+ */
81
+ stopApp(): Promise<unknown>;
82
+ /**
83
+ * Sends a correlated zero-copy binary hybrid frame to the ensured worker and resolves
84
+ * with `{ opcode, payload, correlationId }` when the matching reply arrives.
85
+ *
86
+ * Automatically relaunches the worker once via `ensureWorkerRunning()` if it was stopped
87
+ * due to idle timeout or if the daemon returns a no-active-worker `system.error`.
88
+ */
89
+ request<K extends keyof TOpcodes & string>(opcode: K, ...args: OpcodeRequestArgs<TOpcodes, K>): Promise<WorkerResponse<OpcodeResponseFor<TOpcodes, K>>>;
90
+ /**
91
+ * Registers a listener for streaming or unsolicited worker frames matching `opcode`
92
+ * (or `'*'` to subscribe to all stream frames). Returns an idempotent unsubscribe closure.
93
+ */
94
+ onStream<K extends (keyof TOpcodes & string) | '*'>(opcode: K, callback: StreamCallback<K extends '*' ? string : K, OpcodeStreamPayloadFor<TOpcodes, K>>): () => void;
95
+ /**
96
+ * Subscribes to live sanitized daemon & worker log entries (`logs.entry`) when
97
+ * Developer Mode is enabled on the local daemon.
98
+ */
99
+ subscribeLogs(onEntry: (entry: LogEntry) => void): Promise<LogsSubscribeOkResponse>;
100
+ /**
101
+ * Unsubscribes from live log streaming (`logs.unsubscribe`). Safe to call repeatedly.
102
+ */
103
+ unsubscribeLogs(): Promise<void>;
104
+ /**
105
+ * Closes the WebSocket session, rejects any in-flight `request()` calls,
106
+ * clears all registered `onStream()` listeners, unsubscribes from live logs,
107
+ * and transitions any mounted `JetPackControlBar` to `'Stopped'`.
108
+ */
109
+ close(): void;
110
+ /**
111
+ * Closes the WebSocket session and unmounts any auto-mounted `JetPackControlBar`
112
+ * and `JetPackLogTerminal`.
113
+ */
114
+ destroy(): void;
115
+ private syncLogTerminalForSession;
116
+ private cleanupConnectionOnly;
117
+ private handleWorkerStopped;
118
+ private dispatchStreamFrame;
119
+ private loadWasmBindings;
120
+ private connectWithAutoPair;
121
+ }
122
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAGL,KAAK,qBAAqB,EAE1B,KAAK,0BAA0B,EAC/B,KAAK,gBAAgB,EAIrB,KAAK,QAAQ,EACb,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EAErB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAE3B,KAAK,cAAc,EAEnB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAMpB,eAAO,MAAM,4BAA4B,gEACsB,CAAC;AAyJhE;;;;;;;;;GASG;AACH,qBAAa,gBAAgB,CAC3B,QAAQ,SAAS,gBAAgB,CAAC,QAAQ,CAAC,GAAG,gBAAgB;IAE9D,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,QAAQ,CAAiC;IACjD,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,cAAc,CAAiC;IACvD,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,oBAAoB,CAAsD;IAClF,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,sBAAsB,CAAyB;IACvD,OAAO,CAAC,eAAe,CAA2D;IAClF,OAAO,CAAC,sBAAsB,CAAqD;IACnF,OAAO,CAAC,sBAAsB,CAAkD;IAChF,OAAO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