/** * AgentScript Transformer * * Transforms user-written AgentScript code into safe, executable format: * 1. Wraps code in `async function __ag_main() { ... }` * 2. Transforms `callTool` → `__safe_callTool` * 3. Transforms loops → `__safe_for` / `__safe_forOf` / `__safe_while` * * @packageDocumentation */ import * as acorn from 'acorn'; /** * Configuration for AgentScript transformation */ export interface AgentScriptTransformConfig { /** * Whether to wrap code in async function __ag_main() * Default: true */ wrapInMain?: boolean; /** * Whether to transform callTool → __safe_callTool * Default: true */ transformCallTool?: boolean; /** * Whether to transform loops for runtime safety * Default: true */ transformLoops?: boolean; /** * Prefix for safe runtime functions * Default: '__safe_' */ prefix?: string; /** * Additional identifiers to transform * Default: [] */ additionalIdentifiers?: string[]; /** * Parse options for acorn */ parseOptions?: acorn.Options; } /** * Transform AgentScript code for safe execution * * **Transformation Steps:** * 1. Parse the code to AST * 2. Wrap in `async function __ag_main() { ... }` (if enabled) * 3. Transform `callTool` → `__safe_callTool` (if enabled) * 4. Transform loops → `__safe_for` / `__safe_forOf` (if enabled) * 5. Generate transformed code * * **Example:** * ```javascript * // Input: * const users = await callTool('users:list', {}); * for (const user of users.items) { * console.log(user.name); * } * * // Output: * async function __ag_main() { * const users = await __safe_callTool('users:list', {}); * for (const user of __safe_forOf(users.items)) { * console.log(user.name); * } * } * ``` * * @param code AgentScript code to transform * @param config Transformation configuration * @returns Transformed code ready for safe execution */ export declare function transformAgentScript(code: string, config?: AgentScriptTransformConfig): string; /** * Check if code is already wrapped in __ag_main * * @param code Code to check * @returns true if code is already wrapped */ export declare function isWrappedInMain(code: string): boolean; /** * Extract code from __ag_main wrapper (if present) * * @param code Code that may be wrapped * @returns Unwrapped code */ export declare function unwrapFromMain(code: string): string;