fix(minecraft): make action tool globals updatable so REPL reflects runtime action changes

Action tools were defined with configurable: false, preventing updates after
the first evaluate() call. New defineUpdatableGlobal uses configurable: true
so installActionTools can redefine them when available actions change.
This commit is contained in:
Rin
2026-02-18 11:14:44 +08:00
committed by Neko Ayaka
parent a140ce5065
commit 32957e4269
@@ -417,7 +417,7 @@ export class JavaScriptPlanner {
private installActionTools(availableActions: Action[]): void {
for (const action of availableActions) {
this.defineGlobalTool(action.name, async (...args: unknown[]) => {
this.defineUpdatableGlobal(action.name, async (...args: unknown[]) => {
const params = this.mapArgsToParams(action, args)
return this.runAction(action.name, params)
})
@@ -598,6 +598,18 @@ export class JavaScriptPlanner {
})
}
// NOTICE: Action tools must be updatable because the set of available actions
// can change at runtime. Unlike builtins (which are immutable), action tool
// globals use configurable: true so they can be redefined on each evaluate().
private defineUpdatableGlobal(name: string, value: unknown): void {
Object.defineProperty(this.sandbox, name, {
value,
configurable: true,
enumerable: true,
writable: false,
})
}
private previewValue(value: unknown): string {
if (value === null)
return 'null'