mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Remember the chosen project template
This commit is contained in:
6 files changed
+121
-20
No files matched your search
@@ -264,7 +264,11 @@ describe('useGenerateProjectInfo', () => {
|
||||
|
||||
expect(projectInfo).toEqual({
|
||||
projectId: 'test-project-name',
|
||||
templateUrl: 'https://gitlab.com/soapbox-pub/mkstack.git'
|
||||
template: {
|
||||
name: 'MKStack',
|
||||
description: 'Build Nostr clients with React.',
|
||||
url: 'https://gitlab.com/soapbox-pub/mkstack.git'
|
||||
}
|
||||
});
|
||||
expect(mockParseProviderModel).toHaveBeenCalledWith('openai/gpt-4', [
|
||||
{ id: 'openai', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
@@ -325,7 +329,7 @@ describe('useGenerateProjectInfo', () => {
|
||||
|
||||
const projectInfo = await result.current.generateProjectInfo('openai/gpt-4', 'test prompt');
|
||||
|
||||
expect(projectInfo.templateUrl).toBe('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
expect(projectInfo.template.url).toBe('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
expect(projectInfo.projectId).toBe('untitled');
|
||||
});
|
||||
|
||||
@@ -363,7 +367,7 @@ describe('useGenerateProjectInfo', () => {
|
||||
const projectInfo = await result.current.generateProjectInfo('openai/gpt-4', 'test prompt');
|
||||
|
||||
expect(projectInfo.projectId).toBe('untitled');
|
||||
expect(projectInfo.templateUrl).toBe('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
expect(projectInfo.template.url).toBe('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
expect(mockGetProject).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
@@ -450,7 +454,11 @@ describe('useGenerateProjectInfo', () => {
|
||||
|
||||
expect(projectInfo).toEqual({
|
||||
projectId: 'vanilla-app',
|
||||
templateUrl: 'https://github.com/example/vanilla-template.git'
|
||||
template: {
|
||||
name: 'VanillaJS',
|
||||
description: 'Simple vanilla JavaScript template.',
|
||||
url: 'https://github.com/example/vanilla-template.git'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -13,7 +13,11 @@ interface UseGenerateProjectInfoOptions {
|
||||
|
||||
interface ProjectInfo {
|
||||
projectId: string;
|
||||
templateUrl: string;
|
||||
template: {
|
||||
name: string;
|
||||
description: string;
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function useGenerateProjectInfo({ onError }: UseGenerateProjectInfoOptions = {}) {
|
||||
@@ -24,7 +28,7 @@ export function useGenerateProjectInfo({ onError }: UseGenerateProjectInfoOption
|
||||
const projectsManager = useProjectsManager();
|
||||
|
||||
// Helper function to generate untitled project name
|
||||
const fallbackWithUntitled = useCallback(async (templateUrl: string): Promise<ProjectInfo> => {
|
||||
const fallbackWithUntitled = useCallback(async (template: { url: string; name: string; description: string }): Promise<ProjectInfo> => {
|
||||
let fallbackId = 'untitled';
|
||||
let counter = 1;
|
||||
|
||||
@@ -40,7 +44,7 @@ export function useGenerateProjectInfo({ onError }: UseGenerateProjectInfoOption
|
||||
|
||||
return {
|
||||
projectId: fallbackId,
|
||||
templateUrl,
|
||||
template,
|
||||
};
|
||||
}, [projectsManager]);
|
||||
|
||||
@@ -126,8 +130,7 @@ You MUST call the create_project tool with your choices.`;
|
||||
if (!selectedTemplate) {
|
||||
// Fallback to first template if invalid URL selected
|
||||
console.warn(`Invalid template URL selected: ${templateUrl}, falling back to first template`);
|
||||
const fallbackTemplate = config.templates[0];
|
||||
return await fallbackWithUntitled(fallbackTemplate.url);
|
||||
return await fallbackWithUntitled(config.templates[0]);
|
||||
}
|
||||
|
||||
// Validate the generated project ID
|
||||
@@ -139,14 +142,14 @@ You MUST call the create_project tool with your choices.`;
|
||||
// Valid and unique project ID
|
||||
return {
|
||||
projectId,
|
||||
templateUrl: selectedTemplate.url,
|
||||
template: selectedTemplate,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// If we reach here, either the regex failed or the project already exists
|
||||
// Fall back to "untitled" with number suffixes
|
||||
return await fallbackWithUntitled(selectedTemplate.url);
|
||||
return await fallbackWithUntitled(selectedTemplate);
|
||||
} catch (error) {
|
||||
// On any error, fall back to first template with untitled name
|
||||
console.error('Error generating project info:', error);
|
||||
@@ -157,7 +160,7 @@ You MUST call the create_project tool with your choices.`;
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return await fallbackWithUntitled(config.templates[0].url);
|
||||
return await fallbackWithUntitled(config.templates[0]);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user