@gtkx/mcp 2.0.0-beta.1 → 2.0.0-beta.11

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.
Files changed (44) hide show
  1. package/README.md +6 -169
  2. package/dist/app-router.d.ts +7 -7
  3. package/dist/app-router.d.ts.map +1 -1
  4. package/dist/app-router.js +63 -32
  5. package/dist/app-router.js.map +1 -1
  6. package/dist/connection-registry.d.ts +0 -1
  7. package/dist/connection-registry.d.ts.map +1 -1
  8. package/dist/connection-registry.js +0 -3
  9. package/dist/connection-registry.js.map +1 -1
  10. package/dist/internal.d.ts +2 -1
  11. package/dist/internal.d.ts.map +1 -1
  12. package/dist/internal.js +2 -1
  13. package/dist/internal.js.map +1 -1
  14. package/dist/protocol/schemas.d.ts +2 -7
  15. package/dist/protocol/schemas.d.ts.map +1 -1
  16. package/dist/protocol/schemas.js +1 -7
  17. package/dist/protocol/schemas.js.map +1 -1
  18. package/dist/reference.d.ts.map +1 -1
  19. package/dist/reference.js +32 -18
  20. package/dist/reference.js.map +1 -1
  21. package/dist/server.d.ts.map +1 -1
  22. package/dist/server.js +110 -62
  23. package/dist/server.js.map +1 -1
  24. package/dist/socket-path.d.ts +11 -0
  25. package/dist/socket-path.d.ts.map +1 -0
  26. package/dist/socket-path.js +74 -0
  27. package/dist/socket-path.js.map +1 -0
  28. package/dist/socket-server.d.ts +3 -1
  29. package/dist/socket-server.d.ts.map +1 -1
  30. package/dist/socket-server.js +48 -32
  31. package/dist/socket-server.js.map +1 -1
  32. package/dist/tool-filter.d.ts.map +1 -1
  33. package/dist/tool-filter.js +1 -3
  34. package/dist/tool-filter.js.map +1 -1
  35. package/package.json +22 -8
  36. package/src/app-router.ts +84 -39
  37. package/src/connection-registry.ts +0 -3
  38. package/src/internal.ts +4 -1
  39. package/src/protocol/schemas.ts +1 -14
  40. package/src/reference.ts +48 -19
  41. package/src/server.ts +133 -64
  42. package/src/socket-path.ts +103 -0
  43. package/src/socket-server.ts +61 -37
  44. package/src/tool-filter.ts +1 -4
package/README.md CHANGED
@@ -1,174 +1,11 @@
1
- <p align="center">
2
- <img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/logo.svg" alt="GTKX" width="100" />
3
- </p>
1
+ # @gtkx/mcp
4
2
 
5
- <h1 align="center">GTKX</h1>
3
+ MCP tools for GTKX documentation and running applications.
6
4
 
7
- <p align="center">
8
- The React framework for Linux, built on GTK.<br />
9
- Write native GTK4 desktop applications with React and TypeScript.
10
- Real GTK widgets, the GNOME stack, and standard web tooling.
11
- </p>
5
+ Connect a coding agent to generated widget references and the live application tree. Tools inspect widgets, perform interactions, and capture screenshots. Follow the guide to configure the server and attach a development session.
12
6
 
13
- <p align="center">
14
- <a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/v/create-gtkx?color=cb3837&logo=npm&label=create-gtkx" alt="npm version" /></a>
15
- <a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/dm/create-gtkx?color=cb3837&logo=npm&label=downloads" alt="npm downloads" /></a>
16
- <img src="https://img.shields.io/badge/node-%E2%89%A526.7-339933?logo=node.js&logoColor=white" alt="Node >= 26.7" />
17
- <a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License: MPL-2.0" /></a>
18
- <a href="https://github.com/gtkx-org/gtkx/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/gtkx-org/gtkx/ci.yml?branch=main&logo=github&label=CI" alt="CI status" /></a>
19
- <img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
20
- </p>
7
+ [Guide](https://gtkx.dev/v2/guide/mcp) · [GTKX](https://gtkx.dev)
21
8
 
22
- <p align="center">
23
- <a href="https://gtkx.dev">Homepage</a> &middot;
24
- <a href="https://gtkx.dev/guide/getting-started">Documentation</a> &middot;
25
- <a href="https://github.com/gtkx-org/gtkx/tree/main/examples">Examples</a> &middot;
26
- <a href="https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md">Contributing</a>
27
- </p>
9
+ GTKX runs on Linux with Node.js and system native libraries. See [Getting Started](https://gtkx.dev/v2/guide/getting-started) for supported versions and installation. This README describes the 2.0 beta.
28
10
 
29
- ---
30
-
31
- <p align="center">
32
- <img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/examples/tutorial/assets/screenshot.png" alt="The Tasks app: an Adwaita window with a sidebar of smart views and colored lists on the left, and a boxed task list on the right." />
33
- </p>
34
-
35
- <p align="center">
36
- <em>The Tasks app you build in the <a href="https://gtkx.dev/tutorial/">tutorial</a>.</em>
37
- </p>
38
-
39
- ## Demo
40
-
41
- The intrinsic elements in this snippet render GTK4 widgets, and ordinary React hooks and events drive them:
42
-
43
- ```tsx
44
- import * as Gtk from "@gtkx/gi/gtk";
45
- import { GtkApplication, GtkApplicationWindow, GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
46
- import { createRoot, quit } from "@gtkx/react";
47
- import { useState } from "react";
48
-
49
- const Counter = () => {
50
- const [count, setCount] = useState(0);
51
-
52
- return (
53
- <GtkApplicationWindow
54
- title="Hello GTKX"
55
- defaultWidth={400}
56
- defaultHeight={300}
57
- onCloseRequest={quit}
58
- >
59
- <GtkBox
60
- orientation={Gtk.Orientation.VERTICAL}
61
- spacing={20}
62
- marginTop={40}
63
- marginBottom={40}
64
- marginStart={40}
65
- marginEnd={40}
66
- valign={Gtk.Align.CENTER}
67
- halign={Gtk.Align.CENTER}
68
- >
69
- <GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
70
- <GtkLabel cssClasses={["title-2"]}>{`Count: ${count}`}</GtkLabel>
71
- <GtkButton
72
- label="Increment"
73
- onClicked={() => setCount((c) => c + 1)}
74
- cssClasses={["suggested-action", "pill"]}
75
- />
76
- </GtkBox>
77
- </GtkApplicationWindow>
78
- );
79
- };
80
-
81
- const App = () => (
82
- <GtkApplication>
83
- <Counter />
84
- </GtkApplication>
85
- );
86
-
87
- createRoot().render(<App />);
88
- ```
89
-
90
- This is the [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world) example, with `app.tsx` and `index.tsx` combined into a single snippet. `@gtkx/gi` and `@gtkx/jsx` are per-project bindings generated by the CLI, not packages you install from npm.
91
-
92
- ## Why GTKX
93
-
94
- ### A declarative layer for the GNOME stack
95
-
96
- GTK4 is mature, and GtkBuilder XML can lay out a static interface, but nothing re-renders that interface when your application state changes, and nothing hot-reloads it as you work. GTKX adds that missing layer, and the tooling around it, on top of the stack you already know:
97
-
98
- - a React reconciler that exposes every GObject as a JSX element,
99
- - a CLI for scaffolding, development, and production builds,
100
- - a dev server with Fast Refresh that patches your running UI in place,
101
- - CSS-in-JS styling, React Hook Form-powered Adwaita controls, gettext-backed react-i18next localization, React Spring animations, React Navigation stack, tab, drawer, and split view navigators, and high-level list, grid, and dialog components,
102
- - a Testing Library-style API for querying and driving your widgets in tests,
103
- - and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
104
-
105
- ### The full GNOME API surface
106
-
107
- React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX exposes it: GTK4, Adwaita, and any other GObject-Introspection library on your system. Linux-only by design.
108
-
109
- ### Why Node.js, and why generated bindings
110
-
111
- GTKX runs on Node.js, which puts native modules, the npm ecosystem, and the tooling built for Node.js APIs within reach. GJS is GNOME's own runtime, built on SpiderMonkey rather than V8; node-gtk runs on Node.js but is lightly maintained, on the older nan/V8 ABI rather than N-API, and still centered on GTK3. The [Why GTKX guide](https://gtkx.dev/guide/why-gtkx) covers what running on Node.js means day to day.
112
-
113
- GTKX generates the TypeScript types and the native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. Codegen covers the whole GTK4 and Adwaita surface.
114
-
115
- At runtime, the native Rust core calls straight into the system GTK4, Adwaita, and GLib libraries through libffi, without loading libgirepository at all.
116
-
117
- ## Quick start
118
-
119
- GTKX is Linux-only and needs Node.js 26.7 or later. See [Requirements](#requirements).
120
-
121
- Scaffold a new app with the `create-gtkx` initializer:
122
-
123
- ```sh
124
- npm create gtkx
125
- ```
126
-
127
- The same command works with other package managers: `pnpm create gtkx` or `yarn create gtkx`.
128
-
129
- Then run your new app:
130
-
131
- ```sh
132
- cd my-app
133
- npm run dev
134
- ```
135
-
136
- To go further, follow the [tutorial](https://gtkx.dev/tutorial/).
137
-
138
- ## Documentation
139
-
140
- The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tutorial that builds a complete GNOME app, from scaffolding to packaging and shipping, plus guides and a full API reference.
141
-
142
- **[Read the docs &rarr;](https://gtkx.dev/guide/why-gtkx)**
143
-
144
- ## Requirements
145
-
146
- GTKX is Linux-only. You need:
147
-
148
- - Linux with the GTK4 (4.20 or later), Adwaita (1.8 or later), and GLib development libraries
149
- - Node.js 26.7 or later
150
-
151
- The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
152
-
153
- ## Examples
154
-
155
- Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
156
-
157
- - [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the counter above.
158
- - [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): a React port of the official GTK4 widget showcase, covering lists, dialogs, gestures, CSS, and OpenGL.
159
- - [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): a WebKitWebView-based web browser.
160
- - [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations): a tour of `@gtkx/animated`, React Spring animations driven by the GTK frame clock.
161
- - [`navigation`](https://github.com/gtkx-org/gtkx/tree/main/examples/navigation): a tour of `@gtkx/navigation`, React Navigation's stack, tab, and drawer navigators rendered with libadwaita.
162
- - [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
163
-
164
- ## Status
165
-
166
- GTKX is stable and ready for production use.
167
-
168
- ## Contributing
169
-
170
- Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 26.7 or later, pnpm, and a Rust toolchain.
171
-
172
- ## License
173
-
174
- GTKX is licensed under [MPL-2.0](https://github.com/gtkx-org/gtkx/blob/main/LICENSE).
11
+ [MPL-2.0](https://github.com/gtkx-org/gtkx/blob/main/LICENSE).
@@ -7,25 +7,25 @@ type RegisteredApp = {
7
7
  connection: ProtocolConnection;
8
8
  };
9
9
  declare class AppRouter extends EventTarget {
10
- private static defaultWaitTimeout;
11
10
  private apps;
12
11
  private connectionToApp;
13
- private requestTimeout;
14
12
  private connections;
15
- constructor(connections: AppConnections, options?: {
16
- requestTimeout?: number;
17
- });
13
+ private pendingAppWaits;
14
+ private isDisposed;
15
+ constructor(connections: AppConnections);
18
16
  private resolveTargetApp;
19
17
  private handleRequest;
20
18
  private handleRegister;
21
19
  private toAppError;
22
20
  private removeApp;
21
+ private waitForRegistration;
23
22
  getApps(): AppInfo[];
24
23
  hasConnectedApps(): boolean;
25
24
  getDefaultApp(): RegisteredApp | undefined;
26
25
  getProjectRoot(): string | undefined;
27
- waitForApp(timeout?: number): Promise<AppInfo>;
28
- sendToApp<T>(applicationId: string | undefined, method: string, params?: RequestParams): Promise<T>;
26
+ dispose(): void;
27
+ waitForApp(applicationId?: string, timeout?: number): Promise<AppInfo>;
28
+ sendToApp<T>(applicationId: string | undefined, method: string, params?: RequestParams, waitTimeout?: number): Promise<T>;
29
29
  }
30
30
  export { AppRouter, type AppRegisteredEvent, type AppUnregisteredEvent };
31
31
  //# sourceMappingURL=app-router.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-router.d.ts","sourceRoot":"","sources":["../src/app-router.ts"],"names":[],"mappings":"AACA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,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,CAAC"}
@@ -2,6 +2,10 @@ import { McpError } from "@modelcontextprotocol/sdk/types.js";
2
2
  import { appNotFoundError, CONNECTION_CLOSED_CODE, connectionWriteFailedError, invalidRequestError, methodNotFoundError, noAppConnectedError, protocolErrorFrom, REQUEST_TIMEOUT_CODE, requestTimeoutError, } from "./protocol/errors.js";
3
3
  import { RegisterParamsSchema } from "./protocol/schemas.js";
4
4
  const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
5
+ const DEFAULT_APP_TIMEOUT_MS = 10_000;
6
+ const routerStoppedError = () => new Error("GTKX MCP server stopped while waiting for an application");
7
+ const appWaitTimeoutError = (timeout) => new Error(`Timeout waiting for app registration after ${String(timeout)}ms. ` +
8
+ "Make sure your GTKX app is running with 'gtkx dev'.");
5
9
  function appRegisteredEvent(info) {
6
10
  return new CustomEvent("appRegistered", { detail: info });
7
11
  }
@@ -9,15 +13,14 @@ function appUnregisteredEvent(applicationId) {
9
13
  return new CustomEvent("appUnregistered", { detail: applicationId });
10
14
  }
11
15
  class AppRouter extends EventTarget {
12
- static defaultWaitTimeout = 10_000;
13
16
  apps = new Map();
14
17
  connectionToApp = new Map();
15
- requestTimeout;
16
18
  connections;
17
- constructor(connections, options = {}) {
19
+ pendingAppWaits = new Set();
20
+ isDisposed = false;
21
+ constructor(connections) {
18
22
  super();
19
23
  this.connections = connections;
20
- this.requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS;
21
24
  this.connections.onRequest = (connection, request) => this.handleRequest(connection, request);
22
25
  this.connections.addEventListener("disconnection", (event) => {
23
26
  this.removeApp(event.detail);
@@ -34,6 +37,9 @@ class AppRouter extends EventTarget {
34
37
  throw noAppConnectedError();
35
38
  }
36
39
  handleRequest(connection, request) {
40
+ if (this.isDisposed) {
41
+ return Promise.reject(routerStoppedError());
42
+ }
37
43
  if (request.method === "app.register") {
38
44
  return Promise.resolve(this.handleRegister(connection, request));
39
45
  }
@@ -49,14 +55,10 @@ class AppRouter extends EventTarget {
49
55
  throw invalidRequestError(parseResult.error.message);
50
56
  }
51
57
  const params = parseResult.data;
52
- const appInfo = {
53
- applicationId: params.applicationId,
54
- pid: params.pid,
55
- ...(params.projectRoot !== undefined && { projectRoot: params.projectRoot }),
56
- };
57
- this.apps.set(params.applicationId, { info: appInfo, connection });
58
+ this.removeApp(connection);
59
+ this.apps.set(params.applicationId, { info: params, connection });
58
60
  this.connectionToApp.set(connection.id, params.applicationId);
59
- this.dispatchEvent(appRegisteredEvent(appInfo));
61
+ this.dispatchEvent(appRegisteredEvent(params));
60
62
  return { success: true };
61
63
  }
62
64
  toAppError(app, error) {
@@ -65,7 +67,7 @@ class AppRouter extends EventTarget {
65
67
  return connectionWriteFailedError(app.info.applicationId);
66
68
  }
67
69
  if (error.code === REQUEST_TIMEOUT_CODE) {
68
- return requestTimeoutError(this.requestTimeout);
70
+ return requestTimeoutError(DEFAULT_REQUEST_TIMEOUT_MS);
69
71
  }
70
72
  return protocolErrorFrom(error);
71
73
  }
@@ -81,6 +83,33 @@ class AppRouter extends EventTarget {
81
83
  this.apps.delete(applicationId);
82
84
  this.dispatchEvent(appUnregisteredEvent(applicationId));
83
85
  }
86
+ async waitForRegistration(applicationId, timeout) {
87
+ const controller = new AbortController();
88
+ const { promise, reject, resolve } = Promise.withResolvers();
89
+ const rejectWait = (error) => {
90
+ controller.abort();
91
+ reject(error);
92
+ };
93
+ const pendingWait = { reject: rejectWait };
94
+ const timeoutId = setTimeout(() => {
95
+ rejectWait(appWaitTimeoutError(timeout));
96
+ }, timeout);
97
+ this.addEventListener("appRegistered", (event) => {
98
+ const info = event.detail;
99
+ if (applicationId === undefined || info.applicationId === applicationId) {
100
+ resolve(info);
101
+ }
102
+ }, { signal: controller.signal });
103
+ this.pendingAppWaits.add(pendingWait);
104
+ try {
105
+ return await promise;
106
+ }
107
+ finally {
108
+ clearTimeout(timeoutId);
109
+ controller.abort();
110
+ this.pendingAppWaits.delete(pendingWait);
111
+ }
112
+ }
84
113
  getApps() {
85
114
  return this.apps.values().map((app) => app.info).toArray();
86
115
  }
@@ -94,29 +123,31 @@ class AppRouter extends EventTarget {
94
123
  getProjectRoot() {
95
124
  return this.getDefaultApp()?.info.projectRoot;
96
125
  }
97
- waitForApp(timeout = AppRouter.defaultWaitTimeout) {
98
- const defaultApp = this.getDefaultApp();
99
- if (defaultApp) {
100
- return Promise.resolve(defaultApp.info);
101
- }
102
- return new Promise((resolve, reject) => {
103
- const timeoutId = setTimeout(() => {
104
- this.removeEventListener("appRegistered", onRegister);
105
- reject(new Error(`Timeout waiting for app registration after ${String(timeout)}ms. ` +
106
- "Make sure your GTKX app is running with 'gtkx dev'."));
107
- }, timeout);
108
- const onRegister = (event) => {
109
- clearTimeout(timeoutId);
110
- this.removeEventListener("appRegistered", onRegister);
111
- resolve(event.detail);
112
- };
113
- this.addEventListener("appRegistered", onRegister);
114
- });
126
+ dispose() {
127
+ if (this.isDisposed) {
128
+ return;
129
+ }
130
+ this.isDisposed = true;
131
+ const error = routerStoppedError();
132
+ for (const pendingWait of this.pendingAppWaits) {
133
+ pendingWait.reject(error);
134
+ }
135
+ }
136
+ waitForApp(applicationId, timeout = DEFAULT_APP_TIMEOUT_MS) {
137
+ if (this.isDisposed) {
138
+ return Promise.reject(routerStoppedError());
139
+ }
140
+ const app = applicationId === undefined ? this.getDefaultApp() : this.apps.get(applicationId);
141
+ if (app) {
142
+ return Promise.resolve(app.info);
143
+ }
144
+ return this.waitForRegistration(applicationId, timeout);
115
145
  }
116
- async sendToApp(applicationId, method, params) {
146
+ async sendToApp(applicationId, method, params, waitTimeout) {
147
+ await this.waitForApp(applicationId, waitTimeout);
117
148
  const app = this.resolveTargetApp(applicationId);
118
149
  try {
119
- return await app.connection.send(method, params, this.requestTimeout);
150
+ return await app.connection.send(method, params, DEFAULT_REQUEST_TIMEOUT_MS);
120
151
  }
121
152
  catch (error) {
122
153
  if (error instanceof McpError) {
@@ -1 +1 @@
1
- {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D,MAAM,CACF,IAAI,KAAK,CACL,8CAA8C,MAAM,CAAC,OAAO,CAAC,MAAM;oBACnE,qDAAqD,CACxD,CACJ,CAAC;YACN,CAAC,EAAE,OAAO,CAAC,CAAC;YAEZ,MAAM,UAAU,GAAG,CAAC,KAAY,EAAQ,EAAE;gBACtC,YAAY,CAAC,SAAS,CAAC,CAAC;gBACxB,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;gBACtD,OAAO,CAAE,KAA4B,CAAC,MAAM,CAAC,CAAC;YAClD,CAAC,CAAC;YAEF,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,SAAS,CAAI,aAAiC,EAAE,MAAc,EAAE,MAAsB;QACxF,MAAM,GAAG,GAAG,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAEjD,IAAI,CAAC;YACD,OAAO,MAAM,GAAG,CAAC,UAAU,CAAC,IAAI,CAAI,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACtC,CAAC;YAED,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;;AAGL,OAAO,EAAE,SAAS,EAAsD,CAAC","sourcesContent":["import { type JSONRPCRequest, McpError, type Result } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { AppConnections, ConnectionEvent, ProtocolConnection, RequestParams } from \"./transport.js\";\nimport {\n appNotFoundError,\n CONNECTION_CLOSED_CODE,\n connectionWriteFailedError,\n invalidRequestError,\n methodNotFoundError,\n noAppConnectedError,\n type ProtocolError,\n protocolErrorFrom,\n REQUEST_TIMEOUT_CODE,\n requestTimeoutError,\n} from \"./protocol/errors.js\";\nimport { type AppInfo, RegisterParamsSchema } from \"./protocol/schemas.js\";\n\ntype AppRegisteredEvent = CustomEvent<AppInfo>;\ntype AppUnregisteredEvent = CustomEvent<string>;\n\ntype RegisteredApp = {\n info: AppInfo;\n connection: ProtocolConnection;\n};\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 30_000;\n\nfunction appRegisteredEvent(info: AppInfo): AppRegisteredEvent {\n return new CustomEvent(\"appRegistered\", { detail: info });\n}\n\nfunction appUnregisteredEvent(applicationId: string): AppUnregisteredEvent {\n return new CustomEvent(\"appUnregistered\", { detail: applicationId });\n}\n\nclass AppRouter extends EventTarget {\n private static defaultWaitTimeout = 10_000;\n\n private apps: Map<string, RegisteredApp> = new Map();\n\n private connectionToApp: Map<string, string> = new Map();\n\n private requestTimeout: number;\n\n private connections: AppConnections;\n\n constructor(connections: AppConnections, options: { requestTimeout?: number } = {}) {\n super();\n this.connections = connections;\n this.requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS;\n this.connections.onRequest = (connection, request) => this.handleRequest(connection, request);\n\n this.connections.addEventListener(\"disconnection\", (event) => {\n this.removeApp((event as ConnectionEvent).detail);\n });\n }\n\n private resolveTargetApp(applicationId: string | undefined): RegisteredApp {\n const app = applicationId ? this.apps.get(applicationId) : this.getDefaultApp();\n\n if (app) {\n return app;\n }\n\n if (applicationId) {\n throw appNotFoundError(applicationId);\n }\n\n throw noAppConnectedError();\n }\n\n private handleRequest(connection: ProtocolConnection, request: JSONRPCRequest): Promise<Result> {\n if (request.method === \"app.register\") {\n return Promise.resolve(this.handleRegister(connection, request));\n }\n\n if (request.method === \"app.unregister\") {\n this.removeApp(connection);\n\n return Promise.resolve({ success: true });\n }\n\n return Promise.reject(methodNotFoundError(request.method));\n }\n\n private handleRegister(connection: ProtocolConnection, request: JSONRPCRequest): Result {\n const parseResult = RegisterParamsSchema.safeParse(request.params);\n\n if (!parseResult.success) {\n throw invalidRequestError(parseResult.error.message);\n }\n\n const params = parseResult.data;\n\n const appInfo: AppInfo = {\n applicationId: params.applicationId,\n pid: params.pid,\n ...(params.projectRoot !== undefined && { projectRoot: params.projectRoot }),\n };\n\n this.apps.set(params.applicationId, { info: appInfo, connection });\n this.connectionToApp.set(connection.id, params.applicationId);\n this.dispatchEvent(appRegisteredEvent(appInfo));\n\n return { success: true };\n }\n\n private toAppError(app: RegisteredApp, error: McpError): ProtocolError {\n if (error.code === CONNECTION_CLOSED_CODE) {\n this.removeApp(app.connection);\n\n return connectionWriteFailedError(app.info.applicationId);\n }\n\n if (error.code === REQUEST_TIMEOUT_CODE) {\n return requestTimeoutError(this.requestTimeout);\n }\n\n return protocolErrorFrom(error);\n }\n\n private removeApp(connection: ProtocolConnection): void {\n const applicationId = this.connectionToApp.get(connection.id);\n this.connectionToApp.delete(connection.id);\n\n if (applicationId === undefined) {\n return;\n }\n\n if (this.apps.get(applicationId)?.connection !== connection) {\n return;\n }\n\n this.apps.delete(applicationId);\n this.dispatchEvent(appUnregisteredEvent(applicationId));\n }\n\n getApps(): AppInfo[] {\n return this.apps.values().map((app) => app.info).toArray();\n }\n\n hasConnectedApps(): boolean {\n return this.apps.size > 0;\n }\n\n getDefaultApp(): RegisteredApp | undefined {\n const first = this.apps.values().next();\n\n return first.done ? undefined : first.value;\n }\n\n getProjectRoot(): string | undefined {\n return this.getDefaultApp()?.info.projectRoot;\n }\n\n waitForApp(timeout: number = AppRouter.defaultWaitTimeout): Promise<AppInfo> {\n const defaultApp = this.getDefaultApp();\n\n if (defaultApp) {\n return Promise.resolve(defaultApp.info);\n }\n\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n this.removeEventListener(\"appRegistered\", onRegister);\n\n reject(\n new Error(\n `Timeout waiting for app registration after ${String(timeout)}ms. ` +\n \"Make sure your GTKX app is running with 'gtkx dev'.\",\n ),\n );\n }, timeout);\n\n const onRegister = (event: Event): void => {\n clearTimeout(timeoutId);\n this.removeEventListener(\"appRegistered\", onRegister);\n resolve((event as AppRegisteredEvent).detail);\n };\n\n this.addEventListener(\"appRegistered\", onRegister);\n });\n }\n\n async sendToApp<T>(applicationId: string | undefined, method: string, params?: RequestParams): Promise<T> {\n const app = this.resolveTargetApp(applicationId);\n\n try {\n return await app.connection.send<T>(method, params, this.requestTimeout);\n } catch (error) {\n if (error instanceof McpError) {\n throw this.toAppError(app, error);\n }\n\n throw error;\n }\n }\n}\n\nexport { AppRouter, type AppRegisteredEvent, type AppUnregisteredEvent };\n"]}
1
+ {"version":3,"file":"app-router.js","sourceRoot":"","sources":["../src/app-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAe,MAAM,oCAAoC,CAAC;AAEhG,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EAEnB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAgB,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAW3E,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAEtC,MAAM,kBAAkB,GAAG,GAAU,EAAE,CAAC,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;AAE9G,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAS,EAAE,CACnD,IAAI,KAAK,CACL,8CAA8C,MAAM,CAAC,OAAO,CAAC,MAAM;IACnE,qDAAqD,CACxD,CAAC;AAEN,SAAS,kBAAkB,CAAC,IAAa;IACrC,OAAO,IAAI,WAAW,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,oBAAoB,CAAC,aAAqB;IAC/C,OAAO,IAAI,WAAW,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;AACzE,CAAC;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K,CAAC,CAAC;YACtC,CAAC;YAED,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AAED,OAAO,EAAE,SAAS,EAAsD,CAAC","sourcesContent":["import { type JSONRPCRequest, McpError, type Result } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { AppConnections, ConnectionEvent, ProtocolConnection, RequestParams } from \"./transport.js\";\nimport {\n appNotFoundError,\n CONNECTION_CLOSED_CODE,\n connectionWriteFailedError,\n invalidRequestError,\n methodNotFoundError,\n noAppConnectedError,\n type ProtocolError,\n protocolErrorFrom,\n REQUEST_TIMEOUT_CODE,\n requestTimeoutError,\n} from \"./protocol/errors.js\";\nimport { type AppInfo, RegisterParamsSchema } from \"./protocol/schemas.js\";\n\ntype AppRegisteredEvent = CustomEvent<AppInfo>;\ntype AppUnregisteredEvent = CustomEvent<string>;\ntype PendingAppWait = { reject: (error: Error) => void };\n\ntype RegisteredApp = {\n info: AppInfo;\n connection: ProtocolConnection;\n};\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 30_000;\nconst DEFAULT_APP_TIMEOUT_MS = 10_000;\n\nconst routerStoppedError = (): Error => new Error(\"GTKX MCP server stopped while waiting for an application\");\n\nconst appWaitTimeoutError = (timeout: number): Error =>\n new Error(\n `Timeout waiting for app registration after ${String(timeout)}ms. ` +\n \"Make sure your GTKX app is running with 'gtkx dev'.\",\n );\n\nfunction appRegisteredEvent(info: AppInfo): AppRegisteredEvent {\n return new CustomEvent(\"appRegistered\", { detail: info });\n}\n\nfunction appUnregisteredEvent(applicationId: string): AppUnregisteredEvent {\n return new CustomEvent(\"appUnregistered\", { detail: applicationId });\n}\n\nclass AppRouter extends EventTarget {\n private apps: Map<string, RegisteredApp> = new Map();\n\n private connectionToApp: Map<string, string> = new Map();\n\n private connections: AppConnections;\n\n private pendingAppWaits: Set<PendingAppWait> = new Set();\n\n private isDisposed = false;\n\n constructor(connections: AppConnections) {\n super();\n this.connections = connections;\n this.connections.onRequest = (connection, request) => this.handleRequest(connection, request);\n\n this.connections.addEventListener(\"disconnection\", (event) => {\n this.removeApp((event as ConnectionEvent).detail);\n });\n }\n\n private resolveTargetApp(applicationId: string | undefined): RegisteredApp {\n const app = applicationId ? this.apps.get(applicationId) : this.getDefaultApp();\n\n if (app) {\n return app;\n }\n\n if (applicationId) {\n throw appNotFoundError(applicationId);\n }\n\n throw noAppConnectedError();\n }\n\n private handleRequest(connection: ProtocolConnection, request: JSONRPCRequest): Promise<Result> {\n if (this.isDisposed) {\n return Promise.reject(routerStoppedError());\n }\n\n if (request.method === \"app.register\") {\n return Promise.resolve(this.handleRegister(connection, request));\n }\n\n if (request.method === \"app.unregister\") {\n this.removeApp(connection);\n\n return Promise.resolve({ success: true });\n }\n\n return Promise.reject(methodNotFoundError(request.method));\n }\n\n private handleRegister(connection: ProtocolConnection, request: JSONRPCRequest): Result {\n const parseResult = RegisterParamsSchema.safeParse(request.params);\n\n if (!parseResult.success) {\n throw invalidRequestError(parseResult.error.message);\n }\n\n const params = parseResult.data;\n this.removeApp(connection);\n this.apps.set(params.applicationId, { info: params, connection });\n this.connectionToApp.set(connection.id, params.applicationId);\n this.dispatchEvent(appRegisteredEvent(params));\n\n return { success: true };\n }\n\n private toAppError(app: RegisteredApp, error: McpError): ProtocolError {\n if (error.code === CONNECTION_CLOSED_CODE) {\n this.removeApp(app.connection);\n\n return connectionWriteFailedError(app.info.applicationId);\n }\n\n if (error.code === REQUEST_TIMEOUT_CODE) {\n return requestTimeoutError(DEFAULT_REQUEST_TIMEOUT_MS);\n }\n\n return protocolErrorFrom(error);\n }\n\n private removeApp(connection: ProtocolConnection): void {\n const applicationId = this.connectionToApp.get(connection.id);\n this.connectionToApp.delete(connection.id);\n\n if (applicationId === undefined) {\n return;\n }\n\n if (this.apps.get(applicationId)?.connection !== connection) {\n return;\n }\n\n this.apps.delete(applicationId);\n this.dispatchEvent(appUnregisteredEvent(applicationId));\n }\n\n private async waitForRegistration(applicationId: string | undefined, timeout: number): Promise<AppInfo> {\n const controller = new AbortController();\n const { promise, reject, resolve } = Promise.withResolvers<AppInfo>();\n const rejectWait = (error: Error): void => {\n controller.abort();\n reject(error);\n };\n const pendingWait: PendingAppWait = { reject: rejectWait };\n const timeoutId = setTimeout(() => {\n rejectWait(appWaitTimeoutError(timeout));\n }, timeout);\n\n this.addEventListener(\n \"appRegistered\",\n (event) => {\n const info = (event as AppRegisteredEvent).detail;\n\n if (applicationId === undefined || info.applicationId === applicationId) {\n resolve(info);\n }\n },\n { signal: controller.signal },\n );\n this.pendingAppWaits.add(pendingWait);\n\n try {\n return await promise;\n } finally {\n clearTimeout(timeoutId);\n controller.abort();\n this.pendingAppWaits.delete(pendingWait);\n }\n }\n\n getApps(): AppInfo[] {\n return this.apps.values().map((app) => app.info).toArray();\n }\n\n hasConnectedApps(): boolean {\n return this.apps.size > 0;\n }\n\n getDefaultApp(): RegisteredApp | undefined {\n const first = this.apps.values().next();\n\n return first.done ? undefined : first.value;\n }\n\n getProjectRoot(): string | undefined {\n return this.getDefaultApp()?.info.projectRoot;\n }\n\n dispose(): void {\n if (this.isDisposed) {\n return;\n }\n\n this.isDisposed = true;\n const error = routerStoppedError();\n\n for (const pendingWait of this.pendingAppWaits) {\n pendingWait.reject(error);\n }\n }\n\n waitForApp(applicationId?: string, timeout: number = DEFAULT_APP_TIMEOUT_MS): Promise<AppInfo> {\n if (this.isDisposed) {\n return Promise.reject(routerStoppedError());\n }\n\n const app = applicationId === undefined ? this.getDefaultApp() : this.apps.get(applicationId);\n\n if (app) {\n return Promise.resolve(app.info);\n }\n\n return this.waitForRegistration(applicationId, timeout);\n }\n\n async sendToApp<T>(\n applicationId: string | undefined,\n method: string,\n params?: RequestParams,\n waitTimeout?: number,\n ): Promise<T> {\n await this.waitForApp(applicationId, waitTimeout);\n const app = this.resolveTargetApp(applicationId);\n\n try {\n return await app.connection.send<T>(method, params, DEFAULT_REQUEST_TIMEOUT_MS);\n } catch (error) {\n if (error instanceof McpError) {\n throw this.toAppError(app, error);\n }\n\n throw error;\n }\n }\n}\n\nexport { AppRouter, type AppRegisteredEvent, type AppUnregisteredEvent };\n"]}
@@ -1,7 +1,6 @@
1
1
  import type { Socket } from "node:net";
2
2
  import { type AppConnections, type ConnectionRequestHandler, ProtocolConnection } from "./transport.js";
3
3
  declare class ConnectionRegistry extends EventTarget implements AppConnections {
4
- private connections;
5
4
  private sockets;
6
5
  onRequest: ConnectionRequestHandler;
7
6
  register(socket: Socket): ProtocolConnection;
@@ -1 +1 @@
1
- {"version":3,"file":"connection-registry.d.ts","sourceRoot":"","sources":["../src/connection-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EACH,KAAK,cAAc,EAGnB,KAAK,wBAAwB,EAC7B,kBAAkB,EACrB,MAAM,gBAAgB,CAAC;AAExB,cAAM,kBAAmB,SAAQ,WAAY,YAAW,cAAc;IAClE,OAAO,CAAC,WAAW,CAA8C;IACjE,OAAO,CAAC,OAAO,CAAkC;IAEjD,SAAS,EAAE,wBAAwB,CAAiF;IAEpH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB;IAiB5C,OAAO,IAAI,IAAI;CAKlB;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"connection-registry.d.ts","sourceRoot":"","sources":["../src/connection-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EACH,KAAK,cAAc,EAGnB,KAAK,wBAAwB,EAC7B,kBAAkB,EACrB,MAAM,gBAAgB,CAAC;AAExB,cAAM,kBAAmB,SAAQ,WAAY,YAAW,cAAc;IAClE,OAAO,CAAC,OAAO,CAAkC;IAEjD,SAAS,EAAE,wBAAwB,CAAiF;IAEpH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB;IAe5C,OAAO,IAAI,IAAI;CAKlB;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1,19 +1,16 @@
1
1
  import { methodNotFoundError } from "./protocol/errors.js";
2
2
  import { connectionDisconnectionEvent, connectionErrorEvent, ProtocolConnection, } from "./transport.js";
3
3
  class ConnectionRegistry extends EventTarget {
4
- connections = new Map();
5
4
  sockets = new Map();
6
5
  onRequest = (_connection, request) => Promise.reject(methodNotFoundError(request.method));
7
6
  register(socket) {
8
7
  const connection = ProtocolConnection.fromSocket(socket, {
9
8
  onClose: () => {
10
- this.connections.delete(connection.id);
11
9
  this.sockets.delete(connection.id);
12
10
  this.dispatchEvent(connectionDisconnectionEvent(connection));
13
11
  },
14
12
  onError: (error) => this.dispatchEvent(connectionErrorEvent(error)),
15
13
  });
16
- this.connections.set(connection.id, connection);
17
14
  this.sockets.set(connection.id, socket);
18
15
  connection.fallbackRequestHandler = (request) => this.onRequest(connection, request);
19
16
  return connection;
@@ -1 +1 @@
1
- {"version":3,"file":"connection-registry.js","sourceRoot":"","sources":["../src/connection-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAEH,4BAA4B,EAC5B,oBAAoB,EAEpB,kBAAkB,GACrB,MAAM,gBAAgB,CAAC;AAExB,MAAM,kBAAmB,SAAQ,WAAW;IAChC,WAAW,GAAoC,IAAI,GAAG,EAAE,CAAC;IACzD,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEjD,SAAS,GAA6B,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAEpH,QAAQ,CAAC,MAAc;QACnB,MAAM,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,MAAM,EAAE;YACrD,OAAO,EAAE,GAAG,EAAE;gBACV,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;gBACvC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;gBACnC,IAAI,CAAC,aAAa,CAAC,4BAA4B,CAAC,UAAU,CAAC,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;SACtE,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACxC,UAAU,CAAC,sBAAsB,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAErF,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,OAAO;QACH,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACzC,MAAM,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;IACL,CAAC;CACJ;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import type { Socket } from \"node:net\";\nimport { methodNotFoundError } from \"./protocol/errors.js\";\nimport {\n type AppConnections,\n connectionDisconnectionEvent,\n connectionErrorEvent,\n type ConnectionRequestHandler,\n ProtocolConnection,\n} from \"./transport.js\";\n\nclass ConnectionRegistry extends EventTarget implements AppConnections {\n private connections: Map<string, ProtocolConnection> = new Map();\n private sockets: Map<string, Socket> = new Map();\n\n onRequest: ConnectionRequestHandler = (_connection, request) => Promise.reject(methodNotFoundError(request.method));\n\n register(socket: Socket): ProtocolConnection {\n const connection = ProtocolConnection.fromSocket(socket, {\n onClose: () => {\n this.connections.delete(connection.id);\n this.sockets.delete(connection.id);\n this.dispatchEvent(connectionDisconnectionEvent(connection));\n },\n onError: (error) => this.dispatchEvent(connectionErrorEvent(error)),\n });\n\n this.connections.set(connection.id, connection);\n this.sockets.set(connection.id, socket);\n connection.fallbackRequestHandler = (request) => this.onRequest(connection, request);\n\n return connection;\n }\n\n dispose(): void {\n for (const socket of this.sockets.values()) {\n socket.destroy();\n }\n }\n}\n\nexport { ConnectionRegistry };\n"]}
1
+ {"version":3,"file":"connection-registry.js","sourceRoot":"","sources":["../src/connection-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAEH,4BAA4B,EAC5B,oBAAoB,EAEpB,kBAAkB,GACrB,MAAM,gBAAgB,CAAC;AAExB,MAAM,kBAAmB,SAAQ,WAAW;IAChC,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEjD,SAAS,GAA6B,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAEpH,QAAQ,CAAC,MAAc;QACnB,MAAM,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,MAAM,EAAE;YACrD,OAAO,EAAE,GAAG,EAAE;gBACV,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;gBACnC,IAAI,CAAC,aAAa,CAAC,4BAA4B,CAAC,UAAU,CAAC,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;SACtE,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACxC,UAAU,CAAC,sBAAsB,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAErF,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,OAAO;QACH,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACzC,MAAM,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;IACL,CAAC;CACJ;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import type { Socket } from \"node:net\";\nimport { methodNotFoundError } from \"./protocol/errors.js\";\nimport {\n type AppConnections,\n connectionDisconnectionEvent,\n connectionErrorEvent,\n type ConnectionRequestHandler,\n ProtocolConnection,\n} from \"./transport.js\";\n\nclass ConnectionRegistry extends EventTarget implements AppConnections {\n private sockets: Map<string, Socket> = new Map();\n\n onRequest: ConnectionRequestHandler = (_connection, request) => Promise.reject(methodNotFoundError(request.method));\n\n register(socket: Socket): ProtocolConnection {\n const connection = ProtocolConnection.fromSocket(socket, {\n onClose: () => {\n this.sockets.delete(connection.id);\n this.dispatchEvent(connectionDisconnectionEvent(connection));\n },\n onError: (error) => this.dispatchEvent(connectionErrorEvent(error)),\n });\n\n this.sockets.set(connection.id, socket);\n connection.fallbackRequestHandler = (request) => this.onRequest(connection, request);\n\n return connection;\n }\n\n dispose(): void {\n for (const socket of this.sockets.values()) {\n socket.destroy();\n }\n }\n}\n\nexport { ConnectionRegistry };\n"]}
@@ -1,5 +1,6 @@
1
1
  export { invalidRequestError, isConnectionClosedError, methodNotFoundError, propertyNotFoundError, widgetNotFoundError, } from "./protocol/errors.js";
2
- export { DEFAULT_SOCKET_PATH, DEFAULT_SUBTREE_DEPTH, MAX_SUBTREE_WIDGETS, type ParamsSchema, type SerializedProperty, type SerializedWidget, type ServerInitiatedMethod, type ServerRequestParams, ServerRequestParamsSchemas, } from "./protocol/schemas.js";
2
+ export { DEFAULT_SUBTREE_DEPTH, MAX_SUBTREE_WIDGETS, type ParamsSchema, type SerializedProperty, type SerializedWidget, type ServerInitiatedMethod, type ServerRequestParams, ServerRequestParamsSchemas, } from "./protocol/schemas.js";
3
+ export { MCP_SOCKET_PATH_ENV, resolveMcpSocketPath, } from "./socket-path.js";
3
4
  export { ProtocolConnection } from "./transport.js";
4
5
  export type { JSONRPCRequest, Result } from "@modelcontextprotocol/sdk/types.js";
5
6
  //# sourceMappingURL=internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,0BAA0B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,0BAA0B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACH,mBAAmB,EACnB,oBAAoB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC"}
package/dist/internal.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { invalidRequestError, isConnectionClosedError, methodNotFoundError, propertyNotFoundError, widgetNotFoundError, } from "./protocol/errors.js";
2
- export { DEFAULT_SOCKET_PATH, DEFAULT_SUBTREE_DEPTH, MAX_SUBTREE_WIDGETS, ServerRequestParamsSchemas, } from "./protocol/schemas.js";
2
+ export { DEFAULT_SUBTREE_DEPTH, MAX_SUBTREE_WIDGETS, ServerRequestParamsSchemas, } from "./protocol/schemas.js";
3
+ export { MCP_SOCKET_PATH_ENV, resolveMcpSocketPath, } from "./socket-path.js";
3
4
  export { ProtocolConnection } from "./transport.js";
4
5
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EAMnB,0BAA0B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export {\n invalidRequestError,\n isConnectionClosedError,\n methodNotFoundError,\n propertyNotFoundError,\n widgetNotFoundError,\n} from \"./protocol/errors.js\";\nexport {\n DEFAULT_SOCKET_PATH,\n DEFAULT_SUBTREE_DEPTH,\n MAX_SUBTREE_WIDGETS,\n type ParamsSchema,\n type SerializedProperty,\n type SerializedWidget,\n type ServerInitiatedMethod,\n type ServerRequestParams,\n ServerRequestParamsSchemas,\n} from \"./protocol/schemas.js\";\nexport { ProtocolConnection } from \"./transport.js\";\nexport type { JSONRPCRequest, Result } from \"@modelcontextprotocol/sdk/types.js\";\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,qBAAqB,EACrB,mBAAmB,EAMnB,0BAA0B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACH,mBAAmB,EACnB,oBAAoB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export {\n invalidRequestError,\n isConnectionClosedError,\n methodNotFoundError,\n propertyNotFoundError,\n widgetNotFoundError,\n} from \"./protocol/errors.js\";\nexport {\n DEFAULT_SUBTREE_DEPTH,\n MAX_SUBTREE_WIDGETS,\n type ParamsSchema,\n type SerializedProperty,\n type SerializedWidget,\n type ServerInitiatedMethod,\n type ServerRequestParams,\n ServerRequestParamsSchemas,\n} from \"./protocol/schemas.js\";\nexport {\n MCP_SOCKET_PATH_ENV,\n resolveMcpSocketPath,\n} from \"./socket-path.js\";\nexport { ProtocolConnection } from \"./transport.js\";\nexport type { JSONRPCRequest, Result } from \"@modelcontextprotocol/sdk/types.js\";\n"]}
@@ -17,11 +17,7 @@ type SerializedProperty = {
17
17
  widgetId?: string;
18
18
  note?: string;
19
19
  };
20
- type AppInfo = {
21
- applicationId: string;
22
- pid: number;
23
- projectRoot?: string;
24
- };
20
+ type AppInfo = z.output<typeof RegisterParamsSchema>;
25
21
  type ServerRequestParams<Method extends keyof typeof ServerRequestParamsSchemas> = z.infer<(typeof ServerRequestParamsSchemas)[Method]>;
26
22
  type ParamsSchema<Output> = z.ZodType<Output>;
27
23
  type ServerInitiatedMethod = keyof typeof ServerRequestParamsSchemas;
@@ -84,6 +80,5 @@ declare const ServerRequestParamsSchemas: {
84
80
  "widget.fireEvent": typeof fireEventParams;
85
81
  "widget.screenshot": typeof screenshotParams;
86
82
  };
87
- declare const DEFAULT_SOCKET_PATH: string;
88
- export { DEFAULT_SUBTREE_DEPTH, MAX_SUBTREE_WIDGETS, RegisterParamsSchema, widgetIdParams, widgetPropsParams, treeParams, queryParams, typeParams, fireEventParams, screenshotParams, ServerRequestParamsSchemas, DEFAULT_SOCKET_PATH, type SerializedWidget, type SerializedProperty, type AppInfo, type ServerRequestParams, type ParamsSchema, type ServerInitiatedMethod, };
83
+ export { DEFAULT_SUBTREE_DEPTH, MAX_SUBTREE_WIDGETS, RegisterParamsSchema, widgetIdParams, widgetPropsParams, treeParams, queryParams, typeParams, fireEventParams, screenshotParams, ServerRequestParamsSchemas, type SerializedWidget, type SerializedProperty, type AppInfo, type ServerRequestParams, type ParamsSchema, type ServerInitiatedMethod, };
89
84
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/protocol/schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,KAAK,gBAAgB,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,OAAO,GAAG;IACX,aAAa,E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AAkB,EAAE,OAAO,eAAe,CAAC;IAC3C,mBAAmB,EAAE,OAAO,gBAAgB,CAAC;CAUhD,CAAC;AAEF,OAAO,EACH,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,0BAA0B,EAC1B,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,qBAAqB,GAC7B,CAAC"}
@@ -1,5 +1,3 @@
1
- import { tmpdir } from "node:os";
2
- import { join } from "node:path";
3
1
  import { z } from "zod";
4
2
  const RegisterParamsSchema = z.object({
5
3
  applicationId: z.string(),
@@ -47,9 +45,5 @@ const ServerRequestParamsSchemas = {
47
45
  "widget.fireEvent": fireEventParams,
48
46
  "widget.screenshot": screenshotParams,
49
47
  };
50
- const DEFAULT_SOCKET_PATH = join(getRuntimeDir(), "gtkx-mcp.sock");
51
- function getRuntimeDir() {
52
- return process.env.XDG_RUNTIME_DIR ?? tmpdir();
53
- }
54
- export { DEFAULT_SUBTREE_DEPTH, MAX_SUBTREE_WIDGETS, RegisterParamsSchema, widgetIdParams, widgetPropsParams, treeParams, queryParams, typeParams, fireEventParams, screenshotParams, ServerRequestParamsSchemas, DEFAULT_SOCKET_PATH, };
48
+ export { DEFAULT_SUBTREE_DEPTH, MAX_SUBTREE_WIDGETS, RegisterParamsSchema, widgetIdParams, widgetPropsParams, treeParams, queryParams, typeParams, fireEventParams, screenshotParams, ServerRequestParamsSchemas, };
55
49
  //# sourceMappingURL=schemas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/protocol/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,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IACzB,kBAAkB,EAAE,eAAe;IACnC,mBAAmB,EAAE,gBAAgB;CACxC,CAAC;AAEF,MAAM,mBAAmB,GAAW,IAAI,CAAC,aAAa,EAAE,EAAE,eAAe,CAAC,CAAC;AAE3E,SAAS,aAAa;IAClB,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,MAAM,EAAE,CAAC;AACnD,CAAC;AAED,OAAO,EACH,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,GAOtB,CAAC","sourcesContent":["import { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { z } from \"zod\";\n\ntype SerializedWidget = {\n id: string;\n type: string;\n role: string;\n name: string | null;\n text: string | null;\n isSensitive: boolean;\n isVisible: boolean;\n cssClasses: string[];\n children: SerializedWidget[];\n hiddenChildren?: number;\n};\n\ntype SerializedProperty = {\n type: string;\n value: string | number | boolean | string[] | null;\n widgetId?: string;\n note?: string;\n};\n\ntype AppInfo = {\n applicationId: string;\n pid: number;\n projectRoot?: string;\n};\n\ntype ServerRequestParams<Method extends keyof typeof ServerRequestParamsSchemas> = z.infer<\n (typeof ServerRequestParamsSchemas)[Method]\n>;\n\ntype ParamsSchema<Output> = z.ZodType<Output>;\ntype ServerInitiatedMethod = keyof typeof ServerRequestParamsSchemas;\n\nconst RegisterParamsSchema: z.ZodObject<\n {\n applicationId: z.ZodString;\n pid: z.ZodNumber;\n projectRoot: z.ZodOptional<z.ZodString>;\n }\n> = z.object({\n applicationId: z.string(),\n pid: z.number(),\n projectRoot: z.string().optional(),\n});\n\nconst emptyParams: z.ZodObject<Record<string, never>> = z.object({});\n\nconst widgetIdParams: z.ZodObject<{ widgetId: z.ZodString }> = z.object({\n widgetId: z.string(),\n});\n\nconst DEFAULT_SUBTREE_DEPTH = 8;\nconst MAX_SUBTREE_WIDGETS = 30;\n\nconst widgetPropsParams: z.ZodObject<\n {\n widgetId: z.ZodString;\n properties: z.ZodOptional<z.ZodArray<z.ZodString>>;\n maxDepth: z.ZodOptional<z.ZodNumber>;\n }\n> = z.object({\n widgetId: z.string(),\n properties: z.array(z.string()).optional(),\n maxDepth: z.number().int().nonnegative().optional(),\n});\n\nconst treeParams: z.ZodObject<\n { rootId: z.ZodOptional<z.ZodString>; maxDepth: z.ZodOptional<z.ZodNumber> }\n> = z.object({\n rootId: z.string().optional(),\n maxDepth: z.number().int().nonnegative().optional(),\n});\n\nconst queryOptionsSchema: z.ZodObject<\n { name: z.ZodOptional<z.ZodString>; exact: z.ZodOptional<z.ZodBoolean>; timeout: z.ZodOptional<z.ZodNumber> }\n> = z.object({\n name: z.string().optional(),\n exact: z.boolean().optional(),\n timeout: z.number().optional(),\n});\n\nconst queryParams: z.ZodObject<\n {\n by: z.ZodEnum<{ role: \"role\"; text: \"text\"; name: \"name\"; labelText: \"labelText\" }>;\n value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;\n options: z.ZodOptional<typeof queryOptionsSchema>;\n }\n> = z.object({\n by: z.enum([\"role\", \"text\", \"name\", \"labelText\"]),\n value: z.union([z.string(), z.number()]),\n options: queryOptionsSchema.optional(),\n});\n\nconst typeParams: z.ZodObject<\n { widgetId: z.ZodString; text: z.ZodString; clear: z.ZodOptional<z.ZodBoolean> }\n> = z.object({ widgetId: z.string(), text: z.string(), clear: z.boolean().optional() });\n\nconst fireEventParams: z.ZodObject<\n { widgetId: z.ZodString; signal: z.ZodString; args: z.ZodOptional<z.ZodArray<z.ZodUnknown>> }\n> = z.object({ widgetId: z.string(), signal: z.string(), args: z.array(z.unknown()).optional() });\n\nconst screenshotParams: z.ZodObject<\n { windowId: z.ZodOptional<z.ZodString>; path: z.ZodOptional<z.ZodString> }\n> = z.object({\n windowId: z.string().optional(),\n path: z.string().optional(),\n});\n\nconst ServerRequestParamsSchemas: {\n \"app.getWindows\": typeof emptyParams;\n \"widget.getTree\": typeof treeParams;\n \"widget.query\": typeof queryParams;\n \"widget.getProps\": typeof widgetPropsParams;\n \"widget.click\": typeof widgetIdParams;\n \"widget.type\": typeof typeParams;\n \"widget.fireEvent\": typeof fireEventParams;\n \"widget.screenshot\": typeof screenshotParams;\n} = {\n \"app.getWindows\": emptyParams,\n \"widget.getTree\": treeParams,\n \"widget.query\": queryParams,\n \"widget.getProps\": widgetPropsParams,\n \"widget.click\": widgetIdParams,\n \"widget.type\": typeParams,\n \"widget.fireEvent\": fireEventParams,\n \"widget.screenshot\": screenshotParams,\n};\n\nconst DEFAULT_SOCKET_PATH: string = join(getRuntimeDir(), \"gtkx-mcp.sock\");\n\nfunction getRuntimeDir(): string {\n return process.env.XDG_RUNTIME_DIR ?? tmpdir();\n}\n\nexport {\n DEFAULT_SUBTREE_DEPTH,\n MAX_SUBTREE_WIDGETS,\n RegisterParamsSchema,\n widgetIdParams,\n widgetPropsParams,\n treeParams,\n queryParams,\n typeParams,\n fireEventParams,\n screenshotParams,\n ServerRequestParamsSchemas,\n DEFAULT_SOCKET_PATH,\n type SerializedWidget,\n type SerializedProperty,\n type AppInfo,\n type ServerRequestParams,\n type ParamsSchema,\n type ServerInitiatedMethod,\n};\n"]}
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/protocol/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+BxB,MAAM,oBAAoB,GAMtB,CAAC,CAAC,MAAM,CAAC;IACT,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAC;AAEH,MAAM,WAAW,GAAuC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAErE,MAAM,cAAc,GAA2C,CAAC,CAAC,MAAM,CAAC;IACpE,QAAQ,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,CAAC;AAEH,MAAM,UAAU,GAEZ,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAExF,MAAM,eAAe,GAEjB,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAElG,MAAM,gBAAgB,GAElB,CAAC,CAAC,MAAM,CAAC;IACT,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,0BAA0B,GAS5B;IACA,gBAAgB,EAAE,WAAW;IAC7B,gBAAgB,EAAE,UAAU;IAC5B,cAAc,EAAE,WAAW;IAC3B,iBAAiB,EAAE,iBAAiB;IACpC,cAAc,EAAE,cAAc;IAC9B,aAAa,EAAE,UAAU;IACzB,kBAAkB,EAAE,eAAe;IACnC,mBAAmB,EAAE,gBAAgB;CACxC,CAAC;AAEF,OAAO,EACH,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,0BAA0B,GAO7B,CAAC","sourcesContent":["import { z } from \"zod\";\n\ntype SerializedWidget = {\n id: string;\n type: string;\n role: string;\n name: string | null;\n text: string | null;\n isSensitive: boolean;\n isVisible: boolean;\n cssClasses: string[];\n children: SerializedWidget[];\n hiddenChildren?: number;\n};\n\ntype SerializedProperty = {\n type: string;\n value: string | number | boolean | string[] | null;\n widgetId?: string;\n note?: string;\n};\n\ntype AppInfo = z.output<typeof RegisterParamsSchema>;\n\ntype ServerRequestParams<Method extends keyof typeof ServerRequestParamsSchemas> = z.infer<\n (typeof ServerRequestParamsSchemas)[Method]\n>;\n\ntype ParamsSchema<Output> = z.ZodType<Output>;\ntype ServerInitiatedMethod = keyof typeof ServerRequestParamsSchemas;\n\nconst RegisterParamsSchema: z.ZodObject<\n {\n applicationId: z.ZodString;\n pid: z.ZodNumber;\n projectRoot: z.ZodOptional<z.ZodString>;\n }\n> = z.object({\n applicationId: z.string(),\n pid: z.number(),\n projectRoot: z.string().optional(),\n});\n\nconst emptyParams: z.ZodObject<Record<string, never>> = z.object({});\n\nconst widgetIdParams: z.ZodObject<{ widgetId: z.ZodString }> = z.object({\n widgetId: z.string(),\n});\n\nconst DEFAULT_SUBTREE_DEPTH = 8;\nconst MAX_SUBTREE_WIDGETS = 30;\n\nconst widgetPropsParams: z.ZodObject<\n {\n widgetId: z.ZodString;\n properties: z.ZodOptional<z.ZodArray<z.ZodString>>;\n maxDepth: z.ZodOptional<z.ZodNumber>;\n }\n> = z.object({\n widgetId: z.string(),\n properties: z.array(z.string()).optional(),\n maxDepth: z.number().int().nonnegative().optional(),\n});\n\nconst treeParams: z.ZodObject<\n { rootId: z.ZodOptional<z.ZodString>; maxDepth: z.ZodOptional<z.ZodNumber> }\n> = z.object({\n rootId: z.string().optional(),\n maxDepth: z.number().int().nonnegative().optional(),\n});\n\nconst queryOptionsSchema: z.ZodObject<\n { name: z.ZodOptional<z.ZodString>; exact: z.ZodOptional<z.ZodBoolean>; timeout: z.ZodOptional<z.ZodNumber> }\n> = z.object({\n name: z.string().optional(),\n exact: z.boolean().optional(),\n timeout: z.number().optional(),\n});\n\nconst queryParams: z.ZodObject<\n {\n by: z.ZodEnum<{ role: \"role\"; text: \"text\"; name: \"name\"; labelText: \"labelText\" }>;\n value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;\n options: z.ZodOptional<typeof queryOptionsSchema>;\n }\n> = z.object({\n by: z.enum([\"role\", \"text\", \"name\", \"labelText\"]),\n value: z.union([z.string(), z.number()]),\n options: queryOptionsSchema.optional(),\n});\n\nconst typeParams: z.ZodObject<\n { widgetId: z.ZodString; text: z.ZodString; clear: z.ZodOptional<z.ZodBoolean> }\n> = z.object({ widgetId: z.string(), text: z.string(), clear: z.boolean().optional() });\n\nconst fireEventParams: z.ZodObject<\n { widgetId: z.ZodString; signal: z.ZodString; args: z.ZodOptional<z.ZodArray<z.ZodUnknown>> }\n> = z.object({ widgetId: z.string(), signal: z.string(), args: z.array(z.unknown()).optional() });\n\nconst screenshotParams: z.ZodObject<\n { windowId: z.ZodOptional<z.ZodString>; path: z.ZodOptional<z.ZodString> }\n> = z.object({\n windowId: z.string().optional(),\n path: z.string().optional(),\n});\n\nconst ServerRequestParamsSchemas: {\n \"app.getWindows\": typeof emptyParams;\n \"widget.getTree\": typeof treeParams;\n \"widget.query\": typeof queryParams;\n \"widget.getProps\": typeof widgetPropsParams;\n \"widget.click\": typeof widgetIdParams;\n \"widget.type\": typeof typeParams;\n \"widget.fireEvent\": typeof fireEventParams;\n \"widget.screenshot\": typeof screenshotParams;\n} = {\n \"app.getWindows\": emptyParams,\n \"widget.getTree\": treeParams,\n \"widget.query\": queryParams,\n \"widget.getProps\": widgetPropsParams,\n \"widget.click\": widgetIdParams,\n \"widget.type\": typeParams,\n \"widget.fireEvent\": fireEventParams,\n \"widget.screenshot\": screenshotParams,\n};\n\nexport {\n DEFAULT_SUBTREE_DEPTH,\n MAX_SUBTREE_WIDGETS,\n RegisterParamsSchema,\n widgetIdParams,\n widgetPropsParams,\n treeParams,\n queryParams,\n typeParams,\n fireEventParams,\n screenshotParams,\n ServerRequestParamsSchemas,\n type SerializedWidget,\n type SerializedProperty,\n type AppInfo,\n type ServerRequestParams,\n type ParamsSchema,\n type ServerInitiatedMethod,\n};\n"]}