mirror of
https://github.com/severian-dev/sucker.severian.dev.git
synced 2025-10-28 12:45:55 +00:00
chore: why is this shit not logging
This commit is contained in:
@@ -39,32 +39,55 @@ interface PersonaMatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findTagsBetween(content: string, startMarker: string, endMarker: string): PersonaMatch[] {
|
function findTagsBetween(content: string, startMarker: string, endMarker: string): PersonaMatch[] {
|
||||||
|
console.log("Starting findTagsBetween with markers:", startMarker, endMarker);
|
||||||
|
console.log("Content length:", content.length);
|
||||||
|
console.log("First 100 chars of content:", content.substring(0, 100));
|
||||||
|
|
||||||
const startMarkerTag = `<${startMarker}>`;
|
const startMarkerTag = `<${startMarker}>`;
|
||||||
const endMarkerTag = `<${endMarker}>`;
|
const endMarkerTag = `<${endMarker}>`;
|
||||||
|
|
||||||
const startIdx = content.indexOf(startMarkerTag);
|
const startIdx = content.indexOf(startMarkerTag);
|
||||||
if (startIdx === -1) return [];
|
console.log("Start marker index:", startIdx);
|
||||||
|
if (startIdx === -1) {
|
||||||
|
console.log("Start marker not found");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const endIdx = content.indexOf(endMarkerTag);
|
const endIdx = content.indexOf(endMarkerTag);
|
||||||
if (endIdx === -1) return [];
|
console.log("End marker index:", endIdx);
|
||||||
|
if (endIdx === -1) {
|
||||||
|
console.log("End marker not found");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const section = content.slice(startIdx, endIdx);
|
const section = content.slice(startIdx, endIdx);
|
||||||
|
console.log("Section length:", section.length);
|
||||||
console.log("Section found:", section);
|
console.log("Section found:", section);
|
||||||
|
|
||||||
const matches: PersonaMatch[] = [];
|
const matches: PersonaMatch[] = [];
|
||||||
|
|
||||||
const tagPattern = /<([^/>\s][^>]*)>([\s\S]*?)<\/\1>/g;
|
const tagPattern = /<([^/>\s][^>]*)>([\s\S]*?)<\/\1>/g;
|
||||||
|
console.log("Using pattern:", tagPattern);
|
||||||
let match;
|
let match;
|
||||||
|
|
||||||
|
try {
|
||||||
while ((match = tagPattern.exec(section)) !== null) {
|
while ((match = tagPattern.exec(section)) !== null) {
|
||||||
console.log("Found match:", match[1], match[2].substring(0, 50) + "...");
|
console.log("Found match:", {
|
||||||
|
fullMatch: match[0],
|
||||||
|
tag: match[1],
|
||||||
|
contentPreview: match[2].substring(0, 50) + "..."
|
||||||
|
});
|
||||||
matches.push({
|
matches.push({
|
||||||
tag: match[1].trim(),
|
tag: match[1].trim(),
|
||||||
content: match[2].trim()
|
content: match[2].trim()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error during regex execution:", error);
|
||||||
|
}
|
||||||
|
|
||||||
console.log("Total matches found:", matches.length);
|
console.log("Total matches found:", matches.length);
|
||||||
|
console.log("Matches:", matches);
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,13 +108,24 @@ function safeReplace(text: string, old: string, newStr: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function extractCardData(messages: Message[]): CardData {
|
function extractCardData(messages: Message[]): CardData {
|
||||||
|
console.log("Starting extractCardData");
|
||||||
|
console.log("Messages length:", messages.length);
|
||||||
|
|
||||||
const content0 = messages[0].content;
|
const content0 = messages[0].content;
|
||||||
const content1 = messages[2].content;
|
const content1 = messages[2].content;
|
||||||
|
|
||||||
|
console.log("Content0 length:", content0.length);
|
||||||
|
console.log("Content1 length:", content1.length);
|
||||||
|
|
||||||
// Find all persona tags between system and scenario, take the last one as character
|
// Find all persona tags between system and scenario, take the last one as character
|
||||||
|
console.log("Finding personas between system and scenario");
|
||||||
const personas = findTagsBetween(content0, "system", "scenario");
|
const personas = findTagsBetween(content0, "system", "scenario");
|
||||||
|
console.log("Found personas:", personas);
|
||||||
|
|
||||||
const charPersona = personas[personas.length - 1];
|
const charPersona = personas[personas.length - 1];
|
||||||
|
console.log("Selected char persona:", charPersona);
|
||||||
const charName = charPersona?.tag || "";
|
const charName = charPersona?.tag || "";
|
||||||
|
console.log("Char name:", charName);
|
||||||
|
|
||||||
// Initialize card data with the character name
|
// Initialize card data with the character name
|
||||||
let cardData: CardData = {
|
let cardData: CardData = {
|
||||||
@@ -103,6 +137,8 @@ function extractCardData(messages: Message[]): CardData {
|
|||||||
first_mes: content1,
|
first_mes: content1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("Initial card data:", cardData);
|
||||||
|
|
||||||
// Replace character name with placeholder in all fields
|
// Replace character name with placeholder in all fields
|
||||||
for (const field in cardData) {
|
for (const field in cardData) {
|
||||||
if (field !== "name") {
|
if (field !== "name") {
|
||||||
@@ -113,6 +149,7 @@ function extractCardData(messages: Message[]): CardData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Final card data:", cardData);
|
||||||
return cardData;
|
return cardData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,9 +166,12 @@ export async function POST(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log("Received POST request");
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
|
console.log("Request body received");
|
||||||
|
|
||||||
if (!body.messages || body.messages.length < 2) {
|
if (!body.messages || body.messages.length < 2) {
|
||||||
|
console.log("Invalid request - missing messages or insufficient count");
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Missing messages or insufficient message count" },
|
{ error: "Missing messages or insufficient message count" },
|
||||||
{
|
{
|
||||||
@@ -143,7 +183,10 @@ export async function POST(request: NextRequest) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Processing card data");
|
||||||
const cardData = extractCardData(body.messages);
|
const cardData = extractCardData(body.messages);
|
||||||
|
console.log("Card data processed");
|
||||||
|
|
||||||
extractedCards.push({
|
extractedCards.push({
|
||||||
...cardData,
|
...cardData,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
@@ -162,6 +205,7 @@ export async function POST(request: NextRequest) {
|
|||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error processing request:", error);
|
console.error("Error processing request:", error);
|
||||||
|
console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Internal server error" },
|
{ error: "Internal server error" },
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user