unreal-engine-mcp-server 0.4.0 → 0.4.3
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/.env.production +1 -1
- package/.github/copilot-instructions.md +45 -0
- package/.github/workflows/publish-mcp.yml +1 -1
- package/README.md +21 -5
- package/dist/index.js +124 -31
- package/dist/prompts/index.d.ts +10 -3
- package/dist/prompts/index.js +186 -7
- package/dist/resources/actors.d.ts +19 -1
- package/dist/resources/actors.js +55 -64
- package/dist/resources/assets.js +46 -62
- package/dist/resources/levels.d.ts +21 -3
- package/dist/resources/levels.js +29 -54
- package/dist/tools/actors.d.ts +3 -14
- package/dist/tools/actors.js +246 -302
- package/dist/tools/animation.d.ts +57 -102
- package/dist/tools/animation.js +429 -450
- package/dist/tools/assets.d.ts +13 -2
- package/dist/tools/assets.js +52 -44
- package/dist/tools/audio.d.ts +22 -13
- package/dist/tools/audio.js +467 -121
- package/dist/tools/blueprint.d.ts +32 -13
- package/dist/tools/blueprint.js +699 -448
- package/dist/tools/build_environment_advanced.d.ts +0 -1
- package/dist/tools/build_environment_advanced.js +190 -45
- package/dist/tools/consolidated-tool-definitions.js +78 -252
- package/dist/tools/consolidated-tool-handlers.js +506 -133
- package/dist/tools/debug.d.ts +72 -10
- package/dist/tools/debug.js +167 -31
- package/dist/tools/editor.d.ts +9 -2
- package/dist/tools/editor.js +30 -44
- package/dist/tools/foliage.d.ts +34 -15
- package/dist/tools/foliage.js +97 -107
- package/dist/tools/introspection.js +19 -21
- package/dist/tools/landscape.d.ts +1 -2
- package/dist/tools/landscape.js +311 -168
- package/dist/tools/level.d.ts +3 -28
- package/dist/tools/level.js +642 -192
- package/dist/tools/lighting.d.ts +14 -3
- package/dist/tools/lighting.js +236 -123
- package/dist/tools/materials.d.ts +25 -7
- package/dist/tools/materials.js +102 -79
- package/dist/tools/niagara.d.ts +10 -12
- package/dist/tools/niagara.js +74 -94
- package/dist/tools/performance.d.ts +12 -4
- package/dist/tools/performance.js +38 -79
- package/dist/tools/physics.d.ts +34 -10
- package/dist/tools/physics.js +364 -292
- package/dist/tools/rc.js +97 -23
- package/dist/tools/sequence.d.ts +1 -0
- package/dist/tools/sequence.js +125 -22
- package/dist/tools/ui.d.ts +31 -4
- package/dist/tools/ui.js +83 -66
- package/dist/tools/visual.d.ts +11 -0
- package/dist/tools/visual.js +245 -30
- package/dist/types/tool-types.d.ts +0 -6
- package/dist/types/tool-types.js +1 -8
- package/dist/unreal-bridge.d.ts +32 -2
- package/dist/unreal-bridge.js +621 -127
- package/dist/utils/elicitation.d.ts +57 -0
- package/dist/utils/elicitation.js +104 -0
- package/dist/utils/error-handler.d.ts +0 -33
- package/dist/utils/error-handler.js +4 -111
- package/dist/utils/http.d.ts +2 -22
- package/dist/utils/http.js +12 -75
- package/dist/utils/normalize.d.ts +4 -4
- package/dist/utils/normalize.js +15 -7
- package/dist/utils/python-output.d.ts +18 -0
- package/dist/utils/python-output.js +290 -0
- package/dist/utils/python.d.ts +2 -0
- package/dist/utils/python.js +4 -0
- package/dist/utils/response-validator.js +28 -2
- package/dist/utils/result-helpers.d.ts +27 -0
- package/dist/utils/result-helpers.js +147 -0
- package/dist/utils/safe-json.d.ts +0 -2
- package/dist/utils/safe-json.js +0 -43
- package/dist/utils/validation.d.ts +16 -0
- package/dist/utils/validation.js +70 -7
- package/mcp-config-example.json +2 -2
- package/package.json +10 -9
- package/server.json +37 -14
- package/src/index.ts +130 -33
- package/src/prompts/index.ts +211 -13
- package/src/resources/actors.ts +59 -44
- package/src/resources/assets.ts +48 -51
- package/src/resources/levels.ts +35 -45
- package/src/tools/actors.ts +269 -313
- package/src/tools/animation.ts +556 -539
- package/src/tools/assets.ts +53 -43
- package/src/tools/audio.ts +507 -113
- package/src/tools/blueprint.ts +778 -462
- package/src/tools/build_environment_advanced.ts +266 -64
- package/src/tools/consolidated-tool-definitions.ts +90 -264
- package/src/tools/consolidated-tool-handlers.ts +630 -121
- package/src/tools/debug.ts +176 -33
- package/src/tools/editor.ts +35 -37
- package/src/tools/foliage.ts +110 -104
- package/src/tools/introspection.ts +24 -22
- package/src/tools/landscape.ts +334 -181
- package/src/tools/level.ts +683 -182
- package/src/tools/lighting.ts +244 -123
- package/src/tools/materials.ts +114 -83
- package/src/tools/niagara.ts +87 -81
- package/src/tools/performance.ts +49 -88
- package/src/tools/physics.ts +393 -299
- package/src/tools/rc.ts +102 -24
- package/src/tools/sequence.ts +136 -28
- package/src/tools/ui.ts +101 -70
- package/src/tools/visual.ts +250 -29
- package/src/types/tool-types.ts +0 -9
- package/src/unreal-bridge.ts +658 -140
- package/src/utils/elicitation.ts +129 -0
- package/src/utils/error-handler.ts +4 -159
- package/src/utils/http.ts +16 -115
- package/src/utils/normalize.ts +20 -10
- package/src/utils/python-output.ts +351 -0
- package/src/utils/python.ts +3 -0
- package/src/utils/response-validator.ts +25 -2
- package/src/utils/result-helpers.ts +193 -0
- package/src/utils/safe-json.ts +0 -50
- package/src/utils/validation.ts +94 -7
- package/tests/run-unreal-tool-tests.mjs +720 -0
- package/tsconfig.json +2 -2
- package/dist/python-utils.d.ts +0 -29
- package/dist/python-utils.js +0 -54
- package/dist/types/index.d.ts +0 -323
- package/dist/types/index.js +0 -28
- package/dist/utils/cache-manager.d.ts +0 -64
- package/dist/utils/cache-manager.js +0 -176
- package/dist/utils/errors.d.ts +0 -133
- package/dist/utils/errors.js +0 -256
- package/src/python/editor_compat.py +0 -181
- package/src/python-utils.ts +0 -57
- package/src/types/index.ts +0 -414
- package/src/utils/cache-manager.ts +0 -213
- package/src/utils/errors.ts +0 -312
package/src/types/index.ts
DELETED
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Comprehensive type definitions for Unreal Engine MCP Server
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// Re-export existing types
|
|
6
|
-
export * from './env.js';
|
|
7
|
-
export * from './tool-types.js';
|
|
8
|
-
|
|
9
|
-
// Common Unreal Engine types
|
|
10
|
-
export interface Vector3 {
|
|
11
|
-
x: number;
|
|
12
|
-
y: number;
|
|
13
|
-
z: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface Rotation3 {
|
|
17
|
-
pitch: number;
|
|
18
|
-
yaw: number;
|
|
19
|
-
roll: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface Transform {
|
|
23
|
-
location: Vector3;
|
|
24
|
-
rotation: Rotation3;
|
|
25
|
-
scale?: Vector3;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface Color {
|
|
29
|
-
r: number;
|
|
30
|
-
g: number;
|
|
31
|
-
b: number;
|
|
32
|
-
a?: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Asset types
|
|
36
|
-
export interface Asset {
|
|
37
|
-
Name: string;
|
|
38
|
-
Path: string;
|
|
39
|
-
Class: string;
|
|
40
|
-
PackagePath: string;
|
|
41
|
-
Type?: string;
|
|
42
|
-
Size?: number;
|
|
43
|
-
LastModified?: Date;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface Material extends Asset {
|
|
47
|
-
BaseColor?: Color;
|
|
48
|
-
Metallic?: number;
|
|
49
|
-
Roughness?: number;
|
|
50
|
-
Emissive?: Color;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface Texture extends Asset {
|
|
54
|
-
Width?: number;
|
|
55
|
-
Height?: number;
|
|
56
|
-
Format?: string;
|
|
57
|
-
MipLevels?: number;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Actor types
|
|
61
|
-
export interface Actor {
|
|
62
|
-
Name: string;
|
|
63
|
-
Class: string;
|
|
64
|
-
Path: string;
|
|
65
|
-
Transform?: Transform;
|
|
66
|
-
Components?: Component[];
|
|
67
|
-
Tags?: string[];
|
|
68
|
-
IsSelected?: boolean;
|
|
69
|
-
IsHidden?: boolean;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface Component {
|
|
73
|
-
Name: string;
|
|
74
|
-
Class: string;
|
|
75
|
-
Properties?: Record<string, any>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Level types
|
|
79
|
-
export interface Level {
|
|
80
|
-
Name: string;
|
|
81
|
-
Path: string;
|
|
82
|
-
IsLoaded: boolean;
|
|
83
|
-
IsVisible: boolean;
|
|
84
|
-
Actors?: Actor[];
|
|
85
|
-
StreamingLevels?: StreamingLevel[];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface StreamingLevel {
|
|
89
|
-
Name: string;
|
|
90
|
-
Path: string;
|
|
91
|
-
LoadingState: 'Unloaded' | 'Loading' | 'Loaded';
|
|
92
|
-
ShouldBeLoaded: boolean;
|
|
93
|
-
ShouldBeVisible: boolean;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Blueprint types
|
|
97
|
-
export interface Blueprint {
|
|
98
|
-
Name: string;
|
|
99
|
-
Path: string;
|
|
100
|
-
ParentClass: string;
|
|
101
|
-
Components?: BlueprintComponent[];
|
|
102
|
-
Variables?: BlueprintVariable[];
|
|
103
|
-
Functions?: BlueprintFunction[];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface BlueprintComponent {
|
|
107
|
-
Name: string;
|
|
108
|
-
Type: string;
|
|
109
|
-
DefaultProperties?: Record<string, any>;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface BlueprintVariable {
|
|
113
|
-
Name: string;
|
|
114
|
-
Type: string;
|
|
115
|
-
DefaultValue?: any;
|
|
116
|
-
IsPublic?: boolean;
|
|
117
|
-
Category?: string;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface BlueprintFunction {
|
|
121
|
-
Name: string;
|
|
122
|
-
ReturnType?: string;
|
|
123
|
-
Parameters?: FunctionParameter[];
|
|
124
|
-
IsPublic?: boolean;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export interface FunctionParameter {
|
|
128
|
-
Name: string;
|
|
129
|
-
Type: string;
|
|
130
|
-
DefaultValue?: any;
|
|
131
|
-
IsOptional?: boolean;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Animation types
|
|
135
|
-
export interface AnimationSequence {
|
|
136
|
-
Name: string;
|
|
137
|
-
Path: string;
|
|
138
|
-
Duration: number;
|
|
139
|
-
FrameRate: number;
|
|
140
|
-
Skeleton?: string;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface AnimationMontage {
|
|
144
|
-
Name: string;
|
|
145
|
-
Path: string;
|
|
146
|
-
Sections?: MontageSection[];
|
|
147
|
-
BlendIn?: number;
|
|
148
|
-
BlendOut?: number;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export interface MontageSection {
|
|
152
|
-
Name: string;
|
|
153
|
-
StartTime: number;
|
|
154
|
-
EndTime: number;
|
|
155
|
-
NextSection?: string;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Physics types
|
|
159
|
-
export interface PhysicsBody {
|
|
160
|
-
Mass: number;
|
|
161
|
-
LinearDamping: number;
|
|
162
|
-
AngularDamping: number;
|
|
163
|
-
EnableGravity: boolean;
|
|
164
|
-
IsKinematic: boolean;
|
|
165
|
-
CollisionEnabled: boolean;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export interface PhysicsConstraint {
|
|
169
|
-
Name: string;
|
|
170
|
-
Actor1: string;
|
|
171
|
-
Actor2: string;
|
|
172
|
-
LinearLimits?: Vector3;
|
|
173
|
-
AngularLimits?: Vector3;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Niagara/VFX types
|
|
177
|
-
export interface NiagaraSystem {
|
|
178
|
-
Name: string;
|
|
179
|
-
Path: string;
|
|
180
|
-
Emitters?: NiagaraEmitter[];
|
|
181
|
-
Parameters?: NiagaraParameter[];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export interface NiagaraEmitter {
|
|
185
|
-
Name: string;
|
|
186
|
-
SpawnRate: number;
|
|
187
|
-
Lifetime: number;
|
|
188
|
-
VelocityModule?: Vector3;
|
|
189
|
-
ColorModule?: Color;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export interface NiagaraParameter {
|
|
193
|
-
Name: string;
|
|
194
|
-
Type: string;
|
|
195
|
-
Value: any;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Landscape types
|
|
199
|
-
export interface Landscape {
|
|
200
|
-
Name: string;
|
|
201
|
-
ComponentCount: number;
|
|
202
|
-
Resolution: { x: number; y: number };
|
|
203
|
-
Scale: Vector3;
|
|
204
|
-
Materials?: string[];
|
|
205
|
-
Layers?: LandscapeLayer[];
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export interface LandscapeLayer {
|
|
209
|
-
Name: string;
|
|
210
|
-
BlendMode: string;
|
|
211
|
-
Weight: number;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Remote Control types
|
|
215
|
-
export interface RemoteControlPreset {
|
|
216
|
-
Name: string;
|
|
217
|
-
Path: string;
|
|
218
|
-
ExposedProperties?: ExposedProperty[];
|
|
219
|
-
ExposedFunctions?: ExposedFunction[];
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export interface ExposedProperty {
|
|
223
|
-
Name: string;
|
|
224
|
-
DisplayName?: string;
|
|
225
|
-
ObjectPath: string;
|
|
226
|
-
PropertyPath: string;
|
|
227
|
-
Type: string;
|
|
228
|
-
Value?: any;
|
|
229
|
-
Metadata?: Record<string, any>;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export interface ExposedFunction {
|
|
233
|
-
Name: string;
|
|
234
|
-
DisplayName?: string;
|
|
235
|
-
ObjectPath: string;
|
|
236
|
-
FunctionName: string;
|
|
237
|
-
Parameters?: FunctionParameter[];
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Sequencer types
|
|
241
|
-
export interface LevelSequence {
|
|
242
|
-
Name: string;
|
|
243
|
-
Path: string;
|
|
244
|
-
Duration: number;
|
|
245
|
-
FrameRate: number;
|
|
246
|
-
Tracks?: SequencerTrack[];
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export interface SequencerTrack {
|
|
250
|
-
Name: string;
|
|
251
|
-
Type: string;
|
|
252
|
-
BoundObject?: string;
|
|
253
|
-
Sections?: SequencerSection[];
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export interface SequencerSection {
|
|
257
|
-
StartFrame: number;
|
|
258
|
-
EndFrame: number;
|
|
259
|
-
Properties?: Record<string, any>;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// Performance types
|
|
263
|
-
export interface PerformanceMetrics {
|
|
264
|
-
FPS: number;
|
|
265
|
-
FrameTime: number;
|
|
266
|
-
GameThreadTime: number;
|
|
267
|
-
RenderThreadTime: number;
|
|
268
|
-
GPUTime: number;
|
|
269
|
-
DrawCalls: number;
|
|
270
|
-
Triangles: number;
|
|
271
|
-
Memory: MemoryMetrics;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export interface MemoryMetrics {
|
|
275
|
-
Physical: number;
|
|
276
|
-
Virtual: number;
|
|
277
|
-
GPU: number;
|
|
278
|
-
TextureMemory: number;
|
|
279
|
-
MeshMemory: number;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Engine info types
|
|
283
|
-
export interface EngineVersion {
|
|
284
|
-
Major: number;
|
|
285
|
-
Minor: number;
|
|
286
|
-
Patch: number;
|
|
287
|
-
Build?: number;
|
|
288
|
-
Branch?: string;
|
|
289
|
-
Compatible?: boolean;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export interface ProjectInfo {
|
|
293
|
-
Name: string;
|
|
294
|
-
Path: string;
|
|
295
|
-
EngineVersion: string;
|
|
296
|
-
Plugins?: PluginInfo[];
|
|
297
|
-
Settings?: ProjectSettings;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export interface PluginInfo {
|
|
301
|
-
Name: string;
|
|
302
|
-
Version: string;
|
|
303
|
-
Enabled: boolean;
|
|
304
|
-
Category?: string;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export interface ProjectSettings {
|
|
308
|
-
DefaultMap?: string;
|
|
309
|
-
DefaultGameMode?: string;
|
|
310
|
-
TargetFrameRate?: number;
|
|
311
|
-
EnableRayTracing?: boolean;
|
|
312
|
-
EnableNanite?: boolean;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// Response types
|
|
316
|
-
export interface SuccessResponse<T = any> {
|
|
317
|
-
success: true;
|
|
318
|
-
data?: T;
|
|
319
|
-
message?: string;
|
|
320
|
-
metadata?: Record<string, any>;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export interface ErrorResponse {
|
|
324
|
-
success: false;
|
|
325
|
-
error: string;
|
|
326
|
-
code?: string;
|
|
327
|
-
statusCode?: number;
|
|
328
|
-
details?: Record<string, any>;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
export type ApiResponse<T = any> = SuccessResponse<T> | ErrorResponse;
|
|
332
|
-
|
|
333
|
-
// Tool execution types
|
|
334
|
-
export interface ToolContext {
|
|
335
|
-
bridge: any; // UnrealBridge instance
|
|
336
|
-
tools: Record<string, any>;
|
|
337
|
-
cache?: any;
|
|
338
|
-
metrics?: any;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
export interface ToolResult<T = any> {
|
|
342
|
-
content: Array<{
|
|
343
|
-
type: 'text' | 'json' | 'error';
|
|
344
|
-
text?: string;
|
|
345
|
-
data?: T;
|
|
346
|
-
}>;
|
|
347
|
-
isError?: boolean;
|
|
348
|
-
metadata?: Record<string, any>;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// Event types
|
|
352
|
-
export interface UnrealEvent {
|
|
353
|
-
type: string;
|
|
354
|
-
timestamp: Date;
|
|
355
|
-
data: any;
|
|
356
|
-
source?: string;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
export interface PropertyChangeEvent extends UnrealEvent {
|
|
360
|
-
type: 'property_change';
|
|
361
|
-
objectPath: string;
|
|
362
|
-
propertyName: string;
|
|
363
|
-
oldValue: any;
|
|
364
|
-
newValue: any;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
export interface ActorSpawnEvent extends UnrealEvent {
|
|
368
|
-
type: 'actor_spawn';
|
|
369
|
-
actorName: string;
|
|
370
|
-
actorClass: string;
|
|
371
|
-
location: Vector3;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Utility types
|
|
375
|
-
export type DeepPartial<T> = {
|
|
376
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
export type Nullable<T> = T | null;
|
|
380
|
-
|
|
381
|
-
export type Optional<T> = T | undefined;
|
|
382
|
-
|
|
383
|
-
export type AsyncResult<T> = Promise<ApiResponse<T>>;
|
|
384
|
-
|
|
385
|
-
export type Callback<T> = (error: Error | null, result?: T) => void;
|
|
386
|
-
|
|
387
|
-
// Type guards
|
|
388
|
-
export function isVector3(value: any): value is Vector3 {
|
|
389
|
-
return (
|
|
390
|
-
typeof value === 'object' &&
|
|
391
|
-
value !== null &&
|
|
392
|
-
typeof value.x === 'number' &&
|
|
393
|
-
typeof value.y === 'number' &&
|
|
394
|
-
typeof value.z === 'number'
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export function isRotation3(value: any): value is Rotation3 {
|
|
399
|
-
return (
|
|
400
|
-
typeof value === 'object' &&
|
|
401
|
-
value !== null &&
|
|
402
|
-
typeof value.pitch === 'number' &&
|
|
403
|
-
typeof value.yaw === 'number' &&
|
|
404
|
-
typeof value.roll === 'number'
|
|
405
|
-
);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
export function isSuccessResponse<T>(response: ApiResponse<T>): response is SuccessResponse<T> {
|
|
409
|
-
return response.success === true;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
export function isErrorResponse(response: ApiResponse): response is ErrorResponse {
|
|
413
|
-
return response.success === false;
|
|
414
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cache Manager for API responses
|
|
3
|
-
* Implements LRU cache with TTL support for optimizing repeated API calls
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
interface CacheEntry<T> {
|
|
7
|
-
data: T;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
hits: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface CacheOptions {
|
|
13
|
-
maxSize?: number;
|
|
14
|
-
defaultTTL?: number; // in milliseconds
|
|
15
|
-
enableMetrics?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface CacheMetrics {
|
|
19
|
-
hits: number;
|
|
20
|
-
misses: number;
|
|
21
|
-
evictions: number;
|
|
22
|
-
size: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class CacheManager<T = any> {
|
|
26
|
-
private cache: Map<string, CacheEntry<T>>;
|
|
27
|
-
private readonly maxSize: number;
|
|
28
|
-
private readonly defaultTTL: number;
|
|
29
|
-
private readonly enableMetrics: boolean;
|
|
30
|
-
private metrics: CacheMetrics;
|
|
31
|
-
|
|
32
|
-
constructor(options: CacheOptions = {}) {
|
|
33
|
-
this.cache = new Map();
|
|
34
|
-
this.maxSize = options.maxSize || 100;
|
|
35
|
-
this.defaultTTL = options.defaultTTL || 60000; // 1 minute default
|
|
36
|
-
this.enableMetrics = options.enableMetrics || false;
|
|
37
|
-
this.metrics = {
|
|
38
|
-
hits: 0,
|
|
39
|
-
misses: 0,
|
|
40
|
-
evictions: 0,
|
|
41
|
-
size: 0
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Get item from cache
|
|
47
|
-
*/
|
|
48
|
-
get(key: string): T | null {
|
|
49
|
-
const entry = this.cache.get(key);
|
|
50
|
-
|
|
51
|
-
if (!entry) {
|
|
52
|
-
if (this.enableMetrics) this.metrics.misses++;
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Check if expired
|
|
57
|
-
if (Date.now() - entry.timestamp > this.defaultTTL) {
|
|
58
|
-
this.cache.delete(key);
|
|
59
|
-
if (this.enableMetrics) {
|
|
60
|
-
this.metrics.misses++;
|
|
61
|
-
this.metrics.size--;
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Update hit count and move to end (LRU)
|
|
67
|
-
entry.hits++;
|
|
68
|
-
this.cache.delete(key);
|
|
69
|
-
this.cache.set(key, entry);
|
|
70
|
-
|
|
71
|
-
if (this.enableMetrics) this.metrics.hits++;
|
|
72
|
-
return entry.data;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Set item in cache
|
|
77
|
-
*/
|
|
78
|
-
set(key: string, data: T): void {
|
|
79
|
-
// Evict oldest if at max size
|
|
80
|
-
if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
81
|
-
const firstKey = this.cache.keys().next().value;
|
|
82
|
-
if (firstKey) {
|
|
83
|
-
this.cache.delete(firstKey);
|
|
84
|
-
if (this.enableMetrics) {
|
|
85
|
-
this.metrics.evictions++;
|
|
86
|
-
this.metrics.size--;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const entry: CacheEntry<T> = {
|
|
92
|
-
data,
|
|
93
|
-
timestamp: Date.now(),
|
|
94
|
-
hits: 0
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
this.cache.set(key, entry);
|
|
98
|
-
if (this.enableMetrics) this.metrics.size = this.cache.size;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Check if key exists and is valid
|
|
103
|
-
*/
|
|
104
|
-
has(key: string): boolean {
|
|
105
|
-
const entry = this.cache.get(key);
|
|
106
|
-
if (!entry) return false;
|
|
107
|
-
|
|
108
|
-
// Check expiration
|
|
109
|
-
if (Date.now() - entry.timestamp > this.defaultTTL) {
|
|
110
|
-
this.cache.delete(key);
|
|
111
|
-
if (this.enableMetrics) this.metrics.size--;
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Clear specific key or all cache
|
|
120
|
-
*/
|
|
121
|
-
clear(key?: string): void {
|
|
122
|
-
if (key) {
|
|
123
|
-
this.cache.delete(key);
|
|
124
|
-
if (this.enableMetrics) this.metrics.size = this.cache.size;
|
|
125
|
-
} else {
|
|
126
|
-
this.cache.clear();
|
|
127
|
-
if (this.enableMetrics) {
|
|
128
|
-
this.metrics.size = 0;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Get cache metrics
|
|
135
|
-
*/
|
|
136
|
-
getMetrics(): CacheMetrics {
|
|
137
|
-
return { ...this.metrics };
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Get cache hit rate
|
|
142
|
-
*/
|
|
143
|
-
getHitRate(): number {
|
|
144
|
-
const total = this.metrics.hits + this.metrics.misses;
|
|
145
|
-
return total > 0 ? this.metrics.hits / total : 0;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Wrap async function with cache
|
|
150
|
-
*/
|
|
151
|
-
async wrap<R = T>(
|
|
152
|
-
key: string,
|
|
153
|
-
fn: () => Promise<R>
|
|
154
|
-
): Promise<R> {
|
|
155
|
-
// Check cache first
|
|
156
|
-
const cached = this.get(key) as R | null;
|
|
157
|
-
if (cached !== null) {
|
|
158
|
-
return cached;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Execute function and cache result
|
|
162
|
-
const result = await fn();
|
|
163
|
-
this.set(key, result as any);
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Batch get multiple keys
|
|
169
|
-
*/
|
|
170
|
-
getBatch(keys: string[]): Map<string, T | null> {
|
|
171
|
-
const results = new Map<string, T | null>();
|
|
172
|
-
for (const key of keys) {
|
|
173
|
-
results.set(key, this.get(key));
|
|
174
|
-
}
|
|
175
|
-
return results;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Invalidate cache entries by pattern
|
|
180
|
-
*/
|
|
181
|
-
invalidatePattern(pattern: RegExp): number {
|
|
182
|
-
let count = 0;
|
|
183
|
-
for (const key of this.cache.keys()) {
|
|
184
|
-
if (pattern.test(key)) {
|
|
185
|
-
this.cache.delete(key);
|
|
186
|
-
count++;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (this.enableMetrics) {
|
|
190
|
-
this.metrics.size = this.cache.size;
|
|
191
|
-
}
|
|
192
|
-
return count;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Global cache instances for different purposes
|
|
197
|
-
export const assetCache = new CacheManager({
|
|
198
|
-
maxSize: 500,
|
|
199
|
-
defaultTTL: 300000, // 5 minutes for assets
|
|
200
|
-
enableMetrics: true
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
export const engineCache = new CacheManager({
|
|
204
|
-
maxSize: 50,
|
|
205
|
-
defaultTTL: 600000, // 10 minutes for engine info
|
|
206
|
-
enableMetrics: true
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
export const commandCache = new CacheManager({
|
|
210
|
-
maxSize: 100,
|
|
211
|
-
defaultTTL: 30000, // 30 seconds for commands
|
|
212
|
-
enableMetrics: true
|
|
213
|
-
});
|