import CopilotModel import CopilotService import Foundation import OpenAIService final class CopilotPromptToCodeAPI: PromptToCodeAPI { var task: Task? func stopResponding() { task?.cancel() } func modifyCode( code: String, language: CopilotLanguage, indentSize: Int, usesTabsForIndentation: Bool, requirement: String, projectRootURL: URL, fileURL: URL, allCode: String ) async throws -> AsyncThrowingStream<(code: String, description: String), Error> { let copilotService = CopilotSuggestionService(projectRootURL: projectRootURL) let relativePath = { let filePath = fileURL.path let rootPath = projectRootURL.path if let range = filePath.range(of: rootPath), range.lowerBound == filePath.startIndex { let relativePath = filePath.replacingCharacters( in: filePath.startIndex.. [String] { let lines = split(separator: "\n", omittingEmptySubsequences: false) var all = [String]() for (index, line) in lines.enumerated() { if index == lines.endIndex - 1 { all.append(String(line)) } else { all.append(String(line) + "\n") } } return all } }