UNPKG

lynkr

Version:

Self-hosted LLM gateway and tier-routing proxy for Claude Code, Cursor, and Codex. Routes across Ollama, AWS Bedrock, OpenRouter, Databricks, Azure OpenAI, llama.cpp, and LM Studio with prompt caching, MCP tools, and 60-80% cost savings.

41 lines (32 loc) 1.06 kB
const { appendSessionTurn } = require("./store"); // Cap in-memory history to prevent unbounded growth during long tool loops const MAX_IN_MEMORY_HISTORY = 100; function ensureSessionShape(session) { if (!session) return null; if (!Array.isArray(session.history)) { session.history = []; } if (!session.createdAt) { session.createdAt = Date.now(); } return session; } function appendTurnToSession(session, entry) { const target = ensureSessionShape(session); if (!target) return null; const turn = { ...entry, timestamp: Date.now() }; target.history.push(turn); target.updatedAt = turn.timestamp; // Trim in-memory history if it exceeds the cap if (target.history.length > MAX_IN_MEMORY_HISTORY) { target.history = target.history.slice(-MAX_IN_MEMORY_HISTORY); } // Skip DB write for ephemeral sessions (auto-generated, no client session ID) if (target.id && !target._ephemeral) { appendSessionTurn(target.id, turn, target.metadata ?? {}); } return turn; } module.exports = { appendTurnToSession, };