@cmdless/ui-sdk 0.0.0 → 0.0.4
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 +21 -0
- package/README.md +27 -43
- package/dist/app.d.ts +30 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +8 -0
- package/dist/app.js.map +1 -0
- package/dist/browser/index.d.ts +80 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +83 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/emitter.d.ts +11 -0
- package/dist/emitter.d.ts.map +1 -0
- package/dist/emitter.js +37 -0
- package/dist/emitter.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/node/app.d.ts +25 -0
- package/dist/node/app.d.ts.map +1 -0
- package/dist/node/app.fixture.d.ts +9 -0
- package/dist/node/app.fixture.d.ts.map +1 -0
- package/dist/node/app.fixture.js +21 -0
- package/dist/node/app.fixture.js.map +1 -0
- package/dist/node/app.js +192 -0
- package/dist/node/app.js.map +1 -0
- package/dist/node/app.test.d.ts +2 -0
- package/dist/node/app.test.d.ts.map +1 -0
- package/dist/node/app.test.js +185 -0
- package/dist/node/app.test.js.map +1 -0
- package/dist/node/bin.d.ts +3 -0
- package/dist/node/bin.d.ts.map +1 -0
- package/dist/node/bin.js +4 -0
- package/dist/node/bin.js.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +4 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/mcp.test.d.ts +2 -0
- package/dist/node/mcp.test.d.ts.map +1 -0
- package/dist/node/mcp.test.js +92 -0
- package/dist/node/mcp.test.js.map +1 -0
- package/dist/node/runtime.d.ts +32 -0
- package/dist/node/runtime.d.ts.map +1 -0
- package/dist/node/runtime.js +20 -0
- package/dist/node/runtime.js.map +1 -0
- package/dist/node/streams.d.ts +24 -0
- package/dist/node/streams.d.ts.map +1 -0
- package/dist/node/streams.js +54 -0
- package/dist/node/streams.js.map +1 -0
- package/dist/node/utils.d.ts +95 -0
- package/dist/node/utils.d.ts.map +1 -0
- package/dist/node/utils.js +337 -0
- package/dist/node/utils.js.map +1 -0
- package/dist/node/utils.test.d.ts +2 -0
- package/dist/node/utils.test.d.ts.map +1 -0
- package/dist/node/utils.test.js +91 -0
- package/dist/node/utils.test.js.map +1 -0
- package/dist/runtime.d.ts +31 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +22 -0
- package/dist/runtime.js.map +1 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +30 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cmdless
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,45 +1,29 @@
|
|
|
1
1
|
# @cmdless/ui-sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
This package is a placeholder for OIDC configuration only. It:
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
36
|
-
|
|
37
|
-
## More Information
|
|
38
|
-
|
|
39
|
-
For more details about npm's trusted publishing feature, see:
|
|
40
|
-
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
|
|
41
|
-
- [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
**Maintained for OIDC setup purposes only**
|
|
3
|
+
Shared types and helpers for building on cmdless UI. Everything a consumer or a `@cmdless/ui-runtime` build needs, split by where it runs.
|
|
4
|
+
|
|
5
|
+
## Exports
|
|
6
|
+
|
|
7
|
+
- **`@cmdless/ui-sdk`** — platform-agnostic.
|
|
8
|
+
- `Params`/`ShowParams`/`MessageBoxParams` types, `cmdlessIPC` (the [`@cmdless/rpc-sdk`](../rpc-sdk) protocol definition shared between a window's preload and the Electron main process - main ↔ renderer only, not a consumer's own backend), `createElectronIPC`, and a small typed `Emitter` used internally.
|
|
9
|
+
- `defineApp(({ tool, z }) => ({ name, description?, tools }))` — an app's schema: just names, descriptions, and zod input/output shapes for each tool (both must be object schemas - MCP tool inputs are always a top-level dictionary, and `@modelcontextprotocol/sdk` requires structured output to be object-shaped whenever an `outputSchema` is declared). No handlers live here - `z` is passed into the callback so consumers don't need their own zod dependency. A tool can optionally carry its own `protocol` (an `@cmdless/rpc-sdk` `RpcProtocol`) for the rare case where its UI needs a live, bidirectional channel back to its handler, on top of the one-shot MCP input/output.
|
|
10
|
+
- `runtimeSpec` — `ui-sdk`'s own app schema: `show`/`messageBox`, the same shape as `ShowParams`/`MessageBoxParams` below. Backs `ui-sdk`'s own bin (see below), not `@cmdless/ui-runtime` itself.
|
|
11
|
+
- **`@cmdless/ui-sdk/node`** — for the process invoking cmdless UI (or the Electron main process handling it).
|
|
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`).
|
|
23
|
+
|
|
24
|
+
## Its own bin
|
|
25
|
+
|
|
26
|
+
`ui-sdk` ships a `ui-sdk` bin (`npx @cmdless/ui-sdk ...`), built from `runtimeSpec` the same way any consumer builds their own app with `createApp`. Its `show`/`messageBox` handlers just forward straight through to the existing `CmdlessUI` + dispatcher (spawning `@cmdless/ui-runtime` via `runAsRuntime`, same as always) - this carries no behavior of its own, it's a schema/CLI/MCP front door onto what already happens for every dispatch. The point: `npx @cmdless/ui-sdk mcp` is a standalone, generic MCP server - "show the user a window", "show the user a dialog" - that any MCP-speaking client (an ACP agent, Claude Desktop, anything) can be pointed at directly, independent of any specific app. `@cmdless/ui-runtime` itself is untouched by any of this.
|
|
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]`.
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { RpcProtocol } from '@cmdless/rpc-sdk';
|
|
3
|
+
export type AppTool<InSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, OutSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, P extends RpcProtocol = RpcProtocol> = {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
inputSchema: InSchema;
|
|
7
|
+
outputSchema: OutSchema;
|
|
8
|
+
protocol?: P;
|
|
9
|
+
};
|
|
10
|
+
export type ToolInput<T extends AppTool> = z.infer<T['inputSchema']>;
|
|
11
|
+
export type ToolOutput<T extends AppTool> = z.infer<T['outputSchema']>;
|
|
12
|
+
export type ToolProtocol<T extends AppTool> = T extends AppTool<infer _In, infer _Out, infer P> ? P : never;
|
|
13
|
+
declare function tool<InSchema extends z.ZodObject<z.ZodRawShape>, OutSchema extends z.ZodObject<z.ZodRawShape>, P extends RpcProtocol = RpcProtocol>(name: string, description: string, schemas: {
|
|
14
|
+
input: InSchema;
|
|
15
|
+
output: OutSchema;
|
|
16
|
+
protocol?: P;
|
|
17
|
+
}): AppTool<InSchema, OutSchema, P>;
|
|
18
|
+
export type AppToolsSpec = Record<string, AppTool>;
|
|
19
|
+
export type AppSpec<T extends AppToolsSpec = AppToolsSpec> = {
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
tools: T;
|
|
23
|
+
};
|
|
24
|
+
export type AppFactory<T extends AppToolsSpec> = (parameters: {
|
|
25
|
+
tool: typeof tool;
|
|
26
|
+
z: typeof z;
|
|
27
|
+
}) => AppSpec<T>;
|
|
28
|
+
export declare function defineApp<const T extends A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CAAC,WAAW,CAAC,EAAE,SAAS,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,WAAW,EAC1I,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;CAAE,GAC5D,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CAEjC;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnD,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,YAAY,IAAI,CAAC,UAAU,EAAE;IAC5D,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,CAAC,EAAE,OAAO,CAAC,CAAC;CACb,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAEjB,wBAAgB,SAAS,CAAC,KAAK,CAAC,CAAC,SAAS,YAAY,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE1F"}
|
package/dist/app.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
function tool(name, description, schemas) {
|
|
3
|
+
return { name, description, inputSchema: schemas.input, outputSchema: schemas.output, protocol: schemas.protocol };
|
|
4
|
+
}
|
|
5
|
+
export function defineApp(factory) {
|
|
6
|
+
return factory({ tool, z });
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkCxB,SAAS,IAAI,CACX,IAAY,EACZ,WAAmB,EACnB,OAA6D;IAE7D,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;AACrH,CAAC;AAeD,MAAM,UAAU,SAAS,CAA+B,OAAsB;IAC5E,OAAO,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import 'vscode-jsonrpc/browser';
|
|
2
|
+
import type { RpcPeer } from '@cmdless/rpc-sdk';
|
|
3
|
+
import type { AppSpec, AppTool, AppToolsSpec, ToolInput, ToolOutput, ToolProtocol } from '../app.js';
|
|
4
|
+
import type { Cmdless } from '../index.js';
|
|
5
|
+
export type { Cmdless };
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
cmdless: Cmdless;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export type ClientToolHandler<T extends AppTool> = (input: ToolInput<T>) => Promise<ToolOutput<T>>;
|
|
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>;
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAe,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAK7D,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACrG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,YAAY,EAAE,OAAO,EAAE,CAAC;A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ket } from '@cmdless/rpc-sdk/ws';
|
|
3
|
+
import { Client as McpClient } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
// --- createClient: a facade over an app's MCP server, from the renderer.
|
|
5
|
+
// Mirrors App<T>.tools' shape (same input/output per tool), but each call
|
|
6
|
+
// lazily connects over MCP the first time any tool is actually invoked,
|
|
7
|
+
// rather than eagerly on construction.
|
|
8
|
+
function getCmdless() {
|
|
9
|
+
if (!window.cmdless)
|
|
10
|
+
throw new Error('window.cmdless not found');
|
|
11
|
+
return window.cmdless;
|
|
12
|
+
}
|
|
13
|
+
// mirrors node/app.ts's server-side WebSocketTransport, for the client side.
|
|
14
|
+
class ClientWebSocketTransport {
|
|
15
|
+
socket;
|
|
16
|
+
onclose;
|
|
17
|
+
onerror;
|
|
18
|
+
onmessage;
|
|
19
|
+
ready;
|
|
20
|
+
constructor(socket) {
|
|
21
|
+
this.socket = socket;
|
|
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);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAC,CAAC,oFAAoF;AAErH,OAAO,EAAE,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AAK,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAEnD,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3C,IAAI,SAAS,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAEtC,IAAI,OAAO,KAAK,OAAO,UAAU,EAAE,CAAC,CAAC,CAAC;IACtC,IAAI,GAAG,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;CACvC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAuC;IAEvC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type EmitterEventMap = Record<string, readonly unknown[]>;
|
|
2
|
+
export declare class Emitter<TSend extends EmitterEventMap = {}, TReceive extends EmitterEventMap = TSend> {
|
|
3
|
+
private readonly target;
|
|
4
|
+
private readonly handlers;
|
|
5
|
+
on<K extends keyof TReceive>(type: K, handler: (...args: TReceive[K]) => void): this;
|
|
6
|
+
once<K extends keyof TReceive>(type: K, handler: (...args: TReceive[K]) => void): this;
|
|
7
|
+
off<K extends keyof TReceive>(type: K, handler: (...args: TReceive[K]) => void): this;
|
|
8
|
+
emit<K extends keyof TSend>(type: K, ...args: TSend[K]): boolean;
|
|
9
|
+
subscribe<K extends keyof TReceive>(type: K, handler: (...args: TReceive[K]) => void): () => void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC;AAEjE,qBAAa,OAAO,CAAC,KAAK,SAAS,eAAe,GAAG,EAAE,EAAE,QAAQ,SAAS,eAAe,GAAG,KAAK;IAC/F,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IAEnE,EAAE,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAOnF;IAED,IAAI,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAQrF;IAED,GAAG,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAOpF;IAED,IAAI,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAE/D;IAED,SAAS,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAGhG;CACF"}
|
package/dist/emitter.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class Emitter {
|
|
2
|
+
target = new EventTarget();
|
|
3
|
+
handlers = new WeakMap();
|
|
4
|
+
on(type, handler) {
|
|
5
|
+
const wrapped = (event) => {
|
|
6
|
+
handler(...event.detail);
|
|
7
|
+
};
|
|
8
|
+
this.handlers.set(handler, wrapped);
|
|
9
|
+
this.target.addEventListener(type, wrapped);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
once(type, handler) {
|
|
13
|
+
const wrapped = (event) => {
|
|
14
|
+
this.handlers.delete(handler);
|
|
15
|
+
handler(...event.detail);
|
|
16
|
+
};
|
|
17
|
+
this.handlers.set(handler, wrapped);
|
|
18
|
+
this.target.addEventListener(type, wrapped, { once: true });
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
off(type, handler) {
|
|
22
|
+
const wrapped = this.handlers.get(handler);
|
|
23
|
+
if (wrapped) {
|
|
24
|
+
this.target.removeEventListener(type, wrapped);
|
|
25
|
+
this.handlers.delete(handler);
|
|
26
|
+
}
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
emit(type, ...args) {
|
|
30
|
+
return this.target.dispatchEvent(new CustomEvent(type, { detail: args }));
|
|
31
|
+
}
|
|
32
|
+
subscribe(type, handler) {
|
|
33
|
+
this.on(type, handler);
|
|
34
|
+
return () => this.off(type, handler);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,OAAO;IACD,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;IAC3B,QAAQ,GAAG,IAAI,OAAO,EAA2B,CAAC;IAEnE,EAAE,CAA2B,IAAO,EAAE,OAAuC;QAC3E,MAAM,OAAO,GAAkB,CAAC,KAAK,EAAE,EAAE;YACvC,OAAO,CAAC,GAAI,KAAkC,CAAC,MAAM,CAAC,CAAC;QACzD,CAAC,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAc,EAAE,OAAO,CAAC,CAAC;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
|
|
|
1
|
+
export * from './emitter.js';
|
|
2
|
+
export * from './app.js';
|
|
3
|
+
export * from './runtime.js';
|
|
4
|
+
export * as types from './types.js';
|
|
5
|
+
export interface CmdlessState {
|
|
6
|
+
node: boolean;
|
|
7
|
+
}
|
|
8
|
+
type ResolveParams<T = unknown> = {
|
|
9
|
+
value: T;
|
|
10
|
+
exitCode?: number;
|
|
11
|
+
};
|
|
12
|
+
export type ConnectionInfo = {
|
|
13
|
+
address?: string;
|
|
14
|
+
windowId: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const cmdlessIPC: import("@cmdless/rpc-sdk").Protocol<{
|
|
17
|
+
readonly clientToServer: import("@cmdless/rpc-sdk").RpcSide<{
|
|
18
|
+
state: import("@cmdless/rpc-sdk").RpcRequest<void, CmdlessState>;
|
|
19
|
+
ui: import("@cmdless/rpc-sdk").RpcRequest<{
|
|
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
|
+
}, {
|
|
43
|
+
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
|
+
}>;
|
|
48
|
+
}>;
|
|
49
|
+
export declare const createElectronIPC: (source: import("@cmdless/rpc-sdk").ElectronIPCLike) => import("@cmdless/rpc-sdk").MessageConnection;
|
|
50
|
+
export type Cmdless = {
|
|
51
|
+
ipc: ReturnType<typeof cmdlessIPC.createClient>;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;CACf;AAED,KAAK,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IAChC,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;yBASkB,MAAM;sBAAY,MAAM;;qBAAe,MAAM;;;;;;;;EAWnF,CAAC;AAEJ,eAAO,MAAM,iBAAiB,sGAAgC,CAAC;AAE/D,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;CACjD,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineProtocol, forElectronIPC } from '@cmdless/rpc-sdk';
|
|
2
|
+
export * from './emitter.js';
|
|
3
|
+
export * from './app.js';
|
|
4
|
+
export * from './runtime.js';
|
|
5
|
+
export * as types from './types.js';
|
|
6
|
+
;
|
|
7
|
+
export const cmdlessIPC = defineProtocol(({ side, request, notification }) => ({
|
|
8
|
+
clientToServer: side({
|
|
9
|
+
requests: {
|
|
10
|
+
state: request('state'),
|
|
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'),
|
|
17
|
+
},
|
|
18
|
+
notifications: {
|
|
19
|
+
resolve: notification('resolve'),
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
serverToClient: side({
|
|
23
|
+
notifications: {
|
|
24
|
+
state: notification('state'),
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
export const createElectronIPC = forElectronIPC('cmdless:rpc');
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAInC,CAAC;AAYF,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,KAAK,EAAE,OAAO,CAAqB,OAAO,CAAC;YAC3C,EAAE,EAAE,OAAO,CAAiB,IAAI,CAAC;YACjC,cAAc,EAAE,OAAO,CAAuB,gBAAgB,CAAC;YAC/D,qEAAqE;YACrE,iEAAiE;YACjE,uDAAuD;YACvD,UAAU,EAAE,OAAO,CAAiE,YAAY,CAAC;SAClG;QACD,aAAa,EAAE;YACb,OAAO,EAAE,YAAY,CAAgB,SAAS,CAAC;SAChD;KACF,CAAC;IACF,cAAc,EAAE,IAAI,CAAC;QACnB,aAAa,EAAE;YACb,KAAK,EAAE,YAAY,CAAe,OAAO,CAAC;SAC3C;KACF,CAAC;CACH,CAAC,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import type { AppSpec, AppTool, AppToolsSpec, ToolInput, ToolOutput } from '../app.js';
|
|
3
|
+
export type ToolHandler<T extends AppTool> = (input: ToolInput<T>) => Promise<ToolOutput<T>>;
|
|
4
|
+
export type ToolHandlers<T extends AppToolsSpec> = {
|
|
5
|
+
[K in keyof T]: ToolHandler<T[K]>;
|
|
6
|
+
};
|
|
7
|
+
export type McpHandle = {
|
|
8
|
+
address: string;
|
|
9
|
+
dispose: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
export type App<T extends AppToolsSpec> = {
|
|
12
|
+
spec: AppSpec<T>;
|
|
13
|
+
tools: ToolHandlers<T>;
|
|
14
|
+
cli: () => Command;
|
|
15
|
+
run: (argv?: readonly string[]) => Promise<void>;
|
|
16
|
+
mcp: () => Promise<McpHandle>;
|
|
17
|
+
};
|
|
18
|
+
export type AppSetup<T extends AppToolsSpec> = () => ToolHandlers<T>;
|
|
19
|
+
export type AppOptions<T extends AppToolsSpec> = {
|
|
20
|
+
spec: AppSpec<T>;
|
|
21
|
+
setup: AppSetup<T>;
|
|
22
|
+
startup?: (app: App<T>) => void | Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
export declare function createApp<T extends AppToolsSpec>(options: App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C/C,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACjB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAInB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD,CAAC;AAMF,wBAAgB,SAAS,CAAC,CAAC,SAAS,YAAY,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CActF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const createTestApp: () => import("./app.js").App<{
|
|
2
|
+
readonly echo: import("../app.js").AppTool<import("zod").ZodObject<{
|
|
3
|
+
text: import("zod").ZodString;
|
|
4
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
5
|
+
text: import("zod").ZodString;
|
|
6
|
+
}, import("zod/v4/core").$strip>, import("@cmdless/rpc-sdk").RpcProtocol>;
|
|
7
|
+
}>;
|
|
8
|
+
export default createTestApp;
|
|
9
|
+
//# sourceMappingURL=app.fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.fixture.d.ts","sourceRoot":"","sources":["../../src/node/app.fixture.ts"],"names":[],"mappings":"AAaA,QAAA,MAAM,aAAa;;;;;;EAKjB,CAAC;eAEY,aAAa"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineApp } from '../index.js';
|
|
2
|
+
import { createApp } from './index.js';
|
|
3
|
+
const spec = defineApp(({ tool, z }) => ({
|
|
4
|
+
name: 'test-fixture-app',
|
|
5
|
+
tools: {
|
|
6
|
+
echo: tool('echo', 'Echo input', {
|
|
7
|
+
input: z.object({ text: z.string() }),
|
|
8
|
+
output: z.object({ text: z.string() }),
|
|
9
|
+
}),
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
const createTestApp = createApp({
|
|
13
|
+
spec,
|
|
14
|
+
setup: () => ({
|
|
15
|
+
echo: async ({ text }) => ({ text }),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
export default createTestApp;
|
|
19
|
+
if (import.meta.url === `file://${process.argv[1]}`)
|
|
20
|
+
await createTestApp().run();
|
|
21
|
+
//# sourceMappingURL=app.fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.fixture.js","sourceRoot":"","sources":["../../src/node/app.fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,IAAI,EAAE,kBAAkB;IACxB,KAAK,EAAE;QACL,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE;YAC/B,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YACrC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;SACvC,CAAC;KACH;CACF,CAAC,CAAC,CAAC;AAEJ,MAAM,aAAa,GAAG,SAAS,CAAC;IAC9B,IAAI;IACJ,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACZ,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;KACrC,CAAC;CACH,CAAC,CAAC;AAEH,eAAe,aAAa,CAAC;AAE7B,IAAI,OAAO,IAAI,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;IACjD,MAAM,aAAa,EAAE,CAAC,GAAG,EAAE,CAAC"}
|