"""Transcript distill intern — compress session transcript into structured action-list.""" from __future__ import annotations from pathlib import Path from typing import Any from .base import BlockedByPolicy, Intern, InternResponse class TranscriptDistill(Intern): id = "transcript_distill" description = "Compress a session transcript/log into a structured action-list." def run(self, paths: list[str], question: str = "Extract action items, decisions, and unresolved questions.", **kwargs: Any) -> InternResponse | BlockedByPolicy: contents: list[str] = [] for p in paths: text = Path(p).read_text(encoding="utf-8", errors="replace") contents.append(f"--- {p} ---\n{text}") combined = "\n\n".join(contents) prompt = f"Transcript:\n{combined}\n\nTask: {question}" if self.client is None: return InternResponse(text="No client configured", usage={}) extra_body = kwargs.get("extra_body", {}) resp = self.client.chat.completions.create( model=self.model or "deepseek-v4-flash", messages=[ {"role": "system", "content": self.system_prompt}, {"role": "user", "content": prompt}, ], max_tokens=kwargs.get("max_tokens", self.max_tokens), temperature=self.temperature, extra_body=extra_body if extra_body else None, ) choice = resp.choices[0] return InternResponse( text=choice.message.content or "", usage={ "tokens_in": resp.usage.prompt_tokens if resp.usage else 0, "tokens_out": resp.usage.completion_tokens if resp.usage else 0, }, )