@directivegames/genesys.sdk 3.2.2
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 +60 -0
- package/dist/src/asset-pack/eslint.config.js +43 -0
- package/dist/src/asset-pack/scripts/postinstall.js +64 -0
- package/dist/src/asset-pack/src/index.js +1 -0
- package/dist/src/core/cli.js +306 -0
- package/dist/src/core/common.js +324 -0
- package/dist/src/core/index.js +6 -0
- package/dist/src/core/tools/build-project.js +450 -0
- package/dist/src/core/tools/index.js +2 -0
- package/dist/src/core/tools/new-asset-pack.js +150 -0
- package/dist/src/core/tools/new-project.js +292 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/dependencies.js +82 -0
- package/dist/src/electron/IpcSerializableError.js +38 -0
- package/dist/src/electron/api.js +7 -0
- package/dist/src/electron/backend/actions.js +56 -0
- package/dist/src/electron/backend/handler.js +441 -0
- package/dist/src/electron/backend/logging.js +41 -0
- package/dist/src/electron/backend/main.js +315 -0
- package/dist/src/electron/backend/menu.js +208 -0
- package/dist/src/electron/backend/state.js +201 -0
- package/dist/src/electron/backend/tools/const.js +9 -0
- package/dist/src/electron/backend/tools/file-server.js +383 -0
- package/dist/src/electron/backend/tools/open-project.js +261 -0
- package/dist/src/electron/backend/window.js +161 -0
- package/dist/src/templates/eslint.config.js +43 -0
- package/dist/src/templates/scripts/genesys/build-project.js +42 -0
- package/dist/src/templates/scripts/genesys/calc-bounding-box.js +205 -0
- package/dist/src/templates/scripts/genesys/common.js +36 -0
- package/dist/src/templates/scripts/genesys/const.js +9 -0
- package/dist/src/templates/scripts/genesys/dev/dump-default-scene.js +8 -0
- package/dist/src/templates/scripts/genesys/dev/generate-manifest.js +116 -0
- package/dist/src/templates/scripts/genesys/dev/launcher.js +39 -0
- package/dist/src/templates/scripts/genesys/dev/storage-provider.js +188 -0
- package/dist/src/templates/scripts/genesys/dev/update-template-scenes.js +67 -0
- package/dist/src/templates/scripts/genesys/doc-server.js +12 -0
- package/dist/src/templates/scripts/genesys/genesys-mcp.js +413 -0
- package/dist/src/templates/scripts/genesys/mcp/doc-tools.js +70 -0
- package/dist/src/templates/scripts/genesys/mcp/editor-functions.js +123 -0
- package/dist/src/templates/scripts/genesys/mcp/editor-tools.js +51 -0
- package/dist/src/templates/scripts/genesys/mcp/get-scene-state.js +26 -0
- package/dist/src/templates/scripts/genesys/mcp/run-subprocess.js +23 -0
- package/dist/src/templates/scripts/genesys/mcp/search-actors.js +703 -0
- package/dist/src/templates/scripts/genesys/mcp/search-assets.js +296 -0
- package/dist/src/templates/scripts/genesys/mcp/utils.js +234 -0
- package/dist/src/templates/scripts/genesys/misc.js +32 -0
- package/dist/src/templates/scripts/genesys/mock.js +5 -0
- package/dist/src/templates/scripts/genesys/place-actors.js +112 -0
- package/dist/src/templates/scripts/genesys/post-install.js +25 -0
- package/dist/src/templates/scripts/genesys/remove-engine-comments.js +113 -0
- package/dist/src/templates/scripts/genesys/storageProvider.js +146 -0
- package/dist/src/templates/scripts/genesys/validate-prefabs.js +115 -0
- package/dist/src/templates/src/index.js +20 -0
- package/dist/src/templates/src/templates/firstPerson/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/firstPerson/src/game.js +30 -0
- package/dist/src/templates/src/templates/firstPerson/src/player.js +60 -0
- package/dist/src/templates/src/templates/fps/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/fps/src/game.js +30 -0
- package/dist/src/templates/src/templates/fps/src/player.js +64 -0
- package/dist/src/templates/src/templates/fps/src/weapon.js +62 -0
- package/dist/src/templates/src/templates/freeCamera/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/freeCamera/src/game.js +30 -0
- package/dist/src/templates/src/templates/freeCamera/src/player.js +43 -0
- package/dist/src/templates/src/templates/sideScroller/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/sideScroller/src/const.js +43 -0
- package/dist/src/templates/src/templates/sideScroller/src/game.js +103 -0
- package/dist/src/templates/src/templates/sideScroller/src/level-generator.js +249 -0
- package/dist/src/templates/src/templates/sideScroller/src/player.js +105 -0
- package/dist/src/templates/src/templates/thirdPerson/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/thirdPerson/src/game.js +30 -0
- package/dist/src/templates/src/templates/thirdPerson/src/player.js +63 -0
- package/dist/src/templates/src/templates/vehicle/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/vehicle/src/base-vehicle.js +122 -0
- package/dist/src/templates/src/templates/vehicle/src/game.js +33 -0
- package/dist/src/templates/src/templates/vehicle/src/mesh-vehicle.js +189 -0
- package/dist/src/templates/src/templates/vehicle/src/player.js +102 -0
- package/dist/src/templates/src/templates/vehicle/src/primitive-vehicle.js +259 -0
- package/dist/src/templates/src/templates/vehicle/src/ui-hints.js +100 -0
- package/dist/src/templates/src/templates/vr-game/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/vr-game/src/game.js +55 -0
- package/dist/src/templates/src/templates/vr-game/src/sample-vr-actor.js +29 -0
- package/dist/src/templates/vite.config.js +46 -0
- package/package.json +176 -0
- package/scripts/post-install.ts +143 -0
- package/src/asset-pack/.gitattributes +89 -0
- package/src/asset-pack/eslint.config.js +45 -0
- package/src/asset-pack/gitignore +11 -0
- package/src/asset-pack/scripts/postinstall.ts +81 -0
- package/src/asset-pack/src/index.ts +0 -0
- package/src/asset-pack/tsconfig.json +34 -0
- package/src/templates/.cursor/mcp.json +20 -0
- package/src/templates/.cursorignore +2 -0
- package/src/templates/.gitattributes +89 -0
- package/src/templates/.vscode/settings.json +6 -0
- package/src/templates/AGENTS.md +86 -0
- package/src/templates/CLAUDE.md +1 -0
- package/src/templates/README.md +24 -0
- package/src/templates/eslint.config.js +45 -0
- package/src/templates/gitignore +11 -0
- package/src/templates/index.html +34 -0
- package/src/templates/pnpm-lock.yaml +3676 -0
- package/src/templates/scripts/genesys/build-project.ts +51 -0
- package/src/templates/scripts/genesys/calc-bounding-box.ts +272 -0
- package/src/templates/scripts/genesys/common.ts +46 -0
- package/src/templates/scripts/genesys/const.ts +9 -0
- package/src/templates/scripts/genesys/dev/dump-default-scene.ts +11 -0
- package/src/templates/scripts/genesys/dev/generate-manifest.ts +146 -0
- package/src/templates/scripts/genesys/dev/launcher.ts +46 -0
- package/src/templates/scripts/genesys/dev/storage-provider.ts +229 -0
- package/src/templates/scripts/genesys/dev/update-template-scenes.ts +84 -0
- package/src/templates/scripts/genesys/doc-server.ts +16 -0
- package/src/templates/scripts/genesys/genesys-mcp.ts +526 -0
- package/src/templates/scripts/genesys/mcp/doc-tools.ts +86 -0
- package/src/templates/scripts/genesys/mcp/editor-functions.ts +151 -0
- package/src/templates/scripts/genesys/mcp/editor-tools.ts +73 -0
- package/src/templates/scripts/genesys/mcp/get-scene-state.ts +35 -0
- package/src/templates/scripts/genesys/mcp/run-subprocess.ts +30 -0
- package/src/templates/scripts/genesys/mcp/search-actors.ts +858 -0
- package/src/templates/scripts/genesys/mcp/search-assets.ts +380 -0
- package/src/templates/scripts/genesys/mcp/utils.ts +281 -0
- package/src/templates/scripts/genesys/misc.ts +42 -0
- package/src/templates/scripts/genesys/mock.ts +6 -0
- package/src/templates/scripts/genesys/place-actors.ts +179 -0
- package/src/templates/scripts/genesys/post-install.ts +30 -0
- package/src/templates/scripts/genesys/prefab.schema.json +85 -0
- package/src/templates/scripts/genesys/remove-engine-comments.ts +135 -0
- package/src/templates/scripts/genesys/run-mcp-inspector.bat +5 -0
- package/src/templates/scripts/genesys/storageProvider.ts +182 -0
- package/src/templates/scripts/genesys/validate-prefabs.ts +138 -0
- package/src/templates/src/index.ts +22 -0
- package/src/templates/src/templates/firstPerson/assets/default.genesys-scene +166 -0
- package/src/templates/src/templates/firstPerson/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/firstPerson/src/game.ts +39 -0
- package/src/templates/src/templates/firstPerson/src/player.ts +63 -0
- package/src/templates/src/templates/fps/assets/default.genesys-scene +9460 -0
- package/src/templates/src/templates/fps/assets/models/SM_Beam_400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_ChamferCube.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Floor_Thick_400x400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Floor_Thick_400x400_Orange.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Floor_Thin_400x400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Floor_Thin_400x400_Orange.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Ramp_400x400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Rifle.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Wall_Thin_400x200.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Wall_Thin_400x200_Orange.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Wall_Thin_400x400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Wall_Thin_400x400_Orange.glb +0 -0
- package/src/templates/src/templates/fps/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/fps/src/game.ts +39 -0
- package/src/templates/src/templates/fps/src/player.ts +69 -0
- package/src/templates/src/templates/fps/src/weapon.ts +54 -0
- package/src/templates/src/templates/freeCamera/assets/default.genesys-scene +166 -0
- package/src/templates/src/templates/freeCamera/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/freeCamera/src/game.ts +39 -0
- package/src/templates/src/templates/freeCamera/src/player.ts +45 -0
- package/src/templates/src/templates/sideScroller/assets/default.genesys-scene +122 -0
- package/src/templates/src/templates/sideScroller/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/sideScroller/src/const.ts +46 -0
- package/src/templates/src/templates/sideScroller/src/game.ts +122 -0
- package/src/templates/src/templates/sideScroller/src/level-generator.ts +361 -0
- package/src/templates/src/templates/sideScroller/src/player.ts +125 -0
- package/src/templates/src/templates/thirdPerson/assets/default.genesys-scene +166 -0
- package/src/templates/src/templates/thirdPerson/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/thirdPerson/src/game.ts +39 -0
- package/src/templates/src/templates/thirdPerson/src/player.ts +61 -0
- package/src/templates/src/templates/vehicle/assets/default.genesys-scene +226 -0
- package/src/templates/src/templates/vehicle/assets/models/cyberTruck/chassis.glb +0 -0
- package/src/templates/src/templates/vehicle/assets/models/cyberTruck/wheel.glb +0 -0
- package/src/templates/src/templates/vehicle/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/vehicle/src/base-vehicle.ts +145 -0
- package/src/templates/src/templates/vehicle/src/game.ts +43 -0
- package/src/templates/src/templates/vehicle/src/mesh-vehicle.ts +191 -0
- package/src/templates/src/templates/vehicle/src/player.ts +109 -0
- package/src/templates/src/templates/vehicle/src/primitive-vehicle.ts +266 -0
- package/src/templates/src/templates/vehicle/src/ui-hints.ts +101 -0
- package/src/templates/src/templates/vr-game/assets/default.genesys-scene +247 -0
- package/src/templates/src/templates/vr-game/src/auto-imports.ts +1 -0
- package/src/templates/src/templates/vr-game/src/game.ts +66 -0
- package/src/templates/src/templates/vr-game/src/sample-vr-actor.ts +26 -0
- package/src/templates/tsconfig.json +35 -0
- package/src/templates/vite.config.ts +52 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import * as ENGINE from 'genesys.js';
|
|
5
|
+
import getPort from 'get-port';
|
|
6
|
+
import { nanoid } from 'nanoid';
|
|
7
|
+
import { WebSocket, WebSocketServer } from 'ws';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
|
|
10
|
+
import { StorageProvider } from '../storageProvider.js';
|
|
11
|
+
|
|
12
|
+
const clients = new Map<string, WebSocket>();
|
|
13
|
+
|
|
14
|
+
// prefer 8765 to 8770
|
|
15
|
+
const port = await getPort({port: [8765, 8766, 8767, 8768, 8769, 8770]});
|
|
16
|
+
const wss = new WebSocketServer({ port });
|
|
17
|
+
const portFile = path.join(ENGINE.PROJECT_PATH_PREFIX, `${process.argv[2] ?? ''}.mcp-port`);
|
|
18
|
+
|
|
19
|
+
wss.on('error', error => {
|
|
20
|
+
console.error('WebSocket server error:', error);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
wss.on('listening', () => {
|
|
24
|
+
new StorageProvider().uploadFile(ENGINE.AssetPath.fromString(portFile), port.toString());
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
interface ClientResponse {
|
|
28
|
+
requestId: string;
|
|
29
|
+
data: any;
|
|
30
|
+
}
|
|
31
|
+
const pendingRequests = new Map<string, (data: any) => void>();
|
|
32
|
+
|
|
33
|
+
wss.on('connection', (ws) => {
|
|
34
|
+
let clientId: string | null = null;
|
|
35
|
+
|
|
36
|
+
ws.on('message', (message) => {
|
|
37
|
+
try {
|
|
38
|
+
const data = JSON.parse(message.toString());
|
|
39
|
+
|
|
40
|
+
// Client registers itself
|
|
41
|
+
if (data.type === 'register' && typeof data.clientId === 'string') {
|
|
42
|
+
clientId = data.clientId;
|
|
43
|
+
clients.set(clientId!, ws);
|
|
44
|
+
// console.log(`Client registered: ${clientId}`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const resolver = pendingRequests.get(data.requestId);
|
|
48
|
+
if (resolver) {
|
|
49
|
+
resolver(data);
|
|
50
|
+
pendingRequests.delete(data.requestId);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
// console.error('Invalid message:', message.toString());
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
ws.on('close', () => {
|
|
59
|
+
if (clientId) {
|
|
60
|
+
clients.delete(clientId);
|
|
61
|
+
// console.log(`Client disconnected: ${clientId}`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// when cursor exits
|
|
67
|
+
process.stdin.on('end', shutdown);
|
|
68
|
+
process.stdin.on('close', shutdown);
|
|
69
|
+
|
|
70
|
+
// normally when process exits
|
|
71
|
+
process.on('SIGTERM', shutdown);
|
|
72
|
+
process.on('SIGINT', shutdown); // Ctrl+C
|
|
73
|
+
process.on('SIGQUIT', shutdown);
|
|
74
|
+
|
|
75
|
+
function shutdown() {
|
|
76
|
+
wss.close(() => {
|
|
77
|
+
new StorageProvider().deleteFile(ENGINE.AssetPath.fromString(portFile));
|
|
78
|
+
process.exit(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
wss.clients.forEach((client) => {
|
|
82
|
+
if (client.readyState === WebSocket.OPEN) {
|
|
83
|
+
client.terminate(); // force close
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
clients.clear();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const EditorIdSchema = z.string().optional().describe(`
|
|
90
|
+
ID of the editor that should respond.
|
|
91
|
+
If not provided, will proceed if there is only one editor connected, will return error if there are multiple editors connected.
|
|
92
|
+
Can always try without providing this, and only ask the user to provide it if there are multiple editors connected.
|
|
93
|
+
`);
|
|
94
|
+
|
|
95
|
+
export function getClientWebSocket(editorId?: string | null) {
|
|
96
|
+
if (clients.size === 0) {
|
|
97
|
+
throw new Error('No editors connected. Please make sure the Genesys editor is running and connected to the MCP.');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const editorIds = Array.from(clients.keys());
|
|
101
|
+
if (!editorId) {
|
|
102
|
+
if (clients.size > 1) {
|
|
103
|
+
throw new Error(`Multiple editors connected, please specify editorId. Available editor IDs: ${editorIds}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// only one editor connected, use its ID
|
|
107
|
+
editorId = editorIds[0];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const ws = clients.get(editorId);
|
|
111
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
112
|
+
return ws;
|
|
113
|
+
} else {
|
|
114
|
+
throw new Error(`Editor with ID ${editorId} is not connected or not ready. Please specify a valid editor ID, available editor IDs: ${editorIds}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
export async function getCurrentScene(editorId?: string | null): Promise<string> {
|
|
120
|
+
let ws: WebSocket;
|
|
121
|
+
try {
|
|
122
|
+
ws = getClientWebSocket(editorId);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
return Promise.reject(error);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const requestId = nanoid();
|
|
129
|
+
const message = {
|
|
130
|
+
command: 'getCurrentScene',
|
|
131
|
+
requestId,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
ws.send(JSON.stringify(message));
|
|
135
|
+
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
const timeout = setTimeout(() => {
|
|
138
|
+
pendingRequests.delete(requestId);
|
|
139
|
+
reject(new Error('Timeout waiting for client to response with current scene'));
|
|
140
|
+
}, 500); // 500 ms timeout
|
|
141
|
+
|
|
142
|
+
pendingRequests.set(requestId, (data: any) => {
|
|
143
|
+
clearTimeout(timeout);
|
|
144
|
+
if ('currentScene' in data) {
|
|
145
|
+
resolve(data.currentScene);
|
|
146
|
+
} else {
|
|
147
|
+
reject(new Error('Invalid response from editor'));
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { EditorIdSchema, getClientWebSocket, getCurrentScene } from './editor-functions.js';
|
|
5
|
+
import { mcpLogger } from './utils.js';
|
|
6
|
+
|
|
7
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
import type { WebSocket } from 'ws';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export function addEditorTools(server: McpServer) {
|
|
12
|
+
server.registerTool(
|
|
13
|
+
'selectActors',
|
|
14
|
+
{
|
|
15
|
+
description: 'Make the editor to select an actor by its UUID.',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
actorIds: z.array(z.string()).describe('UUIDs of the actors to select'),
|
|
18
|
+
editorId: EditorIdSchema,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
async ({actorIds, editorId}) => {
|
|
22
|
+
using loggerContext = mcpLogger(server);
|
|
23
|
+
|
|
24
|
+
let ws: WebSocket;
|
|
25
|
+
try {
|
|
26
|
+
ws = getClientWebSocket(editorId);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return {
|
|
29
|
+
isError: true,
|
|
30
|
+
content: [{ type: 'text', text: `Error connecting to client: ${error}` }]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ws.send(JSON.stringify({
|
|
35
|
+
command: 'selectActorsByIds',
|
|
36
|
+
actorIds
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
content: [{ type: 'text', text: 'Success' }]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
server.registerTool(
|
|
47
|
+
'getCurrentScene',
|
|
48
|
+
{
|
|
49
|
+
description: 'Get the current scene opened in the editor.',
|
|
50
|
+
inputSchema: {
|
|
51
|
+
editorId: EditorIdSchema
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
async ({editorId}) => {
|
|
55
|
+
using loggerContext = mcpLogger(server);
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const currentScene = await getCurrentScene(editorId);
|
|
59
|
+
return {
|
|
60
|
+
content: [{ type: 'text', text: `Current scene: ${currentScene}` }]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return {
|
|
65
|
+
isError: true,
|
|
66
|
+
content: [{ type: 'text', text: `Failed to get the current scene: ${error}` }]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mockBrowserEnvironment } from '../mock.js';
|
|
2
|
+
|
|
3
|
+
import { loadWorld } from './utils.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
mockBrowserEnvironment();
|
|
7
|
+
|
|
8
|
+
export async function getSceneState(sceneName: string, specifiedActors?: string[], getDetailedComponentsInfo?: boolean) {
|
|
9
|
+
using worldResource = await loadWorld(sceneName, { readonly: true, skipLoadingGLTF: false });
|
|
10
|
+
|
|
11
|
+
const world = worldResource.world;
|
|
12
|
+
return world.describe({specifiedActors, includeComponentsDetails: getDetailedComponentsInfo});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// This foramts the json into a yaml style output, so as to get rid of quotes and braces to hopefully save some tokens
|
|
16
|
+
// it's not much compared to a condensed json output. Not using it for now
|
|
17
|
+
function format(obj: any, indent = 0): string {
|
|
18
|
+
const spaces = ' '.repeat(indent);
|
|
19
|
+
if (Array.isArray(obj)) {
|
|
20
|
+
return obj
|
|
21
|
+
.map(item => `${spaces}- ${format(item, indent + 1).trimStart()}`)
|
|
22
|
+
.join('\n');
|
|
23
|
+
} else if (obj && typeof obj === 'object') {
|
|
24
|
+
return Object.entries(obj)
|
|
25
|
+
.map(
|
|
26
|
+
([key, value]) =>
|
|
27
|
+
`${spaces}${key}: ${
|
|
28
|
+
typeof value === 'object' ? `\n${format(value, indent + 1)}` : value
|
|
29
|
+
}`
|
|
30
|
+
)
|
|
31
|
+
.join('\n');
|
|
32
|
+
} else {
|
|
33
|
+
return String(obj);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { fork } from 'child_process';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import { getProjectRoot } from '../common.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export async function runSubProcess(script: string, params: any): Promise<any> {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const worker = fork(path.join(getProjectRoot(), 'scripts', 'mcp', script), { silent: true });
|
|
10
|
+
|
|
11
|
+
worker.on('message', (msg: string) => {
|
|
12
|
+
worker.kill();
|
|
13
|
+
resolve(msg);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
worker.on('error', (error) => {
|
|
17
|
+
console.error('Worker error:', error);
|
|
18
|
+
worker.kill();
|
|
19
|
+
reject(error);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
worker.on('exit', (code) => {
|
|
23
|
+
if (code !== 0) {
|
|
24
|
+
reject(new Error(`Worker stopped with exit code ${code}`));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
worker.send(params);
|
|
29
|
+
});
|
|
30
|
+
}
|