forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomCommand.swift
More file actions
43 lines (36 loc) · 1.23 KB
/
CustomCommand.swift
File metadata and controls
43 lines (36 loc) · 1.23 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
import Foundation
import CryptoKit
public struct CustomCommand: Codable {
/// The custom command feature.
///
/// Keep everything optional so nothing will break when the format changes.
public enum Feature: Codable {
case promptToCode(extraSystemPrompt: String?, prompt: String?, continuousMode: Bool?, generateDescription: Bool?)
case chatWithSelection(extraSystemPrompt: String?, prompt: String?, useExtraSystemPrompt: Bool?)
case customChat(systemPrompt: String?, prompt: String?)
}
public var id: String { commandId ?? legacyId }
public var commandId: String?
public var name: String
public var feature: Feature
public init(commandId: String, name: String, feature: Feature) {
self.commandId = commandId
self.name = name
self.feature = feature
}
var legacyId: String {
name.sha1HexString
}
}
private extension Digest {
var bytes: [UInt8] { Array(makeIterator()) }
var data: Data { Data(bytes) }
var hexStr: String {
bytes.map { String(format: "%02X", $0) }.joined()
}
}
private extension String {
var sha1HexString: String {
Insecure.SHA1.hash(data: data(using: .utf8) ?? Data()).hexStr
}
}