@kernl-sdk/xai 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -0
- package/dist/__tests__/realtime.integration.test.d.ts +2 -0
- package/dist/__tests__/realtime.integration.test.d.ts.map +1 -0
- package/dist/__tests__/realtime.integration.test.js +157 -0
- package/dist/__tests__/realtime.test.d.ts +2 -0
- package/dist/__tests__/realtime.test.d.ts.map +1 -0
- package/dist/__tests__/realtime.test.js +263 -0
- package/dist/connection.d.ts +47 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +138 -0
- package/dist/convert/event.d.ts +28 -0
- package/dist/convert/event.d.ts.map +1 -0
- package/dist/convert/event.js +314 -0
- package/dist/convert/types.d.ts +212 -0
- package/dist/convert/types.d.ts.map +1 -0
- package/dist/convert/types.js +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/model.d.ts +36 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +112 -0
- package/dist/protocol.d.ts +212 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +1 -0
- package/dist/realtime/connection.d.ts +47 -0
- package/dist/realtime/connection.d.ts.map +1 -0
- package/dist/realtime/connection.js +138 -0
- package/dist/realtime/convert/event.d.ts +28 -0
- package/dist/realtime/convert/event.d.ts.map +1 -0
- package/dist/realtime/convert/event.js +314 -0
- package/dist/realtime/model.d.ts +36 -0
- package/dist/realtime/model.d.ts.map +1 -0
- package/dist/realtime/model.js +111 -0
- package/dist/realtime/protocol.d.ts +212 -0
- package/dist/realtime/protocol.d.ts.map +1 -0
- package/dist/realtime/protocol.js +1 -0
- package/dist/realtime.d.ts +36 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +250 -0
- package/package.json +55 -0
- package/src/__tests__/realtime.integration.test.ts +203 -0
- package/src/__tests__/realtime.test.ts +350 -0
- package/src/index.ts +41 -0
- package/src/realtime/connection.ts +167 -0
- package/src/realtime/convert/event.ts +388 -0
- package/src/realtime/model.ts +162 -0
- package/src/realtime/protocol.ts +286 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Grok (xAI) Realtime API wire types.
|
|
5
|
+
*
|
|
6
|
+
* Based on https://docs.x.ai/docs/guides/voice/agent
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// Client Events
|
|
11
|
+
// =============================================================================
|
|
12
|
+
|
|
13
|
+
export type GrokClientEvent =
|
|
14
|
+
| GrokSessionUpdate
|
|
15
|
+
| GrokInputAudioBufferAppend
|
|
16
|
+
| GrokInputAudioBufferCommit
|
|
17
|
+
| GrokInputAudioBufferClear
|
|
18
|
+
| GrokConversationItemCreate
|
|
19
|
+
| GrokResponseCreate;
|
|
20
|
+
|
|
21
|
+
export interface GrokSessionUpdate {
|
|
22
|
+
type: "session.update";
|
|
23
|
+
session: GrokSessionConfig;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface GrokInputAudioBufferAppend {
|
|
27
|
+
type: "input_audio_buffer.append";
|
|
28
|
+
audio: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface GrokInputAudioBufferCommit {
|
|
32
|
+
type: "input_audio_buffer.commit";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface GrokInputAudioBufferClear {
|
|
36
|
+
type: "input_audio_buffer.clear";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface GrokConversationItemCreate {
|
|
40
|
+
type: "conversation.item.create";
|
|
41
|
+
item: GrokItem;
|
|
42
|
+
previous_item_id?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface GrokResponseCreate {
|
|
46
|
+
type: "response.create";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// =============================================================================
|
|
50
|
+
// Server Events
|
|
51
|
+
// =============================================================================
|
|
52
|
+
|
|
53
|
+
export type GrokServerEvent =
|
|
54
|
+
| GrokConversationCreated
|
|
55
|
+
| GrokSessionUpdated
|
|
56
|
+
| GrokInputAudioBufferCommitted
|
|
57
|
+
| GrokInputAudioBufferCleared
|
|
58
|
+
| GrokInputAudioBufferSpeechStarted
|
|
59
|
+
| GrokInputAudioBufferSpeechStopped
|
|
60
|
+
| GrokConversationItemAdded
|
|
61
|
+
| GrokConversationItemInputAudioTranscriptionCompleted
|
|
62
|
+
| GrokResponseCreated
|
|
63
|
+
| GrokResponseOutputItemAdded
|
|
64
|
+
| GrokResponseDone
|
|
65
|
+
| GrokResponseOutputAudioDelta
|
|
66
|
+
| GrokResponseOutputAudioDone
|
|
67
|
+
| GrokResponseOutputAudioTranscriptDelta
|
|
68
|
+
| GrokResponseOutputAudioTranscriptDone
|
|
69
|
+
| GrokResponseFunctionCallArgumentsDone;
|
|
70
|
+
|
|
71
|
+
export interface GrokConversationCreated {
|
|
72
|
+
type: "conversation.created";
|
|
73
|
+
event_id: string;
|
|
74
|
+
conversation: {
|
|
75
|
+
id: string;
|
|
76
|
+
object: "realtime.conversation";
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface GrokSessionUpdated {
|
|
81
|
+
type: "session.updated";
|
|
82
|
+
event_id: string;
|
|
83
|
+
session: GrokSession;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface GrokInputAudioBufferCommitted {
|
|
87
|
+
type: "input_audio_buffer.committed";
|
|
88
|
+
event_id: string;
|
|
89
|
+
previous_item_id?: string;
|
|
90
|
+
item_id: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface GrokInputAudioBufferCleared {
|
|
94
|
+
type: "input_audio_buffer.cleared";
|
|
95
|
+
event_id: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface GrokInputAudioBufferSpeechStarted {
|
|
99
|
+
type: "input_audio_buffer.speech_started";
|
|
100
|
+
event_id: string;
|
|
101
|
+
item_id: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface GrokInputAudioBufferSpeechStopped {
|
|
105
|
+
type: "input_audio_buffer.speech_stopped";
|
|
106
|
+
event_id: string;
|
|
107
|
+
item_id: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface GrokConversationItemAdded {
|
|
111
|
+
type: "conversation.item.added";
|
|
112
|
+
event_id: string;
|
|
113
|
+
previous_item_id?: string;
|
|
114
|
+
item: GrokItemWithId;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface GrokConversationItemInputAudioTranscriptionCompleted {
|
|
118
|
+
type: "conversation.item.input_audio_transcription.completed";
|
|
119
|
+
event_id: string;
|
|
120
|
+
item_id: string;
|
|
121
|
+
transcript: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface GrokResponseCreated {
|
|
125
|
+
type: "response.created";
|
|
126
|
+
event_id: string;
|
|
127
|
+
response: {
|
|
128
|
+
id: string;
|
|
129
|
+
object: "realtime.response";
|
|
130
|
+
status: "in_progress";
|
|
131
|
+
output: unknown[];
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface GrokResponseOutputItemAdded {
|
|
136
|
+
type: "response.output_item.added";
|
|
137
|
+
event_id: string;
|
|
138
|
+
response_id: string;
|
|
139
|
+
output_index: number;
|
|
140
|
+
item: GrokItemWithId;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface GrokResponseDone {
|
|
144
|
+
type: "response.done";
|
|
145
|
+
event_id: string;
|
|
146
|
+
response: {
|
|
147
|
+
id: string;
|
|
148
|
+
object: "realtime.response";
|
|
149
|
+
status: "completed" | "cancelled" | "failed";
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface GrokResponseOutputAudioDelta {
|
|
154
|
+
type: "response.output_audio.delta";
|
|
155
|
+
event_id: string;
|
|
156
|
+
response_id: string;
|
|
157
|
+
item_id: string;
|
|
158
|
+
output_index: number;
|
|
159
|
+
content_index: number;
|
|
160
|
+
delta: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface GrokResponseOutputAudioDone {
|
|
164
|
+
type: "response.output_audio.done";
|
|
165
|
+
event_id: string;
|
|
166
|
+
response_id: string;
|
|
167
|
+
item_id: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface GrokResponseOutputAudioTranscriptDelta {
|
|
171
|
+
type: "response.output_audio_transcript.delta";
|
|
172
|
+
event_id: string;
|
|
173
|
+
response_id: string;
|
|
174
|
+
item_id: string;
|
|
175
|
+
delta: string;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface GrokResponseOutputAudioTranscriptDone {
|
|
179
|
+
type: "response.output_audio_transcript.done";
|
|
180
|
+
event_id: string;
|
|
181
|
+
response_id: string;
|
|
182
|
+
item_id: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface GrokResponseFunctionCallArgumentsDone {
|
|
186
|
+
type: "response.function_call_arguments.done";
|
|
187
|
+
event_id: string;
|
|
188
|
+
response_id?: string;
|
|
189
|
+
item_id?: string;
|
|
190
|
+
call_id: string;
|
|
191
|
+
name: string;
|
|
192
|
+
arguments: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// =============================================================================
|
|
196
|
+
// Shared Types
|
|
197
|
+
// =============================================================================
|
|
198
|
+
|
|
199
|
+
export interface GrokSession {
|
|
200
|
+
instructions?: string;
|
|
201
|
+
voice?: GrokVoice;
|
|
202
|
+
turn_detection?: GrokTurnDetection;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface GrokSessionConfig {
|
|
206
|
+
instructions?: string;
|
|
207
|
+
voice?: GrokVoice;
|
|
208
|
+
turn_detection?: GrokTurnDetection | null;
|
|
209
|
+
audio?: GrokAudioConfig;
|
|
210
|
+
tools?: GrokTool[];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Available Grok voices.
|
|
215
|
+
*/
|
|
216
|
+
export type GrokVoice = "Ara" | "Rex" | "Sal" | "Eve" | "Leo";
|
|
217
|
+
|
|
218
|
+
export interface GrokTurnDetection {
|
|
219
|
+
type: "server_vad" | null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface GrokAudioConfig {
|
|
223
|
+
input?: {
|
|
224
|
+
format?: GrokAudioFormat;
|
|
225
|
+
};
|
|
226
|
+
output?: {
|
|
227
|
+
format?: GrokAudioFormat;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface GrokAudioFormat {
|
|
232
|
+
type: "audio/pcm" | "audio/pcmu" | "audio/pcma";
|
|
233
|
+
rate?: number;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export type GrokTool =
|
|
237
|
+
| GrokFunctionTool
|
|
238
|
+
| GrokWebSearchTool
|
|
239
|
+
| GrokXSearchTool
|
|
240
|
+
| GrokFileSearchTool;
|
|
241
|
+
|
|
242
|
+
export interface GrokFunctionTool {
|
|
243
|
+
type: "function";
|
|
244
|
+
name: string;
|
|
245
|
+
description?: string;
|
|
246
|
+
parameters?: JSONSchema7;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface GrokWebSearchTool {
|
|
250
|
+
type: "web_search";
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export interface GrokXSearchTool {
|
|
254
|
+
type: "x_search";
|
|
255
|
+
allowed_x_handles?: string[];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface GrokFileSearchTool {
|
|
259
|
+
type: "file_search";
|
|
260
|
+
vector_store_ids: string[];
|
|
261
|
+
max_num_results?: number;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export type GrokItem = GrokMessageItem | GrokFunctionCallOutputItem;
|
|
265
|
+
|
|
266
|
+
export interface GrokMessageItem {
|
|
267
|
+
type: "message";
|
|
268
|
+
role: "user" | "assistant";
|
|
269
|
+
content: GrokContentPart[];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface GrokFunctionCallOutputItem {
|
|
273
|
+
type: "function_call_output";
|
|
274
|
+
call_id: string;
|
|
275
|
+
output: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export type GrokItemWithId = GrokItem & {
|
|
279
|
+
id: string;
|
|
280
|
+
object: "realtime.item";
|
|
281
|
+
status: "completed" | "in_progress";
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export type GrokContentPart =
|
|
285
|
+
| { type: "input_text"; text: string }
|
|
286
|
+
| { type: "input_audio"; transcript?: string };
|
package/tsconfig.json
ADDED