feat: add system disclosure policy gate
Memind CI / Test, build, and release guards (pull_request) Successful in 3m14s

This commit is contained in:
john
2026-07-23 22:53:15 +08:00
parent ba6cc10f08
commit 205b5fd8be
20 changed files with 1585 additions and 2 deletions
+52 -1
View File
@@ -155,7 +155,7 @@ function buildModelMessages({ previousMessages, userMessage, memories, routingMe
];
}
function buildAssistantMessage(reply, { requestId, now }) {
function buildAssistantMessage(reply, { requestId, now, metadata = {} }) {
return {
id: `direct-assistant-${requestId || crypto.randomUUID()}`,
role: 'assistant',
@@ -165,6 +165,7 @@ function buildAssistantMessage(reply, { requestId, now }) {
userVisible: true,
source: 'portal-direct-chat',
chatRequestId: requestId || undefined,
...metadata,
},
};
}
@@ -440,10 +441,60 @@ export function createDirectChatService({
};
}
async function respondDeterministically({
userId,
sessionId = null,
requestId,
userMessage,
reply,
metadata = {},
onSessionReady = null,
} = {}) {
const activeSessionId = sessionId || createDirectSessionId();
const snapshot = await sessionSnapshotService.get(activeSessionId).catch(() => null);
const previousMessages = Array.isArray(snapshot?.messages) ? snapshot.messages : [];
const now = new Date().toISOString();
if (!sessionId) {
await sessionStore.registerAgentSession(userId, activeSessionId, 'h5-direct');
}
if (typeof onSessionReady === 'function') {
await onSessionReady(activeSessionId);
}
const pendingMessages = [...previousMessages, userMessage];
const assistantMessage = buildAssistantMessage(String(reply ?? ''), {
requestId,
now,
metadata,
});
const messages = [...pendingMessages, assistantMessage];
const session = {
id: activeSessionId,
name: snapshot?.session?.name ?? 'New Chat',
working_dir: snapshot?.session?.working_dir ?? '',
message_count: messages.length,
created_at: snapshot?.session?.created_at ?? now,
updated_at: now,
user_set_name: snapshot?.session?.user_set_name ?? false,
recipe: snapshot?.session?.recipe ?? null,
conversation: messages,
};
await sessionSnapshotService.save(activeSessionId, userId, session, messages);
return {
ok: true,
sessionId: activeSessionId,
messages,
session,
assistantMessage,
billing: null,
deterministic: true,
};
}
return {
getStatus,
canHandle,
explainCanHandle,
respondDeterministically,
run,
};
}