@cmdless/ui-sdk 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,18 +7,23 @@ Shared types and helpers for building on cmdless UI, split by where they run.
7
7
  - **`@cmdless/ui-sdk`** — platform-agnostic.
8
8
  - `types` — `ShowTypes`, `MessageBoxTypes`, and the card and form shapes (`AdaptiveCard`, `CardEvent`, `CardView`, `FormView`).
9
9
  - The agent prompts as cards: `elicitationCard`/`elicitationResult` (MCP's and ACP's elicitation, form mode) and `permissionCard`/`permissionResult` (ACP's permission request) — a request in, a card to show; what the card ended with in, the protocol's answer out. Closing the card is cancelling.
10
- - `Cmdless`, what a window's page gets as `window.cmdless`: `resolve(value)` ends the window, and `connect()` (use `connect` from `/browser`) reaches its backend.
10
+ - `Cmdless`, what a window's page gets as `window.cmdless`: `resolve(value)` ends the window, and `backend` is the connection to its backend, started as the page loads — or nothing, if it has none — and `connect()` opens another (use `connect` from `/browser`).
11
11
  - The host's own channels to a window's preload (`cmdlessIPC`, `cmdlessViewIPC`, `createElectronIPC`, `createElectronViewIPC`) — main ↔ preload only.
12
12
 
13
13
  - **`@cmdless/ui-sdk/node`** — Node only.
14
14
  - `UIHost` — a connection to a host (one Electron process per app name, run by [`@cmdless/ui-runtime`](../../apps/ui-runtime)).
15
- - `UIHost.create({ app?, cmdlessRoot?, timeoutMs? })` starts the host for `app`, or joins it if it's already running. Without `app`, the host is a throwaway one of this caller's own.
16
- - `openWindow(params, backend?)`, `openDialog(params)`, `openCard(params)` and `openForm(params)` open a window, a message box, an [Adaptive Card](https://adaptivecards.io) or a JSON Schema form; `createTray(params)` creates a tray icon and `showNotification(params)` an OS notification. Each resolves to a remote handle once the host has. A handle's `closed` settles with the value it ends with — a window's resolve or the redirect it caught, the dialog's chosen button, a card's `Action.Submit` (`{ action, inputs }`), a form's data — or nothing if it was closed by hand; `close(value?)` ends it. Anything can be opened from another handle (`handle.openWindow(...)`, ...) to open in front of it. A tray reports clicks, and a card each `Action.Execute`, through `onEvent`; `update(...)` changes either.
15
+ - `UIHost.create({ app?, cmdlessRoot?, timeoutMs?, initialize? })` starts the host for `app`, or joins it if it's already running. Without `app`, the host is a throwaway one of this caller's own. `initialize(host)` sets the UIHost up before `create` hands it back — and, for the owner, before anything else can join: a second run of the app waits until it has settled, so whatever it sets up (`onMessage`, a tray) is there before another UIHost can reach it. If it throws, `create` does, and leaves the host.
16
+ - `openWindow(params)`, `openDialog(params)`, `openCard(params)` and `openForm(params)` open a window, a message box, an [Adaptive Card](https://adaptivecards.io) or a JSON Schema form; `createTray(params)` creates a tray icon (an empty `icon` uses the runtime's own) and `showNotification(params)` an OS notification. Each resolves to a remote handle once the host has. A handle's `closed` settles with the value it ends with — a window's resolve or the redirect it caught, the dialog's chosen button (and its checkbox, if it has one), a card's `Action.Submit` (`{ action, inputs }`), a form's data — or nothing if it was closed by hand; `close(value?)` ends it, and `focus()` brings its window to the front (restoring it if it's minimized). Anything can be opened from another handle (`handle.openWindow(...)`, ...) to open in front of it. A tray reports clicks, and a card each `Action.Execute`, through `onEvent`; `update(...)` changes either.
17
17
  - How a window, card or form looks goes in `window: { width?, height?, title? }`. Cards and forms fit their window's height to what they show unless a height is given.
18
- - A window's **backend** is an accept function — `protocol.accept(configure)` from [`@cmdless/rpc-sdk`](../rpc-sdk), or a host's own `accept` to share one (and its store) across windows. Its page calls `connect(protocol, configure?)` from `/browser`, and talks to this process directly: the host only introduces them, with a token for one connection that stays in the window's preload. Each page load is a new connection.
19
- - `UIHost.showWindow`, `showDialog`, `showCard`, `showForm`, `showElicitation` and `showPermission` are the one-shot forms: start or join a host, show one thing, and hand back what it ended with.
18
+ - A window's **backend** (`params.backend`) is an accept function — `protocol.accept(configure)` from [`@cmdless/rpc-sdk`](../rpc-sdk), or a host's own `accept` to share one (and its store) across windows. Its page calls `connect(protocol, configure?)` from `/browser`, and talks to this process directly: the host only introduces them, with a token for one connection that stays in the window's preload. The UIHost keeps it under a key of its own, made before the window opens, and drops it when the window ends. A page's first `connect` takes the connection started as it loaded, and any after it (a component mounted again, say) get their own; a page whose window has no backend sees `window.cmdless.backend` unset, and `connect` fails at once rather than waiting.
19
+ - **Factories** package something to open with its own typed params — a window and the backend serving it, say: `const logViewer = UIHost.factory(async (opener, params: { file: string }) => opener.openWindow({ ... }))`. `host.open(logViewer, params)` opens it on its own, `handle.open(logViewer, params)` in front of that handle, and `UIHost.show(logViewer, params, options?)` as a one-shot. The opener (`UIOpener`) is a host or a handle: either opens windows, dialogs, cards and forms, and `.host` reaches the host itself.
20
+ - `UIHost.showWindow`, `showDialog`, `showCard`, `showForm`, `showElicitation` and `showPermission` are the one-shot forms: start or join a host, show one thing, and hand back what it ended with. Each takes the params first and the host options (`{ app, cmdlessRoot, timeoutMs }`) last, optionally.
21
+ - **Between UIHosts of one app:** each connection has an id (`connectionId`), and `params.hasSingleInstanceLock` says whether it's the owner. `connections()` lists every UIHost connected to the host, with which one is the owner. `send(message, to?)` hands a message (anything JSON carries) to another of them through the host: to the owner unless `to` names a connection. It settles once the host has passed it on, and fails for a connection that isn't there. `onMessage(({ from, message }) => ...)` hears them. So a second run of an app can pass what it was asked to the one that's running, `send({ ... })`, then leave.
20
22
  - `dispose()` leaves the host; for its owner (the one whose creator started it), that ends it.
21
23
  - `getCmdlessApp`/`setCmdlessApp`, `setCmdlessUrl`/`acquireCmdlessUrl` — accessors for cmdless's environment, so callers never read `process.env` themselves. Each setter writes to this process's env, or to an env object passed in for a child about to be spawned. A dev-mode Vite plugin (see `apps/hangar-ui`'s `vite.config.ts`) can publish its dev server's URL with `setCmdlessUrl(url, env)` before spawning a consumer's bin, for the bin to show instead of its built renderer.
24
+ - An app name is a package name's shape (`@scope/name`, in lowercase letters, digits and `. _ ~ -`): `getCmdlessApp` and `setCmdlessApp` refuse anything else, since it names `userData`, the app's bundles and its lock. A throwaway app's name is the prefix and a UUID, exactly.
25
+ - `LaunchHost` — a connection to [`@cmdless/launch-tray`](../../apps/launch-tray), which keeps and runs launches. `LaunchHost.create({ cmdlessRoot? })` connects to the running tray, or starts one — the newest version already in the cmdless root's cache, or the latest from npm when there's none; nothing updates what's cached. `add(launch)` keeps one (`added`, `replaced`, `unchanged`); `open(launch, { command?, keep? })` runs one — `command` naming which of its command lists, asked for if it has several and none's given — and keeps it too with `keep` (`opened`, or `cancelled` if the choice or a source's trust was turned down). `LaunchHost.add` and `LaunchHost.open` are the one-shots. The launch type (`Launch`, `LaunchSource`, `LaunchCommand`), its checks and helpers (`validLaunch`, `parseLaunch`, `commandNames`, `commandsFor`, `sourceKey`, `describeSource`) and `launchProtocol` are in `@cmdless/ui-sdk`.
26
+ - `resolveRuntimeBin(cmdlessRoot?)` — ui-runtime's bin at the version this package speaks: the local install when it's that version, or else that version from the cmdless root's cache.
22
27
  - The ephemeral-app helpers (`getEphemeralPrefix`, `isEphemeralCmdlessApp`, `isEphemeralUserData`), and the few [`@cmdless/core`](../core) helpers the host and `@cmdless/ui` use.
23
28
 
24
29
  - **`@cmdless/ui-sdk/browser`** — renderer only: the `window.cmdless` type, and `connect(protocol, configure?)`, which connects a window's page to the backend it was opened with. `configure` sets handlers up before it listens, so nothing the backend sends at once is missed.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE1D,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;AAMvC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF;AAOD,wBAAsB,OAAO,CAAC,CAAC,SAAS,cAAc,EACpD,QAAQ,EAAE,CAAC,EACX,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,GACzC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAatB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE1D,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;AAMvC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF;AAaD,wBAAsB,OAAO,CAAC,CAAC,SAAS,cAAc,EACpD,QAAQ,EAAE,CAAC,EACX,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,GACzC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAgBtB"}
@@ -4,10 +4,20 @@ import { createSocketConnection } from '@cmdless/rpc-sdk/ws';
4
4
  // sets up handlers before the connection listens, so nothing the backend
5
5
  // sends right away is missed. A protocol with a name and version can be held
6
6
  // to them with checkVersion() once connected.
7
+ //
8
+ // The first connect() picks up the connection started as the page loaded;
9
+ // any after it (a component mounted again, say) get one of their own. A
10
+ // window opened without a backend fails at once rather than waiting: check
11
+ // window.cmdless.backend first to tell beforehand.
12
+ let claimed = false;
7
13
  export async function connect(protocol, configure) {
8
14
  if (!window.cmdless)
9
15
  throw new Error('not in a cmdless window');
10
- const socket = await window.cmdless.connect();
16
+ if (!window.cmdless.backend)
17
+ throw new Error('this window was opened without a backend');
18
+ const first = !claimed;
19
+ claimed = true;
20
+ const socket = await (first ? window.cmdless.backend : window.cmdless.connect());
11
21
  const backend = protocol.createClient(createSocketConnection({
12
22
  send: message => socket.send(message),
13
23
  onMessage: listener => socket.onMessage(listener),
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB7D,yEAAyE;AACzE,8EAA8E;AAC9E,yEAAyE;AACzE,6EAA6E;AAC7E,8CAA8C;AAC9C,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,QAAW,EACX,SAA0C;IAE1C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,YAAY,CAAC,sBAAsB,CAAC;QAC3D,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACrC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;QACjD,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC;QAClB,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC7C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;KAC9B,CAAC,CAAgB,CAAC;IACnB,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,MAAM,EAAE,CAAC;IACjB,OAAO,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB7D,yEAAyE;AACzE,8EAA8E;AAC9E,yEAAyE;AACzE,6EAA6E;AAC7E,8CAA8C;AAC9C,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,2EAA2E;AAC3E,mDAAmD;AACnD,IAAI,OAAO,GAAG,KAAK,CAAC;AACpB,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,QAAW,EACX,SAA0C;IAE1C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAChE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACzF,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC;IACvB,OAAO,GAAG,IAAI,CAAC;IACf,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACjF,MAAM,OAAO,GAAG,QAAQ,CAAC,YAAY,CAAC,sBAAsB,CAAC;QAC3D,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACrC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;QACjD,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC;QAClB,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC7C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;KAC9B,CAAC,CAAgB,CAAC;IACnB,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,MAAM,EAAE,CAAC;IACjB,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { AdaptiveCard, CardEvent, CardView, FormView } from './types.js';
2
2
  export * as types from './types.js';
3
3
  export * from './prompts.js';
4
+ export * from './launch.js';
4
5
  type ResolveParams<T = unknown> = {
5
6
  value: T;
6
7
  exitCode?: number;
@@ -47,8 +48,10 @@ export type CmdlessSocket = {
47
48
  onClose(listener: (code: number, reason: string) => void): void;
48
49
  close(): void;
49
50
  };
51
+ export declare const BACKEND_ARG = "--cmdless-backend";
50
52
  export type Cmdless = {
51
53
  resolve(value: unknown, exitCode?: number): void;
54
+ backend?: Promise<CmdlessSocket>;
52
55
  connect(): Promise<CmdlessSocket>;
53
56
  view: ReturnType<typeof cmdlessViewIPC.createClient>;
54
57
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE9E,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,cAAc,CAAC;AAE7B,KAAK,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IAChC,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,MAAM,MAAM,kBAAkB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAIhE,eAAO,MAAM,UAAU;;;;;;EASpB,CAAC;AAEJ,eAAO,MAAM,iBAAiB,sGAAgC,CAAC;AAG/D,MAAM,MAAM,SAAS,GAAG,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,QAAQ,CAAC,GAAG,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,QAAQ,CAAC,CAAC;AAKtF,eAAO,MAAM,cAAc;;;;;;oBAOS,OAAO;;;oBACN,MAAM;;;;;kBAKR,YAAY;;;EAG5C,CAAC;AAEJ,eAAO,MAAM,qBAAqB,sGAAiC,CAAC;AAIpE,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,OAAO,EAAE,M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,CAAC;AAKtF,eAAO,MAAM,cAAc;;;;;;oBAOS,OAAO;;;oBACN,MAAM;;;;;kBAKR,YAAY;;;EAG5C,CAAC;AAEJ,eAAO,MAAM,qBAAqB,sGAAiC,CAAC;AAIpE,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IACrD,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IAChE,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAGF,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAG/C,MAAM,MAAM,OAAO,GAAG;IAEpB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAIjD,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAEjC,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IAClC,IAAI,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,YAAY,CAAC,CAAC;CACtD,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { defineProtocol, forElectronIPC } from '@cmdless/rpc-sdk';
2
2
  export * as types from './types.js';
3
3
  export * from './prompts.js';
4
+ export * from './launch.js';
4
5
  // what a window's preload can say to the host: resolve the window with a
5
6
  // value, and ask for its backend
6
7
  export const cmdlessIPC = defineProtocol(({ side, request, notification }) => ({
@@ -35,4 +36,6 @@ export const cmdlessViewIPC = defineProtocol(({ side, request, notification }) =
35
36
  }),
36
37
  }));
37
38
  export const createElectronViewIPC = forElectronIPC('cmdless:view');
39
+ // what tells a window's preload, at start, that its window has a backend
40
+ export const BACKEND_ARG = '--cmdless-backend';
38
41
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,cAAc,CAAC;AAW7B,yEAAyE;AACzE,iCAAiC;AACjC,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7E,cAAc,EAAE,IAAI,CAAC;QACnB,QAAQ,EAAE;YACR,OAAO,EAAE,OAAO,CAA2B,SAAS,CAAC;SACtD;QACD,aAAa,EAAE;YACb,OAAO,EAAE,YAAY,CAAgB,SAAS,CAAC;SAChD;KACF,CAAC;CACH,CAAC,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;AAK/D,0EAA0E;AAC1E,uEAAuE;AACvE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;IACjF,cAAc,EAAE,IAAI,CAAC;QACnB,QAAQ,EAAE;YACR,KAAK,EAAE,OAAO,CAAkB,YAAY,CAAC;SAC9C;QACD,aAAa,EAAE;YACb,KAAK,EAAE,YAAY,CAAY,YAAY,CAAC;YAC5C,KAAK,EAAE,YAAY,CAAsB,YAAY,CAAC;YACtD,MAAM,EAAE,YAAY,CAAqB,aAAa,CAAC;SACxD;KACF,CAAC;IACF,cAAc,EAAE,IAAI,CAAC;QACnB,aAAa,EAAE;YACb,MAAM,EAAE,YAAY,CAAyB,aAAa,CAAC;SAC5D;KACF,CAAC;CACH,CAAC,CAAC,CAAC;AAEJ,MAAM,CAAC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C,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;AAWpE,yEAAyE;AACzE,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC"}
@@ -0,0 +1,51 @@
1
+ export type LaunchSource = {
2
+ type: 'npm';
3
+ package: string;
4
+ version?: string;
5
+ } | {
6
+ type: 'git';
7
+ repo: string;
8
+ ref?: string;
9
+ workspace?: string;
10
+ build?: string[];
11
+ } | {
12
+ type: 'local';
13
+ path: string;
14
+ };
15
+ export type LaunchCommand = {
16
+ source: string;
17
+ bin?: string;
18
+ args: string[];
19
+ };
20
+ export type Launch = {
21
+ name: string;
22
+ sources: Record<string, LaunchSource>;
23
+ commands: LaunchCommand[] | Record<string, LaunchCommand[]>;
24
+ };
25
+ export declare function validLaunch(data: unknown): Launch;
26
+ export declare function parseLaunch(text: string): Launch;
27
+ export declare const sameLaunch: (a: Launch, b: Launch) => boolean;
28
+ export declare const commandNames: (launch: Launch) => string[] | undefined;
29
+ export declare function commandsFor(launch: Launch, command?: string): LaunchCommand[];
30
+ export declare function repoKey(repo: string): string;
31
+ export declare function sourceKey(source: LaunchSource): string;
32
+ export declare function describeSource(source: LaunchSource): string;
33
+ export type AddResult = 'added' | 'replaced' | 'unchanged';
34
+ export type OpenResult = 'opened' | 'cancelled';
35
+ export type OpenOptions = {
36
+ command?: string;
37
+ keep?: boolean;
38
+ };
39
+ export declare const launchProtocol: import("@cmdless/rpc-sdk").Protocol<{
40
+ readonly name: "launch";
41
+ readonly version: 2;
42
+ readonly clientToServer: import("@cmdless/rpc-sdk").RpcSide<NoInfer<{
43
+ add: import("@cmdless/rpc-sdk").RpcRequest<{
44
+ launch: Launch;
45
+ }, AddResult>;
46
+ open: import("@cmdless/rpc-sdk").RpcRequest<{
47
+ launch: Launch;
48
+ } & OpenOptions, OpenResult>;
49
+ }>, {}>;
50
+ }>;
51
+ //# sourceMappingURL=launch.d.ts.map
@@ -0,0 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AAS,CAAC,MAAM,EAAE,YAAY,UAM7C;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,UAMlD;AAID,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,WAAW,CAAC;AAI3D,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC;AAIhD,MAAM,MAAM,WAAW,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAG/D,eAAO,MAAM,cAAc;;;;;oBAOE,MAAM;;;oBAIL,MAAM;;;EAGjC,CAAC"}
package/dist/launch.js ADDED
@@ -0,0 +1,152 @@
1
+ import { defineProtocol } from '@cmdless/rpc-sdk';
2
+ const isStrings = (value) => Array.isArray(value) && value.every(each => typeof each === 'string');
3
+ const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
4
+ const text = (value, what) => {
5
+ if (typeof value !== 'string' || !value.trim())
6
+ throw new Error(`${what} is missing`);
7
+ return value.trim();
8
+ };
9
+ const optional = (value, what) => value === undefined ? undefined : text(value, what);
10
+ function validSource(name, data) {
11
+ if (!isObject(data))
12
+ throw new Error(`source ${name} isn't an object`);
13
+ const what = (field) => `source ${name}'s ${field}`;
14
+ switch (data.type) {
15
+ case 'npm': {
16
+ const version = optional(data.version, what('version'));
17
+ return { type: 'npm', package: text(data.package, what('package')), ...version !== undefined && { version } };
18
+ }
19
+ case 'git': {
20
+ const ref = optional(data.ref, what('ref'));
21
+ const workspace = optional(data.workspace, what('workspace'));
22
+ if (data.build !== undefined && !isStrings(data.build))
23
+ throw new Error(`${what('build')} isn't a list of scripts`);
24
+ return {
25
+ type: 'git', repo: text(data.repo, what('repo')),
26
+ ...ref !== undefined && { ref }, ...workspace !== undefined && { workspace },
27
+ ...data.build !== undefined && { build: data.build },
28
+ };
29
+ }
30
+ case 'local':
31
+ return { type: 'local', path: text(data.path, what('path')) };
32
+ default:
33
+ throw new Error(`source ${name} is npm, git or local`);
34
+ }
35
+ }
36
+ function validCommands(data, sources, where) {
37
+ if (!Array.isArray(data) || data.length === 0)
38
+ throw new Error(`${where} has no commands`);
39
+ return data.map((each, i) => {
40
+ const at = `${where}'s command ${i + 1}`;
41
+ if (!isObject(each))
42
+ throw new Error(`${at} isn't an object`);
43
+ const source = text(each.source, `${at}'s source`);
44
+ if (!(source in sources))
45
+ throw new Error(`${at} uses source ${source}, which isn't in sources`);
46
+ const bin = optional(each.bin, `${at}'s bin`);
47
+ const args = each.args ?? [];
48
+ if (!isStrings(args))
49
+ throw new Error(`${at}'s args aren't all strings`);
50
+ return { source, ...bin !== undefined && { bin }, args };
51
+ });
52
+ }
53
+ // a launch, checked - from parsed JSON, or whatever a client sent - throws
54
+ // saying what's wrong
55
+ export function validLaunch(data) {
56
+ if (!isObject(data))
57
+ throw new Error('a launch is a JSON object');
58
+ const name = text(data.name, 'the launch\'s name');
59
+ if (!isObject(data.sources))
60
+ throw new Error('the launch has no sources');
61
+ const sources = Object.fromEntries(Object.entries(data.sources).map(([key, source]) => [key, validSource(key, source)]));
62
+ let commands;
63
+ if (Array.isArray(data.commands))
64
+ commands = validCommands(data.commands, sources, 'the launch');
65
+ else if (isObject(data.commands) && Object.keys(data.commands).length) {
66
+ commands = Object.fromEntries(Object.entries(data.commands).map(([key, list]) => {
67
+ if (!key.trim())
68
+ throw new Error('a command list has no name');
69
+ return [key, validCommands(list, sources, `commands ${key}`)];
70
+ }));
71
+ }
72
+ else
73
+ throw new Error('the launch has no commands');
74
+ const used = new Set((Array.isArray(commands) ? commands : Object.values(commands).flat()).map(command => command.source));
75
+ const unused = Object.keys(sources).filter(key => !used.has(key));
76
+ if (unused.length)
77
+ throw new Error(`no command uses source${unused.length > 1 ? 's' : ''} ${unused.join(', ')}`);
78
+ return { name, sources, commands };
79
+ }
80
+ // a .cmdless file's text, as a launch
81
+ export function parseLaunch(text) {
82
+ let data;
83
+ try {
84
+ data = JSON.parse(text);
85
+ }
86
+ catch (error) {
87
+ throw new Error(`it isn't JSON: ${error.message}`);
88
+ }
89
+ return validLaunch(data);
90
+ }
91
+ // whether two launches say exactly the same
92
+ export const sameLaunch = (a, b) => JSON.stringify(a) === JSON.stringify(b);
93
+ // the names of a launch's command lists - none, for one list
94
+ export const commandNames = (launch) => Array.isArray(launch.commands) ? undefined : Object.keys(launch.commands);
95
+ // the commands to run: the launch's one list, or the one named - which a
96
+ // launch with named lists needs, and one without can't take
97
+ export function commandsFor(launch, command) {
98
+ if (Array.isArray(launch.commands)) {
99
+ if (command !== undefined)
100
+ throw new Error(`${launch.name} has no named commands, so not ${command}`);
101
+ return launch.commands;
102
+ }
103
+ if (command === undefined)
104
+ throw new Error(`${launch.name} needs one of ${Object.keys(launch.commands).join(', ')}`);
105
+ const commands = launch.commands[command];
106
+ if (!commands)
107
+ throw new Error(`${launch.name} has no commands ${command} - there's ${Object.keys(launch.commands).join(', ')}`);
108
+ return commands;
109
+ }
110
+ // a GitHub repo however it's written - github:owner/repo, owner/repo, its
111
+ // https or ssh URL - as github:owner/repo; any other URL as it is, less a
112
+ // git+ prefix and .git suffix
113
+ export function repoKey(repo) {
114
+ const bare = repo.trim().replace(/#.*$/, '');
115
+ const github = /^(?:github:|(?:git\+)?(?:https?|ssh):\/\/(?:git@)?github\.com\/|git@github\.com:)?([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/i.exec(bare);
116
+ return github ? `github:${github[1]}/${github[2]}`.toLowerCase() : bare.replace(/^git\+/, '').replace(/\.git\/?$/, '');
117
+ }
118
+ // what trusting a source trusts: an npm package by name, any version; a
119
+ // repo, any ref; a folder - so the same source named differently, or at
120
+ // another version or ref, is the same trust
121
+ export function sourceKey(source) {
122
+ switch (source.type) {
123
+ case 'npm': return `npm:${source.package}`;
124
+ case 'git': return `git:${repoKey(source.repo)}`;
125
+ case 'local': return `local:${source.path}`;
126
+ }
127
+ }
128
+ // a source as it reads, to someone asked to trust it
129
+ export function describeSource(source) {
130
+ switch (source.type) {
131
+ case 'npm': return `${source.package} from npm`;
132
+ case 'git': return `${source.workspace ? `${source.workspace} in ` : ''}${repoKey(source.repo)}`;
133
+ case 'local': return `the package at ${source.path}`;
134
+ }
135
+ }
136
+ // what @cmdless/launch-tray serves: one tray per user, on a socket
137
+ export const launchProtocol = defineProtocol(({ side, request }) => ({
138
+ // bump only for a change that breaks clients - adding things doesn't
139
+ name: 'launch',
140
+ version: 2,
141
+ clientToServer: side({
142
+ requests: {
143
+ // keeps a launch, under Launch in the tray
144
+ add: request('launch/add'),
145
+ // runs a launch, asking which commands if it has several and none is
146
+ // given, and to trust any source it uses that isn't - settling once
147
+ // it's running, not once it's done
148
+ open: request('launch/open'),
149
+ },
150
+ }),
151
+ }));
152
+ //# sourceMappingURL=launch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launch.js","sourceRoot":"","sources":["../src/launch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA6BlD,MAAM,SAAS,GAAG,CAAC,KAAc,EAAqB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC;AAC/H,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACrI,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,IAAY,EAAE,EAAE;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,aAAa,CAAC,CAAC;IACtF,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC,CAAC;AACF,MAAM,QAAQ,G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K,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC;QAChD,KAAK,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,SAAS,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACjG,KAAK,OAAO,EAAE,OAAO,kBAAkB,MAAM,CAAC,IAAI,EAAE,CAAC;IACvD,CAAC;AACH,CAAC;AAcD,mEAAmE;AACnE,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IACnE,qEAAqE;IACrE,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,CAAC;IACV,cAAc,EAAE,IAAI,CAAC;QACnB,QAAQ,EAAE;YACR,2CAA2C;YAC3C,GAAG,EAAE,OAAO,CAAgC,YAAY,CAAC;YACzD,qEAAqE;YACrE,oEAAoE;YACpE,mCAAmC;YACnC,IAAI,EAAE,OAAO,CAA+C,aAAa,CAAC;SAC3E;KACF,CAAC;CACH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=launch.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launch.test.d.ts","sourceRoot":"","sources":["../src/launch.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { commandNames, commandsFor, parseLaunch, repoKey, sourceKey, validLaunch } from './launch.js';
4
+ const app = { type: 'npm', package: '@x/app' };
5
+ test('a launch is its sources and commands that use them, checked', () => {
6
+ assert.deepEqual(parseLaunch(JSON.stringify({ name: ' x ', sources: { app }, commands: [{ source: 'app' }] })), { name: 'x', sources: { app: { type: 'npm', package: '@x/app' } }, commands: [{ source: 'app', args: [] }] });
7
+ assert.throws(() => parseLaunch('nope'), /isn't JSON/);
8
+ assert.throws(() => validLaunch({ name: 'x', sources: { app }, commands: [] }), /no commands/);
9
+ assert.throws(() => validLaunch({ name: 'x', sources: { app }, commands: [{ source: 'other' }] }), /isn't in sources/);
10
+ assert.throws(() => validLaunch({ name: 'x', sources: { app, spare: app }, commands: [{ source: 'app' }] }), /no command uses source spare/);
11
+ assert.throws(() => validLaunch({ name: 'x', sources: { app: { type: 'ftp' } }, commands: [{ source: 'app' }] }), /npm, git or local/);
12
+ assert.throws(() => validLaunch({ name: 'x', sources: { app: { type: 'git' } }, commands: [{ source: 'app' }] }), /repo is missing/);
13
+ assert.throws(() => validLaunch({ name: 'x', sources: { app }, commands: [{ source: 'app', args: [1] }] }), /aren't all strings/);
14
+ });
15
+ test('named command lists are choices, and one is needed', () => {
16
+ const launch = validLaunch({ name: 'x', sources: { app }, commands: { prod: [{ source: 'app' }], dev: [{ source: 'app', args: ['--dev'] }] } });
17
+ assert.deepEqual(commandNames(launch), ['prod', 'dev']);
18
+ assert.deepEqual(commandsFor(launch, 'dev'), [{ source: 'app', args: ['--dev'] }]);
19
+ assert.throws(() => commandsFor(launch), /needs one of prod, dev/);
20
+ assert.throws(() => commandsFor(launch, 'qa'), /no commands qa/);
21
+ const single = validLaunch({ name: 'y', sources: { app }, commands: [{ source: 'app' }] });
22
+ assert.equal(commandNames(single), undefined);
23
+ assert.throws(() => commandsFor(single, 'prod'), /no named commands/);
24
+ });
25
+ test('trust is the package, the repo however it\'s written, or the folder', () => {
26
+ for (const repo of ['github:Owner/Repo', 'owner/repo', 'https://github.com/owner/repo.git', 'git+https://github.com/owner/repo', 'git@github.com:owner/repo.git', 'github:owner/repo#dev'])
27
+ assert.equal(repoKey(repo), 'github:owner/repo', repo);
28
+ assert.equal(sourceKey({ type: 'npm', package: '@x/app', version: '1.0.0' }), 'npm:@x/app');
29
+ assert.equal(sourceKey({ type: 'git', repo: 'owner/repo', ref: 'v2' }), 'git:github:owner/repo');
30
+ assert.equal(sourceKey({ type: 'local', path: '/a/b' }), 'local:/a/b');
31
+ });
32
+ //# sourceMappingURL=launch.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launch.test.js","sourceRoot":"","sources":["../src/launch.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtG,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAE/C,IAAI,CAAC,6DAA6D,EAAE,GAAG,EAAE;IACvE,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5G,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAChH,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC;IACvD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;IAC/F,MAAM,CAAC,MAAM,CAAC,GAAG,EA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G,EAAE;IAC/E,KAAK,MAAM,IAAI,IAAI,CAAC,mBAAmB,EAAE,YAAY,EAAE,mCAAmC,EAAE,mCAAmC,EAAE,+BAA+B,EAAE,uBAAuB,CAAC;QACxL,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAC;IACzD,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC;IAC5F,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,uBAAuB,CAAC,CAAC;IACjG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC;AACzE,CAAC,CAAC,CAAC"}
@@ -13,6 +13,7 @@ export type InitializeResult = {
13
13
  ephemeral: boolean;
14
14
  sdkVersion: string;
15
15
  hasSingleInstanceLock: boolean;
16
+ connectionId: string;
16
17
  };
17
18
  export type WindowOptions = {
18
19
  width?: number;
@@ -26,6 +27,10 @@ export type WindowParams = {
26
27
  external?: boolean;
27
28
  window?: WindowOptions;
28
29
  parent?: string;
30
+ backend?: WindowBackend;
31
+ };
32
+ export type WindowOpenParams = Omit<WindowParams, 'backend'> & {
33
+ backend?: string;
29
34
  };
30
35
  export type DialogParams = {
31
36
  type: MessageBoxType;
@@ -34,6 +39,8 @@ export type DialogParams = {
34
39
  buttons?: string[];
35
40
  defaultId?: number;
36
41
  cancelId?: number;
42
+ checkboxLabel?: string;
43
+ checkboxChecked?: boolean;
37
44
  parent?: string;
38
45
  };
39
46
  export type DialogResult = {
@@ -87,7 +94,9 @@ export type ClipboardWriteParams = {
87
94
  export type HandleParams = {
88
95
  id: string;
89
96
  };
90
- export type WindowConnectParams = HandleParams;
97
+ export type WindowConnectParams = {
98
+ backend: string;
99
+ };
91
100
  export type WindowConnectResult = {
92
101
  url: string;
93
102
  token: string;
@@ -99,27 +108,44 @@ export type HandleClosedParams = HandleParams & {
99
108
  value?: unknown;
100
109
  error?: string;
101
110
  };
111
+ export type ConnectionInfo = {
112
+ id: string;
113
+ owner: boolean;
114
+ };
115
+ export type SendParams = {
116
+ to?: string;
117
+ message: unknown;
118
+ };
119
+ export type ConnectionMessage = {
120
+ from: string;
121
+ message: unknown;
122
+ };
102
123
  declare const uiHostProtocol: import("@cmdless/rpc-sdk").Protocol<{
103
124
  readonly clientToServer: import("@cmdless/rpc-sdk").RpcSide<NoInfer<{
104
125
  init: import("@cmdless/rpc-sdk").RpcRequest<InitializeParams, InitializeResult>;
105
- windowOpen: import("@cmdless/rpc-sdk").RpcRequest<WindowParams, HandleParams>;
126
+ windowOpen: import("@cmdless/rpc-sdk").RpcRequest<WindowOpenParams, HandleParams>;
106
127
  dialogOpen: import("@cmdless/rpc-sdk").RpcRequest<DialogParams, HandleParams>;
107
128
  trayCreate: import("@cmdless/rpc-sdk").RpcRequest<TrayParams, HandleParams>;
108
129
  trayUpdate: import("@cmdless/rpc-sdk").RpcRequest<TrayUpdateParams, void>;
109
130
  handleClose: import("@cmdless/rpc-sdk").RpcRequest<HandleCloseParams, void>;
131
+ handleFocus: import("@cmdless/rpc-sdk").RpcRequest<HandleParams, void>;
110
132
  shellOpenExternal: import("@cmdless/rpc-sdk").RpcRequest<OpenExternalParams, void>;
111
133
  clipboardWriteText: import("@cmdless/rpc-sdk").RpcRequest<ClipboardWriteParams, void>;
112
134
  notificationShow: import("@cmdless/rpc-sdk").RpcRequest<NotificationParams, HandleParams>;
113
135
  cardOpen: import("@cmdless/rpc-sdk").RpcRequest<CardParams, HandleParams>;
114
136
  cardUpdate: import("@cmdless/rpc-sdk").RpcRequest<CardUpdateParams, void>;
115
137
  formOpen: import("@cmdless/rpc-sdk").RpcRequest<FormParams, HandleParams>;
138
+ connections: import("@cmdless/rpc-sdk").RpcRequest<void, ConnectionInfo[]>;
139
+ connectionSend: import("@cmdless/rpc-sdk").RpcRequest<SendParams, void>;
140
+ ready: import("@cmdless/rpc-sdk").RpcRequest<void, void>;
116
141
  }>, {}>;
117
142
  readonly serverToClient: import("@cmdless/rpc-sdk").RpcSide<NoInfer<{
118
- windowConnect: import("@cmdless/rpc-sdk").RpcRequest<HandleParams, WindowConnectResult>;
143
+ windowConnect: import("@cmdless/rpc-sdk").RpcRequest<WindowConnectParams, WindowConnectResult>;
119
144
  }>, NoInfer<{
120
145
  handleClosed: import("@cmdless/rpc-sdk").RpcNotification<HandleClosedParams>;
121
146
  trayEvent: import("@cmdless/rpc-sdk").RpcNotification<HandleParams & TrayEvent>;
122
147
  cardEvent: import("@cmdless/rpc-sdk").RpcNotification<HandleParams & CardEvent>;
148
+ connectionMessage: import("@cmdless/rpc-sdk").RpcNotification<ConnectionMessage>;
123
149
  }>>;
124
150
  }>;
125
151
  export type UIServer = ReturnType<typeof UIHost.protocol.createServer>;
@@ -128,22 +154,34 @@ export type CreateHostOptions = {
128
154
  app?: string;
129
155
  cmdlessRoot?: string;
130
156
  timeoutMs?: number;
157
+ initialize?: (host: UIHost) => void | Promise<void>;
131
158
  };
132
159
  export type WindowBackend = (connection: Parameters<RpcProtocol['createServer']>[0]) => {
133
160
  listen(): void;
134
161
  };
135
162
  declare const end: unique symbol;
136
- export declare abstract class RemoteHandle<T = unknown> {
163
+ export interface UIOpener {
164
+ readonly host: UIHost;
165
+ openWindow<W = unknown>(params: Omit<WindowParams, 'parent'>): Promise<RemoteWindow<W>>;
166
+ openDialog(params: Omit<DialogParams, 'parent'>): Promise<RemoteDialog>;
167
+ openCard(params: Omit<CardParams, 'parent'>): Promise<RemoteCard>;
168
+ openForm<F = unknown>(params: Omit<FormParams, 'parent'>): Promise<RemoteForm<F>>;
169
+ open<P, H extends RemoteHandle<any>>(factory: UIFactory<P, H>, params: P): Promise<H>;
170
+ }
171
+ export type UIFactory<P, H extends RemoteHandle<any>> = (opener: UIOpener, params: P) => Promise<H>;
172
+ export declare abstract class RemoteHandle<T = unknown> implements UIOpener {
137
173
  readonly host: UIHost;
138
174
  readonly id: string;
139
175
  readonly closed: Promise<T>;
140
176
  private settle;
141
177
  constructor(host: UIHost, id: string);
142
178
  close(value?: T): Promise<void>;
143
- openWindow<W = unknown>(params: Omit<WindowParams, 'parent'>, backend?: WindowBackend): Promise<RemoteWindow<W>>;
179
+ focus(): Promise<void>;
180
+ openWindow<W = unknown>(params: Omit<WindowParams, 'parent'>): Promise<RemoteWindow<W>>;
144
181
  openDialog(params: Omit<DialogParams, 'parent'>): Promise<RemoteDialog>;
145
182
  openCard(params: Omit<CardParams, 'parent'>): Promise<RemoteCard>;
146
183
  openForm<F = unknown>(params: Omit<FormParams, 'parent'>): Promise<RemoteForm<F>>;
184
+ open<P, H extends RemoteHandle<any>>(factory: UIFactory<P, H>, params: P): Promise<H>;
147
185
  [end]({ value, error }: Omit<HandleClosedParams, 'id'>): void;
148
186
  }
149
187
  export declare class RemoteWindow<T = unknown> extends RemoteHandle<T> {
@@ -181,58 +219,73 @@ export declare class UIClipboardHandler {
181
219
  constructor(host: UIHost);
182
220
  writeText(text: string): Promise<void>;
183
221
  }
184
- export declare class UIHost {
222
+ export declare class UIHost implements UIOpener {
185
223
  readonly client: UIClient;
186
224
  readonly params: InitializeResult;
187
225
  static readonly protocol: import("@cmdless/rpc-sdk").Protocol<{
188
226
  readonly clientToServer: import("@cmdless/rpc-sdk").RpcSide<NoInfer<{
189
227
  init: import("@cmdless/rpc-sdk").RpcRequest<InitializeParams, InitializeResult>;
190
- windowOpen: import("@cmdless/rpc-sdk").RpcRequest<WindowParams, HandleParams>;
228
+ windowOpen: import("@cmdless/rpc-sdk").RpcRequest<WindowOpenParams, HandleParams>;
191
229
  dialogOpen: import("@cmdless/rpc-sdk").RpcRequest<DialogParams, HandleParams>;
192
230
  trayCreate: import("@cmdless/rpc-sdk").RpcRequest<TrayParams, HandleParams>;
193
231
  trayUpdate: import("@cmdless/rpc-sdk").RpcRequest<TrayUpdateParams, void>;
194
232
  handleClose: import("@cmdless/rpc-sdk").RpcRequest<HandleCloseParams, void>;
233
+ handleFocus: import("@cmdless/rpc-sdk").RpcRequest<HandleParams, void>;
195
234
  shellOpenExternal: import("@cmdless/rpc-sdk").RpcRequest<OpenExternalParams, void>;
196
235
  clipboardWriteText: import("@cmdless/rpc-sdk").RpcRequest<ClipboardWriteParams, void>;
197
236
  notificationShow: import("@cmdless/rpc-sdk").RpcRequest<NotificationParams, HandleParams>;
198
237
  cardOpen: import("@cmdless/rpc-sdk").RpcRequest<CardParams, HandleParams>;
199
238
  cardUpdate: import("@cmdless/rpc-sdk").RpcRequest<CardUpdateParams, void>;
200
239
  formOpen: import("@cmdless/rpc-sdk").RpcRequest<FormParams, HandleParams>;
240
+ connections: import("@cmdless/rpc-sdk").RpcRequest<void, ConnectionInfo[]>;
241
+ connectionSend: import("@cmdless/rpc-sdk").RpcRequest<SendParams, void>;
242
+ ready: import("@cmdless/rpc-sdk").RpcRequest<void, void>;
201
243
  }>, {}>;
202
244
  readonly serverToClient: import("@cmdless/rpc-sdk").RpcSide<NoInfer<{
203
- windowConnect: import("@cmdless/rpc-sdk").RpcRequest<HandleParams, WindowConnectResult>;
245
+ windowConnect: import("@cmdless/rpc-sdk").RpcRequest<WindowConnectParams, WindowConnectResult>;
204
246
  }>, NoInfer<{
205
247
  handleClosed: import("@cmdless/rpc-sdk").RpcNotification<HandleClosedParams>;
206
248
  trayEvent: import("@cmdless/rpc-sdk").RpcNotification<HandleParams & TrayEvent>;
207
249
  cardEvent: import("@cmdless/rpc-sdk").RpcNotification<HandleParams & CardEvent>;
250
+ connectionMessage: import("@cmdless/rpc-sdk").RpcNotification<ConnectionMessage>;
208
251
  }>>;
209
252
  }>;
253
+ static factory<P, H extends RemoteHandle<any>>(factory: UIFactory<P, H>): UIFactory<P, H>;
254
+ get host(): this;
210
255
  readonly shell: UIShellHandler;
211
256
  readonly clipboard: UIClipboardHandler;
257
+ private readonly messageListeners;
212
258
  private readonly remotes;
213
259
  private readonly unclaimed;
214
260
  private readonly backends;
215
- private readonly opening;
216
261
  private readonly tokens;
217
262
  private backendServer?;
218
263
  private constructor();
264
+ get connectionId(): string;
265
+ connections(): Promise<ConnectionInfo[]>;
266
+ send(message: unknown, to?: string): Promise<void>;
267
+ onMessage(listener: (message: ConnectionMessage) => void): {
268
+ dispose: () => void;
269
+ };
219
270
  private connectWindow;
220
271
  private startBackendServer;
221
272
  private closeBackendServer;
222
273
  private forgetBackend;
223
- static create({ app, cmdlessRoot, timeoutMs }?: CreateHostOptions): Promise<UIHost>;
224
- static showWindow<T = unknown>(options: CreateHostOptions, params: WindowParams, backend?: WindowBackend): Promise<T>;
225
- static showDialog(options: CreateHostOptions, params: DialogParams): Promise<DialogResult>;
226
- static showCard(options: CreateHostOptions, params: CardParams): Promise<CardEvent | undefined>;
227
- static showElicitation(options: CreateHostOptions, request: ElicitationRequest & {
274
+ static create({ app, cmdlessRoot, timeoutMs, initialize }?: CreateHostOptions): Promise<UIHost>;
275
+ static showWindow<T = unknown>(params: WindowParams, options?: CreateHostOptions): Promise<T>;
276
+ static showDialog(params: DialogParams, options?: CreateHostOptions): Promise<DialogResult>;
277
+ static showCard(params: CardParams, options?: CreateHostOptions): Promise<CardEvent | undefined>;
278
+ static showElicitation(request: ElicitationRequest & {
228
279
  window?: WindowOptions;
229
- }): Promise<import("../prompts.js").ElicitationResult>;
230
- static showPermission(options: CreateHostOptions, request: PermissionRequest & {
280
+ }, options?: CreateHostOptions): Promise<import("../prompts.js").ElicitationResult>;
281
+ static showPermission(request: PermissionRequest & {
231
282
  window?: WindowOptions;
232
- }): Promise<import("../prompts.js").PermissionOutcome>;
233
- static showForm<F = unknown>(options: CreateHostOptions, params: FormParams): Promise<F | undefined>;
283
+ }, options?: CreateHostOptions): Promise<import("../prompts.js").PermissionOutcome>;
284
+ static showForm<F = unknown>(params: FormParams, options?: CreateHostOptions): Promise<F | undefined>;
285
+ static show<P, T>(factory: UIFactory<P, RemoteHandle<T>>, params: P, options?: CreateHostOptions): Promise<T>;
234
286
  private static once;
235
- openWindow<T = unknown>(params: WindowParams, backend?: WindowBackend): Promise<RemoteWindow<T>>;
287
+ open<P, H extends RemoteHandle<any>>(factory: UIFactory<P, H>, params: P): Promise<H>;
288
+ openWindow<T = unknown>({ backend, ...params }: WindowParams): Promise<RemoteWindow<T>>;
236
289
  openDialog(params: DialogParams): Promise<RemoteDialog>;
237
290
  showNotification(params: NotificationParams): Promise<RemoteNotification>;
238
291
  createTray(params: TrayParams): Promise<RemoteTray>;