Skip to content

AI-Text (ghost-text, correct, translate, rewrite)

Server side behind the AiTextField/AiTextArea widgets (kumiko-framework/renderer-web). Mounts the real ai-text feature — no extra business logic here, the feature already is the complete API surface the widgets call.

  • One handler, four modesai-text:query:run takes a discriminated union payload (complete | correct | translate | rewrite); the widget picks the mode, the server picks the prompt.
  • Mounting the real feature — this recipe requires ai-text and an LLM provider plugin for ai-foundation (a mock in the integration test, a real provider — Anthropic, OpenAI-compatible — in production).
  • Cap + audit come for freeai-text enforces a per-tenant monthly request cap and writes a user-attributed audit row per call; nothing extra to wire up in a consuming app.

ai-text requires ai-foundation (provider host) and cap-counter. Mount an LLM provider plugin (ai-provider-anthropic, ai-provider-openai-compat, or a mock in tests) alongside. The integration test under src/__tests__/ boots that exact stack against real Postgres + Redis and scripts the provider — full exhaustive coverage (cap-exceeded, refusal, audit attribution) lives in packages/ai-text/src/__tests__/; this recipe just proves the sample composition mounts and runs.

Terminal window
bun --env-file=../.env test --config=bunfig.integration.toml samples/recipes/ai-text

The feature entry point — embedded straight from the source file, so the code here is exactly what runs. Multi-file samples keep their remaining files next to it on GitHub (link below):

// AI-Text Sample
// Shows how an app mounts the real `ai-text` feature (kumiko-enterprise/
// packages/ai-text) — the server side behind the AiTextField/AiTextArea
// widgets (kumiko-framework/renderer-web). No extra business logic here:
// `ai-text` already is the complete API surface the widgets call
// (`ai-text:query:run`, discriminated on mode: complete/correct/translate/
// rewrite). An app just requires it alongside a provider plugin for
// ai-foundation (see the integration test for the mock-provider wiring).
import { aiTextFeature } from "@cosmicdriftgamestudio/kumiko-ai-text";
export { aiTextFeature };

Enterprise recipe — samples/recipes/ai-text/src/feature.ts in the private kumiko-enterprise workspace.