78 lines
3.4 KiB
JavaScript
78 lines
3.4 KiB
JavaScript
"use strict";
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
exports.applyAssistantCapabilityBindingResponseGuard = applyAssistantCapabilityBindingResponseGuard;
|
||
function formatMissingAnchors(anchors) {
|
||
if (anchors.length === 0) {
|
||
return "нужный объект, период или организацию";
|
||
}
|
||
return anchors.join(", ");
|
||
}
|
||
function buildClarificationReply(binding) {
|
||
return [
|
||
"Нужно уточнение, чтобы не подставить неподтвержденный объект в расчет.",
|
||
`Не хватает: ${formatMissingAnchors(binding.missing_anchors)}.`,
|
||
"Уточните это, и я продолжу тот же сценарий."
|
||
].join("\n");
|
||
}
|
||
function buildBlockedReply(binding) {
|
||
const reasons = binding.violations.length > 0 ? binding.violations.join(", ") : "runtime_binding_blocked";
|
||
return [
|
||
"Не могу надежно подтвердить ответ в текущем контексте.",
|
||
`Проверка сценария остановила ответ: ${reasons}.`,
|
||
"Лучше уточнить объект или перезапустить вопрос от корневого запроса, чем выдавать это как подтвержденный факт."
|
||
].join("\n");
|
||
}
|
||
function applyAssistantCapabilityBindingResponseGuard(input) {
|
||
const binding = input.capabilityBinding;
|
||
const baseAudit = {
|
||
schema_version: "assistant_capability_binding_response_guard_v1",
|
||
guard_owner: "assistantCapabilityBindingResponseGuard",
|
||
applied: false,
|
||
action: binding?.binding_action ?? "none",
|
||
original_reply_type: input.replyType,
|
||
guarded_reply_type: input.replyType,
|
||
reason_codes: binding?.reason_codes ?? []
|
||
};
|
||
if (!binding || binding.binding_action === "allow" || binding.binding_action === "observe_only") {
|
||
return {
|
||
assistantReply: input.assistantReply,
|
||
replyType: input.replyType,
|
||
audit: baseAudit
|
||
};
|
||
}
|
||
if (binding.binding_action === "clarify") {
|
||
return {
|
||
assistantReply: buildClarificationReply(binding),
|
||
replyType: "partial_coverage",
|
||
audit: {
|
||
...baseAudit,
|
||
applied: true,
|
||
guarded_reply_type: "partial_coverage",
|
||
reason_codes: [...baseAudit.reason_codes, "capability_binding_guard_clarification_reply"]
|
||
}
|
||
};
|
||
}
|
||
if (binding.binding_action === "block") {
|
||
return {
|
||
assistantReply: buildBlockedReply(binding),
|
||
replyType: "partial_coverage",
|
||
audit: {
|
||
...baseAudit,
|
||
applied: true,
|
||
guarded_reply_type: "partial_coverage",
|
||
reason_codes: [...baseAudit.reason_codes, "capability_binding_guard_blocked_reply"]
|
||
}
|
||
};
|
||
}
|
||
return {
|
||
assistantReply: input.assistantReply,
|
||
replyType: input.replyType === "factual" ? "partial_coverage" : input.replyType,
|
||
audit: {
|
||
...baseAudit,
|
||
applied: input.replyType === "factual",
|
||
guarded_reply_type: input.replyType === "factual" ? "partial_coverage" : input.replyType,
|
||
reason_codes: [...baseAudit.reason_codes, "capability_binding_guard_limited_reply_type"]
|
||
}
|
||
};
|
||
}
|