({
assistant,
model,
llmApi,
initialPrompt,
resume,
fork,
additionalRules,
additionalPrompts,
onShowConfigSelector,
onShowModelSelector,
onShowUpdateSelector,
onShowMCPSelector,
onShowSessionSelector,
onShowJobsSelector,
onShowExportSelector,
onClear,
onRefreshStatic,
isRemoteMode = false,
remoteUrl,
onShowDiff,
onShowStatusMessage,
}: UseChatProps)
| 46 | } from "./useChat.types.js"; |
| 47 | |
| 48 | export function useChat({ |
| 49 | assistant, |
| 50 | model, |
| 51 | llmApi, |
| 52 | initialPrompt, |
| 53 | resume, |
| 54 | fork, |
| 55 | additionalRules, |
| 56 | additionalPrompts, |
| 57 | onShowConfigSelector, |
| 58 | onShowModelSelector, |
| 59 | onShowUpdateSelector, |
| 60 | onShowMCPSelector, |
| 61 | onShowSessionSelector, |
| 62 | onShowJobsSelector, |
| 63 | onShowExportSelector, |
| 64 | onClear, |
| 65 | onRefreshStatic, |
| 66 | isRemoteMode = false, |
| 67 | remoteUrl, |
| 68 | onShowDiff, |
| 69 | onShowStatusMessage, |
| 70 | }: UseChatProps) { |
| 71 | const { exit } = useApp(); |
| 72 | |
| 73 | // Track service subscription |
| 74 | const serviceListenerCleanupRef = useRef<null | (() => void)>(null); |
| 75 | |
| 76 | // Store the current session |
| 77 | const [currentSession, setCurrentSession] = useState<Session>(() => { |
| 78 | // In remote mode, start with empty session (will be populated by polling) |
| 79 | if (isRemoteMode) { |
| 80 | return createSession([]); |
| 81 | } |
| 82 | |
| 83 | // Fork from an existing session if fork flag is used |
| 84 | if (fork) { |
| 85 | const { loadSessionById, startNewSession } = require("../../session.js"); |
| 86 | const sessionToFork = loadSessionById(fork); |
| 87 | if (sessionToFork) { |
| 88 | return startNewSession(sessionToFork.history); |
| 89 | } |
| 90 | // If session not found, create a new empty session |
| 91 | return createSession([]); |
| 92 | } |
| 93 | |
| 94 | // Load previous session if resume flag is used |
| 95 | if (resume) { |
| 96 | const savedSession = loadSession(); |
| 97 | if (savedSession) { |
| 98 | return savedSession; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Create new session |
| 103 | return createSession([]); |
| 104 | }); |
| 105 |
no test coverage detected