Skip to content

自定义适配器

所有核心能力可插拔。

自定义解析器

typescript
import { ParserRegistry } from '@sciexpr/parser'

class AsciiMathParser implements IParser {
  id = 'asciimath'; formats = ['asciimath']
  canParse(input) { return input.includes('`') }
  parse(input) { /* 实现你的逻辑 */ }
}

new ParserRegistry().register(new AsciiMathParser())

自定义渲染器

typescript
import { RendererRegistry } from '@sciexpr/renderer'

class TikZRenderer implements IRenderer {
  id = 'tikz'; outputFormat = 'latex' as const
  render(ast) { return { value: '\\begin{tikzpicture}...', format: 'latex' } }
}

registry.register(new TikZRenderer())

自定义验证器

typescript
class PhysicsValidator implements IValidator {
  id = 'physics'; name = 'Physics'
  validate(node) { return { valid: true, errors: [], warnings: [] } }
}

自定义 AI Provider

typescript
class LocalLLMProvider implements IAICompletionProvider {
  id = 'local-llm'; name = 'Local LLM'
  async complete(ctx) {
    const res = await fetch('http://localhost:11434/api/chat', {
      body: JSON.stringify({ prompt: ctx.currentInput }),
    })
    return res.json()
  }
}

基于 MIT 协议发布