memory settings implementation

This commit is contained in:
Storme-bit
2026-04-17 23:13:36 -07:00
parent 1cc7b62d79
commit 77275cf476
7 changed files with 254 additions and 206 deletions

View File

@@ -33,60 +33,6 @@ export async function sendMessage(sessionId, message, model) {
return res.json();
}
// onChunk(text) called for each token
// onDone({ model, tokenCount }) called when stream closes
// returns an abort function — call it to cancel mid-stream
/*
export function streamMessage(sessionId, message, model, { onChunk, onDone, onError }) {
const controller = new AbortController();
(async () => {
try {
const res = await fetch(`${BASE_URL}/chat/stream`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionId, message, model }),
signal: controller.signal,
});
if (!res.ok) throw new Error(`Stream request failed: ${res.status}`);
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
// Append to buffer and split on double newline (SSE event delimiter)
buffer += decoder.decode(value, { stream: true });
const events = buffer.split('\n\n');
buffer = events.pop(); // last item may be incomplete — keep in buffer
for (const event of events) {
const line = event.trim();
if (!line.startsWith('data: ')) continue;
const raw = line.slice(6);
try {
const data = JSON.parse(raw);
if (data.text) onChunk(data.text);
if (data.done) onDone({ model: data.model ?? model, tokenCount: data.tokenCount ?? 0 });
if (data.error) onError(new Error(data.error));
} catch {
// malformed JSON — skip
}
}
}
} catch (err) {
if (err.name !== 'AbortError') onError(err);
}
})();
return () => controller.abort();
}
*/
export function streamMessage(sessionId, message, model, { onChunk, onDone, onError }) {
const controller = new AbortController();
@@ -148,17 +94,7 @@ export async function fetchModels() {
if(!res.ok) throw new Error(`Failted to fetch models: ${res.status}`);
return res.json();
}
/*
export async function renameSession(sessionId, name) {
const res = await fetch(`${BASE_URL}/sessions/${sessionId}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name }),
});
if (!res.ok) throw new Error(`Failed to rename session: ${res.status}`);
return res.json();
}
*/
export async function updateSession(sessionId, { name, projectId } = {}) {
const res = await fetch(`${BASE_URL}/sessions/${sessionId}`, {
method: 'PATCH',
@@ -221,7 +157,7 @@ export async function updateSessionProject(sessionId, projectId) {
return res.json();
}
export async function getEpisodes({ limit = 50, offset = 0, sessionId, q } = {}) {
export async function getEpisodes({ limit = API_DEFAULTS.EPISODE_LIMIT, offset = API_DEFAULTS.OFFSET, sessionId, q } = {}) {
const url = new URL(`${BASE_URL}/episodes`, window.location.origin);
url.searchParams.set('limit', limit);
url.searchParams.set('offset', offset);

View File

@@ -1,7 +1,8 @@
import React, { useState, useEffect } from 'react';
import { fetchSessions, deleteSession } from '../api/orchestration';
import { API_DEFAULTS } from '../config/constants';
const PAGE_SIZE = 20;
const PAGE_SIZE = API_DEFAULTS.PAGE_SIZE;
export default function AllChatsView({ onSelectSession }) {
const [sessions, setSessions] = useState([]);

View File

@@ -11,4 +11,9 @@ export const API_DEFAULTS = {
SESSIONS_LIMIT: 20,
HISTORY_LIMIT: 50,
OFFSET: 0,
EPISODE_LIMIT: 50,
}
export const CLIENT_DEFAULTS = {
PAGE_SIZE: 20,
}