"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.REPLY_SUPPRESSION_PREFIX_ZH = exports.REPLY_SUPPRESSION_PREFIX_EN = exports.ANSWERING_REPLY_REMINDER_PREFIX_ZH = exports.ANSWERING_REPLY_REMINDER_PREFIX_EN = exports.REPLY_TOOL_REMINDER_PREFIX_ZH = exports.REPLY_TOOL_REMINDER_PREFIX_EN = exports.NO_ACTIVE_REPLY_PREFIX_ZH = exports.NO_ACTIVE_REPLY_PREFIX_EN = exports.ACTIVE_REPLY_TOOL_PREFIX_ZH = exports.ACTIVE_REPLY_TOOL_PREFIX_EN = void 0;
exports.buildActiveReplyToolNote = buildActiveReplyToolNote;
exports.buildActiveReplyObligationContextText = buildActiveReplyObligationContextText;
exports.buildSideDialogCompletionRule = buildSideDialogCompletionRule;
exports.buildSideDialogRoleHeaderCopy = buildSideDialogRoleHeaderCopy;
exports.buildReplyObligationSuppressionGuideText = buildReplyObligationSuppressionGuideText;
exports.buildReplyToolReminderText = buildReplyToolReminderText;
exports.buildAnsweringReplyReminderText = buildAnsweringReplyReminderText;
exports.isReplyToolReminderPromptContent = isReplyToolReminderPromptContent;
exports.isStandaloneRuntimeGuidePromptContent = isStandaloneRuntimeGuidePromptContent;
const tellask_labels_1 = require("./tellask-labels");
exports.ACTIVE_REPLY_TOOL_PREFIX_EN = '[Dominds reply path]';
exports.ACTIVE_REPLY_TOOL_PREFIX_ZH = '[Dominds 回复路径]';
exports.NO_ACTIVE_REPLY_PREFIX_EN = '[Dominds no reply needed]';
exports.NO_ACTIVE_REPLY_PREFIX_ZH = '[Dominds 无需回贴]';
exports.REPLY_TOOL_REMINDER_PREFIX_EN = '[Dominds send the reply now]';
exports.REPLY_TOOL_REMINDER_PREFIX_ZH = '[Dominds 现在发送回贴]';
exports.ANSWERING_REPLY_REMINDER_PREFIX_EN = '[Dominds requester still needs reply]';
exports.ANSWERING_REPLY_REMINDER_PREFIX_ZH = '[Dominds 诉请者仍需回贴]';
exports.REPLY_SUPPRESSION_PREFIX_EN = '[Dominds handle this interjection first]';
exports.REPLY_SUPPRESSION_PREFIX_ZH = '[Dominds 先接住这轮]';
function formatReplyTargetAgentId(agentId, language) {
    if (agentId && agentId.trim() !== '') {
        return `@${agentId}`;
    }
    return language === 'zh' ? '对方' : 'the other dialog';
}
function buildReplyToolReminderLine(args) {
    const toolName = args.directive.expectedReplyCallName;
    const replyTarget = formatReplyTargetAgentId(args.replyTargetAgentId, args.language);
    const kindLabel = (0, tellask_labels_1.getTellaskKindLabel)({
        language: args.language,
        name: args.directive.expectedReplyCallName,
        bracketed: true,
    });
    return args.language === 'zh'
        ? `${replyTarget} 还在等你完成${kindLabel}的回贴。请现在调用 \`${toolName}({ replyContent })\` 发送。`
        : `${replyTarget} is still waiting for your ${kindLabel} reply. Call \`${toolName}({ replyContent })\` now to send it.`;
}
// Business scenario: Dominds has a durable record that this dialog still owes a final reply to
// the requester. The model is not supposed to rediscover whether this is replyTellask,
// replyTellaskSessionless, or replyTellaskBack from old transcript text; that choice comes from
// the active request record. The copy therefore says Dominds already chose one path and names one
// tool. It also says "when final content is ready" because an active reply path is a delivery
// constraint, not a command to abandon necessary local work and close early.
function buildActiveReplyToolNote(args) {
    if (args.language === 'zh') {
        return [
            exports.ACTIVE_REPLY_TOOL_PREFIX_ZH,
            'Dominds 已经判断好：这轮如果要把最终结果回给诉请者，只能用下面这个工具。',
            `先把当前任务做对；等最终内容准备好时，调用 \`${args.toolName}\`。不要提前发送，也不要改用别的回复工具。`,
        ].join('\n');
    }
    return [
        exports.ACTIVE_REPLY_TOOL_PREFIX_EN,
        'Dominds has already decided the reply path: if this turn sends the final result back to the requester, use only the tool below.',
        `Do the current task correctly first; when the final content is ready, call \`${args.toolName}\`. Do not send early or switch to another reply tool.`,
    ].join('\n');
}
// Business scenario: the dialog still owes a final answer to a requester, but this block is
// persistent context rather than a fresh user request. Without that distinction, models tend to
// treat the state block itself as an instruction to immediately reply or to re-open the original
// request as new work. Keep the wording simple: who is waiting, which request it is, and which
// exact tool sends the final content when the answer is actually ready.
function buildActiveReplyObligationContextText(args) {
    if (args.language === 'zh') {
        return [
            '[Dominds 待回贴任务]',
            '这是 Dominds 状态，不是新的用户请求。',
            `要回给的对话：${args.directive.targetDialogId}`,
            `对应请求：${args.directive.targetCallId}`,
            `发送最终内容时调用：\`${args.directive.expectedReplyCallName}({ replyContent })\``,
            '',
            '原始诉请内容：',
            args.directive.tellaskContent,
        ].join('\n');
    }
    return [
        '[Dominds pending reply task]',
        'This is Dominds state, not a new user request.',
        `Dialog to reply to: ${args.directive.targetDialogId}`,
        `Request to answer: ${args.directive.targetCallId}`,
        `When sending the final content, call: \`${args.directive.expectedReplyCallName}({ replyContent })\``,
        '',
        'Original request content:',
        args.directive.tellaskContent,
    ].join('\n');
}
// Business scenario: a Side Dialog has enough information to finish the assigned work. At that
// point `tellaskBack` is still only for asking the requester a question; it must not be used as a
// final delivery path. Dominds may already name the precise reply tool from durable state, so the
// model should not choose among reply variants by memory or by guessing from the original
// assignment.
function buildSideDialogCompletionRule(language) {
    return language === 'zh'
        ? '当前支线已完成并能给出最终交付时：先专注把当前任务做对；若 Dominds 点名了精确回复工具，就只在发送最终内容时调用那个工具，不要改用别的回复工具，也不要用 `tellaskBack` 发送最终结果。'
        : 'If the current Side Dialog is complete and can deliver the final result: focus on finishing the actual task first; if Dominds names an exact reply tool, call that tool only when sending the final content, do not switch to another reply tool, and do not use `tellaskBack` for final delivery.';
}
function buildSideDialogRoleHeaderCopy(args) {
    const tellaskerTag = `@${args.tellaskerId}`;
    if (args.expectedReplyTool === undefined) {
        return args.language === 'zh'
            ? `${tellaskerTag} 已通过诉请安排你处理下述诉请内容。只有确实需要向诉请者回问、且现有规程无法直接判责时，才调用 \`tellaskBack\`。`
            : `${tellaskerTag} has assigned you to handle the request content below. Call \`tellaskBack\` only when you truly need to ask the tellasker back and existing SOP cannot directly identify another owner.`;
    }
    const kindLabel = (0, tellask_labels_1.getTellaskKindLabel)({
        language: args.language,
        name: args.expectedReplyTool,
        bracketed: true,
    });
    return args.language === 'zh'
        ? `${tellaskerTag} 已通过${kindLabel}安排你处理下述诉请内容。等你准备好最终回复后，调用 \`${args.expectedReplyTool}\` 发回去。只有确实需要向诉请者回问、且现有规程无法直接判责时，才调用 \`tellaskBack\`。`
        : `${tellaskerTag} has assigned you, via this ${kindLabel}, to handle the request content below. When the final reply is ready, call \`${args.expectedReplyTool}\` to send it back. Call \`tellaskBack\` only when you truly need to ask the tellasker back and existing SOP cannot directly identify another owner.`;
}
// Business scenario: a real user interjected while a longer-running requester reply was still
// open. The current user message wins the immediate turn; the older reply task remains ordinary
// durable state for later drive logic. The model-facing copy must not ask the model to decide
// whether the old request or the new user message wins; Dominds already decided. It also must not
// ban tools generally: tools are fine when the current user message itself needs them, but old
// request/reminder context must not pull the model back into earlier handoff work before the
// visible user answer.
function buildReplyObligationSuppressionGuideText(language) {
    if (language === 'zh') {
        return [
            exports.REPLY_SUPPRESSION_PREFIX_ZH,
            '本轮最新用户消息是真实用户插话；先按这条最新用户消息回答，让用户看到你已经接住了当前话题。',
            '原来的长线诉请、回贴任务、技能/SOP 触发条件都不能抢在当前用户消息前面；不要在回答当前用户消息前切回旧任务、旧工具流程或旧收口。',
            '只有当前用户消息本身需要，才使用工具；不要因为旧长线任务、旧技能提示或旧提醒项去调用工具。',
            '当前用户插话得到可见回复后，Dominds 会按已有回复义务、续推和普通驱动规则继续处理后续状态。',
        ].join('\n');
    }
    return [
        exports.REPLY_SUPPRESSION_PREFIX_EN,
        'The latest user message in this turn is a real user interjection; answer that latest user message first so the user can see you handled the current topic.',
        'The earlier long-line request, reply task, and skill/SOP triggers must not jump ahead of the current user message; do not switch back to the old task, old tool flow, or old closure before answering the current user message.',
        'Use tools only if the current user message itself requires them; do not call tools because of the earlier long-line task, old skill hints, or old reminders.',
        'After the current user interjection has a visible reply, Dominds will continue according to the existing reply obligation, diligence push, and normal drive rules.',
    ].join('\n');
}
// Business scenario: the model already wrote content that can be sent back to the requester but
// stopped as plain text instead of using the reply tool Dominds named. In that state Dominds can
// be precise: this is no longer "keep working", it is "send the already-produced final content
// through this tool". Avoid fallback/internal terminology here; the model only needs to know that
// plain text is not the formal delivery path to the other dialog.
function buildReplyToolReminderText(args) {
    const prefix = args.language === 'zh' ? exports.REPLY_TOOL_REMINDER_PREFIX_ZH : exports.REPLY_TOOL_REMINDER_PREFIX_EN;
    return args.language === 'zh'
        ? [
            prefix,
            '',
            `你刚才已经写出了可以发回去的内容，但还没调用 \`${args.directive.expectedReplyCallName}\`。`,
            '',
            buildReplyToolReminderLine(args),
            '请现在用这个工具发送；不要只发普通文本，否则对方那边可能收不到正式回贴。',
        ].join('\n')
        : [
            prefix,
            '',
            `You already wrote content that can be sent back, but you still have not called \`${args.directive.expectedReplyCallName}\`.`,
            '',
            buildReplyToolReminderLine(args),
            'Use this tool to send it now; do not rely on plain text, because the other dialog may not receive a formal reply that way.',
        ].join('\n');
}
// Business scenario: the model produced structured `answering` (or called `answerHuman`) while a
// Side Dialog still owes a formal reply to its requester. A2H is a human-attention answer or status
// record; it is intentionally not the requester delivery channel. Keep this as a reply-tool
// reminder so a later plain-text answer can use the same direct-fallback recovery semantics as
// ordinary reminders.
function buildAnsweringReplyReminderText(args) {
    const prefix = args.language === 'zh'
        ? exports.ANSWERING_REPLY_REMINDER_PREFIX_ZH
        : exports.ANSWERING_REPLY_REMINDER_PREFIX_EN;
    const replyTarget = formatReplyTargetAgentId(args.replyTargetAgentId, args.language);
    const kindLabel = (0, tellask_labels_1.getTellaskKindLabel)({
        language: args.language,
        name: args.directive.expectedReplyCallName,
        bracketed: true,
    });
    return args.language === 'zh'
        ? [
            prefix,
            '',
            '`answering` / `answerHuman` 只会记录给人类看的 A2H 答复或状态说明，不会把正式回贴送达诉请者。',
            '',
            `${replyTarget} 还在等你完成${kindLabel}的回贴。若最终内容已经准备好，请现在调用 \`${args.directive.expectedReplyCallName}({ replyContent })\` 发送；不要用 \`answering\` 或 \`answerHuman\` 代替诉请者回贴。`,
        ].join('\n')
        : [
            prefix,
            '',
            '`answering` / `answerHuman` only records an A2H answer or status for the human. It does not deliver the formal reply to the requester.',
            '',
            `${replyTarget} is still waiting for your ${kindLabel} reply. If the final content is ready, call \`${args.directive.expectedReplyCallName}({ replyContent })\` now; do not use \`answering\` or \`answerHuman\` as the requester reply path.`,
        ].join('\n');
}
function isReplyToolReminderPromptContent(content) {
    return (content.startsWith(exports.REPLY_TOOL_REMINDER_PREFIX_ZH) ||
        content.startsWith(exports.REPLY_TOOL_REMINDER_PREFIX_EN) ||
        content.startsWith(exports.ANSWERING_REPLY_REMINDER_PREFIX_ZH) ||
        content.startsWith(exports.ANSWERING_REPLY_REMINDER_PREFIX_EN));
}
function isStandaloneRuntimeGuidePromptContent(content) {
    return (content.startsWith(exports.REPLY_SUPPRESSION_PREFIX_ZH) ||
        content.startsWith(exports.REPLY_SUPPRESSION_PREFIX_EN));
}
