Next camp refactor live (#5706)
This commit is contained in:
+42
-38
@@ -2,48 +2,52 @@ import { Session, startAgent } from './api';
|
||||
import type { setViewType } from './hooks/useNavigation';
|
||||
|
||||
export function resumeSession(session: Session, setView: setViewType) {
|
||||
if (process.env.ALPHA) {
|
||||
setView('pair', {
|
||||
disableAnimation: true,
|
||||
resumeSessionId: session.id,
|
||||
});
|
||||
} else {
|
||||
const workingDir = session.working_dir;
|
||||
if (!workingDir) {
|
||||
throw new Error('Cannot resume session: working directory is missing in session');
|
||||
}
|
||||
window.electron.createChatWindow(
|
||||
undefined, // query
|
||||
workingDir,
|
||||
undefined, // version
|
||||
session.id
|
||||
);
|
||||
setView('pair', {
|
||||
disableAnimation: true,
|
||||
resumeSessionId: session.id,
|
||||
});
|
||||
}
|
||||
|
||||
export async function createSession(options?: {
|
||||
recipeId?: string;
|
||||
recipeDeeplink?: string;
|
||||
}): Promise<Session> {
|
||||
const body: {
|
||||
working_dir: string;
|
||||
recipe_id?: string;
|
||||
recipe_deeplink?: string;
|
||||
} = {
|
||||
working_dir: window.appConfig.get('GOOSE_WORKING_DIR') as string,
|
||||
};
|
||||
|
||||
if (options?.recipeId) {
|
||||
body.recipe_id = options.recipeId;
|
||||
} else if (options?.recipeDeeplink) {
|
||||
body.recipe_deeplink = options.recipeDeeplink;
|
||||
}
|
||||
|
||||
const newAgent = await startAgent({
|
||||
body,
|
||||
throwOnError: true,
|
||||
});
|
||||
return newAgent.data;
|
||||
}
|
||||
|
||||
export async function startNewSession(
|
||||
initialText: string | undefined,
|
||||
resetChat: (() => void) | null,
|
||||
setView: setViewType
|
||||
) {
|
||||
if (!resetChat || process.env.ALPHA) {
|
||||
const newAgent = await startAgent({
|
||||
body: {
|
||||
working_dir: window.appConfig.get('GOOSE_WORKING_DIR') as string,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
const session = newAgent.data;
|
||||
setView('pair', {
|
||||
disableAnimation: true,
|
||||
initialMessage: initialText,
|
||||
resumeSessionId: session.id,
|
||||
});
|
||||
} else {
|
||||
resetChat();
|
||||
setView('pair', {
|
||||
disableAnimation: true,
|
||||
initialMessage: initialText,
|
||||
});
|
||||
setView: setViewType,
|
||||
options?: {
|
||||
recipeId?: string;
|
||||
recipeDeeplink?: string;
|
||||
}
|
||||
): Promise<Session> {
|
||||
const session = await createSession(options);
|
||||
|
||||
setView('pair', {
|
||||
disableAnimation: true,
|
||||
initialMessage: initialText,
|
||||
resumeSessionId: session.id,
|
||||
});
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user