81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import { Session, startAgent, ExtensionConfig } from './api';
|
|
import type { setViewType } from './hooks/useNavigation';
|
|
import {
|
|
getExtensionConfigsWithOverrides,
|
|
clearExtensionOverrides,
|
|
hasExtensionOverrides,
|
|
} from './store/extensionOverrides';
|
|
import type { FixedExtensionEntry } from './components/ConfigContext';
|
|
|
|
export function resumeSession(session: Session, setView: setViewType) {
|
|
setView('pair', {
|
|
disableAnimation: true,
|
|
resumeSessionId: session.id,
|
|
});
|
|
}
|
|
|
|
export async function createSession(
|
|
workingDir: string,
|
|
options?: {
|
|
recipeId?: string;
|
|
recipeDeeplink?: string;
|
|
extensionConfigs?: ExtensionConfig[];
|
|
allExtensions?: FixedExtensionEntry[];
|
|
}
|
|
): Promise<Session> {
|
|
const body: {
|
|
working_dir: string;
|
|
recipe_id?: string;
|
|
recipe_deeplink?: string;
|
|
extension_overrides?: ExtensionConfig[];
|
|
} = {
|
|
working_dir: workingDir,
|
|
};
|
|
|
|
if (options?.recipeId) {
|
|
body.recipe_id = options.recipeId;
|
|
} else if (options?.recipeDeeplink) {
|
|
body.recipe_deeplink = options.recipeDeeplink;
|
|
}
|
|
|
|
if (options?.extensionConfigs && options.extensionConfigs.length > 0) {
|
|
body.extension_overrides = options.extensionConfigs;
|
|
} else if (options?.allExtensions) {
|
|
const extensionConfigs = getExtensionConfigsWithOverrides(options.allExtensions);
|
|
if (extensionConfigs.length > 0) {
|
|
body.extension_overrides = extensionConfigs;
|
|
}
|
|
if (hasExtensionOverrides()) {
|
|
clearExtensionOverrides();
|
|
}
|
|
}
|
|
|
|
const newAgent = await startAgent({
|
|
body,
|
|
throwOnError: true,
|
|
});
|
|
|
|
return newAgent.data;
|
|
}
|
|
|
|
export async function startNewSession(
|
|
workingDir: string,
|
|
initialText: string | undefined,
|
|
setView: setViewType,
|
|
options?: {
|
|
recipeId?: string;
|
|
recipeDeeplink?: string;
|
|
allExtensions?: FixedExtensionEntry[];
|
|
}
|
|
): Promise<Session> {
|
|
const session = await createSession(workingDir, options);
|
|
|
|
setView('pair', {
|
|
disableAnimation: true,
|
|
initialMessage: initialText,
|
|
resumeSessionId: session.id,
|
|
});
|
|
|
|
return session;
|
|
}
|