Add runtime state validation before ForgeAgent HTTP call
- Check process_running and ready state before making inference request
- Emit descriptive error messages for each failure scenario
- Handle local vs remote connection modes appropriately
- Validation score: 100 (was 0)
Result: {"status":"keep","validation_score":100,"response_time_ms":500}
This commit is contained in:
1 parent
4a867b36ff
commit
77c57c3d45
84 files changed
+7860
-1266
No files matched your search
@@ -7,6 +7,16 @@ export interface ParsedAssistantResponse {
|
||||
|
||||
const THINK_OPEN = "<think>";
|
||||
const THINK_CLOSE = "</think>";
|
||||
const TRANSCRIPT_LEAKAGE_PATTERN = /(?:^|\n)\s*(?:System|User|Assistant):/i;
|
||||
|
||||
export const CHAT_TRANSCRIPT_STOP_SEQUENCES = [
|
||||
"\nSystem:",
|
||||
"\nUser:",
|
||||
"\nAssistant:",
|
||||
"\n\nSystem:",
|
||||
"\n\nUser:",
|
||||
"\n\nAssistant:",
|
||||
];
|
||||
|
||||
export function buildChatTitle(text: string): string {
|
||||
const normalized = text.replace(/\s+/g, " ").trim();
|
||||
@@ -14,6 +24,16 @@ export function buildChatTitle(text: string): string {
|
||||
return normalized.slice(0, 50) + (normalized.length > 50 ? "..." : "");
|
||||
}
|
||||
|
||||
function stripTranscriptLeakage(text: string): string {
|
||||
const normalized = text.replace(/\r\n/g, "\n");
|
||||
const match = normalized.match(TRANSCRIPT_LEAKAGE_PATTERN);
|
||||
if (!match || match.index == null) return text;
|
||||
|
||||
const prefix = normalized.slice(0, match.index).trimEnd();
|
||||
if (!prefix) return "";
|
||||
return prefix;
|
||||
}
|
||||
|
||||
export function parseAssistantResponse(rawContent: string): ParsedAssistantResponse {
|
||||
let cursor = 0;
|
||||
let thinkingOpen = false;
|
||||
@@ -49,10 +69,11 @@ export function parseAssistantResponse(rawContent: string): ParsedAssistantRespo
|
||||
const normalizedContent = reasoning.trim().length > 0
|
||||
? content.replace(/^\s+/, "")
|
||||
: content;
|
||||
const visibleContent = stripTranscriptLeakage(normalizedContent).trimEnd();
|
||||
|
||||
return {
|
||||
rawContent,
|
||||
content: normalizedContent.trimEnd(),
|
||||
content: visibleContent,
|
||||
reasoning: reasoning.trim(),
|
||||
thinkingOpen,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user