@juspay/neurolink 9.68.13 → 9.68.14

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.
@@ -1,78 +1,51 @@
1
- import { AIProviderName } from "../constants/enums.js";
2
- import { BaseProvider } from "../core/baseProvider.js";
3
- import type { NeuroLink } from "../neurolink.js";
4
- import type { EnhancedGenerateResult, TextGenerationOptions, ValidationSchema, StreamOptions, StreamResult } from "../types/index.js";
5
- import type { LanguageModel } from "../types/index.js";
1
+ import type { AIProviderName } from "../constants/enums.js";
2
+ import type { EnhancedGenerateResult, NeurolinkCredentials, OpenAICompatStreamLifecycleListeners, TextGenerationOptions } from "../types/index.js";
3
+ import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
6
4
  /**
7
- * OpenAI Provider v2 - BaseProvider Implementation
8
- * Migrated to use factory pattern with exact Google AI provider pattern
5
+ * OpenAI Provider direct HTTP, no AI SDK.
6
+ *
7
+ * OpenAI chat completions at api.openai.com/v1. All request / stream /
8
+ * tool-loop orchestration lives in `OpenAIChatCompletionsProvider`; this
9
+ * class adds:
10
+ * - OTel span wrap with cost (`onStreamStart`)
11
+ * - Native `/v1/embeddings` (`embed` / `embedMany`)
12
+ * - Image generation via `/v1/images/generations` (`executeImageGeneration`)
13
+ * - OpenAI-specific error mapping (`formatProviderError`)
14
+ *
15
+ * @see https://platform.openai.com/docs/api-reference
9
16
  */
10
- export declare class OpenAIProvider extends BaseProvider {
11
- private model;
12
- private credentials?;
13
- constructor(modelName?: string, neurolink?: NeuroLink, _region?: string, credentials?: {
14
- apiKey?: string;
15
- baseURL?: string;
16
- });
17
+ export declare class OpenAIProvider extends OpenAIChatCompletionsProvider {
18
+ constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["openai"]);
19
+ protected getProviderName(): AIProviderName;
20
+ protected getDefaultModel(): string;
21
+ formatProviderError(error: unknown): Error;
17
22
  /**
18
- * Check if this provider supports tool/function calling
23
+ * Wrap the stream in an OTel span to capture provider-level latency,
24
+ * token usage, finish reason, and cost. Mirrors the pre-migration
25
+ * `streamText`-span behaviour.
19
26
  */
20
- supportsTools(): boolean;
21
- getProviderName(): AIProviderName;
22
- getDefaultModel(): string;
27
+ protected onStreamStart(modelId: string): OpenAICompatStreamLifecycleListeners | undefined;
23
28
  /**
24
- * Get the default embedding model for OpenAI
25
- * @returns The default OpenAI embedding model name
29
+ * Default embedding model, overridable via OPENAI_EMBEDDING_MODEL env var.
26
30
  */
27
31
  protected getDefaultEmbeddingModel(): string;
28
32
  /**
29
- * Returns the Vercel AI SDK model instance for OpenAI
30
- */
31
- getAISDKModel(): LanguageModel;
32
- /**
33
- * OpenAI-specific tool validation and filtering
34
- * Filters out tools that might cause streaming issues
35
- */
36
- private validateAndFilterToolsForOpenAI;
37
- /**
38
- * Validate Zod schema structure
39
- */
40
- private validateZodSchema;
41
- /**
42
- * Validate tool structure for OpenAI compatibility
43
- * More lenient validation to avoid filtering out valid tools
44
- */
45
- /** Shared helper: mark a stream span as ERROR, record the exception, and end it. */
46
- private endStreamSpanWithError;
47
- private isValidToolStructure;
48
- /**
49
- * Validate tool parameters for OpenAI compatibility
50
- * Ensures the tool has either valid Zod schema or valid JSON schema
51
- */
52
- private isValidToolParameters;
53
- formatProviderError(error: unknown): Error;
54
- /**
55
- * executeGenerate method removed - generation is now handled by BaseProvider.
56
- * For details on the changes and migration steps, refer to the BaseProvider documentation
57
- * and the migration guide in the project repository.
58
- */
59
- protected executeStream(options: StreamOptions, _analysisSchema?: ValidationSchema): Promise<StreamResult>;
60
- private createOpenAITransformedStream;
61
- private extractOpenAIChunkContent;
62
- /**
63
- * Generate embeddings for text using OpenAI text-embedding models
33
+ * Generate an embedding for a single text input via native /v1/embeddings.
34
+ *
64
35
  * @param text - The text to embed
65
36
  * @param modelName - The embedding model to use (default: text-embedding-3-small)
66
37
  * @returns Promise resolving to the embedding vector
67
38
  */
68
39
  embed(text: string, modelName?: string): Promise<number[]>;
69
40
  /**
70
- * Generate embeddings for multiple texts in a single batch
41
+ * Generate embeddings for multiple texts in a single batch via native /v1/embeddings.
42
+ *
71
43
  * @param texts - The texts to embed
72
44
  * @param modelName - The embedding model to use (default: text-embedding-3-small)
73
45
  * @returns Promise resolving to an array of embedding vectors
74
46
  */
75
47
  embedMany(texts: string[], modelName?: string): Promise<number[][]>;
48
+ private callEmbeddings;
76
49
  /**
77
50
  * Image generation via the OpenAI Images API (`/v1/images/generations`).
78
51
  *
@@ -95,4 +68,3 @@ export declare class OpenAIProvider extends BaseProvider {
95
68
  */
96
69
  private aspectRatioToOpenAISize;
97
70
  }
98
- export default OpenAIProvider;