mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-12 17:12:06 +08:00
feat(chat): unify session gateway with stable IDs and a single WS protocol
The frontend previously juggled placeholder IDs, provider-native IDs, and session_created handoffs, which caused race conditions and provider-specific branching. This introduces app-allocated session IDs, a chat run registry with event replay, delta sidebar updates, and one kind-based websocket contract so the UI can treat every provider the same while JSONL remains the source of truth.
This commit is contained in:
@@ -383,6 +383,47 @@ export function createCompleteMessage(opts: {
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
//----------------- CONVERSATION HISTORY PAGINATION UTILITIES ------------
|
||||
/**
|
||||
* Slices one page from the END of a chronologically ordered message list.
|
||||
*
|
||||
* This is the single pagination contract for conversation history across all
|
||||
* providers: `offset = 0` returns the most recent `limit` items, increasing
|
||||
* offsets walk backwards in time (for "scroll up to load older" UIs), and a
|
||||
* `null` limit returns everything. Items must already be sorted oldest-first;
|
||||
* the returned page preserves that order.
|
||||
*
|
||||
* Every provider history reader must use this helper instead of slicing
|
||||
* manually so `offset`/`limit` query params behave identically regardless of
|
||||
* which provider produced the session.
|
||||
*/
|
||||
export function sliceTailPage<T>(
|
||||
items: T[],
|
||||
limit: number | null,
|
||||
offset: number,
|
||||
): { page: T[]; hasMore: boolean } {
|
||||
const total = items.length;
|
||||
const normalizedOffset = Math.max(0, offset);
|
||||
|
||||
if (limit === null) {
|
||||
// A null limit returns the full list; offset still trims newest entries
|
||||
// so "everything before the page I already have" stays expressible.
|
||||
const end = Math.max(0, total - normalizedOffset);
|
||||
return {
|
||||
page: items.slice(0, end),
|
||||
hasMore: false,
|
||||
};
|
||||
}
|
||||
|
||||
const end = Math.max(0, total - normalizedOffset);
|
||||
const start = Math.max(0, end - Math.max(0, limit));
|
||||
return {
|
||||
page: items.slice(start, end),
|
||||
hasMore: start > 0,
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
//----------------- MCP CONFIG PARSING UTILITIES ------------
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user