import { p as resolveDefaultModelForAgent } from "../model-selection-DCVjDyLz.js";
import { r as logVerbose } from "../globals-D7B2Z7Cq.js";
import { t as requireApiKey } from "../model-auth-runtime-shared-dZ8tvB7w.js";
import { a as isSilentReplyText, n as SILENT_REPLY_TOKEN, t as HEARTBEAT_TOKEN } from "../tokens-YO2YMbmh.js";
import { n as HEARTBEAT_PROMPT, o as resolveHeartbeatPrompt, s as stripHeartbeatToken, t as DEFAULT_HEARTBEAT_ACK_MAX_CHARS } from "../heartbeat-FoYjVBnE.js";
import { r as getApiKeyForModel } from "../model-auth-BqWY8X0_.js";
import { a as chunkText, c as resolveTextChunkLimit, i as chunkMarkdownTextWithMode, o as chunkTextWithMode, r as chunkMarkdownText, s as resolveChunkMode } from "../chunk-B4_1DzFc.js";
import { a as createReplyReferencePlanner } from "../reply-threading-_Y4OCdgb.js";
import { n as resolveModelAsync } from "../model-ULj-XWPO.js";
import { n as isAbortRequestText } from "../abort-primitives-s9s-zEQw.js";
import { a as createReplyDispatcher, l as resetInboundDedupe, n as dispatchInboundMessageWithBufferedDispatcher, o as createReplyDispatcherWithTyping, r as dispatchInboundMessageWithDispatcher, t as dispatchInboundMessage } from "../dispatch-CwAj1R2j.js";
import { t as finalizeInboundContext } from "../inbound-context-D7yXPuCs.js";
import { n as resolveInboundDebounceMs, t as createInboundDebouncer } from "../inbound-debounce-CE7zvWF0.js";
import { n as dispatchReplyWithDispatcher, t as dispatchReplyWithBufferedBlockDispatcher } from "../provider-dispatcher-CdV5Aq_c.js";
import { n as parseActivationCommand, t as normalizeGroupActivation } from "../group-activation-B2Sbpuao.js";
import { t as resolveHeartbeatReplyPayload } from "../heartbeat-reply-payload-yC8O54t5.js";
import { t as getReplyFromConfig } from "../reply-Dj3WLgPa.js";
import "../abort-CevHBCpf.js";
import { n as isBtwRequestText } from "../btw-command-07Um9B4p.js";
import { t as prepareModelForSimpleCompletion } from "../simple-completion-transport-Du1gG-_i.js";
import { completeSimple } from "@earendil-works/pi-ai";
//#region src/auto-reply/reply/conversation-label-generator.ts
const DEFAULT_MAX_LABEL_LENGTH = 128;
const TIMEOUT_MS = 15e3;
function isTextContentBlock(block) {
	return block.type === "text";
}
async function generateConversationLabel(params) {
	const { userMessage, prompt, cfg, agentId, agentDir } = params;
	const maxLength = typeof params.maxLength === "number" && Number.isFinite(params.maxLength) && params.maxLength > 0 ? Math.floor(params.maxLength) : DEFAULT_MAX_LABEL_LENGTH;
	const modelRef = resolveDefaultModelForAgent({
		cfg,
		agentId
	});
	const resolved = await resolveModelAsync(modelRef.provider, modelRef.model, agentDir, cfg);
	if (!resolved.model) {
		logVerbose(`conversation-label-generator: failed to resolve model ${modelRef.provider}/${modelRef.model}`);
		return null;
	}
	const completionModel = prepareModelForSimpleCompletion({
		model: resolved.model,
		cfg
	});
	const apiKey = requireApiKey(await getApiKeyForModel({
		model: completionModel,
		cfg,
		agentDir
	}), modelRef.provider);
	const controller = new AbortController();
	const timeout = setTimeout(() => controller.abort(), TIMEOUT_MS);
	try {
		const text = (await completeSimple(completionModel, { messages: [{
			role: "user",
			content: `${prompt}\n\n${userMessage}`,
			timestamp: Date.now()
		}] }, {
			apiKey,
			maxTokens: 100,
			temperature: .3,
			signal: controller.signal
		})).content.filter(isTextContentBlock).map((block) => block.text).join("").trim();
		if (!text) return null;
		return text.slice(0, maxLength);
	} finally {
		clearTimeout(timeout);
	}
}
//#endregion
export { DEFAULT_HEARTBEAT_ACK_MAX_CHARS, HEARTBEAT_PROMPT, HEARTBEAT_TOKEN, SILENT_REPLY_TOKEN, chunkMarkdownText, chunkMarkdownTextWithMode, chunkText, chunkTextWithMode, createInboundDebouncer, createReplyDispatcher, createReplyDispatcherWithTyping, createReplyReferencePlanner, dispatchInboundMessage, dispatchInboundMessageWithBufferedDispatcher, dispatchInboundMessageWithDispatcher, dispatchReplyWithBufferedBlockDispatcher, dispatchReplyWithDispatcher, finalizeInboundContext, generateConversationLabel, getReplyFromConfig, isAbortRequestText, isBtwRequestText, isSilentReplyText, normalizeGroupActivation, parseActivationCommand, resetInboundDedupe, resolveChunkMode, resolveHeartbeatPrompt, resolveHeartbeatReplyPayload, resolveInboundDebounceMs, resolveTextChunkLimit, stripHeartbeatToken };
