@holoscript/core 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/dist/chunk-2XXE34KS.js +344 -0
  2. package/dist/chunk-2XXE34KS.js.map +1 -0
  3. package/dist/chunk-3X2EGU7Z.cjs +52 -0
  4. package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
  5. package/dist/chunk-AFFVFO4D.js +1689 -0
  6. package/dist/chunk-AFFVFO4D.js.map +1 -0
  7. package/dist/chunk-DGUM43GV.js +10 -0
  8. package/dist/chunk-DGUM43GV.js.map +1 -0
  9. package/{src/HoloScriptDebugger.ts → dist/chunk-DOY73HDH.js} +118 -257
  10. package/dist/chunk-DOY73HDH.js.map +1 -0
  11. package/dist/chunk-JEQ2X3Z6.cjs +12 -0
  12. package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
  13. package/dist/chunk-L6VLNVKP.cjs +1691 -0
  14. package/dist/chunk-L6VLNVKP.cjs.map +1 -0
  15. package/dist/chunk-MFNO57XL.cjs +347 -0
  16. package/dist/chunk-MFNO57XL.cjs.map +1 -0
  17. package/dist/chunk-R75MREOS.cjs +424 -0
  18. package/dist/chunk-R75MREOS.cjs.map +1 -0
  19. package/dist/chunk-SATNCODL.js +45 -0
  20. package/dist/chunk-SATNCODL.js.map +1 -0
  21. package/dist/chunk-T57ZL7KR.cjs +1281 -0
  22. package/dist/chunk-T57ZL7KR.cjs.map +1 -0
  23. package/dist/chunk-U72GEJZT.js +1279 -0
  24. package/dist/chunk-U72GEJZT.js.map +1 -0
  25. package/dist/debugger.cjs +20 -0
  26. package/dist/debugger.cjs.map +1 -0
  27. package/dist/debugger.d.cts +171 -0
  28. package/dist/debugger.d.ts +171 -0
  29. package/dist/debugger.js +7 -0
  30. package/dist/debugger.js.map +1 -0
  31. package/dist/index.cjs +6803 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +4093 -0
  34. package/dist/index.d.ts +4093 -0
  35. package/dist/index.js +6715 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/parser.cjs +14 -0
  38. package/dist/parser.cjs.map +1 -0
  39. package/dist/parser.d.cts +172 -0
  40. package/dist/parser.d.ts +172 -0
  41. package/dist/parser.js +5 -0
  42. package/dist/parser.js.map +1 -0
  43. package/dist/runtime.cjs +14 -0
  44. package/dist/runtime.cjs.map +1 -0
  45. package/dist/runtime.d.cts +200 -0
  46. package/dist/runtime.d.ts +200 -0
  47. package/dist/runtime.js +5 -0
  48. package/dist/runtime.js.map +1 -0
  49. package/dist/type-checker.cjs +17 -0
  50. package/dist/type-checker.cjs.map +1 -0
  51. package/dist/type-checker.d.cts +105 -0
  52. package/dist/type-checker.d.ts +105 -0
  53. package/dist/type-checker.js +4 -0
  54. package/dist/type-checker.js.map +1 -0
  55. package/dist/types-4h8cbtF_.d.cts +329 -0
  56. package/dist/types-4h8cbtF_.d.ts +329 -0
  57. package/package.json +17 -13
  58. package/src/HoloScript2DParser.js +0 -227
  59. package/src/HoloScript2DParser.ts +0 -261
  60. package/src/HoloScriptCodeParser.js +0 -1102
  61. package/src/HoloScriptCodeParser.ts +0 -1188
  62. package/src/HoloScriptDebugger.js +0 -458
  63. package/src/HoloScriptParser.js +0 -338
  64. package/src/HoloScriptParser.ts +0 -397
  65. package/src/HoloScriptPlusParser.js +0 -371
  66. package/src/HoloScriptPlusParser.ts +0 -543
  67. package/src/HoloScriptRuntime.js +0 -1399
  68. package/src/HoloScriptRuntime.test.js +0 -351
  69. package/src/HoloScriptRuntime.test.ts +0 -436
  70. package/src/HoloScriptRuntime.ts +0 -1653
  71. package/src/HoloScriptTypeChecker.js +0 -356
  72. package/src/HoloScriptTypeChecker.ts +0 -475
  73. package/src/__tests__/GraphicsServices.test.js +0 -357
  74. package/src/__tests__/GraphicsServices.test.ts +0 -427
  75. package/src/__tests__/HoloScriptPlusParser.test.js +0 -317
  76. package/src/__tests__/HoloScriptPlusParser.test.ts +0 -392
  77. package/src/__tests__/integration.test.js +0 -336
  78. package/src/__tests__/integration.test.ts +0 -416
  79. package/src/__tests__/performance.bench.js +0 -218
  80. package/src/__tests__/performance.bench.ts +0 -262
  81. package/src/__tests__/type-checker.test.js +0 -60
  82. package/src/__tests__/type-checker.test.ts +0 -73
  83. package/src/index.js +0 -217
  84. package/src/index.ts +0 -426
  85. package/src/interop/Interoperability.js +0 -413
  86. package/src/interop/Interoperability.ts +0 -494
  87. package/src/logger.js +0 -42
  88. package/src/logger.ts +0 -57
  89. package/src/parser/EnhancedParser.js +0 -205
  90. package/src/parser/EnhancedParser.ts +0 -251
  91. package/src/parser/HoloScriptPlusParser.js +0 -928
  92. package/src/parser/HoloScriptPlusParser.ts +0 -1089
  93. package/src/runtime/HoloScriptPlusRuntime.js +0 -674
  94. package/src/runtime/HoloScriptPlusRuntime.ts +0 -861
  95. package/src/runtime/PerformanceTelemetry.js +0 -323
  96. package/src/runtime/PerformanceTelemetry.ts +0 -467
  97. package/src/runtime/RuntimeOptimization.js +0 -361
  98. package/src/runtime/RuntimeOptimization.ts +0 -416
  99. package/src/services/HololandGraphicsPipelineService.js +0 -506
  100. package/src/services/HololandGraphicsPipelineService.ts +0 -662
  101. package/src/services/PlatformPerformanceOptimizer.js +0 -356
  102. package/src/services/PlatformPerformanceOptimizer.ts +0 -503
  103. package/src/state/ReactiveState.js +0 -427
  104. package/src/state/ReactiveState.ts +0 -572
  105. package/src/tools/DeveloperExperience.js +0 -376
  106. package/src/tools/DeveloperExperience.ts +0 -438
  107. package/src/traits/AIDriverTrait.js +0 -322
  108. package/src/traits/AIDriverTrait.test.js +0 -329
  109. package/src/traits/AIDriverTrait.test.ts +0 -357
  110. package/src/traits/AIDriverTrait.ts +0 -474
  111. package/src/traits/LightingTrait.js +0 -313
  112. package/src/traits/LightingTrait.test.js +0 -410
  113. package/src/traits/LightingTrait.test.ts +0 -462
  114. package/src/traits/LightingTrait.ts +0 -505
  115. package/src/traits/MaterialTrait.js +0 -194
  116. package/src/traits/MaterialTrait.test.js +0 -286
  117. package/src/traits/MaterialTrait.test.ts +0 -329
  118. package/src/traits/MaterialTrait.ts +0 -324
  119. package/src/traits/RenderingTrait.js +0 -356
  120. package/src/traits/RenderingTrait.test.js +0 -363
  121. package/src/traits/RenderingTrait.test.ts +0 -427
  122. package/src/traits/RenderingTrait.ts +0 -555
  123. package/src/traits/VRTraitSystem.js +0 -740
  124. package/src/traits/VRTraitSystem.ts +0 -1040
  125. package/src/traits/VoiceInputTrait.js +0 -284
  126. package/src/traits/VoiceInputTrait.test.js +0 -226
  127. package/src/traits/VoiceInputTrait.test.ts +0 -252
  128. package/src/traits/VoiceInputTrait.ts +0 -401
  129. package/src/types/AdvancedTypeSystem.js +0 -226
  130. package/src/types/AdvancedTypeSystem.ts +0 -494
  131. package/src/types/HoloScriptPlus.d.ts +0 -853
  132. package/src/types.js +0 -6
  133. package/src/types.ts +0 -369
  134. package/tsconfig.json +0 -23
  135. package/tsup.config.d.ts +0 -2
  136. package/tsup.config.js +0 -18
  137. package/tsup.config.ts +0 -19
@@ -0,0 +1,1691 @@
1
+ 'use strict';
2
+
3
+ var chunk3X2EGU7Z_cjs = require('./chunk-3X2EGU7Z.cjs');
4
+
5
+ // src/ReactiveState.ts
6
+ var ReactiveState = class {
7
+ constructor(initialState = {}) {
8
+ this.subscribers = /* @__PURE__ */ new Set();
9
+ this.state = { ...initialState };
10
+ this.proxy = this.createReactiveProxy(this.state);
11
+ }
12
+ createReactiveProxy(target) {
13
+ const self = this;
14
+ return new Proxy(target, {
15
+ get(obj, key) {
16
+ const val = obj[key];
17
+ if (val && typeof val === "object" && !Array.isArray(val)) {
18
+ return self.createReactiveProxy(val);
19
+ }
20
+ return val;
21
+ },
22
+ set(obj, key, value) {
23
+ const oldVal = obj[key];
24
+ obj[key] = value;
25
+ if (oldVal !== value) {
26
+ self.notify();
27
+ }
28
+ return true;
29
+ }
30
+ });
31
+ }
32
+ get(key) {
33
+ return this.proxy[key];
34
+ }
35
+ set(key, value) {
36
+ this.proxy[key] = value;
37
+ }
38
+ update(updates) {
39
+ Object.assign(this.proxy, updates);
40
+ }
41
+ subscribe(callback) {
42
+ this.subscribers.add(callback);
43
+ return () => this.subscribers.delete(callback);
44
+ }
45
+ getSnapshot() {
46
+ return { ...this.state };
47
+ }
48
+ notify() {
49
+ this.subscribers.forEach((cb) => cb(this.getSnapshot()));
50
+ }
51
+ };
52
+ var ExpressionEvaluator = class {
53
+ constructor(context = {}) {
54
+ this.context = context;
55
+ }
56
+ evaluate(expression) {
57
+ if (typeof expression !== "string") return expression;
58
+ const dangerousPatterns = [
59
+ /\beval\s*\(/,
60
+ /\brequire\s*\(/,
61
+ /\bimport\s*\(/,
62
+ /\bprocess\s*\./,
63
+ /\bglobal\s*\./,
64
+ /\b__dirname\b/,
65
+ /\b__filename\b/,
66
+ /\bfs\s*\./,
67
+ /\bchild_process\s*\./,
68
+ /\bfs\.writeFileSync/,
69
+ /\bfs\.readFileSync/
70
+ ];
71
+ for (const pattern of dangerousPatterns) {
72
+ if (pattern.test(expression)) {
73
+ console.warn(`Security: Blocked suspicious expression: ${expression}`);
74
+ return void 0;
75
+ }
76
+ }
77
+ if (expression.includes("${")) {
78
+ const trimmed = expression.trim();
79
+ const match = trimmed.match(/^\$\{([^}]+)\}$/);
80
+ if (match) {
81
+ return this.evaluate(match[1]);
82
+ }
83
+ return this.interpolate(expression);
84
+ }
85
+ const keys = Object.keys(this.context);
86
+ const values = Object.values(this.context);
87
+ try {
88
+ const fn = new Function(...keys, `return (${expression})`);
89
+ return fn(...values);
90
+ } catch (e) {
91
+ return expression;
92
+ }
93
+ }
94
+ interpolate(str) {
95
+ return str.replace(/\$\{([^}]+)\}/g, (_, expr) => {
96
+ const val = this.evaluate(expr);
97
+ return val !== void 0 ? String(val) : "";
98
+ });
99
+ }
100
+ updateContext(updates) {
101
+ Object.assign(this.context, updates);
102
+ }
103
+ setContext(context) {
104
+ this.context = { ...context };
105
+ }
106
+ };
107
+ function createState(initial = {}) {
108
+ return new ReactiveState(initial);
109
+ }
110
+
111
+ // src/HoloScriptRuntime.ts
112
+ var RUNTIME_SECURITY_LIMITS = {
113
+ maxExecutionDepth: 50,
114
+ maxTotalNodes: 1e3,
115
+ maxExecutionTimeMs: 5e3,
116
+ maxParticlesPerSystem: 1e3,
117
+ maxCallStackDepth: 100
118
+ };
119
+ var HoloScriptRuntime = class {
120
+ constructor(_importLoader, customFunctions) {
121
+ this.particleSystems = /* @__PURE__ */ new Map();
122
+ this.executionHistory = [];
123
+ this.startTime = 0;
124
+ this.nodeCount = 0;
125
+ this.callStack = [];
126
+ this.eventHandlers = /* @__PURE__ */ new Map();
127
+ this.animations = /* @__PURE__ */ new Map();
128
+ this.uiElements = /* @__PURE__ */ new Map();
129
+ this.context = this.createEmptyContext();
130
+ this.currentScope = { variables: this.context.variables };
131
+ this.builtinFunctions = this.initBuiltins(customFunctions);
132
+ }
133
+ /**
134
+ * Initialize built-in functions
135
+ */
136
+ initBuiltins(customFunctions) {
137
+ const builtins = /* @__PURE__ */ new Map();
138
+ if (customFunctions) {
139
+ for (const [name, func] of Object.entries(customFunctions)) {
140
+ builtins.set(name, func);
141
+ }
142
+ }
143
+ builtins.set("show", (args) => {
144
+ const target = String(args[0]);
145
+ const element = this.uiElements.get(target);
146
+ if (element) element.visible = true;
147
+ const hologram = this.context.hologramState.get(target);
148
+ if (hologram) {
149
+ this.createParticleEffect(`${target}_show`, { x: 0, y: 0, z: 0 }, hologram.color, 15);
150
+ }
151
+ chunk3X2EGU7Z_cjs.logger.info("show", { target });
152
+ return { shown: target };
153
+ });
154
+ builtins.set("hide", (args) => {
155
+ const target = String(args[0]);
156
+ const element = this.uiElements.get(target);
157
+ if (element) element.visible = false;
158
+ chunk3X2EGU7Z_cjs.logger.info("hide", { target });
159
+ return { hidden: target };
160
+ });
161
+ builtins.set("pulsate", (args) => {
162
+ const target = String(args[0]);
163
+ const options = args[1] || {};
164
+ const duration = Number(options.duration) || 1e3;
165
+ const color = String(options.color || "#ffffff");
166
+ const position = this.context.spatialMemory.get(target) || { x: 0, y: 0, z: 0 };
167
+ this.createParticleEffect(`${target}_pulse`, position, color, 30);
168
+ return { pulsing: target, duration };
169
+ });
170
+ builtins.set("animate", (args) => {
171
+ const target = String(args[0]);
172
+ const options = args[1] || {};
173
+ const animation = {
174
+ target,
175
+ property: String(options.property || "position.y"),
176
+ from: Number(options.from || 0),
177
+ to: Number(options.to || 1),
178
+ duration: Number(options.duration || 1e3),
179
+ startTime: Date.now(),
180
+ easing: String(options.easing || "linear"),
181
+ loop: Boolean(options.loop),
182
+ yoyo: Boolean(options.yoyo)
183
+ };
184
+ this.animations.set(`${target}_${animation.property}`, animation);
185
+ return { animating: target, animation };
186
+ });
187
+ builtins.set("spawn", (args) => {
188
+ const target = String(args[0]);
189
+ const position = args[1] || { x: 0, y: 0, z: 0 };
190
+ this.context.spatialMemory.set(target, position);
191
+ this.createParticleEffect(`${target}_spawn`, position, "#00ff00", 25);
192
+ return { spawned: target, at: position };
193
+ });
194
+ builtins.set("move", (args) => {
195
+ const target = String(args[0]);
196
+ const position = args[1] || { x: 0, y: 0, z: 0 };
197
+ const current = this.context.spatialMemory.get(target);
198
+ if (current) {
199
+ this.context.spatialMemory.set(target, position);
200
+ this.createConnectionStream(target, `${target}_dest`, current, position, "move");
201
+ }
202
+ return { moved: target, to: position };
203
+ });
204
+ builtins.set("set", (args) => {
205
+ const target = String(args[0]);
206
+ const value = args[1];
207
+ this.setVariable(target, value);
208
+ return { set: target, value };
209
+ });
210
+ builtins.set("get", (args) => {
211
+ const target = String(args[0]);
212
+ return this.getVariable(target);
213
+ });
214
+ builtins.set("add", (args) => Number(args[0]) + Number(args[1]));
215
+ builtins.set("subtract", (args) => Number(args[0]) - Number(args[1]));
216
+ builtins.set("multiply", (args) => Number(args[0]) * Number(args[1]));
217
+ builtins.set("divide", (args) => Number(args[1]) !== 0 ? Number(args[0]) / Number(args[1]) : 0);
218
+ builtins.set("mod", (args) => Number(args[0]) % Number(args[1]));
219
+ builtins.set("abs", (args) => Math.abs(Number(args[0])));
220
+ builtins.set("floor", (args) => Math.floor(Number(args[0])));
221
+ builtins.set("ceil", (args) => Math.ceil(Number(args[0])));
222
+ builtins.set("round", (args) => Math.round(Number(args[0])));
223
+ builtins.set("min", (args) => Math.min(...args.map(Number)));
224
+ builtins.set("max", (args) => Math.max(...args.map(Number)));
225
+ builtins.set("random", () => Math.random());
226
+ builtins.set("concat", (args) => args.map(String).join(""));
227
+ builtins.set("length", (args) => {
228
+ const val = args[0];
229
+ if (typeof val === "string") return val.length;
230
+ if (Array.isArray(val)) return val.length;
231
+ return 0;
232
+ });
233
+ builtins.set("substring", (args) => String(args[0]).substring(Number(args[1]), Number(args[2])));
234
+ builtins.set("uppercase", (args) => String(args[0]).toUpperCase());
235
+ builtins.set("lowercase", (args) => String(args[0]).toLowerCase());
236
+ builtins.set("push", (args) => {
237
+ const arr = args[0];
238
+ if (Array.isArray(arr)) {
239
+ arr.push(args[1]);
240
+ return arr;
241
+ }
242
+ return [args[0], args[1]];
243
+ });
244
+ builtins.set("pop", (args) => {
245
+ const arr = args[0];
246
+ if (Array.isArray(arr)) return arr.pop();
247
+ return void 0;
248
+ });
249
+ builtins.set("at", (args) => {
250
+ const arr = args[0];
251
+ const index = Number(args[1]);
252
+ if (Array.isArray(arr)) return arr[index];
253
+ return void 0;
254
+ });
255
+ builtins.set("showSettings", () => {
256
+ this.emit("show-settings");
257
+ return true;
258
+ });
259
+ builtins.set("openChat", (args) => {
260
+ const config = args[0] || {};
261
+ this.emit("show-chat", config);
262
+ return true;
263
+ });
264
+ builtins.set("log", (args) => {
265
+ chunk3X2EGU7Z_cjs.logger.info("HoloScript log", { args });
266
+ return args[0];
267
+ });
268
+ builtins.set("print", (args) => {
269
+ const message = args.map(String).join(" ");
270
+ chunk3X2EGU7Z_cjs.logger.info("print", { message });
271
+ return message;
272
+ });
273
+ builtins.set("typeof", (args) => typeof args[0]);
274
+ builtins.set("isArray", (args) => Array.isArray(args[0]));
275
+ builtins.set("isNumber", (args) => typeof args[0] === "number" && !isNaN(args[0]));
276
+ builtins.set("isString", (args) => typeof args[0] === "string");
277
+ builtins.set("shop", (args) => this.handleShop(args));
278
+ builtins.set("inventory", (args) => this.handleInventory(args));
279
+ builtins.set("purchase", (args) => this.handlePurchase(args));
280
+ builtins.set("presence", (args) => this.handlePresence(args));
281
+ builtins.set("invite", (args) => this.handleInvite(args));
282
+ builtins.set("share", (args) => this.handleShare(args));
283
+ builtins.set("physics", (args) => this.handlePhysics(args));
284
+ builtins.set("gravity", (args) => this.handleGravity(args));
285
+ builtins.set("collide", (args) => this.handleCollide(args));
286
+ builtins.set("animate", (args) => this.handleAnimate(args));
287
+ builtins.set("calculate_arc", (args) => this.handleCalculateArc(args));
288
+ return builtins;
289
+ }
290
+ /**
291
+ * Execute a single AST node
292
+ */
293
+ async executeNode(node) {
294
+ const startTime = Date.now();
295
+ try {
296
+ this.context.executionStack.push(node);
297
+ let result;
298
+ switch (node.type) {
299
+ case "orb":
300
+ result = await this.executeOrb(node);
301
+ break;
302
+ case "method":
303
+ case "function":
304
+ result = await this.executeFunction(node);
305
+ break;
306
+ case "connection":
307
+ result = await this.executeConnection(node);
308
+ break;
309
+ case "gate":
310
+ result = await this.executeGate(node);
311
+ break;
312
+ case "stream":
313
+ result = await this.executeStream(node);
314
+ break;
315
+ case "call":
316
+ result = await this.executeCall(node);
317
+ break;
318
+ case "debug":
319
+ result = await this.executeDebug(node);
320
+ break;
321
+ case "visualize":
322
+ result = await this.executeVisualize(node);
323
+ break;
324
+ case "2d-element":
325
+ result = await this.executeUIElement(node);
326
+ break;
327
+ case "nexus":
328
+ case "building":
329
+ result = await this.executeStructure(node);
330
+ break;
331
+ case "assignment":
332
+ result = await this.executeAssignment(node);
333
+ break;
334
+ case "return":
335
+ result = await this.executeReturn(node);
336
+ break;
337
+ case "generic":
338
+ result = await this.executeGeneric(node);
339
+ break;
340
+ case "expression-statement":
341
+ result = await this.executeCall(node);
342
+ break;
343
+ case "scale":
344
+ result = await this.executeScale(node);
345
+ break;
346
+ case "focus":
347
+ result = await this.executeFocus(node);
348
+ break;
349
+ case "environment":
350
+ result = await this.executeEnvironment(node);
351
+ break;
352
+ case "composition":
353
+ result = await this.executeComposition(node);
354
+ break;
355
+ case "template":
356
+ result = await this.executeTemplate(node);
357
+ break;
358
+ case "server":
359
+ result = await this.executeServerNode(node);
360
+ break;
361
+ case "database":
362
+ result = await this.executeDatabaseNode(node);
363
+ break;
364
+ case "fetch":
365
+ result = await this.executeFetchNode(node);
366
+ break;
367
+ case "execute":
368
+ result = await this.executeTarget(node);
369
+ break;
370
+ case "state-declaration":
371
+ result = await this.executeStateDeclaration(node);
372
+ break;
373
+ default:
374
+ result = {
375
+ success: false,
376
+ error: `Unknown node type: ${node.type}`,
377
+ executionTime: Date.now() - startTime
378
+ };
379
+ }
380
+ result.executionTime = Date.now() - startTime;
381
+ this.executionHistory.push(result);
382
+ this.context.executionStack.pop();
383
+ return result;
384
+ } catch (error) {
385
+ const execTime = Date.now() - startTime;
386
+ const errorResult = {
387
+ success: false,
388
+ error: error instanceof Error ? error.message : String(error),
389
+ executionTime: execTime
390
+ };
391
+ this.executionHistory.push(errorResult);
392
+ this.context.executionStack.pop();
393
+ return errorResult;
394
+ }
395
+ }
396
+ /**
397
+ * Execute multiple nodes or a single node (unified entry point)
398
+ */
399
+ async execute(nodes) {
400
+ if (Array.isArray(nodes)) {
401
+ const results = await this.executeProgram(nodes);
402
+ const success = results.every((r) => r.success);
403
+ return {
404
+ success,
405
+ output: success ? `Program executed (${results.length} nodes)` : "Program failed",
406
+ error: results.find((r) => !r.success)?.error
407
+ };
408
+ } else {
409
+ return this.executeNode(nodes);
410
+ }
411
+ }
412
+ /**
413
+ * Execute multiple nodes in sequence
414
+ */
415
+ async executeProgram(nodes, depth = 0) {
416
+ if (depth === 0) {
417
+ this.startTime = Date.now();
418
+ this.nodeCount = 0;
419
+ }
420
+ if (depth > RUNTIME_SECURITY_LIMITS.maxExecutionDepth) {
421
+ chunk3X2EGU7Z_cjs.logger.error("Max execution depth exceeded", { depth });
422
+ return [{
423
+ success: false,
424
+ error: `Max execution depth exceeded (${RUNTIME_SECURITY_LIMITS.maxExecutionDepth})`,
425
+ executionTime: 0
426
+ }];
427
+ }
428
+ const results = [];
429
+ for (const node of nodes) {
430
+ this.nodeCount++;
431
+ if (this.nodeCount > RUNTIME_SECURITY_LIMITS.maxTotalNodes) {
432
+ chunk3X2EGU7Z_cjs.logger.error("Max total nodes exceeded", { count: this.nodeCount });
433
+ results.push({
434
+ success: false,
435
+ error: "Max total nodes exceeded",
436
+ executionTime: Date.now() - this.startTime
437
+ });
438
+ break;
439
+ }
440
+ if (Date.now() - this.startTime > RUNTIME_SECURITY_LIMITS.maxExecutionTimeMs) {
441
+ chunk3X2EGU7Z_cjs.logger.error("Execution timeout", { duration: Date.now() - this.startTime });
442
+ results.push({
443
+ success: false,
444
+ error: "Execution timeout",
445
+ executionTime: Date.now() - this.startTime
446
+ });
447
+ break;
448
+ }
449
+ const result = await this.executeNode(node);
450
+ results.push(result);
451
+ if (!result.success && node.type !== "visualize") {
452
+ break;
453
+ }
454
+ if (node.type === "return") {
455
+ break;
456
+ }
457
+ }
458
+ return results;
459
+ }
460
+ /**
461
+ * Call a function with arguments
462
+ */
463
+ async callFunction(name, args = []) {
464
+ const builtin = this.builtinFunctions.get(name);
465
+ if (builtin) {
466
+ try {
467
+ const result = builtin(args);
468
+ return {
469
+ success: true,
470
+ output: result
471
+ };
472
+ } catch (error) {
473
+ return {
474
+ success: false,
475
+ error: `Built-in function ${name} failed: ${error}`
476
+ };
477
+ }
478
+ }
479
+ const func = this.context.functions.get(name);
480
+ if (!func) {
481
+ return {
482
+ success: false,
483
+ error: `Function '${name}' not found`
484
+ };
485
+ }
486
+ if (this.callStack.length >= RUNTIME_SECURITY_LIMITS.maxCallStackDepth) {
487
+ return {
488
+ success: false,
489
+ error: `Max call stack depth exceeded (${RUNTIME_SECURITY_LIMITS.maxCallStackDepth})`
490
+ };
491
+ }
492
+ const parentScope = this.currentScope;
493
+ this.currentScope = {
494
+ variables: /* @__PURE__ */ new Map(),
495
+ parent: parentScope
496
+ };
497
+ func.parameters.forEach((param, index) => {
498
+ const value = index < args.length ? args[index] : param.defaultValue;
499
+ this.currentScope.variables.set(param.name, value);
500
+ });
501
+ this.callStack.push(name);
502
+ let returnValue = void 0;
503
+ try {
504
+ const results = await this.executeProgram(func.body, this.callStack.length);
505
+ const lastResult = results[results.length - 1];
506
+ if (lastResult?.output !== void 0) {
507
+ returnValue = lastResult.output;
508
+ }
509
+ this.createExecutionEffect(name, func.position || { x: 0, y: 0, z: 0 });
510
+ return {
511
+ success: results.every((r) => r.success),
512
+ output: returnValue,
513
+ hologram: func.hologram,
514
+ spatialPosition: func.position
515
+ };
516
+ } finally {
517
+ this.currentScope = parentScope;
518
+ this.callStack.pop();
519
+ }
520
+ }
521
+ /**
522
+ * Set a variable in current scope
523
+ */
524
+ setVariable(name, value) {
525
+ if (name.includes(".")) {
526
+ const parts = name.split(".");
527
+ const objName = parts[0];
528
+ const propPath = parts.slice(1);
529
+ let obj = this.getVariable(objName);
530
+ if (obj === void 0 || typeof obj !== "object" || obj === null) {
531
+ obj = {};
532
+ this.currentScope.variables.set(objName, obj);
533
+ }
534
+ let current = obj;
535
+ for (let i = 0; i < propPath.length - 1; i++) {
536
+ if (current[propPath[i]] === void 0 || typeof current[propPath[i]] !== "object") {
537
+ current[propPath[i]] = {};
538
+ }
539
+ current = current[propPath[i]];
540
+ }
541
+ current[propPath[propPath.length - 1]] = value;
542
+ } else {
543
+ this.currentScope.variables.set(name, value);
544
+ }
545
+ }
546
+ /**
547
+ * Get a variable from scope chain
548
+ */
549
+ getVariable(name) {
550
+ if (name.includes(".")) {
551
+ const parts = name.split(".");
552
+ let value = this.getVariable(parts[0]);
553
+ for (let i = 1; i < parts.length && value !== void 0; i++) {
554
+ if (typeof value === "object" && value !== null) {
555
+ value = value[parts[i]];
556
+ } else {
557
+ return void 0;
558
+ }
559
+ }
560
+ return value;
561
+ }
562
+ let scope = this.currentScope;
563
+ while (scope) {
564
+ if (scope.variables.has(name)) {
565
+ return scope.variables.get(name);
566
+ }
567
+ scope = scope.parent;
568
+ }
569
+ if (this.context.variables.has(name)) {
570
+ return this.context.variables.get(name);
571
+ }
572
+ if (this.context.functions.has(name)) {
573
+ return this.context.functions.get(name);
574
+ }
575
+ return void 0;
576
+ }
577
+ /**
578
+ * Evaluate an expression
579
+ */
580
+ evaluateExpression(expr) {
581
+ if (!expr || typeof expr !== "string") return expr;
582
+ const evaluator = new ExpressionEvaluator(this.context.state.getSnapshot());
583
+ const varContext = {};
584
+ this.context.variables.forEach((v, k) => varContext[k] = v);
585
+ evaluator.updateContext(varContext);
586
+ return evaluator.evaluate(expr);
587
+ }
588
+ // ============================================================================
589
+ // Node Executors
590
+ // ============================================================================
591
+ async executeOrb(node) {
592
+ const scale = this.context.currentScale || 1;
593
+ const adjustedPos = node.position ? {
594
+ x: node.position.x * scale,
595
+ y: node.position.y * scale,
596
+ z: node.position.z * scale
597
+ } : { x: 0, y: 0, z: 0 };
598
+ if (node.position) {
599
+ this.context.spatialMemory.set(node.name, adjustedPos);
600
+ }
601
+ const hologram = node.hologram ? {
602
+ ...node.hologram,
603
+ size: (node.hologram.size || 1) * scale
604
+ } : void 0;
605
+ const evaluatedProperties = {};
606
+ for (const [key, val] of Object.entries(node.properties)) {
607
+ if (typeof val === "string") {
608
+ evaluatedProperties[key] = this.evaluateExpression(val);
609
+ } else {
610
+ evaluatedProperties[key] = val;
611
+ }
612
+ }
613
+ const orbData = {
614
+ __type: "orb",
615
+ name: node.name,
616
+ properties: evaluatedProperties,
617
+ traits: node.directives?.filter((d) => d.type === "trait").map((d) => d.name) || [],
618
+ directives: node.directives || [],
619
+ position: adjustedPos,
620
+ hologram,
621
+ created: Date.now(),
622
+ // Methods bound to this orb
623
+ show: () => this.builtinFunctions.get("show")([node.name]),
624
+ hide: () => this.builtinFunctions.get("hide")([node.name]),
625
+ pulse: (opts) => this.builtinFunctions.get("pulse")([node.name, opts])
626
+ };
627
+ this.context.variables.set(node.name, orbData);
628
+ if (hologram) {
629
+ this.context.hologramState.set(node.name, hologram);
630
+ }
631
+ if (node.directives) {
632
+ this.applyDirectives(node);
633
+ }
634
+ this.createParticleEffect(`${node.name}_creation`, adjustedPos, "#00ffff", 20);
635
+ chunk3X2EGU7Z_cjs.logger.info("Orb created", { name: node.name, properties: Object.keys(node.properties), scale });
636
+ return {
637
+ success: true,
638
+ output: orbData,
639
+ hologram,
640
+ spatialPosition: adjustedPos
641
+ };
642
+ }
643
+ async executeFunction(node) {
644
+ this.context.functions.set(node.name, node);
645
+ const hologram = {
646
+ shape: "cube",
647
+ color: "#ff6b35",
648
+ size: 1.5,
649
+ glow: true,
650
+ interactive: true,
651
+ ...node.hologram
652
+ };
653
+ this.context.hologramState.set(node.name, hologram);
654
+ chunk3X2EGU7Z_cjs.logger.info("Function defined", { name: node.name, params: node.parameters.map((p) => p.name) });
655
+ return {
656
+ success: true,
657
+ output: `Function '${node.name}' defined with ${node.parameters.length} parameter(s)`,
658
+ hologram,
659
+ spatialPosition: node.position
660
+ };
661
+ }
662
+ async executeConnection(node) {
663
+ this.context.connections.push(node);
664
+ const fromPos = this.context.spatialMemory.get(node.from);
665
+ const toPos = this.context.spatialMemory.get(node.to);
666
+ if (fromPos && toPos) {
667
+ this.createConnectionStream(node.from, node.to, fromPos, toPos, node.dataType);
668
+ }
669
+ if (node.bidirectional) {
670
+ this.on(`${node.from}.changed`, async (data) => {
671
+ this.setVariable(node.to, data);
672
+ this.emit(`${node.to}.changed`, data);
673
+ });
674
+ this.on(`${node.to}.changed`, async (data) => {
675
+ this.setVariable(node.from, data);
676
+ this.emit(`${node.from}.changed`, data);
677
+ });
678
+ }
679
+ chunk3X2EGU7Z_cjs.logger.info("Connection created", { from: node.from, to: node.to, dataType: node.dataType });
680
+ return {
681
+ success: true,
682
+ output: `Connected '${node.from}' to '${node.to}' (${node.dataType})`,
683
+ hologram: {
684
+ shape: "cylinder",
685
+ color: this.getDataTypeColor(node.dataType),
686
+ size: 0.1,
687
+ glow: true,
688
+ interactive: false
689
+ }
690
+ };
691
+ }
692
+ async executeGate(node) {
693
+ try {
694
+ const condition = this.evaluateCondition(node.condition);
695
+ const path = condition ? node.truePath : node.falsePath;
696
+ chunk3X2EGU7Z_cjs.logger.info("Gate evaluation", { condition: node.condition, result: condition });
697
+ if (path.length > 0) {
698
+ await this.executeProgram(path, this.callStack.length + 1);
699
+ }
700
+ return {
701
+ success: true,
702
+ output: `Gate: took ${condition ? "true" : "false"} path`,
703
+ hologram: {
704
+ shape: "pyramid",
705
+ color: condition ? "#00ff00" : "#ff0000",
706
+ size: 1,
707
+ glow: true,
708
+ interactive: true
709
+ }
710
+ };
711
+ } catch (error) {
712
+ return {
713
+ success: false,
714
+ error: `Gate execution failed: ${error}`
715
+ };
716
+ }
717
+ }
718
+ async executeStream(node) {
719
+ let data = this.getVariable(node.source);
720
+ chunk3X2EGU7Z_cjs.logger.info("Stream processing", { name: node.name, source: node.source, transforms: node.transformations.length });
721
+ for (const transform of node.transformations) {
722
+ data = await this.applyTransformation(data, transform);
723
+ }
724
+ this.setVariable(`${node.name}_result`, data);
725
+ this.createFlowingStream(node.name, node.position || { x: 0, y: 0, z: 0 }, data);
726
+ return {
727
+ success: true,
728
+ output: `Stream '${node.name}' processed ${Array.isArray(data) ? data.length : 1} item(s)`,
729
+ hologram: node.hologram,
730
+ spatialPosition: node.position
731
+ };
732
+ }
733
+ async executeCall(node) {
734
+ const funcName = node.target || "";
735
+ const args = node.args || [];
736
+ return this.callFunction(funcName, args);
737
+ }
738
+ async executeDebug(node) {
739
+ const debugInfo = {
740
+ variables: Object.fromEntries(this.currentScope.variables),
741
+ contextVariables: Object.fromEntries(this.context.variables),
742
+ functions: Array.from(this.context.functions.keys()),
743
+ connections: this.context.connections.length,
744
+ callStack: [...this.callStack],
745
+ uiElements: Array.from(this.uiElements.keys()),
746
+ animations: Array.from(this.animations.keys()),
747
+ executionHistory: this.executionHistory.slice(-10)
748
+ };
749
+ const debugOrb = {
750
+ shape: "pyramid",
751
+ color: "#ff1493",
752
+ size: 0.8,
753
+ glow: true,
754
+ interactive: true
755
+ };
756
+ this.context.hologramState.set(`debug_${node.target || "program"}`, debugOrb);
757
+ chunk3X2EGU7Z_cjs.logger.info("Debug info", debugInfo);
758
+ return {
759
+ success: true,
760
+ output: debugInfo,
761
+ hologram: debugOrb
762
+ };
763
+ }
764
+ async executeVisualize(node) {
765
+ const target = node.target || "";
766
+ const data = this.getVariable(target);
767
+ if (data === void 0) {
768
+ return {
769
+ success: false,
770
+ error: `No data found for '${target}'`
771
+ };
772
+ }
773
+ const visHologram = {
774
+ shape: "cylinder",
775
+ color: "#32cd32",
776
+ size: 1.5,
777
+ glow: true,
778
+ interactive: true
779
+ };
780
+ this.createDataVisualization(target, data, node.position || { x: 0, y: 0, z: 0 });
781
+ return {
782
+ success: true,
783
+ output: { visualizing: target, data },
784
+ hologram: visHologram
785
+ };
786
+ }
787
+ async executeUIElement(node) {
788
+ const element = {
789
+ type: node.elementType,
790
+ name: node.name,
791
+ properties: { ...node.properties },
792
+ visible: true,
793
+ enabled: true
794
+ };
795
+ if (node.elementType === "textinput") {
796
+ element.value = node.properties.value || "";
797
+ } else if (node.elementType === "slider") {
798
+ element.value = node.properties.value || node.properties.min || 0;
799
+ } else if (node.elementType === "toggle") {
800
+ element.value = node.properties.checked || false;
801
+ }
802
+ this.uiElements.set(node.name, element);
803
+ if (node.events) {
804
+ for (const [eventName, handlerName] of Object.entries(node.events)) {
805
+ this.on(`${node.name}.${eventName}`, async () => {
806
+ await this.callFunction(handlerName);
807
+ });
808
+ }
809
+ }
810
+ chunk3X2EGU7Z_cjs.logger.info("UI element created", { type: node.elementType, name: node.name });
811
+ return {
812
+ success: true,
813
+ output: element
814
+ };
815
+ }
816
+ /**
817
+ * Execute generic voice commands
818
+ * Handles commands like: show, hide, animate, pulse, create
819
+ */
820
+ async executeGeneric(_node) {
821
+ const genericNode = _node;
822
+ const command = String(genericNode.command || "").trim().toLowerCase();
823
+ const tokens = command.split(/\s+/);
824
+ const action = tokens[0];
825
+ const target = tokens[1];
826
+ chunk3X2EGU7Z_cjs.logger.info("Executing generic command", { command, action, target });
827
+ try {
828
+ let result;
829
+ switch (action) {
830
+ case "show":
831
+ result = await this.executeShowCommand(target, genericNode);
832
+ break;
833
+ case "hide":
834
+ result = await this.executeHideCommand(target, genericNode);
835
+ break;
836
+ case "create":
837
+ case "summon":
838
+ result = await this.executeCreateCommand(tokens.slice(1), genericNode);
839
+ break;
840
+ case "animate":
841
+ result = await this.executeAnimateCommand(target, tokens.slice(2), genericNode);
842
+ break;
843
+ case "pulse":
844
+ result = await this.executePulseCommand(target, tokens.slice(2), genericNode);
845
+ break;
846
+ case "move":
847
+ result = await this.executeMoveCommand(target, tokens.slice(2), genericNode);
848
+ break;
849
+ case "delete":
850
+ case "remove":
851
+ result = await this.executeDeleteCommand(target, genericNode);
852
+ break;
853
+ default:
854
+ chunk3X2EGU7Z_cjs.logger.warn("Unknown voice command action", { action, command });
855
+ result = {
856
+ executed: false,
857
+ message: `Unknown command: ${action}`
858
+ };
859
+ }
860
+ return {
861
+ success: true,
862
+ output: result
863
+ };
864
+ } catch (error) {
865
+ return {
866
+ success: false,
867
+ error: `Generic command execution failed: ${String(error)}`
868
+ };
869
+ }
870
+ }
871
+ /**
872
+ * Execute 'show' command
873
+ */
874
+ async executeShowCommand(target, _node) {
875
+ const hologram = _node.hologram || {
876
+ shape: "orb",
877
+ color: "#00ffff",
878
+ size: 0.8,
879
+ glow: true,
880
+ interactive: true
881
+ };
882
+ const position = _node.position || { x: 0, y: 0, z: 0 };
883
+ this.context.spatialMemory.set(target, position);
884
+ this.createParticleEffect(`${target}_show`, position, hologram.color, 15);
885
+ chunk3X2EGU7Z_cjs.logger.info("Show command executed", { target, position });
886
+ return {
887
+ showed: target,
888
+ hologram,
889
+ position
890
+ };
891
+ }
892
+ /**
893
+ * Execute 'hide' command
894
+ */
895
+ async executeHideCommand(target, _node) {
896
+ const position = this.context.spatialMemory.get(target) || { x: 0, y: 0, z: 0 };
897
+ this.createParticleEffect(`${target}_hide`, position, "#ff0000", 10);
898
+ chunk3X2EGU7Z_cjs.logger.info("Hide command executed", { target });
899
+ return {
900
+ hidden: target
901
+ };
902
+ }
903
+ /**
904
+ * Execute 'create' command
905
+ */
906
+ async executeCreateCommand(tokens, _node) {
907
+ if (tokens.length < 2) {
908
+ return { error: "Create command requires shape and name" };
909
+ }
910
+ const shape = tokens[0];
911
+ const name = tokens[1];
912
+ const position = _node.position || { x: 0, y: 0, z: 0 };
913
+ const hologram = {
914
+ shape,
915
+ color: _node.hologram?.color || "#00ffff",
916
+ size: _node.hologram?.size || 1,
917
+ glow: _node.hologram?.glow !== false,
918
+ interactive: _node.hologram?.interactive !== false
919
+ };
920
+ this.context.spatialMemory.set(name, position);
921
+ this.createParticleEffect(`${name}_create`, position, hologram.color, 20);
922
+ chunk3X2EGU7Z_cjs.logger.info("Create command executed", { shape, name, position });
923
+ return {
924
+ created: name,
925
+ shape,
926
+ hologram,
927
+ position
928
+ };
929
+ }
930
+ /**
931
+ * Execute 'animate' command
932
+ */
933
+ async executeAnimateCommand(target, tokens, _node) {
934
+ const property = tokens[0] || "position.y";
935
+ const duration = parseInt(tokens[1] || "1000", 10);
936
+ const animation = {
937
+ target,
938
+ property,
939
+ from: 0,
940
+ to: 1,
941
+ duration,
942
+ startTime: Date.now(),
943
+ easing: "ease-in-out"
944
+ };
945
+ this.animations.set(`${target}_${property}`, animation);
946
+ chunk3X2EGU7Z_cjs.logger.info("Animate command executed", { target, property, duration });
947
+ return {
948
+ animating: target,
949
+ animation
950
+ };
951
+ }
952
+ /**
953
+ * Execute 'pulse' command
954
+ */
955
+ async executePulseCommand(target, tokens, _node) {
956
+ const duration = parseInt(tokens[0] || "500", 10);
957
+ const position = this.context.spatialMemory.get(target) || { x: 0, y: 0, z: 0 };
958
+ this.createParticleEffect(`${target}_pulse`, position, "#ffff00", 30);
959
+ const animation = {
960
+ target,
961
+ property: "scale",
962
+ from: 1,
963
+ to: 1.5,
964
+ duration,
965
+ startTime: Date.now(),
966
+ easing: "sine",
967
+ yoyo: true,
968
+ loop: true
969
+ };
970
+ this.animations.set(`${target}_pulse`, animation);
971
+ chunk3X2EGU7Z_cjs.logger.info("Pulse command executed", { target, duration });
972
+ return {
973
+ pulsing: target,
974
+ duration
975
+ };
976
+ }
977
+ /**
978
+ * Execute 'move' command
979
+ */
980
+ async executeMoveCommand(target, tokens, _node) {
981
+ const x = parseFloat(tokens[0] || "0");
982
+ const y = parseFloat(tokens[1] || "0");
983
+ const z = parseFloat(tokens[2] || "0");
984
+ const position = { x, y, z };
985
+ const current = this.context.spatialMemory.get(target);
986
+ if (current) {
987
+ this.context.spatialMemory.set(target, position);
988
+ this.createConnectionStream(target, `${target}_move`, current, position, "movement");
989
+ } else {
990
+ this.context.spatialMemory.set(target, position);
991
+ }
992
+ chunk3X2EGU7Z_cjs.logger.info("Move command executed", { target, position });
993
+ return {
994
+ moved: target,
995
+ to: position
996
+ };
997
+ }
998
+ /**
999
+ * Execute 'delete' command
1000
+ */
1001
+ async executeDeleteCommand(target, _node) {
1002
+ const position = this.context.spatialMemory.get(target);
1003
+ if (position) {
1004
+ this.createParticleEffect(`${target}_delete`, position, "#ff0000", 15);
1005
+ this.context.spatialMemory.delete(target);
1006
+ }
1007
+ chunk3X2EGU7Z_cjs.logger.info("Delete command executed", { target });
1008
+ return {
1009
+ deleted: target
1010
+ };
1011
+ }
1012
+ async executeStructure(node) {
1013
+ const hologram = node.hologram || {
1014
+ shape: node.type === "nexus" ? "sphere" : "cube",
1015
+ color: node.type === "nexus" ? "#9b59b6" : "#e74c3c",
1016
+ size: node.type === "nexus" ? 3 : 4,
1017
+ glow: true,
1018
+ interactive: true
1019
+ };
1020
+ return {
1021
+ success: true,
1022
+ output: { type: node.type, created: true },
1023
+ hologram,
1024
+ spatialPosition: node.position
1025
+ };
1026
+ }
1027
+ async executeAssignment(node) {
1028
+ const value = this.evaluateExpression(String(node.value));
1029
+ this.setVariable(node.name, value);
1030
+ return {
1031
+ success: true,
1032
+ output: { assigned: node.name, value }
1033
+ };
1034
+ }
1035
+ async executeReturn(node) {
1036
+ const value = this.evaluateExpression(String(node.value));
1037
+ return {
1038
+ success: true,
1039
+ output: value
1040
+ };
1041
+ }
1042
+ // ============================================================================
1043
+ // Condition Evaluation
1044
+ // ============================================================================
1045
+ evaluateCondition(condition) {
1046
+ if (!condition) return false;
1047
+ const suspiciousKeywords = ["eval", "process", "require", "__proto__", "constructor"];
1048
+ if (suspiciousKeywords.some((kw) => condition.toLowerCase().includes(kw))) {
1049
+ chunk3X2EGU7Z_cjs.logger.warn("Suspicious condition blocked", { condition });
1050
+ return false;
1051
+ }
1052
+ try {
1053
+ if (condition.trim().toLowerCase() === "true") return true;
1054
+ if (condition.trim().toLowerCase() === "false") return false;
1055
+ const comparisonPatterns = [
1056
+ { regex: /^(.+?)\s*(===|!==)\s*(.+)$/ },
1057
+ { regex: /^(.+?)\s*(==|!=|>=|<=|>|<)\s*(.+)$/ },
1058
+ { regex: /^(.+?)\s*(&&)\s*(.+)$/, logical: "and" },
1059
+ { regex: /^(.+?)\s*(\|\|)\s*(.+)$/, logical: "or" }
1060
+ ];
1061
+ for (const { regex, logical } of comparisonPatterns) {
1062
+ const match = condition.match(regex);
1063
+ if (match) {
1064
+ const [, leftExpr, operator, rightExpr] = match;
1065
+ const left = this.evaluateExpression(leftExpr.trim());
1066
+ const right = this.evaluateExpression(rightExpr.trim());
1067
+ if (logical === "and") return Boolean(left) && Boolean(right);
1068
+ if (logical === "or") return Boolean(left) || Boolean(right);
1069
+ switch (operator) {
1070
+ case "===":
1071
+ return left === right;
1072
+ case "!==":
1073
+ return left !== right;
1074
+ case "==":
1075
+ return left == right;
1076
+ case "!=":
1077
+ return left != right;
1078
+ case ">=":
1079
+ return Number(left) >= Number(right);
1080
+ case "<=":
1081
+ return Number(left) <= Number(right);
1082
+ case ">":
1083
+ return Number(left) > Number(right);
1084
+ case "<":
1085
+ return Number(left) < Number(right);
1086
+ }
1087
+ }
1088
+ }
1089
+ if (condition.startsWith("!")) {
1090
+ return !this.evaluateCondition(condition.slice(1).trim());
1091
+ }
1092
+ const value = this.evaluateExpression(condition.trim());
1093
+ return Boolean(value);
1094
+ } catch (error) {
1095
+ chunk3X2EGU7Z_cjs.logger.error("Condition evaluation error", { condition, error });
1096
+ return false;
1097
+ }
1098
+ }
1099
+ // ============================================================================
1100
+ // Transformation
1101
+ // ============================================================================
1102
+ async applyTransformation(data, transform) {
1103
+ const params = transform.parameters || {};
1104
+ switch (transform.operation) {
1105
+ case "filter": {
1106
+ if (!Array.isArray(data)) return data;
1107
+ const predicate = params.predicate;
1108
+ if (predicate) {
1109
+ return data.filter((item) => {
1110
+ this.setVariable("_item", item);
1111
+ return this.evaluateCondition(predicate);
1112
+ });
1113
+ }
1114
+ return data.filter((item) => item !== null && item !== void 0);
1115
+ }
1116
+ case "map": {
1117
+ if (!Array.isArray(data)) return data;
1118
+ const mapper = params.mapper;
1119
+ if (mapper) {
1120
+ return data.map((item) => {
1121
+ this.setVariable("_item", item);
1122
+ return this.evaluateExpression(mapper);
1123
+ });
1124
+ }
1125
+ return data.map((item) => ({ value: item, processed: true }));
1126
+ }
1127
+ case "reduce": {
1128
+ if (!Array.isArray(data)) return data;
1129
+ const initial = params.initial ?? 0;
1130
+ const reducer = params.reducer;
1131
+ if (reducer) {
1132
+ return data.reduce((acc, item) => {
1133
+ this.setVariable("_acc", acc);
1134
+ this.setVariable("_item", item);
1135
+ return this.evaluateExpression(reducer);
1136
+ }, initial);
1137
+ }
1138
+ return data.reduce((acc, item) => acc + (typeof item === "number" ? item : 0), 0);
1139
+ }
1140
+ case "sort": {
1141
+ if (!Array.isArray(data)) return data;
1142
+ const key = params.key;
1143
+ const desc = params.descending;
1144
+ const sorted = [...data].sort((a, b) => {
1145
+ const aVal = key ? a[key] : a;
1146
+ const bVal = key ? b[key] : b;
1147
+ if (aVal < bVal) return desc ? 1 : -1;
1148
+ if (aVal > bVal) return desc ? -1 : 1;
1149
+ return 0;
1150
+ });
1151
+ return sorted;
1152
+ }
1153
+ case "sum":
1154
+ return Array.isArray(data) ? data.reduce((sum, item) => sum + (typeof item === "number" ? item : 0), 0) : data;
1155
+ case "count":
1156
+ return Array.isArray(data) ? data.length : 1;
1157
+ case "unique":
1158
+ return Array.isArray(data) ? Array.from(new Set(data)) : data;
1159
+ case "flatten":
1160
+ return Array.isArray(data) ? data.flat() : data;
1161
+ case "reverse":
1162
+ return Array.isArray(data) ? [...data].reverse() : data;
1163
+ case "take": {
1164
+ if (!Array.isArray(data)) return data;
1165
+ const count = Number(params.count) || 10;
1166
+ return data.slice(0, count);
1167
+ }
1168
+ case "skip": {
1169
+ if (!Array.isArray(data)) return data;
1170
+ const count = Number(params.count) || 0;
1171
+ return data.slice(count);
1172
+ }
1173
+ default:
1174
+ chunk3X2EGU7Z_cjs.logger.warn("Unknown transformation", { operation: transform.operation });
1175
+ return data;
1176
+ }
1177
+ }
1178
+ // ============================================================================
1179
+ // Event System
1180
+ // ============================================================================
1181
+ /**
1182
+ * Register event handler
1183
+ */
1184
+ on(event, handler) {
1185
+ const handlers = this.eventHandlers.get(event) || [];
1186
+ handlers.push(handler);
1187
+ this.eventHandlers.set(event, handlers);
1188
+ }
1189
+ /**
1190
+ * Register host function
1191
+ */
1192
+ registerFunction(name, handler) {
1193
+ this.builtinFunctions.set(name, handler);
1194
+ chunk3X2EGU7Z_cjs.logger.info(`Host function registered: ${name}`);
1195
+ }
1196
+ /**
1197
+ * Remove event handler
1198
+ */
1199
+ off(event, handler) {
1200
+ if (!handler) {
1201
+ this.eventHandlers.delete(event);
1202
+ } else {
1203
+ const handlers = this.eventHandlers.get(event) || [];
1204
+ this.eventHandlers.set(event, handlers.filter((h) => h !== handler));
1205
+ }
1206
+ }
1207
+ /**
1208
+ * Emit event
1209
+ */
1210
+ async emit(event, data) {
1211
+ const handlers = this.eventHandlers.get(event) || [];
1212
+ for (const handler of handlers) {
1213
+ try {
1214
+ await handler(data);
1215
+ } catch (error) {
1216
+ chunk3X2EGU7Z_cjs.logger.error("Event handler error", { event, error });
1217
+ }
1218
+ }
1219
+ }
1220
+ /**
1221
+ * Trigger UI event
1222
+ */
1223
+ async triggerUIEvent(elementName, eventType, data) {
1224
+ const element = this.uiElements.get(elementName);
1225
+ if (!element) {
1226
+ chunk3X2EGU7Z_cjs.logger.warn("UI element not found", { elementName });
1227
+ return;
1228
+ }
1229
+ if (eventType === "change" && data !== void 0) {
1230
+ element.value = data;
1231
+ }
1232
+ await this.emit(`${elementName}.${eventType}`, data);
1233
+ }
1234
+ // ============================================================================
1235
+ // Animation System
1236
+ // ============================================================================
1237
+ /**
1238
+ * Update all animations
1239
+ */
1240
+ updateAnimations() {
1241
+ const now = Date.now();
1242
+ for (const [key, anim] of this.animations) {
1243
+ const elapsed = now - anim.startTime;
1244
+ let progress = Math.min(elapsed / anim.duration, 1);
1245
+ progress = this.applyEasing(progress, anim.easing);
1246
+ let currentValue = anim.from + (anim.to - anim.from) * progress;
1247
+ if (anim.yoyo && progress >= 1) {
1248
+ anim.startTime = now;
1249
+ [anim.from, anim.to] = [anim.to, anim.from];
1250
+ }
1251
+ this.setVariable(`${anim.target}.${anim.property}`, currentValue);
1252
+ if (progress >= 1 && !anim.loop && !anim.yoyo) {
1253
+ this.animations.delete(key);
1254
+ } else if (progress >= 1 && anim.loop) {
1255
+ anim.startTime = now;
1256
+ }
1257
+ }
1258
+ this.updateSystemVariables();
1259
+ }
1260
+ /**
1261
+ * Update real-life and system variables ($time, $user, etc.)
1262
+ */
1263
+ updateSystemVariables() {
1264
+ const now = /* @__PURE__ */ new Date();
1265
+ this.setVariable("$time", now.toLocaleTimeString());
1266
+ this.setVariable("$date", now.toLocaleDateString());
1267
+ this.setVariable("$timestamp", now.getTime());
1268
+ this.setVariable("$hour", now.getHours());
1269
+ this.setVariable("$minute", now.getMinutes());
1270
+ this.setVariable("$second", now.getSeconds());
1271
+ if (this.getVariable("$user") === void 0) {
1272
+ this.setVariable("$user", {
1273
+ id: "user_123",
1274
+ name: "Alpha Explorer",
1275
+ level: 42,
1276
+ rank: "Legendary",
1277
+ achievements: ["First World", "Spirit Guide"],
1278
+ preferences: { theme: "holographic", language: "en" }
1279
+ });
1280
+ }
1281
+ if (this.getVariable("$location") === void 0) {
1282
+ this.setVariable("$location", {
1283
+ city: "Neo Tokyo",
1284
+ region: "Holo-Sector 7",
1285
+ coordinates: { lat: 35.6895, lng: 139.6917 },
1286
+ altitude: 450
1287
+ });
1288
+ }
1289
+ if (this.getVariable("$weather") === void 0) {
1290
+ this.setVariable("$weather", {
1291
+ condition: "Neon Mist",
1292
+ temperature: 24,
1293
+ humidity: 65,
1294
+ windSpeed: 12,
1295
+ unit: "C"
1296
+ });
1297
+ }
1298
+ if (this.getVariable("$wallet") === void 0) {
1299
+ this.setVariable("$wallet", {
1300
+ address: "0xHolo...42ff",
1301
+ balance: 1337.5,
1302
+ currency: "HOLO",
1303
+ network: "MainNet"
1304
+ });
1305
+ }
1306
+ if (this.getVariable("$ai_config") === void 0) {
1307
+ const savedKeys = typeof localStorage !== "undefined" ? localStorage.getItem("brittney_api_keys") : null;
1308
+ let configuredCount = 0;
1309
+ if (savedKeys) {
1310
+ try {
1311
+ const keys = JSON.parse(savedKeys);
1312
+ configuredCount = Object.values(keys).filter((k) => !!k).length;
1313
+ } catch (e) {
1314
+ }
1315
+ }
1316
+ this.setVariable("$ai_config", {
1317
+ status: configuredCount > 0 ? "configured" : "pending",
1318
+ providerCount: configuredCount,
1319
+ lastUpdated: Date.now()
1320
+ });
1321
+ }
1322
+ if (this.getVariable("$chat_status") === void 0) {
1323
+ this.setVariable("$chat_status", {
1324
+ active: true,
1325
+ typing: false,
1326
+ version: "1.0.0-brittney"
1327
+ });
1328
+ }
1329
+ }
1330
+ // ==========================================================================
1331
+ // COMMERCE PRIMITIVES
1332
+ // ==========================================================================
1333
+ handleShop(args) {
1334
+ const config = args[0] || {};
1335
+ this.emit("shop", config);
1336
+ return { success: true, type: "shop", config };
1337
+ }
1338
+ handleInventory(args) {
1339
+ const item = args[0];
1340
+ const action = args[1] || "add";
1341
+ this.emit("inventory", { item, action });
1342
+ return { success: true, item, action };
1343
+ }
1344
+ handlePurchase(args) {
1345
+ const productId = args[0];
1346
+ this.emit("purchase", { productId });
1347
+ return { success: true, productId, status: "pending" };
1348
+ }
1349
+ // ==========================================================================
1350
+ // SOCIAL PRIMITIVES
1351
+ // ==========================================================================
1352
+ handlePresence(args) {
1353
+ const config = args[0] || {};
1354
+ this.emit("presence", config);
1355
+ return { success: true, active: true };
1356
+ }
1357
+ handleInvite(args) {
1358
+ const userId = args[0];
1359
+ this.emit("invite", { userId });
1360
+ return { success: true, userId };
1361
+ }
1362
+ handleShare(args) {
1363
+ const scriptId = args[0];
1364
+ const targetUserId = args[1];
1365
+ this.emit("share", { scriptId, targetUserId });
1366
+ return { success: true, scriptId };
1367
+ }
1368
+ // ==========================================================================
1369
+ // PHYSICS PRIMITIVES
1370
+ // ==========================================================================
1371
+ handlePhysics(args) {
1372
+ const config = args[0] || {};
1373
+ this.emit("physics", config);
1374
+ return { success: true, enabled: config.enabled !== false };
1375
+ }
1376
+ handleGravity(args) {
1377
+ const value = args[0] ?? 9.81;
1378
+ this.emit("gravity", { value });
1379
+ return { success: true, value };
1380
+ }
1381
+ handleCollide(args) {
1382
+ const target = args[0];
1383
+ const handler = args[1];
1384
+ this.emit("collide", { target, handler });
1385
+ return { success: true, target };
1386
+ }
1387
+ /**
1388
+ * Handle calculate_arc(start, end, speed)
1389
+ */
1390
+ handleCalculateArc(args) {
1391
+ if (args.length < 3) return { x: 0, y: 0, z: 0 };
1392
+ const start = args[0];
1393
+ const end = args[1];
1394
+ const speed = args[2];
1395
+ const dx = end.x - start.x;
1396
+ const dz = end.z - start.z;
1397
+ const dy = end.y - start.y;
1398
+ const dist = Math.sqrt(dx * dx + dz * dz);
1399
+ if (dist < 0.1) return { x: 0, y: speed, z: 0 };
1400
+ const t = dist / speed;
1401
+ const vx = dx / t;
1402
+ const vz = dz / t;
1403
+ const vy = dy / t + 0.5 * 9.81 * t;
1404
+ return { x: vx, y: vy, z: vz };
1405
+ }
1406
+ handleAnimate(args) {
1407
+ const options = args[0] || {};
1408
+ this.emit("animate", options);
1409
+ return { success: true, options };
1410
+ }
1411
+ applyEasing(t, easing) {
1412
+ switch (easing) {
1413
+ case "easeIn":
1414
+ return t * t;
1415
+ case "easeOut":
1416
+ return t * (2 - t);
1417
+ case "easeInOut":
1418
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
1419
+ case "easeInQuad":
1420
+ return t * t;
1421
+ case "easeOutQuad":
1422
+ return t * (2 - t);
1423
+ case "easeInOutQuad":
1424
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
1425
+ case "linear":
1426
+ default:
1427
+ return t;
1428
+ }
1429
+ }
1430
+ // ============================================================================
1431
+ // Particle Effects
1432
+ // ============================================================================
1433
+ createParticleEffect(name, position, color, count) {
1434
+ const limitedCount = Math.min(count, RUNTIME_SECURITY_LIMITS.maxParticlesPerSystem);
1435
+ const particles = [];
1436
+ for (let i = 0; i < limitedCount; i++) {
1437
+ particles.push({
1438
+ x: position.x + (Math.random() - 0.5) * 2,
1439
+ y: position.y + (Math.random() - 0.5) * 2,
1440
+ z: position.z + (Math.random() - 0.5) * 2
1441
+ });
1442
+ }
1443
+ this.particleSystems.set(name, {
1444
+ particles,
1445
+ color,
1446
+ lifetime: 3e3,
1447
+ speed: 0.01
1448
+ });
1449
+ }
1450
+ createConnectionStream(from, to, fromPos, toPos, dataType) {
1451
+ const streamName = `connection_${from}_${to}`;
1452
+ const particles = [];
1453
+ const steps = 20;
1454
+ for (let i = 0; i <= steps; i++) {
1455
+ const t = i / steps;
1456
+ particles.push({
1457
+ x: fromPos.x + (toPos.x - fromPos.x) * t,
1458
+ y: fromPos.y + (toPos.y - fromPos.y) * t,
1459
+ z: fromPos.z + (toPos.z - fromPos.z) * t
1460
+ });
1461
+ }
1462
+ this.particleSystems.set(streamName, {
1463
+ particles,
1464
+ color: this.getDataTypeColor(dataType),
1465
+ lifetime: 5e3,
1466
+ speed: 0.02
1467
+ });
1468
+ }
1469
+ createFlowingStream(name, position, data) {
1470
+ const count = Array.isArray(data) ? Math.min(data.length, 50) : 10;
1471
+ this.createParticleEffect(`${name}_flow`, position, "#45b7d1", count);
1472
+ }
1473
+ createExecutionEffect(name, position) {
1474
+ this.createParticleEffect(`${name}_execution`, position, "#ff4500", 30);
1475
+ }
1476
+ createDataVisualization(name, data, position) {
1477
+ let count = 10;
1478
+ if (Array.isArray(data)) {
1479
+ count = Math.min(data.length, 100);
1480
+ } else if (typeof data === "object" && data !== null) {
1481
+ count = Math.min(Object.keys(data).length * 5, 50);
1482
+ }
1483
+ this.createParticleEffect(`${name}_visualization`, position, "#32cd32", count);
1484
+ }
1485
+ getDataTypeColor(dataType) {
1486
+ const colors = {
1487
+ "string": "#ff6b35",
1488
+ "number": "#4ecdc4",
1489
+ "boolean": "#45b7d1",
1490
+ "object": "#96ceb4",
1491
+ "array": "#ffeaa7",
1492
+ "any": "#dda0dd",
1493
+ "move": "#ff69b4"
1494
+ };
1495
+ return colors[dataType] || "#ffffff";
1496
+ }
1497
+ // ============================================================================
1498
+ // Public API
1499
+ // ============================================================================
1500
+ getParticleSystems() {
1501
+ return new Map(this.particleSystems);
1502
+ }
1503
+ updateParticles(deltaTime) {
1504
+ for (const [name, system] of this.particleSystems) {
1505
+ system.lifetime -= deltaTime;
1506
+ system.particles.forEach((particle) => {
1507
+ particle.x += (Math.random() - 0.5) * system.speed;
1508
+ particle.y += (Math.random() - 0.5) * system.speed;
1509
+ particle.z += (Math.random() - 0.5) * system.speed;
1510
+ });
1511
+ if (system.lifetime <= 0) {
1512
+ this.particleSystems.delete(name);
1513
+ }
1514
+ }
1515
+ }
1516
+ getContext() {
1517
+ return { ...this.context };
1518
+ }
1519
+ getUIElements() {
1520
+ return new Map(this.uiElements);
1521
+ }
1522
+ getUIElement(name) {
1523
+ return this.uiElements.get(name);
1524
+ }
1525
+ getAnimations() {
1526
+ return new Map(this.animations);
1527
+ }
1528
+ reset() {
1529
+ this.context = this.createEmptyContext();
1530
+ this.currentScope = { variables: this.context.variables };
1531
+ this.callStack = [];
1532
+ this.particleSystems.clear();
1533
+ this.executionHistory = [];
1534
+ this.eventHandlers.clear();
1535
+ this.animations.clear();
1536
+ this.uiElements.clear();
1537
+ }
1538
+ createEmptyContext() {
1539
+ return {
1540
+ variables: /* @__PURE__ */ new Map(),
1541
+ functions: /* @__PURE__ */ new Map(),
1542
+ exports: /* @__PURE__ */ new Map(),
1543
+ connections: [],
1544
+ spatialMemory: /* @__PURE__ */ new Map(),
1545
+ hologramState: /* @__PURE__ */ new Map(),
1546
+ executionStack: [],
1547
+ currentScale: 1,
1548
+ scaleMagnitude: "standard",
1549
+ focusHistory: [],
1550
+ environment: {},
1551
+ templates: /* @__PURE__ */ new Map(),
1552
+ state: createState({})
1553
+ };
1554
+ }
1555
+ async executeScale(node) {
1556
+ const parentScale = this.context.currentScale;
1557
+ this.context.currentScale *= node.multiplier;
1558
+ this.context.scaleMagnitude = node.magnitude;
1559
+ chunk3X2EGU7Z_cjs.logger.info("Scale context entering", { magnitude: node.magnitude, multiplier: this.context.currentScale });
1560
+ this.emit("scale:change", { multiplier: this.context.currentScale, magnitude: node.magnitude });
1561
+ const results = await this.executeProgram(node.body, this.context.executionStack.length);
1562
+ this.context.currentScale = parentScale;
1563
+ this.emit("scale:change", { multiplier: this.context.currentScale });
1564
+ return {
1565
+ success: results.every((r) => r.success),
1566
+ output: `Executed scale block: ${node.magnitude}`
1567
+ };
1568
+ }
1569
+ async executeFocus(node) {
1570
+ this.context.focusHistory.push(node.target);
1571
+ const results = await this.executeProgram(node.body, this.context.executionStack.length);
1572
+ return {
1573
+ success: results.every((r) => r.success),
1574
+ output: `Focused on ${node.target}`
1575
+ };
1576
+ }
1577
+ async executeEnvironment(node) {
1578
+ this.context.environment = { ...this.context.environment, ...node.settings };
1579
+ return { success: true, output: "Environment updated" };
1580
+ }
1581
+ async executeComposition(node) {
1582
+ return {
1583
+ success: (await this.executeProgram(node.children, this.context.executionStack.length)).every((r) => r.success),
1584
+ output: `Composition ${node.name} executed`
1585
+ };
1586
+ }
1587
+ async executeTemplate(node) {
1588
+ this.context.templates.set(node.name, node);
1589
+ return { success: true, output: `Template ${node.name} registered` };
1590
+ }
1591
+ async executeServerNode(node) {
1592
+ if (this.context.mode === "public") {
1593
+ return { success: false, error: "SecurityViolation: Server creation blocked in public mode.", executionTime: 0 };
1594
+ }
1595
+ chunk3X2EGU7Z_cjs.logger.info(`Starting server on port ${node.port}`);
1596
+ return {
1597
+ success: true,
1598
+ output: `Server listening on port ${node.port}`,
1599
+ hologram: node.hologram,
1600
+ executionTime: 0
1601
+ };
1602
+ }
1603
+ async executeDatabaseNode(node) {
1604
+ if (this.context.mode === "public") {
1605
+ return { success: false, error: "SecurityViolation: DB access blocked in public mode.", executionTime: 0 };
1606
+ }
1607
+ chunk3X2EGU7Z_cjs.logger.info(`Executing Query: ${node.query}`);
1608
+ return {
1609
+ success: true,
1610
+ output: `Query executed: ${node.query}`,
1611
+ hologram: node.hologram,
1612
+ executionTime: 0
1613
+ };
1614
+ }
1615
+ async executeFetchNode(node) {
1616
+ if (this.context.mode === "public") {
1617
+ return { success: false, error: "SecurityViolation: External fetch blocked in public mode.", executionTime: 0 };
1618
+ }
1619
+ chunk3X2EGU7Z_cjs.logger.info(`Fetching: ${node.url}`);
1620
+ return {
1621
+ success: true,
1622
+ output: `Fetched data from ${node.url}`,
1623
+ hologram: node.hologram,
1624
+ executionTime: 0
1625
+ };
1626
+ }
1627
+ async executeTarget(node) {
1628
+ const target = this.context.functions.get(node.target);
1629
+ if (!target) {
1630
+ return {
1631
+ success: false,
1632
+ error: `Function ${node.target} not found`,
1633
+ executionTime: 0
1634
+ };
1635
+ }
1636
+ const result = await this.executeFunction(target);
1637
+ this.createExecutionEffect(node.target, target.position || { x: 0, y: 0, z: 0 });
1638
+ return {
1639
+ success: true,
1640
+ output: `Executed ${node.target}`,
1641
+ hologram: {
1642
+ shape: "sphere",
1643
+ color: "#ff4500",
1644
+ size: 1.2,
1645
+ glow: true,
1646
+ interactive: false
1647
+ },
1648
+ executionTime: result.executionTime
1649
+ };
1650
+ }
1651
+ async executeStateDeclaration(node) {
1652
+ const stateDirective = node.directives?.find((d) => d.type === "state");
1653
+ if (stateDirective) {
1654
+ this.context.state.update(stateDirective.body);
1655
+ }
1656
+ return { success: true, output: "State updated" };
1657
+ }
1658
+ applyDirectives(node) {
1659
+ if (!node.directives) return;
1660
+ for (const d of node.directives) {
1661
+ if (d.type === "trait") {
1662
+ chunk3X2EGU7Z_cjs.logger.info(`Applying trait ${d.name} to ${node.type}`);
1663
+ if (d.name === "chat") {
1664
+ this.emit("show-chat", d.config);
1665
+ }
1666
+ } else if (d.type === "state") {
1667
+ this.context.state.update(d.body);
1668
+ } else if (d.type === "lifecycle") {
1669
+ if (d.hook === "on_mount") {
1670
+ this.evaluateExpression(d.body);
1671
+ }
1672
+ }
1673
+ }
1674
+ }
1675
+ getExecutionHistory() {
1676
+ return [...this.executionHistory];
1677
+ }
1678
+ getHologramStates() {
1679
+ return new Map(this.context.hologramState);
1680
+ }
1681
+ getCallStack() {
1682
+ return [...this.callStack];
1683
+ }
1684
+ getState() {
1685
+ return this.context.state.getSnapshot();
1686
+ }
1687
+ };
1688
+
1689
+ exports.HoloScriptRuntime = HoloScriptRuntime;
1690
+ //# sourceMappingURL=chunk-L6VLNVKP.cjs.map
1691
+ //# sourceMappingURL=chunk-L6VLNVKP.cjs.map