forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetchWebPageTool.swift
More file actions
46 lines (40 loc) · 1.36 KB
/
FetchWebPageTool.swift
File metadata and controls
46 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import AppKit
import AXExtension
import AXHelper
import ConversationServiceProvider
import Foundation
import JSONRPC
import Logger
import WebKit
import WebContentExtractor
public class FetchWebPageTool: ICopilotTool {
public static let name = ToolName.fetchWebPage
public func invokeTool(
_ request: InvokeClientToolRequest,
completion: @escaping (AnyJSONRPCResponse) -> Void,
chatHistoryUpdater: ChatHistoryUpdater?,
contextProvider: (any ToolContextProvider)?
) -> Bool {
guard let params = request.params,
let input = params.input,
let urls = input["urls"]?.value as? [String]
else {
completeResponse(request, status: .error, response: "Invalid parameters", completion: completion)
return true
}
guard !urls.isEmpty else {
completeResponse(request, status: .error, response: "No valid URLs provided", completion: completion)
return true
}
// Use the improved WebContentFetcher to fetch content from all URLs
Task {
let results = await WebContentFetcher.fetchMultipleContentAsync(from: urls)
completeResponses(
request,
responses: results,
completion: completion
)
}
return true
}
}