-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.go
43 lines (36 loc) · 1.6 KB
/
handler.go
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
package oairt
import "github.com/yawn/oairt/types"
type Event interface {
*types.ServerError |
*types.ServerSessionCreated | *types.ServerSessionUpdated |
*types.ServerConversationCreated |
*types.ServerInputAudioBufferCommitted | *types.ServerInputAudioBufferCleared | *types.ServerInputAudioBufferSpeechStarted | *types.ServerInputAudioBufferSpeechStopped |
*types.ServerConversationItemCreated | *types.ServerConversationInputAudioTranscriptionCompleted | *types.ServerConversationInputAudioTranscriptionFailed | *types.ServerConversationItemTruncated | *types.ServerConversationItemDeleted |
*types.ServerResponseCreated | *types.ServerResponseDone |
*types.ServerResponseOutputItemAdded | *types.ServerResponseOutputItemDone |
*types.ServerResponseContentPartAdded | *types.ServerResponseContentPartDone |
*types.ServerResponseTextDelta | *types.ServerResponseTextDone |
*types.ServerResponseAudioTranscriptDelta | *types.ServerResponseAudioTranscriptDone |
*types.ServerResponseAudioDelta | *types.ServerResponseAudioDone |
*types.ServerResponseFunctionCallArgumentsDelta | *types.ServerResponseFunctionCallArgumentsDone |
*types.ServerRateLimitsUpdated
}
type Handler[T Event] struct {
Handle func(T) (bool, error)
ID string
Type types.ServerEventType
}
func (c *Handler[T]) handle(event any) (bool, error) {
return c.Handle(event.(T))
}
func (c *Handler[T]) id() string {
return c.ID
}
func (c *Handler[T]) isApplicable(_type string) bool {
return c.Type == _type
}
type handler interface {
handle(event any) (cont bool, err error)
id() (id string)
isApplicable(_type string) (ok bool)
}