@juspay/neurolink 8.16.0 → 8.17.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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [8.17.0](https://github.com/juspay/neurolink/compare/v8.16.0...v8.17.0) (2025-12-16)
2
+
3
+ ### Features
4
+
5
+ - **(tts):** Add TTS type integration to GenerateOptions, GenerateResult, and StreamChunk ([e290330](https://github.com/juspay/neurolink/commit/e290330e8fe22a4cd0427185cbddbb8856fbd5ca))
6
+
1
7
  ## [8.16.0](https://github.com/juspay/neurolink/compare/v8.15.0...v8.16.0) (2025-12-16)
2
8
 
3
9
  ### Features
@@ -7,6 +7,7 @@ import type { ChatMessage, ConversationMemoryConfig } from "./conversation.js";
7
7
  import type { MiddlewareFactoryOptions } from "./middlewareTypes.js";
8
8
  import type { JsonValue } from "./common.js";
9
9
  import type { Content, ImageWithAltText } from "./content.js";
10
+ import type { TTSOptions, TTSResult } from "./ttsTypes.js";
10
11
  /**
11
12
  * Generate function options type - Primary method for content generation
12
13
  * Supports multimodal content while maintaining backward compatibility
@@ -52,6 +53,39 @@ export type GenerateOptions = {
52
53
  format?: "jpeg" | "png";
53
54
  transcribeAudio?: boolean;
54
55
  };
56
+ /**
57
+ * Text-to-Speech (TTS) configuration
58
+ *
59
+ * Enable audio generation from the text response. The generated audio will be
60
+ * returned in the result's `audio` field as a TTSResult object.
61
+ *
62
+ * @example Basic TTS
63
+ * ```typescript
64
+ * const result = await neurolink.generate({
65
+ * input: { text: "Tell me a story" },
66
+ * provider: "google-ai",
67
+ * tts: { enabled: true, voice: "en-US-Neural2-C" }
68
+ * });
69
+ * console.log(result.audio?.buffer); // Audio Buffer
70
+ * ```
71
+ *
72
+ * @example Advanced TTS with options
73
+ * ```typescript
74
+ * const result = await neurolink.generate({
75
+ * input: { text: "Speak slowly and clearly" },
76
+ * provider: "google-ai",
77
+ * tts: {
78
+ * enabled: true,
79
+ * voice: "en-US-Neural2-D",
80
+ * speed: 0.8,
81
+ * pitch: 2.0,
82
+ * format: "mp3",
83
+ * quality: "standard"
84
+ * }
85
+ * });
86
+ * ```
87
+ */
88
+ tts?: TTSOptions;
55
89
  provider?: AIProviderName | string;
56
90
  model?: string;
57
91
  region?: string;
@@ -144,6 +178,35 @@ export type GenerateResult = {
144
178
  outputs?: {
145
179
  text: string;
146
180
  };
181
+ /**
182
+ * Text-to-Speech audio result
183
+ *
184
+ * Contains the generated audio buffer and metadata when TTS is enabled.
185
+ * Generated by TTSProcessor.synthesize() using the specified provider.
186
+ *
187
+ * @example Accessing TTS audio
188
+ * ```typescript
189
+ * const result = await neurolink.generate({
190
+ * input: { text: "Hello world" },
191
+ * provider: "google-ai",
192
+ * tts: { enabled: true, voice: "en-US-Neural2-C" }
193
+ * });
194
+ *
195
+ * if (result.audio) {
196
+ * console.log(`Audio size: ${result.audio.size} bytes`);
197
+ * console.log(`Format: ${result.audio.format}`);
198
+ * if (result.audio.duration) {
199
+ * console.log(`Duration: ${result.audio.duration}s`);
200
+ * }
201
+ * if (result.audio.voice) {
202
+ * console.log(`Voice: ${result.audio.voice}`);
203
+ * }
204
+ * // Save or play the audio buffer
205
+ * fs.writeFileSync('output.mp3', result.audio.buffer);
206
+ * }
207
+ * ```
208
+ */
209
+ audio?: TTSResult;
147
210
  provider?: string;
148
211
  model?: string;
149
212
  usage?: TokenUsage;
@@ -9,6 +9,7 @@ import type { EvaluationData } from "../index.js";
9
9
  import type { UnknownRecord, JsonValue } from "./common.js";
10
10
  import type { MiddlewareFactoryOptions } from "../types/middlewareTypes.js";
11
11
  import type { ChatMessage } from "./conversation.js";
12
+ import type { TTSOptions, TTSChunk } from "./ttsTypes.js";
12
13
  /**
13
14
  * Progress tracking and metadata for streaming operations
14
15
  */
@@ -121,6 +122,60 @@ export type AudioChunk = {
121
122
  channels: number;
122
123
  encoding: PCMEncoding;
123
124
  };
125
+ /**
126
+ * Stream chunk type using discriminated union for type safety
127
+ *
128
+ * Used in streaming responses to deliver either text or TTS audio chunks.
129
+ * The discriminated union ensures type safety - only one variant can exist at a time.
130
+ *
131
+ * @example Processing text chunks
132
+ * ```typescript
133
+ * for await (const chunk of result.stream) {
134
+ * if (chunk.type === "text") {
135
+ * console.log(chunk.content); // TypeScript knows 'content' exists
136
+ * }
137
+ * }
138
+ * ```
139
+ *
140
+ * @example Processing audio chunks
141
+ * ```typescript
142
+ * const audioBuffer: Buffer[] = [];
143
+ * for await (const chunk of result.stream) {
144
+ * if (chunk.type === "audio") {
145
+ * audioBuffer.push(chunk.audioChunk.data); // TypeScript knows 'audioChunk' exists
146
+ * if (chunk.audioChunk.isFinal) {
147
+ * const fullAudio = Buffer.concat(audioBuffer);
148
+ * fs.writeFileSync('output.mp3', fullAudio);
149
+ * }
150
+ * }
151
+ * }
152
+ * ```
153
+ *
154
+ * @example Processing both text and audio
155
+ * ```typescript
156
+ * for await (const chunk of result.stream) {
157
+ * switch (chunk.type) {
158
+ * case "text":
159
+ * process.stdout.write(chunk.content);
160
+ * break;
161
+ * case "audio":
162
+ * playAudioChunk(chunk.audioChunk.data);
163
+ * break;
164
+ * }
165
+ * }
166
+ * ```
167
+ */
168
+ export type StreamChunk = {
169
+ /** Discriminator for text chunks */
170
+ type: "text";
171
+ /** Text content chunk */
172
+ content: string;
173
+ } | {
174
+ /** Discriminator for audio chunks */
175
+ type: "audio";
176
+ /** TTS audio chunk data */
177
+ audioChunk: TTSChunk;
178
+ };
124
179
  export type StreamOptions = {
125
180
  input: {
126
181
  text: string;
@@ -168,6 +223,46 @@ export type StreamOptions = {
168
223
  format?: "jpeg" | "png";
169
224
  transcribeAudio?: boolean;
170
225
  };
226
+ /**
227
+ * Text-to-Speech (TTS) configuration for streaming
228
+ *
229
+ * Enable audio generation from the streamed text response. Audio chunks will be
230
+ * delivered through the stream alongside text chunks as TTSChunk objects.
231
+ *
232
+ * @example Basic streaming TTS
233
+ * ```typescript
234
+ * const result = await neurolink.stream({
235
+ * input: { text: "Tell me a story" },
236
+ * provider: "google-ai",
237
+ * tts: { enabled: true, voice: "en-US-Neural2-C" }
238
+ * });
239
+ *
240
+ * for await (const chunk of result.stream) {
241
+ * if (chunk.type === "text") {
242
+ * process.stdout.write(chunk.content);
243
+ * } else if (chunk.type === "audio") {
244
+ * // Handle audio chunk
245
+ * playAudioChunk(chunk.audioChunk.data);
246
+ * }
247
+ * }
248
+ * ```
249
+ *
250
+ * @example Advanced streaming TTS with audio buffer
251
+ * ```typescript
252
+ * const result = await neurolink.stream({
253
+ * input: { text: "Speak slowly" },
254
+ * provider: "google-ai",
255
+ * tts: {
256
+ * enabled: true,
257
+ * voice: "en-US-Neural2-D",
258
+ * speed: 0.8,
259
+ * format: "mp3",
260
+ * quality: "hd"
261
+ * }
262
+ * });
263
+ * ```
264
+ */
265
+ tts?: TTSOptions;
171
266
  provider?: AIProviderName | string;
172
267
  model?: string;
173
268
  region?: string;
@@ -114,3 +114,27 @@ export declare function isTTSResult(value: unknown): value is TTSResult;
114
114
  * Type guard to check if TTSOptions are valid
115
115
  */
116
116
  export declare function isValidTTSOptions(options: unknown): options is TTSOptions;
117
+ /**
118
+ * TTS audio chunk for streaming Text-to-Speech output
119
+ *
120
+ * Represents a chunk of audio data generated during streaming TTS.
121
+ * Used in StreamChunk type to deliver audio alongside text content.
122
+ */
123
+ export type TTSChunk = {
124
+ /** Audio data chunk as Buffer */
125
+ data: Buffer;
126
+ /** Audio format of this chunk */
127
+ format: AudioFormat;
128
+ /** Chunk sequence number (0-indexed) */
129
+ index: number;
130
+ /** Whether this is the final audio chunk */
131
+ isFinal: boolean;
132
+ /** Cumulative audio size in bytes so far */
133
+ cumulativeSize?: number;
134
+ /** Estimated total duration in seconds (if available) */
135
+ estimatedDuration?: number;
136
+ /** Voice used for generation */
137
+ voice?: string;
138
+ /** Sample rate in Hz */
139
+ sampleRate?: number;
140
+ };
@@ -7,6 +7,7 @@ import type { ChatMessage, ConversationMemoryConfig } from "./conversation.js";
7
7
  import type { MiddlewareFactoryOptions } from "./middlewareTypes.js";
8
8
  import type { JsonValue } from "./common.js";
9
9
  import type { Content, ImageWithAltText } from "./content.js";
10
+ import type { TTSOptions, TTSResult } from "./ttsTypes.js";
10
11
  /**
11
12
  * Generate function options type - Primary method for content generation
12
13
  * Supports multimodal content while maintaining backward compatibility
@@ -52,6 +53,39 @@ export type GenerateOptions = {
52
53
  format?: "jpeg" | "png";
53
54
  transcribeAudio?: boolean;
54
55
  };
56
+ /**
57
+ * Text-to-Speech (TTS) configuration
58
+ *
59
+ * Enable audio generation from the text response. The generated audio will be
60
+ * returned in the result's `audio` field as a TTSResult object.
61
+ *
62
+ * @example Basic TTS
63
+ * ```typescript
64
+ * const result = await neurolink.generate({
65
+ * input: { text: "Tell me a story" },
66
+ * provider: "google-ai",
67
+ * tts: { enabled: true, voice: "en-US-Neural2-C" }
68
+ * });
69
+ * console.log(result.audio?.buffer); // Audio Buffer
70
+ * ```
71
+ *
72
+ * @example Advanced TTS with options
73
+ * ```typescript
74
+ * const result = await neurolink.generate({
75
+ * input: { text: "Speak slowly and clearly" },
76
+ * provider: "google-ai",
77
+ * tts: {
78
+ * enabled: true,
79
+ * voice: "en-US-Neural2-D",
80
+ * speed: 0.8,
81
+ * pitch: 2.0,
82
+ * format: "mp3",
83
+ * quality: "standard"
84
+ * }
85
+ * });
86
+ * ```
87
+ */
88
+ tts?: TTSOptions;
55
89
  provider?: AIProviderName | string;
56
90
  model?: string;
57
91
  region?: string;
@@ -144,6 +178,35 @@ export type GenerateResult = {
144
178
  outputs?: {
145
179
  text: string;
146
180
  };
181
+ /**
182
+ * Text-to-Speech audio result
183
+ *
184
+ * Contains the generated audio buffer and metadata when TTS is enabled.
185
+ * Generated by TTSProcessor.synthesize() using the specified provider.
186
+ *
187
+ * @example Accessing TTS audio
188
+ * ```typescript
189
+ * const result = await neurolink.generate({
190
+ * input: { text: "Hello world" },
191
+ * provider: "google-ai",
192
+ * tts: { enabled: true, voice: "en-US-Neural2-C" }
193
+ * });
194
+ *
195
+ * if (result.audio) {
196
+ * console.log(`Audio size: ${result.audio.size} bytes`);
197
+ * console.log(`Format: ${result.audio.format}`);
198
+ * if (result.audio.duration) {
199
+ * console.log(`Duration: ${result.audio.duration}s`);
200
+ * }
201
+ * if (result.audio.voice) {
202
+ * console.log(`Voice: ${result.audio.voice}`);
203
+ * }
204
+ * // Save or play the audio buffer
205
+ * fs.writeFileSync('output.mp3', result.audio.buffer);
206
+ * }
207
+ * ```
208
+ */
209
+ audio?: TTSResult;
147
210
  provider?: string;
148
211
  model?: string;
149
212
  usage?: TokenUsage;
@@ -9,6 +9,7 @@ import type { EvaluationData } from "../index.js";
9
9
  import type { UnknownRecord, JsonValue } from "./common.js";
10
10
  import type { MiddlewareFactoryOptions } from "../types/middlewareTypes.js";
11
11
  import type { ChatMessage } from "./conversation.js";
12
+ import type { TTSOptions, TTSChunk } from "./ttsTypes.js";
12
13
  /**
13
14
  * Progress tracking and metadata for streaming operations
14
15
  */
@@ -121,6 +122,60 @@ export type AudioChunk = {
121
122
  channels: number;
122
123
  encoding: PCMEncoding;
123
124
  };
125
+ /**
126
+ * Stream chunk type using discriminated union for type safety
127
+ *
128
+ * Used in streaming responses to deliver either text or TTS audio chunks.
129
+ * The discriminated union ensures type safety - only one variant can exist at a time.
130
+ *
131
+ * @example Processing text chunks
132
+ * ```typescript
133
+ * for await (const chunk of result.stream) {
134
+ * if (chunk.type === "text") {
135
+ * console.log(chunk.content); // TypeScript knows 'content' exists
136
+ * }
137
+ * }
138
+ * ```
139
+ *
140
+ * @example Processing audio chunks
141
+ * ```typescript
142
+ * const audioBuffer: Buffer[] = [];
143
+ * for await (const chunk of result.stream) {
144
+ * if (chunk.type === "audio") {
145
+ * audioBuffer.push(chunk.audioChunk.data); // TypeScript knows 'audioChunk' exists
146
+ * if (chunk.audioChunk.isFinal) {
147
+ * const fullAudio = Buffer.concat(audioBuffer);
148
+ * fs.writeFileSync('output.mp3', fullAudio);
149
+ * }
150
+ * }
151
+ * }
152
+ * ```
153
+ *
154
+ * @example Processing both text and audio
155
+ * ```typescript
156
+ * for await (const chunk of result.stream) {
157
+ * switch (chunk.type) {
158
+ * case "text":
159
+ * process.stdout.write(chunk.content);
160
+ * break;
161
+ * case "audio":
162
+ * playAudioChunk(chunk.audioChunk.data);
163
+ * break;
164
+ * }
165
+ * }
166
+ * ```
167
+ */
168
+ export type StreamChunk = {
169
+ /** Discriminator for text chunks */
170
+ type: "text";
171
+ /** Text content chunk */
172
+ content: string;
173
+ } | {
174
+ /** Discriminator for audio chunks */
175
+ type: "audio";
176
+ /** TTS audio chunk data */
177
+ audioChunk: TTSChunk;
178
+ };
124
179
  export type StreamOptions = {
125
180
  input: {
126
181
  text: string;
@@ -168,6 +223,46 @@ export type StreamOptions = {
168
223
  format?: "jpeg" | "png";
169
224
  transcribeAudio?: boolean;
170
225
  };
226
+ /**
227
+ * Text-to-Speech (TTS) configuration for streaming
228
+ *
229
+ * Enable audio generation from the streamed text response. Audio chunks will be
230
+ * delivered through the stream alongside text chunks as TTSChunk objects.
231
+ *
232
+ * @example Basic streaming TTS
233
+ * ```typescript
234
+ * const result = await neurolink.stream({
235
+ * input: { text: "Tell me a story" },
236
+ * provider: "google-ai",
237
+ * tts: { enabled: true, voice: "en-US-Neural2-C" }
238
+ * });
239
+ *
240
+ * for await (const chunk of result.stream) {
241
+ * if (chunk.type === "text") {
242
+ * process.stdout.write(chunk.content);
243
+ * } else if (chunk.type === "audio") {
244
+ * // Handle audio chunk
245
+ * playAudioChunk(chunk.audioChunk.data);
246
+ * }
247
+ * }
248
+ * ```
249
+ *
250
+ * @example Advanced streaming TTS with audio buffer
251
+ * ```typescript
252
+ * const result = await neurolink.stream({
253
+ * input: { text: "Speak slowly" },
254
+ * provider: "google-ai",
255
+ * tts: {
256
+ * enabled: true,
257
+ * voice: "en-US-Neural2-D",
258
+ * speed: 0.8,
259
+ * format: "mp3",
260
+ * quality: "hd"
261
+ * }
262
+ * });
263
+ * ```
264
+ */
265
+ tts?: TTSOptions;
171
266
  provider?: AIProviderName | string;
172
267
  model?: string;
173
268
  region?: string;
@@ -114,3 +114,27 @@ export declare function isTTSResult(value: unknown): value is TTSResult;
114
114
  * Type guard to check if TTSOptions are valid
115
115
  */
116
116
  export declare function isValidTTSOptions(options: unknown): options is TTSOptions;
117
+ /**
118
+ * TTS audio chunk for streaming Text-to-Speech output
119
+ *
120
+ * Represents a chunk of audio data generated during streaming TTS.
121
+ * Used in StreamChunk type to deliver audio alongside text content.
122
+ */
123
+ export type TTSChunk = {
124
+ /** Audio data chunk as Buffer */
125
+ data: Buffer;
126
+ /** Audio format of this chunk */
127
+ format: AudioFormat;
128
+ /** Chunk sequence number (0-indexed) */
129
+ index: number;
130
+ /** Whether this is the final audio chunk */
131
+ isFinal: boolean;
132
+ /** Cumulative audio size in bytes so far */
133
+ cumulativeSize?: number;
134
+ /** Estimated total duration in seconds (if available) */
135
+ estimatedDuration?: number;
136
+ /** Voice used for generation */
137
+ voice?: string;
138
+ /** Sample rate in Hz */
139
+ sampleRate?: number;
140
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "8.16.0",
3
+ "version": "8.17.0",
4
4
  "description": "Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and deploy AI applications with 9 major providers: OpenAI, Anthropic, Google AI, AWS Bedrock, Azure, Hugging Face, Ollama, and Mistral AI.",
5
5
  "author": {
6
6
  "name": "Juspay Technologies",