-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAppMessage.swift
More file actions
84 lines (78 loc) · 2.75 KB
/
AppMessage.swift
File metadata and controls
84 lines (78 loc) · 2.75 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// AppMessage.swift
//
//
// Created by Brent Whitman on 2024-01-15.
//
import Foundation
struct AppMessage: Codable {
enum MessageType: Codable, Equatable {
case hang
case functionCall
case transcript
case speechUpdate
case metadata
case conversationUpdate
case modelOutput
case statusUpdate
case voiceInput
case userInterrupted
case assistantStarted
case workflowNodeStarted
case toolCalls
case toolCallsResult
case transferUpdate
case languageChangeDetected
case chatCreated
case chatDeleted
case sessionCreated
case sessionUpdated
case sessionDeleted
case callDeleted
case callDeleteFailed
case unknown(String)
private static let rawValueMapping: [(String, MessageType)] = [
("hang", .hang),
("function-call", .functionCall),
("transcript", .transcript),
("transcript[transcriptType=\"final\"]", .transcript),
("speech-update", .speechUpdate),
("metadata", .metadata),
("conversation-update", .conversationUpdate),
("model-output", .modelOutput),
("status-update", .statusUpdate),
("voice-input", .voiceInput),
("user-interrupted", .userInterrupted),
("assistant.started", .assistantStarted),
("workflow.node.started", .workflowNodeStarted),
("tool-calls", .toolCalls),
("tool-calls-result", .toolCallsResult),
("transfer-update", .transferUpdate),
("language-change-detected", .languageChangeDetected),
("chat.created", .chatCreated),
("chat.deleted", .chatDeleted),
("session.created", .sessionCreated),
("session.updated", .sessionUpdated),
("session.deleted", .sessionDeleted),
("call.deleted", .callDeleted),
("call.delete.failed", .callDeleteFailed),
]
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(String.self)
self = Self.rawValueMapping.first(where: { $0.0 == rawValue })?.1 ?? .unknown(rawValue)
}
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .unknown(let rawValue):
try container.encode(rawValue)
default:
if let pair = Self.rawValueMapping.first(where: { $0.1 == self }) {
try container.encode(pair.0)
}
}
}
}
let type: MessageType
}