npm.io
0.0.5 • Published 2 weeks ago

@assistant-ui/x-generative-compiler

Licence
MIT
Version
0.0.5
Deps
5
Size
186 kB
Vulns
0
Weekly
699

@assistant-ui/x-generative-compiler

Internal package. Not meant for direct use. Use a build integration such as @assistant-ui/next or @assistant-ui/vite.

The framework-agnostic "use generative" compiler. It takes a module that colocates a tool's schema, its server-only execute, and its client-only render, and rewrites it for a single build target:

  • client — keeps render and any "use client" execute (frontend tools), drops backend execute and humanTool() sentinels, and stamps each tool's inferred type.
  • server — keeps the backend execute (importing server-only), drops render, and omits externally-defined backend tools marked with externalTool().

The marker functions a "use generative" file imports — defineToolkit and humanTool — live in @assistant-ui/core/react (re-exported from @assistant-ui/react). This package only recognizes them by name and strips them at build time.

API

import {
  compileGenerative,
  isGenerativeModule,
  GenerativeCompileError,
  DIRECTIVE,
  type Target,
} from "@assistant-ui/x-generative-compiler";

if (isGenerativeModule(code)) {
  const { code: out, map } = compileGenerative(code, {
    target: "server", // or "client"
    filename,
    sourceMaps: true,
  });
}

Keywords