@zooly/glow-server provides the server-side logic for the Glow chat system: streaming LLM responses, tool execution, cache lookup, context switching, and chat lifecycle management.
@zooly/glow-serverpackages/glow-server| Export | Purpose |
|---|---|
handleGlowChatStream | Entry point for streaming; validates session, delegates to cache/core, returns stream response |
handleGlowChatCore | Main LLM flow: prompts, tools, streamText |
handleGlowChatWithCache | Wraps core; checks question cache when enabled |
handleGlowChatGenerate | Generate flow: getOrCreateGlowChat + handleGlowChatWithCache + stream |
| Export | Purpose |
|---|---|
getOrCreateGlowChat | Create new chat or return existing by chatId |
getGlowChatData | Load glowChat + glowSettings by glowChatId |
createGlowChat | Create chat with options |
createNewGlowChat | Create new chat for a flow slug |
| Export | Purpose |
|---|---|
changeChatContext | Switch chat to new flow by slug |
returnToContext | Return to previous flow |
buildContextStack | Build context from tool call logs |
getCurrentNodeTools | Resolve tools for current node |
getToolsList | All tools for a flow |
executeApiTool | Call external API for API tools |
toolsBase | Base tools (moveToNodeId, changeChatContext, returnToContext) |
| Export | Purpose |
|---|---|
getGlowChatSystemPrompt | Flow-level system prompt |
getGlowChatInstructionsSystemPrompt | Node-level instructions |
getFirstNodeMetadata | First node metadata from flow |
getCurrentNodeMetadata | Current node metadata |
moveToNodeIdInstructions | Instructions for moveToNodeId tool |
| Export | Purpose |
|---|---|
extractQuestionFromMessage | Extract question text for cache lookup |
transformNodesMetadata, transformField, transformFields | Field transformers |
generateZodSchema | Generate Zod schema from tool fields |
defaultOnFinish | Default onFinish handler |
prepareStepHandler | Prepare step handler |
onStepFinishHandler | Step finish handler |
saveMessageData | Save message data |
| Export | Purpose |
|---|---|
defaultModel | Default model config (openai/gpt-4.1) |
ai - AI SDK (streamText, convertToModelMessages, etc.)@zooly/db - Database access, cache, embeddings@zooly/types - GlowChat, GlowSettings, GlowTool, etc.@zooly/util - extractQuestionFromMessage@zooly/llm-mock - Mock LLM for testingnext - Request typesnext-auth - Session typeszod - Schema validationuuid - ID generationimport { handleGlowChatStream } from "@zooly/glow-server";
export async function POST(request: Request) {
const session = await getServerSession(authOptions);
return handleGlowChatStream(request, session ?? undefined);
}
import { getOrCreateGlowChat } from "@zooly/glow-server";
const { glowChat, glowSettings } = await getOrCreateGlowChat({
chatId: "my-chat-id",
glowSlug: "backstage-mini-app",
restart: false,
});
See App Integration for full integration steps.