mirror of
https://github.com/aaif-goose/goose.git
synced 2026-07-03 14:10:03 +02:00
refactor: change open recipe in new window to pass recipe id (#7392)
This commit is contained in:
+17
-4
@@ -84,17 +84,23 @@ const PairRouteWrapper = ({
|
||||
|
||||
const resumeSessionId = searchParams.get('resumeSessionId') ?? undefined;
|
||||
const recipeDeeplinkFromConfig = window.appConfig?.get('recipeDeeplink') as string | undefined;
|
||||
const recipeIdFromConfig = window.appConfig?.get('recipeId') as string | undefined;
|
||||
const initialMessage = routeState.initialMessage;
|
||||
|
||||
// Create session if we have an initialMessage or recipeDeeplink but no sessionId
|
||||
// Create session if we have an initialMessage, recipeDeeplink, or recipeId but no sessionId
|
||||
useEffect(() => {
|
||||
if ((initialMessage || recipeDeeplinkFromConfig) && !resumeSessionId && !isCreatingSession) {
|
||||
if (
|
||||
(initialMessage || recipeDeeplinkFromConfig || recipeIdFromConfig) &&
|
||||
!resumeSessionId &&
|
||||
!isCreatingSession
|
||||
) {
|
||||
setIsCreatingSession(true);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const newSession = await createSession(getInitialWorkingDir(), {
|
||||
recipeDeeplink: recipeDeeplinkFromConfig,
|
||||
recipeId: recipeIdFromConfig,
|
||||
allExtensions: extensionsList,
|
||||
});
|
||||
|
||||
@@ -126,7 +132,14 @@ const PairRouteWrapper = ({
|
||||
// Note: isCreatingSession is intentionally NOT in the dependency array
|
||||
// It's only used as a guard to prevent concurrent session creation
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [initialMessage, recipeDeeplinkFromConfig, resumeSessionId, setSearchParams, extensionsList]);
|
||||
}, [
|
||||
initialMessage,
|
||||
recipeDeeplinkFromConfig,
|
||||
recipeIdFromConfig,
|
||||
resumeSessionId,
|
||||
setSearchParams,
|
||||
extensionsList,
|
||||
]);
|
||||
|
||||
// Add resumed session to active sessions if not already there
|
||||
useEffect(() => {
|
||||
@@ -450,7 +463,7 @@ export function AppInner() {
|
||||
if ((isMac ? event.metaKey : event.ctrlKey) && event.key === 'n') {
|
||||
event.preventDefault();
|
||||
try {
|
||||
window.electron.createChatWindow(undefined, getInitialWorkingDir());
|
||||
window.electron.createChatWindow({ dir: getInitialWorkingDir() });
|
||||
} catch (error) {
|
||||
console.error('Error creating new window:', error);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export default function LauncherView() {
|
||||
if (query.trim()) {
|
||||
const initialMessage = query;
|
||||
setQuery('');
|
||||
window.electron.createChatWindow(initialMessage, getInitialWorkingDir());
|
||||
window.electron.createChatWindow({ query: initialMessage, dir: getInitialWorkingDir() });
|
||||
setTimeout(() => {
|
||||
window.electron.closeWindow();
|
||||
}, 200);
|
||||
|
||||
@@ -84,10 +84,9 @@ const AppLayoutContent: React.FC<AppLayoutContentProps> = ({ activeSessions }) =
|
||||
};
|
||||
|
||||
const handleNewWindow = () => {
|
||||
window.electron.createChatWindow(
|
||||
undefined,
|
||||
window.appConfig.get('GOOSE_WORKING_DIR') as string | undefined
|
||||
);
|
||||
window.electron.createChatWindow({
|
||||
dir: window.appConfig.get('GOOSE_WORKING_DIR') as string | undefined,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -75,7 +75,7 @@ const ParameterInputModal: React.FC<ParameterInputModalProps> = ({
|
||||
if (option === 'new-chat') {
|
||||
try {
|
||||
const workingDir = getInitialWorkingDir();
|
||||
window.electron.createChatWindow(undefined, workingDir);
|
||||
window.electron.createChatWindow({ dir: workingDir });
|
||||
window.electron.hideWindow();
|
||||
} catch (error) {
|
||||
console.error('Error creating new window:', error);
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { useForm } from '@tanstack/react-form';
|
||||
import {
|
||||
Recipe,
|
||||
generateDeepLink,
|
||||
Parameter,
|
||||
encodeRecipe,
|
||||
stripEmptyExtensions,
|
||||
} from '../../recipe';
|
||||
import { Recipe, generateDeepLink, Parameter } from '../../recipe';
|
||||
import { Check, ExternalLink, Play, Save, X } from 'lucide-react';
|
||||
import { Geese } from '../icons/Geese';
|
||||
import Copy from '../icons/Copy';
|
||||
@@ -333,21 +327,12 @@ export default function CreateEditRecipeModal({
|
||||
try {
|
||||
const recipe = getCurrentRecipe();
|
||||
|
||||
await saveRecipe(recipe, recipeId);
|
||||
const savedId = await saveRecipe(recipe, recipeId);
|
||||
|
||||
// Close modal first
|
||||
onClose(true);
|
||||
|
||||
// Encode the recipe as a deeplink before passing to the new window
|
||||
const encodedRecipe = await encodeRecipe(stripEmptyExtensions(recipe));
|
||||
window.electron.createChatWindow(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
encodedRecipe
|
||||
);
|
||||
window.electron.createChatWindow({ recipeId: savedId });
|
||||
|
||||
toastSuccess({
|
||||
title: recipe.title,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useForm } from '@tanstack/react-form';
|
||||
import { Recipe, encodeRecipe, stripEmptyExtensions } from '../../recipe';
|
||||
import { Recipe } from '../../recipe';
|
||||
import { Geese } from '../icons/Geese';
|
||||
import { X, Save, Play, Loader2 } from 'lucide-react';
|
||||
import { Button } from '../ui/button';
|
||||
@@ -182,21 +182,13 @@ export default function CreateRecipeFromSessionModal({
|
||||
: undefined,
|
||||
};
|
||||
|
||||
await saveRecipe(recipe, null);
|
||||
const recipeId = await saveRecipe(recipe, null);
|
||||
|
||||
onRecipeCreated?.(recipe);
|
||||
onClose();
|
||||
|
||||
if (runAfterSave) {
|
||||
const encodedRecipe = await encodeRecipe(stripEmptyExtensions(recipe));
|
||||
window.electron.createChatWindow(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
encodedRecipe
|
||||
);
|
||||
window.electron.createChatWindow({ recipeId });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to create recipe:', error);
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
} from '../../api';
|
||||
import ImportRecipeForm, { ImportRecipeButton } from './ImportRecipeForm';
|
||||
import CreateEditRecipeModal from './CreateEditRecipeModal';
|
||||
import { generateDeepLink, encodeRecipe, Recipe, stripEmptyExtensions } from '../../recipe';
|
||||
import { generateDeepLink } from '../../recipe';
|
||||
import { useNavigation } from '../../hooks/useNavigation';
|
||||
import { CronPicker } from '../schedule/CronPicker';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '../ui/dialog';
|
||||
@@ -139,12 +139,12 @@ export default function RecipesView() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleStartRecipeChat = async (recipe: Recipe) => {
|
||||
const handleStartRecipeChat = async (recipeId: string) => {
|
||||
try {
|
||||
const newAgent = await startAgent({
|
||||
body: {
|
||||
working_dir: getInitialWorkingDir(),
|
||||
recipe: stripEmptyExtensions(recipe) as Recipe,
|
||||
recipe_id: recipeId,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
@@ -165,17 +165,13 @@ export default function RecipesView() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleStartRecipeChatInNewWindow = async (recipe: Recipe) => {
|
||||
const handleStartRecipeChatInNewWindow = async (recipeId: string) => {
|
||||
try {
|
||||
const encodedRecipe = await encodeRecipe(stripEmptyExtensions(recipe) as Recipe);
|
||||
window.electron.createChatWindow(
|
||||
undefined,
|
||||
getInitialWorkingDir(),
|
||||
undefined,
|
||||
undefined,
|
||||
'pair',
|
||||
encodedRecipe
|
||||
);
|
||||
window.electron.createChatWindow({
|
||||
dir: getInitialWorkingDir(),
|
||||
viewType: 'pair',
|
||||
recipeId,
|
||||
});
|
||||
trackRecipeStarted(true, undefined, true);
|
||||
} catch (error) {
|
||||
console.error('Failed to open recipe in new window:', error);
|
||||
@@ -509,9 +505,9 @@ export default function RecipesView() {
|
||||
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
handleStartRecipeChat(recipe);
|
||||
await handleStartRecipeChat(recipeManifestResponse.id);
|
||||
}}
|
||||
size="sm"
|
||||
className="h-8 w-8 p-0"
|
||||
@@ -520,9 +516,9 @@ export default function RecipesView() {
|
||||
<Play className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
handleStartRecipeChatInNewWindow(recipe);
|
||||
await handleStartRecipeChatInNewWindow(recipeManifestResponse.id);
|
||||
}}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@@ -532,9 +528,9 @@ export default function RecipesView() {
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
handleEditRecipe(recipeManifestResponse);
|
||||
await handleEditRecipe(recipeManifestResponse);
|
||||
}}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
|
||||
@@ -536,13 +536,11 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
|
||||
|
||||
const handleOpenInNewWindow = useCallback((session: Session, e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
window.electron.createChatWindow(
|
||||
undefined,
|
||||
session.working_dir,
|
||||
undefined,
|
||||
session.id,
|
||||
'pair'
|
||||
);
|
||||
window.electron.createChatWindow({
|
||||
dir: session.working_dir,
|
||||
resumeSessionId: session.id,
|
||||
viewType: 'pair',
|
||||
});
|
||||
}, []);
|
||||
|
||||
const SessionItem = React.memo(function SessionItem({
|
||||
|
||||
+94
-106
@@ -158,17 +158,12 @@ if (process.platform !== 'darwin') {
|
||||
const deeplinkData = parseRecipeDeeplink(protocolUrl);
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
|
||||
createChat(
|
||||
app,
|
||||
undefined,
|
||||
openDir || undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
deeplinkData?.config,
|
||||
scheduledJobId || undefined,
|
||||
deeplinkData?.parameters
|
||||
);
|
||||
await createChat(app, {
|
||||
dir: openDir || undefined,
|
||||
recipeDeeplink: deeplinkData?.config,
|
||||
scheduledJobId: scheduledJobId || undefined,
|
||||
recipeParameters: deeplinkData?.parameters,
|
||||
});
|
||||
});
|
||||
return; // Skip the rest of the handler
|
||||
}
|
||||
@@ -217,7 +212,7 @@ async function handleProtocolUrl(url: string) {
|
||||
const targetWindow =
|
||||
existingWindows.length > 0
|
||||
? existingWindows[0]
|
||||
: await createChat(app, undefined, openDir || undefined);
|
||||
: await createChat(app, { dir: openDir || undefined });
|
||||
await processProtocolUrl(parsedUrl, targetWindow);
|
||||
} else {
|
||||
// For other URL types, reuse existing window if available
|
||||
@@ -229,7 +224,7 @@ async function handleProtocolUrl(url: string) {
|
||||
}
|
||||
firstOpenWindow.focus();
|
||||
} else {
|
||||
firstOpenWindow = await createChat(app, undefined, openDir || undefined);
|
||||
firstOpenWindow = await createChat(app, { dir: openDir || undefined });
|
||||
}
|
||||
|
||||
if (firstOpenWindow) {
|
||||
@@ -258,17 +253,12 @@ async function processProtocolUrl(parsedUrl: URL, window: BrowserWindow) {
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
|
||||
// Create a new window and ignore the passed-in window
|
||||
createChat(
|
||||
app,
|
||||
undefined,
|
||||
openDir || undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
deeplinkData?.config,
|
||||
scheduledJobId || undefined,
|
||||
deeplinkData?.parameters
|
||||
);
|
||||
await createChat(app, {
|
||||
dir: openDir || undefined,
|
||||
recipeDeeplink: deeplinkData?.config,
|
||||
scheduledJobId: scheduledJobId || undefined,
|
||||
recipeParameters: deeplinkData?.parameters,
|
||||
});
|
||||
pendingDeepLink = null;
|
||||
}
|
||||
}
|
||||
@@ -296,17 +286,12 @@ app.on('open-url', async (_event, url) => {
|
||||
}
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
|
||||
await createChat(
|
||||
app,
|
||||
undefined,
|
||||
openDir || undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
deeplinkData?.config,
|
||||
scheduledJobId || undefined,
|
||||
deeplinkData?.parameters
|
||||
);
|
||||
await createChat(app, {
|
||||
dir: openDir || undefined,
|
||||
recipeDeeplink: deeplinkData?.config,
|
||||
scheduledJobId: scheduledJobId || undefined,
|
||||
recipeParameters: deeplinkData?.parameters,
|
||||
});
|
||||
windowDeeplinkURL = null;
|
||||
return;
|
||||
}
|
||||
@@ -329,7 +314,7 @@ app.on('open-url', async (_event, url) => {
|
||||
}
|
||||
} else {
|
||||
openUrlHandledLaunch = true;
|
||||
firstOpenWindow = await createChat(app, undefined, openDir || undefined);
|
||||
firstOpenWindow = await createChat(app, { dir: openDir || undefined });
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -380,7 +365,7 @@ async function handleFileOpen(filePath: string) {
|
||||
addRecentDir(targetDir);
|
||||
|
||||
// Create new window for the directory
|
||||
const newWindow = await createChat(app, undefined, targetDir);
|
||||
const newWindow = await createChat(app, { dir: targetDir });
|
||||
|
||||
// Focus the new window
|
||||
if (newWindow) {
|
||||
@@ -478,17 +463,28 @@ const windowPowerSaveBlockers = new Map<number, number>(); // windowId -> blocke
|
||||
// Track pending initial messages per window
|
||||
const pendingInitialMessages = new Map<number, string>(); // windowId -> initialMessage
|
||||
|
||||
const createChat = async (
|
||||
app: App,
|
||||
initialMessage?: string,
|
||||
dir?: string,
|
||||
_version?: string,
|
||||
resumeSessionId?: string,
|
||||
viewType?: string,
|
||||
recipeDeeplink?: string, // Raw deeplink decoded on server
|
||||
scheduledJobId?: string, // Scheduled job ID if applicable
|
||||
recipeParameters?: Record<string, string> // Recipe parameter values from deeplink URL
|
||||
) => {
|
||||
interface CreateChatOptions {
|
||||
initialMessage?: string;
|
||||
dir?: string;
|
||||
resumeSessionId?: string;
|
||||
viewType?: string;
|
||||
recipeDeeplink?: string;
|
||||
recipeId?: string;
|
||||
scheduledJobId?: string;
|
||||
recipeParameters?: Record<string, string>;
|
||||
}
|
||||
|
||||
const createChat = async (app: App, options: CreateChatOptions = {}) => {
|
||||
const {
|
||||
initialMessage,
|
||||
dir,
|
||||
resumeSessionId,
|
||||
viewType,
|
||||
recipeDeeplink,
|
||||
recipeId,
|
||||
scheduledJobId,
|
||||
recipeParameters,
|
||||
} = options;
|
||||
const settings = getSettings();
|
||||
const serverSecret = getServerSecret(settings);
|
||||
|
||||
@@ -548,6 +544,7 @@ const createChat = async (
|
||||
GOOSE_BASE_URL_SHARE: baseUrlShare,
|
||||
GOOSE_VERSION: version,
|
||||
recipeDeeplink: recipeDeeplink,
|
||||
recipeId: recipeId,
|
||||
recipeParameters: recipeParameters,
|
||||
scheduledJobId: scheduledJobId,
|
||||
SECURITY_ML_MODEL_MAPPING: process.env.SECURITY_ML_MODEL_MAPPING,
|
||||
@@ -590,7 +587,7 @@ const createChat = async (
|
||||
}
|
||||
});
|
||||
mainWindow.destroy();
|
||||
return createChat(app, initialMessage, dir);
|
||||
return createChat(app, { initialMessage, dir });
|
||||
}
|
||||
} else {
|
||||
dialog.showMessageBoxSync({
|
||||
@@ -720,7 +717,10 @@ const createChat = async (
|
||||
if (viewType) {
|
||||
appPath = routeMap[viewType] || '/';
|
||||
}
|
||||
if (appPath === '/' && (recipeDeeplink !== undefined || initialMessage)) {
|
||||
if (
|
||||
appPath === '/' &&
|
||||
(recipeDeeplink !== undefined || recipeId !== undefined || initialMessage)
|
||||
) {
|
||||
appPath = '/pair';
|
||||
}
|
||||
|
||||
@@ -931,7 +931,7 @@ const showWindow = async () => {
|
||||
log.info('No windows are open, creating a new one...');
|
||||
const recentDirs = loadRecentDirs();
|
||||
const openDir = recentDirs.length > 0 ? recentDirs[0] : null;
|
||||
await createChat(app, undefined, openDir || undefined);
|
||||
await createChat(app, { dir: openDir || undefined });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -963,8 +963,8 @@ const buildRecentFilesMenu = () => {
|
||||
const recentDirs = loadRecentDirs();
|
||||
return recentDirs.map((dir) => ({
|
||||
label: dir,
|
||||
click: () => {
|
||||
createChat(app, undefined, dir);
|
||||
click: async () => {
|
||||
await createChat(app, { dir });
|
||||
},
|
||||
}));
|
||||
};
|
||||
@@ -1052,18 +1052,11 @@ const openDirectoryDialog = async (): Promise<OpenDialogReturnValue> => {
|
||||
if (windowDeeplinkURL) {
|
||||
deeplinkData = parseRecipeDeeplink(windowDeeplinkURL);
|
||||
}
|
||||
// Create a new window with the selected directory
|
||||
await createChat(
|
||||
app,
|
||||
undefined,
|
||||
dirToAdd,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
deeplinkData?.config,
|
||||
undefined,
|
||||
deeplinkData?.parameters
|
||||
);
|
||||
await createChat(app, {
|
||||
dir: dirToAdd,
|
||||
recipeDeeplink: deeplinkData?.config,
|
||||
recipeParameters: deeplinkData?.parameters,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -1615,7 +1608,7 @@ ipcMain.handle('get-allowed-extensions', async () => {
|
||||
const createNewWindow = async (app: App, dir?: string | null) => {
|
||||
const recentDirs = loadRecentDirs();
|
||||
const openDir = dir || (recentDirs.length > 0 ? recentDirs[0] : undefined);
|
||||
return await createChat(app, undefined, openDir);
|
||||
return await createChat(app, { dir: openDir });
|
||||
};
|
||||
|
||||
const focusWindow = () => {
|
||||
@@ -2032,48 +2025,43 @@ async function appMain() {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(
|
||||
'create-chat-window',
|
||||
(event, query, dir, version, resumeSessionId, viewType, recipeDeeplink) => {
|
||||
if (!dir?.trim()) {
|
||||
const recentDirs = loadRecentDirs();
|
||||
dir = recentDirs.length > 0 ? recentDirs[0] : undefined;
|
||||
}
|
||||
ipcMain.on('create-chat-window', (event, options = {}) => {
|
||||
const { query, dir, resumeSessionId, viewType, recipeId } = options;
|
||||
|
||||
const isFromLauncher = query && !resumeSessionId && !viewType && !recipeDeeplink;
|
||||
|
||||
if (isFromLauncher) {
|
||||
const senderWindow = BrowserWindow.fromWebContents(event.sender);
|
||||
const launcherWindowId = senderWindow?.id;
|
||||
const allWindows = BrowserWindow.getAllWindows();
|
||||
|
||||
const existingWindows = allWindows.filter(
|
||||
(win) => !win.isDestroyed() && win.id !== launcherWindowId
|
||||
);
|
||||
|
||||
if (existingWindows.length > 0) {
|
||||
const targetWindow = existingWindows[0];
|
||||
targetWindow.show();
|
||||
targetWindow.focus();
|
||||
targetWindow.webContents.send('set-initial-message', query);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, create a new window
|
||||
createChat(
|
||||
app,
|
||||
query,
|
||||
dir,
|
||||
version,
|
||||
resumeSessionId,
|
||||
viewType,
|
||||
recipeDeeplink,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
let resolvedDir = dir;
|
||||
if (!resolvedDir?.trim()) {
|
||||
const recentDirs = loadRecentDirs();
|
||||
resolvedDir = recentDirs.length > 0 ? recentDirs[0] : undefined;
|
||||
}
|
||||
);
|
||||
|
||||
const isFromLauncher = query && !resumeSessionId && !viewType && !recipeId;
|
||||
|
||||
if (isFromLauncher) {
|
||||
const senderWindow = BrowserWindow.fromWebContents(event.sender);
|
||||
const launcherWindowId = senderWindow?.id;
|
||||
const allWindows = BrowserWindow.getAllWindows();
|
||||
|
||||
const existingWindows = allWindows.filter(
|
||||
(win) => !win.isDestroyed() && win.id !== launcherWindowId
|
||||
);
|
||||
|
||||
if (existingWindows.length > 0) {
|
||||
const targetWindow = existingWindows[0];
|
||||
targetWindow.show();
|
||||
targetWindow.focus();
|
||||
targetWindow.webContents.send('set-initial-message', query);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
createChat(app, {
|
||||
initialMessage: query,
|
||||
dir: resolvedDir,
|
||||
resumeSessionId,
|
||||
viewType,
|
||||
recipeId,
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('close-window', (event) => {
|
||||
const window = BrowserWindow.fromWebContents(event.sender);
|
||||
|
||||
+12
-25
@@ -89,6 +89,15 @@ interface UpdaterEvent {
|
||||
data?: unknown;
|
||||
}
|
||||
|
||||
export interface CreateChatWindowOptions {
|
||||
query?: string;
|
||||
dir?: string;
|
||||
version?: string;
|
||||
resumeSessionId?: string;
|
||||
viewType?: string;
|
||||
recipeId?: string;
|
||||
}
|
||||
|
||||
// Define the API types in a single place
|
||||
type ElectronAPI = {
|
||||
platform: string;
|
||||
@@ -96,14 +105,7 @@ type ElectronAPI = {
|
||||
getConfig: () => Record<string, unknown>;
|
||||
hideWindow: () => void;
|
||||
directoryChooser: () => Promise<Electron.OpenDialogReturnValue>;
|
||||
createChatWindow: (
|
||||
query?: string,
|
||||
dir?: string,
|
||||
version?: string,
|
||||
resumeSessionId?: string,
|
||||
viewType?: string,
|
||||
recipeDeeplink?: string
|
||||
) => void;
|
||||
createChatWindow: (options?: CreateChatWindowOptions) => void;
|
||||
logInfo: (txt: string) => void;
|
||||
showNotification: (data: NotificationData) => void;
|
||||
showMessageBox: (options: MessageBoxOptions) => Promise<MessageBoxResponse>;
|
||||
@@ -188,23 +190,8 @@ const electronAPI: ElectronAPI = {
|
||||
},
|
||||
hideWindow: () => ipcRenderer.send('hide-window'),
|
||||
directoryChooser: () => ipcRenderer.invoke('directory-chooser'),
|
||||
createChatWindow: (
|
||||
query?: string,
|
||||
dir?: string,
|
||||
version?: string,
|
||||
resumeSessionId?: string,
|
||||
viewType?: string,
|
||||
recipeDeeplink?: string
|
||||
) =>
|
||||
ipcRenderer.send(
|
||||
'create-chat-window',
|
||||
query,
|
||||
dir,
|
||||
version,
|
||||
resumeSessionId,
|
||||
viewType,
|
||||
recipeDeeplink
|
||||
),
|
||||
createChatWindow: (options?: CreateChatWindowOptions) =>
|
||||
ipcRenderer.send('create-chat-window', options || {}),
|
||||
logInfo: (txt: string) => ipcRenderer.send('logInfo', txt),
|
||||
showNotification: (data: NotificationData) => ipcRenderer.send('notify', data),
|
||||
showMessageBox: (options: MessageBoxOptions) => ipcRenderer.invoke('show-message-box', options),
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Recipe, saveRecipe as saveRecipeApi, listRecipes, RecipeManifest } from '../api';
|
||||
import { stripEmptyExtensions } from '.';
|
||||
|
||||
export const saveRecipe = async (recipe: Recipe, recipeId?: string | null): Promise<string> => {
|
||||
try {
|
||||
let response = await saveRecipeApi({
|
||||
body: {
|
||||
recipe,
|
||||
recipe: stripEmptyExtensions(recipe),
|
||||
id: recipeId,
|
||||
},
|
||||
throwOnError: true,
|
||||
|
||||
@@ -38,6 +38,7 @@ export async function createSession(
|
||||
workingDir: string,
|
||||
options?: {
|
||||
recipeDeeplink?: string;
|
||||
recipeId?: string;
|
||||
extensionConfigs?: ExtensionConfig[];
|
||||
allExtensions?: FixedExtensionEntry[];
|
||||
}
|
||||
@@ -45,12 +46,15 @@ export async function createSession(
|
||||
const body: {
|
||||
working_dir: string;
|
||||
recipe?: Recipe;
|
||||
recipe_id?: string;
|
||||
extension_overrides?: ExtensionConfig[];
|
||||
} = {
|
||||
working_dir: workingDir,
|
||||
};
|
||||
|
||||
if (options?.recipeDeeplink) {
|
||||
if (options?.recipeId) {
|
||||
body.recipe_id = options.recipeId;
|
||||
} else if (options?.recipeDeeplink) {
|
||||
body.recipe = await decodeRecipe(options.recipeDeeplink);
|
||||
}
|
||||
|
||||
@@ -79,6 +83,7 @@ export async function startNewSession(
|
||||
workingDir: string,
|
||||
options?: {
|
||||
recipeDeeplink?: string;
|
||||
recipeId?: string;
|
||||
allExtensions?: FixedExtensionEntry[];
|
||||
}
|
||||
): Promise<Session> {
|
||||
|
||||
Reference in New Issue
Block a user