introduction.md 2.0 KB


title: Introduction group: Getting started order: 10

summary: What AGI is, where scripts run and a first script.

AGI (the ArOZ Online JavaScript Gateway Interface) is the server-side JavaScript runtime used by ArozOS for module scripts (.agi / .js). Scripts run in an Otto VM with sandboxed access to ArozOS functions. Every request or script gets a fresh VM, and every call into the file system, the database or another user's data is checked against the permissions of the user the script runs for.

AGI Version

  • Runtime version: {{agiVersion}} (AgiVersion in src/mod/agi/agi.go)

Where scripts run

  • init.agi: a WebApp's startup script, run once at boot from ./web/<App>/init.agi with system scope only. It registers the app with registerModule(...) and must not call user or file functions.
  • Front-end calls: a WebApp's page calls its backend scripts through ao_module_agirun(...) (/system/ajgi/interface). The script runs with the permissions of the signed-in user, and the request's form fields become global variables.
  • Serverless and scheduled scripts: external endpoints, nightly tasks (addNightlyTask) and user-approved scheduled tasks (scheduler).

JavaScript version

Otto implements ECMAScript 5. Declare variables with var and write functions with function: let, const, class, arrow functions and template literals are syntax errors. Regular expressions use Go's RE2 syntax, so lookahead and backreferences are not available.

Quick Start

// Basic response
sendResp("Hello from AGI");

// JSON response
sendJSONResp({ ok: true, time: Date.now() });

// Load a library
if (requirelib("filelib")) {
    var files = filelib.glob("user:/Desktop/*");
    sendJSONResp(files);
}

Every code sample in this reference has a Run button that opens it in the Playground, which runs the same Otto interpreter in your browser against a small virtual file system.