@terreno/ai
v57.6.1
Published
Provider-agnostic AI service with streaming chat, request logging, and admin tools — part of Terreno, the batteries-included TypeScript framework for universal apps.
Readme
@terreno/ai
AI service layer for Terreno apps - GPT chat, request logging, and admin tools.
AI service layer for Terreno backends — provider-agnostic chat, request logging, GPT history, projects, file uploads, MCP tools, and optional Langfuse integration.
Install
bun add @terreno/ai @terreno/api mongooseAlso install a Vercel AI SDK provider in your app (e.g. bun add @ai-sdk/google).
Quick start
import {TerrenoApp} from "@terreno/api";
import {AiApp, AIService} from "@terreno/ai";
import {google} from "@ai-sdk/google";
import {User} from "./models/user";
const aiService = new AIService({model: google("gemini-2.5-flash")});
new TerrenoApp({userModel: User})
.register(new AiApp({aiService}))
.start();This mounts GPT chat (POST /gpt/prompt), history CRUD (/gpt/histories), projects, and the admin AI request explorer. Add LangfuseApp, FileStorageService, and MCPService when you need those features.
What's included
AIService— text, streaming, structured JSON, remix, summary, and translation helpersAiApp— TerrenoPlugin that registers all AI routes in one call- Mongoose models:
AIRequest,GptHistory,Project,FileAttachment - Route registrars:
addGptRoutes,addGptHistoryRoutes,addProjectRoutes,addFileRoutes,addMcpRoutes,addAiRequestsExplorerRoutes LangfuseApp— optional Langfuse tracing and admin UI routesFileStorageService— GCS uploads with signed URLsMCPService— SSE MCP client for tool callinggetMCPTools— wrap registeredmodelRouterMCP tools as Vercel AI SDK tools for in-processstreamText/generateText- Gemini and Vertex helpers:
listGeminiApiModels,createVertexProvider
Documentation
Full API reference: docs/reference/ai.md
License and Contributing
Licensed under the MIT License. See CONTRIBUTING.md for contribution guidelines.
