chore: Initial pass at cleanup of initializeAgent (#1888)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ExtensionConfig } from '../../../api/types.gen';
|
||||
import { getApiUrl, getSecretKey } from '../../../config';
|
||||
import { toastService, ToastServiceOptions } from '../../../toasts';
|
||||
import { replaceWithShims } from './utils';
|
||||
|
||||
/**
|
||||
* Makes an API call to the extension endpoints
|
||||
@@ -166,19 +167,3 @@ export async function removeFromAgent(
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the path to the binary based on the command
|
||||
async function replaceWithShims(cmd: string): Promise<string> {
|
||||
const binaryPathMap: Record<string, string> = {
|
||||
goosed: await window.electron.getBinaryPath('goosed'),
|
||||
npx: await window.electron.getBinaryPath('npx'),
|
||||
uvx: await window.electron.getBinaryPath('uvx'),
|
||||
};
|
||||
|
||||
if (binaryPathMap[cmd]) {
|
||||
console.log('--------> Replacing command with shim ------>', cmd, binaryPathMap[cmd]);
|
||||
return binaryPathMap[cmd];
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@@ -127,3 +127,19 @@ export function extractExtensionConfig(fixedEntry: FixedExtensionEntry): Extensi
|
||||
const { enabled, ...extensionConfig } = fixedEntry;
|
||||
return extensionConfig;
|
||||
}
|
||||
|
||||
export async function replaceWithShims(cmd: string) {
|
||||
const binaryPathMap: Record<string, string> = {
|
||||
goosed: await window.electron.getBinaryPath('goosed'),
|
||||
jbang: await window.electron.getBinaryPath('jbang'),
|
||||
npx: await window.electron.getBinaryPath('npx'),
|
||||
uvx: await window.electron.getBinaryPath('uvx'),
|
||||
};
|
||||
|
||||
if (binaryPathMap[cmd]) {
|
||||
console.log('--------> Replacing command with shim ------>', cmd, binaryPathMap[cmd]);
|
||||
cmd = binaryPathMap[cmd];
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import BackButton from '../../ui/BackButton';
|
||||
import ProviderGrid from './ProviderGrid';
|
||||
import { useConfig } from '../../ConfigContext';
|
||||
import { ProviderDetails } from '../../../api/types.gen';
|
||||
import { useAgent } from '../../../agent/UpdateAgent';
|
||||
import { initializeAgent } from '../../../agent/';
|
||||
import WelcomeGooseLogo from '../../WelcomeGooseLogo';
|
||||
|
||||
interface ProviderSettingsProps {
|
||||
@@ -14,7 +14,6 @@ interface ProviderSettingsProps {
|
||||
|
||||
export default function ProviderSettings({ onClose, isOnboarding }: ProviderSettingsProps) {
|
||||
const { getProviders, upsert } = useConfig();
|
||||
const { initializeAgent } = useAgent();
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [providers, setProviders] = useState<ProviderDetails[]>([]);
|
||||
const initialLoadDone = useRef(false);
|
||||
@@ -70,7 +69,7 @@ export default function ProviderSettings({ onClose, isOnboarding }: ProviderSett
|
||||
);
|
||||
|
||||
// initialize agent
|
||||
await initializeAgent(provider_name, model);
|
||||
await initializeAgent({ provider: provider.name, model });
|
||||
} catch (error) {
|
||||
console.error(`Failed to initialize with provider ${provider_name}:`, error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user