@cmdless/ui-sdk 0.0.4 → 0.0.5
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 +16 -21
- package/dist/browser/index.d.ts +4 -74
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +19 -80
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +42 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/dist/node/host.d.ts +246 -0
- package/dist/node/host.d.ts.map +1 -0
- package/dist/node/host.js +378 -0
- package/dist/node/host.js.map +1 -0
- package/dist/node/index.d.ts +1 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -2
- package/dist/node/index.js.map +1 -1
- package/dist/node/utils.d.ts +9 -92
- package/dist/node/utils.d.ts.map +1 -1
- package/dist/node/utils.js +50 -325
- package/dist/node/utils.js.map +1 -1
- package/dist/node/utils.test.js +13 -87
- package/dist/node/utils.test.js.map +1 -1
- package/dist/prompts.d.ts +33 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +66 -0
- package/dist/prompts.js.map +1 -0
- package/dist/types.d.ts +25 -78
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -27
- package/dist/types.js.map +1 -1
- package/package.json +4 -10
- package/dist/app.d.ts +0 -30
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -8
- package/dist/app.js.map +0 -1
- package/dist/emitter.d.ts +0 -11
- package/dist/emitter.d.ts.map +0 -1
- package/dist/emitter.js +0 -37
- package/dist/emitter.js.map +0 -1
- package/dist/node/app.d.ts +0 -25
- package/dist/node/app.d.ts.map +0 -1
- package/dist/node/app.fixture.d.ts +0 -9
- package/dist/node/app.fixture.d.ts.map +0 -1
- package/dist/node/app.fixture.js +0 -21
- package/dist/node/app.fixture.js.map +0 -1
- package/dist/node/app.js +0 -192
- package/dist/node/app.js.map +0 -1
- package/dist/node/app.test.d.ts +0 -2
- package/dist/node/app.test.d.ts.map +0 -1
- package/dist/node/app.test.js +0 -185
- package/dist/node/app.test.js.map +0 -1
- package/dist/node/bin.d.ts +0 -3
- package/dist/node/bin.d.ts.map +0 -1
- package/dist/node/bin.js +0 -4
- package/dist/node/bin.js.map +0 -1
- package/dist/node/mcp.test.d.ts +0 -2
- package/dist/node/mcp.test.d.ts.map +0 -1
- package/dist/node/mcp.test.js +0 -92
- package/dist/node/mcp.test.js.map +0 -1
- package/dist/node/runtime.d.ts +0 -32
- package/dist/node/runtime.d.ts.map +0 -1
- package/dist/node/runtime.js +0 -20
- package/dist/node/runtime.js.map +0 -1
- package/dist/node/streams.d.ts +0 -24
- package/dist/node/streams.d.ts.map +0 -1
- package/dist/node/streams.js +0 -54
- package/dist/node/streams.js.map +0 -1
- package/dist/runtime.d.ts +0 -31
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -22
- package/dist/runtime.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
# @cmdless/ui-sdk
|
|
2
2
|
|
|
3
|
-
Shared types and helpers for building on cmdless UI
|
|
3
|
+
Shared types and helpers for building on cmdless UI, split by where they run.
|
|
4
4
|
|
|
5
5
|
## Exports
|
|
6
6
|
|
|
7
7
|
- **`@cmdless/ui-sdk`** — platform-agnostic.
|
|
8
|
-
- `
|
|
9
|
-
-
|
|
10
|
-
- `
|
|
11
|
-
-
|
|
12
|
-
- `createApp({ spec, setup, startup? })` — turns an `AppSpec` into a runnable app. `setup()` is called once per instance and returns the tool handlers (a factory rather than a plain object, so handlers can close over per-instance state); `startup(app)` runs when the CLI is invoked with no subcommand (e.g. "just launch the window"). Returns a **factory**, not an instance - a consumer's own `src/node/app.ts` does `export default createApp({...})`, and whatever loads it (a bin entrypoint, a vite plugin's dev-mode HMR) calls it to get a fresh `App`: `{ spec, tools, cli(), run(argv?), mcp() }`.
|
|
13
|
-
- `tools` - the handlers, callable directly in-process.
|
|
14
|
-
- `cli()` - the generated Commander program (`tool <name> [json] [--flags]`, and `mcp`). `<name>`'s input is an optional JSON positional merged with `--field` flag overrides - scalar fields (string/number/boolean/enum) become plain flags, and object/record fields also become flags, parsed as JSON (e.g. `--config '{"reasoning":"high"}'`).
|
|
15
|
-
- `run(argv?)` - `cli().parseAsync(argv)`.
|
|
16
|
-
- `mcp()` - starts the MCP server on a plain WebSocket (not one of MCP's standard transports) and returns `{ address, dispose() }`, for embedding without going through argv. The CLI's own `mcp` subcommand speaks standard MCP stdio when run normally (e.g. by an external MCP client like Claude Desktop), and switches to this WebSocket form only when launched with an `'ipc'` channel present (i.e. by `runAsMcp` below).
|
|
17
|
-
- `runAsMcp(importMeta, packageName, version?, cmdlessRoot?)` — resolves a package (locally via `findLocalBinPath`, falling back to `ensurePackage`'s cache) and spawns its `mcp` subcommand with an `'ipc'` stdio channel, returning `{ address, dispose() }` once the child reports its WebSocket address back. Used by an Electron main process to mediate a renderer's request for some package's MCP server, since a renderer can open a WebSocket but can't spawn a process or speak stdio itself.
|
|
18
|
-
- `CmdlessUI` dispatches `show`/`message-box` requests — by default by spawning `@cmdless/ui-runtime` (via `runAsRuntime`), or with a custom `dispatch` for handling a request in-process (e.g. a window's own preload asking for a nested dialog).
|
|
19
|
-
- `createShowCommand({ params, result?, dispatcher?, cmdlessRoot?, transport? })` — the usual way to build a one-off "show a window" CLI command: takes a `params(input)` callback that returns the `ShowParams` to use, and returns an `(input, parent?) => Promise<Out>` function. If a dev server has published its own URL via `CmdlessEnv.url` (see below), it always overrides `params()`'s `type`/`source` - individual commands never need to check for that themselves. Pass `transport` to also stand up a `@cmdless/rpc-sdk/ws/node` server per invocation and pass its address through as `--address`, for a renderer that needs to talk directly to this process.
|
|
20
|
-
- `CmdlessEnv` — typed accessors for the `CMDLESS_ROOT`/`CMDLESS_APP`/`CMDLESS_URL` environment variables. A dev-mode Vite plugin (see `apps/agent-runner`'s `vite.config.ts` for the pattern) can publish its dev server's URL under `CmdlessEnv.url` before spawning a consumer's bin, so `createShowCommand` picks it up automatically instead of the built renderer.
|
|
21
|
-
- `BinChannel` — a small socket-based protocol (built on `@cmdless/rpc-sdk`'s Node socket transport) for a bin process to talk to a long-running child it spawns (e.g. Electron), without using `child_process`'s `'ipc'` stdio channel - that combination is a documented source of Electron `app.whenReady()` hangs ([electron/electron#17044](https://github.com/electron/electron/issues/17044)). Call `BinChannel.start(onMessage)` in the parent *before* spawning (fold its returned `env` into the spawn call), and `await BinChannel.connect()` at the top of the child to get a `send(message)` function back.
|
|
22
|
-
- Package-caching helpers: `ensurePackage`, `runAsPackage`, `runAsRuntime`, `runPackage` (blocking, captures stdout once the process exits), `spawnPackage` (non-blocking, inherited stdio - for a long-running process like Electron where you don't need to read its output), `spawnAsPackage(importMeta, packageName, args?, options?)` (non-blocking, piped stdio - for a long-running process you need to stream to/from, e.g. a JSON-RPC-over-stdio child), `findLocalBinPath` (resolves a package's `bin` entry to an absolute path via `findPackageJSON`, given the caller's own `import.meta`).
|
|
8
|
+
- `types` — `ShowTypes`, `MessageBoxTypes`, and the card and form shapes (`AdaptiveCard`, `CardEvent`, `CardView`, `FormView`).
|
|
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.
|
|
11
|
+
- The host's own channels to a window's preload (`cmdlessIPC`, `cmdlessViewIPC`, `createElectronIPC`, `createElectronViewIPC`) — main ↔ preload only.
|
|
23
12
|
|
|
24
|
-
|
|
13
|
+
- **`@cmdless/ui-sdk/node`** — Node only.
|
|
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.
|
|
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.
|
|
20
|
+
- `dispose()` leaves the host; for its owner (the one whose creator started it), that ends it.
|
|
21
|
+
- `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.
|
|
22
|
+
- The ephemeral-app helpers (`getEphemeralPrefix`, `isEphemeralCmdlessApp`, `isEphemeralUserData`), and the few [`@cmdless/core`](../core) helpers the host and `@cmdless/ui` use.
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
- **`@cmdless/ui-sdk/browser`** — for code running in a cmdless-hosted window.
|
|
28
|
-
- `createClient(spec, { name, version })` — a facade over an app's MCP server, from the renderer. Returns a factory `(cmdless) => { spec, tools }` where each `tools[name]` matches `App<T>.tools[name]`'s shape, but lazily connects over MCP (via `window.cmdless.ipc`'s `mcpAddress` request, mediated by Electron main) the first time any tool is actually invoked. Since it only captures data until that factory is called, this is safe to export from a consumer's own `/shared` code - `export const client = createClient(spec, packageJson)` - for another app to import as a sibling dependency, or for the app itself to use on its own tools.
|
|
29
|
-
- `createRenderer({ client, tool, apps? })` — the renderer side of one specific tool. `tool` (a value off that app's own `spec.tools`) gives the renderer its name/description and, if that tool declared a `protocol`, connects it over `cmdlessIPC`'s `connectionInfo` handshake (exposed as `.rpc`). `client` is the renderer's own app (its other tools, via MCP); `apps` is a `Record<string, ClientFactory>` of sibling apps' `createClient` exports, connected the same way and exposed at `.apps[key]`.
|
|
24
|
+
- **`@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.
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,80 +1,10 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
import type { Cmdless } from '../index.js';
|
|
5
|
-
export type { Cmdless };
|
|
1
|
+
import type { ClientOf, ClientProtocol } from '@cmdless/rpc-sdk';
|
|
2
|
+
import type { Cmdless, CmdlessSocket } from '../index.js';
|
|
3
|
+
export type { Cmdless, CmdlessSocket };
|
|
6
4
|
declare global {
|
|
7
5
|
interface Window {
|
|
8
6
|
cmdless: Cmdless;
|
|
9
7
|
}
|
|
10
8
|
}
|
|
11
|
-
export
|
|
12
|
-
export type ClientTools<T extends AppToolsSpec> = {
|
|
13
|
-
[K in keyof T]: ClientToolHandler<T[K]>;
|
|
14
|
-
};
|
|
15
|
-
export type ClientApp<T extends AppToolsSpec> = {
|
|
16
|
-
spec: AppSpec<T>;
|
|
17
|
-
tools: ClientTools<T>;
|
|
18
|
-
};
|
|
19
|
-
export type ClientInfo = {
|
|
20
|
-
name: string;
|
|
21
|
-
version: string;
|
|
22
|
-
};
|
|
23
|
-
export type ClientFactory<T extends AppToolsSpec> = (cmdless: Cmdless) => ClientApp<T>;
|
|
24
|
-
export declare function createClient<T extends AppToolsSpec>(spec: AppSpec<T>, info: ClientInfo): ClientFactory<T>;
|
|
25
|
-
export type RendererApps = Record<string, ClientFactory<AppToolsSpec>>;
|
|
26
|
-
export type RendererClients<Apps extends RendererApps> = {
|
|
27
|
-
[K in keyof Apps]: Apps[K] extends ClientFactory<infer T> ? ClientApp<T> : never;
|
|
28
|
-
};
|
|
29
|
-
export type RendererOptions<T extends AppToolsSpec, Tool extends AppTool, Apps extends RendererApps> = {
|
|
30
|
-
client: ClientFactory<T>;
|
|
31
|
-
tool: Tool;
|
|
32
|
-
apps?: Apps;
|
|
33
|
-
};
|
|
34
|
-
export declare class Renderer<T extends AppToolsSpec, Tool extends AppTool, Apps extends RendererApps> {
|
|
35
|
-
private readonly tool;
|
|
36
|
-
readonly client: ClientApp<T>;
|
|
37
|
-
readonly apps: RendererClients<Apps>;
|
|
38
|
-
rpc?: RpcPeer<NonNullable<ToolProtocol<Tool>>['client']>;
|
|
39
|
-
constructor(tool: Tool, client: ClientFactory<T>, apps?: Apps);
|
|
40
|
-
get name(): string;
|
|
41
|
-
get description(): string;
|
|
42
|
-
get attached(): boolean;
|
|
43
|
-
get connected(): boolean;
|
|
44
|
-
get cmdless(): Cmdless;
|
|
45
|
-
get ipc(): RpcPeer<import("@cmdless/rpc-sdk").RpcChannel<import("@cmdless/rpc-sdk").MergeSides<import("@cmdless/rpc-sdk").RpcSide<{
|
|
46
|
-
state: import("@cmdless/rpc-sdk").RpcRequest<void, import("../index.js").CmdlessState>;
|
|
47
|
-
ui: import("@cmdless/rpc-sdk").RpcRequest<{
|
|
48
|
-
app?: string | undefined;
|
|
49
|
-
parent?: number | undefined;
|
|
50
|
-
width?: number | undefined;
|
|
51
|
-
height?: number | undefined;
|
|
52
|
-
address?: string | undefined;
|
|
53
|
-
kind: "show";
|
|
54
|
-
type: "file" | "url";
|
|
55
|
-
source: string;
|
|
56
|
-
} | {
|
|
57
|
-
app?: string | undefined;
|
|
58
|
-
parent?: number | undefined;
|
|
59
|
-
kind: "message-box";
|
|
60
|
-
type: "error" | "info" | "none" | "question" | "warning";
|
|
61
|
-
message: string;
|
|
62
|
-
}, string>;
|
|
63
|
-
connectionInfo: import("@cmdless/rpc-sdk").RpcRequest<void, import("../index.js").ConnectionInfo>;
|
|
64
|
-
mcpAddress: import("@cmdless/rpc-sdk").RpcRequest<{
|
|
65
|
-
packageName: string;
|
|
66
|
-
version?: string;
|
|
67
|
-
}, {
|
|
68
|
-
address: string;
|
|
69
|
-
}>;
|
|
70
|
-
}, {
|
|
71
|
-
resolve: import("@cmdless/rpc-sdk").RpcNotification<{
|
|
72
|
-
value: unknown;
|
|
73
|
-
exitCode?: number;
|
|
74
|
-
}>;
|
|
75
|
-
}>, import("@cmdless/rpc-sdk").EmptySide>, import("@cmdless/rpc-sdk").MergeSides<import("@cmdless/rpc-sdk").RpcSide<import("@cmdless/rpc-sdk").RpcRequests, {
|
|
76
|
-
state: import("@cmdless/rpc-sdk").RpcNotification<import("../index.js").CmdlessState>;
|
|
77
|
-
}>, import("@cmdless/rpc-sdk").EmptySide>>>;
|
|
78
|
-
}
|
|
79
|
-
export declare function createRenderer<T extends AppToolsSpec, Tool extends AppTool, Apps extends RendererApps>(options: RendererOptions<T, Tool, Apps>): Renderer<T, Tool, Apps>;
|
|
9
|
+
export declare function connect<P extends ClientProtocol>(protocol: P, configure?: (backend: ClientOf<P>) => void): Promise<ClientOf<P>>;
|
|
80
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,83 +1,22 @@
|
|
|
1
|
-
import '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
function getCmdless() {
|
|
1
|
+
import { createSocketConnection } from '@cmdless/rpc-sdk/ws';
|
|
2
|
+
// connects this window to the backend it was opened with - the node side
|
|
3
|
+
// that opened it, straight to it once the host has introduced them. configure
|
|
4
|
+
// sets up handlers before the connection listens, so nothing the backend
|
|
5
|
+
// sends right away is missed. A protocol with a name and version can be held
|
|
6
|
+
// to them with checkVersion() once connected.
|
|
7
|
+
export async function connect(protocol, configure) {
|
|
9
8
|
if (!window.cmdless)
|
|
10
|
-
throw new Error('
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.ready = new Promise(resolve => socket.addEventListener('open', () => resolve(), { once: true }));
|
|
23
|
-
socket.addEventListener('message', event => this.onmessage?.(JSON.parse(event.data)));
|
|
24
|
-
socket.addEventListener('close', () => this.onclose?.());
|
|
25
|
-
socket.addEventListener('error', () => this.onerror?.(new Error('MCP WebSocket error')));
|
|
26
|
-
}
|
|
27
|
-
async start() { await this.ready; }
|
|
28
|
-
async send(message) { this.socket.send(JSON.stringify(message)); }
|
|
29
|
-
async close() { this.socket.close(); }
|
|
30
|
-
}
|
|
31
|
-
export function createClient(spec, info) {
|
|
32
|
-
return cmdless => {
|
|
33
|
-
let mcp;
|
|
34
|
-
const connect = () => mcp ??= cmdless.ipc.request.mcpAddress({ packageName: info.name, version: info.version })
|
|
35
|
-
.then(async ({ address }) => {
|
|
36
|
-
const client = new McpClient({ name: info.name, version: info.version });
|
|
37
|
-
await client.connect(new ClientWebSocketTransport(new WebSocket(address)));
|
|
38
|
-
return client;
|
|
39
|
-
});
|
|
40
|
-
const tools = {};
|
|
41
|
-
for (const tool of Object.values(spec.tools)) {
|
|
42
|
-
tools[tool.name] = async (input) => {
|
|
43
|
-
const client = await connect();
|
|
44
|
-
const result = await client.callTool({ name: tool.name, arguments: input });
|
|
45
|
-
return result.structuredContent;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return { spec, tools };
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export class Renderer {
|
|
52
|
-
tool;
|
|
53
|
-
client;
|
|
54
|
-
apps;
|
|
55
|
-
rpc;
|
|
56
|
-
constructor(tool, client, apps) {
|
|
57
|
-
this.tool = tool;
|
|
58
|
-
const cmdless = this.cmdless;
|
|
59
|
-
this.client = client(cmdless);
|
|
60
|
-
this.apps = Object.fromEntries(Object.entries(apps ?? {}).map(([key, factory]) => [key, factory(cmdless)]));
|
|
61
|
-
if (tool.protocol) {
|
|
62
|
-
const protocol = tool.protocol;
|
|
63
|
-
this.ipc.request.connectionInfo().then(({ address }) => {
|
|
64
|
-
if (!address)
|
|
65
|
-
return;
|
|
66
|
-
return connectWebSocket(protocol, { url: address }).then(rpc => {
|
|
67
|
-
rpc.listen();
|
|
68
|
-
this.rpc = rpc;
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
get name() { return this.tool.name; }
|
|
74
|
-
get description() { return this.tool.description; }
|
|
75
|
-
get attached() { return !!window.cmdless; }
|
|
76
|
-
get connected() { return !!this.rpc; }
|
|
77
|
-
get cmdless() { return getCmdless(); }
|
|
78
|
-
get ipc() { return this.cmdless.ipc; }
|
|
79
|
-
}
|
|
80
|
-
export function createRenderer(options) {
|
|
81
|
-
return new Renderer(options.tool, options.client, options.apps);
|
|
9
|
+
throw new Error('not in a cmdless window');
|
|
10
|
+
const socket = await window.cmdless.connect();
|
|
11
|
+
const backend = protocol.createClient(createSocketConnection({
|
|
12
|
+
send: message => socket.send(message),
|
|
13
|
+
onMessage: listener => socket.onMessage(listener),
|
|
14
|
+
onError: () => { },
|
|
15
|
+
onClose: listener => socket.onClose(listener),
|
|
16
|
+
dispose: () => socket.close(),
|
|
17
|
+
}));
|
|
18
|
+
configure?.(backend);
|
|
19
|
+
backend.listen();
|
|
20
|
+
return backend;
|
|
82
21
|
}
|
|
83
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
export * from './app.js';
|
|
3
|
-
export * from './runtime.js';
|
|
1
|
+
import type { AdaptiveCard, CardEvent, CardView, FormView } from './types.js';
|
|
4
2
|
export * as types from './types.js';
|
|
5
|
-
export
|
|
6
|
-
node: boolean;
|
|
7
|
-
}
|
|
3
|
+
export * from './prompts.js';
|
|
8
4
|
type ResolveParams<T = unknown> = {
|
|
9
5
|
value: T;
|
|
10
6
|
exitCode?: number;
|
|
11
7
|
};
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export type BackendCredentials = {
|
|
9
|
+
url: string;
|
|
10
|
+
token: string;
|
|
15
11
|
};
|
|
16
12
|
export declare const cmdlessIPC: import("@cmdless/rpc-sdk").Protocol<{
|
|
17
|
-
readonly clientToServer: import("@cmdless/rpc-sdk").RpcSide<{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
app?: string | undefined;
|
|
21
|
-
parent?: number | undefined;
|
|
22
|
-
width?: number | undefined;
|
|
23
|
-
height?: number | undefined;
|
|
24
|
-
address?: string | undefined;
|
|
25
|
-
kind: "show";
|
|
26
|
-
type: "file" | "url";
|
|
27
|
-
source: string;
|
|
28
|
-
} | {
|
|
29
|
-
app?: string | undefined;
|
|
30
|
-
parent?: number | undefined;
|
|
31
|
-
kind: "message-box";
|
|
32
|
-
type: "error" | "info" | "none" | "question" | "warning";
|
|
33
|
-
message: string;
|
|
34
|
-
}, string>;
|
|
35
|
-
connectionInfo: import("@cmdless/rpc-sdk").RpcRequest<void, ConnectionInfo>;
|
|
36
|
-
mcpAddress: import("@cmdless/rpc-sdk").RpcRequest<{
|
|
37
|
-
packageName: string;
|
|
38
|
-
version?: string;
|
|
39
|
-
}, {
|
|
40
|
-
address: string;
|
|
41
|
-
}>;
|
|
42
|
-
}, {
|
|
13
|
+
readonly clientToServer: import("@cmdless/rpc-sdk").RpcSide<NoInfer<{
|
|
14
|
+
connect: import("@cmdless/rpc-sdk").RpcRequest<void, BackendCredentials>;
|
|
15
|
+
}>, NoInfer<{
|
|
43
16
|
resolve: import("@cmdless/rpc-sdk").RpcNotification<ResolveParams<unknown>>;
|
|
44
|
-
}
|
|
45
|
-
readonly serverToClient: import("@cmdless/rpc-sdk").RpcSide<import("@cmdless/rpc-sdk").RpcRequests, {
|
|
46
|
-
state: import("@cmdless/rpc-sdk").RpcNotification<CmdlessState>;
|
|
47
|
-
}>;
|
|
17
|
+
}>>;
|
|
48
18
|
}>;
|
|
49
19
|
export declare const createElectronIPC: (source: import("@cmdless/rpc-sdk").ElectronIPCLike) => import("@cmdless/rpc-sdk").MessageConnection;
|
|
20
|
+
export type ViewProps = ({
|
|
21
|
+
view: 'card';
|
|
22
|
+
} & CardView) | ({
|
|
23
|
+
view: 'form';
|
|
24
|
+
} & FormView);
|
|
25
|
+
export declare const cmdlessViewIPC: import("@cmdless/rpc-sdk").Protocol<{
|
|
26
|
+
readonly clientToServer: import("@cmdless/rpc-sdk").RpcSide<NoInfer<{
|
|
27
|
+
props: import("@cmdless/rpc-sdk").RpcRequest<void, ViewProps>;
|
|
28
|
+
}>, NoInfer<{
|
|
29
|
+
event: import("@cmdless/rpc-sdk").RpcNotification<CardEvent>;
|
|
30
|
+
close: import("@cmdless/rpc-sdk").RpcNotification<{
|
|
31
|
+
value?: unknown;
|
|
32
|
+
}>;
|
|
33
|
+
resize: import("@cmdless/rpc-sdk").RpcNotification<{
|
|
34
|
+
height: number;
|
|
35
|
+
}>;
|
|
36
|
+
}>>;
|
|
37
|
+
readonly serverToClient: import("@cmdless/rpc-sdk").RpcSide<{}, NoInfer<{
|
|
38
|
+
update: import("@cmdless/rpc-sdk").RpcNotification<{
|
|
39
|
+
card: AdaptiveCard;
|
|
40
|
+
}>;
|
|
41
|
+
}>>;
|
|
42
|
+
}>;
|
|
43
|
+
export declare const createElectronViewIPC: (source: import("@cmdless/rpc-sdk").ElectronIPCLike) => import("@cmdless/rpc-sdk").MessageConnection;
|
|
44
|
+
export type CmdlessSocket = {
|
|
45
|
+
send(message: string): void;
|
|
46
|
+
onMessage(listener: (message: string) => void): void;
|
|
47
|
+
onClose(listener: (code: number, reason: string) => void): void;
|
|
48
|
+
close(): void;
|
|
49
|
+
};
|
|
50
50
|
export type Cmdless = {
|
|
51
|
-
|
|
51
|
+
resolve(value: unknown, exitCode?: number): void;
|
|
52
|
+
connect(): Promise<CmdlessSocket>;
|
|
53
|
+
view: ReturnType<typeof cmdlessViewIPC.createClient>;
|
|
52
54
|
};
|
|
53
55
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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,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,MAAM,MAAM,OAAO,GAAG;IAEpB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAGjD,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,29 +1,38 @@
|
|
|
1
1
|
import { defineProtocol, forElectronIPC } from '@cmdless/rpc-sdk';
|
|
2
|
-
export * from './emitter.js';
|
|
3
|
-
export * from './app.js';
|
|
4
|
-
export * from './runtime.js';
|
|
5
2
|
export * as types from './types.js';
|
|
6
|
-
;
|
|
3
|
+
export * from './prompts.js';
|
|
4
|
+
// what a window's preload can say to the host: resolve the window with a
|
|
5
|
+
// value, and ask for its backend
|
|
7
6
|
export const cmdlessIPC = defineProtocol(({ side, request, notification }) => ({
|
|
8
7
|
clientToServer: side({
|
|
9
8
|
requests: {
|
|
10
|
-
|
|
11
|
-
ui: request('ui'),
|
|
12
|
-
connectionInfo: request('connectionInfo'),
|
|
13
|
-
// asks main for a package's MCP server address - main serves its own
|
|
14
|
-
// already-running instance directly if packageName is itself, or
|
|
15
|
-
// resolves/spawns it (runAsMcp) if it's a sibling app.
|
|
16
|
-
mcpAddress: request('mcpAddress'),
|
|
9
|
+
connect: request('connect'),
|
|
17
10
|
},
|
|
18
11
|
notifications: {
|
|
19
12
|
resolve: notification('resolve'),
|
|
20
13
|
},
|
|
21
14
|
}),
|
|
15
|
+
}));
|
|
16
|
+
export const createElectronIPC = forElectronIPC('cmdless:rpc');
|
|
17
|
+
// how one of the host's own views talks to it: it asks what to show, says
|
|
18
|
+
// how tall its content is (for its window to fit it), reports a card's
|
|
19
|
+
// actions, and ends with a value; the host sends it a card to show instead
|
|
20
|
+
export const cmdlessViewIPC = defineProtocol(({ side, request, notification }) => ({
|
|
21
|
+
clientToServer: side({
|
|
22
|
+
requests: {
|
|
23
|
+
props: request('view/props'),
|
|
24
|
+
},
|
|
25
|
+
notifications: {
|
|
26
|
+
event: notification('view/event'),
|
|
27
|
+
close: notification('view/close'),
|
|
28
|
+
resize: notification('view/resize'),
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
22
31
|
serverToClient: side({
|
|
23
32
|
notifications: {
|
|
24
|
-
|
|
33
|
+
update: notification('view/update'),
|
|
25
34
|
},
|
|
26
35
|
}),
|
|
27
36
|
}));
|
|
28
|
-
export const
|
|
37
|
+
export const createElectronViewIPC = forElectronIPC('cmdless:view');
|
|
29
38
|
//# 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,
|
|
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,MAAM,qBAAqB,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC"}
|