JavaScript Runtime Specification for Agents
This document specifies the available objects and functions in the sandboxed JavaScript (ES2023) environment used for script execution. This skill does not have its own tool; it provides the instructions for the global JavaScript tool.
Core Runtime Rules
Go-to-JS Bridge Naming Convention
[!IMPORTANT]
Methods and properties exported from the Go environment into JavaScript must be called using Uppercase initials (e.g., ReadFile, SetURL). JavaScript-native or user-defined functions follow standard camelCase.
Global Functions and Objects
All methods are synchronous and can be called directly.
Logging and Output
print(...args): Logs arguments to the session output (Use this instead of console`).
console: Standard logging object with methods (Not recommended to use, use print instead):
log(...args), info(...args), warn(...args), error(...args), debug(...args).
Virtual File System: VirtualFiles
The VirtualFiles object provides access to the private session storage.
- File Operations:
ReadFile(path): Returns Uint8Array.
ReadStrFile(path): Returns string.
WriteFile(path, Uint8Array): Writes binary data.
WriteStrFile(path, string): Writes string data.
DeleteFile(path): Removes a file.
Exists(path): Returns boolean.
Info(path): Returns metadata {Name, Size, IsDir}.
- Directory Operations:
ReadDir(path): Returns array of file info objects {Name, Size, IsDir}.
CreateDir(path): Creates a directory.
DeleteDir(path): Removes a directory.
- Path Utilities:
Join(...segments): Joins path segments.
Split(path): Splits path into segments.
Parent(path): Returns parent directory.
Name(path): Returns file name.
HTTP Client: HttpRequest
Network requests are constructed using a fluent builder.
- HttpRequest Builder Methods:
SetURL(url): Sets the URL.
SetMethod(method): Sets the HTTP method.
SetHeader(key, ...values): Sets a header.
AddHeader(key, ...values): Adds a header.
RemoveHeader(key): Removes a header.
SetBody(Uint8Array): Sets the request body.
SetBodyString(string): Sets the request body as a string.
SetBodyObj(obj): Sets the request body as an object.
SetBodyFormData(HttpFormData): Sets the request body as form data.
- Execution Methods:
Fetch(): Executes and returns HttpResponse.
- Shorthands:
Get(), Post(), Put(), Delete(), Patch(), Head(), Options().
- HttpResponse Object:
Status (string) - The status of the response.
StatusCode (int) - The status code of the response.
Header (object) - The headers of the response.
BodyBytes() (Uint8Array) - The body of the response as bytes.
BodyString() (string) - The body of the response as a string.
CloseBody() - Closes stream (automatic on body read).
Form Data: HttpFormData
AddField(key, value)
AddFile(key, filename, Uint8Array)
1---2name: javascript3description: Technical reference of the JavaScript runtime environment for agents.4---56# JavaScript Runtime Specification for Agents78This document specifies the available objects and functions in the sandboxed JavaScript (ES2023) environment used for script execution. This skill does not have its own tool; it provides the instructions for the global JavaScript tool.910## Core Runtime Rules1112### Go-to-JS Bridge Naming Convention1314> [!IMPORTANT]15> Methods and properties exported from the Go environment into JavaScript **must** be called using **Uppercase** initials (e.g., `ReadFile`, `SetURL`). JavaScript-native or user-defined functions follow standard camelCase.1617## Global Functions and Objects1819All methods are synchronous and can be called directly.2021### Logging and Output2223- `print(...args)`: Logs arguments to the session output (Use this instead of console`).24- `console`: Standard logging object with methods (Not recommended to use, use `print` instead):25 - `log(...args)`, `info(...args)`, `warn(...args)`, `error(...args)`, `debug(...args)`.2627### Virtual File System: `VirtualFiles`2829The `VirtualFiles` object provides access to the private session storage.3031- **File Operations**:32 - `ReadFile(path)`: Returns `Uint8Array`.33 - `ReadStrFile(path)`: Returns `string`.34 - `WriteFile(path, Uint8Array)`: Writes binary data.35 - `WriteStrFile(path, string)`: Writes string data.36 - `DeleteFile(path)`: Removes a file.37 - `Exists(path)`: Returns `boolean`.38 - `Info(path)`: Returns metadata {Name, Size, IsDir}.39- **Directory Operations**:40 - `ReadDir(path)`: Returns array of file info objects {Name, Size, IsDir}.41 - `CreateDir(path)`: Creates a directory.42 - `DeleteDir(path)`: Removes a directory.43- **Path Utilities**:44 - `Join(...segments)`: Joins path segments.45 - `Split(path)`: Splits path into segments.46 - `Parent(path)`: Returns parent directory.47 - `Name(path)`: Returns file name.4849### HTTP Client: `HttpRequest`5051Network requests are constructed using a fluent builder.5253- **HttpRequest Builder Methods**:54 - `SetURL(url)`: Sets the URL.55 - `SetMethod(method)`: Sets the HTTP method.56 - `SetHeader(key, ...values)`: Sets a header.57 - `AddHeader(key, ...values)`: Adds a header.58 - `RemoveHeader(key)`: Removes a header.59 - `SetBody(Uint8Array)`: Sets the request body.60 - `SetBodyString(string)`: Sets the request body as a string.61 - `SetBodyObj(obj)`: Sets the request body as an object.62 - `SetBodyFormData(HttpFormData)`: Sets the request body as form data.63- **Execution Methods**:64 - `Fetch()`: Executes and returns `HttpResponse`.65 - Shorthands: `Get()`, `Post()`, `Put()`, `Delete()`, `Patch()`, `Head()`, `Options()`.66- **HttpResponse Object**:67 - `Status` (string) - The status of the response.68 - `StatusCode` (int) - The status code of the response.69 - `Header` (object) - The headers of the response.70 - `BodyBytes()` (Uint8Array) - The body of the response as bytes.71 - `BodyString()` (string) - The body of the response as a string.72 - `CloseBody()` - Closes stream (automatic on body read).7374### Form Data: `HttpFormData`7576- `AddField(key, value)`77- `AddFile(key, filename, Uint8Array)`