From 1953266bcad6b03b01f27e253813cf4cf246ac4d Mon Sep 17 00:00:00 2001 From: Jack Amadeo Date: Wed, 10 Sep 2025 13:27:06 -0400 Subject: [PATCH] Send the secret with decodeRecipe (#4597) --- ui/desktop/src/main.ts | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index dd3b986a..bab53332 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -51,30 +51,18 @@ import { import { UPDATES_ENABLED } from './updates'; import { Recipe } from './recipe'; import './utils/recipeHash'; +import { decodeRecipe } from './api/sdk.gen'; -// API URL constructor for main process before window is ready -function getApiUrlMain(endpoint: string, dynamicPort: number): string { - const host = process.env.GOOSE_API_HOST || 'http://127.0.0.1'; - const port = dynamicPort || process.env.GOOSE_PORT; - const cleanEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`; - return `${host}:${port}${cleanEndpoint}`; -} - -// When opening the app with a deeplink, the window is still initializing so we have to duplicate some window dependant logic here. -async function decodeRecipeMain(deeplink: string, port: number): Promise { +async function decodeRecipeMain(deeplink: string): Promise { try { - const response = await fetch(getApiUrlMain('/recipes/decode', port), { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ deeplink }), - }); - - if (response.ok) { - const data = await response.json(); - return data.recipe; - } - } catch { - console.error('Failed to decode recipe'); + return ( + await decodeRecipe({ + throwOnError: true, + body: { deeplink }, + }) + ).data.recipe; + } catch (e) { + console.error('Failed to decode recipe:', e); } return null; } @@ -758,7 +746,7 @@ const createChat = async ( console.log('[Main] Starting background recipe decoding for:', recipeDeeplink); // Decode recipe asynchronously after window is created - decodeRecipeMain(recipeDeeplink, port) + decodeRecipeMain(recipeDeeplink) .then((decodedRecipe) => { if (decodedRecipe) { console.log('[Main] Recipe decoded successfully, updating window config');