Skip to content

Commit d459872

Browse files
STetsingAniket-Engg
authored andcommitted
initial ask edit toggle
1 parent bd407c5 commit d459872

File tree

3 files changed

+94
-11
lines changed

3 files changed

+94
-11
lines changed

libs/remix-ai-core/src/agents/workspaceAgent.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,51 @@ export class workspaceAgent {
9393
if (typeof payload === 'string') {
9494
payload = JSON.parse(payload)
9595
}
96-
let modifiedFilesMarkdown = '### List of Modified Files\n'
96+
let modifiedFilesMarkdown = '#### **List of Modified Files**\n'
97+
let createdFilesMarkdown = '#### **List of Created Files**\n'
98+
let hasCreatedFiles = false
99+
97100
for (const file of payload.files) {
98101
if (!Object.values(SupportedFileExtensions).some(ext => file.fileName.endsWith(ext))) continue;
99-
// const fileContent = await this.plugin.call('codeFormatter', 'format', file.fileName, file.content, true);
100-
await statusCallback?.(`Showing diff for ${file.fileName}...`)
101-
await this.plugin.call('editor', 'showCustomDiff', file.fileName, file.content)
102-
modifiedFilesMarkdown += `- ${file.fileName}\n`
102+
103+
try {
104+
const fileExists = await this.plugin.call('fileManager', 'exists', file.fileName)
105+
106+
if (fileExists) {
107+
await this.plugin.call('editor', 'showCustomDiff', file.fileName, file.content)
108+
modifiedFilesMarkdown += `- ${file.fileName}\n`
109+
} else {
110+
await statusCallback?.(`Creating file ${file.fileName}...`)
111+
112+
const dirPath = file.fileName.substring(0, file.fileName.lastIndexOf('/'))
113+
if (dirPath && dirPath.length > 0) {
114+
try {
115+
await this.plugin.call('fileManager', 'mkdir', dirPath)
116+
} catch (mkdirError) {
117+
// Directory already exist, just continue
118+
}
119+
}
120+
121+
await this.plugin.call('fileManager', 'writeFile', file.fileName, "")
122+
await new Promise(resolve => setTimeout(resolve, 2000)) // wait so the content is written before diffing
123+
await this.plugin.call('editor', 'showCustomDiff', file.fileName, file.content)
124+
createdFilesMarkdown += `- ${file.fileName}\n`
125+
hasCreatedFiles = true
126+
}
127+
} catch (fileError) {
128+
console.warn(`Error processing file ${file.fileName}:`, fileError)
129+
}
103130
}
131+
104132
await statusCallback?.('Workspace modifications complete!')
105-
return modifiedFilesMarkdown
133+
134+
// Build result markdown
135+
let result = modifiedFilesMarkdown
136+
if (hasCreatedFiles) {
137+
result += '\n' + createdFilesMarkdown
138+
}
139+
140+
return result || 'No files modified'
106141
} catch (error) {
107142
console.warn('Error writing generation results:', error);
108143
return 'No files modified'

libs/remix-ui/remix-ai-assistant/src/components/prompt.tsx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface PromptAreaProps {
3838
aiAssistantGroupList: groupListType[]
3939
textareaRef?: React.RefObject<HTMLTextAreaElement>
4040
maximizePanel: () => Promise<void>
41+
aiMode: 'ask' | 'edit'
42+
setAiMode: React.Dispatch<React.SetStateAction<'ask' | 'edit'>>
4143
}
4244

4345
const _paq = (window._paq = window._paq || [])
@@ -73,7 +75,9 @@ export const PromptArea: React.FC<PromptAreaProps> = ({
7375
aiContextGroupList,
7476
aiAssistantGroupList,
7577
textareaRef,
76-
maximizePanel
78+
maximizePanel,
79+
aiMode,
80+
setAiMode
7781
}) => {
7882

7983
return (
@@ -109,7 +113,32 @@ export const PromptArea: React.FC<PromptAreaProps> = ({
109113
{contextChoice === 'current' && <span data-id="aiContext-current">{'Current File'}</span>}
110114
</button>
111115

112-
<div className="d-flex justify-content-center align-items-center">
116+
<div className="d-flex justify-content-center align-items-center gap-2">
117+
{/* Ask/Edit Mode Toggle */}
118+
<div className="btn-group btn-group-sm" role="group">
119+
<button
120+
type="button"
121+
className={`btn ${aiMode === 'ask' ? 'btn-primary' : 'btn-outline-secondary'} px-2`}
122+
onClick={() => {
123+
setAiMode('ask')
124+
_paq.push(['trackEvent', 'remixAI', 'ModeSwitch', 'ask'])
125+
}}
126+
title="Ask mode - Chat with AI"
127+
>
128+
Ask
129+
</button>
130+
<button
131+
type="button"
132+
className={`btn ${aiMode === 'edit' ? 'btn-primary' : 'btn-outline-secondary'} px-2`}
133+
onClick={() => {
134+
setAiMode('edit')
135+
_paq.push(['trackEvent', 'remixAI', 'ModeSwitch', 'edit'])
136+
}}
137+
title="Edit mode - Edit workspace code"
138+
>
139+
Edit
140+
</button>
141+
</div>
113142
<CustomTooltip
114143
tooltipText={<TooltipContent />}
115144
delay={{ show: 1000, hide: 0 }}
@@ -145,7 +174,11 @@ export const PromptArea: React.FC<PromptAreaProps> = ({
145174
onKeyDown={e => {
146175
if (e.key === 'Enter' && !isStreaming) handleSend()
147176
}}
148-
placeholder="Ask me anything, add workspace files..."
177+
placeholder={
178+
aiMode === 'ask'
179+
? "Ask me anything, add workspace files..."
180+
: "Describe the workspace you want to generate..."
181+
}
149182
/>
150183

151184
<div className="d-flex justify-content-between">

libs/remix-ui/remix-ai-assistant/src/components/remix-ui-remix-ai-assistant.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const RemixUiRemixAiAssistant = React.forwardRef<
5151
const [availableModels, setAvailableModels] = useState<string[]>([])
5252
const [selectedModel, setSelectedModel] = useState<string | null>(null)
5353
const [isOllamaFailureFallback, setIsOllamaFailureFallback] = useState(false)
54+
const [aiMode, setAiMode] = useState<'ask' | 'edit'>('ask')
5455

5556
const historyRef = useRef<HTMLDivElement | null>(null)
5657
const modelBtnRef = useRef(null)
@@ -416,11 +417,23 @@ export const RemixUiRemixAiAssistant = React.forwardRef<
416417
},
417418
[isStreaming, props.plugin]
418419
)
420+
const handleGenerateWorkspaceWithPrompt = useCallback(async (prompt: string) => {
421+
dispatchActivity('button', 'generateWorkspace')
422+
if (prompt && prompt.trim()) {
423+
await sendPrompt(`/workspace ${prompt.trim()}`)
424+
_paq.push(['trackEvent', 'remixAI', 'GenerateNewAIWorkspaceFromEditMode', prompt])
425+
}
426+
}, [sendPrompt])
419427

420428
const handleSend = useCallback(async () => {
421-
await sendPrompt(input)
429+
if (aiMode === 'ask') {
430+
await sendPrompt(input)
431+
} else if (aiMode === 'edit') {
432+
// Call generateWorkspace for edit mode with the current input
433+
await handleGenerateWorkspaceWithPrompt(input)
434+
}
422435
setInput('')
423-
}, [input, sendPrompt])
436+
}, [input, sendPrompt, aiMode, handleGenerateWorkspaceWithPrompt])
424437

425438
// Added handlers for special command buttons (assumed to exist)
426439
const handleAddContext = useCallback(() => {
@@ -734,6 +747,8 @@ export const RemixUiRemixAiAssistant = React.forwardRef<
734747
aiContextGroupList={aiContextGroupList}
735748
aiAssistantGroupList={aiAssistantGroupList}
736749
textareaRef={textareaRef}
750+
aiMode={aiMode}
751+
setAiMode={setAiMode}
737752
/>
738753
</section>
739754
</div>

0 commit comments

Comments
 (0)