import { taskModelCompletion } from './task-model.js';

const SYSTEM_PROMPT =
  'Summarize this conversation in one sentence, 15 words max. No quotes, no prefix.';

const MAX_INPUT_CHARS = 1000;

export async function oneLineSummary(
  messages: Array<{ role: string; content: string }>,
): Promise<string> {
  const lastPairs = messages.slice(-6);
  let input = lastPairs
    .map((m) => `${m.role}: ${m.content}`)
    .join('\n');
  if (input.length > MAX_INPUT_CHARS) {
    input = input.slice(0, MAX_INPUT_CHARS);
  }
  return taskModelCompletion({
    system: SYSTEM_PROMPT,
    user: input,
    maxTokens: 30,
    temperature: 0.3,
  });
}
