AI, HTTP & Tools
## g.http.* — HTTP
Section titled “## g.http.* — HTTP”| Method | Signature | Description |
|---|---|---|
g.http.makeHttpRequest | (options) → Promise<HttpResponse> | Make an HTTP request |
HttpRequestOptions:
{ url: string // required method?: string // "GET" (default), "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS" body?: string headers?: Record<string, string> timeout?: number // milliseconds}HttpResponse:
{ status: number statusText: string body: string headers: Record<string, string>}## g.llm.* — LLM
Section titled “## g.llm.* — LLM”Requires an LLM provider to be configured.
| Method | Signature | Description |
|---|---|---|
g.llm.promptLocalLlm | (model, prompt, options?) → Promise<string> | Send a prompt to the configured LLM |
g.llm.abortLocalLlm | () | Cancel an in-progress LLM request |
g.llm.getLocalLlmModels | () → Promise<OllamaModelInfo[]> | List available models |
OllamaOptions:
{ timeout?: number // milliseconds image?: string // base64-encoded image for vision models}## g.secrets.* — Secrets
Section titled “## g.secrets.* — Secrets”See Secrets for full details.
| Method | Signature | Description |
|---|---|---|
g.secrets.getSecret | (secretName) → Promise<string> | Get a decrypted secret value |
OcrOptions (for g.page.ocr):
{ x?: number y?: number width?: number height?: number lang?: string // default: "eng" browserTabId?: string}## Top-level g.* — Utility
Section titled “## Top-level g.* — Utility”| Method | Signature | Description |
|---|---|---|
g.log | (message) → void | Write to the Console pane |
g.wait | (milliseconds?) → Promise | Sleep for a duration |
g.generateApiDocs | (outputDirectory?) → string | Generate scripting-api.d.ts |
g.generateApiDocs() is an advanced TypeScript-only helper. For the full scripting support bundle, use Tools > Developer > Generate Scripting Support Files… to generate TypeScript definitions, Lua and Janet guides, workspace LLM instructions, and TypeScript authoring scaffold files.
## g.tool.* — Tool Context
Section titled “## g.tool.* — Tool Context”Available when a script is invoked as a custom MCP tool.
| Property | Type | Description |
|---|---|---|
g.tool.args | any | null | Parameters passed by the AI agent (null if not invoked as a tool) |
## Standard Library Globals
Section titled “## Standard Library Globals”These are top-level globals available in both JavaScript and Lua engines — not under g.*.
URL / URLSearchParams
Section titled “URL / URLSearchParams”WHATWG URL API backed by System.Uri. In JS use new URL(...), in Lua use URL(...) (returns a table).
URL properties: href, origin, protocol, hostname, host, port, pathname, search, hash, username, password, searchParams
const url = new URL("https://example.com/path?q=hello&page=2");const q = url.searchParams.get("q"); // "hello"g.log(url.hostname); // "example.com"g.log(url.pathname); // "/path"
// Relative URL resolutionconst api = new URL("/api/data", "https://example.com");g.log(api.href); // "https://example.com/api/data"btoa() / atob()
Section titled “btoa() / atob()”Base64 encode and decode (UTF-8).
const encoded = btoa("Hello, World!"); // "SGVsbG8sIFdvcmxkIQ=="const decoded = atob(encoded); // "Hello, World!"crypto.randomUUID()
Section titled “crypto.randomUUID()”Generate a UUID v4 string.
const id = crypto.randomUUID(); // "3b241101-e2bb-4d7a-8613-e9a3fdc1e2b3"## g.tts.* — Text-to-Speech
Section titled “## g.tts.* — Text-to-Speech”Windows Speech Synthesis. Always available (not workspace-scoped).
| Method | Signature | Async | Description |
|---|---|---|---|
speak | (text, options?) → Promise | Yes | Speak text aloud |
getVoices | () → string[] | No | List available voice names |
stop | () | No | Stop current speech |
SpeakOptions:
{ voice?: string // e.g., "Microsoft David" rate?: number // -10 to 10, default 0}## g.stt.* — Speech-to-Text
Section titled “## g.stt.* — Speech-to-Text”The local Whisper STT engine allows scripts to listen for user voice commands or transcribe audio files. All processing happens locally on your CPU.
| Method | Signature | Async | Description |
|---|---|---|---|
listen | (ms) → Promise<string> | Yes | Record audio from the selected microphone for a duration (in milliseconds) and return the transcribed text. |
transcribeFile | (path) → Promise<string> | Yes | Read an existing .wav file from disk and return its transcribed text. |
Example
Section titled “Example”async function main() { g.log("Listening for 5 seconds..."); try { const text = await g.stt.listen(5000); g.log("You said: " + text);
if (text.toLowerCase().includes("hello")) { g.log("Hello to you too!"); } } catch (e) { g.log("STT Error: " + e.message); }}