@casual-simulation/aux-runtime 3.4.6-alpha.14668890889 → 3.5.0-alpha.15119114602
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/package.json +8 -8
- package/runtime/AuxCompiler.d.ts +0 -1
- package/runtime/AuxCompiler.js.map +1 -1
- package/runtime/AuxGlobalContext.d.ts +1 -1
- package/runtime/AuxGlobalContext.js +3 -1
- package/runtime/AuxGlobalContext.js.map +1 -1
- package/runtime/AuxLibrary.d.ts +125 -65
- package/runtime/AuxLibrary.js +510 -167
- package/runtime/AuxLibrary.js.map +1 -1
- package/runtime/AuxLibraryDefinitions.def +782 -0
- package/runtime/AuxResults.js.map +1 -1
- package/runtime/AuxRuntime.js +545 -512
- package/runtime/AuxRuntime.js.map +1 -1
- package/runtime/AuxRuntimeDynamicImports.js +2 -13
- package/runtime/AuxRuntimeDynamicImports.js.map +1 -1
- package/runtime/CompiledBot.js +1 -1
- package/runtime/CompiledBot.js.map +1 -1
- package/runtime/RecordsEvents.d.ts +162 -3
- package/runtime/RecordsEvents.js +162 -3
- package/runtime/RecordsEvents.js.map +1 -1
- package/runtime/RuntimeBot.js +3 -1
- package/runtime/RuntimeBot.js.map +1 -1
- package/runtime/RuntimeStateVersion.js +3 -1
- package/runtime/RuntimeStateVersion.js.map +1 -1
- package/runtime/Transpiler.js +10 -1
- package/runtime/Transpiler.js.map +1 -1
- package/runtime/Utils.d.ts +1 -1
- package/runtime/Utils.js.map +1 -1
- package/runtime/test/TestScriptBotFactory.js.map +1 -1
package/runtime/AuxRuntime.js
CHANGED
|
@@ -15,15 +15,6 @@
|
|
|
15
15
|
* You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
18
|
import { hasValue, tagsOnBot, isFormula, isScript, isNumber, BOT_SPACE_TAG, botUpdated, isBot, ORIGINAL_OBJECT, DEFAULT_ENERGY, getBotSpace, ON_ACTION_ACTION_NAME, breakIntoIndividualEvents, ON_BOT_ADDED_ACTION_NAME, ON_ANY_BOTS_ADDED_ACTION_NAME, ON_ANY_BOTS_REMOVED_ACTION_NAME, ON_BOT_CHANGED_ACTION_NAME, ON_ANY_BOTS_CHANGED_ACTION_NAME, updatedBot, TAG_MASK_SPACE_PRIORITIES, CLEAR_CHANGES_SYMBOL, DNA_TAG_PREFIX, isRuntimeBot, createBot, ON_ERROR, action, isBotInDimension, asyncResult, registerBuiltinPortal, defineGlobalBot, isBotLink, parseBotLink, isBotDate, parseBotDate, formatBotDate, isTaggedString, parseTaggedString, parseNumber, isTaggedNumber, isBotVector, parseBotVector, formatBotVector, isBotRotation, parseBotRotation, formatBotRotation, parseTaggedNumber, REPLACE_BOT_SYMBOL, isModule, calculateStringTagValue, ON_RESOLVE_MODULE, } from '@casual-simulation/aux-common/bots';
|
|
28
19
|
import { Subject, Subscription } from 'rxjs';
|
|
29
20
|
import { AuxCompiler, getInterpretableFunction, isInterpretableFunction, IMPORT_META_FACTORY, IMPORT_FACTORY, EXPORT_FACTORY, } from './AuxCompiler';
|
|
@@ -34,7 +25,7 @@ import { RanOutOfEnergyError } from './AuxResults';
|
|
|
34
25
|
import { isPromise, isRuntimePromise, isUrl, markAsRuntimePromise, } from './Utils';
|
|
35
26
|
import { DefaultRealtimeEditModeProvider } from './AuxRealtimeEditModeProvider';
|
|
36
27
|
import { sortBy, forOwn, merge, union } from 'lodash';
|
|
37
|
-
import { applyTagEdit, isTagEdit
|
|
28
|
+
import { applyTagEdit, isTagEdit } from '@casual-simulation/aux-common/bots';
|
|
38
29
|
import { updateRuntimeVersion } from './RuntimeStateVersion';
|
|
39
30
|
import { replaceMacros } from './Transpiler';
|
|
40
31
|
import { DateTime } from 'luxon';
|
|
@@ -70,11 +61,9 @@ function importInterpreter() {
|
|
|
70
61
|
return (interpreterImportPromise = _importInterpreterCore());
|
|
71
62
|
}
|
|
72
63
|
}
|
|
73
|
-
function _importInterpreterCore() {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
registerInterpreterModule(module);
|
|
77
|
-
});
|
|
64
|
+
async function _importInterpreterCore() {
|
|
65
|
+
const module = await _dynamicImportInterpreter();
|
|
66
|
+
registerInterpreterModule(module);
|
|
78
67
|
}
|
|
79
68
|
/**
|
|
80
69
|
* Defines an class that is able to manage the runtime state of an AUX.
|
|
@@ -240,8 +229,10 @@ export class AuxRuntime {
|
|
|
240
229
|
this._globalContext.global = this._globalObject;
|
|
241
230
|
if (this._interpreter) {
|
|
242
231
|
// Use the interpreted versions of APIs
|
|
243
|
-
this._interpretedApi =
|
|
244
|
-
this._interpretedTagSpecificApi =
|
|
232
|
+
this._interpretedApi = { ...this._library.api };
|
|
233
|
+
this._interpretedTagSpecificApi = {
|
|
234
|
+
...this._library.tagSpecificApi,
|
|
235
|
+
};
|
|
245
236
|
for (let key in this._interpretedApi) {
|
|
246
237
|
const val = this._interpretedApi[key];
|
|
247
238
|
if (isInterpretableFunction(val)) {
|
|
@@ -257,122 +248,116 @@ export class AuxRuntime {
|
|
|
257
248
|
}
|
|
258
249
|
}
|
|
259
250
|
}
|
|
260
|
-
_importModule(module, meta, dependencyChain = [], allowCustomResolution = true) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
throw new Error('Module not found: ' + module);
|
|
270
|
-
}
|
|
251
|
+
async _importModule(module, meta, dependencyChain = [], allowCustomResolution = true) {
|
|
252
|
+
try {
|
|
253
|
+
let m;
|
|
254
|
+
let bot;
|
|
255
|
+
const allowResolution = meta.tag !== ON_RESOLVE_MODULE && allowCustomResolution;
|
|
256
|
+
if (typeof module !== 'string') {
|
|
257
|
+
m = module;
|
|
258
|
+
if (!m) {
|
|
259
|
+
throw new Error('Module not found: ' + module);
|
|
271
260
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
const globalModule = this._cachedGlobalModules.get(module);
|
|
264
|
+
if (globalModule) {
|
|
265
|
+
return await globalModule;
|
|
266
|
+
}
|
|
267
|
+
m = await this.resolveModule(module, meta, allowResolution);
|
|
268
|
+
if (!m) {
|
|
269
|
+
throw new Error('Module not found: ' + module);
|
|
270
|
+
}
|
|
271
|
+
if (dependencyChain.length > 1) {
|
|
272
|
+
const index = dependencyChain.indexOf(m.id);
|
|
273
|
+
if (index >= 0) {
|
|
274
|
+
throw new Error(`Circular dependency detected: ${dependencyChain
|
|
275
|
+
.slice(index)
|
|
276
|
+
.join(' -> ')} -> ${m.id}`);
|
|
288
277
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
278
|
+
}
|
|
279
|
+
if ('botId' in m) {
|
|
280
|
+
bot = this._compiledState[m.botId];
|
|
281
|
+
if (bot) {
|
|
282
|
+
const exports = bot.exports[m.tag];
|
|
283
|
+
if (exports) {
|
|
284
|
+
return await exports;
|
|
296
285
|
}
|
|
297
286
|
}
|
|
298
287
|
}
|
|
299
|
-
const promise = this._importModuleCore(m, [...dependencyChain, m.id], allowResolution);
|
|
300
|
-
if (bot) {
|
|
301
|
-
bot.exports[m.tag] = promise;
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
this._cachedGlobalModules.set(m.id, promise);
|
|
305
|
-
}
|
|
306
|
-
return yield promise;
|
|
307
288
|
}
|
|
308
|
-
|
|
309
|
-
|
|
289
|
+
const promise = this._importModuleCore(m, [...dependencyChain, m.id], allowResolution);
|
|
290
|
+
if (bot) {
|
|
291
|
+
bot.exports[m.tag] = promise;
|
|
310
292
|
}
|
|
311
|
-
|
|
293
|
+
else {
|
|
294
|
+
this._cachedGlobalModules.set(m.id, promise);
|
|
295
|
+
}
|
|
296
|
+
return await promise;
|
|
297
|
+
}
|
|
298
|
+
finally {
|
|
299
|
+
this._scheduleJobQueueCheck();
|
|
300
|
+
}
|
|
312
301
|
}
|
|
313
|
-
_importModuleCore(m, dependencyChain, allowCustomResolution) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
yield module.moduleFunc(importFunc, exportFunc);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
else if ('source' in m) {
|
|
331
|
-
const source = m.source;
|
|
332
|
-
const mod = this._compile(null, null, source, {});
|
|
333
|
-
if (mod.moduleFunc) {
|
|
334
|
-
yield mod.moduleFunc(importFunc, exportFunc);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
else if ('exports' in m) {
|
|
338
|
-
Object.assign(exports, m.exports);
|
|
302
|
+
async _importModuleCore(m, dependencyChain, allowCustomResolution) {
|
|
303
|
+
try {
|
|
304
|
+
const exports = {};
|
|
305
|
+
const importFunc = (id, meta) => this._importModule(id, meta, dependencyChain, allowCustomResolution);
|
|
306
|
+
const exportFunc = async (valueOrSource, e, meta) => {
|
|
307
|
+
const result = await this._resolveExports(valueOrSource, e, meta, dependencyChain, allowCustomResolution);
|
|
308
|
+
this._scheduleJobQueueCheck();
|
|
309
|
+
Object.assign(exports, result);
|
|
310
|
+
};
|
|
311
|
+
if ('botId' in m) {
|
|
312
|
+
const bot = this._compiledState[m.botId];
|
|
313
|
+
const module = bot === null || bot === void 0 ? void 0 : bot.modules[m.tag];
|
|
314
|
+
if (module) {
|
|
315
|
+
await module.moduleFunc(importFunc, exportFunc);
|
|
339
316
|
}
|
|
340
|
-
|
|
341
|
-
|
|
317
|
+
}
|
|
318
|
+
else if ('source' in m) {
|
|
319
|
+
const source = m.source;
|
|
320
|
+
const mod = this._compile(null, null, source, {});
|
|
321
|
+
if (mod.moduleFunc) {
|
|
322
|
+
await mod.moduleFunc(importFunc, exportFunc);
|
|
342
323
|
}
|
|
343
|
-
return exports;
|
|
344
324
|
}
|
|
345
|
-
|
|
346
|
-
|
|
325
|
+
else if ('exports' in m) {
|
|
326
|
+
Object.assign(exports, m.exports);
|
|
347
327
|
}
|
|
348
|
-
|
|
328
|
+
else if ('url' in m) {
|
|
329
|
+
return await this.dynamicImport(m.url);
|
|
330
|
+
}
|
|
331
|
+
return exports;
|
|
332
|
+
}
|
|
333
|
+
finally {
|
|
334
|
+
this._scheduleJobQueueCheck();
|
|
335
|
+
}
|
|
349
336
|
}
|
|
350
|
-
_resolveExports(valueOrSource, exports, meta, dependencyChain, allowCustomResolution) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
result[key] = sourceModule[source];
|
|
364
|
-
}
|
|
337
|
+
async _resolveExports(valueOrSource, exports, meta, dependencyChain, allowCustomResolution) {
|
|
338
|
+
if (typeof valueOrSource === 'string') {
|
|
339
|
+
const sourceModule = await this._importModule(valueOrSource, meta, dependencyChain, allowCustomResolution);
|
|
340
|
+
if (exports) {
|
|
341
|
+
const result = {};
|
|
342
|
+
for (let val of exports) {
|
|
343
|
+
if (typeof val === 'string') {
|
|
344
|
+
result[val] = sourceModule[val];
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
const [source, target] = val;
|
|
348
|
+
const key = target !== null && target !== void 0 ? target : source;
|
|
349
|
+
result[key] = sourceModule[source];
|
|
365
350
|
}
|
|
366
|
-
return result;
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
return sourceModule;
|
|
370
351
|
}
|
|
352
|
+
return result;
|
|
371
353
|
}
|
|
372
354
|
else {
|
|
373
|
-
return
|
|
355
|
+
return sourceModule;
|
|
374
356
|
}
|
|
375
|
-
}
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
return valueOrSource;
|
|
360
|
+
}
|
|
376
361
|
}
|
|
377
362
|
/**
|
|
378
363
|
* Performs a dynamic import() of the given module.
|
|
@@ -380,155 +365,153 @@ export class AuxRuntime {
|
|
|
380
365
|
* @param module The module that should be imported.
|
|
381
366
|
* @returns Returns a promise that resolves with the module's exports.
|
|
382
367
|
*/
|
|
383
|
-
dynamicImport(module) {
|
|
384
|
-
return
|
|
385
|
-
return yield import(/* @vite-ignore */ module);
|
|
386
|
-
});
|
|
368
|
+
async dynamicImport(module) {
|
|
369
|
+
return await import(/* @vite-ignore */ module);
|
|
387
370
|
}
|
|
388
371
|
/**
|
|
389
372
|
* Attempts to resolve the module with the given name.
|
|
390
373
|
* @param moduleName The name of the module to resolve.
|
|
391
374
|
* @param meta The metadata that should be used to resolve the module.
|
|
392
375
|
*/
|
|
393
|
-
resolveModule(moduleName, meta, allowCustomResolution = true) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const result = this._library.tagSpecificApi[key](ctx);
|
|
414
|
-
exports[key] = result;
|
|
376
|
+
async resolveModule(moduleName, meta, allowCustomResolution = true) {
|
|
377
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.tag) === ON_RESOLVE_MODULE) {
|
|
378
|
+
allowCustomResolution = false;
|
|
379
|
+
}
|
|
380
|
+
if (moduleName === 'casualos') {
|
|
381
|
+
let exports = {
|
|
382
|
+
...this._library.api,
|
|
383
|
+
};
|
|
384
|
+
const bot = (meta === null || meta === void 0 ? void 0 : meta.botId) ? this._compiledState[meta.botId] : null;
|
|
385
|
+
const ctx = {
|
|
386
|
+
bot,
|
|
387
|
+
tag: meta === null || meta === void 0 ? void 0 : meta.tag,
|
|
388
|
+
creator: bot
|
|
389
|
+
? this._getRuntimeBot(bot.script.tags.creator)
|
|
390
|
+
: null,
|
|
391
|
+
config: null,
|
|
392
|
+
};
|
|
393
|
+
for (let key in this._library.tagSpecificApi) {
|
|
394
|
+
if (!Object.prototype.hasOwnProperty.call(this._library.tagSpecificApi, key)) {
|
|
395
|
+
continue;
|
|
415
396
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
exports,
|
|
419
|
-
};
|
|
397
|
+
const result = this._library.tagSpecificApi[key](ctx);
|
|
398
|
+
exports[key] = result;
|
|
420
399
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
else if (typeof result.exports === 'object' &&
|
|
446
|
-
result.exports) {
|
|
400
|
+
return {
|
|
401
|
+
id: 'casualos',
|
|
402
|
+
exports,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (allowCustomResolution) {
|
|
406
|
+
const shoutResult = this.shout(ON_RESOLVE_MODULE, undefined, {
|
|
407
|
+
module: moduleName,
|
|
408
|
+
meta,
|
|
409
|
+
});
|
|
410
|
+
const actionResult = isRuntimePromise(shoutResult)
|
|
411
|
+
? await shoutResult
|
|
412
|
+
: shoutResult;
|
|
413
|
+
for (let scriptResult of actionResult.results) {
|
|
414
|
+
const result = await scriptResult;
|
|
415
|
+
if (result) {
|
|
416
|
+
if (typeof result === 'object') {
|
|
417
|
+
if (typeof result.botId === 'string' &&
|
|
418
|
+
typeof result.tag === 'string') {
|
|
419
|
+
const bot = this._compiledState[result.botId];
|
|
420
|
+
const mod = bot === null || bot === void 0 ? void 0 : bot.modules[result.tag];
|
|
421
|
+
if (mod) {
|
|
447
422
|
return {
|
|
423
|
+
botId: result.botId,
|
|
448
424
|
id: moduleName,
|
|
449
|
-
|
|
425
|
+
tag: result.tag,
|
|
450
426
|
};
|
|
451
427
|
}
|
|
452
428
|
}
|
|
453
|
-
else if (typeof result === '
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
return {
|
|
462
|
-
id: moduleName,
|
|
463
|
-
source: result,
|
|
464
|
-
};
|
|
465
|
-
}
|
|
429
|
+
else if (typeof result.exports === 'object' &&
|
|
430
|
+
result.exports) {
|
|
431
|
+
return {
|
|
432
|
+
id: moduleName,
|
|
433
|
+
exports: result.exports,
|
|
434
|
+
};
|
|
466
435
|
}
|
|
467
436
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const isRelativeImport = moduleName.startsWith('.') || moduleName.startsWith(':');
|
|
471
|
-
if (isRelativeImport) {
|
|
472
|
-
if (!meta) {
|
|
473
|
-
throw new Error('Cannot resolve relative import without metadata');
|
|
474
|
-
}
|
|
475
|
-
const bot = this._compiledState[meta.botId];
|
|
476
|
-
if (!bot) {
|
|
477
|
-
throw new Error('Cannot resolve relative import without bot');
|
|
478
|
-
}
|
|
479
|
-
const system = calculateStringTagValue(null, bot, 'system', `🔗${bot.id}`);
|
|
480
|
-
const split = system.split('.');
|
|
481
|
-
for (let i = 0; i < moduleName.length; i++) {
|
|
482
|
-
if (moduleName[i] === ':') {
|
|
483
|
-
split.pop();
|
|
484
|
-
}
|
|
485
|
-
else if (moduleName[i] === '.') {
|
|
486
|
-
/* empty */
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
moduleName =
|
|
490
|
-
split.join('.') + '.' + moduleName.substring(i);
|
|
491
|
-
break;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
if (moduleName.startsWith('🔗')) {
|
|
496
|
-
const [id, tag] = moduleName.substring('🔗'.length).split('.');
|
|
497
|
-
const bot = this._compiledState[id];
|
|
498
|
-
if (bot && tag) {
|
|
499
|
-
return {
|
|
500
|
-
id: moduleName,
|
|
501
|
-
botId: bot.id,
|
|
502
|
-
tag: tag,
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
const lastIndex = moduleName.lastIndexOf('.');
|
|
507
|
-
if (lastIndex >= 0) {
|
|
508
|
-
const system = moduleName.substring(0, lastIndex);
|
|
509
|
-
const tag = moduleName.substring(lastIndex + 1);
|
|
510
|
-
const botIds = this._systemMap.get(system);
|
|
511
|
-
if (botIds) {
|
|
512
|
-
for (let id of botIds) {
|
|
513
|
-
const bot = this._compiledState[id];
|
|
514
|
-
if (bot && bot.modules[tag]) {
|
|
437
|
+
else if (typeof result === 'string') {
|
|
438
|
+
if (isUrl(result)) {
|
|
515
439
|
return {
|
|
516
|
-
botId: id,
|
|
517
440
|
id: moduleName,
|
|
518
|
-
|
|
441
|
+
url: result,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
return {
|
|
446
|
+
id: moduleName,
|
|
447
|
+
source: result,
|
|
519
448
|
};
|
|
520
449
|
}
|
|
521
450
|
}
|
|
522
451
|
}
|
|
523
452
|
}
|
|
524
|
-
|
|
453
|
+
}
|
|
454
|
+
const isRelativeImport = moduleName.startsWith('.') || moduleName.startsWith(':');
|
|
455
|
+
if (isRelativeImport) {
|
|
456
|
+
if (!meta) {
|
|
457
|
+
throw new Error('Cannot resolve relative import without metadata');
|
|
458
|
+
}
|
|
459
|
+
const bot = this._compiledState[meta.botId];
|
|
460
|
+
if (!bot) {
|
|
461
|
+
throw new Error('Cannot resolve relative import without bot');
|
|
462
|
+
}
|
|
463
|
+
const system = calculateStringTagValue(null, bot, 'system', `🔗${bot.id}`);
|
|
464
|
+
const split = system.split('.');
|
|
465
|
+
for (let i = 0; i < moduleName.length; i++) {
|
|
466
|
+
if (moduleName[i] === ':') {
|
|
467
|
+
split.pop();
|
|
468
|
+
}
|
|
469
|
+
else if (moduleName[i] === '.') {
|
|
470
|
+
/* empty */
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
moduleName =
|
|
474
|
+
split.join('.') + '.' + moduleName.substring(i);
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (moduleName.startsWith('🔗')) {
|
|
480
|
+
const [id, tag] = moduleName.substring('🔗'.length).split('.');
|
|
481
|
+
const bot = this._compiledState[id];
|
|
482
|
+
if (bot && tag) {
|
|
525
483
|
return {
|
|
526
484
|
id: moduleName,
|
|
527
|
-
|
|
485
|
+
botId: bot.id,
|
|
486
|
+
tag: tag,
|
|
528
487
|
};
|
|
529
488
|
}
|
|
530
|
-
|
|
531
|
-
|
|
489
|
+
}
|
|
490
|
+
const lastIndex = moduleName.lastIndexOf('.');
|
|
491
|
+
if (lastIndex >= 0) {
|
|
492
|
+
const system = moduleName.substring(0, lastIndex);
|
|
493
|
+
const tag = moduleName.substring(lastIndex + 1);
|
|
494
|
+
const botIds = this._systemMap.get(system);
|
|
495
|
+
if (botIds) {
|
|
496
|
+
for (let id of botIds) {
|
|
497
|
+
const bot = this._compiledState[id];
|
|
498
|
+
if (bot && bot.modules[tag]) {
|
|
499
|
+
return {
|
|
500
|
+
botId: id,
|
|
501
|
+
id: moduleName,
|
|
502
|
+
tag: tag,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (isUrl(moduleName)) {
|
|
509
|
+
return {
|
|
510
|
+
id: moduleName,
|
|
511
|
+
url: moduleName,
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
return null;
|
|
532
515
|
}
|
|
533
516
|
getShoutTimers() {
|
|
534
517
|
return {};
|
|
@@ -607,269 +590,284 @@ export class AuxRuntime {
|
|
|
607
590
|
_getExecutingDebugger() {
|
|
608
591
|
return this._currentDebugger;
|
|
609
592
|
}
|
|
610
|
-
_createDebugger(options) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
return `uuid-${idCount}`;
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
let allActions = [];
|
|
627
|
-
let allErrors = [];
|
|
628
|
-
let create;
|
|
629
|
-
if (interpreter &&
|
|
630
|
-
isInterpretableFunction(runtime._library.tagSpecificApi.create)) {
|
|
631
|
-
const func = getInterpretableFunction(runtime._library.tagSpecificApi.create)({
|
|
632
|
-
bot: null,
|
|
633
|
-
config: null,
|
|
634
|
-
creator: null,
|
|
635
|
-
tag: null,
|
|
636
|
-
});
|
|
637
|
-
create = (...args) => {
|
|
638
|
-
const result = func(...args);
|
|
639
|
-
if (isGenerator(result)) {
|
|
640
|
-
return runtime._processGenerator(result);
|
|
641
|
-
}
|
|
642
|
-
return result;
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
else {
|
|
646
|
-
create = runtime._library.tagSpecificApi.create({
|
|
647
|
-
bot: null,
|
|
648
|
-
config: null,
|
|
649
|
-
creator: null,
|
|
650
|
-
tag: null,
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
const isCommonAction = (action) => {
|
|
654
|
-
return !(action.type === 'add_bot' ||
|
|
655
|
-
action.type === 'remove_bot' ||
|
|
656
|
-
action.type === 'update_bot' ||
|
|
657
|
-
action.type === 'apply_state');
|
|
593
|
+
async _createDebugger(options) {
|
|
594
|
+
const forceSyncScripts = typeof (options === null || options === void 0 ? void 0 : options.allowAsynchronousScripts) === 'boolean'
|
|
595
|
+
? !options.allowAsynchronousScripts
|
|
596
|
+
: false;
|
|
597
|
+
await importInterpreter();
|
|
598
|
+
const interpreter = (options === null || options === void 0 ? void 0 : options.pausable) ? new Interpreter() : null;
|
|
599
|
+
const runtime = new AuxRuntime(this._globalContext.version, this._globalContext.device, this._libraryFactory, this._editModeProvider, this._exemptSpaces, forceSyncScripts, interpreter);
|
|
600
|
+
runtime._autoBatch = true;
|
|
601
|
+
let idCount = 0;
|
|
602
|
+
if (!(options === null || options === void 0 ? void 0 : options.useRealUUIDs)) {
|
|
603
|
+
runtime._globalContext.uuid = () => {
|
|
604
|
+
idCount += 1;
|
|
605
|
+
return `uuid-${idCount}`;
|
|
658
606
|
};
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
607
|
+
}
|
|
608
|
+
let allActions = [];
|
|
609
|
+
let allErrors = [];
|
|
610
|
+
let create;
|
|
611
|
+
if (interpreter &&
|
|
612
|
+
isInterpretableFunction(runtime._library.tagSpecificApi.create)) {
|
|
613
|
+
const func = getInterpretableFunction(runtime._library.tagSpecificApi.create)({
|
|
614
|
+
bot: null,
|
|
615
|
+
config: null,
|
|
616
|
+
creator: null,
|
|
617
|
+
tag: null,
|
|
618
|
+
});
|
|
619
|
+
create = (...args) => {
|
|
620
|
+
const result = func(...args);
|
|
621
|
+
if (isGenerator(result)) {
|
|
622
|
+
return runtime._processGenerator(result);
|
|
623
|
+
}
|
|
624
|
+
return result;
|
|
663
625
|
};
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
:
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
create = runtime._library.tagSpecificApi.create({
|
|
629
|
+
bot: null,
|
|
630
|
+
config: null,
|
|
631
|
+
creator: null,
|
|
632
|
+
tag: null,
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
const isCommonAction = (action) => {
|
|
636
|
+
return !(action.type === 'add_bot' ||
|
|
637
|
+
action.type === 'remove_bot' ||
|
|
638
|
+
action.type === 'update_bot' ||
|
|
639
|
+
action.type === 'apply_state');
|
|
640
|
+
};
|
|
641
|
+
const getAllActions = () => {
|
|
642
|
+
const actions = runtime._processUnbatchedActions();
|
|
643
|
+
allActions.push(...actions);
|
|
644
|
+
return allActions;
|
|
645
|
+
};
|
|
646
|
+
// The config bot is always ID 0 in debuggers
|
|
647
|
+
const configBotId = (options === null || options === void 0 ? void 0 : options.useRealUUIDs)
|
|
648
|
+
? runtime.context.uuid()
|
|
649
|
+
: 'uuid-0';
|
|
650
|
+
const configBotTags = (options === null || options === void 0 ? void 0 : options.configBot)
|
|
651
|
+
? isBot(options === null || options === void 0 ? void 0 : options.configBot)
|
|
652
|
+
? options.configBot.tags
|
|
653
|
+
: options.configBot
|
|
654
|
+
: {};
|
|
655
|
+
runtime.context.createBot(createBot(configBotId, configBotTags, 'tempLocal'));
|
|
656
|
+
runtime.process(this._builtinPortalBots.map((b) => registerBuiltinPortal(b)));
|
|
657
|
+
runtime.userId = configBotId;
|
|
658
|
+
const api = {
|
|
659
|
+
...runtime._library.api,
|
|
660
|
+
};
|
|
661
|
+
if (interpreter) {
|
|
662
|
+
for (let key in runtime._library.api) {
|
|
663
|
+
const val = runtime._library.api[key];
|
|
664
|
+
if (isInterpretableFunction(val)) {
|
|
665
|
+
const func = getInterpretableFunction(val);
|
|
666
|
+
api[key] = (...args) => {
|
|
667
|
+
const result = func(...args);
|
|
668
|
+
if (isGenerator(result)) {
|
|
669
|
+
return runtime._processGenerator(result);
|
|
670
|
+
}
|
|
671
|
+
return result;
|
|
672
|
+
};
|
|
690
673
|
}
|
|
691
674
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
675
|
+
}
|
|
676
|
+
if (interpreter && (options === null || options === void 0 ? void 0 : options.pausable)) {
|
|
677
|
+
interpreter.debugging = true;
|
|
678
|
+
}
|
|
679
|
+
const debug = {
|
|
680
|
+
[UNCOPIABLE]: true,
|
|
681
|
+
...api,
|
|
682
|
+
getAllActions,
|
|
683
|
+
getCommonActions: () => {
|
|
684
|
+
return getAllActions().filter(isCommonAction);
|
|
685
|
+
},
|
|
686
|
+
getBotActions: () => {
|
|
687
|
+
return getAllActions().filter((a) => !isCommonAction(a));
|
|
688
|
+
},
|
|
689
|
+
getErrors: () => {
|
|
690
|
+
const errors = runtime._processUnbatchedErrors();
|
|
691
|
+
allErrors.push(...errors);
|
|
692
|
+
return allErrors;
|
|
693
|
+
},
|
|
694
|
+
onBeforeUserAction: (listener) => {
|
|
695
|
+
runtime._beforeActionListeners.push(listener);
|
|
696
|
+
},
|
|
697
|
+
onScriptActionEnqueued: (listener) => {
|
|
698
|
+
runtime._scriptActionEnqueuedListeners.push(listener);
|
|
699
|
+
},
|
|
700
|
+
onAfterScriptUpdatedTag: (listener) => {
|
|
701
|
+
runtime._scriptUpdatedTagListeners.push(listener);
|
|
702
|
+
},
|
|
703
|
+
onAfterScriptUpdatedTagMask: (listener) => {
|
|
704
|
+
runtime._scriptUpdatedTagMaskListeners.push(listener);
|
|
705
|
+
},
|
|
706
|
+
getCallStack() {
|
|
707
|
+
if (!interpreter) {
|
|
708
|
+
throw new Error('getCallStack() is only supported on pausable debuggers.');
|
|
709
|
+
}
|
|
710
|
+
return runtime._mapCallStack(interpreter.agent.executionContextStack);
|
|
711
|
+
},
|
|
712
|
+
async performUserAction(...actions) {
|
|
713
|
+
const result = await runtime.process(actions);
|
|
714
|
+
return result.map((r) => (r ? r.results : null));
|
|
715
|
+
},
|
|
716
|
+
// TODO: Determine whether to support this
|
|
717
|
+
// onBeforeScriptEnter: (
|
|
718
|
+
// listener: (trace: DebuggerScriptEnterTrace) => void
|
|
719
|
+
// ) => {
|
|
720
|
+
// runtime._beforeScriptEnterListeners.push(listener);
|
|
721
|
+
// },
|
|
722
|
+
// onAfterScriptExit: (
|
|
723
|
+
// listener: (trace: DebuggerScriptExitTrace) => void
|
|
724
|
+
// ) => {
|
|
725
|
+
// runtime._afterScriptExitListeners.push(listener);
|
|
726
|
+
// },
|
|
727
|
+
setPauseTrigger(b, tag, options) {
|
|
728
|
+
var _a, _b, _c;
|
|
729
|
+
if (typeof b === 'object' && 'triggerId' in b) {
|
|
730
|
+
runtime.setBreakpoint({
|
|
731
|
+
id: b.triggerId,
|
|
732
|
+
botId: b.botId,
|
|
733
|
+
tag: b.tag,
|
|
734
|
+
lineNumber: b.lineNumber,
|
|
735
|
+
columnNumber: b.columnNumber,
|
|
736
|
+
states: (_a = b.states) !== null && _a !== void 0 ? _a : ['before'],
|
|
737
|
+
disabled: !((_b = b.enabled) !== null && _b !== void 0 ? _b : true),
|
|
721
738
|
});
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
columnNumber: trigger.columnNumber,
|
|
757
|
-
states: (_c = trigger.states) !== null && _c !== void 0 ? _c : ['before'],
|
|
758
|
-
disabled: false,
|
|
759
|
-
});
|
|
760
|
-
return trigger;
|
|
761
|
-
}
|
|
762
|
-
},
|
|
763
|
-
removePauseTrigger(triggerOrId) {
|
|
764
|
-
let id = typeof triggerOrId === 'string'
|
|
765
|
-
? triggerOrId
|
|
766
|
-
: triggerOrId.triggerId;
|
|
767
|
-
runtime.removeBreakpoint(id);
|
|
768
|
-
},
|
|
769
|
-
disablePauseTrigger(triggerOrId) {
|
|
770
|
-
var _a;
|
|
771
|
-
if (typeof triggerOrId === 'string') {
|
|
772
|
-
let trigger = runtime._breakpoints.get(triggerOrId);
|
|
773
|
-
if (trigger) {
|
|
774
|
-
trigger.disabled = true;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
else {
|
|
778
|
-
runtime.setBreakpoint({
|
|
779
|
-
id: triggerOrId.triggerId,
|
|
780
|
-
botId: triggerOrId.botId,
|
|
781
|
-
tag: triggerOrId.tag,
|
|
782
|
-
lineNumber: triggerOrId.lineNumber,
|
|
783
|
-
columnNumber: triggerOrId.columnNumber,
|
|
784
|
-
states: (_a = triggerOrId.states) !== null && _a !== void 0 ? _a : ['before'],
|
|
785
|
-
disabled: true,
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
|
-
},
|
|
789
|
-
enablePauseTrigger(triggerOrId) {
|
|
790
|
-
var _a;
|
|
791
|
-
if (typeof triggerOrId === 'string') {
|
|
792
|
-
let trigger = runtime._breakpoints.get(triggerOrId);
|
|
793
|
-
if (trigger) {
|
|
794
|
-
trigger.disabled = false;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
else {
|
|
798
|
-
runtime.setBreakpoint({
|
|
799
|
-
id: triggerOrId.triggerId,
|
|
800
|
-
botId: triggerOrId.botId,
|
|
801
|
-
tag: triggerOrId.tag,
|
|
802
|
-
lineNumber: triggerOrId.lineNumber,
|
|
803
|
-
columnNumber: triggerOrId.columnNumber,
|
|
804
|
-
states: (_a = triggerOrId.states) !== null && _a !== void 0 ? _a : ['before'],
|
|
805
|
-
disabled: false,
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
},
|
|
809
|
-
listPauseTriggers() {
|
|
810
|
-
let triggers = [];
|
|
811
|
-
for (let breakpoint of runtime._breakpoints.values()) {
|
|
812
|
-
triggers.push({
|
|
813
|
-
triggerId: breakpoint.id,
|
|
814
|
-
botId: breakpoint.botId,
|
|
815
|
-
tag: breakpoint.tag,
|
|
816
|
-
columnNumber: breakpoint.columnNumber,
|
|
817
|
-
lineNumber: breakpoint.lineNumber,
|
|
818
|
-
states: breakpoint.states.slice(),
|
|
819
|
-
enabled: !breakpoint.disabled,
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
return triggers;
|
|
823
|
-
},
|
|
824
|
-
listCommonPauseTriggers(botOrId, tag) {
|
|
825
|
-
const id = typeof botOrId === 'string' ? botOrId : botOrId.id;
|
|
826
|
-
const bot = runtime.currentState[id];
|
|
827
|
-
const func = bot.listeners[tag];
|
|
828
|
-
if (!func) {
|
|
829
|
-
return [];
|
|
739
|
+
return b;
|
|
740
|
+
}
|
|
741
|
+
else {
|
|
742
|
+
const id = isBot(b) ? b.id : b;
|
|
743
|
+
const trigger = {
|
|
744
|
+
triggerId: uuid(),
|
|
745
|
+
botId: id,
|
|
746
|
+
tag: tag,
|
|
747
|
+
...options,
|
|
748
|
+
};
|
|
749
|
+
runtime.setBreakpoint({
|
|
750
|
+
id: trigger.triggerId,
|
|
751
|
+
botId: id,
|
|
752
|
+
tag: tag,
|
|
753
|
+
lineNumber: trigger.lineNumber,
|
|
754
|
+
columnNumber: trigger.columnNumber,
|
|
755
|
+
states: (_c = trigger.states) !== null && _c !== void 0 ? _c : ['before'],
|
|
756
|
+
disabled: false,
|
|
757
|
+
});
|
|
758
|
+
return trigger;
|
|
759
|
+
}
|
|
760
|
+
},
|
|
761
|
+
removePauseTrigger(triggerOrId) {
|
|
762
|
+
let id = typeof triggerOrId === 'string'
|
|
763
|
+
? triggerOrId
|
|
764
|
+
: triggerOrId.triggerId;
|
|
765
|
+
runtime.removeBreakpoint(id);
|
|
766
|
+
},
|
|
767
|
+
disablePauseTrigger(triggerOrId) {
|
|
768
|
+
var _a;
|
|
769
|
+
if (typeof triggerOrId === 'string') {
|
|
770
|
+
let trigger = runtime._breakpoints.get(triggerOrId);
|
|
771
|
+
if (trigger) {
|
|
772
|
+
trigger.disabled = true;
|
|
830
773
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
botId: stop.breakpoint.botId,
|
|
842
|
-
tag: stop.breakpoint.tag,
|
|
843
|
-
lineNumber: stop.breakpoint.lineNumber,
|
|
844
|
-
columnNumber: stop.breakpoint.columnNumber,
|
|
845
|
-
states: stop.breakpoint.states,
|
|
846
|
-
},
|
|
847
|
-
};
|
|
848
|
-
callback(pause);
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
runtime.setBreakpoint({
|
|
777
|
+
id: triggerOrId.triggerId,
|
|
778
|
+
botId: triggerOrId.botId,
|
|
779
|
+
tag: triggerOrId.tag,
|
|
780
|
+
lineNumber: triggerOrId.lineNumber,
|
|
781
|
+
columnNumber: triggerOrId.columnNumber,
|
|
782
|
+
states: (_a = triggerOrId.states) !== null && _a !== void 0 ? _a : ['before'],
|
|
783
|
+
disabled: true,
|
|
849
784
|
});
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
return runtime.userBot;
|
|
859
|
-
},
|
|
860
|
-
getPortalBots() {
|
|
861
|
-
var _a;
|
|
862
|
-
let portalBots = new Map();
|
|
863
|
-
for (let [portal, id] of runtime._portalBots) {
|
|
864
|
-
portalBots.set(portal, (_a = runtime.currentState[id]) === null || _a === void 0 ? void 0 : _a.script);
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
enablePauseTrigger(triggerOrId) {
|
|
788
|
+
var _a;
|
|
789
|
+
if (typeof triggerOrId === 'string') {
|
|
790
|
+
let trigger = runtime._breakpoints.get(triggerOrId);
|
|
791
|
+
if (trigger) {
|
|
792
|
+
trigger.disabled = false;
|
|
865
793
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
runtime.setBreakpoint({
|
|
797
|
+
id: triggerOrId.triggerId,
|
|
798
|
+
botId: triggerOrId.botId,
|
|
799
|
+
tag: triggerOrId.tag,
|
|
800
|
+
lineNumber: triggerOrId.lineNumber,
|
|
801
|
+
columnNumber: triggerOrId.columnNumber,
|
|
802
|
+
states: (_a = triggerOrId.states) !== null && _a !== void 0 ? _a : ['before'],
|
|
803
|
+
disabled: false,
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
listPauseTriggers() {
|
|
808
|
+
let triggers = [];
|
|
809
|
+
for (let breakpoint of runtime._breakpoints.values()) {
|
|
810
|
+
triggers.push({
|
|
811
|
+
triggerId: breakpoint.id,
|
|
812
|
+
botId: breakpoint.botId,
|
|
813
|
+
tag: breakpoint.tag,
|
|
814
|
+
columnNumber: breakpoint.columnNumber,
|
|
815
|
+
lineNumber: breakpoint.lineNumber,
|
|
816
|
+
states: breakpoint.states.slice(),
|
|
817
|
+
enabled: !breakpoint.disabled,
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
return triggers;
|
|
821
|
+
},
|
|
822
|
+
listCommonPauseTriggers(botOrId, tag) {
|
|
823
|
+
const id = typeof botOrId === 'string' ? botOrId : botOrId.id;
|
|
824
|
+
const bot = runtime.currentState[id];
|
|
825
|
+
const func = bot.listeners[tag];
|
|
826
|
+
if (!func) {
|
|
827
|
+
return [];
|
|
828
|
+
}
|
|
829
|
+
return runtime._compiler.listPossibleBreakpoints(func, runtime._interpreter);
|
|
830
|
+
},
|
|
831
|
+
onPause(callback) {
|
|
832
|
+
runtime.onRuntimeStop.subscribe((stop) => {
|
|
833
|
+
const pause = {
|
|
834
|
+
pauseId: stop.stopId,
|
|
835
|
+
state: stop.state,
|
|
836
|
+
callStack: runtime._mapCallStack(stop.stack),
|
|
837
|
+
trigger: {
|
|
838
|
+
triggerId: stop.breakpoint.id,
|
|
839
|
+
botId: stop.breakpoint.botId,
|
|
840
|
+
tag: stop.breakpoint.tag,
|
|
841
|
+
lineNumber: stop.breakpoint.lineNumber,
|
|
842
|
+
columnNumber: stop.breakpoint.columnNumber,
|
|
843
|
+
states: stop.breakpoint.states,
|
|
844
|
+
},
|
|
845
|
+
};
|
|
846
|
+
callback(pause);
|
|
847
|
+
});
|
|
848
|
+
},
|
|
849
|
+
resume(pause) {
|
|
850
|
+
runtime.continueAfterStop(pause.pauseId);
|
|
851
|
+
},
|
|
852
|
+
[GET_RUNTIME]() {
|
|
853
|
+
return runtime;
|
|
854
|
+
},
|
|
855
|
+
get configBot() {
|
|
856
|
+
return runtime.userBot;
|
|
857
|
+
},
|
|
858
|
+
getPortalBots() {
|
|
859
|
+
var _a;
|
|
860
|
+
let portalBots = new Map();
|
|
861
|
+
for (let [portal, id] of runtime._portalBots) {
|
|
862
|
+
portalBots.set(portal, (_a = runtime.currentState[id]) === null || _a === void 0 ? void 0 : _a.script);
|
|
863
|
+
}
|
|
864
|
+
return portalBots;
|
|
865
|
+
},
|
|
866
|
+
create,
|
|
867
|
+
};
|
|
868
|
+
runtime._currentDebugger = debug;
|
|
869
|
+
this._scheduleJobQueueCheck();
|
|
870
|
+
return debug;
|
|
873
871
|
}
|
|
874
872
|
_mapCallStack(stack) {
|
|
875
873
|
const interpreter = this._interpreter;
|
|
@@ -1649,9 +1647,13 @@ export class AuxRuntime {
|
|
|
1649
1647
|
if (masks) {
|
|
1650
1648
|
if (!replacedBot) {
|
|
1651
1649
|
replacedBot = true;
|
|
1652
|
-
bot =
|
|
1650
|
+
bot = {
|
|
1651
|
+
...bot,
|
|
1652
|
+
};
|
|
1653
1653
|
if (bot.masks) {
|
|
1654
|
-
bot.masks =
|
|
1654
|
+
bot.masks = {
|
|
1655
|
+
...bot.masks,
|
|
1656
|
+
};
|
|
1655
1657
|
}
|
|
1656
1658
|
else {
|
|
1657
1659
|
bot.masks = {};
|
|
@@ -2081,7 +2083,9 @@ export class AuxRuntime {
|
|
|
2081
2083
|
for (let action of actions) {
|
|
2082
2084
|
if (action.type === 'add_bot') {
|
|
2083
2085
|
if (this._newBots.has(action.id)) {
|
|
2084
|
-
action.bot.tags =
|
|
2086
|
+
action.bot.tags = {
|
|
2087
|
+
...action.bot.tags,
|
|
2088
|
+
};
|
|
2085
2089
|
}
|
|
2086
2090
|
}
|
|
2087
2091
|
}
|
|
@@ -2100,7 +2104,9 @@ export class AuxRuntime {
|
|
|
2100
2104
|
const newBot = this._newBots.get(bot.id);
|
|
2101
2105
|
newBot.masks = {};
|
|
2102
2106
|
for (let space in bot.maskChanges) {
|
|
2103
|
-
newBot.masks[space] =
|
|
2107
|
+
newBot.masks[space] = {
|
|
2108
|
+
...bot.maskChanges[space],
|
|
2109
|
+
};
|
|
2104
2110
|
}
|
|
2105
2111
|
}
|
|
2106
2112
|
}
|
|
@@ -2108,12 +2114,14 @@ export class AuxRuntime {
|
|
|
2108
2114
|
if (isInContext(this._globalContext, bot)) {
|
|
2109
2115
|
let update = {};
|
|
2110
2116
|
if (hasTagChange) {
|
|
2111
|
-
update.tags =
|
|
2117
|
+
update.tags = { ...bot.changes };
|
|
2112
2118
|
}
|
|
2113
2119
|
if (hasMaskChange) {
|
|
2114
2120
|
update.masks = {};
|
|
2115
2121
|
for (let space in bot.maskChanges) {
|
|
2116
|
-
update.masks[space] =
|
|
2122
|
+
update.masks[space] = {
|
|
2123
|
+
...bot.maskChanges[space],
|
|
2124
|
+
};
|
|
2117
2125
|
}
|
|
2118
2126
|
}
|
|
2119
2127
|
updates.push(botUpdated(bot.id, update));
|
|
@@ -2142,7 +2150,7 @@ export class AuxRuntime {
|
|
|
2142
2150
|
let compiledBot = {
|
|
2143
2151
|
id: bot.id,
|
|
2144
2152
|
precalculated: true,
|
|
2145
|
-
tags: fromFactory ? bot.tags :
|
|
2153
|
+
tags: fromFactory ? bot.tags : { ...bot.tags },
|
|
2146
2154
|
listeners: {},
|
|
2147
2155
|
modules: {},
|
|
2148
2156
|
exports: {},
|
|
@@ -2161,9 +2169,9 @@ export class AuxRuntime {
|
|
|
2161
2169
|
}
|
|
2162
2170
|
// Copy existing tag masks to the new bot
|
|
2163
2171
|
if (!fromFactory && this._existingMasks[bot.id]) {
|
|
2164
|
-
bot =
|
|
2172
|
+
bot = { ...bot };
|
|
2165
2173
|
if (bot.masks) {
|
|
2166
|
-
bot.masks =
|
|
2174
|
+
bot.masks = { ...bot.masks };
|
|
2167
2175
|
}
|
|
2168
2176
|
const existing = this._existingMasks[bot.id];
|
|
2169
2177
|
delete this._existingMasks[bot.id];
|
|
@@ -2172,7 +2180,7 @@ export class AuxRuntime {
|
|
|
2172
2180
|
bot.masks = {};
|
|
2173
2181
|
}
|
|
2174
2182
|
else if (bot.masks[space]) {
|
|
2175
|
-
bot.masks[space] =
|
|
2183
|
+
bot.masks[space] = { ...bot.masks[space] };
|
|
2176
2184
|
}
|
|
2177
2185
|
for (let tag in existing[space]) {
|
|
2178
2186
|
if (hasValue((_b = (_a = bot.masks) === null || _a === void 0 ? void 0 : _a[space]) === null || _b === void 0 ? void 0 : _b[tag])) {
|
|
@@ -2189,7 +2197,9 @@ export class AuxRuntime {
|
|
|
2189
2197
|
if (hasValue(bot.masks)) {
|
|
2190
2198
|
compiledBot.masks = {};
|
|
2191
2199
|
for (let space in bot.masks) {
|
|
2192
|
-
compiledBot.masks[space] =
|
|
2200
|
+
compiledBot.masks[space] = {
|
|
2201
|
+
...bot.masks[space],
|
|
2202
|
+
};
|
|
2193
2203
|
}
|
|
2194
2204
|
}
|
|
2195
2205
|
compiledBot.script = this._createRuntimeBot(compiledBot);
|
|
@@ -2632,12 +2642,20 @@ export class AuxRuntime {
|
|
|
2632
2642
|
enumerable: false,
|
|
2633
2643
|
configurable: false,
|
|
2634
2644
|
writable: false,
|
|
2635
|
-
value: (module) =>
|
|
2636
|
-
return
|
|
2637
|
-
}
|
|
2645
|
+
value: async (module) => {
|
|
2646
|
+
return await this.resolveModule(module, meta, true);
|
|
2647
|
+
},
|
|
2638
2648
|
});
|
|
2639
|
-
const constants =
|
|
2640
|
-
|
|
2649
|
+
const constants = {
|
|
2650
|
+
...((_a = options.api) !== null && _a !== void 0 ? _a : this._library.api),
|
|
2651
|
+
tagName: tag,
|
|
2652
|
+
globalThis: this._globalObject,
|
|
2653
|
+
[IMPORT_META_FACTORY]: meta,
|
|
2654
|
+
__energyCheck: this._library.api.__energyCheck,
|
|
2655
|
+
};
|
|
2656
|
+
const specifics = {
|
|
2657
|
+
...((_b = options.tagSpecificApi) !== null && _b !== void 0 ? _b : this._library.tagSpecificApi),
|
|
2658
|
+
};
|
|
2641
2659
|
if (this._interpreter) {
|
|
2642
2660
|
delete constants.globalThis;
|
|
2643
2661
|
// if (this.canTriggerBreakpoint) {
|
|
@@ -2681,9 +2699,20 @@ export class AuxRuntime {
|
|
|
2681
2699
|
throw data;
|
|
2682
2700
|
},
|
|
2683
2701
|
constants: constants,
|
|
2684
|
-
variables:
|
|
2702
|
+
variables: {
|
|
2703
|
+
...specifics,
|
|
2704
|
+
this: (ctx) => (ctx.bot ? ctx.bot.script : null),
|
|
2705
|
+
thisBot: (ctx) => (ctx.bot ? ctx.bot.script : null),
|
|
2706
|
+
bot: (ctx) => (ctx.bot ? ctx.bot.script : null),
|
|
2707
|
+
tags: (ctx) => (ctx.bot ? ctx.bot.script.tags : null),
|
|
2708
|
+
raw: (ctx) => (ctx.bot ? ctx.bot.script.raw : null),
|
|
2709
|
+
masks: (ctx) => (ctx.bot ? ctx.bot.script.masks : null),
|
|
2710
|
+
creatorBot: (ctx) => ctx.creator,
|
|
2711
|
+
configBot: () => this.context.playerBot,
|
|
2712
|
+
links: (ctx) => (ctx.bot ? ctx.bot.script.links : null),
|
|
2685
2713
|
// Default import function
|
|
2686
|
-
[`_${IMPORT_FACTORY}`]: () => (module, meta) => this._importModule(module, meta)
|
|
2714
|
+
[`_${IMPORT_FACTORY}`]: () => (module, meta) => this._importModule(module, meta),
|
|
2715
|
+
},
|
|
2687
2716
|
arguments: [['that', 'data'], IMPORT_FACTORY, EXPORT_FACTORY],
|
|
2688
2717
|
});
|
|
2689
2718
|
if (hasValue(bot)) {
|
|
@@ -3025,7 +3054,11 @@ export class AuxRuntime {
|
|
|
3025
3054
|
};
|
|
3026
3055
|
this._stopState = state;
|
|
3027
3056
|
let breakpoint = this._breakpoints.get(next.value.breakpoint.id);
|
|
3028
|
-
this._onRuntimeStop.next(
|
|
3057
|
+
this._onRuntimeStop.next({
|
|
3058
|
+
...next.value,
|
|
3059
|
+
breakpoint,
|
|
3060
|
+
stopId: this._currentStopCount,
|
|
3061
|
+
});
|
|
3029
3062
|
return;
|
|
3030
3063
|
}
|
|
3031
3064
|
}
|