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:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user