feat(server): basic implementation of server runtime and SDK (#13)

* feat(server): basic implementation of server runtime and SDK
* refactor: better typing
This commit is contained in:
Neko
2025-01-15 20:54:46 +08:00
committed by GitHub
parent 61614775bd
commit 790189f1eb
19 changed files with 558 additions and 267 deletions
View File
@@ -0,0 +1 @@
export * from './websocket'
@@ -0,0 +1,49 @@
export interface DiscordGuildMember {
nickname: string
displayName: string
id: string
}
export interface Discord {
guildMember?: DiscordGuildMember
guildId?: string
channelId?: string
}
interface InputSource {
browser: string
discord: Discord
}
export interface WebSocketBaseEvent<T, D> {
type: T
data: D
}
export type WithInputSource<Source extends keyof InputSource> = {
[S in Source]: InputSource[S]
}
// Thanks to:
//
// A little hack for creating extensible discriminated unions : r/typescript
// https://www.reddit.com/r/typescript/comments/1064ibt/a_little_hack_for_creating_extensible/
export interface WebSocketEvents {
'module:announce': {
name: string
possibleEvents: Array<(keyof WebSocketEvents)>
}
'input:text': {
text: string
} & Partial<WithInputSource<'browser' | 'discord'>>
'input:text:voice': {
transcription: string
} & Partial<WithInputSource<'browser' | 'discord'>>
'input:voice': {
audio: ArrayBuffer
} & Partial<WithInputSource<'browser' | 'discord'>>
}
export type WebSocketEvent = {
[K in keyof WebSocketEvents]: WebSocketBaseEvent<K, WebSocketEvents[K]>;
}[keyof WebSocketEvents]
@@ -0,0 +1 @@
export * from './events'