-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
called claude api and execute the return code
- Loading branch information
Showing
13 changed files
with
525 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::process::Command; | ||
use tauri::command; | ||
|
||
#[command] | ||
pub fn execute_code(code: String) -> Result<String, String> { | ||
let output = if cfg!(target_os = "windows") { | ||
Command::new("powershell") | ||
.arg("-Command") | ||
.arg(&code) | ||
.output() | ||
} else if cfg!(target_os = "macos") { | ||
Command::new("sh").arg("-c").arg(&code).output() | ||
} else { | ||
// Assuming Linux or other Unix-like systems | ||
Command::new("bash").arg("-c").arg(&code).output() | ||
}; | ||
|
||
match output { | ||
Ok(output) => { | ||
if output.status.success() { | ||
Ok(String::from_utf8_lossy(&output.stdout).to_string()) | ||
} else { | ||
Err(String::from_utf8_lossy(&output.stderr).to_string()) | ||
} | ||
} | ||
Err(e) => Err(format!("Failed to execute command: {}", e)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod file_operations; | ||
pub mod ai_operations; | ||
// pub mod file_operations; | ||
// pub mod ai_operations; | ||
pub mod execute_code; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React, { useState, useEffect, useRef } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Button } from "@/components/ui/button"; | ||
import { useSpeechRecognition } from "@/hooks/useSpeechRecognition"; | ||
import { | ||
MAX_CHARS, | ||
MIN_TEXTAREA_HEIGHT, | ||
MAX_TEXTAREA_HEIGHT, | ||
} from "@/utils/constants"; | ||
import { Textarea } from "@chakra-ui/react"; | ||
import { cn } from "@/lib/utils"; | ||
import { Send, StopCircle } from "lucide-react"; | ||
|
||
const BottomInputContainer = ({ | ||
isLoading, | ||
input, | ||
// stopListening, | ||
// startListening, | ||
handleSend, | ||
setInput, | ||
abortRequest, | ||
}: { | ||
input: string; | ||
isLoading: boolean; | ||
// stopListening: () => void; | ||
// startListening: () => void; | ||
handleSend: () => void; | ||
setInput: (s: string) => void; | ||
abortRequest: () => void; | ||
}) => { | ||
const { t } = useTranslation(); | ||
const { transcript } = useSpeechRecognition(); | ||
const textareaRef = useRef<HTMLTextAreaElement>(null); | ||
|
||
// const handleVoiceInput = () => { | ||
// if (transcript) { | ||
// stopListening(); | ||
// } else { | ||
// startListening(); | ||
// } | ||
// }; | ||
|
||
const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
const value = e.target.value; | ||
if (value.length <= MAX_CHARS) { | ||
setInput(value); | ||
} | ||
}; | ||
|
||
const adjustHeight = () => { | ||
const textarea = textareaRef.current; | ||
if (!textarea) return; | ||
|
||
textarea.style.height = "auto"; | ||
const scrollHeight = input === "" ? 45 : textarea.scrollHeight; | ||
const lines = scrollHeight / 45; | ||
const newRows = Math.max(1, Math.min(10, Math.floor(lines))); | ||
|
||
textarea.style.height = `${newRows * 45}px`; | ||
}; | ||
|
||
useEffect(adjustHeight, [input]); | ||
|
||
return ( | ||
<div className="bg-gray-50 dark:bg-gray-800"> | ||
<div className="flex p-2 items-end space-x-2 bg-white dark:bg-gray-700 rounded-2 overflow-hidden shadow-inner"> | ||
{/* <Button | ||
variant="ghost" | ||
className="rounded-full min-w-10 p-2" | ||
onClick={handleVoiceInput} | ||
> | ||
<Mic size={16} className={transcript ? "text-red-500" : ""} /> | ||
</Button> */} | ||
<Textarea | ||
ref={textareaRef} | ||
value={input} | ||
onChange={handleInputChange} | ||
placeholder={t("typeMessage")!} | ||
className={cn( | ||
"flex-grow border-none bg-transparent focus:ring-0 focus:outline-none resize-none", | ||
"min-h-[2.5rem] py-2 px-3 text-base leading-relaxed", | ||
"scrollbar scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600", | ||
"scrollbar-track-transparent scrollbar-thin hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500", | ||
"!border-none focus-visible:ring-0 focus-visible:outline-none" | ||
)} | ||
style={{ | ||
minHeight: `${MIN_TEXTAREA_HEIGHT}px`, | ||
maxHeight: `${MAX_TEXTAREA_HEIGHT}px`, | ||
overflowY: "auto", | ||
boxSizing: "border-box", | ||
}} | ||
onKeyPress={(e) => { | ||
if (e.key === "Enter" && !e.shiftKey && !isLoading) { | ||
e.preventDefault(); | ||
handleSend(); | ||
} | ||
}} | ||
/> | ||
<Button | ||
className="rounded-full min-w-10 p-2" | ||
onClick={isLoading ? abortRequest : handleSend} | ||
> | ||
{isLoading ? ( | ||
<StopCircle size={16} className="text-red-500" /> | ||
) : ( | ||
<Send size={16} /> | ||
)} | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BottomInputContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from "react"; | ||
import { CheckCircle, XCircle, Clock } from "lucide-react"; | ||
import { ExecutionStep } from "@/type"; | ||
|
||
const ExecutionStepComponent: React.FC<{ step: ExecutionStep }> = ({ | ||
step, | ||
}) => { | ||
const getStatusIcon = () => { | ||
switch (step.status) { | ||
case "success": | ||
return <CheckCircle className="text-green-500" />; | ||
case "failure": | ||
return <XCircle className="text-red-500" />; | ||
default: | ||
return <Clock className="text-gray-500" />; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="border rounded p-2 mb-2"> | ||
<div className="flex items-center"> | ||
{getStatusIcon()} | ||
<span className="ml-2 font-bold">{step.step}</span> | ||
</div> | ||
<pre className="bg-gray-100 p-2 mt-2 rounded text-sm overflow-x-auto"> | ||
<code>{step.code}</code> | ||
</pre> | ||
{step.result && ( | ||
<div className="mt-2"> | ||
<strong>Result:</strong> | ||
<p>{step.result}</p> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ExecutionStepComponent; |
Oops, something went wrong.