@holoscript/core 2.0.2 → 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 (54) hide show
  1. package/dist/{chunk-KWYIVRIH.js → chunk-2XXE34KS.js} +2 -2
  2. package/dist/chunk-2XXE34KS.js.map +1 -0
  3. package/dist/{chunk-EU6CZMGJ.js → chunk-AFFVFO4D.js} +511 -118
  4. package/dist/chunk-AFFVFO4D.js.map +1 -0
  5. package/dist/chunk-DGUM43GV.js +10 -0
  6. package/dist/{chunk-4CV4JOE5.js.map → chunk-DGUM43GV.js.map} +1 -1
  7. package/dist/{chunk-VYIDLUCV.js → chunk-DOY73HDH.js} +4 -4
  8. package/dist/{chunk-VYIDLUCV.js.map → chunk-DOY73HDH.js.map} +1 -1
  9. package/dist/chunk-JEQ2X3Z6.cjs +12 -0
  10. package/dist/{chunk-CZLDE2OZ.cjs.map → chunk-JEQ2X3Z6.cjs.map} +1 -1
  11. package/dist/{chunk-3N67RLQP.cjs → chunk-L6VLNVKP.cjs} +511 -118
  12. package/dist/chunk-L6VLNVKP.cjs.map +1 -0
  13. package/dist/{chunk-VMZN4EVR.cjs → chunk-MFNO57XL.cjs} +2 -2
  14. package/dist/chunk-MFNO57XL.cjs.map +1 -0
  15. package/dist/{chunk-WFI4T3XB.cjs → chunk-R75MREOS.cjs} +6 -6
  16. package/dist/{chunk-WFI4T3XB.cjs.map → chunk-R75MREOS.cjs.map} +1 -1
  17. package/dist/{chunk-4OHVW4XR.cjs → chunk-T57ZL7KR.cjs} +299 -45
  18. package/dist/chunk-T57ZL7KR.cjs.map +1 -0
  19. package/dist/{chunk-MCP6D4LT.js → chunk-U72GEJZT.js} +299 -45
  20. package/dist/chunk-U72GEJZT.js.map +1 -0
  21. package/dist/debugger.cjs +6 -6
  22. package/dist/debugger.d.cts +1 -1
  23. package/dist/debugger.d.ts +1 -1
  24. package/dist/debugger.js +4 -4
  25. package/dist/index.cjs +1896 -1099
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +3145 -1534
  28. package/dist/index.d.ts +3145 -1534
  29. package/dist/index.js +1922 -1133
  30. package/dist/index.js.map +1 -1
  31. package/dist/parser.cjs +3 -3
  32. package/dist/parser.d.cts +34 -1
  33. package/dist/parser.d.ts +34 -1
  34. package/dist/parser.js +2 -2
  35. package/dist/runtime.cjs +3 -3
  36. package/dist/runtime.d.cts +47 -27
  37. package/dist/runtime.d.ts +47 -27
  38. package/dist/runtime.js +2 -2
  39. package/dist/type-checker.cjs +4 -4
  40. package/dist/type-checker.d.cts +3 -3
  41. package/dist/type-checker.d.ts +3 -3
  42. package/dist/type-checker.js +2 -2
  43. package/dist/{types-D6g4ACjP.d.cts → types-4h8cbtF_.d.cts} +80 -13
  44. package/dist/{types-D6g4ACjP.d.ts → types-4h8cbtF_.d.ts} +80 -13
  45. package/package.json +21 -20
  46. package/LICENSE +0 -21
  47. package/dist/chunk-3N67RLQP.cjs.map +0 -1
  48. package/dist/chunk-4CV4JOE5.js +0 -24
  49. package/dist/chunk-4OHVW4XR.cjs.map +0 -1
  50. package/dist/chunk-CZLDE2OZ.cjs +0 -28
  51. package/dist/chunk-EU6CZMGJ.js.map +0 -1
  52. package/dist/chunk-KWYIVRIH.js.map +0 -1
  53. package/dist/chunk-MCP6D4LT.js.map +0 -1
  54. package/dist/chunk-VMZN4EVR.cjs.map +0 -1
@@ -2,6 +2,112 @@
2
2
 
3
3
  var chunk3X2EGU7Z_cjs = require('./chunk-3X2EGU7Z.cjs');
4
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
+
5
111
  // src/HoloScriptRuntime.ts
6
112
  var RUNTIME_SECURITY_LIMITS = {
7
113
  maxExecutionDepth: 50,
@@ -11,7 +117,7 @@ var RUNTIME_SECURITY_LIMITS = {
11
117
  maxCallStackDepth: 100
12
118
  };
13
119
  var HoloScriptRuntime = class {
14
- constructor(_importLoader) {
120
+ constructor(_importLoader, customFunctions) {
15
121
  this.particleSystems = /* @__PURE__ */ new Map();
16
122
  this.executionHistory = [];
17
123
  this.startTime = 0;
@@ -22,13 +128,18 @@ var HoloScriptRuntime = class {
22
128
  this.uiElements = /* @__PURE__ */ new Map();
23
129
  this.context = this.createEmptyContext();
24
130
  this.currentScope = { variables: this.context.variables };
25
- this.builtinFunctions = this.initBuiltins();
131
+ this.builtinFunctions = this.initBuiltins(customFunctions);
26
132
  }
27
133
  /**
28
134
  * Initialize built-in functions
29
135
  */
30
- initBuiltins() {
136
+ initBuiltins(customFunctions) {
31
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
+ }
32
143
  builtins.set("show", (args) => {
33
144
  const target = String(args[0]);
34
145
  const element = this.uiElements.get(target);
@@ -47,7 +158,7 @@ var HoloScriptRuntime = class {
47
158
  chunk3X2EGU7Z_cjs.logger.info("hide", { target });
48
159
  return { hidden: target };
49
160
  });
50
- builtins.set("pulse", (args) => {
161
+ builtins.set("pulsate", (args) => {
51
162
  const target = String(args[0]);
52
163
  const options = args[1] || {};
53
164
  const duration = Number(options.duration) || 1e3;
@@ -141,6 +252,15 @@ var HoloScriptRuntime = class {
141
252
  if (Array.isArray(arr)) return arr[index];
142
253
  return void 0;
143
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
+ });
144
264
  builtins.set("log", (args) => {
145
265
  chunk3X2EGU7Z_cjs.logger.info("HoloScript log", { args });
146
266
  return args[0];
@@ -154,6 +274,17 @@ var HoloScriptRuntime = class {
154
274
  builtins.set("isArray", (args) => Array.isArray(args[0]));
155
275
  builtins.set("isNumber", (args) => typeof args[0] === "number" && !isNaN(args[0]));
156
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));
157
288
  return builtins;
158
289
  }
159
290
  /**
@@ -181,7 +312,6 @@ var HoloScriptRuntime = class {
181
312
  case "stream":
182
313
  result = await this.executeStream(node);
183
314
  break;
184
- case "execute":
185
315
  case "call":
186
316
  result = await this.executeCall(node);
187
317
  break;
@@ -210,6 +340,36 @@ var HoloScriptRuntime = class {
210
340
  case "expression-statement":
211
341
  result = await this.executeCall(node);
212
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;
213
373
  default:
214
374
  result = {
215
375
  success: false,
@@ -233,6 +393,22 @@ var HoloScriptRuntime = class {
233
393
  return errorResult;
234
394
  }
235
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
+ }
236
412
  /**
237
413
  * Execute multiple nodes in sequence
238
414
  */
@@ -403,119 +579,45 @@ var HoloScriptRuntime = class {
403
579
  */
404
580
  evaluateExpression(expr) {
405
581
  if (!expr || typeof expr !== "string") return expr;
406
- expr = expr.trim();
407
- const suspicious = ["eval", "process", "require", "__proto__", "constructor", "Function"];
408
- if (suspicious.some((kw) => expr.toLowerCase().includes(kw))) {
409
- chunk3X2EGU7Z_cjs.logger.warn("Suspicious expression blocked", { expr });
410
- return void 0;
411
- }
412
- if (expr.startsWith('"') && expr.endsWith('"') || expr.startsWith("'") && expr.endsWith("'")) {
413
- return expr.slice(1, -1);
414
- }
415
- if (/^-?\d+(\.\d+)?$/.test(expr)) {
416
- return parseFloat(expr);
417
- }
418
- if (expr === "true") return true;
419
- if (expr === "false") return false;
420
- if (expr === "null") return null;
421
- if (expr === "undefined") return void 0;
422
- if (expr.startsWith("[") && expr.endsWith("]")) {
423
- const inner = expr.slice(1, -1);
424
- if (!inner.trim()) return [];
425
- const elements = this.splitByComma(inner);
426
- return elements.map((e) => this.evaluateExpression(e.trim()));
427
- }
428
- if (expr.startsWith("{") && expr.endsWith("}")) {
429
- const inner = expr.slice(1, -1);
430
- if (!inner.trim()) return {};
431
- const pairs = this.splitByComma(inner);
432
- const obj = {};
433
- for (const pair of pairs) {
434
- const colonIndex = pair.indexOf(":");
435
- if (colonIndex > 0) {
436
- const key = pair.slice(0, colonIndex).trim();
437
- const value = pair.slice(colonIndex + 1).trim();
438
- obj[key] = this.evaluateExpression(value);
439
- }
440
- }
441
- return obj;
442
- }
443
- const funcMatch = expr.match(/^(\w+)\s*\((.*)?\)$/);
444
- if (funcMatch) {
445
- const [, funcName, argsStr] = funcMatch;
446
- const args = argsStr ? this.splitByComma(argsStr).map((a) => this.evaluateExpression(a.trim())) : [];
447
- const builtin = this.builtinFunctions.get(funcName);
448
- if (builtin) {
449
- return builtin(args);
450
- }
451
- if (this.context.functions.has(funcName)) {
452
- return { __holoCall: funcName, args };
453
- }
454
- return void 0;
455
- }
456
- const binaryOps = [
457
- { pattern: /(.+)\s*\+\s*(.+)/, op: (a, b) => typeof a === "string" || typeof b === "string" ? String(a) + String(b) : Number(a) + Number(b) },
458
- { pattern: /(.+)\s*-\s*(.+)/, op: (a, b) => Number(a) - Number(b) },
459
- { pattern: /(.+)\s*\*\s*(.+)/, op: (a, b) => Number(a) * Number(b) },
460
- { pattern: /(.+)\s*\/\s*(.+)/, op: (a, b) => Number(b) !== 0 ? Number(a) / Number(b) : 0 },
461
- { pattern: /(.+)\s*%\s*(.+)/, op: (a, b) => Number(a) % Number(b) }
462
- ];
463
- for (const { pattern, op } of binaryOps) {
464
- const match = expr.match(pattern);
465
- if (match) {
466
- const left = this.evaluateExpression(match[1]);
467
- const right = this.evaluateExpression(match[2]);
468
- return op(left, right);
469
- }
470
- }
471
- return this.getVariable(expr);
472
- }
473
- /**
474
- * Split string by comma, respecting nesting
475
- */
476
- splitByComma(str) {
477
- const parts = [];
478
- let current = "";
479
- let depth = 0;
480
- let inString = false;
481
- let stringChar = "";
482
- for (let i = 0; i < str.length; i++) {
483
- const char = str[i];
484
- if (!inString && (char === '"' || char === "'")) {
485
- inString = true;
486
- stringChar = char;
487
- } else if (inString && char === stringChar && str[i - 1] !== "\\") {
488
- inString = false;
489
- }
490
- if (!inString) {
491
- if (char === "(" || char === "[" || char === "{") depth++;
492
- if (char === ")" || char === "]" || char === "}") depth--;
493
- if (char === "," && depth === 0) {
494
- parts.push(current.trim());
495
- current = "";
496
- continue;
497
- }
498
- }
499
- current += char;
500
- }
501
- if (current.trim()) {
502
- parts.push(current.trim());
503
- }
504
- return parts;
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);
505
587
  }
506
588
  // ============================================================================
507
589
  // Node Executors
508
590
  // ============================================================================
509
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 };
510
598
  if (node.position) {
511
- this.context.spatialMemory.set(node.name, 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
+ }
512
612
  }
513
613
  const orbData = {
514
614
  __type: "orb",
515
615
  name: node.name,
516
- properties: { ...node.properties },
517
- position: node.position || { x: 0, y: 0, z: 0 },
518
- hologram: node.hologram,
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,
519
621
  created: Date.now(),
520
622
  // Methods bound to this orb
521
623
  show: () => this.builtinFunctions.get("show")([node.name]),
@@ -523,16 +625,19 @@ var HoloScriptRuntime = class {
523
625
  pulse: (opts) => this.builtinFunctions.get("pulse")([node.name, opts])
524
626
  };
525
627
  this.context.variables.set(node.name, orbData);
526
- if (node.hologram) {
527
- this.context.hologramState.set(node.name, node.hologram);
628
+ if (hologram) {
629
+ this.context.hologramState.set(node.name, hologram);
630
+ }
631
+ if (node.directives) {
632
+ this.applyDirectives(node);
528
633
  }
529
- this.createParticleEffect(`${node.name}_creation`, node.position || { x: 0, y: 0, z: 0 }, "#00ffff", 20);
530
- chunk3X2EGU7Z_cjs.logger.info("Orb created", { name: node.name, properties: Object.keys(node.properties) });
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 });
531
636
  return {
532
637
  success: true,
533
638
  output: orbData,
534
- hologram: node.hologram,
535
- spatialPosition: node.position
639
+ hologram,
640
+ spatialPosition: adjustedPos
536
641
  };
537
642
  }
538
643
  async executeFunction(node) {
@@ -1050,7 +1155,7 @@ var HoloScriptRuntime = class {
1050
1155
  case "count":
1051
1156
  return Array.isArray(data) ? data.length : 1;
1052
1157
  case "unique":
1053
- return Array.isArray(data) ? [...new Set(data)] : data;
1158
+ return Array.isArray(data) ? Array.from(new Set(data)) : data;
1054
1159
  case "flatten":
1055
1160
  return Array.isArray(data) ? data.flat() : data;
1056
1161
  case "reverse":
@@ -1081,6 +1186,13 @@ var HoloScriptRuntime = class {
1081
1186
  handlers.push(handler);
1082
1187
  this.eventHandlers.set(event, handlers);
1083
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
+ }
1084
1196
  /**
1085
1197
  * Remove event handler
1086
1198
  */
@@ -1143,6 +1255,158 @@ var HoloScriptRuntime = class {
1143
1255
  anim.startTime = now;
1144
1256
  }
1145
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 };
1146
1410
  }
1147
1411
  applyEasing(t, easing) {
1148
1412
  switch (easing) {
@@ -1279,9 +1543,135 @@ var HoloScriptRuntime = class {
1279
1543
  connections: [],
1280
1544
  spatialMemory: /* @__PURE__ */ new Map(),
1281
1545
  hologramState: /* @__PURE__ */ new Map(),
1282
- executionStack: []
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}`
1283
1567
  };
1284
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
+ }
1285
1675
  getExecutionHistory() {
1286
1676
  return [...this.executionHistory];
1287
1677
  }
@@ -1291,8 +1681,11 @@ var HoloScriptRuntime = class {
1291
1681
  getCallStack() {
1292
1682
  return [...this.callStack];
1293
1683
  }
1684
+ getState() {
1685
+ return this.context.state.getSnapshot();
1686
+ }
1294
1687
  };
1295
1688
 
1296
1689
  exports.HoloScriptRuntime = HoloScriptRuntime;
1297
- //# sourceMappingURL=chunk-3N67RLQP.cjs.map
1298
- //# sourceMappingURL=chunk-3N67RLQP.cjs.map
1690
+ //# sourceMappingURL=chunk-L6VLNVKP.cjs.map
1691
+ //# sourceMappingURL=chunk-L6VLNVKP.cjs.map