-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAgentLS.swift
43 lines (38 loc) · 1.29 KB
/
AgentLS.swift
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
public extension AgentClient {
func listAgentDirectory(_ req: LSRequest) async throws(SDKError) -> LSResponse {
let res = try await request("/api/v0/list-directory", method: .post, body: req)
guard res.resp.statusCode == 200 else {
throw responseAsError(res)
}
return try decode(LSResponse.self, from: res.data)
}
}
public struct LSRequest: Sendable, Codable {
// e.g. [], ["repos", "coder"]
public let path: [String]
// Whether the supplied path is relative to the user's home directory,
// or the root directory.
public let relativity: LSRelativity
public init(path: [String], relativity: LSRelativity) {
self.path = path
self.relativity = relativity
}
public enum LSRelativity: String, Sendable, Codable {
case root
case home
}
}
public struct LSResponse: Sendable, Codable {
public let absolute_path: [String]
// e.g. Windows: "C:\\Users\\coder"
// Linux: "/home/coder"
public let absolute_path_string: String
public let contents: [LSFile]
}
public struct LSFile: Sendable, Codable {
public let name: String
// e.g. "C:\\Users\\coder\\hello.txt"
// "/home/coder/hello.txt"
public let absolute_path_string: String
public let is_dir: Bool
}