Skip to main content

Module wasm

Module wasm 

Source
Expand description

WebAssembly bindings for the AgentScript parser.

This module provides JavaScript-accessible functions for parsing AgentScript source code and working with the resulting AST.

§Example (JavaScript)

import init, { parse_agent, parse_agent_to_json, serialize_agent } from './sf_agentscript.js';

await init();

// Parse to JS object
const ast = parse_agent(source);
console.log(ast.config.agent_name);

// Or parse to JSON string
const json = parse_agent_to_json(source);

// Serialize AST back to source
const regenerated = serialize_agent(ast);

Functions§

init
Initialize panic hook for better error messages in the browser console.
normalize_agent
Parse AgentScript source, then serialize it back.
parse_agent
Parse AgentScript source code and return the AST as a JavaScript object.
parse_agent_to_json
Parse AgentScript source code and return the AST as a JSON string.
serialize_agent
Serialize an AST back to AgentScript source code.
validate_agent
Validate AgentScript source code without returning the full AST.
validate_agent_semantic
Validate AgentScript source code and return structured errors and warnings.
version
Get the version of the parser.