refactor(chat): split stream helpers
This commit is contained in:
@@ -4,6 +4,7 @@ import { MemoryStore } from "../memory/store.js";
|
||||
import { type OpencodeRuntimeAdapter } from "../runtime/opencode.js";
|
||||
|
||||
import { collectTextContent } from "./chatStream.js";
|
||||
import { isPressureTrendDemoPrompt } from "./pressureTrendDemo.js";
|
||||
|
||||
const TITLE_PROMPT_TIMEOUT_MS = 5000;
|
||||
const TITLE_CONTEXT_MESSAGE_LIMIT = 40;
|
||||
@@ -217,6 +218,35 @@ export const shouldRestoreConversationForRuntime = (options: {
|
||||
runtimeHasConversation: boolean;
|
||||
}) => !options.hadExistingSessionRecord || !options.runtimeHasConversation;
|
||||
|
||||
export const buildForkedSessionUiState = (
|
||||
sourceState: { messages?: unknown[] } | null | undefined,
|
||||
input: {
|
||||
keepMessageCount: number;
|
||||
targetSessionId: string;
|
||||
},
|
||||
) => ({
|
||||
sessionId: input.targetSessionId,
|
||||
isTitleManuallyEdited: false,
|
||||
messages: Array.isArray(sourceState?.messages)
|
||||
? sourceState.messages.slice(0, input.keepMessageCount)
|
||||
: [],
|
||||
});
|
||||
|
||||
export const resolveRequestedStreamSessionId = (input: {
|
||||
sessionId?: string;
|
||||
promptText: string;
|
||||
createClientSessionId: () => string;
|
||||
}) => {
|
||||
const sessionId = input.sessionId?.trim();
|
||||
if (sessionId) {
|
||||
return sessionId;
|
||||
}
|
||||
if (isPressureTrendDemoPrompt(input.promptText)) {
|
||||
return input.createClientSessionId();
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const buildRestoredConversationContext = (recentTurns: SessionTurnRecord[]) => {
|
||||
const formattedTurns = recentTurns
|
||||
.slice(-RESTORE_TURN_LIMIT)
|
||||
|
||||
Reference in New Issue
Block a user