WebService
WebService serves static files from one or more local directories, each mounted at a URL route prefix. It supports HTTP Basic Auth, extension allowlists and blocklists, file size limits, CORS, directory browsing, and optional SSL/TLS. Use it when an agent needs to serve supporting assets such as audio files, images, or prompts from the same process.
Every route except /health requires HTTP Basic Auth, and start() throws until credentials are configured. Supply them with the basicAuth option, the config file’s security.auth.basic, or the SWML_BASIC_AUTH_USER and SWML_BASIC_AUTH_PASSWORD environment variables.
Constructor
options
Configuration object. Every field is optional. Explicit options override values from the config file.
options.port
Port to bind to.
options.directories
Map of URL route prefixes to local directory paths.
options.basicAuth
Basic auth credentials as [username, password]. Falls back to the config file’s security.auth.basic, then to the SWML_BASIC_AUTH_USER and SWML_BASIC_AUTH_PASSWORD environment variables. Every route except /health requires them. If no password is configured from any of these (an empty one doesn’t count), the service refuses every request and start() throws.
options.configFile
Path to a JSON config file.
options.enableDirectoryBrowsing
Serve directory listings and fall back to index.html.
options.allowedExtensions
Allowlist of file extensions, for example ['.html', '.css']. All extensions are allowed when omitted.
options.blockedExtensions
Blocklist of file extensions or names. An entry is also refused as the name of any directory on the path below the mount. Whatever this holds, a path with a component below the mount that starts with a dot, other than .well-known, is never served.
options.maxFileSize
Maximum file size in bytes (100 MB by default).
options.enableCors
Enable CORS.
options.ssl
SSL/TLS configuration. See SslConfig for the fields.
Properties
port
Port the service binds to.
enableDirectoryBrowsing
Whether directory listings are enabled.
maxFileSize
Maximum file size in bytes that will be served.
enableCors
Whether CORS is enabled.
allowedExtensions
Allowlist of file extensions, or null to allow all (subject to the blocklist).
blockedExtensions
Blocklist of file extensions and file names.
directories
Map of URL route prefixes to local directory paths.
sslConfig
The SslConfig instance used by this service, for inspecting SSL settings after construction. Read-only.