@juspay/neurolink 9.67.1 → 9.67.3

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.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Abstract base class for providers that talk to an OpenAI chat-completions
3
+ * shaped HTTP endpoint. Owns the entire request/stream/tool-loop pipeline
4
+ * so concrete providers only declare configuration + provider-specific
5
+ * quirks (env var names, default model, error mapping).
6
+ *
7
+ * Currently extended by:
8
+ * - OpenAICompatibleProvider (generic /v1/chat/completions backend)
9
+ * - LiteLLMProvider (LiteLLM proxy server)
10
+ * - DeepSeekProvider (api.deepseek.com)
11
+ *
12
+ * Subclasses provide:
13
+ * - getProviderName() / getDefaultModel() / formatProviderError() (abstract)
14
+ * - optional overrides: getFallbackModelName, getFallbackModels,
15
+ * adjustBuildBodyOptions, onStreamStart, getAvailableModels
16
+ *
17
+ * Nothing here imports from "ai" or "@ai-sdk/*". The base class is a
18
+ * direct HTTP client + multi-step tool-execution loop driven by SSE.
19
+ */
20
+ import type { AIProviderName } from "../constants/enums.js";
21
+ import { BaseProvider } from "../core/baseProvider.js";
22
+ import type { LanguageModel, OpenAICompatBuildBodyArgs, OpenAICompatStreamLifecycleListeners, Schema, StreamOptions, StreamResult, ZodUnknownSchema } from "../types/index.js";
23
+ /**
24
+ * Abstract HTTP+SSE provider for OpenAI chat-completions-shaped endpoints.
25
+ */
26
+ export declare abstract class OpenAIChatCompletionsProvider extends BaseProvider {
27
+ protected config: {
28
+ baseURL: string;
29
+ apiKey: string;
30
+ };
31
+ protected resolvedModel?: string;
32
+ constructor(providerName: AIProviderName, modelName: string | undefined, sdk: unknown, config: {
33
+ baseURL: string;
34
+ apiKey: string;
35
+ });
36
+ protected abstract getProviderName(): AIProviderName;
37
+ protected abstract getDefaultModel(): string;
38
+ protected abstract formatProviderError(error: unknown): Error;
39
+ /**
40
+ * Model name to return when `getDefaultModel()` is empty AND
41
+ * auto-discovery via `/models` finds nothing. Default "gpt-3.5-turbo".
42
+ */
43
+ protected getFallbackModelName(): string;
44
+ /**
45
+ * Hardcoded model names returned from `getAvailableModels()` when the
46
+ * remote `/models` endpoint can't be reached. Default empty.
47
+ */
48
+ protected getFallbackModels(): string[];
49
+ /**
50
+ * Hook to mutate the `buildBody` options before the wire body is
51
+ * constructed. Default identity. Override for model-specific quirks
52
+ * (e.g. LiteLLM's Gemini 2.5 maxTokens skip).
53
+ */
54
+ protected adjustBuildBodyOptions(_modelId: string, opts: OpenAICompatBuildBodyArgs["options"]): OpenAICompatBuildBodyArgs["options"];
55
+ /**
56
+ * Hook called once at the start of every `executeStream` invocation.
57
+ * Return lifecycle listeners (onUsage / onFinish) to receive deferred
58
+ * analytics events as the stream progresses. Default returns undefined
59
+ * (no extra wiring). LiteLLM uses this for the OTel span wrap with cost.
60
+ */
61
+ protected onStreamStart(_modelId: string): OpenAICompatStreamLifecycleListeners | undefined;
62
+ /**
63
+ * Returns true if `resolveModelName` should fall back to fetching
64
+ * `getAvailableModels()` and picking the first one when no explicit
65
+ * model is configured. Default true. Subclasses with a non-empty
66
+ * `getDefaultModel()` will never hit this branch anyway.
67
+ */
68
+ protected shouldAutoDiscoverModel(): boolean;
69
+ supportsTools(): boolean;
70
+ /**
71
+ * Returns a minimal V3-shaped model used by BaseProvider's `generate()`
72
+ * non-streaming path. Driven by the parent's `generateText`. The
73
+ * streaming path bypasses this entirely.
74
+ */
75
+ protected getAISDKModel(): Promise<LanguageModel>;
76
+ protected resolveModelName(): Promise<string>;
77
+ private buildDelegatingModel;
78
+ /**
79
+ * Streaming path — drives the chat-completions endpoint directly. No
80
+ * streamText, no AI SDK orchestrator. Tool calls, multi-step loops,
81
+ * telemetry, abort handling all inline.
82
+ */
83
+ protected executeStream(options: StreamOptions, _analysisSchema?: ZodUnknownSchema | Schema<unknown>): Promise<StreamResult>;
84
+ private runStreamLoop;
85
+ private streamOneStep;
86
+ private executeToolBatch;
87
+ /**
88
+ * Default implementation hits `${baseURL}/models`. Subclasses with a
89
+ * different endpoint path, caching, or fallback strategy should override.
90
+ */
91
+ getAvailableModels(): Promise<string[]>;
92
+ getFirstAvailableModel(): Promise<string>;
93
+ }