/// import { computed, Default, generateText, ifElse, NAME, pattern, UI, type VNode, } from "commontools"; // ===== Types ===== type SummaryInput = { topic?: Default; context?: Default, Record>; }; type SummaryOutput = { [NAME]: string; [UI]: VNode; topic: string; summary: string; pending: boolean; }; // ===== Pattern ===== /** * Generates a concise summary of provided context using an LLM. * Designed as "suggestion fuel" - a lightweight utility pattern that can be * instantiated across many different contexts. */ const Summary = pattern(({ topic, context }) => { // Build the prompt dynamically based on topic and context const prompt = computed(() => { const t = topic || "the following"; return `Please provide a concise, well-structured summary of ${t}`; }); // Generate the summary const response = generateText({ system: "You are a helpful assistant that creates clear, concise summaries. Focus on the key points and structure your response in a readable way.", prompt, context, }); return { [NAME]: computed(() => (topic ? `Summary: ${topic}` : "Summary")), [UI]: ( {computed(() => topic || "Summary")} {ifElse( response.pending,
Generating summary...
,
{response.result}
, )}
), topic, summary: computed(() => response.result || ""), pending: response.pending, }; }); export default Summary;