M13.1: ScriptUI frontend (dialogs, palettes, dockable panels), script menus, example plug-in, docs
- ui-egui: scriptui_view draws script windows at engine layout bounds; PanelKind::ScriptPanel; File ▸ Scripts and Window menu list scripts/panels (egui + native menus) - examples/plugins/posterize-bands (WebAssembly, API v1); host plug-in tests; desktop loads <config>/Plug-ins - MCP: script_ui and history tools; docs/plugins.md, agents.md, parity, architecture, ATTRIBUTION Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
89c9b1b6ee
commit
00eb951711
@@ -265,6 +265,32 @@ fn bridge_rejects_non_loopback() {
|
||||
assert!(Backend::bridge("localhost:9877").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_ui_and_history_tools() {
|
||||
let mut sess = Session::default();
|
||||
effectcraft_script::install(&mut sess);
|
||||
let mut s = McpServer::new(Backend::headless(sess));
|
||||
let code = "var d = new Window('dialog', 'Ask'); var g = d.add('group'); g.add('button', undefined, 'OK', {name: 'ok'}); \
|
||||
if (d.show() == 1) app.project.items.addComp('Answered', 64, 64, 1, 1, 24); 'done'";
|
||||
let r = call_json(&mut s, "run_script", json!({"code": code}));
|
||||
assert_eq!(r["waiting"], json!(true), "{r}");
|
||||
let list = call_json(&mut s, "script_ui", json!({}));
|
||||
assert_eq!(list[0]["title"], "Ask");
|
||||
let tree = call_json(&mut s, "script_ui", json!({"action": "get"}));
|
||||
assert_eq!(tree["root"]["children"][0]["children"][0]["name"], "ok");
|
||||
let r = call_json(&mut s, "script_ui", json!({"action": "click", "widget": "ok"}));
|
||||
assert_eq!(r["result"], json!("done"), "{r}");
|
||||
// History: undo the comp, make another, and jump back to the first on its branch.
|
||||
call_json(&mut s, "undo", json!({}));
|
||||
call_json(&mut s, "execute_command", json!({"command": "comp.new", "params": {"name": "Other", "width": 64, "height": 64}}));
|
||||
let h = call_json(&mut s, "history", json!({}));
|
||||
let branch = h["states"].as_array().unwrap().iter().find(|n| n["depth"] == 1).unwrap()["index"].clone();
|
||||
let h = call_json(&mut s, "history", json!({"goto": branch}));
|
||||
let cur = h["current"].as_u64().unwrap() as usize;
|
||||
assert_eq!(h["states"][cur]["depth"], 0, "the jumped-to state is now the working line");
|
||||
assert!(call_json(&mut s, "get_project", json!({})).to_string().contains("Answered"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_script_round_trip() {
|
||||
let mut sess = Session::default();
|
||||
|
||||
@@ -315,6 +315,20 @@ fn redo(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
history(b, a, "edit.redo")
|
||||
}
|
||||
|
||||
fn script_ui_tool(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
let action = get(a, "action").and_then(Value::as_str).unwrap_or("list");
|
||||
let id = match action {
|
||||
"list" => "scriptui.list",
|
||||
"get" => "scriptui.get",
|
||||
"click" => "scriptui.click",
|
||||
"set" => "scriptui.set",
|
||||
"close" => "scriptui.close",
|
||||
other => return Err(Error::BadArgs(format!("unknown action `{other}` (list | get | click | set | close)"))),
|
||||
};
|
||||
let p = obj(&[("window", get(a, "window")), ("widget", get(a, "widget")), ("value", get(a, "value")), ("result", get(a, "result"))]);
|
||||
json_reply(b.exec(id, p)?)
|
||||
}
|
||||
|
||||
fn history_tool(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
if let Some(g) = get(a, "goto") {
|
||||
let p = match g {
|
||||
@@ -554,6 +568,24 @@ static TOOLS: &[ToolDef] = &[
|
||||
schema: || schema(json!({"goto": {"type": ["integer", "string"], "description": "State index or id to jump to (edit.history.goto)."}}), &[]),
|
||||
run: history_tool,
|
||||
},
|
||||
ToolDef {
|
||||
name: "script_ui",
|
||||
description: "Drive ScriptUI windows that scripts opened (dialogs, palettes, dockable panels). action `list` (default): open windows; `get`: a window's control tree (type, name, text, value, checked, items, selection, bounds); `click`: press a button / toggle a checkbox / pick a radio button; `set`: type text, move a slider, pick a list item (index or text); `close`: close a window (`result` for a dialog's show(), default 2 = Cancel). Controls by id, \"#id\", properties.name or text. A dialog's script resumes when the dialog closes.",
|
||||
bridge_only: false,
|
||||
schema: || {
|
||||
schema(
|
||||
json!({
|
||||
"action": {"type": "string", "enum": ["list", "get", "click", "set", "close"]},
|
||||
"window": {"type": ["integer", "string"], "description": "Window id or title (optional when one is open)."},
|
||||
"widget": {"type": ["integer", "string"], "description": "Control id, \"#id\", properties.name or text."},
|
||||
"value": {"description": "For `set`: text, number, bool, item index or item text."},
|
||||
"result": {"type": "integer", "description": "For `close`: what the dialog's show() returns."}
|
||||
}),
|
||||
&[],
|
||||
)
|
||||
},
|
||||
run: script_ui_tool,
|
||||
},
|
||||
ToolDef {
|
||||
name: "screenshot",
|
||||
description: "Screenshot of the live app window, or one panel (`Composition`, `Timeline`, `EffectControls`, `Project`, ...) or element id, as PNG (longest side `max_side`, default 1600). Use it to check what the UI looks like after an action.",
|
||||
|
||||
Reference in New Issue
Block a user