@aethervtt/shard-protocol 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +18 -0
- package/dist/png.d.ts +9 -0
- package/dist/png.js +69 -0
- package/dist/preview.d.ts +10 -0
- package/dist/preview.js +249 -0
- package/dist/server.d.ts +59 -0
- package/dist/server.js +1086 -0
- package/dist/transport.d.ts +15 -0
- package/dist/transport.js +53 -0
- package/package.json +42 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProtocolServer } from './server.js';
|
|
2
|
+
export declare const DEFAULT_HUB_PORT = 7811;
|
|
3
|
+
export interface HubConnectionOptions {
|
|
4
|
+
/** Shown to the hub (and MCP clients) to identify this app, e.g. "playground" or "studio". */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Keep retrying with backoff when the hub isn't there. Default true. */
|
|
7
|
+
reconnect?: boolean;
|
|
8
|
+
/** Called on connect/disconnect, for UI. */
|
|
9
|
+
onStatus?: (connected: boolean) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Connects an app to a protocol hub (the CLI or MCP server) over WebSocket. The app dials out, so a
|
|
13
|
+
* browser tab can be driven as easily as a headless run. Returns a function that disconnects.
|
|
14
|
+
*/
|
|
15
|
+
export declare function connectToHub(url: string, server: ProtocolServer, options: HubConnectionOptions): () => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const DEFAULT_HUB_PORT = 7811;
|
|
2
|
+
function connectToHub(url, server, options) {
|
|
3
|
+
let socket;
|
|
4
|
+
let closed = false;
|
|
5
|
+
let delay = 500;
|
|
6
|
+
let timer;
|
|
7
|
+
const offNotify = server.onNotification((n) => {
|
|
8
|
+
if (socket?.readyState === WebSocket.OPEN) socket.send(JSON.stringify(n));
|
|
9
|
+
});
|
|
10
|
+
const open = () => {
|
|
11
|
+
socket = new WebSocket(url);
|
|
12
|
+
socket.onopen = () => {
|
|
13
|
+
delay = 500;
|
|
14
|
+
socket.send(
|
|
15
|
+
JSON.stringify({
|
|
16
|
+
jsonrpc: "2.0",
|
|
17
|
+
method: "hello",
|
|
18
|
+
params: { name: options.name, protocol: 1 }
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
options.onStatus?.(true);
|
|
22
|
+
};
|
|
23
|
+
socket.onmessage = async (event) => {
|
|
24
|
+
let request;
|
|
25
|
+
try {
|
|
26
|
+
request = JSON.parse(String(event.data));
|
|
27
|
+
} catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const response = await server.handle(request);
|
|
31
|
+
if (response && socket?.readyState === WebSocket.OPEN) socket.send(JSON.stringify(response));
|
|
32
|
+
};
|
|
33
|
+
socket.onclose = () => {
|
|
34
|
+
options.onStatus?.(false);
|
|
35
|
+
if (closed || options.reconnect === false) return;
|
|
36
|
+
timer = setTimeout(open, delay);
|
|
37
|
+
delay = Math.min(delay * 2, 1e4);
|
|
38
|
+
};
|
|
39
|
+
socket.onerror = () => {
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
open();
|
|
43
|
+
return () => {
|
|
44
|
+
closed = true;
|
|
45
|
+
if (timer) clearTimeout(timer);
|
|
46
|
+
offNotify();
|
|
47
|
+
socket?.close();
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
DEFAULT_HUB_PORT,
|
|
52
|
+
connectToHub
|
|
53
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aethervtt/shard-protocol",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@aethervtt/shard-assets": "0.0.1",
|
|
20
|
+
"@aethervtt/shard-core": "0.0.1",
|
|
21
|
+
"@aethervtt/shard-input": "0.0.1",
|
|
22
|
+
"@aethervtt/shard-platform": "0.0.1",
|
|
23
|
+
"@aethervtt/shard-render": "0.0.1",
|
|
24
|
+
"@aethervtt/shard-runtime": "0.0.1",
|
|
25
|
+
"@aethervtt/shard-scene": "0.0.1",
|
|
26
|
+
"@aethervtt/shard-text": "0.0.1",
|
|
27
|
+
"@aethervtt/shard-texture": "0.0.1",
|
|
28
|
+
"@aethervtt/shard-transform": "0.0.1"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/aethervtt/shard.git",
|
|
33
|
+
"directory": "packages/protocol"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"provenance": true
|
|
38
|
+
},
|
|
39
|
+
"shard": {
|
|
40
|
+
"buildSha": "d6c5c6aef4675575c878b02cf2c8f738b4190229"
|
|
41
|
+
}
|
|
42
|
+
}
|