add missing files

This commit is contained in:
2026-09-05 01:31:41 +02:00
parent 627ef530b7
commit 16b7a69d52
5 changed files with 198 additions and 0 deletions
+96
View File
@@ -0,0 +1,96 @@
export const retryStylePrompts = Object.freeze({
shorter: "Rewrite the assistant reply to be shorter and tighter while preserving its meaning.",
direct: "Rewrite the assistant reply to be more direct and less padded.",
emotional: "Rewrite the assistant reply to be more emotionally expressive without changing the core meaning.",
"stay-in-character": "Rewrite the assistant reply to stay more strongly in character and voice.",
dialogue: "Rewrite the assistant reply as dialogue only. Remove narration unless required for clarity."
});
export function clampRetryActiveIndex(index, variants) {
const numeric = Number(index);
if (!Number.isInteger(numeric) || numeric < 0) return 0;
return Math.min(numeric, Math.max(0, variants.length - 1));
}
export function parseRetryVariants(rawValue, content) {
if (!rawValue) return [content || ""];
try {
const parsed = JSON.parse(rawValue);
if (Array.isArray(parsed)) {
const normalized = parsed.map((item) => String(item || "").trim()).filter(Boolean);
if (normalized.length) return normalized;
}
} catch {
return [content || ""];
}
return [content || ""];
}
export function formatChatMessage(row) {
if (!row) return null;
const retryVariants = parseRetryVariants(row.retry_variants, row.content);
const retryActiveIndex = clampRetryActiveIndex(row.retry_active_index, retryVariants);
return {
id: row.id,
role: row.role,
content: row.content,
modelName: row.model_name || null,
retryVariants,
retryActiveIndex,
retryRetriesUsed: Number(row.retry_retries_used || 0),
retryPromptMessageId: row.retry_prompt_message_id ?? null
};
}
export function buildMemoryPrompt(memories) {
const facts = (memories || [])
.map((memory) => String(memory.fact || "").trim())
.filter(Boolean)
.slice(0, 30);
if (!facts.length) return null;
return [
"LONG-TERM MEMORY:",
"These are durable facts the assistant should remember for this chat/persona context.",
"Use them for continuity, but do not mention them unless relevant.",
...facts.map((fact, index) => `${index + 1}. ${fact}`)
].join("\n");
}
export function buildContextSummaryPrompt(summary) {
if (!summary) return null;
return [
"CONVERSATION SUMMARY:",
"This is compressed background context from earlier messages in this chat.",
"Use it for continuity. Recent raw messages below are more authoritative.",
summary
].join("\n");
}
export function buildPersonaStatePrompt(state) {
if (!state) return null;
const lines = [
["Relationship notes", state.relationship_notes],
["Tone", state.tone],
["Current location", state.current_location],
["Goals", state.goals],
["Unresolved threads", state.unresolved_threads],
["Boundaries", state.boundaries]
]
.map(([label, value]) => [label, String(value || "").trim()])
.filter(([, value]) => value)
.map(([label, value]) => `${label}: ${value}`);
if (!lines.length) return null;
return [
"PERSONA RELATIONSHIP STATE:",
"Use this roleplay continuity state for the current assistant/user persona pair.",
"Keep it consistent unless the latest user message clearly changes it.",
...lines
].join("\n");
}
export function formatMessagesForSummary(messages) {
return messages.map((message) => {
const speaker = message.role === "bot" ? "Assistant" : message.role === "user" ? "User" : message.role;
return `${speaker}: ${String(message.content || "").trim()}`;
}).join("\n\n");
}