@tanstack/ai-grok 0.6.8 → 0.7.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.
Files changed (44) hide show
  1. package/dist/esm/adapters/image.js +15 -8
  2. package/dist/esm/adapters/image.js.map +1 -1
  3. package/dist/esm/adapters/transcription.d.ts +84 -0
  4. package/dist/esm/adapters/transcription.js +109 -0
  5. package/dist/esm/adapters/transcription.js.map +1 -0
  6. package/dist/esm/adapters/tts.d.ts +70 -0
  7. package/dist/esm/adapters/tts.js +137 -0
  8. package/dist/esm/adapters/tts.js.map +1 -0
  9. package/dist/esm/audio/transcription-provider-options.d.ts +41 -0
  10. package/dist/esm/audio/tts-provider-options.d.ts +42 -0
  11. package/dist/esm/index.d.ts +8 -2
  12. package/dist/esm/index.js +17 -2
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/model-meta.d.ts +6 -0
  15. package/dist/esm/model-meta.js +22 -1
  16. package/dist/esm/model-meta.js.map +1 -1
  17. package/dist/esm/realtime/adapter.d.ts +21 -0
  18. package/dist/esm/realtime/adapter.js +816 -0
  19. package/dist/esm/realtime/adapter.js.map +1 -0
  20. package/dist/esm/realtime/index.d.ts +4 -0
  21. package/dist/esm/realtime/realtime-contract.d.ts +30 -0
  22. package/dist/esm/realtime/token.d.ts +22 -0
  23. package/dist/esm/realtime/token.js +73 -0
  24. package/dist/esm/realtime/token.js.map +1 -0
  25. package/dist/esm/realtime/types.d.ts +95 -0
  26. package/dist/esm/utils/audio.d.ts +23 -0
  27. package/dist/esm/utils/audio.js +171 -0
  28. package/dist/esm/utils/audio.js.map +1 -0
  29. package/dist/esm/utils/index.d.ts +1 -0
  30. package/package.json +6 -3
  31. package/src/adapters/image.ts +16 -7
  32. package/src/adapters/transcription.ts +233 -0
  33. package/src/adapters/tts.ts +260 -0
  34. package/src/audio/transcription-provider-options.ts +54 -0
  35. package/src/audio/tts-provider-options.ts +44 -0
  36. package/src/index.ts +50 -1
  37. package/src/model-meta.ts +54 -0
  38. package/src/realtime/adapter.ts +1215 -0
  39. package/src/realtime/index.ts +18 -0
  40. package/src/realtime/realtime-contract.ts +46 -0
  41. package/src/realtime/token.ts +131 -0
  42. package/src/realtime/types.ts +105 -0
  43. package/src/utils/audio.ts +217 -0
  44. package/src/utils/index.ts +1 -0
package/src/index.ts CHANGED
@@ -33,6 +33,31 @@ export type {
33
33
  GrokImageModelProviderOptionsByName,
34
34
  } from './image/image-provider-options'
35
35
 
36
+ // Speech (TTS) adapter - for text-to-speech
37
+ export {
38
+ GrokSpeechAdapter,
39
+ createGrokSpeech,
40
+ grokSpeech,
41
+ type GrokSpeechConfig,
42
+ } from './adapters/tts'
43
+ export type {
44
+ GrokTTSProviderOptions,
45
+ GrokTTSVoice,
46
+ GrokTTSCodec,
47
+ } from './audio/tts-provider-options'
48
+
49
+ // Transcription adapter - for speech-to-text
50
+ export {
51
+ GrokTranscriptionAdapter,
52
+ createGrokTranscription,
53
+ grokTranscription,
54
+ type GrokTranscriptionConfig,
55
+ } from './adapters/transcription'
56
+ export type {
57
+ GrokTranscriptionProviderOptions,
58
+ GrokSTTAudioFormat,
59
+ } from './audio/transcription-provider-options'
60
+
36
61
  // ============================================================================
37
62
  // Type Exports
38
63
  // ============================================================================
@@ -45,8 +70,17 @@ export type {
45
70
  ResolveInputModalities,
46
71
  GrokChatModel,
47
72
  GrokImageModel,
73
+ GrokTTSModel,
74
+ GrokTranscriptionModel,
75
+ GrokRealtimeModel,
76
+ } from './model-meta'
77
+ export {
78
+ GROK_CHAT_MODELS,
79
+ GROK_IMAGE_MODELS,
80
+ GROK_TTS_MODELS,
81
+ GROK_TRANSCRIPTION_MODELS,
82
+ GROK_REALTIME_MODELS,
48
83
  } from './model-meta'
49
- export { GROK_CHAT_MODELS, GROK_IMAGE_MODELS } from './model-meta'
50
84
  export type {
51
85
  GrokTextMetadata,
52
86
  GrokImageMetadata,
@@ -55,3 +89,18 @@ export type {
55
89
  GrokDocumentMetadata,
56
90
  GrokMessageMetadataByModality,
57
91
  } from './message-types'
92
+
93
+ // ============================================================================
94
+ // Realtime (Voice Agent) Adapters
95
+ // ============================================================================
96
+
97
+ export { grokRealtimeToken, grokRealtime } from './realtime/index'
98
+
99
+ export type {
100
+ GrokRealtimeVoice,
101
+ GrokRealtimeTokenOptions,
102
+ GrokRealtimeOptions,
103
+ GrokTurnDetection,
104
+ GrokSemanticVADConfig,
105
+ GrokServerVADConfig,
106
+ } from './realtime/index'
package/src/model-meta.ts CHANGED
@@ -283,8 +283,62 @@ export const GROK_CHAT_MODELS = [
283
283
  */
284
284
  export const GROK_IMAGE_MODELS = [GROK_2_IMAGE.name] as const
285
285
 
286
+ // xAI's `/v1/tts` endpoint is endpoint-addressed and does not take a `model`
287
+ // parameter. This synthetic identifier satisfies the SDK's `TTSOptions.model`
288
+ // contract and provides a stable value for logging and fixture matching.
289
+ const GROK_TTS = {
290
+ name: 'grok-tts',
291
+ supports: {
292
+ input: ['text'],
293
+ output: ['audio'],
294
+ },
295
+ } as const satisfies ModelMeta
296
+
297
+ // xAI's `/v1/stt` endpoint is endpoint-addressed and does not take a `model`
298
+ // parameter. This synthetic identifier satisfies the SDK's
299
+ // `TranscriptionOptions.model` contract.
300
+ const GROK_STT = {
301
+ name: 'grok-stt',
302
+ supports: {
303
+ input: ['audio'],
304
+ output: ['text'],
305
+ },
306
+ } as const satisfies ModelMeta
307
+
308
+ const GROK_VOICE_FAST_1 = {
309
+ name: 'grok-voice-fast-1.0',
310
+ supports: {
311
+ input: ['audio', 'text'],
312
+ output: ['audio', 'text'],
313
+ capabilities: ['tool_calling'],
314
+ tools: [] as const,
315
+ },
316
+ } as const satisfies ModelMeta
317
+
318
+ const GROK_VOICE_THINK_FAST_1 = {
319
+ name: 'grok-voice-think-fast-1.0',
320
+ supports: {
321
+ input: ['audio', 'text'],
322
+ output: ['audio', 'text'],
323
+ capabilities: ['reasoning', 'tool_calling'],
324
+ tools: [] as const,
325
+ },
326
+ } as const satisfies ModelMeta
327
+
328
+ export const GROK_TTS_MODELS = [GROK_TTS.name] as const
329
+
330
+ export const GROK_TRANSCRIPTION_MODELS = [GROK_STT.name] as const
331
+
332
+ export const GROK_REALTIME_MODELS = [
333
+ GROK_VOICE_FAST_1.name,
334
+ GROK_VOICE_THINK_FAST_1.name,
335
+ ] as const
336
+
286
337
  export type GrokChatModel = (typeof GROK_CHAT_MODELS)[number]
287
338
  export type GrokImageModel = (typeof GROK_IMAGE_MODELS)[number]
339
+ export type GrokTTSModel = (typeof GROK_TTS_MODELS)[number]
340
+ export type GrokTranscriptionModel = (typeof GROK_TRANSCRIPTION_MODELS)[number]
341
+ export type GrokRealtimeModel = (typeof GROK_REALTIME_MODELS)[number]
288
342
 
289
343
  /**
290
344
  * Type-only map from Grok chat model name to its supported input modalities.