@gtkx/mcp 2.0.0-beta.1 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -40
- package/dist/app-router.d.ts +6 -2
- package/dist/app-router.d.ts.map +1 -1
- package/dist/app-router.js +56 -19
- package/dist/app-router.js.map +1 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -1
- package/dist/internal.js.map +1 -1
- package/dist/protocol/schemas.d.ts +1 -2
- package/dist/protocol/schemas.d.ts.map +1 -1
- package/dist/protocol/schemas.js +1 -7
- package/dist/protocol/schemas.js.map +1 -1
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js +12 -11
- package/dist/reference.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +92 -44
- package/dist/server.js.map +1 -1
- package/dist/socket-path.d.ts +11 -0
- package/dist/socket-path.d.ts.map +1 -0
- package/dist/socket-path.js +74 -0
- package/dist/socket-path.js.map +1 -0
- package/dist/socket-server.d.ts +3 -1
- package/dist/socket-server.d.ts.map +1 -1
- package/dist/socket-server.js +48 -32
- package/dist/socket-server.js.map +1 -1
- package/package.json +9 -7
- package/src/app-router.ts +77 -22
- package/src/internal.ts +4 -1
- package/src/protocol/schemas.ts +0 -9
- package/src/reference.ts +12 -11
- package/src/server.ts +114 -46
- package/src/socket-path.ts +103 -0
- package/src/socket-server.ts +61 -37
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<h1 align="center">GTKX</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
The React framework for Linux
|
|
9
|
-
Write native
|
|
10
|
-
Real
|
|
8
|
+
The React framework for Linux.<br />
|
|
9
|
+
Write native GNOME applications with React and TypeScript.
|
|
10
|
+
Real Adwaita and GTK4 widgets with standard web tooling.
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
@@ -38,11 +38,12 @@
|
|
|
38
38
|
|
|
39
39
|
## Demo
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
This app starts with an Adwaita application shell, renders native GTK4 widgets inside it, and uses ordinary React hooks and events:
|
|
42
42
|
|
|
43
43
|
```tsx
|
|
44
44
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
45
|
-
import {
|
|
45
|
+
import { AdwApplication, AdwApplicationWindow, AdwHeaderBar, AdwToolbarView } from "@gtkx/jsx/adw";
|
|
46
|
+
import { GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
|
|
46
47
|
import { createRoot, quit } from "@gtkx/react";
|
|
47
48
|
import { useState } from "react";
|
|
48
49
|
|
|
@@ -50,38 +51,40 @@ const Counter = () => {
|
|
|
50
51
|
const [count, setCount] = useState(0);
|
|
51
52
|
|
|
52
53
|
return (
|
|
53
|
-
<
|
|
54
|
+
<AdwApplicationWindow
|
|
54
55
|
title="Hello GTKX"
|
|
55
56
|
defaultWidth={400}
|
|
56
57
|
defaultHeight={300}
|
|
57
58
|
onCloseRequest={quit}
|
|
58
59
|
>
|
|
59
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
<AdwToolbarView topBar={<AdwHeaderBar />}>
|
|
61
|
+
<GtkBox
|
|
62
|
+
orientation={Gtk.Orientation.VERTICAL}
|
|
63
|
+
spacing={20}
|
|
64
|
+
marginTop={40}
|
|
65
|
+
marginBottom={40}
|
|
66
|
+
marginStart={40}
|
|
67
|
+
marginEnd={40}
|
|
68
|
+
valign={Gtk.Align.CENTER}
|
|
69
|
+
halign={Gtk.Align.CENTER}
|
|
70
|
+
>
|
|
71
|
+
<GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
|
|
72
|
+
<GtkLabel cssClasses={["title-2"]}>{`Count: ${String(count)}`}</GtkLabel>
|
|
73
|
+
<GtkButton
|
|
74
|
+
label="Increment"
|
|
75
|
+
onClicked={() => setCount((c) => c + 1)}
|
|
76
|
+
cssClasses={["suggested-action", "pill"]}
|
|
77
|
+
/>
|
|
78
|
+
</GtkBox>
|
|
79
|
+
</AdwToolbarView>
|
|
80
|
+
</AdwApplicationWindow>
|
|
78
81
|
);
|
|
79
82
|
};
|
|
80
83
|
|
|
81
84
|
const App = () => (
|
|
82
|
-
<
|
|
85
|
+
<AdwApplication>
|
|
83
86
|
<Counter />
|
|
84
|
-
</
|
|
87
|
+
</AdwApplication>
|
|
85
88
|
);
|
|
86
89
|
|
|
87
90
|
createRoot().render(<App />);
|
|
@@ -91,9 +94,9 @@ This is the [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/
|
|
|
91
94
|
|
|
92
95
|
## Why GTKX
|
|
93
96
|
|
|
94
|
-
###
|
|
97
|
+
### Adwaita-first application development
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
GTKX uses Adwaita as the foundation for applications, windows, navigation, dialogs, and adaptive layouts, with the complete GTK4 toolkit underneath. It adds a declarative React layer and an integrated TypeScript toolchain to the GNOME platform:
|
|
97
100
|
|
|
98
101
|
- a React reconciler that exposes every GObject as a JSX element,
|
|
99
102
|
- a CLI for scaffolding, development, and production builds,
|
|
@@ -102,17 +105,17 @@ GTK4 is mature, and GtkBuilder XML can lay out a static interface, but nothing r
|
|
|
102
105
|
- a Testing Library-style API for querying and driving your widgets in tests,
|
|
103
106
|
- and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
|
|
104
107
|
|
|
105
|
-
###
|
|
108
|
+
### Native GNOME widgets, without a compatibility layer
|
|
106
109
|
|
|
107
|
-
React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX
|
|
110
|
+
React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX renders real Adwaita and GTK4 widgets and exposes any other GObject-Introspection library on your system. It is GNOME-native and Linux-only by design.
|
|
108
111
|
|
|
109
112
|
### Why Node.js, and why generated bindings
|
|
110
113
|
|
|
111
114
|
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
115
|
|
|
113
|
-
GTKX generates the TypeScript types and
|
|
116
|
+
GTKX generates the TypeScript types and native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. `Adw-1` is the sole default GIR root; its GIR include pulls in `Gtk-4.0`, so codegen covers both complete API surfaces. Neither belongs in a GTKX 2 `libraries` list.
|
|
114
117
|
|
|
115
|
-
At runtime, the native Rust core calls straight into the system
|
|
118
|
+
At runtime, the native Rust core calls straight into the system Adwaita, GTK4, and GLib libraries through libffi, without loading libgirepository at all.
|
|
116
119
|
|
|
117
120
|
## Quick start
|
|
118
121
|
|
|
@@ -121,10 +124,10 @@ GTKX is Linux-only and needs Node.js 26.7 or later. See [Requirements](#requirem
|
|
|
121
124
|
Scaffold a new app with the `create-gtkx` initializer:
|
|
122
125
|
|
|
123
126
|
```sh
|
|
124
|
-
npm create gtkx
|
|
127
|
+
npm create gtkx@beta
|
|
125
128
|
```
|
|
126
129
|
|
|
127
|
-
The same command works with other package managers: `pnpm create gtkx` or `yarn create gtkx`.
|
|
130
|
+
The same command works with other package managers: `pnpm create gtkx@beta` or `yarn create gtkx@beta`.
|
|
128
131
|
|
|
129
132
|
Then run your new app:
|
|
130
133
|
|
|
@@ -145,7 +148,7 @@ The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tu
|
|
|
145
148
|
|
|
146
149
|
GTKX is Linux-only. You need:
|
|
147
150
|
|
|
148
|
-
- Linux with the
|
|
151
|
+
- Linux with the Adwaita (1.8 or later), GTK4 (4.20 or later), and GLib development libraries
|
|
149
152
|
- Node.js 26.7 or later
|
|
150
153
|
|
|
151
154
|
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.
|
|
@@ -154,10 +157,10 @@ The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other tar
|
|
|
154
157
|
|
|
155
158
|
Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
|
|
156
159
|
|
|
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):
|
|
159
|
-
- [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser):
|
|
160
|
-
- [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations):
|
|
160
|
+
- [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the Adwaita counter above.
|
|
161
|
+
- [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): the official GTK4 widget showcase in an Adwaita application shell, covering lists, dialogs, gestures, CSS, and OpenGL.
|
|
162
|
+
- [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): an Adwaita browser built around `WebKitWebView`.
|
|
163
|
+
- [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations): an Adwaita showcase for `@gtkx/animated`, with React Spring animations driven by the GTK frame clock.
|
|
161
164
|
- [`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
165
|
- [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
|
|
163
166
|
|
package/dist/app-router.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ declare class AppRouter extends EventTarget {
|
|
|
12
12
|
private connectionToApp;
|
|
13
13
|
private requestTimeout;
|
|
14
14
|
private connections;
|
|
15
|
+
private pendingAppWaits;
|
|
16
|
+
private isDisposed;
|
|
15
17
|
constructor(connections: AppConnections, options?: {
|
|
16
18
|
requestTimeout?: number;
|
|
17
19
|
});
|
|
@@ -20,12 +22,14 @@ declare class AppRouter extends EventTarget {
|
|
|
20
22
|
private handleRegister;
|
|
21
23
|
private toAppError;
|
|
22
24
|
private removeApp;
|
|
25
|
+
private waitForRegistration;
|
|
23
26
|
getApps(): AppInfo[];
|
|
24
27
|
hasConnectedApps(): boolean;
|
|
25
28
|
getDefaultApp(): RegisteredApp | undefined;
|
|
26
29
|
getProjectRoot(): string | undefined;
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
dispose(): void;
|
|
31
|
+
waitForApp(applicationId?: string, timeout?: number): Promise<AppInfo>;
|
|
32
|
+
sendToApp<T>(applicationId: string | undefined, method: string, params?: RequestParams, waitTimeout?: number): Promise<T>;
|
|
29
33
|
}
|
|
30
34
|
export { AppRouter, type AppRegisteredEvent, type AppUnregisteredEvent };
|
|
31
35
|
//# sourceMappingURL=app-router.d.ts.map
|
package/dist/app-router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-router.d.ts","sourceRoot":"","sources":["../src/app-router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAmB,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAazG,OAAO,EAAE,KAAK,OAAO,EAAwB,MAAM,uBAAuB,CAAC;AAE3E,KAAK,kBAAkB,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;AAC/C,KAAK,oBAAoB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"app-router.d.ts","sourceRoot":"","sources":["../src/app-router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAA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rB,OAAO,CAAC,CAAC,CAAC;CAchB;AAED,OAAO,EAAE,SAAS,EAAE,KAAK,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,CAAC"}
|
package/dist/app-router.js
CHANGED
|
@@ -2,6 +2,9 @@ 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 routerStoppedError = () => new Error("GTKX MCP server stopped while waiting for an application");
|
|
6
|
+
const appWaitTimeoutError = (timeout) => new Error(`Timeout waiting for app registration after ${String(timeout)}ms. ` +
|
|
7
|
+
"Make sure your GTKX app is running with 'gtkx dev'.");
|
|
5
8
|
function appRegisteredEvent(info) {
|
|
6
9
|
return new CustomEvent("appRegistered", { detail: info });
|
|
7
10
|
}
|
|
@@ -14,6 +17,8 @@ class AppRouter extends EventTarget {
|
|
|
14
17
|
connectionToApp = new Map();
|
|
15
18
|
requestTimeout;
|
|
16
19
|
connections;
|
|
20
|
+
pendingAppWaits = new Set();
|
|
21
|
+
isDisposed = false;
|
|
17
22
|
constructor(connections, options = {}) {
|
|
18
23
|
super();
|
|
19
24
|
this.connections = connections;
|
|
@@ -34,6 +39,9 @@ class AppRouter extends EventTarget {
|
|
|
34
39
|
throw noAppConnectedError();
|
|
35
40
|
}
|
|
36
41
|
handleRequest(connection, request) {
|
|
42
|
+
if (this.isDisposed) {
|
|
43
|
+
return Promise.reject(routerStoppedError());
|
|
44
|
+
}
|
|
37
45
|
if (request.method === "app.register") {
|
|
38
46
|
return Promise.resolve(this.handleRegister(connection, request));
|
|
39
47
|
}
|
|
@@ -81,6 +89,33 @@ class AppRouter extends EventTarget {
|
|
|
81
89
|
this.apps.delete(applicationId);
|
|
82
90
|
this.dispatchEvent(appUnregisteredEvent(applicationId));
|
|
83
91
|
}
|
|
92
|
+
async waitForRegistration(applicationId, timeout) {
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
const { promise, reject, resolve } = Promise.withResolvers();
|
|
95
|
+
const rejectWait = (error) => {
|
|
96
|
+
controller.abort();
|
|
97
|
+
reject(error);
|
|
98
|
+
};
|
|
99
|
+
const pendingWait = { reject: rejectWait };
|
|
100
|
+
const timeoutId = setTimeout(() => {
|
|
101
|
+
rejectWait(appWaitTimeoutError(timeout));
|
|
102
|
+
}, timeout);
|
|
103
|
+
this.addEventListener("appRegistered", (event) => {
|
|
104
|
+
const info = event.detail;
|
|
105
|
+
if (applicationId === undefined || info.applicationId === applicationId) {
|
|
106
|
+
resolve(info);
|
|
107
|
+
}
|
|
108
|
+
}, { signal: controller.signal });
|
|
109
|
+
this.pendingAppWaits.add(pendingWait);
|
|
110
|
+
try {
|
|
111
|
+
return await promise;
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
clearTimeout(timeoutId);
|
|
115
|
+
controller.abort();
|
|
116
|
+
this.pendingAppWaits.delete(pendingWait);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
84
119
|
getApps() {
|
|
85
120
|
return this.apps.values().map((app) => app.info).toArray();
|
|
86
121
|
}
|
|
@@ -94,26 +129,28 @@ class AppRouter extends EventTarget {
|
|
|
94
129
|
getProjectRoot() {
|
|
95
130
|
return this.getDefaultApp()?.info.projectRoot;
|
|
96
131
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
132
|
+
dispose() {
|
|
133
|
+
if (this.isDisposed) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.isDisposed = true;
|
|
137
|
+
const error = routerStoppedError();
|
|
138
|
+
for (const pendingWait of this.pendingAppWaits) {
|
|
139
|
+
pendingWait.reject(error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
waitForApp(applicationId, timeout = AppRouter.defaultWaitTimeout) {
|
|
143
|
+
if (this.isDisposed) {
|
|
144
|
+
return Promise.reject(routerStoppedError());
|
|
145
|
+
}
|
|
146
|
+
const app = applicationId === undefined ? this.getDefaultApp() : this.apps.get(applicationId);
|
|
147
|
+
if (app) {
|
|
148
|
+
return Promise.resolve(app.info);
|
|
149
|
+
}
|
|
150
|
+
return this.waitForRegistration(applicationId, timeout);
|
|
115
151
|
}
|
|
116
|
-
async sendToApp(applicationId, method, params) {
|
|
152
|
+
async sendToApp(applicationId, method, params, waitTimeout) {
|
|
153
|
+
await this.waitForApp(applicationId, waitTimeout);
|
|
117
154
|
const app = this.resolveTargetApp(applicationId);
|
|
118
155
|
try {
|
|
119
156
|
return await app.connection.send(method, params, this.requestTimeout);
|
package/dist/app-router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;AAU3E,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAE1C,SAAS,kBAAkB,CAAC,IAAa;IACrC,OAAO,IAAI,WAAW,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,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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,EAC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\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;\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 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 private pendingAppWaits: Set<PendingAppWait> = new Set();\n\n private isDisposed = false;\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 (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\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 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 = AppRouter.defaultWaitTimeout): 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, 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"]}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { invalidRequestError, isConnectionClosedError, methodNotFoundError, propertyNotFoundError, widgetNotFoundError, } from "./protocol/errors.js";
|
|
2
|
-
export {
|
|
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
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -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,
|
|
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 {
|
|
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
|
package/dist/internal.js.map
CHANGED
|
@@ -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,
|
|
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"]}
|
|
@@ -84,6 +84,5 @@ declare const ServerRequestParamsSchemas: {
|
|
|
84
84
|
"widget.fireEvent": typeof fireEventParams;
|
|
85
85
|
"widget.screenshot": typeof screenshotParams;
|
|
86
86
|
};
|
|
87
|
-
|
|
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, };
|
|
87
|
+
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
88
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/protocol/schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/protocol/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,KAAK,gBAAgB,GAAG;IACpB,EAAE,EAAE,MAAM,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,UAAU,CAAC;IACjC,kBAAkB,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"}
|
package/dist/protocol/schemas.js
CHANGED
|
@@ -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
|
-
|
|
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":["../../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W;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 = {\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\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"]}
|
package/dist/reference.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../src/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAsE,MAAM,eAAe,CAAC;AAEtH,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,yCAAyC,CAAC;AAK3F,OAAO,EAAsC,KAAK,IAAI,EAAiB,MAAM,WAAW,CAAC;AAEzF,KAAK,YAAY,GAAG,IAAI,CACpB,YAAY,EACZ,QAAQ,GAAG,mBAAmB,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ,GAAG,aAAa,CACxF,CAAC;AAEF,KAAK,aAAa,GAAG,UAAU,GAAG,kBAAkB,GAAG,KAAK,CAAC;AAE7D,KAAK,eAAe,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,CAAC;CACzB,CAAC;AAEF,KAAK,eAAe,GAAG,eAAe,GAAG;IACrC,SAAS,EAAE,YAAY,CAAC;CAC3B,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC5B,UAAU,EA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AEF,KAAK,iBAAiB,GAAG;IACrB,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACzD,OAAO,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC;CAClD,CAAC;AAsBF,KAAK,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;AAkM1D,QAAA,MAAM,uBAAuB,GAAI,SAAS,wBAAwB,KAAG,iBAgBpE,CAAC;AA2HF,QAAA,MAAM,mBAAmB,GAAI,UAAU,iBAAiB,KAAG,IAAI,EAI9D,CAAC;AAmJF,QAAA,MAAM,0BAA0B,GAAI,QAAQ,cAAc,EAAE,UAAU,iBAAiB,KAAG,IAIzF,CAAC;AAEF,OAAO,EACH,uBAAuB,EACvB,mBAAmB,EACnB,0BAA0B,EAC1B,KAAK,iBAAiB,GACzB,CAAC"}
|
package/dist/reference.js
CHANGED
|
@@ -25,8 +25,8 @@ const SYMBOL_KIND = z.enum([
|
|
|
25
25
|
"function",
|
|
26
26
|
"constant",
|
|
27
27
|
]);
|
|
28
|
-
const SYMBOL_DESCRIPTION = "Qualified symbol name (`
|
|
29
|
-
"or bare symbol name when unambiguous (`
|
|
28
|
+
const SYMBOL_DESCRIPTION = "Qualified symbol name (`Adw.Toast`, `Gtk.Orientation`, `GLib.idleAdd`), JSX element name (`AdwToast`), " +
|
|
29
|
+
"or bare symbol name when unambiguous (`Toast`).";
|
|
30
30
|
const PROJECT_ROOT_DESCRIPTION = "Directory of the GTKX project whose bindings to document, absolute or relative to the working directory. " +
|
|
31
31
|
"Any directory inside the project works; its `gtkx.config.ts` decides the documented libraries. Omit to use " +
|
|
32
32
|
"the project containing the working directory, falling back to a connected app's project.";
|
|
@@ -38,12 +38,12 @@ const listApiShape = {
|
|
|
38
38
|
namespace: z
|
|
39
39
|
.string()
|
|
40
40
|
.optional()
|
|
41
|
-
.describe("Namespace to list (e.g. `
|
|
41
|
+
.describe("Namespace to list (e.g. `Adw`, `Gtk`, `Gio`). Omit for an overview of all namespaces."),
|
|
42
42
|
};
|
|
43
43
|
const searchApiShape = {
|
|
44
44
|
...projectRootShape,
|
|
45
45
|
query: z.string().describe("Case-insensitive substring of a symbol name, e.g. `headerbar` or `orientation`."),
|
|
46
|
-
namespace: z.string().optional().describe("Restrict matches to one namespace (e.g. `
|
|
46
|
+
namespace: z.string().optional().describe("Restrict matches to one namespace (e.g. `Adw`)."),
|
|
47
47
|
kind: SYMBOL_KIND.optional().describe("Restrict matches to one symbol kind."),
|
|
48
48
|
limit: z.number().int().min(1).optional().describe("Maximum number of results (default: 20)."),
|
|
49
49
|
};
|
|
@@ -211,8 +211,9 @@ const listApiTool = (provider) => defineTool({
|
|
|
211
211
|
name: "gtkx_list_api",
|
|
212
212
|
title: "List API reference",
|
|
213
213
|
kind: "readOnly",
|
|
214
|
-
description: "List the project's generated
|
|
215
|
-
"
|
|
214
|
+
description: "List the project's generated bindings API (`@gtkx/gi` and `@gtkx/jsx`), including Adwaita, " +
|
|
215
|
+
"GTK4, and its declared GIR libraries. Without a namespace, returns every namespace with symbol counts; " +
|
|
216
|
+
"with a namespace, lists all of its symbols grouped by kind.",
|
|
216
217
|
inputSchema: listApiShape,
|
|
217
218
|
handler: ({ namespace, projectRoot }) => scopedResult(provider, projectRoot, (reference) => listApiResult(reference, namespace)),
|
|
218
219
|
});
|
|
@@ -220,7 +221,7 @@ const searchApiTool = (provider) => defineTool({
|
|
|
220
221
|
name: "gtkx_search_api",
|
|
221
222
|
title: "Search API reference",
|
|
222
223
|
kind: "readOnly",
|
|
223
|
-
description: "Search the project's generated
|
|
224
|
+
description: "Search the project's generated bindings API by symbol name. Returns matching symbols with " +
|
|
224
225
|
"their namespace, kind, and a one-line summary; fetch full pages with `gtkx_get_api_docs`.",
|
|
225
226
|
inputSchema: searchApiShape,
|
|
226
227
|
handler: (args) => scopedResult(provider, args.projectRoot, (reference) => searchApiResult(reference, args)),
|
|
@@ -229,7 +230,7 @@ const getApiDocsTool = (provider) => defineTool({
|
|
|
229
230
|
name: "gtkx_get_api_docs",
|
|
230
231
|
title: "Get API docs",
|
|
231
232
|
kind: "readOnly",
|
|
232
|
-
description: "Get the full reference page for one symbol of the project's generated
|
|
233
|
+
description: "Get the full reference page for one symbol of the project's generated bindings: JSX elements " +
|
|
233
234
|
"(props, signals, methods) or `@gtkx/gi` classes, interfaces, records, enums, callbacks, aliases, " +
|
|
234
235
|
"functions, and constants.",
|
|
235
236
|
inputSchema: apiDocsShape,
|
|
@@ -278,7 +279,7 @@ const symbolPage = async (uri, provider, namespace, symbol) => {
|
|
|
278
279
|
const registerIndexResource = (server, provider) => {
|
|
279
280
|
server.registerResource("gtkx-api-reference", "gtkx://reference/index", {
|
|
280
281
|
title: "GTKX API reference index",
|
|
281
|
-
description: "Namespaces of the project's generated
|
|
282
|
+
description: "Namespaces of the project's generated bindings, with symbol and JSX element counts.",
|
|
282
283
|
mimeType: "text/markdown",
|
|
283
284
|
}, async (uri) => {
|
|
284
285
|
const { reference } = await provider.get();
|
|
@@ -302,7 +303,7 @@ const registerNamespaceResource = (server, provider) => {
|
|
|
302
303
|
},
|
|
303
304
|
}), {
|
|
304
305
|
title: "GTKX namespace reference",
|
|
305
|
-
description: "All symbols of one namespace of the project's generated
|
|
306
|
+
description: "All symbols of one namespace of the project's generated bindings, grouped by kind.",
|
|
306
307
|
mimeType: "text/markdown",
|
|
307
308
|
}, async (uri, variables) => {
|
|
308
309
|
const namespace = variableValue(variables.namespace);
|
|
@@ -323,7 +324,7 @@ const registerSymbolResource = (server, provider) => {
|
|
|
323
324
|
},
|
|
324
325
|
}), {
|
|
325
326
|
title: "GTKX symbol reference",
|
|
326
|
-
description: "Reference page for one symbol of the project's generated
|
|
327
|
+
description: "Reference page for one symbol of the project's generated bindings: a JSX element or a " +
|
|
327
328
|
"class, interface, record, enum, callback, alias, function, or constant.",
|
|
328
329
|
mimeType: "text/markdown",
|
|
329
330
|
}, (uri, variables) => symbolPage(uri, provider, variableValue(variables.namespace), variableValue(variables.symbol)));
|