mirror of
https://github.com/severian-dev/sucker.severian.dev.git
synced 2026-10-18 01:20:29 +00:00
Say what actually went wrong
Every failure produced the same reply: read the directions, and check your context size. For a card Janitor truncated that was fair. For a request shape the user never chose, or for a bug in sucker, it blamed them for something they could not have done anything about — and sent them back to directions they had already followed. Failures that can be explained now explain themselves: no card in the request, no greeting in the chat, a card that arrived truncated (which keeps the context-size advice, since that is where it belongs), and a request with nothing in it. Anything else is a bug nobody anticipated, so the reply says as much, says it is not the user's fault, and asks them to DM @lyseverian on Discord — an unexplained failure nobody reports never gets fixed. Internals are never echoed back. SuckerError is recognised by name as well as by identity, because Next can bundle a module into more than one chunk and a mismatched class would quietly send every explained error down the unknown-bug path. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NX2SsmUqQftWTZAY4BDuFa
This commit is contained in:
@@ -5,6 +5,13 @@ import {
|
||||
tokenCandidates,
|
||||
type Message,
|
||||
} from "@/lib/messages";
|
||||
import {
|
||||
NO_CARD,
|
||||
NO_GREETING,
|
||||
TOO_FEW_MESSAGES,
|
||||
TRUNCATED_CARD,
|
||||
userFacingMessage,
|
||||
} from "@/lib/errors";
|
||||
|
||||
interface CardVersion {
|
||||
version: number;
|
||||
@@ -122,10 +129,10 @@ function extractCardData(messages: Message[]): ExtractedCard {
|
||||
const { system, greeting, nameSlot } = selectMessageSlots(messages);
|
||||
|
||||
if (!system) {
|
||||
throw new Error("No system message: this request carries no character card.");
|
||||
throw NO_CARD;
|
||||
}
|
||||
if (!greeting) {
|
||||
throw new Error("No assistant message: this chat has no greeting to read.");
|
||||
throw NO_GREETING;
|
||||
}
|
||||
|
||||
const first_mes = greeting.replace(/{user}/g, "{{user}}");
|
||||
@@ -162,7 +169,7 @@ function extractCardData(messages: Message[]): ExtractedCard {
|
||||
!content.includes("<.>") ||
|
||||
!content.includes("<UserPersona>.</UserPersona>")
|
||||
) {
|
||||
throw new Error("Required substrings not found");
|
||||
throw TRUNCATED_CARD;
|
||||
}
|
||||
|
||||
content = content.replace("<.>", "");
|
||||
@@ -335,12 +342,10 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
if (!body.messages || body.messages.length < 2) {
|
||||
if (isStreamingRequest) {
|
||||
return createSSEErrorResponse(
|
||||
"Missing messages or insufficient message count"
|
||||
);
|
||||
return createSSEErrorResponse(TOO_FEW_MESSAGES.message);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Missing messages or insufficient message count" },
|
||||
{ error: TOO_FEW_MESSAGES.message },
|
||||
{
|
||||
status: 400,
|
||||
headers: {
|
||||
@@ -560,8 +565,7 @@ export async function POST(request: NextRequest) {
|
||||
} catch (error) {
|
||||
console.error("Error processing request:", error);
|
||||
|
||||
const errorMessage =
|
||||
"You dingus, read the directions on sucker before trying again. If you're trying to suck a bot with more tokens than your current context limit, try bumping your Context Size setting up on Generation Settings.";
|
||||
const errorMessage = userFacingMessage(error);
|
||||
|
||||
// Check if this was a streaming request
|
||||
const acceptHeader = request.headers.get("accept");
|
||||
|
||||
Reference in New Issue
Block a user