@casual-simulation/aux-runtime 3.8.2-alpha.19511653187 → 3.10.3-alpha.20787554310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +677 -54
- package/package.json +85 -86
- package/runtime/AuxCompiler.d.ts +11 -2
- package/runtime/AuxCompiler.js +44 -31
- package/runtime/AuxCompiler.js.map +1 -1
- package/runtime/AuxDevice.d.ts +11 -0
- package/runtime/AuxGlobalContext.d.ts +7 -0
- package/runtime/AuxGlobalContext.js +3 -0
- package/runtime/AuxGlobalContext.js.map +1 -1
- package/runtime/AuxLibrary.d.ts +61 -6
- package/runtime/AuxLibrary.js +567 -107
- package/runtime/AuxLibrary.js.map +1 -1
- package/runtime/AuxLibraryDefinitions.def +2432 -671
- package/runtime/AuxRuntime.js +51 -46
- package/runtime/AuxRuntime.js.map +1 -1
- package/runtime/RecordsEvents.d.ts +294 -2
- package/runtime/RecordsEvents.js +178 -12
- package/runtime/RecordsEvents.js.map +1 -1
- package/runtime/RuntimeBot.js +1 -1
- package/runtime/RuntimeBot.js.map +1 -1
- package/runtime/Transpiler.d.ts +27 -2
- package/runtime/Transpiler.js +117 -20
- package/runtime/Transpiler.js.map +1 -1
- package/runtime/test/TestScriptBotFactory.js +1 -2
- package/runtime/test/TestScriptBotFactory.js.map +1 -1
package/runtime/AuxRuntime.js
CHANGED
|
@@ -313,7 +313,7 @@ export class AuxRuntime {
|
|
|
313
313
|
};
|
|
314
314
|
if ('botId' in m) {
|
|
315
315
|
const bot = this._compiledState[m.botId];
|
|
316
|
-
const module = bot
|
|
316
|
+
const module = bot?.modules[m.tag];
|
|
317
317
|
if (module) {
|
|
318
318
|
await module.moduleFunc(importFunc, exportFunc);
|
|
319
319
|
}
|
|
@@ -348,7 +348,7 @@ export class AuxRuntime {
|
|
|
348
348
|
}
|
|
349
349
|
else {
|
|
350
350
|
const [source, target] = val;
|
|
351
|
-
const key = target
|
|
351
|
+
const key = target ?? source;
|
|
352
352
|
result[key] = sourceModule[source];
|
|
353
353
|
}
|
|
354
354
|
}
|
|
@@ -377,17 +377,17 @@ export class AuxRuntime {
|
|
|
377
377
|
* @param meta The metadata that should be used to resolve the module.
|
|
378
378
|
*/
|
|
379
379
|
async resolveModule(moduleName, meta, allowCustomResolution = true) {
|
|
380
|
-
if (
|
|
380
|
+
if (meta?.tag === ON_RESOLVE_MODULE) {
|
|
381
381
|
allowCustomResolution = false;
|
|
382
382
|
}
|
|
383
383
|
if (moduleName === 'casualos') {
|
|
384
384
|
let exports = {
|
|
385
385
|
...this._library.api,
|
|
386
386
|
};
|
|
387
|
-
const bot =
|
|
387
|
+
const bot = meta?.botId ? this._compiledState[meta.botId] : null;
|
|
388
388
|
const ctx = {
|
|
389
389
|
bot,
|
|
390
|
-
tag: meta
|
|
390
|
+
tag: meta?.tag,
|
|
391
391
|
creator: bot
|
|
392
392
|
? this._getRuntimeBot(bot.script.tags.creator)
|
|
393
393
|
: null,
|
|
@@ -420,7 +420,7 @@ export class AuxRuntime {
|
|
|
420
420
|
if (typeof result.botId === 'string' &&
|
|
421
421
|
typeof result.tag === 'string') {
|
|
422
422
|
const bot = this._compiledState[result.botId];
|
|
423
|
-
const mod = bot
|
|
423
|
+
const mod = bot?.modules[result.tag];
|
|
424
424
|
if (mod) {
|
|
425
425
|
return {
|
|
426
426
|
botId: result.botId,
|
|
@@ -591,15 +591,15 @@ export class AuxRuntime {
|
|
|
591
591
|
return this._currentDebugger;
|
|
592
592
|
}
|
|
593
593
|
async _createDebugger(options) {
|
|
594
|
-
const forceSyncScripts = typeof
|
|
594
|
+
const forceSyncScripts = typeof options?.allowAsynchronousScripts === 'boolean'
|
|
595
595
|
? !options.allowAsynchronousScripts
|
|
596
596
|
: false;
|
|
597
597
|
await importInterpreter();
|
|
598
|
-
const interpreter =
|
|
598
|
+
const interpreter = options?.pausable ? new Interpreter() : null;
|
|
599
599
|
const runtime = new AuxRuntime(this._globalContext.version, this._globalContext.device, this._libraryFactory, this._editModeProvider, this._exemptSpaces, forceSyncScripts, interpreter);
|
|
600
600
|
runtime._autoBatch = true;
|
|
601
601
|
let idCount = 0;
|
|
602
|
-
if (!
|
|
602
|
+
if (!options?.useRealUUIDs) {
|
|
603
603
|
runtime._globalContext.uuid = () => {
|
|
604
604
|
idCount += 1;
|
|
605
605
|
return `uuid-${idCount}`;
|
|
@@ -644,11 +644,11 @@ export class AuxRuntime {
|
|
|
644
644
|
return allActions;
|
|
645
645
|
};
|
|
646
646
|
// The config bot is always ID 0 in debuggers
|
|
647
|
-
const configBotId =
|
|
647
|
+
const configBotId = options?.useRealUUIDs
|
|
648
648
|
? runtime.context.uuid()
|
|
649
649
|
: 'uuid-0';
|
|
650
|
-
const configBotTags =
|
|
651
|
-
? isBot(options
|
|
650
|
+
const configBotTags = options?.configBot
|
|
651
|
+
? isBot(options?.configBot)
|
|
652
652
|
? options.configBot.tags
|
|
653
653
|
: options.configBot
|
|
654
654
|
: {};
|
|
@@ -673,7 +673,7 @@ export class AuxRuntime {
|
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
|
-
if (interpreter &&
|
|
676
|
+
if (interpreter && options?.pausable) {
|
|
677
677
|
interpreter.debugging = true;
|
|
678
678
|
}
|
|
679
679
|
const debug = {
|
|
@@ -725,7 +725,6 @@ export class AuxRuntime {
|
|
|
725
725
|
// runtime._afterScriptExitListeners.push(listener);
|
|
726
726
|
// },
|
|
727
727
|
setPauseTrigger(b, tag, options) {
|
|
728
|
-
var _a, _b, _c;
|
|
729
728
|
if (typeof b === 'object' && 'triggerId' in b) {
|
|
730
729
|
runtime.setBreakpoint({
|
|
731
730
|
id: b.triggerId,
|
|
@@ -733,8 +732,8 @@ export class AuxRuntime {
|
|
|
733
732
|
tag: b.tag,
|
|
734
733
|
lineNumber: b.lineNumber,
|
|
735
734
|
columnNumber: b.columnNumber,
|
|
736
|
-
states:
|
|
737
|
-
disabled: !(
|
|
735
|
+
states: b.states ?? ['before'],
|
|
736
|
+
disabled: !(b.enabled ?? true),
|
|
738
737
|
});
|
|
739
738
|
return b;
|
|
740
739
|
}
|
|
@@ -752,7 +751,7 @@ export class AuxRuntime {
|
|
|
752
751
|
tag: tag,
|
|
753
752
|
lineNumber: trigger.lineNumber,
|
|
754
753
|
columnNumber: trigger.columnNumber,
|
|
755
|
-
states:
|
|
754
|
+
states: trigger.states ?? ['before'],
|
|
756
755
|
disabled: false,
|
|
757
756
|
});
|
|
758
757
|
return trigger;
|
|
@@ -765,7 +764,6 @@ export class AuxRuntime {
|
|
|
765
764
|
runtime.removeBreakpoint(id);
|
|
766
765
|
},
|
|
767
766
|
disablePauseTrigger(triggerOrId) {
|
|
768
|
-
var _a;
|
|
769
767
|
if (typeof triggerOrId === 'string') {
|
|
770
768
|
let trigger = runtime._breakpoints.get(triggerOrId);
|
|
771
769
|
if (trigger) {
|
|
@@ -779,13 +777,12 @@ export class AuxRuntime {
|
|
|
779
777
|
tag: triggerOrId.tag,
|
|
780
778
|
lineNumber: triggerOrId.lineNumber,
|
|
781
779
|
columnNumber: triggerOrId.columnNumber,
|
|
782
|
-
states:
|
|
780
|
+
states: triggerOrId.states ?? ['before'],
|
|
783
781
|
disabled: true,
|
|
784
782
|
});
|
|
785
783
|
}
|
|
786
784
|
},
|
|
787
785
|
enablePauseTrigger(triggerOrId) {
|
|
788
|
-
var _a;
|
|
789
786
|
if (typeof triggerOrId === 'string') {
|
|
790
787
|
let trigger = runtime._breakpoints.get(triggerOrId);
|
|
791
788
|
if (trigger) {
|
|
@@ -799,7 +796,7 @@ export class AuxRuntime {
|
|
|
799
796
|
tag: triggerOrId.tag,
|
|
800
797
|
lineNumber: triggerOrId.lineNumber,
|
|
801
798
|
columnNumber: triggerOrId.columnNumber,
|
|
802
|
-
states:
|
|
799
|
+
states: triggerOrId.states ?? ['before'],
|
|
803
800
|
disabled: false,
|
|
804
801
|
});
|
|
805
802
|
}
|
|
@@ -856,10 +853,9 @@ export class AuxRuntime {
|
|
|
856
853
|
return runtime.userBot;
|
|
857
854
|
},
|
|
858
855
|
getPortalBots() {
|
|
859
|
-
var _a;
|
|
860
856
|
let portalBots = new Map();
|
|
861
857
|
for (let [portal, id] of runtime._portalBots) {
|
|
862
|
-
portalBots.set(portal,
|
|
858
|
+
portalBots.set(portal, runtime.currentState[id]?.script);
|
|
863
859
|
}
|
|
864
860
|
return portalBots;
|
|
865
861
|
},
|
|
@@ -1627,7 +1623,6 @@ export class AuxRuntime {
|
|
|
1627
1623
|
});
|
|
1628
1624
|
}
|
|
1629
1625
|
_addBotsToState(bots, nextUpdate) {
|
|
1630
|
-
var _a, _b;
|
|
1631
1626
|
let newBots = [];
|
|
1632
1627
|
let newBotIDs = new Set();
|
|
1633
1628
|
for (let bot of bots) {
|
|
@@ -1658,7 +1653,7 @@ export class AuxRuntime {
|
|
|
1658
1653
|
else {
|
|
1659
1654
|
bot.masks = {};
|
|
1660
1655
|
}
|
|
1661
|
-
bot.masks[space] = Object.assign({},
|
|
1656
|
+
bot.masks[space] = Object.assign({}, bot.masks[space] ?? {}, masks);
|
|
1662
1657
|
}
|
|
1663
1658
|
}
|
|
1664
1659
|
}
|
|
@@ -1679,7 +1674,7 @@ export class AuxRuntime {
|
|
|
1679
1674
|
let newMasks;
|
|
1680
1675
|
let addNewMasks = false;
|
|
1681
1676
|
let hasNewMasks = false;
|
|
1682
|
-
if (!
|
|
1677
|
+
if (!newBot?.masks?.[space]) {
|
|
1683
1678
|
addNewMasks = true;
|
|
1684
1679
|
newMasks = {};
|
|
1685
1680
|
}
|
|
@@ -1747,7 +1742,7 @@ export class AuxRuntime {
|
|
|
1747
1742
|
const system = bot.values['system'];
|
|
1748
1743
|
if (hasValue(system)) {
|
|
1749
1744
|
const map = this._systemMap.get(system);
|
|
1750
|
-
map
|
|
1745
|
+
map?.delete(bot.id);
|
|
1751
1746
|
}
|
|
1752
1747
|
for (let breakpoint of bot.breakpoints) {
|
|
1753
1748
|
this._interpreter.removeBreakpointById(breakpoint.id);
|
|
@@ -1769,7 +1764,6 @@ export class AuxRuntime {
|
|
|
1769
1764
|
return removedBots;
|
|
1770
1765
|
}
|
|
1771
1766
|
_updateBotsWithState(update, updates, nextUpdate, newBotIds) {
|
|
1772
|
-
var _a, _b;
|
|
1773
1767
|
for (let id of update.updatedBots) {
|
|
1774
1768
|
if (!id) {
|
|
1775
1769
|
continue;
|
|
@@ -1841,7 +1835,7 @@ export class AuxRuntime {
|
|
|
1841
1835
|
else {
|
|
1842
1836
|
compiled.masks[space][tag] = tagValue;
|
|
1843
1837
|
}
|
|
1844
|
-
|
|
1838
|
+
delete compiled.originalTagMaskEditValues[space]?.[tag];
|
|
1845
1839
|
updatedTags.add(tag);
|
|
1846
1840
|
partial.masks[space][tag] = tagValue;
|
|
1847
1841
|
}
|
|
@@ -1852,7 +1846,7 @@ export class AuxRuntime {
|
|
|
1852
1846
|
let hasTag = false;
|
|
1853
1847
|
if (compiled.masks) {
|
|
1854
1848
|
for (let space of TAG_MASK_SPACE_PRIORITIES) {
|
|
1855
|
-
const tagValue =
|
|
1849
|
+
const tagValue = compiled.masks[space]?.[tag];
|
|
1856
1850
|
if (hasValue(tagValue)) {
|
|
1857
1851
|
this._compileTagValue(compiled, tag, tagValue);
|
|
1858
1852
|
hasTag = true;
|
|
@@ -2148,7 +2142,6 @@ export class AuxRuntime {
|
|
|
2148
2142
|
return updates;
|
|
2149
2143
|
}
|
|
2150
2144
|
_createCompiledBot(bot, fromFactory) {
|
|
2151
|
-
var _a, _b;
|
|
2152
2145
|
let compiledBot = {
|
|
2153
2146
|
id: bot.id,
|
|
2154
2147
|
precalculated: true,
|
|
@@ -2187,7 +2180,7 @@ export class AuxRuntime {
|
|
|
2187
2180
|
bot.masks[space] = { ...bot.masks[space] };
|
|
2188
2181
|
}
|
|
2189
2182
|
for (let tag in existing[space]) {
|
|
2190
|
-
if (hasValue(
|
|
2183
|
+
if (hasValue(bot.masks?.[space]?.[tag])) {
|
|
2191
2184
|
continue;
|
|
2192
2185
|
}
|
|
2193
2186
|
if (!bot.masks[space]) {
|
|
@@ -2339,9 +2332,8 @@ export class AuxRuntime {
|
|
|
2339
2332
|
};
|
|
2340
2333
|
}
|
|
2341
2334
|
getTagMask(bot, tag) {
|
|
2342
|
-
var _a, _b;
|
|
2343
2335
|
for (let space of TAG_MASK_SPACE_PRIORITIES) {
|
|
2344
|
-
const tagValue =
|
|
2336
|
+
const tagValue = bot.masks?.[space]?.[tag];
|
|
2345
2337
|
if (hasValue(tagValue)) {
|
|
2346
2338
|
return this._compileTagMaskValue(bot, tag, space, tagValue);
|
|
2347
2339
|
}
|
|
@@ -2410,11 +2402,10 @@ export class AuxRuntime {
|
|
|
2410
2402
|
return !!bot.signatures ? bot.signatures[signature] : undefined;
|
|
2411
2403
|
}
|
|
2412
2404
|
_compileTagOrMask(bot, existingBot, tag) {
|
|
2413
|
-
var _a, _b, _c;
|
|
2414
2405
|
let hadMask = false;
|
|
2415
2406
|
if (existingBot.masks) {
|
|
2416
2407
|
for (let space of TAG_MASK_SPACE_PRIORITIES) {
|
|
2417
|
-
const tagValue =
|
|
2408
|
+
const tagValue = existingBot.masks[space]?.[tag];
|
|
2418
2409
|
if (hasValue(tagValue)) {
|
|
2419
2410
|
if (!bot.masks) {
|
|
2420
2411
|
bot.masks = {};
|
|
@@ -2426,7 +2417,7 @@ export class AuxRuntime {
|
|
|
2426
2417
|
this._compileTagValue(bot, tag, tagValue);
|
|
2427
2418
|
return [space, tag];
|
|
2428
2419
|
}
|
|
2429
|
-
else if (hasValue(
|
|
2420
|
+
else if (hasValue(bot.masks?.[space]?.[tag])) {
|
|
2430
2421
|
// Indicate that there used to be a value for the tag mask
|
|
2431
2422
|
// but it has been removed.
|
|
2432
2423
|
hadMask = true;
|
|
@@ -2449,10 +2440,9 @@ export class AuxRuntime {
|
|
|
2449
2440
|
return [undefined, tag];
|
|
2450
2441
|
}
|
|
2451
2442
|
_compileTag(bot, tag, tagValue) {
|
|
2452
|
-
var _a;
|
|
2453
2443
|
if (bot.masks) {
|
|
2454
2444
|
for (let space of TAG_MASK_SPACE_PRIORITIES) {
|
|
2455
|
-
if (hasValue(
|
|
2445
|
+
if (hasValue(bot.masks[space]?.[tag])) {
|
|
2456
2446
|
return;
|
|
2457
2447
|
}
|
|
2458
2448
|
}
|
|
@@ -2610,7 +2600,7 @@ export class AuxRuntime {
|
|
|
2610
2600
|
value = result;
|
|
2611
2601
|
}
|
|
2612
2602
|
}
|
|
2613
|
-
if (
|
|
2603
|
+
if (listener?.moduleFunc && !module) {
|
|
2614
2604
|
module = listener;
|
|
2615
2605
|
}
|
|
2616
2606
|
return { value, listener, module };
|
|
@@ -2670,7 +2660,7 @@ export class AuxRuntime {
|
|
|
2670
2660
|
}
|
|
2671
2661
|
}
|
|
2672
2662
|
_compile(bot, tag, script, options) {
|
|
2673
|
-
|
|
2663
|
+
const startTime = performance.now();
|
|
2674
2664
|
script = replaceMacros(script);
|
|
2675
2665
|
let functionName;
|
|
2676
2666
|
let diagnosticFunctionName;
|
|
@@ -2682,7 +2672,7 @@ export class AuxRuntime {
|
|
|
2682
2672
|
fileName = `${bot.id}.${diagnosticFunctionName}`;
|
|
2683
2673
|
}
|
|
2684
2674
|
const meta = markAsUncopiableObject({
|
|
2685
|
-
botId: bot
|
|
2675
|
+
botId: bot?.id,
|
|
2686
2676
|
tag: tag,
|
|
2687
2677
|
});
|
|
2688
2678
|
Object.defineProperty(meta, 'resolve', {
|
|
@@ -2694,20 +2684,20 @@ export class AuxRuntime {
|
|
|
2694
2684
|
},
|
|
2695
2685
|
});
|
|
2696
2686
|
const constants = {
|
|
2697
|
-
...(
|
|
2687
|
+
...(options.api ?? this._library.api),
|
|
2698
2688
|
tagName: tag,
|
|
2699
2689
|
globalThis: this._globalObject,
|
|
2700
2690
|
[IMPORT_META_FACTORY]: meta,
|
|
2701
2691
|
__energyCheck: this._library.api.__energyCheck,
|
|
2702
2692
|
};
|
|
2703
2693
|
const specifics = {
|
|
2704
|
-
...(
|
|
2694
|
+
...(options.tagSpecificApi ?? this._library.tagSpecificApi),
|
|
2705
2695
|
};
|
|
2706
2696
|
if (this._interpreter) {
|
|
2707
2697
|
delete constants.globalThis;
|
|
2708
2698
|
// if (this.canTriggerBreakpoint) {
|
|
2709
|
-
Object.assign(constants,
|
|
2710
|
-
Object.assign(specifics,
|
|
2699
|
+
Object.assign(constants, options.api ?? this._interpretedApi);
|
|
2700
|
+
Object.assign(specifics, options.tagSpecificApi ?? this._interpretedTagSpecificApi);
|
|
2711
2701
|
// }
|
|
2712
2702
|
}
|
|
2713
2703
|
const func = this._compiler.compile(script, {
|
|
@@ -2793,6 +2783,21 @@ export class AuxRuntime {
|
|
|
2793
2783
|
else {
|
|
2794
2784
|
func.moduleFunc = null;
|
|
2795
2785
|
}
|
|
2786
|
+
if (this._globalContext) {
|
|
2787
|
+
const endTime = performance.now();
|
|
2788
|
+
const compileTime = endTime - startTime;
|
|
2789
|
+
this._globalContext.addLoadTime('script_compile', compileTime);
|
|
2790
|
+
this._globalContext.addLoadTime('script_transpile', func.metadata.transpileTimeMs);
|
|
2791
|
+
this._globalContext.addLoadTime('script_engine_compile', func.metadata.engineCompileTimeMs);
|
|
2792
|
+
if (compileTime >= 100) {
|
|
2793
|
+
console.warn('[AuxRuntime] Slow script compile (>=100ms):', {
|
|
2794
|
+
botId: bot.id,
|
|
2795
|
+
tag: tag,
|
|
2796
|
+
system: bot.values['system'],
|
|
2797
|
+
compileTime: `${compileTime}ms`,
|
|
2798
|
+
});
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2796
2801
|
return func;
|
|
2797
2802
|
}
|
|
2798
2803
|
_handleError(err, bot, tag) {
|