1+ import type { AssistantMessage , ToolMessage } from '@xsai/shared-chat'
2+
13export interface DiscordGuildMember {
24 nickname : string
35 displayName : string
@@ -10,48 +12,66 @@ export interface Discord {
1012 channelId ?: string
1113}
1214
15+ export enum WebSocketEventSource {
16+ Server = 'proj-airi:server-runtime' ,
17+ StageWeb = 'proj-airi:stage-web' ,
18+ StageTamagotchi = 'proj-airi:stage-tamagotchi' ,
19+ }
20+
1321interface InputSource {
14- browser : string
15- discord : Discord
22+ 'stage-web' : string
23+ 'stage-tamagotchi' : string
24+ 'discord' : Discord
25+ }
26+
27+ interface OutputSource {
28+ 'gen-ai-model-chat' : string
29+ }
30+
31+ export enum ContextUpdateStrategy {
32+ ReplaceSelf = 'replace-self' ,
33+ AppendSelf = 'append-self' ,
34+ }
35+
36+ export interface ContextUpdateDestinationAll {
37+ all : true
38+ }
39+
40+ export interface ContextUpdateDestinationList {
41+ include ?: Array < string >
42+ exclude ?: Array < string >
1643}
1744
18- export type ContextSource
19- = | 'text'
20- | 'stt'
21- | 'vision'
22- | 'llm'
23- | 'server-channel'
24- | 'plugin'
25- | 'system'
26-
27- export interface ContextMessage < Payload = unknown , Meta = Record < string , unknown > > {
28- /**
29- * Session identifier so UIs can group conversations from multiple windows/devices.
30- */
31- sessionId : string
32- /**
33- * Unix timestamp in milliseconds.
34- */
35- ts : number
36- role : 'user' | 'assistant' | 'system' | 'error' | 'tool'
37- source : ContextSource
38- /**
39- * The actual payload being carried. Keep this generic so different inputs (text, stt, vision)
40- * can share the same envelope.
41- */
42- payload : Payload
43- meta ?: Meta
45+ export type ContextUpdateDestinationFilter
46+ = | ContextUpdateDestinationAll
47+ | ContextUpdateDestinationList
48+
49+ export interface ContextUpdate <
50+ Metadata extends Record < string , any > = Record < string , unknown > ,
51+ // eslint-disable-next-line ts/no-unnecessary-type-constraint
52+ Content extends any = undefined ,
53+ > {
54+ strategy : ContextUpdateStrategy
55+ text : string
56+ content ?: Content
57+ destinations ?: Array < string > | ContextUpdateDestinationFilter
58+ metadata ?: Metadata
4459}
4560
46- export interface WebSocketBaseEvent < T , D > {
61+ export interface WebSocketBaseEvent < T , D , S extends string = string > {
4762 type : T
4863 data : D
64+ source : WebSocketEventSource | S
4965}
5066
5167export type WithInputSource < Source extends keyof InputSource > = {
5268 [ S in Source ] : InputSource [ S ]
5369}
5470
71+ export type WithOutputSource < Source extends keyof OutputSource > = {
72+ [ S in Source ] : OutputSource [ S ]
73+ }
74+
5575// Thanks to:
5676//
5777// A little hack for creating extensible discriminated unions : r/typescript
@@ -80,17 +100,23 @@ export interface WebSocketEvents<C = undefined> {
80100 }
81101 'input:text' : {
82102 text : string
83- } & Partial < WithInputSource < 'browser ' | 'discord' > >
103+ } & Partial < WithInputSource < 'stage-web' | 'stage-tamagotchi ' | 'discord' > >
84104 'input:text:voice' : {
85105 transcription : string
86- } & Partial < WithInputSource < 'browser ' | 'discord' > >
106+ } & Partial < WithInputSource < 'stage-web' | 'stage-tamagotchi ' | 'discord' > >
87107 'input:voice' : {
88108 audio : ArrayBuffer
89- } & Partial < WithInputSource < 'browser' | 'discord' > >
90- 'vscode:context' : C
91- 'context:update' : ContextMessage
109+ } & Partial < WithInputSource < 'stage-web' | 'stage-tamagotchi' | 'discord' > >
110+ 'output:gen-ai:chat:message' : {
111+ messages : Array < AssistantMessage | ToolMessage >
112+ } & Partial < WithInputSource < 'stage-web' | 'stage-tamagotchi' | 'discord' > > & Partial < WithOutputSource < 'gen-ai-model-chat' > >
113+ 'context:update' : ContextUpdate
92114}
93115
94116export type WebSocketEvent < C = undefined > = {
95117 [ K in keyof WebSocketEvents < C > ] : WebSocketBaseEvent < K , WebSocketEvents < C > [ K ] > ;
96118} [ keyof WebSocketEvents < C > ]
119+
120+ export type WebSocketEventOptionalSource < C = undefined > = {
121+ [ K in keyof WebSocketEvents < C > ] : Omit < WebSocketBaseEvent < K , WebSocketEvents < C > [ K ] > , 'source' > & Partial < Pick < WebSocketBaseEvent < K , WebSocketEvents < C > [ K ] > , 'source' > > ;
122+ } [ keyof WebSocketEvents < C > ]
0 commit comments