Skip to content

PromptScript API


browser-compiler/src

Browser-compatible PromptScript compiler.

Provides in-memory compilation for browser environments (playgrounds, web editors). Uses a virtual file system instead of Node.js fs operations.

Example

import { compile, VirtualFileSystem, getBundledRegistryFiles } from '@promptscript/browser-compiler';

// Create virtual file system with project files
const files = new Map([
  ['project.prs', `
    @meta { id: "my-project" syntax: "1.0.0" }
    @identity { """You are a helpful assistant.""" }
  `],
]);

// Optionally add bundled registry files for @inherit support
const registry = getBundledRegistryFiles();
for (const [path, content] of Object.entries(registry)) {
  files.set(path, content);
}

// Compile
const result = await compile(files, 'project.prs');

if (result.success) {
  for (const [outputPath, output] of result.outputs) {
    console.log(`${outputPath}:`, output.content);
  }
} else {
  console.error('Compilation errors:', result.errors);
}

Classes

Interfaces

Type Aliases

Variables

Functions