| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702 |
- {
- "_note": "This file is the source for the Terminal in-app documentation panel. It is derived from mod/agi/README.md. Whenever README.md is updated, this file MUST also be updated to keep the in-app help in sync.",
- "_version": "3.0",
- "sections": [
- {
- "id": "core",
- "name": "Core",
- "desc": "Built-in functions always available without requirelib()",
- "functions": [
- {
- "name": "sendResp",
- "sig": "sendResp(content)",
- "desc": "Set the HTTP response body.",
- "ret": "void",
- "example": "sendResp(\"Hello from AGI\");"
- },
- {
- "name": "sendJSONResp",
- "sig": "sendJSONResp(objectOrJsonString)",
- "desc": "Set Content-Type to application/json and write a JSON response.",
- "ret": "void",
- "example": "sendJSONResp({ ok: true, items: [1, 2, 3] });"
- },
- {
- "name": "echo",
- "sig": "echo(content)",
- "desc": "Append text to the current HTTP_RESP.",
- "ret": "void",
- "example": "echo(\"Hello \");\necho(\"World\");"
- },
- {
- "name": "sendOK",
- "sig": "sendOK()",
- "desc": "Set response to the string \"ok\".",
- "ret": "void",
- "example": "sendOK();"
- },
- {
- "name": "requirelib",
- "sig": "requirelib(libname)",
- "desc": "Load an AGI library into the current VM. Returns true on success.",
- "ret": "bool",
- "example": "if (!requirelib(\"filelib\")) {\n sendResp(\"filelib not available\");\n}"
- },
- {
- "name": "includes",
- "sig": "includes(scriptName)",
- "desc": "Load and execute another script relative to the current script's directory.",
- "ret": "void",
- "example": "includes(\"helpers.js\");"
- },
- {
- "name": "delay",
- "sig": "delay(ms)",
- "desc": "Sleep for the given number of milliseconds. After websocket.upgrade(), also pumps incoming WebSocket messages.",
- "ret": "void",
- "example": "delay(500);"
- },
- {
- "name": "exit",
- "sig": "exit()",
- "desc": "Stop script execution immediately.",
- "ret": "void",
- "example": "if (!userIsAdmin()) exit();"
- },
- {
- "name": "execd",
- "sig": "execd(scriptName, payload)",
- "desc": "Execute another AGI script asynchronously as a detached process.",
- "ret": "void",
- "example": "execd(\"worker.agi\", JSON.stringify({ job: \"thumbs\" }));"
- },
- {
- "name": "console.log",
- "sig": "console.log(...args)",
- "desc": "Write a line to the server log. In Terminal sessions, output is captured and shown in yellow.",
- "ret": "void",
- "example": "console.log(\"Debug:\", someVariable);"
- }
- ]
- },
- {
- "id": "db",
- "name": "DB",
- "desc": "Key-value database functions, always available.",
- "functions": [
- {
- "name": "newDBTableIfNotExists",
- "sig": "newDBTableIfNotExists(tableName)",
- "desc": "Create a database table if it does not already exist.",
- "ret": "bool",
- "example": "newDBTableIfNotExists(\"my_table\");"
- },
- {
- "name": "DBTableExists",
- "sig": "DBTableExists(tableName)",
- "desc": "Return true if the table exists.",
- "ret": "bool",
- "example": "if (DBTableExists(\"my_table\")) sendOK();"
- },
- {
- "name": "writeDBItem",
- "sig": "writeDBItem(tableName, key, value)",
- "desc": "Write a string value to the given key.",
- "ret": "bool",
- "example": "writeDBItem(\"my_table\", \"theme\", \"dark\");"
- },
- {
- "name": "readDBItem",
- "sig": "readDBItem(tableName, key)",
- "desc": "Read a string value from the given key.",
- "ret": "string",
- "example": "var theme = readDBItem(\"my_table\", \"theme\");"
- },
- {
- "name": "listDBTable",
- "sig": "listDBTable(tableName)",
- "desc": "Return all key-value pairs in the table as an object.",
- "ret": "object",
- "example": "var kv = listDBTable(\"my_table\");\nsendJSONResp(kv);"
- },
- {
- "name": "deleteDBItem",
- "sig": "deleteDBItem(tableName, key)",
- "desc": "Delete a single key from the table.",
- "ret": "bool",
- "example": "deleteDBItem(\"my_table\", \"theme\");"
- },
- {
- "name": "dropDBTable",
- "sig": "dropDBTable(tableName)",
- "desc": "Delete the entire table.",
- "ret": "bool",
- "example": "dropDBTable(\"my_table\");"
- }
- ]
- },
- {
- "id": "user",
- "name": "User",
- "desc": "User management and permission functions.",
- "functions": [
- {
- "name": "pathCanWrite",
- "sig": "pathCanWrite(vpath)",
- "desc": "Return true if the current user can write to the virtual path.",
- "ret": "bool",
- "example": "if (pathCanWrite(\"user:/Documents\")) sendOK();"
- },
- {
- "name": "getUserPermissionGroup",
- "sig": "getUserPermissionGroup()",
- "desc": "Return a JSON string describing the current user's permission group.",
- "ret": "string (JSON)",
- "example": "var group = JSON.parse(getUserPermissionGroup());"
- },
- {
- "name": "userIsAdmin",
- "sig": "userIsAdmin()",
- "desc": "Return true if the current user is an administrator.",
- "ret": "bool",
- "example": "if (!userIsAdmin()) {\n sendResp(\"Admin only\");\n exit();\n}"
- },
- {
- "name": "userExists",
- "sig": "userExists(username)",
- "desc": "(Admin only) Return true if the username exists.",
- "ret": "bool",
- "example": "if (userExists(\"alice\")) echo(\"exists\");"
- },
- {
- "name": "createUser",
- "sig": "createUser(username, password, defaultGroup)",
- "desc": "(Admin only) Create a new user account.",
- "ret": "bool",
- "example": "createUser(\"alice\", \"StrongPass\", \"default\");"
- },
- {
- "name": "removeUser",
- "sig": "removeUser(username)",
- "desc": "(Admin only) Delete a user account.",
- "ret": "bool",
- "example": "removeUser(\"alice\");"
- }
- ]
- },
- {
- "id": "filelib",
- "name": "filelib",
- "desc": "Virtual filesystem read, write, and metadata operations.",
- "load": "requirelib(\"filelib\");",
- "functions": [
- {
- "name": "filelib.writeFile",
- "sig": "filelib.writeFile(vpath, content)",
- "desc": "Write text content to a virtual path. Creates the file if it does not exist.",
- "ret": "bool",
- "example": "requirelib(\"filelib\");\nfilelib.writeFile(\"user:/notes.txt\", \"Hello World\");"
- },
- {
- "name": "filelib.readFile",
- "sig": "filelib.readFile(vpath)",
- "desc": "Read text content from a virtual path.",
- "ret": "string | false",
- "example": "requirelib(\"filelib\");\nvar text = filelib.readFile(\"user:/notes.txt\");"
- },
- {
- "name": "filelib.deleteFile",
- "sig": "filelib.deleteFile(vpath)",
- "desc": "Delete a file at the virtual path.",
- "ret": "bool",
- "example": "requirelib(\"filelib\");\nfilelib.deleteFile(\"user:/notes.txt\");"
- },
- {
- "name": "filelib.walk",
- "sig": "filelib.walk(vpath, mode)",
- "desc": "Recursively list entries. mode: \"all\", \"file\", or \"folder\".",
- "ret": "string[]",
- "example": "requirelib(\"filelib\");\nvar files = filelib.walk(\"user:/\", \"file\");"
- },
- {
- "name": "filelib.glob",
- "sig": "filelib.glob(pattern, sortMode)",
- "desc": "Glob match files. sortMode: \"default\" or user-defined sort. Does not support ** patterns.",
- "ret": "string[]",
- "example": "requirelib(\"filelib\");\nvar jpgs = filelib.glob(\"user:/Desktop/*.jpg\", \"default\");"
- },
- {
- "name": "filelib.aglob",
- "sig": "filelib.aglob(pattern, sortMode)",
- "desc": "Advanced glob supporting ** recursive patterns. Cannot scan bare root dirs.",
- "ret": "string[]",
- "example": "requirelib(\"filelib\");\nvar pngs = filelib.aglob(\"user:/Desktop/**/*.png\", \"default\");"
- },
- {
- "name": "filelib.readdir",
- "sig": "filelib.readdir(vpath, sortMode)",
- "desc": "List directory entries. Returns array of {Filename, Filepath, Ext, Filesize, Modtime, IsDir}.",
- "ret": "object[]",
- "example": "requirelib(\"filelib\");\nvar entries = filelib.readdir(\"user:/Desktop\", \"default\");\nsendJSONResp(entries);"
- },
- {
- "name": "filelib.filesize",
- "sig": "filelib.filesize(vpath)",
- "desc": "Return file size in bytes.",
- "ret": "number",
- "example": "requirelib(\"filelib\");\nvar sz = filelib.filesize(\"user:/movie.mp4\");"
- },
- {
- "name": "filelib.fileExists",
- "sig": "filelib.fileExists(vpath)",
- "desc": "Return true if the path exists as a file.",
- "ret": "bool",
- "example": "requirelib(\"filelib\");\nif (filelib.fileExists(\"user:/a.txt\")) sendOK();"
- },
- {
- "name": "filelib.isDir",
- "sig": "filelib.isDir(vpath)",
- "desc": "Return true if the path is a directory.",
- "ret": "bool",
- "example": "requirelib(\"filelib\");\nif (filelib.isDir(\"user:/Desktop\")) sendOK();"
- },
- {
- "name": "filelib.mkdir",
- "sig": "filelib.mkdir(vpath)",
- "desc": "Create a directory (and parents) at the virtual path.",
- "ret": "bool",
- "example": "requirelib(\"filelib\");\nfilelib.mkdir(\"user:/newfolder\");"
- },
- {
- "name": "filelib.md5",
- "sig": "filelib.md5(vpath)",
- "desc": "Return the MD5 hash string of a file.",
- "ret": "string",
- "example": "requirelib(\"filelib\");\nvar hash = filelib.md5(\"user:/a.txt\");"
- },
- {
- "name": "filelib.mtime",
- "sig": "filelib.mtime(vpath, parseToUnix)",
- "desc": "Return file modification time. parseToUnix=true returns a Unix timestamp; otherwise a formatted string.",
- "ret": "number | string",
- "example": "requirelib(\"filelib\");\nvar ts = filelib.mtime(\"user:/a.txt\", true);"
- },
- {
- "name": "filelib.rootName",
- "sig": "filelib.rootName(vpath)",
- "desc": "Return the display name of the storage root that owns this path.",
- "ret": "string",
- "example": "requirelib(\"filelib\");\nvar root = filelib.rootName(\"user:/Desktop/a.txt\");"
- }
- ]
- },
- {
- "id": "imagelib",
- "name": "imagelib",
- "desc": "Image dimension, resize, crop, and EXIF operations.",
- "load": "requirelib(\"imagelib\");",
- "functions": [
- {
- "name": "imagelib.getImageDimension",
- "sig": "imagelib.getImageDimension(vpath)",
- "desc": "Return [width, height] of the image.",
- "ret": "[number, number]",
- "example": "requirelib(\"imagelib\");\nvar dim = imagelib.getImageDimension(\"user:/img.jpg\");"
- },
- {
- "name": "imagelib.resizeImage",
- "sig": "imagelib.resizeImage(src, dest, width, height)",
- "desc": "Resize an image and save to dest.",
- "ret": "bool",
- "example": "requirelib(\"imagelib\");\nimagelib.resizeImage(\"user:/img.jpg\", \"user:/img_small.jpg\", 800, 600);"
- },
- {
- "name": "imagelib.resizeImageBase64",
- "sig": "imagelib.resizeImageBase64(src, width, height, format)",
- "desc": "Resize an image and return it as a base64 data URL. format: \"jpeg\", \"png\".",
- "ret": "string (data URL)",
- "example": "requirelib(\"imagelib\");\nvar b64 = imagelib.resizeImageBase64(\"user:/img.jpg\", 320, 240, \"jpeg\");"
- },
- {
- "name": "imagelib.cropImage",
- "sig": "imagelib.cropImage(src, dest, x, y, width, height)",
- "desc": "Crop a region from an image and save to dest.",
- "ret": "bool",
- "example": "requirelib(\"imagelib\");\nimagelib.cropImage(\"user:/img.jpg\", \"user:/crop.jpg\", 10, 10, 200, 200);"
- },
- {
- "name": "imagelib.loadThumbString",
- "sig": "imagelib.loadThumbString(vpath)",
- "desc": "Return the cached thumbnail as a base64 string.",
- "ret": "string",
- "example": "requirelib(\"imagelib\");\nvar thumb = imagelib.loadThumbString(\"user:/img.jpg\");"
- },
- {
- "name": "imagelib.hasExif",
- "sig": "imagelib.hasExif(vpath)",
- "desc": "Return true if the image has EXIF metadata.",
- "ret": "bool",
- "example": "requirelib(\"imagelib\");\nif (imagelib.hasExif(\"user:/img.jpg\")) echo(\"has exif\");"
- },
- {
- "name": "imagelib.getExif",
- "sig": "imagelib.getExif(vpath)",
- "desc": "Return EXIF data as a JSON string.",
- "ret": "string (JSON)",
- "example": "requirelib(\"imagelib\");\nvar exif = JSON.parse(imagelib.getExif(\"user:/img.jpg\"));"
- }
- ]
- },
- {
- "id": "http",
- "name": "http",
- "desc": "Outbound HTTP request helpers.",
- "load": "requirelib(\"http\");",
- "functions": [
- {
- "name": "http.get",
- "sig": "http.get(url)",
- "desc": "Perform an HTTP GET and return the response body as a string.",
- "ret": "string",
- "example": "requirelib(\"http\");\nvar body = http.get(\"https://example.com/api\");"
- },
- {
- "name": "http.post",
- "sig": "http.post(url, jsonString)",
- "desc": "Perform an HTTP POST with JSON body and return the response body.",
- "ret": "string",
- "example": "requirelib(\"http\");\nvar resp = http.post(\"https://example.com/api\", JSON.stringify({a:1}));"
- },
- {
- "name": "http.head",
- "sig": "http.head(url, headerKey)",
- "desc": "Fetch response headers. Without headerKey returns all headers as JSON; with headerKey returns just that header.",
- "ret": "string (JSON)",
- "example": "requirelib(\"http\");\nvar headers = JSON.parse(http.head(\"https://example.com\"));"
- },
- {
- "name": "http.getCode",
- "sig": "http.getCode(url)",
- "desc": "Return the HTTP status code for the URL.",
- "ret": "number",
- "example": "requirelib(\"http\");\nvar code = http.getCode(\"https://example.com\");"
- },
- {
- "name": "http.download",
- "sig": "http.download(url, destDirVpath, filenameOptional)",
- "desc": "Download a URL into the destination virtual directory.",
- "ret": "bool",
- "example": "requirelib(\"http\");\nhttp.download(\"https://example.com/a.zip\", \"user:/Downloads\", \"a.zip\");"
- },
- {
- "name": "http.getb64",
- "sig": "http.getb64(url)",
- "desc": "Fetch a URL and return the raw bytes as a base64 string.",
- "ret": "string",
- "example": "requirelib(\"http\");\nvar raw = http.getb64(\"https://example.com/logo.png\");"
- },
- {
- "name": "http.redirect",
- "sig": "http.redirect(targetUrl, statusCode)",
- "desc": "Redirect the client. Default statusCode is 307.",
- "ret": "void",
- "example": "requirelib(\"http\");\nhttp.redirect(\"https://example.com/new\", 302);"
- }
- ]
- },
- {
- "id": "share",
- "name": "share",
- "desc": "Create and manage public file share links.",
- "load": "requirelib(\"share\");",
- "functions": [
- {
- "name": "share.shareFile",
- "sig": "share.shareFile(vpath, timeoutSec)",
- "desc": "Create a public share link. timeoutSec=0 means no expiry. Returns the share UUID.",
- "ret": "string (uuid)",
- "example": "requirelib(\"share\");\nvar uuid = share.shareFile(\"user:/report.pdf\", 3600);"
- },
- {
- "name": "share.removeShare",
- "sig": "share.removeShare(shareUUID)",
- "desc": "Remove an existing share link.",
- "ret": "bool",
- "example": "requirelib(\"share\");\nshare.removeShare(uuid);"
- },
- {
- "name": "share.checkShareExists",
- "sig": "share.checkShareExists(shareUUID)",
- "desc": "Return true if the share UUID is still valid.",
- "ret": "bool",
- "example": "requirelib(\"share\");\nif (share.checkShareExists(uuid)) sendOK();"
- },
- {
- "name": "share.fileIsShared",
- "sig": "share.fileIsShared(vpath)",
- "desc": "Return true if the file already has an active share link.",
- "ret": "bool",
- "example": "requirelib(\"share\");\nif (share.fileIsShared(\"user:/report.pdf\")) sendOK();"
- },
- {
- "name": "share.getFileShareUUID",
- "sig": "share.getFileShareUUID(vpath)",
- "desc": "Return the share UUID for the given file, or false if not shared.",
- "ret": "string | false",
- "example": "requirelib(\"share\");\nvar sid = share.getFileShareUUID(\"user:/report.pdf\");"
- }
- ]
- },
- {
- "id": "appdata",
- "name": "appdata",
- "desc": "Read-only access to web-root application data files.",
- "load": "requirelib(\"appdata\");",
- "functions": [
- {
- "name": "appdata.readFile",
- "sig": "appdata.readFile(relativePathFromWebRoot)",
- "desc": "Read a file relative to ./web/. Returns false on error.",
- "ret": "string | false",
- "example": "requirelib(\"appdata\");\nvar conf = appdata.readFile(\"MyApp/config.json\");"
- },
- {
- "name": "appdata.listDir",
- "sig": "appdata.listDir(relativeDirFromWebRoot)",
- "desc": "List files in a directory relative to ./web/. Returns an array of relative paths.",
- "ret": "string[]",
- "example": "requirelib(\"appdata\");\nvar files = appdata.listDir(\"MyApp\");\nsendJSONResp(files);"
- },
- {
- "name": "appdata.getModuleList",
- "sig": "appdata.getModuleList()",
- "desc": "Return an array of registered module objects.",
- "ret": "object[]",
- "example": "requirelib(\"appdata\");\nvar mods = appdata.getModuleList();"
- }
- ]
- },
- {
- "id": "sysinfo",
- "name": "sysinfo",
- "desc": "Real-time system resource information.",
- "load": "requirelib(\"sysinfo\");",
- "functions": [
- {
- "name": "sysinfo.getCPUUsage",
- "sig": "sysinfo.getCPUUsage()",
- "desc": "Return CPU usage as a percentage (0–100).",
- "ret": "number",
- "example": "requirelib(\"sysinfo\");\nvar cpu = sysinfo.getCPUUsage();"
- },
- {
- "name": "sysinfo.getRAMUsage",
- "sig": "sysinfo.getRAMUsage()",
- "desc": "Return {used, total, percent} memory statistics.",
- "ret": "object",
- "example": "requirelib(\"sysinfo\");\nvar ram = sysinfo.getRAMUsage();\nsendJSONResp(ram);"
- },
- {
- "name": "sysinfo.getNetworkUsage",
- "sig": "sysinfo.getNetworkUsage()",
- "desc": "Return {rxRate, txRate, rxTotal, txTotal} in bytes/bytes-per-second.",
- "ret": "object",
- "example": "requirelib(\"sysinfo\");\nvar net = sysinfo.getNetworkUsage();"
- },
- {
- "name": "sysinfo.getDiskInfo",
- "sig": "sysinfo.getDiskInfo()",
- "desc": "Return an array of logical disk info objects.",
- "ret": "object[]",
- "example": "requirelib(\"sysinfo\");\nvar disks = sysinfo.getDiskInfo();\nsendJSONResp(disks);"
- }
- ]
- },
- {
- "id": "ziplib",
- "name": "ziplib",
- "desc": "Archive creation and extraction (zip, tar, tar.gz, gz).",
- "load": "requirelib(\"ziplib\");",
- "functions": [
- {
- "name": "ziplib.extractZipFile",
- "sig": "ziplib.extractZipFile(src, destDir)",
- "desc": "Extract a ZIP archive into destDir.",
- "ret": "bool",
- "example": "requirelib(\"ziplib\");\nziplib.extractZipFile(\"user:/a.zip\", \"user:/out/\");"
- },
- {
- "name": "ziplib.createZipFile",
- "sig": "ziplib.createZipFile(sourcesArrayOrString, outputZip)",
- "desc": "Create a ZIP archive from one or more source paths.",
- "ret": "bool",
- "example": "requirelib(\"ziplib\");\nziplib.createZipFile([\"user:/a.txt\", \"user:/b.txt\"], \"user:/bundle.zip\");"
- },
- {
- "name": "ziplib.extractAnyFile",
- "sig": "ziplib.extractAnyFile(srcArchive, destDir)",
- "desc": "Auto-detect archive format and extract into destDir.",
- "ret": "bool",
- "example": "requirelib(\"ziplib\");\nziplib.extractAnyFile(\"user:/archive.tar.gz\", \"user:/out/\");"
- },
- {
- "name": "ziplib.createAnyZipFile",
- "sig": "ziplib.createAnyZipFile(sourcesArrayOrString, outputPath, format)",
- "desc": "Create an archive in any supported format. format: \"zip\", \"tar\", \"tar.gz\", \"gz\".",
- "ret": "bool",
- "example": "requirelib(\"ziplib\");\nziplib.createAnyZipFile([\"user:/folder\"], \"user:/bundle.tar.gz\", \"tar.gz\");"
- },
- {
- "name": "ziplib.isValidZipFile",
- "sig": "ziplib.isValidZipFile(vpath)",
- "desc": "Return true if the file is a recognisable archive.",
- "ret": "bool",
- "example": "requirelib(\"ziplib\");\nvar ok = ziplib.isValidZipFile(\"user:/a.zip\");"
- },
- {
- "name": "ziplib.listZipFileContents",
- "sig": "ziplib.listZipFileContents(zipPath)",
- "desc": "Return a JSON tree string of the archive's contents.",
- "ret": "string (JSON)",
- "example": "requirelib(\"ziplib\");\nvar tree = JSON.parse(ziplib.listZipFileContents(\"user:/a.zip\"));"
- },
- {
- "name": "ziplib.getFileFromZip",
- "sig": "ziplib.getFileFromZip(zipPath, filePathInZip)",
- "desc": "Extract one file to tmp:/ and return its virtual path.",
- "ret": "string (vpath)",
- "example": "requirelib(\"ziplib\");\nvar tmp = ziplib.getFileFromZip(\"user:/a.zip\", \"docs/readme.txt\");"
- }
- ]
- },
- {
- "id": "websocket",
- "name": "websocket",
- "desc": "Upgrade the HTTP connection to a persistent WebSocket session.",
- "load": "requirelib(\"websocket\");",
- "functions": [
- {
- "name": "websocket.upgrade",
- "sig": "websocket.upgrade(timeoutSec)",
- "desc": "Upgrade to WebSocket. Also overrides delay() with a message-pumping version. Returns false on failure.",
- "ret": "bool",
- "example": "requirelib(\"websocket\");\nif (!websocket.upgrade(120)) exit();\nwebsocket.send(\"Connected!\");"
- },
- {
- "name": "websocket.send",
- "sig": "websocket.send(text)",
- "desc": "Send a text frame to the client. Returns false if the connection is closed.",
- "ret": "bool",
- "example": "websocket.send(\"Hello client\");"
- },
- {
- "name": "websocket.read",
- "sig": "websocket.read(timeoutMs)",
- "desc": "Read next message. Returns string on message, null on timeout (still open), false if closed. Omit timeoutMs to block.",
- "ret": "string | null | false",
- "example": "var msg = websocket.read(5000);\nif (msg === false) { /* closed */ }\nif (msg === null) { /* timeout */ }"
- },
- {
- "name": "websocket.available",
- "sig": "websocket.available()",
- "desc": "Return count of buffered unread messages. Non-blocking.",
- "ret": "number",
- "example": "if (websocket.available() > 0) {\n var msg = websocket.read();\n}"
- },
- {
- "name": "websocket.isClosed",
- "sig": "websocket.isClosed()",
- "desc": "Return true when the connection is no longer active.",
- "ret": "bool",
- "example": "while (!websocket.isClosed()) {\n websocket.send(\"tick\");\n delay(1000);\n}"
- },
- {
- "name": "websocket.onMessage",
- "sig": "websocket.onMessage = function(msg) { ... }",
- "desc": "Assign a callback fired inside delay(). msg = { data, timestamp, type }. Set to null to stop and leave messages in buffer.",
- "ret": "void",
- "example": "var last = \"\";\nwebsocket.onMessage = function(msg) {\n last = msg.data;\n};\nwhile (!websocket.isClosed()) {\n if (last !== \"\") {\n websocket.send(\"Echo: \" + last);\n last = \"\";\n }\n delay(100);\n}"
- },
- {
- "name": "websocket.close",
- "sig": "websocket.close()",
- "desc": "Send a normal-closure frame and close the connection.",
- "ret": "bool",
- "example": "websocket.close();"
- }
- ]
- },
- {
- "id": "scheduler",
- "name": "scheduler",
- "desc": "Register and manage recurring background tasks for a webapp.",
- "load": "requirelib(\"scheduler\");",
- "functions": [
- {
- "name": "scheduler.hasPermission",
- "sig": "scheduler.hasPermission()",
- "desc": "Return true if the current user is allowed to create scheduled tasks.",
- "ret": "bool",
- "example": "requirelib(\"scheduler\");\nif (!scheduler.hasPermission()) sendResp(\"no_permission\");"
- },
- {
- "name": "scheduler.registered",
- "sig": "scheduler.registered(taskName, appName)",
- "desc": "Return true if the task is already registered for this user+app.",
- "ret": "bool",
- "example": "requirelib(\"scheduler\");\nif (scheduler.registered(\"MyApp_Sync\", \"MyApp\")) sendResp(\"already_registered\");"
- },
- {
- "name": "scheduler.register",
- "sig": "scheduler.register(taskName, appName, intervalSecs, description, scriptName)",
- "desc": "Register a new background task. scriptName defaults to \"cron.agi\".",
- "ret": "bool",
- "example": "requirelib(\"scheduler\");\nvar ok = scheduler.register(\"MyApp_Sync\", \"MyApp\", 3600, \"Hourly sync\", \"cron.agi\");"
- },
- {
- "name": "scheduler.unregister",
- "sig": "scheduler.unregister(taskName)",
- "desc": "Remove a registered task.",
- "ret": "bool",
- "example": "requirelib(\"scheduler\");\nscheduler.unregister(\"MyApp_Sync\");"
- }
- ]
- },
- {
- "id": "ffmpeg",
- "name": "ffmpeg",
- "desc": "Media conversion via ffmpeg. Only available when ffmpeg is installed on the host.",
- "load": "requirelib(\"ffmpeg\");",
- "functions": [
- {
- "name": "ffmpeg.convert",
- "sig": "ffmpeg.convert(input, output, compression)",
- "desc": "Generic media conversion.",
- "ret": "bool",
- "example": "requirelib(\"ffmpeg\");\nffmpeg.convert(\"user:/in.mov\", \"user:/out.mp4\", 0);"
- },
- {
- "name": "ffmpeg.videoConvert",
- "sig": "ffmpeg.videoConvert(input, output, resolution, compressionRate, progressFile)",
- "desc": "Convert video to the given resolution. progressFile is a virtual path for JSON progress updates.",
- "ret": "bool",
- "example": "requirelib(\"ffmpeg\");\nffmpeg.videoConvert(\"user:/in.mp4\", \"user:/out.mp4\", \"720p\", 55, \"tmp:/progress.json\");"
- },
- {
- "name": "ffmpeg.audioConvert",
- "sig": "ffmpeg.audioConvert(input, output, sampleRate, progressFile)",
- "desc": "Convert audio to the given sample rate.",
- "ret": "bool",
- "example": "requirelib(\"ffmpeg\");\nffmpeg.audioConvert(\"user:/in.wav\", \"user:/out.mp3\", 44100, \"tmp:/audio_progress.json\");"
- },
- {
- "name": "ffmpeg.imageConvert",
- "sig": "ffmpeg.imageConvert(input, output, scaleFactor, compressionRate)",
- "desc": "Convert/resize an image. scaleFactor 0.5 = 50% size.",
- "ret": "bool",
- "example": "requirelib(\"ffmpeg\");\nffmpeg.imageConvert(\"user:/in.png\", \"user:/out.jpg\", 0.5, 80);"
- }
- ]
- }
- ]
- }
|