feat: WorldState memory, increased context, better error handling

- Added WorldState types for character location tracking
- Increased RECENT_MESSAGES_COUNT from 6 to 15
- Increased server limits (50k/200k chars)
- Added language reminders to system prompts
- Better error logging for 400 errors
This commit is contained in:
Alexej Wolff
2026-05-06 21:57:22 +02:00
parent 0b62e73111
commit 77b2794eb1
4 changed files with 251 additions and 19 deletions
+6 -4
View File
@@ -143,8 +143,8 @@ function pickAllowedFields(obj, allowedFields) {
const DEEPSEEK_LIMITS = {
MAX_TOKENS_LIMIT: 4096,
MAX_MESSAGES: 100,
MAX_MESSAGE_LENGTH: 32000, // ~8k tokens per message
MAX_TOTAL_LENGTH: 128000, // ~32k tokens total
MAX_MESSAGE_LENGTH: 50000, // ~12k tokens per message (increased for long context)
MAX_TOTAL_LENGTH: 200000, // ~50k tokens total (increased for world state + summary)
RATE_LIMIT_WINDOW_MS: 60 * 1000, // 1 minute
RATE_LIMIT_MAX_REQUESTS: 20, // 20 requests per minute per user
};
@@ -1196,6 +1196,7 @@ app.post("/api/deepseek/chat", requireAuth, async (req, res) => {
// Validation
const validationErrors = validateDeepSeekRequest(req.body);
if (validationErrors.length > 0) {
console.warn("DeepSeek chat validation failed:", validationErrors);
return res
.status(400)
.json({ error: "Validation failed", details: validationErrors });
@@ -1206,7 +1207,7 @@ app.post("/api/deepseek/chat", requireAuth, async (req, res) => {
return res.status(500).json({ error: "DeepSeek API key not configured" });
}
const { messages, temperature = 0.8, max_tokens = 1000 } = req.body;
const { temperature = 0.8, max_tokens = 1000 } = req.body;
const sanitizedMessages = sanitizeDeepSeekMessages(messages);
const clampedMaxTokens = Math.min(
max_tokens,
@@ -1256,6 +1257,7 @@ app.post("/api/deepseek/chat/stream", requireAuth, async (req, res) => {
// Validation
const validationErrors = validateDeepSeekRequest(req.body);
if (validationErrors.length > 0) {
console.warn("DeepSeek stream validation failed:", validationErrors);
return res
.status(400)
.json({ error: "Validation failed", details: validationErrors });
@@ -1266,7 +1268,7 @@ app.post("/api/deepseek/chat/stream", requireAuth, async (req, res) => {
return res.status(500).json({ error: "DeepSeek API key not configured" });
}
const { messages, temperature = 0.8, max_tokens = 1000 } = req.body;
const { temperature = 0.8, max_tokens = 1000 } = req.body;
const sanitizedMessages = sanitizeDeepSeekMessages(messages);
const clampedMaxTokens = Math.min(
max_tokens,