mirror of
https://github.com/7836246/cursor2api.git
synced 2026-06-20 10:22:16 +08:00
fix: 修复写入文件路径问题,保留绝对路径
This commit is contained in:
BIN
cursor2api
BIN
cursor2api
Binary file not shown.
@@ -168,11 +168,14 @@ func ExtractCommandFromRefusal(response string) string {
|
||||
switch toolCall.Tool {
|
||||
case "write_file", "write_to_file":
|
||||
if toolCall.Path != "" && toolCall.Content != "" {
|
||||
// 转换为 echo 命令
|
||||
// 转换为 echo 命令,保留绝对路径
|
||||
// 转义内容中的特殊字符
|
||||
content := strings.ReplaceAll(toolCall.Content, `"`, `\"`)
|
||||
content = strings.ReplaceAll(content, `$`, `\$`)
|
||||
return fmt.Sprintf(`echo "%s" > "%s"`, content, toolCall.Path)
|
||||
content = strings.ReplaceAll(content, "`", "\\`")
|
||||
path := toolCall.Path
|
||||
// 如果路径不是绝对路径,添加当前工作目录(但这里我们直接使用原始路径)
|
||||
return fmt.Sprintf(`printf '%%s' "%s" > "%s"`, content, path)
|
||||
}
|
||||
case "bash", "run_command":
|
||||
if toolCall.Command != "" {
|
||||
|
||||
Reference in New Issue
Block a user