refactor: Centralise deeplink encode and decode into server (#3489)
This commit is contained in:
@@ -432,7 +432,7 @@ const RecipeEditorRoute = () => {
|
||||
|
||||
if (!config) {
|
||||
const electronConfig = window.electron.getConfig();
|
||||
config = electronConfig.recipeConfig;
|
||||
config = electronConfig.recipe;
|
||||
}
|
||||
|
||||
return <RecipeEditor config={config} />;
|
||||
@@ -758,7 +758,7 @@ export default function App() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const viewType = urlParams.get('view');
|
||||
const resumeSessionId = urlParams.get('resumeSessionId');
|
||||
const recipeConfig = window.appConfig.get('recipeConfig');
|
||||
const recipeConfig = window.appConfig.get('recipe');
|
||||
|
||||
// Check for session resume first - this takes priority over other navigation
|
||||
if (resumeSessionId) {
|
||||
@@ -979,7 +979,7 @@ export default function App() {
|
||||
|
||||
// Handle navigation to pair view for recipe deeplinks after router is ready
|
||||
useEffect(() => {
|
||||
const recipeConfig = window.appConfig.get('recipeConfig');
|
||||
const recipeConfig = window.appConfig.get('recipe');
|
||||
if (
|
||||
recipeConfig &&
|
||||
typeof recipeConfig === 'object' &&
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Recipe } from '../recipe';
|
||||
import { Recipe, generateDeepLink } from '../recipe';
|
||||
import { Parameter } from '../recipe/index';
|
||||
|
||||
import { Buffer } from 'buffer';
|
||||
import { FullExtensionConfig } from '../extensions';
|
||||
import { Geese } from './icons/Geese';
|
||||
import Copy from './icons/Copy';
|
||||
@@ -23,13 +22,6 @@ interface RecipeEditorProps {
|
||||
config?: Recipe;
|
||||
}
|
||||
|
||||
// Function to generate a deep link from a recipe
|
||||
function generateDeepLink(recipe: Recipe): string {
|
||||
const configBase64 = Buffer.from(JSON.stringify(recipe)).toString('base64');
|
||||
const urlSafe = encodeURIComponent(configBase64);
|
||||
return `goose://recipe?config=${urlSafe}`;
|
||||
}
|
||||
|
||||
export default function RecipeEditor({ config }: RecipeEditorProps) {
|
||||
const { getExtensions } = useConfig();
|
||||
const navigate = useNavigate();
|
||||
@@ -58,6 +50,9 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
||||
setValue: (value: string) => void;
|
||||
} | null>(null);
|
||||
|
||||
const [deeplink, setDeeplink] = useState('');
|
||||
const [isGeneratingDeeplink, setIsGeneratingDeeplink] = useState(false);
|
||||
|
||||
// Initialize selected extensions for the recipe from config or localStorage
|
||||
const [recipeExtensions] = useState<string[]>(() => {
|
||||
// First try to get from localStorage
|
||||
@@ -134,7 +129,7 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
||||
setParameters(allParams);
|
||||
}, [instructions, prompt]);
|
||||
|
||||
const getCurrentConfig = (): Recipe => {
|
||||
const getCurrentConfig = useCallback((): Recipe => {
|
||||
// Transform the internal parameters state into the desired output format.
|
||||
const formattedParameters = parameters.map((param) => {
|
||||
const formattedParam: Parameter = {
|
||||
@@ -184,7 +179,62 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
||||
console.log('Final config extensions:', config.extensions);
|
||||
|
||||
return config;
|
||||
};
|
||||
}, [
|
||||
recipeConfig,
|
||||
title,
|
||||
description,
|
||||
instructions,
|
||||
activities,
|
||||
prompt,
|
||||
parameters,
|
||||
recipeExtensions,
|
||||
extensionOptions,
|
||||
]);
|
||||
|
||||
// Generate deeplink whenever recipe configuration changes
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
|
||||
const generateLink = async () => {
|
||||
if (!title.trim() || !description.trim() || !instructions.trim()) {
|
||||
setDeeplink('');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsGeneratingDeeplink(true);
|
||||
try {
|
||||
const currentConfig = getCurrentConfig();
|
||||
const link = await generateDeepLink(currentConfig);
|
||||
if (!isCancelled) {
|
||||
setDeeplink(link);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to generate deeplink:', error);
|
||||
if (!isCancelled) {
|
||||
setDeeplink('Error generating deeplink');
|
||||
}
|
||||
} finally {
|
||||
if (!isCancelled) {
|
||||
setIsGeneratingDeeplink(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
generateLink();
|
||||
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, [
|
||||
title,
|
||||
description,
|
||||
instructions,
|
||||
prompt,
|
||||
activities,
|
||||
parameters,
|
||||
recipeExtensions,
|
||||
getCurrentConfig,
|
||||
]);
|
||||
|
||||
const [errors, setErrors] = useState<{
|
||||
title?: string;
|
||||
@@ -217,9 +267,11 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
||||
);
|
||||
};
|
||||
|
||||
const deeplink = generateDeepLink(getCurrentConfig());
|
||||
|
||||
const handleCopy = () => {
|
||||
if (!deeplink || isGeneratingDeeplink || deeplink === 'Error generating deeplink') {
|
||||
return;
|
||||
}
|
||||
|
||||
navigator.clipboard
|
||||
.writeText(deeplink)
|
||||
.then(() => {
|
||||
@@ -437,6 +489,9 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
||||
onClick={() => validateForm() && handleCopy()}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={
|
||||
!deeplink || isGeneratingDeeplink || deeplink === 'Error generating deeplink'
|
||||
}
|
||||
className="p-2 hover:bg-background-default rounded-lg transition-colors flex items-center disabled:opacity-50 disabled:hover:bg-transparent flex-shrink-0"
|
||||
>
|
||||
{copied ? (
|
||||
@@ -457,7 +512,9 @@ export default function RecipeEditor({ config }: RecipeEditorProps) {
|
||||
className={`text-sm dark:text-white font-mono cursor-pointer hover:bg-background-default p-2 rounded transition-colors overflow-x-auto whitespace-nowrap ${!title.trim() || !description.trim() ? 'text-textDisabled' : 'text-textStandard'}`}
|
||||
style={{ maxWidth: '500px', width: '100%' }}
|
||||
>
|
||||
{deeplink}
|
||||
{isGeneratingDeeplink
|
||||
? 'Generating deeplink...'
|
||||
: deeplink || 'Click to generate deeplink'}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -21,8 +21,7 @@ import { Card } from './ui/card';
|
||||
import { Button } from './ui/button';
|
||||
import { Skeleton } from './ui/skeleton';
|
||||
import { MainPanelLayout } from './Layout/MainPanelLayout';
|
||||
import { Recipe } from '../recipe';
|
||||
import { Buffer } from 'buffer';
|
||||
import { Recipe, decodeRecipe } from '../recipe';
|
||||
import { toastSuccess, toastError } from '../toasts';
|
||||
|
||||
interface RecipesViewProps {
|
||||
@@ -149,7 +148,7 @@ export default function RecipesView({ _onLoadRecipe }: RecipesViewProps = {}) {
|
||||
};
|
||||
|
||||
// Function to parse deeplink and extract recipe
|
||||
const parseDeeplink = (deeplink: string): Recipe | null => {
|
||||
const parseDeeplink = async (deeplink: string): Promise<Recipe | null> => {
|
||||
try {
|
||||
const cleanLink = deeplink.trim();
|
||||
|
||||
@@ -157,15 +156,12 @@ export default function RecipesView({ _onLoadRecipe }: RecipesViewProps = {}) {
|
||||
throw new Error('Invalid deeplink format. Expected: goose://recipe?config=...');
|
||||
}
|
||||
|
||||
// Extract and decode the base64 config
|
||||
const configBase64 = cleanLink.replace('goose://recipe?config=', '');
|
||||
const recipeEncoded = cleanLink.replace('goose://recipe?config=', '');
|
||||
|
||||
if (!configBase64) {
|
||||
if (!recipeEncoded) {
|
||||
throw new Error('No recipe configuration found in deeplink');
|
||||
}
|
||||
const urlDecoded = decodeURIComponent(configBase64);
|
||||
const configJson = Buffer.from(urlDecoded, 'base64').toString('utf-8');
|
||||
const recipe = JSON.parse(configJson) as Recipe;
|
||||
const recipe = await decodeRecipe(recipeEncoded);
|
||||
|
||||
if (!recipe.title || !recipe.description || !recipe.instructions) {
|
||||
throw new Error('Recipe is missing required fields (title, description, instructions)');
|
||||
@@ -185,7 +181,7 @@ export default function RecipesView({ _onLoadRecipe }: RecipesViewProps = {}) {
|
||||
|
||||
setImporting(true);
|
||||
try {
|
||||
const recipe = parseDeeplink(importDeeplink.trim());
|
||||
const recipe = await parseDeeplink(importDeeplink.trim());
|
||||
|
||||
if (!recipe) {
|
||||
throw new Error('Invalid deeplink or recipe format');
|
||||
@@ -228,14 +224,19 @@ export default function RecipesView({ _onLoadRecipe }: RecipesViewProps = {}) {
|
||||
};
|
||||
|
||||
// Auto-generate recipe name when deeplink changes
|
||||
const handleDeeplinkChange = (value: string) => {
|
||||
const handleDeeplinkChange = async (value: string) => {
|
||||
setImportDeeplink(value);
|
||||
|
||||
if (value.trim()) {
|
||||
const recipe = parseDeeplink(value.trim());
|
||||
if (recipe && recipe.title) {
|
||||
const suggestedName = generateRecipeFilename(recipe);
|
||||
setImportRecipeName(suggestedName);
|
||||
try {
|
||||
const recipe = await parseDeeplink(value.trim());
|
||||
if (recipe && recipe.title) {
|
||||
const suggestedName = generateRecipeFilename(recipe);
|
||||
setImportRecipeName(suggestedName);
|
||||
}
|
||||
} catch (error) {
|
||||
// Silently handle parsing errors during auto-suggest
|
||||
console.log('Could not parse deeplink for auto-suggest:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Recipe } from '../recipe';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { Recipe, generateDeepLink } from '../recipe';
|
||||
import { Parameter } from '../recipe/index';
|
||||
import { Buffer } from 'buffer';
|
||||
import { FullExtensionConfig } from '../extensions';
|
||||
import { Geese } from './icons/Geese';
|
||||
import Copy from './icons/Copy';
|
||||
@@ -23,13 +22,6 @@ interface ViewRecipeModalProps {
|
||||
config: Recipe;
|
||||
}
|
||||
|
||||
// Function to generate a deep link from a recipe
|
||||
function generateDeepLink(recipe: Recipe): string {
|
||||
const configBase64 = Buffer.from(JSON.stringify(recipe)).toString('base64');
|
||||
const urlSafe = encodeURIComponent(configBase64);
|
||||
return `goose://recipe?config=${urlSafe}`;
|
||||
}
|
||||
|
||||
export default function ViewRecipeModal({ isOpen, onClose, config }: ViewRecipeModalProps) {
|
||||
const { getExtensions } = useConfig();
|
||||
const [recipeConfig] = useState<Recipe | undefined>(config);
|
||||
@@ -118,7 +110,7 @@ export default function ViewRecipeModal({ isOpen, onClose, config }: ViewRecipeM
|
||||
setParameters(allParams);
|
||||
}, [instructions, prompt]);
|
||||
|
||||
const getCurrentConfig = (): Recipe => {
|
||||
const getCurrentConfig = useCallback((): Recipe => {
|
||||
// Transform the internal parameters state into the desired output format.
|
||||
const formattedParameters = parameters.map((param) => {
|
||||
const formattedParam: Parameter = {
|
||||
@@ -163,7 +155,17 @@ export default function ViewRecipeModal({ isOpen, onClose, config }: ViewRecipeM
|
||||
};
|
||||
|
||||
return updatedConfig;
|
||||
};
|
||||
}, [
|
||||
recipeConfig,
|
||||
title,
|
||||
description,
|
||||
instructions,
|
||||
activities,
|
||||
prompt,
|
||||
parameters,
|
||||
recipeExtensions,
|
||||
extensionOptions,
|
||||
]);
|
||||
|
||||
const [errors, setErrors] = useState<{
|
||||
title?: string;
|
||||
@@ -196,9 +198,59 @@ export default function ViewRecipeModal({ isOpen, onClose, config }: ViewRecipeM
|
||||
);
|
||||
};
|
||||
|
||||
const deeplink = generateDeepLink(getCurrentConfig());
|
||||
const [deeplink, setDeeplink] = useState('');
|
||||
const [isGeneratingDeeplink, setIsGeneratingDeeplink] = useState(false);
|
||||
|
||||
// Generate deeplink whenever recipe configuration changes
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
|
||||
const generateLink = async () => {
|
||||
if (!title.trim() || !description.trim() || !instructions.trim()) {
|
||||
setDeeplink('');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsGeneratingDeeplink(true);
|
||||
try {
|
||||
const currentConfig = getCurrentConfig();
|
||||
const link = await generateDeepLink(currentConfig);
|
||||
if (!isCancelled) {
|
||||
setDeeplink(link);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to generate deeplink:', error);
|
||||
if (!isCancelled) {
|
||||
setDeeplink('Error generating deeplink');
|
||||
}
|
||||
} finally {
|
||||
if (!isCancelled) {
|
||||
setIsGeneratingDeeplink(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
generateLink();
|
||||
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, [
|
||||
title,
|
||||
description,
|
||||
instructions,
|
||||
prompt,
|
||||
activities,
|
||||
parameters,
|
||||
recipeExtensions,
|
||||
getCurrentConfig,
|
||||
]);
|
||||
|
||||
const handleCopy = () => {
|
||||
if (!deeplink || isGeneratingDeeplink || deeplink === 'Error generating deeplink') {
|
||||
return;
|
||||
}
|
||||
|
||||
navigator.clipboard
|
||||
.writeText(deeplink)
|
||||
.then(() => {
|
||||
@@ -430,6 +482,9 @@ export default function ViewRecipeModal({ isOpen, onClose, config }: ViewRecipeM
|
||||
onClick={() => validateForm() && handleCopy()}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={
|
||||
!deeplink || isGeneratingDeeplink || deeplink === 'Error generating deeplink'
|
||||
}
|
||||
className="ml-4 p-2 hover:bg-background-default rounded-lg transition-colors flex items-center disabled:opacity-50 disabled:hover:bg-transparent"
|
||||
>
|
||||
{copied ? (
|
||||
@@ -448,7 +503,9 @@ export default function ViewRecipeModal({ isOpen, onClose, config }: ViewRecipeM
|
||||
onClick={() => validateForm() && handleCopy()}
|
||||
className={`text-sm truncate font-mono cursor-pointer ${!title.trim() || !description.trim() ? 'text-textDisabled' : 'text-textStandard'}`}
|
||||
>
|
||||
{deeplink}
|
||||
{isGeneratingDeeplink
|
||||
? 'Generating deeplink...'
|
||||
: deeplink || 'Click to generate deeplink'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -5,8 +5,7 @@ import { Input } from '../ui/input';
|
||||
import { Select } from '../ui/Select';
|
||||
import cronstrue from 'cronstrue';
|
||||
import * as yaml from 'yaml';
|
||||
import { Buffer } from 'buffer';
|
||||
import { Recipe } from '../../recipe';
|
||||
import { Recipe, decodeRecipe } from '../../recipe';
|
||||
import ClockIcon from '../../assets/clock-icon.svg';
|
||||
|
||||
type FrequencyValue = 'once' | 'every' | 'daily' | 'weekly' | 'monthly';
|
||||
@@ -107,20 +106,19 @@ type SourceType = 'file' | 'deeplink';
|
||||
type ExecutionMode = 'background' | 'foreground';
|
||||
|
||||
// Function to parse deep link and extract recipe config
|
||||
function parseDeepLink(deepLink: string): Recipe | null {
|
||||
async function parseDeepLink(deepLink: string): Promise<Recipe | null> {
|
||||
try {
|
||||
const url = new URL(deepLink);
|
||||
if (url.protocol !== 'goose:' || (url.hostname !== 'bot' && url.hostname !== 'recipe')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const configParam = url.searchParams.get('config');
|
||||
if (!configParam) {
|
||||
const recipeParam = url.searchParams.get('config');
|
||||
if (!recipeParam) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const configJson = Buffer.from(decodeURIComponent(configParam), 'base64').toString('utf-8');
|
||||
return JSON.parse(configJson) as Recipe;
|
||||
return await decodeRecipe(recipeParam);
|
||||
} catch (error) {
|
||||
console.error('Failed to parse deep link:', error);
|
||||
return null;
|
||||
@@ -287,26 +285,33 @@ export const CreateScheduleModal: React.FC<CreateScheduleModalProps> = ({
|
||||
const [internalValidationError, setInternalValidationError] = useState<string | null>(null);
|
||||
|
||||
const handleDeepLinkChange = useCallback(
|
||||
(value: string) => {
|
||||
async (value: string) => {
|
||||
setDeepLinkInput(value);
|
||||
setInternalValidationError(null);
|
||||
|
||||
if (value.trim()) {
|
||||
const recipe = parseDeepLink(value.trim());
|
||||
if (recipe) {
|
||||
setParsedRecipe(recipe);
|
||||
// Auto-populate schedule ID from recipe title if available
|
||||
if (recipe.title && !scheduleId) {
|
||||
const cleanId = recipe.title
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9-]/g, '-')
|
||||
.replace(/-+/g, '-');
|
||||
setScheduleId(cleanId);
|
||||
try {
|
||||
const recipe = await parseDeepLink(value.trim());
|
||||
if (recipe) {
|
||||
setParsedRecipe(recipe);
|
||||
// Auto-populate schedule ID from recipe title if available
|
||||
if (recipe.title && !scheduleId) {
|
||||
const cleanId = recipe.title
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9-]/g, '-')
|
||||
.replace(/-+/g, '-');
|
||||
setScheduleId(cleanId);
|
||||
}
|
||||
} else {
|
||||
setParsedRecipe(null);
|
||||
setInternalValidationError(
|
||||
'Invalid deep link format. Please use a goose://bot or goose://recipe link.'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
} catch (error) {
|
||||
setParsedRecipe(null);
|
||||
setInternalValidationError(
|
||||
'Invalid deep link format. Please use a goose://bot or goose://recipe link.'
|
||||
'Failed to parse deep link. Please ensure using a goose://bot or goose://recipe link and try again.'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -2,8 +2,7 @@ import React, { useState, useEffect } from 'react';
|
||||
import { Card } from '../ui/card';
|
||||
import { Button } from '../ui/button';
|
||||
import { Input } from '../ui/input';
|
||||
import { Recipe } from '../../recipe';
|
||||
import { generateDeepLink } from '../ui/DeepLinkModal';
|
||||
import { Recipe, generateDeepLink } from '../../recipe';
|
||||
import Copy from '../icons/Copy';
|
||||
import { Check } from 'lucide-react';
|
||||
|
||||
@@ -24,24 +23,29 @@ export const ScheduleFromRecipeModal: React.FC<ScheduleFromRecipeModalProps> = (
|
||||
const [deepLink, setDeepLink] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && recipe) {
|
||||
// Convert Recipe to the format expected by generateDeepLink
|
||||
const recipeConfig = {
|
||||
id: recipe.title?.toLowerCase().replace(/[^a-z0-9-]/g, '-') || 'recipe',
|
||||
title: recipe.title,
|
||||
description: recipe.description,
|
||||
instructions: recipe.instructions,
|
||||
activities: recipe.activities || [],
|
||||
prompt: recipe.prompt,
|
||||
extensions: recipe.extensions,
|
||||
goosehints: recipe.goosehints,
|
||||
context: recipe.context,
|
||||
profile: recipe.profile,
|
||||
author: recipe.author,
|
||||
};
|
||||
const link = generateDeepLink(recipeConfig);
|
||||
setDeepLink(link);
|
||||
}
|
||||
let isCancelled = false;
|
||||
|
||||
const generateLink = async () => {
|
||||
if (isOpen && recipe) {
|
||||
try {
|
||||
const link = await generateDeepLink(recipe);
|
||||
if (!isCancelled) {
|
||||
setDeepLink(link);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to generate deeplink:', error);
|
||||
if (!isCancelled) {
|
||||
setDeepLink('Error generating deeplink');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
generateLink();
|
||||
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, [isOpen, recipe]);
|
||||
|
||||
const handleCopy = () => {
|
||||
|
||||
@@ -1,42 +1,60 @@
|
||||
import React, { useMemo, useState, useEffect, useRef } from 'react';
|
||||
import { Buffer } from 'buffer';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import Copy from '../icons/Copy';
|
||||
import { Card } from './card';
|
||||
|
||||
interface RecipeConfig {
|
||||
instructions?: string;
|
||||
activities?: string[];
|
||||
[key: string]: unknown;
|
||||
}
|
||||
import { Recipe, generateDeepLink } from '../../recipe';
|
||||
|
||||
interface DeepLinkModalProps {
|
||||
recipeConfig: RecipeConfig;
|
||||
recipe: Recipe;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
// Function to generate a deep link from a bot config
|
||||
export function generateDeepLink(recipeConfig: RecipeConfig): string {
|
||||
const configBase64 = Buffer.from(JSON.stringify(recipeConfig)).toString('base64');
|
||||
const urlSafe = encodeURIComponent(configBase64);
|
||||
return `goose://bot?config=${urlSafe}`;
|
||||
}
|
||||
|
||||
export function DeepLinkModal({ recipeConfig: initialRecipeConfig, onClose }: DeepLinkModalProps) {
|
||||
// Create editable state for the bot config
|
||||
const [recipeConfig, setRecipeConfig] = useState(initialRecipeConfig);
|
||||
const [instructions, setInstructions] = useState(initialRecipeConfig.instructions || '');
|
||||
const [activities, setActivities] = useState<string[]>(initialRecipeConfig.activities || []);
|
||||
export function DeepLinkModal({ recipe: initialRecipe, onClose }: DeepLinkModalProps) {
|
||||
// Create editable state for the recipe
|
||||
const [recipe, setRecipe] = useState(initialRecipe);
|
||||
const [instructions, setInstructions] = useState(initialRecipe.instructions || '');
|
||||
const [activities, setActivities] = useState<string[]>(initialRecipe.activities || []);
|
||||
const [activityInput, setActivityInput] = useState('');
|
||||
|
||||
// State for the deep link
|
||||
const [deepLink, setDeepLink] = useState('');
|
||||
const [isGeneratingLink, setIsGeneratingLink] = useState(false);
|
||||
|
||||
// Generate the deep link using the current bot config
|
||||
const deepLink = useMemo(() => {
|
||||
const currentConfig = {
|
||||
...recipeConfig,
|
||||
instructions,
|
||||
activities,
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
|
||||
const generateLink = async () => {
|
||||
setIsGeneratingLink(true);
|
||||
try {
|
||||
const currentConfig = {
|
||||
...recipe,
|
||||
instructions,
|
||||
activities,
|
||||
title: recipe.title || 'Generated Recipe',
|
||||
description: recipe.description || 'Recipe created from chat',
|
||||
};
|
||||
const link = await generateDeepLink(currentConfig);
|
||||
if (!isCancelled) {
|
||||
setDeepLink(link);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to generate deeplink:', error);
|
||||
if (!isCancelled) {
|
||||
setDeepLink('Error generating deeplink');
|
||||
}
|
||||
} finally {
|
||||
if (!isCancelled) {
|
||||
setIsGeneratingLink(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
return generateDeepLink(currentConfig);
|
||||
}, [recipeConfig, instructions, activities]);
|
||||
|
||||
generateLink();
|
||||
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, [recipe, instructions, activities]);
|
||||
|
||||
// Handle Esc key press
|
||||
useEffect(() => {
|
||||
@@ -55,10 +73,10 @@ export function DeepLinkModal({ recipeConfig: initialRecipeConfig, onClose }: De
|
||||
};
|
||||
}, [onClose]);
|
||||
|
||||
// Update the bot config when instructions or activities change
|
||||
// Update the recipe when instructions or activities change
|
||||
useEffect(() => {
|
||||
setRecipeConfig({
|
||||
...recipeConfig,
|
||||
setRecipe({
|
||||
...recipe,
|
||||
instructions,
|
||||
activities,
|
||||
});
|
||||
@@ -114,16 +132,21 @@ export function DeepLinkModal({ recipeConfig: initialRecipeConfig, onClose }: De
|
||||
<div className="flex items-center">
|
||||
<input
|
||||
type="text"
|
||||
value={deepLink}
|
||||
value={isGeneratingLink ? 'Generating deeplink...' : deepLink}
|
||||
readOnly
|
||||
className="flex-1 p-3 border border-borderSubtle rounded-l-md bg-transparent text-textStandard"
|
||||
/>
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(deepLink);
|
||||
window.electron.logInfo('Deep link copied to clipboard');
|
||||
if (!isGeneratingLink && deepLink && deepLink !== 'Error generating deeplink') {
|
||||
navigator.clipboard.writeText(deepLink);
|
||||
window.electron.logInfo('Deep link copied to clipboard');
|
||||
}
|
||||
}}
|
||||
className="p-2 bg-blue-500 text-white rounded-r-md hover:bg-blue-600 flex items-center justify-center min-w-[100px]"
|
||||
disabled={
|
||||
isGeneratingLink || !deepLink || deepLink === 'Error generating deeplink'
|
||||
}
|
||||
className="p-2 bg-blue-500 text-white rounded-r-md hover:bg-blue-600 flex items-center justify-center min-w-[100px] disabled:bg-gray-400 disabled:cursor-not-allowed"
|
||||
>
|
||||
<Copy className="w-5 h-5 mr-1" />
|
||||
Copy
|
||||
@@ -135,15 +158,13 @@ export function DeepLinkModal({ recipeConfig: initialRecipeConfig, onClose }: De
|
||||
<div className="flex mb-6">
|
||||
<button
|
||||
onClick={() => {
|
||||
// Open the deep link with the current bot config
|
||||
// Open the deep link with the current recipe config
|
||||
const currentConfig = {
|
||||
id: 'deeplink-recipe',
|
||||
name: 'DeepLink Recipe',
|
||||
title: 'DeepLink Recipe',
|
||||
description: 'Recipe from deep link',
|
||||
...recipeConfig,
|
||||
...recipe,
|
||||
instructions,
|
||||
activities,
|
||||
title: recipe.title || 'DeepLink Recipe',
|
||||
description: recipe.description || 'Recipe from deep link',
|
||||
};
|
||||
window.electron.createChatWindow(
|
||||
undefined,
|
||||
|
||||
@@ -46,7 +46,7 @@ export const useRecipeManager = (messages: Message[], locationState?: LocationSt
|
||||
}
|
||||
|
||||
// Fallback to app config (from deeplinks)
|
||||
const appRecipeConfig = window.appConfig.get('recipeConfig') as Recipe | null;
|
||||
const appRecipeConfig = window.appConfig.get('recipe') as Recipe | null;
|
||||
if (appRecipeConfig) {
|
||||
return appRecipeConfig;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ export const useRecipeManager = (messages: Message[], locationState?: LocationSt
|
||||
|
||||
// If we have a recipe from app config (deeplink), persist it
|
||||
// But only if the chat context doesn't explicitly have null (which indicates it was cleared)
|
||||
const appRecipeConfig = window.appConfig.get('recipeConfig') as Recipe | null;
|
||||
const appRecipeConfig = window.appConfig.get('recipe') as Recipe | null;
|
||||
if (appRecipeConfig && chatContext.chat.recipeConfig === undefined) {
|
||||
// Only set if recipeConfig is undefined, not if it's explicitly null
|
||||
chatContext.setRecipeConfig(appRecipeConfig);
|
||||
@@ -197,16 +197,6 @@ export const useRecipeManager = (messages: Message[], locationState?: LocationSt
|
||||
throw new Error('No recipe data received');
|
||||
}
|
||||
|
||||
// Create a new window for the recipe editor
|
||||
const recipeConfig = {
|
||||
id: response.recipe.title || 'untitled',
|
||||
title: response.recipe.title || 'Untitled Recipe',
|
||||
description: response.recipe.description || '',
|
||||
instructions: response.recipe.instructions || '',
|
||||
activities: response.recipe.activities || [],
|
||||
prompt: response.recipe.prompt || '',
|
||||
};
|
||||
|
||||
// Set a flag to prevent the current window from reacting to recipe config changes
|
||||
// This prevents navigation conflicts when creating new windows
|
||||
window.sessionStorage.setItem('ignoreRecipeConfigChanges', 'true');
|
||||
@@ -217,7 +207,7 @@ export const useRecipeManager = (messages: Message[], locationState?: LocationSt
|
||||
undefined, // dir
|
||||
undefined, // version
|
||||
undefined, // resumeSessionId
|
||||
recipeConfig, // recipe config
|
||||
response.recipe, // recipe config
|
||||
'recipeEditor' // view type
|
||||
);
|
||||
|
||||
|
||||
+106
-91
@@ -49,6 +49,34 @@ import {
|
||||
getUpdateAvailable,
|
||||
} from './utils/autoUpdater';
|
||||
import { UPDATES_ENABLED } from './updates';
|
||||
import { Recipe } from './recipe';
|
||||
|
||||
// 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<Recipe | null> {
|
||||
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 (error) {
|
||||
console.error('Failed to decode recipe:', error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Updater functions (moved here to keep updates.ts minimal for release replacement)
|
||||
function shouldSetupUpdater(): boolean {
|
||||
@@ -171,31 +199,24 @@ if (process.platform === 'win32') {
|
||||
|
||||
// If it's a bot/recipe URL, handle it directly by creating a new window
|
||||
if (parsedUrl.hostname === 'bot' || parsedUrl.hostname === 'recipe') {
|
||||
app.whenReady().then(() => {
|
||||
app.whenReady().then(async () => {
|
||||
const recentDirs = loadRecentDirs();
|
||||
const openDir = recentDirs.length > 0 ? recentDirs[0] : null;
|
||||
|
||||
let recipeConfig = null;
|
||||
const configParam = parsedUrl.searchParams.get('config');
|
||||
if (configParam) {
|
||||
try {
|
||||
recipeConfig = JSON.parse(
|
||||
Buffer.from(decodeURIComponent(configParam), 'base64').toString('utf-8')
|
||||
);
|
||||
const recipeDeeplink = parsedUrl.searchParams.get('config');
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
|
||||
// Check if this is a scheduled job
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
if (scheduledJobId) {
|
||||
console.log(`[main] Opening scheduled job: ${scheduledJobId}`);
|
||||
recipeConfig.scheduledJobId = scheduledJobId;
|
||||
recipeConfig.isScheduledExecution = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to parse bot config:', e);
|
||||
}
|
||||
}
|
||||
|
||||
createChat(app, undefined, openDir || undefined, undefined, undefined, recipeConfig);
|
||||
createChat(
|
||||
app,
|
||||
undefined,
|
||||
openDir || undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
recipeDeeplink || undefined,
|
||||
scheduledJobId || undefined
|
||||
);
|
||||
});
|
||||
return; // Skip the rest of the handler
|
||||
}
|
||||
@@ -244,7 +265,7 @@ async function handleProtocolUrl(url: string) {
|
||||
existingWindows.length > 0
|
||||
? existingWindows[0]
|
||||
: await createChat(app, undefined, openDir || undefined);
|
||||
processProtocolUrl(parsedUrl, targetWindow);
|
||||
await processProtocolUrl(parsedUrl, targetWindow);
|
||||
} else {
|
||||
// For other URL types, reuse existing window if available
|
||||
const existingWindows = BrowserWindow.getAllWindows();
|
||||
@@ -261,17 +282,17 @@ async function handleProtocolUrl(url: string) {
|
||||
if (firstOpenWindow) {
|
||||
const webContents = firstOpenWindow.webContents;
|
||||
if (webContents.isLoadingMainFrame()) {
|
||||
webContents.once('did-finish-load', () => {
|
||||
processProtocolUrl(parsedUrl, firstOpenWindow);
|
||||
webContents.once('did-finish-load', async () => {
|
||||
await processProtocolUrl(parsedUrl, firstOpenWindow);
|
||||
});
|
||||
} else {
|
||||
processProtocolUrl(parsedUrl, firstOpenWindow);
|
||||
await processProtocolUrl(parsedUrl, firstOpenWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function processProtocolUrl(parsedUrl: URL, window: BrowserWindow) {
|
||||
async function processProtocolUrl(parsedUrl: URL, window: BrowserWindow) {
|
||||
const recentDirs = loadRecentDirs();
|
||||
const openDir = recentDirs.length > 0 ? recentDirs[0] : null;
|
||||
|
||||
@@ -280,27 +301,21 @@ function processProtocolUrl(parsedUrl: URL, window: BrowserWindow) {
|
||||
} else if (parsedUrl.hostname === 'sessions') {
|
||||
window.webContents.send('open-shared-session', pendingDeepLink);
|
||||
} else if (parsedUrl.hostname === 'bot' || parsedUrl.hostname === 'recipe') {
|
||||
let recipeConfig = null;
|
||||
const configParam = parsedUrl.searchParams.get('config');
|
||||
if (configParam) {
|
||||
try {
|
||||
recipeConfig = JSON.parse(
|
||||
Buffer.from(decodeURIComponent(configParam), 'base64').toString('utf-8')
|
||||
);
|
||||
const recipeDeeplink = parsedUrl.searchParams.get('config');
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
|
||||
// Check if this is a scheduled job
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
if (scheduledJobId) {
|
||||
console.log(`[main] Opening scheduled job: ${scheduledJobId}`);
|
||||
recipeConfig.scheduledJobId = scheduledJobId;
|
||||
recipeConfig.isScheduledExecution = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to parse bot config:', e);
|
||||
}
|
||||
}
|
||||
// Create a new window and ignore the passed-in window
|
||||
createChat(app, undefined, openDir || undefined, undefined, undefined, recipeConfig);
|
||||
createChat(
|
||||
app,
|
||||
undefined,
|
||||
openDir || undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
recipeDeeplink || undefined,
|
||||
scheduledJobId || undefined
|
||||
);
|
||||
}
|
||||
pendingDeepLink = null;
|
||||
}
|
||||
@@ -312,28 +327,24 @@ app.on('open-url', async (_event, url) => {
|
||||
const openDir = recentDirs.length > 0 ? recentDirs[0] : null;
|
||||
|
||||
// Handle bot/recipe URLs by directly creating a new window
|
||||
console.log('[Main] Received open-url event:', url);
|
||||
if (parsedUrl.hostname === 'bot' || parsedUrl.hostname === 'recipe') {
|
||||
let recipeConfig = null;
|
||||
const configParam = parsedUrl.searchParams.get('config');
|
||||
const base64 = decodeURIComponent(configParam || '');
|
||||
if (configParam) {
|
||||
try {
|
||||
recipeConfig = JSON.parse(Buffer.from(base64, 'base64').toString('utf-8'));
|
||||
|
||||
// Check if this is a scheduled job
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
if (scheduledJobId) {
|
||||
console.log(`[main] Opening scheduled job: ${scheduledJobId}`);
|
||||
recipeConfig.scheduledJobId = scheduledJobId;
|
||||
recipeConfig.isScheduledExecution = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to parse bot config:', e);
|
||||
}
|
||||
}
|
||||
console.log('[Main] Detected bot/recipe URL, creating new chat window');
|
||||
const recipeDeeplink = parsedUrl.searchParams.get('config');
|
||||
const scheduledJobId = parsedUrl.searchParams.get('scheduledJob');
|
||||
|
||||
// Create a new window directly
|
||||
await createChat(app, undefined, openDir || undefined, undefined, undefined, recipeConfig);
|
||||
await createChat(
|
||||
app,
|
||||
undefined,
|
||||
openDir || undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
recipeDeeplink || undefined,
|
||||
scheduledJobId || undefined
|
||||
);
|
||||
return; // Skip the rest of the handler
|
||||
}
|
||||
|
||||
@@ -497,23 +508,16 @@ const windowMap = new Map<number, BrowserWindow>();
|
||||
// Track power save blocker ID globally
|
||||
let powerSaveBlockerId: number | null = null;
|
||||
|
||||
interface RecipeConfig {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
instructions: string;
|
||||
activities: string[];
|
||||
prompt: string;
|
||||
}
|
||||
|
||||
const createChat = async (
|
||||
app: App,
|
||||
query?: string,
|
||||
dir?: string,
|
||||
_version?: string,
|
||||
resumeSessionId?: string,
|
||||
recipeConfig?: RecipeConfig, // Bot configuration
|
||||
viewType?: string // View type
|
||||
recipe?: Recipe, // Recipe configuration when already loaded, takes precedence over deeplink
|
||||
viewType?: string,
|
||||
recipeDeeplink?: string, // Raw deeplink used as a fallback when recipe is not loaded. Required on new windows as we need to wait for the window to load before decoding.
|
||||
scheduledJobId?: string // Scheduled job ID if applicable
|
||||
) => {
|
||||
// Initialize variables for process and configuration
|
||||
let port = 0;
|
||||
@@ -560,6 +564,20 @@ const createChat = async (
|
||||
goosedProcess = newGoosedProcess;
|
||||
}
|
||||
|
||||
// Decode recipe from deeplink if needed
|
||||
if (!recipe && recipeDeeplink) {
|
||||
const decodedRecipe = await decodeRecipeMain(recipeDeeplink, port);
|
||||
if (decodedRecipe) {
|
||||
recipe = decodedRecipe;
|
||||
|
||||
// Handle scheduled job parameters if present
|
||||
if (scheduledJobId) {
|
||||
recipe.scheduledJobId = scheduledJobId;
|
||||
recipe.isScheduledExecution = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load and manage window state
|
||||
const mainWindowState = windowStateKeeper({
|
||||
defaultWidth: 940, // large enough to show the sidebar on launch
|
||||
@@ -594,7 +612,7 @@ const createChat = async (
|
||||
REQUEST_DIR: dir,
|
||||
GOOSE_BASE_URL_SHARE: sharingUrl,
|
||||
GOOSE_VERSION: gooseVersion,
|
||||
recipeConfig: recipeConfig,
|
||||
recipe: recipe,
|
||||
}),
|
||||
],
|
||||
partition: 'persist:goose', // Add this line to ensure persistence
|
||||
@@ -648,7 +666,7 @@ const createChat = async (
|
||||
GOOSE_WORKING_DIR: working_dir,
|
||||
REQUEST_DIR: dir,
|
||||
GOOSE_BASE_URL_SHARE: sharingUrl,
|
||||
recipeConfig: recipeConfig,
|
||||
recipe: recipe,
|
||||
};
|
||||
|
||||
// We need to wait for the window to load before we can access localStorage
|
||||
@@ -1873,21 +1891,18 @@ app.whenReady().then(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(
|
||||
'create-chat-window',
|
||||
(_, query, dir, version, resumeSessionId, recipeConfig, viewType) => {
|
||||
if (!dir?.trim()) {
|
||||
const recentDirs = loadRecentDirs();
|
||||
dir = recentDirs.length > 0 ? recentDirs[0] : null;
|
||||
}
|
||||
|
||||
// Log the recipeConfig for debugging
|
||||
console.log('Creating chat window with recipeConfig:', recipeConfig);
|
||||
|
||||
// Pass recipeConfig as part of viewOptions when viewType is recipeEditor
|
||||
createChat(app, query, dir, version, resumeSessionId, recipeConfig, viewType);
|
||||
ipcMain.on('create-chat-window', (_, query, dir, version, resumeSessionId, recipe, viewType) => {
|
||||
if (!dir?.trim()) {
|
||||
const recentDirs = loadRecentDirs();
|
||||
dir = recentDirs.length > 0 ? recentDirs[0] : undefined;
|
||||
}
|
||||
);
|
||||
|
||||
// Log the recipe for debugging
|
||||
console.log('Creating chat window with recipe:', recipe);
|
||||
|
||||
// Pass recipe as part of viewOptions when viewType is recipeEditor
|
||||
createChat(app, query, dir, version, resumeSessionId, recipe, viewType);
|
||||
});
|
||||
|
||||
ipcMain.on('notify', (_event, data) => {
|
||||
try {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import Electron, { contextBridge, ipcRenderer, webUtils } from 'electron';
|
||||
import { Recipe } from './recipe';
|
||||
|
||||
// RecipeConfig is used for window creation and should match Recipe interface
|
||||
type RecipeConfig = Recipe;
|
||||
|
||||
interface NotificationData {
|
||||
title: string;
|
||||
body: string;
|
||||
@@ -55,7 +52,7 @@ type ElectronAPI = {
|
||||
dir?: string,
|
||||
version?: string,
|
||||
resumeSessionId?: string,
|
||||
recipeConfig?: RecipeConfig,
|
||||
recipe?: Recipe,
|
||||
viewType?: string
|
||||
) => void;
|
||||
logInfo: (txt: string) => void;
|
||||
@@ -139,18 +136,10 @@ const electronAPI: ElectronAPI = {
|
||||
dir?: string,
|
||||
version?: string,
|
||||
resumeSessionId?: string,
|
||||
recipeConfig?: RecipeConfig,
|
||||
recipe?: Recipe,
|
||||
viewType?: string
|
||||
) =>
|
||||
ipcRenderer.send(
|
||||
'create-chat-window',
|
||||
query,
|
||||
dir,
|
||||
version,
|
||||
resumeSessionId,
|
||||
recipeConfig,
|
||||
viewType
|
||||
),
|
||||
ipcRenderer.send('create-chat-window', query, dir, version, resumeSessionId, recipe, viewType),
|
||||
logInfo: (txt: string) => ipcRenderer.send('logInfo', txt),
|
||||
showNotification: (data: NotificationData) => ipcRenderer.send('notify', data),
|
||||
showMessageBox: (options: MessageBoxOptions) => ipcRenderer.invoke('show-message-box', options),
|
||||
|
||||
@@ -72,3 +72,71 @@ export async function createRecipe(request: CreateRecipeRequest): Promise<Create
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export interface EncodeRecipeRequest {
|
||||
recipe: Recipe;
|
||||
}
|
||||
|
||||
export interface EncodeRecipeResponse {
|
||||
deeplink: string;
|
||||
}
|
||||
|
||||
export interface DecodeRecipeRequest {
|
||||
deeplink: string;
|
||||
}
|
||||
|
||||
export interface DecodeRecipeResponse {
|
||||
recipe: Recipe;
|
||||
}
|
||||
|
||||
export async function encodeRecipe(recipe: Recipe): Promise<string> {
|
||||
const url = getApiUrl('/recipes/encode');
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ recipe } as EncodeRecipeRequest),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to encode recipe: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data: EncodeRecipeResponse = await response.json();
|
||||
return data.deeplink;
|
||||
}
|
||||
|
||||
export async function decodeRecipe(deeplink: string): Promise<Recipe> {
|
||||
const url = getApiUrl('/recipes/decode');
|
||||
|
||||
console.log('Decoding recipe from deeplink:', deeplink);
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ deeplink } as DecodeRecipeRequest),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Failed to decode deeplink:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
});
|
||||
throw new Error(`Failed to decode deeplink: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data: DecodeRecipeResponse = await response.json();
|
||||
if (!data.recipe) {
|
||||
console.error('Decoded recipe is null:', data);
|
||||
throw new Error('Decoded recipe is null');
|
||||
}
|
||||
return data.recipe;
|
||||
}
|
||||
|
||||
export async function generateDeepLink(recipe: Recipe): Promise<string> {
|
||||
const encoded = await encodeRecipe(recipe);
|
||||
return `goose://recipe?config=${encoded}`;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ export const updateSystemPromptWithParameters = async (
|
||||
recipeParameters: Record<string, string>
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const recipeConfig = window.appConfig?.get?.('recipeConfig');
|
||||
const recipeConfig = window.appConfig?.get?.('recipe');
|
||||
const originalInstructions = (recipeConfig as { instructions?: string })?.instructions;
|
||||
|
||||
if (!originalInstructions) {
|
||||
@@ -189,7 +189,7 @@ export const initializeSystem = async (
|
||||
await initializeAgent({ provider, model });
|
||||
|
||||
// Get recipeConfig directly here
|
||||
const recipeConfig = window.appConfig?.get?.('recipeConfig');
|
||||
const recipeConfig = window.appConfig?.get?.('recipe');
|
||||
const botPrompt = (recipeConfig as { instructions?: string })?.instructions;
|
||||
const responseConfig = (recipeConfig as { response?: { json_schema?: unknown } })?.response;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user