Skip to content

@mokalabs/core

Terminal window
npm install @mokalabs/core

@mokalabs/core is the headless engine behind the UI: providers, MCP client manager, skills, the agent loop and the event bus.

import { MokaEngine, ConfigStore, parseConfig } from "@mokalabs/core";
// From a file (changes via setConfig are persisted)…
const store = new ConfigStore("./moka.json");
const { config } = await store.load();
const engine = new MokaEngine({ config, store });
// …or in memory
const inMemory = new MokaEngine({ config: parseConfig({ llms: [/* … */], workspaces: [/* … */] }) });
// Observe everything
engine.bus.subscribe((e) => console.log(`[${e.kind}] ${e.title}`));
// Run a turn
const history = [{ role: "user", content: "Roll 2d20" }];
for await (const chunk of engine.chat({ messages: history })) {
if (chunk.type === "text") process.stdout.write(chunk.text);
if (chunk.type === "tool-call") console.log("\n→", chunk.tool, chunk.input);
if (chunk.type === "finish") history.push(...chunk.messages); // keep for the next turn
}
await engine.close(); // stops stdio servers
Method
chat({messages, workspaceId?, llmId?, signal?})Async iterator of chat chunks
getConfig() / setConfig(next)Read / validate + persist config
workspace(id?) / llm(id?)Resolve a workspace or model profile
connectAll(workspaceId?)Connect servers eagerly
loadSkills(ids?)Load skills from disk
testLlm(profile) / listModels(profile)Connectivity helpers
mcpThe McpManager (ensure, callTool, readResource, getPrompt, states, …)
busThe EventBus (subscribe, history, clear)
Export
parseConfig, mokaConfigSchema, mokaJsonSchema()Validate configs; JSON Schema for editors
resolveSecret, redactConfigenv:/${} resolution; safe-to-share copies
createModel(profile), PROVIDER_PRESETS, detectProfiles(env)Providers
loadSkill, discoverSkills, parseFrontmatterSkills
importMcpJson, exportMcpJson, exportCodeInterop with Claude/Cursor/VS Code configs; code generation
parseA2ui, detectResultUi, renderUiToMessages, toolUiResourceUriGenerative UI helpers

Because MokaEngine accepts any OpenAI-compatible base URL, you can run agent tests against a local mock model (or a cheap real one) and assert on tool calls:

const calls: string[] = [];
for await (const c of engine.chat({ messages: [{ role: "user", content: "What's 6*7?" }] })) {
if (c.type === "tool-call") calls.push(c.tool);
}
expect(calls).toContain("calculate");