-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAppMessage.swift
More file actions
95 lines (90 loc) · 3.44 KB
/
AppMessage.swift
File metadata and controls
95 lines (90 loc) · 3.44 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
85
86
87
88
89
90
91
92
93
94
95
//
// AppMessage.swift
//
//
// Created by Brent Whitman on 2024-01-15.
//
import Foundation
struct AppMessage: Decodable {
enum MessageType: String {
case hang
case functionCall = "function-call"
case transcript
case speechUpdate = "speech-update"
case metadata
case conversationUpdate = "conversation-update"
case modelOutput = "model-output"
case statusUpdate = "status-update"
case voiceInput = "voice-input"
case userInterrupted = "user-interrupted"
case assistantStarted = "assistant.started"
case workflowNodeStarted = "workflow.node.started"
case toolCalls = "tool-calls"
case toolCallsResult = "tool-calls-result"
case transferUpdate = "transfer-update"
case languageChangeDetected = "language-change-detected"
case chatCreated = "chat.created"
case chatDeleted = "chat.deleted"
case sessionCreated = "session.created"
case sessionUpdated = "session.updated"
case sessionDeleted = "session.deleted"
case callDeleted = "call.deleted"
case callDeleteFailed = "call.delete.failed"
case unknown
}
let type: String
var messageType: MessageType {
// Messages can be configured as transcript[transcriptType="final"].
let normalizedType = String(type.split(separator: "[", maxSplits: 1).first ?? "")
switch normalizedType {
case MessageType.functionCall.rawValue:
return .functionCall
case MessageType.hang.rawValue:
return .hang
case MessageType.transcript.rawValue:
return .transcript
case MessageType.speechUpdate.rawValue:
return .speechUpdate
case MessageType.metadata.rawValue:
return .metadata
case MessageType.conversationUpdate.rawValue:
return .conversationUpdate
case MessageType.modelOutput.rawValue:
return .modelOutput
case MessageType.statusUpdate.rawValue:
return .statusUpdate
case MessageType.voiceInput.rawValue:
return .voiceInput
case MessageType.userInterrupted.rawValue:
return .userInterrupted
case MessageType.assistantStarted.rawValue:
return .assistantStarted
case MessageType.workflowNodeStarted.rawValue:
return .workflowNodeStarted
case MessageType.toolCalls.rawValue:
return .toolCalls
case MessageType.toolCallsResult.rawValue, "function-call-result", "tool.completed", "assistant.tool.completed":
return .toolCallsResult
case MessageType.transferUpdate.rawValue:
return .transferUpdate
case MessageType.languageChangeDetected.rawValue, "language-changed":
return .languageChangeDetected
case MessageType.chatCreated.rawValue:
return .chatCreated
case MessageType.chatDeleted.rawValue:
return .chatDeleted
case MessageType.sessionCreated.rawValue:
return .sessionCreated
case MessageType.sessionUpdated.rawValue:
return .sessionUpdated
case MessageType.sessionDeleted.rawValue:
return .sessionDeleted
case MessageType.callDeleted.rawValue:
return .callDeleted
case MessageType.callDeleteFailed.rawValue:
return .callDeleteFailed
default:
return .unknown
}
}
}