fix: enforce security profile language across DAVE
This commit is contained in:
17
server.mjs
17
server.mjs
@@ -93,6 +93,7 @@ const telegramChatAssistant = new TelegramChatAssistant({
|
||||
provider: llmProvider,
|
||||
agent: config.telegram.agentEnabled ? terminalAgent : null,
|
||||
getContext: () => buildTelegramChatContext(currentData, buildHealth()),
|
||||
getPreferredLanguage: () => securityProfileStore.getAgentProfile()?.language || null,
|
||||
historyMessages: config.telegram.aiHistoryMessages,
|
||||
maxInputChars: config.telegram.aiMaxInputChars,
|
||||
maxTokens: config.telegram.aiMaxTokens,
|
||||
@@ -211,8 +212,9 @@ if (telegramAlerter.isConfigured) {
|
||||
}
|
||||
const chatId = msg?.chat?.id || config.telegram.chatId;
|
||||
const result = await telegramChatAssistant.replyDetailed(question, { chatId });
|
||||
const german = securityProfileStore.getAgentProfile()?.language === 'de';
|
||||
const tools = [...new Set((result.trace || []).filter(item => item.status === 'ok').map(item => item.tool))];
|
||||
const traceSuffix = tools.length ? `\n\nTools used: ${tools.join(', ')}` : '';
|
||||
const traceSuffix = tools.length ? `\n\n${german ? 'Verwendete Werkzeuge' : 'Tools used'}: ${tools.join(', ')}` : '';
|
||||
if (result.pendingAction) {
|
||||
const action = result.pendingAction;
|
||||
return {
|
||||
@@ -926,12 +928,13 @@ function shouldRunProactiveAgent(delta) {
|
||||
async function runProactiveAgent(data, delta) {
|
||||
if (telegramAlerter.getMuteStatus().muted) return false;
|
||||
const prompt = `Evaluate the latest sweep as the operator's Security Manager. Use the security profile when available to assess geographic and personal relevance, dependencies, urgency, and preferred language. Cross-check material changes with source health, evidence, scenarios, memory, and predictions as needed. Distinguish verified facts from inference. Do not call mutating tools. Delta summary: ${JSON.stringify(delta?.summary || {})}`;
|
||||
const profile = securityProfileStore.getAgentProfile();
|
||||
const result = await terminalAgent.analyzeProactively(prompt, {
|
||||
context: buildTelegramChatContext(data, buildHealth()),
|
||||
runtime: { data, delta },
|
||||
preferredLanguage: profile?.language || null,
|
||||
});
|
||||
if (result.pendingAction) return false;
|
||||
const profile = securityProfileStore.getAgentProfile();
|
||||
const policy = evaluateSecurityAlertPolicy(result, profile);
|
||||
if (!profile && !result.notify) {
|
||||
return telegramAlerter.evaluateAndAlert(null, delta, memory);
|
||||
@@ -940,10 +943,14 @@ async function runProactiveAgent(data, delta) {
|
||||
console.log(`[Security Manager] Proactive notification suppressed: ${policy.reason}`);
|
||||
return false;
|
||||
}
|
||||
const evidence = result.evidence?.length ? `\nEvidence:\n${result.evidence.map(item => `- ${item}`).join('\n')}` : '';
|
||||
const german = profile?.language === 'de';
|
||||
const evidence = result.evidence?.length ? `\n${german ? 'Belege' : 'Evidence'}:\n${result.evidence.map(item => `- ${item}`).join('\n')}` : '';
|
||||
const tools = [...new Set((result.trace || []).filter(item => item.status === 'ok').map(item => item.tool))];
|
||||
const trace = tools.length ? `\nTools: ${tools.join(', ')}` : '';
|
||||
const sent = await telegramAlerter.sendMessage(`[AGENT ${String(result.priority || 'routine').toUpperCase()}]\n${result.answer}${evidence}${trace}`, { parseMode: null });
|
||||
const trace = tools.length ? `\n${german ? 'Werkzeuge' : 'Tools'}: ${tools.join(', ')}` : '';
|
||||
const priority = german
|
||||
? ({ routine: 'HINWEIS', priority: 'PRIORITÄT', flash: 'SOFORT' }[result.priority] || 'HINWEIS')
|
||||
: String(result.priority || 'routine').toUpperCase();
|
||||
const sent = await telegramAlerter.sendMessage(`[DAVE // ${priority}]\n${result.answer}${evidence}${trace}`, { parseMode: null });
|
||||
return sent.ok;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user