-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathICopilotTool.swift
More file actions
62 lines (56 loc) · 2.24 KB
/
ICopilotTool.swift
File metadata and controls
62 lines (56 loc) · 2.24 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import ConversationServiceProvider
import JSONRPC
import ChatTab
enum ToolInvocationStatus: String {
case success, error, cancelled
}
public protocol ToolContextProvider {
// MARK: insert_edit_into_file
var chatTabInfo: ChatTabInfo { get }
func updateFileEdits(by fileEdit: FileEdit) -> Void
}
public typealias ChatHistoryUpdater = (String, [AgentRound]) -> Void
public protocol ICopilotTool {
/**
* Invokes the Copilot tool with the given request.
* - Parameters:
* - request: The tool invocation request.
* - completion: Closure called with JSON-RPC response when tool execution completes.
* - chatHistoryUpdater: Optional closure to update chat history during tool execution.
* - contextProvider: Optional provider that supplies additional context information
* needed for tool execution, such as chat tab data and file editing capabilities.
* - Returns: Boolean indicating if the tool call has completed. True if the tool call is completed, false otherwise.
*/
func invokeTool(
_ request: InvokeClientToolRequest,
completion: @escaping (AnyJSONRPCResponse) -> Void,
chatHistoryUpdater: ChatHistoryUpdater?,
contextProvider: ToolContextProvider?
) -> Bool
}
extension ICopilotTool {
/**
* Completes a tool response.
* - Parameters:
* - request: The original tool invocation request.
* - status: The completion status of the tool execution (success, error, or cancelled).
* - response: The string value to include in the response content.
* - completion: The completion handler to call with the response.
*/
func completeResponse(
_ request: InvokeClientToolRequest,
status: ToolInvocationStatus = .success,
response: String = "",
completion: @escaping (AnyJSONRPCResponse) -> Void
) {
let result: JSONValue = .array([
.hash([
"status": .string(status.rawValue),
"content": .array([.hash(["value": .string(response)])])
]),
.null
])
completion(AnyJSONRPCResponse(id: request.id, result: result))
}
}
extension ChatService: ToolContextProvider { }