@juspay/neurolink 7.53.3 → 7.53.4

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
+ ## [7.53.4](https://github.com/juspay/neurolink/compare/v7.53.3...v7.53.4) (2025-11-05)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **(sdk):** structured object response in generate function ([f16d597](https://github.com/juspay/neurolink/commit/f16d597f8e9a64f24a7a6ad5344c93add524c23d))
6
+
1
7
  ## [7.53.3](https://github.com/juspay/neurolink/compare/v7.53.2...v7.53.3) (2025-11-03)
2
8
 
3
9
  ## [7.53.2](https://github.com/juspay/neurolink/compare/v7.53.1...v7.53.2) (2025-10-28)
package/README.md CHANGED
@@ -25,6 +25,7 @@ Extracted from production systems at Juspay and battle-tested at enterprise scal
25
25
 
26
26
  ## What's New (Q4 2025)
27
27
 
28
+ - **Structured Output with Zod Schemas** – Type-safe JSON generation with automatic validation using `schema` + `output.format: "json"` in `generate()`. → [Structured Output Guide](docs/features/structured-output.md)
28
29
  - **CSV File Support** – Attach CSV files to prompts for AI-powered data analysis with auto-detection. → [CSV Guide](docs/features/multimodal-chat.md#csv-file-support)
29
30
  - **PDF File Support** – Process PDF documents with native visual analysis for Vertex AI, Anthropic, Bedrock, AI Studio. → [PDF Guide](docs/features/pdf-support.md)
30
31
  - **LiteLLM Integration** – Access 100+ AI models from all major providers through unified interface. → [Setup Guide](docs/LITELLM-INTEGRATION.md)
@@ -24,6 +24,11 @@ export const textGenerationOptionsSchema = {
24
24
  type: "number",
25
25
  description: "The maximum number of tokens to generate.",
26
26
  },
27
+ output: {
28
+ type: "string",
29
+ description: "AI response format - specify just the format value (e.g., 'json', 'structured'). Note: This is automatically transformed to { format: value } for the API.",
30
+ allowedValues: ["text", "json", "structured", "none"],
31
+ },
27
32
  systemPrompt: {
28
33
  type: "string",
29
34
  description: "The system prompt to guide the AI's behavior.",
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { generateText, tool as createAISDKTool, jsonSchema } from "ai";
2
+ import { generateText, tool as createAISDKTool, jsonSchema, Output } from "ai";
3
3
  import { AIProviderName } from "../constants/enums.js";
4
4
  import { MiddlewareFactory } from "../middleware/factory.js";
5
5
  import { logger } from "../utils/logger.js";
@@ -301,6 +301,9 @@ export class BaseProvider {
301
301
  */
302
302
  async executeGeneration(model, messages, tools, options) {
303
303
  const shouldUseTools = !options.disableTools && this.supportsTools();
304
+ const useStructuredOutput = !!options.schema &&
305
+ (options.output?.format === "json" ||
306
+ options.output?.format === "structured");
304
307
  return await generateText({
305
308
  model,
306
309
  messages,
@@ -309,6 +312,10 @@ export class BaseProvider {
309
312
  toolChoice: shouldUseTools ? "auto" : "none",
310
313
  temperature: options.temperature,
311
314
  maxTokens: options.maxTokens,
315
+ ...(useStructuredOutput &&
316
+ options.schema && {
317
+ experimental_output: Output.object({ schema: options.schema }),
318
+ }),
312
319
  experimental_telemetry: this.getStreamTelemetryConfig(options, "generate"),
313
320
  onStepFinish: ({ toolCalls, toolResults }) => {
314
321
  logger.info("Tool execution completed", { toolResults, toolCalls });
@@ -439,9 +446,17 @@ export class BaseProvider {
439
446
  /**
440
447
  * Format the enhanced result
441
448
  */
442
- formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions) {
449
+ formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions, options) {
450
+ // Only access experimental_output if we set a schema
451
+ // (accessing it when not set throws an error)
452
+ const useStructuredOutput = !!options.schema &&
453
+ (options.output?.format === "json" ||
454
+ options.output?.format === "structured");
455
+ const content = useStructuredOutput
456
+ ? JSON.stringify(generateResult.experimental_output)
457
+ : generateResult.text;
443
458
  return {
444
- content: generateResult.text,
459
+ content,
445
460
  usage: {
446
461
  input: generateResult.usage?.promptTokens || 0,
447
462
  output: generateResult.usage?.completionTokens || 0,
@@ -579,7 +594,7 @@ export class BaseProvider {
579
594
  const responseTime = Date.now() - startTime;
580
595
  await this.recordPerformanceMetrics(generateResult.usage, responseTime);
581
596
  const { toolsUsed, toolExecutions } = this.extractToolInformation(generateResult);
582
- const enhancedResult = this.formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions);
597
+ const enhancedResult = this.formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions, options);
583
598
  return await this.enhanceResult(enhancedResult, options, startTime);
584
599
  }
585
600
  catch (error) {
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { generateText, tool as createAISDKTool, jsonSchema } from "ai";
2
+ import { generateText, tool as createAISDKTool, jsonSchema, Output } from "ai";
3
3
  import { AIProviderName } from "../constants/enums.js";
4
4
  import { MiddlewareFactory } from "../middleware/factory.js";
5
5
  import { logger } from "../utils/logger.js";
@@ -301,6 +301,9 @@ export class BaseProvider {
301
301
  */
302
302
  async executeGeneration(model, messages, tools, options) {
303
303
  const shouldUseTools = !options.disableTools && this.supportsTools();
304
+ const useStructuredOutput = !!options.schema &&
305
+ (options.output?.format === "json" ||
306
+ options.output?.format === "structured");
304
307
  return await generateText({
305
308
  model,
306
309
  messages,
@@ -309,6 +312,10 @@ export class BaseProvider {
309
312
  toolChoice: shouldUseTools ? "auto" : "none",
310
313
  temperature: options.temperature,
311
314
  maxTokens: options.maxTokens,
315
+ ...(useStructuredOutput &&
316
+ options.schema && {
317
+ experimental_output: Output.object({ schema: options.schema }),
318
+ }),
312
319
  experimental_telemetry: this.getStreamTelemetryConfig(options, "generate"),
313
320
  onStepFinish: ({ toolCalls, toolResults }) => {
314
321
  logger.info("Tool execution completed", { toolResults, toolCalls });
@@ -439,9 +446,17 @@ export class BaseProvider {
439
446
  /**
440
447
  * Format the enhanced result
441
448
  */
442
- formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions) {
449
+ formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions, options) {
450
+ // Only access experimental_output if we set a schema
451
+ // (accessing it when not set throws an error)
452
+ const useStructuredOutput = !!options.schema &&
453
+ (options.output?.format === "json" ||
454
+ options.output?.format === "structured");
455
+ const content = useStructuredOutput
456
+ ? JSON.stringify(generateResult.experimental_output)
457
+ : generateResult.text;
443
458
  return {
444
- content: generateResult.text,
459
+ content,
445
460
  usage: {
446
461
  input: generateResult.usage?.promptTokens || 0,
447
462
  output: generateResult.usage?.completionTokens || 0,
@@ -579,7 +594,7 @@ export class BaseProvider {
579
594
  const responseTime = Date.now() - startTime;
580
595
  await this.recordPerformanceMetrics(generateResult.usage, responseTime);
581
596
  const { toolsUsed, toolExecutions } = this.extractToolInformation(generateResult);
582
- const enhancedResult = this.formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions);
597
+ const enhancedResult = this.formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions, options);
583
598
  return await this.enhanceResult(enhancedResult, options, startTime);
584
599
  }
585
600
  catch (error) {
@@ -1221,6 +1221,8 @@ export class NeuroLink {
1221
1221
  temperature: options.temperature,
1222
1222
  maxTokens: options.maxTokens,
1223
1223
  systemPrompt: options.systemPrompt,
1224
+ schema: options.schema,
1225
+ output: options.output,
1224
1226
  disableTools: options.disableTools,
1225
1227
  enableAnalytics: options.enableAnalytics,
1226
1228
  enableEvaluation: options.enableEvaluation,
@@ -157,6 +157,9 @@ export type TextGenerationOptions = {
157
157
  maxTokens?: number;
158
158
  systemPrompt?: string;
159
159
  schema?: ZodUnknownSchema | Schema<unknown>;
160
+ output?: {
161
+ format?: "text" | "structured" | "json";
162
+ };
160
163
  tools?: Record<string, Tool>;
161
164
  timeout?: number | string;
162
165
  disableTools?: boolean;
package/dist/neurolink.js CHANGED
@@ -1221,6 +1221,8 @@ export class NeuroLink {
1221
1221
  temperature: options.temperature,
1222
1222
  maxTokens: options.maxTokens,
1223
1223
  systemPrompt: options.systemPrompt,
1224
+ schema: options.schema,
1225
+ output: options.output,
1224
1226
  disableTools: options.disableTools,
1225
1227
  enableAnalytics: options.enableAnalytics,
1226
1228
  enableEvaluation: options.enableEvaluation,
@@ -157,6 +157,9 @@ export type TextGenerationOptions = {
157
157
  maxTokens?: number;
158
158
  systemPrompt?: string;
159
159
  schema?: ZodUnknownSchema | Schema<unknown>;
160
+ output?: {
161
+ format?: "text" | "structured" | "json";
162
+ };
160
163
  tools?: Record<string, Tool>;
161
164
  timeout?: number | string;
162
165
  disableTools?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "7.53.3",
3
+ "version": "7.53.4",
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",