core.md 1.7 KB


title: Core section: core

order: 10

Response functions

sendResp(content)

Sets HTTP_RESP.

sendResp("done");

echo(content)

Appends text to current HTTP_RESP.

echo("Hello ");
echo("World");

sendOK()

Sets response to ok.

sendOK();

sendJSONResp(objectOrJsonString)

Sets HTTP_HEADER = application/json and writes JSON response.

sendJSONResp({ success: true, items: [1, 2, 3] });

Module and scheduling

registerModule(jsonConfigString)

Registers a module from JSON config.

registerModule(JSON.stringify({
    Name: "MyApp",
    Desc: "Example module",
    Group: "Utilities",
    IconPath: "icon.png",
    Version: "1.0",
    StartDir: "index.html",
    SupportFW: true,
    LaunchFWDir: "index.html"
}));

addNightlyTask(scriptPath)

Adds a valid AGI script to nightly task list.

addNightlyTask("MyApp/nightly.agi");

Utility and flow

includes(scriptName)

Loads and executes another script relative to current script directory.

includes("helpers.js");

delay(ms)

Sleeps for milliseconds.

delay(500);

exit()

Stops script execution.

if (!userIsAdmin()) exit();

execd(scriptName, payload)

Executes another script asynchronously.

execd("worker.agi", JSON.stringify({ job: "thumbs" }));

Deprecated (kept for compatibility)

  • requirepkg(...) -> deprecated in AGI v3
  • execpkg(...) -> deprecated in AGI v3
  • decodeVirtualPath(...) -> deprecated
  • decodeAbsoluteVirtualPath(...) -> deprecated
  • encodeRealPath(...) -> deprecated