// src/interfaces/chat-turn.ts // Copyright (C) 2026 Rob Colbert // Licensed under the Apache License, Version 2.0 export enum ChatTurnStatus { Processing = "processing", Finished = "finished", Error = "error", } export interface IChatTurnStats { toolCallCount: number; // total number of tool functions called this turn inputTokens: number; // total number of input tokens processed this turn thinkingTokenCount: number; // total number of thinking tokens generated this turn responseTokens: number; // total number of response/output tokens generated this turn durationMs: number; // total turn runtime in seconds durationLabel: string; // total turn runtime as hh:mm:ss } export interface IChatToolCall { name: string; // tool function name being called parameters: string; // JSON.stringify of input parameters response: string; // the tool's response } export interface IChatSubagentProcess { prompt: string; thinking?: string; response: string; toolCalls: IChatToolCall[]; stats: IChatTurnStats; } /** * A chat turn is a single prompt/response pair with tool call accounting. It * stores all data generated by one run of the Agentic Workflow Loop by a Gadget * Drone process. */ export interface IChatTurn extends Document { _id: Types.ObjectId; createdAt: Date; user: IUser | Types.ObjectId; project: IProject | Types.ObjectId; session: IChatSession | Types.ObjectId; provider: IAiProvider | Types.ObjectId; llm: string; // id/name of the model used to process the prompt mode: ChatSessionMode; // session mode for this turn/prompt status: ChatTurnStatus; prompt: string; thinking?: string; response?: string; toolCalls: IChatToolCall[]; subagents: IChatSubagentProcess[]; // subagents used while processing this turn stats: IChatTurnStats; }