@platanai/core
v0.7.0
Published
Agent-driven image generation and editing toolkit for platan.ai.
Readme
@platanai/core
Agent orchestration, provider ports, and Zod schemas for platan.ai. This package is the library the @platanai/cli is built on. Most users want the CLI, not this package directly — consume @platanai/core when you're embedding the agent or its image tools in your own Node app.
What's inside
- Config loader — walks up from cwd to find
platanai.config.{ts,mjs,js}, validates with Zod, returns a typedLoadedConfig. - Provider ports + adapters —
ImageProvider(generate/edit) andTextProvider(JSON output) with first-party Gemini + OpenAI adapters behind simple registries. - Agent runtime —
runChatTurn,routeIntent,createAgentRuntime. Transport-agnostic — HTTP/CLI/desktop all wrap these. - Image tools — pure-function sharp wrappers:
flipHorizontal,resizeImage,removeBackground,trimImage,tintImage, etc. - Storage ports —
SessionStore+ImageStorewith in-memory and filesystem adapters. - Browser-safe schemas — import from
@platanai/core/schemasin frontend code (nosharpor server-only deps pulled in).
Install
npm install @platanai/coreQuick usage
import {
createAgentRuntime,
createImageProviderGetter,
createIntentRouterGetter,
FsImageStore,
InMemorySessionStore,
loadConfig,
} from "@platanai/core";
const config = await loadConfig();
const runtime = createAgentRuntime({
sessions: new InMemorySessionStore(),
images: new FsImageStore(),
});
const getImageProvider = createImageProviderGetter(config);
const getIntentRouter = createIntentRouterGetter(config);
const session = runtime.createSession();
await runtime.runChatTurn({
intentRouter: getIntentRouter(),
imageProvider: getImageProvider(),
sessionId: session.id,
message: "a pixel art sword",
onEvent: (ev) => console.log(ev),
imageUrl: (sid, iid) => `/img/${sid}/${iid}`,
});Adding a new LLM provider
Drop an adapter in adapters/<vendor>-image-provider.ts (or <vendor>-text-provider.ts), add a case to the matching registry switch, and widen the model union in config.schema.ts. Config users pick it via:
providers: {
image: { provider: "anthropic", model: "...", apiKey: process.env... },
}Supported today: gemini, openai.
Browser-safe schemas
import {
PublicLoadedConfigSchema,
ToolCallSchema,
} from "@platanai/core/schemas";This entry has no server-only dependencies — safe to import from a Vite/Webpack bundle.
Links
License
Apache-2.0.
