Skip to main content

Module scripts

Module scripts 

Source
Expand description

The Scripts workspace: one space to write the app’s custom commands and pipeline steps, in Python or Rust. Scripts tree on the left, the editor (kitchen-ui’s CodeView: highlighting, errors on their lines) in the middle, the run panel (output, the result, errors) under it.

A script runs against what is in front of the user: it reads one JSON object on its stdin, {"args": …, "context": …} (the context is what the app says is shown: the image, the selection, the table), and may print its result as JSON on its last line of output.

A few comment lines at the top say what a script is (ScriptMeta):

# kitchen: command = Count cells
# kitchen: hint = Counts the cells of the shown image
# kitchen: args = {"type": "object", "properties": {"min_area": {"type": "number"}}}
# kitchen: node = in image:image; out counts:table

(// in Rust.) With command, the script becomes a command (ScriptsWorkspace::register): in the menus, the search and an agent’s tools, its arguments the schema given. With node, it becomes a pipeline node (ScriptsWorkspace::nodes) with typed inputs and outputs, whose types are the app’s (ScriptsWorkspace::new takes them). Running a script is a job with a cancel button; what it ran is reported (ScriptsEvent::Finished) for the app to record in its session.

Structs§

NodeSpec
A script as a pipeline node: typed ports, run by its script.
Port
A typed port of a script node.
RunOutput
What a run of a script produced.
Script
A script file.
ScriptMeta
What a script’s header says it is.
ScriptsWorkspace
The Scripts workspace.

Enums§

ScriptsEvent
What the workspace tells its owner.

Functions§

default_runner
The runner used by default: Python with python3; Rust with rust-script (install it with cargo install rust-script). The input goes to the script’s stdin.
script_errors
Errors on the script’s own lines in stderr: a Python traceback’s last frame in the script (File "…/count.py", line 7) with its last line, or a Rust message (--> count.rs:7:5).

Type Aliases§

ContextFn
Gives the script the context: what is shown now.
Runner
Runs a script with its input (blocking; called off the UI thread).