json!({"type": ["integer","string"],"description": "Composition item id or name; omit for the active comp."})
}
fnlayer_s()-> Value{
json!({"type": ["integer","string"],"description": "Layer id (from get_comp), \"#n\" (1-based index from the top) or layer name."})
}
fnpath_s()-> Value{
json!({"type": "string","description": "Property path from get_layer: match ids joined by `/`, `#n` for the nth child, or `@uid`. E.g. `transform/position`, `transform/opacity`, `transform/scale`, `transform/rotation`, `effects/#1/blurriness`, `masks/#1/feather`, `@57`."})
}
fnvalue_s()-> Value{
json!({"description": "Number for 1-D properties (50), array for vectors ([960,540]), \"#rrggbb\" or [r,g,b,a] (0-1) for colours, bool for checkboxes, string for text/menus."})
letm=need(a,"method")?.as_str().ok_or_else(||Error::BadArgs("`method` must be a string".into()))?;
letp=params_of(get(a,"params"))?;
json_reply(b.control(m,p)?)
}
// ------------------------------------------------------------------ the catalogue
staticTOOLS: &[ToolDef]=&[
ToolDef{
name: "list_commands",
description: "List engine commands: id, label, menu path, shortcut, `params` doc (e.g. `{name?, width?, height?, frameRate?, duration? (s)}`) and whether it can run now (`why` if not). Every menu item, shortcut and panel gesture maps to one of these ids; run them with execute_command. Narrow with `filter` (e.g. `layer.new`, `keys`, `effect`).",
bridge_only: false,
schema: ||{
schema(
json!({
"filter": {"type": "string","description": "Only commands whose id or label contains this text (case-insensitive)."},
description: "One command in full: id, label, menu path, shortcut, the `params` doc, a JSON Schema of its parameters (`schema`: properties, required, additionalProperties) and whether it can run now (`why` if not). Use before execute_command when unsure of the parameters; execute_command rejects unknown keys.",
description: "Run any engine command by id with JSON params; edits are undoable. Examples: comp.new {\"name\":\"Main\",\"width\":1920,\"height\":1080,\"frameRate\":30,\"duration\":5}; layer.newText {\"text\":\"Hello\",\"size\":120,\"fill\":\"#ffffff\"} (returns {\"layer\":id}); layer.newSolid {\"color\":\"#3366ff\"}; layer.newShape; effect.apply {\"layer\":3,\"effect\":\"Gaussian Blur\"}; time.set {\"time\":2.5}; layer.select {\"layers\":[3]}. Layers are referenced by id, \"#n\" or name; times are seconds.",
bridge_only: false,
schema: ||{
schema(
json!({
"command": {"type": "string","description": "Command id, e.g. `comp.new`, `layer.newText`, `effect.apply` (see list_commands)."},
description: "Run JavaScript with an After Effects-style scripting object model (app, app.project, items.addComp, comp.layers.addSolid/addText/addShape/addNull/addCamera/addLight, layer.property(\"ADBE Transform Group\").property(\"ADBE Position\").setValueAtTime(t, v), Effects.addProperty(\"ADBE Gaussian Blur 2\"), expressions, markers, renderQueue…). Every edit is an undoable engine command; app.beginUndoGroup/endUndoGroup make one undo step. Returns {ok, result (last expression value), output (writeLn/$.writeln/alert text), error: {message, line, column} | null}. File access is limited to the project folder unless the user allows scripts to write files.",
bridge_only: false,
schema: ||{
schema(
json!({
"code": {"type": "string","description": "JavaScript source, e.g. `var c = app.project.items.addComp(\"Main\", 1920, 1080, 1, 5, 30); c.layers.addText(\"Hi\"); c.numLayers`."},
"name": {"type": "string","description": "Script name used in error messages (default `script`)."}
description: "Project overview: file path, dirty flag, bit depth, every item (id, name, type Composition/Footage/Solid/Folder, size, duration, layer count), the active comp id, current time (s), selected layers and the undo stack.",
bridge_only: false,
schema: ||schema(json!({}),&[]),
run: get_project,
},
ToolDef{
name: "get_comp",
description: "A composition: id, name, size, frame rate, duration, work area, background and its layers top to bottom (id, index, name, type, in/out/start seconds, blend mode, parent, track matte, switches). Layer ids feed get_layer, get_property/set_property and commands.",
description: "A layer's property tree (transform, masks, effects, text, shape contents, ...): leaf properties have a `path` usable with get_property/set_property/add_keyframe, plus uid, match id, name, type, value at `time`, keyframes and expression. Groups contain children; inspect them here, then select a leaf path. `flat: true` returns just a list of {path, type, value, keys, expression} (compact).",
"time": {"type": "number","description": "Comp time in seconds for values (default: current time)."},
"depth": {"type": "integer","description": "Group depth to expand (default all)."},
"flat": {"type": "boolean","description": "Return a flat list of properties instead of the tree."}
}),
&["layer"],
)
},
run: get_layer,
},
ToolDef{
name: "get_property",
description: "Read one property: type, value at `time` (comp seconds; default the current time), whether it is animated, its keyframes (time, value, in/out interpolation) and expression.",
bridge_only: false,
schema: ||{
schema(
json!({"layer": layer_s(),"path": path_s(),"comp": comp_s(),"time": {"type": "number","description": "Comp time in seconds."}}),
&["layer","path"],
)
},
run: get_property,
},
ToolDef{
name: "set_property",
description: "Set a property. Without `time`: sets the static value (or a key at the current time if already animated). With `time`: adds/replaces a keyframe there, turning the stopwatch on. `expression` sets an After Effects-style JS expression (\"\" removes it). Returns the property as get_property does. Examples: {\"layer\":3,\"path\":\"transform/opacity\",\"value\":50}; {\"layer\":\"Title\",\"path\":\"transform/position\",\"value\":[200,540],\"time\":0}; {\"layer\":3,\"path\":\"transform/rotation\",\"expression\":\"time*90\"}.",
"timeBase": {"type": "string","enum": ["layer","comp"],"description": "What `time` counts: layer time (the default) or comp time, as the Timeline shows it."},
"expression": {"type": "string","description": "Expression text; empty string removes the expression."}
}),
&["layer","path"],
)
},
run: set_property,
},
ToolDef{
name: "add_keyframe",
description: "Add keyframes to a property (turns the stopwatch on): one with `time` (+ optional `value`, default the current value) or many with `keys: [{time, value}]`, then optionally set their `interpolation`: linear, bezier, hold, easyEase, easyEaseIn, easyEaseOut. Example: {\"layer\":1,\"path\":\"transform/position\",\"keys\":[{\"time\":0,\"value\":[0,540]},{\"time\":2,\"value\":[1920,540]}],\"interpolation\":\"easyEase\"}.",
"timeBase": {"type": "string","enum": ["layer","comp"],"description": "What `time` counts: layer time (the default) or comp time, as the Timeline shows it."},
description: "Apply an effect to a layer and optionally set its parameters in one undoable call. `effect` is an id (`ec.blur.gaussian`) or After Effects name (`Gaussian Blur`; see list_effects); `values` maps parameter ids to values, e.g. {\"blurriness\": 12}. One undo step; if a value fails, nothing is applied. Returns the instance `path` (`effects/#n`, for set_property / add_keyframe) and its parameters with their paths and current values.",
"effect": {"type": "string","description": "Effect id or name, e.g. `Gaussian Blur`, `Glow`, `Curves`, `ec.color.levels`."},
"values": {"type": "object","description": "Parameter id -> value (ids are in the returned `params` paths), e.g. {\"blurriness\": 12}.","additionalProperties": true}
}),
&["layer","effect"],
)
},
run: add_effect,
},
ToolDef{
name: "list_effects",
description: "The effect registry: id, After Effects name, category, GPU and 32-bpc support. Narrow with `filter` (id, name or category text). Apply with add_effect.",
bridge_only: false,
schema: ||schema(json!({"filter": {"type": "string","description": "Only effects whose id, name or category contains this text."}}),&[]),
description: "The font families text layers can use, bundled and installed on this machine: family, styles, origin (bundled / system / user), whether it is a variable font and the name in the font's own language. Narrow with `query` and `variable`; `rescan` picks up fonts installed since launch. Set one with execute_command `layer.setText {\"layer\", \"font\", \"style\"}`.",
description: "Where things stand: the editor state (active comp, current time, selected layers/keys/items, open comps, tool, work area) plus what this build can do (`app`: version, command and effect counts, GPU effects, import/export formats, After Effects parity summary). Cheap; call it to re-orient after a series of edits.",
description: "Render a composition frame (default: the active comp at the current time) and return it as a PNG image, longest side `max_side` (default 960, 0 = full size). `path` also writes the PNG to disk; `inline: false` returns only the metadata. Use it to check your work.",
bridge_only: false,
schema: ||{
schema(
json!({
"comp": comp_s(),
"time": {"type": "number","description": "Comp time in seconds (default: current time)."},
"max_side": {"type": "integer","description": "Longest side in pixels (default 960; 0 = full comp size)."},
"path": {"type": "string","description": "Also write the PNG here."},
"inline": {"type": "boolean","description": "Include the image in the reply (default true)."},
"transparent": {"type": "boolean","description": "Keep the frame's alpha (RGBA PNG, as an RGB + Alpha render writes it) instead of compositing over the comp's background colour."}
description: "Open a project: `path` to an .ecproj file, `demo: true` for the built-in demo project, or `new: true` for an empty project. Returns the project overview.",
bridge_only: false,
schema: ||{
schema(json!({"path": {"type": "string","description": "Path of an .ecproj file."},"demo": {"type": "boolean"},"new": {"type": "boolean"}}),&[])
},
run: open_project,
},
ToolDef{
name: "save_project",
description: "Save the project to its current file, or to `path` (Save As, .ecproj).",
description: "The branching undo history (History panel): without arguments lists every state {index, id, label, parent, depth (0 = working line, >0 = branch), current, future}; undoing and then editing keeps the undone states as a branch. With `goto` (an index or id from the listing) jumps to that state, on any branch, without losing the others.",
bridge_only: false,
schema: ||schema(json!({"goto": {"type": ["integer","string"],"description": "State index or id to jump to (edit.history.goto)."}}),&[]),
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.",
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.",
bridge_only: true,
schema: ||{
schema(
json!({
"panel": {"type": "string","description": "Panel to crop to."},
"id": {"type": "string","description": "Element id (from ui_elements) to crop to."},
"max_side": {"type": "integer"},
"path": {"type": "string","description": "Keep the full-size PNG at this path."}
}),
&[],
)
},
run: screenshot,
},
ToolDef{
name: "ui_inspect",
description: "UI state: window size, tool, workspace, panels, viewer and timeline view state, playback, active comp, selection, open dialog, render time.",
bridge_only: true,
schema: ||schema(json!({}),&[]),
run: ui_inspect,
},
ToolDef{
name: "ui_elements",
description: "Interactive elements drawn in the last frame: id, label, rect [x,y,w,h] in points. Stable ids such as `tools.Selection`, `panel.Timeline`, `panel.tab.EffectControls`, `project.item.<id>`, `viewer.comp`, `timeline.layer.<id>.bar`, `timeline.prop.<uid>.stopwatch`, `timeline.cti`, `effects.item.<name>`. Filter with `prefix`.",
bridge_only: true,
schema: ||schema(json!({"prefix": {"type": "string","description": "Only ids starting with this, e.g. `tools.`, `timeline.layer.`."}}),&[]),
run: ui_elements,
},
ToolDef{
name: "ui_click",
description: "Click an element by `id` (from ui_elements) or at `x`,`y` (points). `button`: left|right|middle, `count`: 2 for double-click, `modifiers`: {shift, alt, command, ctrl}.",
description: "Press-move-release from `from` to `to`; each is {\"id\": element} (add fx/fy 0-1 for a spot inside it) or {\"x\",\"y\"}. Moves layers in the viewer, drags layer bars/keyframes/the CTI (`timeline.cti`), scrubs values, draws shapes with a shape tool.",
description: "Run several engine commands in one call as ONE undo step (engine.batch). Later steps can use earlier results: a string param \"$N\" or \"$N.key\" is step N's result (1-based), e.g. create a layer, then key and style it: {\"steps\":[{\"command\":\"layer.newText\",\"params\":{\"text\":\"Hi\",\"name\":\"Title\"}},{\"command\":\"prop.addKey\",\"params\":{\"layer\":\"$1.layer\",\"path\":\"transform/opacity\",\"time\":0,\"value\":0}},{\"command\":\"effect.apply\",\"params\":{\"layer\":\"$1.layer\",\"effect\":\"Glow\"}}]}. Returns {steps, results}. If a step fails the whole batch is rolled back (unless atomic: false) and the error names the step.",
description: "List engine commands: id, label, menu path, shortcut, `params` doc (e.g. `{name?, width?, height?, frameRate?, duration? (s)}`) and whether it can run now (`why` if not). Every menu item, shortcut and panel gesture maps to one of these ids; run them with execute_command. Narrow with `filter` (e.g. `layer.new`, `keys`, `effect`).",
bridge_only: false,
schema: ||{
schema(
json!({
"filter": {"type": "string","description": "Only commands whose id or label contains this text (case-insensitive)."},
"enabled_only": {"type": "boolean","description": "Only commands that can run right now."},
description: "Run any engine command by id with JSON params; edits are undoable. Examples: comp.new {\"name\":\"Main\",\"width\":1920,\"height\":1080,\"frameRate\":30,\"duration\":5}; layer.newText {\"text\":\"Hello\",\"size\":120,\"fill\":\"#ffffff\"} (returns {\"layer\":id}); layer.newSolid {\"color\":\"#3366ff\"}; layer.newShape; effect.apply {\"layer\":3,\"effect\":\"Gaussian Blur\"}; time.set {\"time\":2.5}; layer.select {\"layers\":[3]}. Layers are referenced by id, \"#n\" or name; times are seconds.",
bridge_only: false,
schema: ||{
schema(
json!({
"id": {"type": "string","description": "Command id, e.g. `comp.new`, `layer.newText`, `effect.apply` (see list_commands)."},
"params": {"type": "object","description": "Command parameters as documented by list_commands.","additionalProperties": true}
}),
&["id"],
)
},
run: execute_command,
},
ToolDef{
name: "render_preview",
description: "Render a composition frame (default: the active comp at the current time) and return it as a PNG image, longest side `max_side` (default 960, 0 = full size). Use it to check your work.",
bridge_only: false,
schema: ||{
schema(
json!({
"comp": comp_s(),
"time": {"type": "number","description": "Comp time in seconds (default: current time)."},
"max_side": {"type": "integer","description": "Longest side in pixels (default 960; 0 = full comp size)."},
"transparent": {"type": "boolean","description": "Keep the frame's alpha (RGBA PNG, as an RGB + Alpha render writes it) instead of compositing over the comp's background colour."}
}),
&[],
)
},
run: render_frame,
},
ToolDef{
name: "command_batch",
description: "Run commands in order, returning each result or error. Stop at the first error by default; stop_on_error: false continues. Each edit has its own undo step; use batch for an atomic undo group.",