diff --git a/libs/remix-ai-core/src/agents/workspaceAgent.ts b/libs/remix-ai-core/src/agents/workspaceAgent.ts index 22734832c63..32cb10b02c6 100644 --- a/libs/remix-ai-core/src/agents/workspaceAgent.ts +++ b/libs/remix-ai-core/src/agents/workspaceAgent.ts @@ -93,16 +93,51 @@ export class workspaceAgent { if (typeof payload === 'string') { payload = JSON.parse(payload) } - let modifiedFilesMarkdown = '### List of Modified Files\n' + let modifiedFilesMarkdown = '#### **List of Modified Files**\n' + let createdFilesMarkdown = '#### **List of Created Files**\n' + let hasCreatedFiles = false + for (const file of payload.files) { if (!Object.values(SupportedFileExtensions).some(ext => file.fileName.endsWith(ext))) continue; - // const fileContent = await this.plugin.call('codeFormatter', 'format', file.fileName, file.content, true); - await statusCallback?.(`Showing diff for ${file.fileName}...`) - await this.plugin.call('editor', 'showCustomDiff', file.fileName, file.content) - modifiedFilesMarkdown += `- ${file.fileName}\n` + + try { + const fileExists = await this.plugin.call('fileManager', 'exists', file.fileName) + + if (fileExists) { + await this.plugin.call('editor', 'showCustomDiff', file.fileName, file.content) + modifiedFilesMarkdown += `- ${file.fileName}\n` + } else { + await statusCallback?.(`Creating file ${file.fileName}...`) + + const dirPath = file.fileName.substring(0, file.fileName.lastIndexOf('/')) + if (dirPath && dirPath.length > 0) { + try { + await this.plugin.call('fileManager', 'mkdir', dirPath) + } catch (mkdirError) { + // Directory already exist, just continue + } + } + + await this.plugin.call('fileManager', 'writeFile', file.fileName, "") + await new Promise(resolve => setTimeout(resolve, 2000)) // wait so the content is written before diffing + await this.plugin.call('editor', 'showCustomDiff', file.fileName, file.content) + createdFilesMarkdown += `- ${file.fileName}\n` + hasCreatedFiles = true + } + } catch (fileError) { + console.warn(`Error processing file ${file.fileName}:`, fileError) + } } + await statusCallback?.('Workspace modifications complete!') - return modifiedFilesMarkdown + + // Build result markdown + let result = modifiedFilesMarkdown + if (hasCreatedFiles) { + result += '\n' + createdFilesMarkdown + } + + return result || 'No files modified' } catch (error) { console.warn('Error writing generation results:', error); return 'No files modified' diff --git a/libs/remix-ui/remix-ai-assistant/src/components/chat.tsx b/libs/remix-ui/remix-ai-assistant/src/components/chat.tsx index a41f84407f1..18a49a6848a 100644 --- a/libs/remix-ui/remix-ai-assistant/src/components/chat.tsx +++ b/libs/remix-ui/remix-ai-assistant/src/components/chat.tsx @@ -9,7 +9,7 @@ import { CustomTooltip } from "@remix-ui/helper" const DEFAULT_SUGGESTIONS = [ 'What is a modifier?', - 'What is a UniSwap hook?', + 'What is a Uniswap hook?', 'What is a ZKP?' ] @@ -31,20 +31,6 @@ const AiChatIntro = (props) => { RemixAI provides you personalized guidance as you build. It can break down concepts, answer questions about blockchain technology and assist you with your smart contracts.

-
-
- {`: `} - ask your question
-
- {`/w : `} - modify your code
-
- {`/c : `} - continue fixing compilation
-
- {`/g : `} - generate a new workspace
-
{DEFAULT_SUGGESTIONS.map((s, index) => ( -
- } - delay={{ show: 1000, hide: 0 }} - > - _paq.push(['trackEvent', 'remixAI', 'AICommandTooltip', 'User clicked on AI command info'])} - > - +
+ {/* Ask/Edit Mode Toggle */} +
+ + +
@@ -145,7 +165,11 @@ export const PromptArea: React.FC = ({ onKeyDown={e => { if (e.key === 'Enter' && !isStreaming) handleSend() }} - placeholder="Ask me anything, add workspace files..." + placeholder={ + aiMode === 'ask' + ? "Select context and ask me anything!" + : "Edit my codebase, generate new contracts ..." + } />
@@ -182,7 +206,7 @@ export const PromptArea: React.FC = ({ className="btn btn-text btn-sm small fw-light text-secondary mt-2 align-self-end border border-text rounded" onClick={handleGenerateWorkspace} > - {'@Generate'} + {'Create new workspace with AI'} {/*