refactor(chat): split stream helpers
This commit is contained in:
+2
-29
@@ -35,9 +35,11 @@ import {
|
||||
isPressureTrendDemoPrompt,
|
||||
} from "./pressureTrendDemo.js";
|
||||
import {
|
||||
buildForkedSessionUiState,
|
||||
buildPromptWithLearningContext,
|
||||
extractLatestFrontendTurn,
|
||||
generateSessionTitle,
|
||||
resolveRequestedStreamSessionId,
|
||||
shouldGenerateSessionTitle,
|
||||
shouldRestoreConversationForRuntime,
|
||||
} from "./chatSession.js";
|
||||
@@ -98,20 +100,6 @@ const toSessionUiStateContext = (sessionRecord: SessionRecord) => ({
|
||||
sessionId: sessionRecord.sessionId,
|
||||
});
|
||||
|
||||
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)
|
||||
: [],
|
||||
});
|
||||
|
||||
const getSessionRunStatus = (sessionId: string) =>
|
||||
activeRuns.get(sessionId)?.status ?? lastRunStatuses.get(sessionId);
|
||||
|
||||
@@ -193,21 +181,6 @@ const pipeUiChunk = (
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
export const buildChatRouter = (
|
||||
sessionBridge: ChatSessionBridge,
|
||||
runtime: OpencodeRuntimeAdapter,
|
||||
|
||||
Reference in New Issue
Block a user