@jerome-benoit/sap-ai-provider 4.2.2 → 4.2.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.
- package/dist/index.cjs +41 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -56
- package/dist/index.d.ts +87 -56
- package/dist/index.js +40 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EmbeddingModelV3, EmbeddingModelV3CallOptions, EmbeddingModelV3Result, LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { DeploymentIdConfig, ResourceGroupConfig } from '@sap-ai-sdk/ai-api/internal.js';
|
|
3
|
-
import { EmbeddingModelParams, FilteringModule, GroundingModule, MaskingModule, ChatCompletionTool, TranslationModule
|
|
3
|
+
import { EmbeddingModelParams, ChatModel, FilteringModule, GroundingModule, MaskingModule, ChatCompletionTool, TranslationModule } from '@sap-ai-sdk/orchestration';
|
|
4
4
|
export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMessage, DeveloperChatMessage, DocumentTranslationApplyToSelector, FilteringModule, FunctionObject, GroundingModule, LlmModelDetails, LlmModelParams, MaskingModule, OrchestrationClient, OrchestrationConfigRef, OrchestrationEmbeddingClient, OrchestrationErrorResponse, OrchestrationModuleConfig, OrchestrationResponse, OrchestrationStreamChunkResponse, OrchestrationStreamResponse, PromptTemplatingModule, SystemChatMessage, ToolChatMessage, TranslationApplyToCategory, TranslationInputParameters, TranslationModule, TranslationOutputParameters, TranslationTargetLanguage, UserChatMessage, buildAzureContentSafetyFilter, buildDocumentGroundingConfig, buildDpiMaskingProvider, buildLlamaGuard38BFilter, buildTranslationConfig, isConfigReference } from '@sap-ai-sdk/orchestration';
|
|
5
5
|
import { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
|
|
6
6
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
@@ -8,6 +8,8 @@ import { InferSchema } from '@ai-sdk/provider-utils';
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* SAP AI Embedding Model - Vercel AI SDK EmbeddingModelV3 implementation for SAP AI Core.
|
|
11
|
+
*
|
|
12
|
+
* This is the main implementation containing all business logic for SAP AI Core embedding generation.
|
|
11
13
|
* @module sap-ai-embedding-model
|
|
12
14
|
*/
|
|
13
15
|
|
|
@@ -33,9 +35,10 @@ interface SAPAIEmbeddingSettings {
|
|
|
33
35
|
readonly type?: "document" | "query" | "text";
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
38
|
+
* Internal configuration for SAP AI Embedding Model.
|
|
36
39
|
* @internal
|
|
37
40
|
*/
|
|
38
|
-
interface
|
|
41
|
+
interface SAPAIEmbeddingModelConfig {
|
|
39
42
|
readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
40
43
|
readonly destination?: HttpDestinationOrFetchOptions;
|
|
41
44
|
readonly provider: string;
|
|
@@ -63,11 +66,21 @@ declare class SAPAIEmbeddingModel implements EmbeddingModelV3 {
|
|
|
63
66
|
readonly supportsParallelCalls: boolean;
|
|
64
67
|
private readonly config;
|
|
65
68
|
private readonly settings;
|
|
66
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new SAP AI Embedding Model instance.
|
|
71
|
+
*
|
|
72
|
+
* This is the main implementation that handles all SAP AI Core embedding logic.
|
|
73
|
+
* @param modelId - The model identifier (e.g., 'text-embedding-ada-002', 'text-embedding-3-small').
|
|
74
|
+
* @param settings - Model configuration settings (embedding type, model parameters, etc.). Defaults to {}.
|
|
75
|
+
* @param config - SAP AI Core deployment and destination configuration.
|
|
76
|
+
*/
|
|
77
|
+
constructor(modelId: SAPAIEmbeddingModelId, settings: SAPAIEmbeddingSettings | undefined, config: SAPAIEmbeddingModelConfig);
|
|
67
78
|
/**
|
|
68
79
|
* Generates embeddings for the given input values.
|
|
69
|
-
*
|
|
70
|
-
*
|
|
80
|
+
*
|
|
81
|
+
* Validates input count, merges settings, calls SAP AI SDK, and normalizes embeddings.
|
|
82
|
+
* @param options - The Vercel AI SDK V3 embedding call options.
|
|
83
|
+
* @returns The embedding result with vectors, usage data, and warnings.
|
|
71
84
|
*/
|
|
72
85
|
doEmbed(options: EmbeddingModelV3CallOptions): Promise<EmbeddingModelV3Result>;
|
|
73
86
|
/**
|
|
@@ -86,43 +99,6 @@ declare class SAPAIEmbeddingModel implements EmbeddingModelV3 {
|
|
|
86
99
|
private normalizeEmbedding;
|
|
87
100
|
}
|
|
88
101
|
|
|
89
|
-
/** Default provider name used as key in `providerOptions` and `providerMetadata` objects. */
|
|
90
|
-
declare const SAP_AI_PROVIDER_NAME: "sap-ai";
|
|
91
|
-
/**
|
|
92
|
-
* Extracts the provider name from a provider identifier (e.g., "sap-ai.chat" → "sap-ai").
|
|
93
|
-
* @param providerIdentifier - The full provider identifier string.
|
|
94
|
-
* @returns The provider name without any suffix.
|
|
95
|
-
*/
|
|
96
|
-
declare function getProviderName(providerIdentifier: string): string;
|
|
97
|
-
/** Zod schema for SAP AI language model provider options passed via `providerOptions['sap-ai']` object. */
|
|
98
|
-
declare const sapAILanguageModelProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
99
|
-
includeReasoning?: boolean | undefined;
|
|
100
|
-
modelParams?: {
|
|
101
|
-
[x: string]: unknown;
|
|
102
|
-
frequencyPenalty?: number | undefined;
|
|
103
|
-
maxTokens?: number | undefined;
|
|
104
|
-
n?: number | undefined;
|
|
105
|
-
parallel_tool_calls?: boolean | undefined;
|
|
106
|
-
presencePenalty?: number | undefined;
|
|
107
|
-
temperature?: number | undefined;
|
|
108
|
-
topP?: number | undefined;
|
|
109
|
-
} | undefined;
|
|
110
|
-
}>;
|
|
111
|
-
/** SAP AI language model provider options type inferred from Zod schema. */
|
|
112
|
-
type SAPAILanguageModelProviderOptions = InferSchema<typeof sapAILanguageModelProviderOptions>;
|
|
113
|
-
/** Zod schema for SAP AI embedding model provider options passed via `providerOptions['sap-ai']` object. */
|
|
114
|
-
declare const sapAIEmbeddingProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
115
|
-
modelParams?: {
|
|
116
|
-
[x: string]: unknown;
|
|
117
|
-
dimensions?: number | undefined;
|
|
118
|
-
encoding_format?: "base64" | "binary" | "float" | undefined;
|
|
119
|
-
normalize?: boolean | undefined;
|
|
120
|
-
} | undefined;
|
|
121
|
-
type?: "document" | "query" | "text" | undefined;
|
|
122
|
-
}>;
|
|
123
|
-
/** SAP AI embedding model provider options type inferred from Zod schema. */
|
|
124
|
-
type SAPAIEmbeddingProviderOptions = InferSchema<typeof sapAIEmbeddingProviderOptions>;
|
|
125
|
-
|
|
126
102
|
/**
|
|
127
103
|
* Supported model IDs in SAP AI Core.
|
|
128
104
|
* Actual availability depends on your SAP AI Core tenant configuration.
|
|
@@ -185,18 +161,21 @@ interface SAPAISettings {
|
|
|
185
161
|
|
|
186
162
|
/**
|
|
187
163
|
* SAP AI Language Model - Vercel AI SDK LanguageModelV3 implementation for SAP AI Core Orchestration.
|
|
164
|
+
*
|
|
165
|
+
* This is the main implementation containing all business logic for SAP AI Core integration.
|
|
188
166
|
*/
|
|
189
167
|
|
|
190
168
|
/**
|
|
169
|
+
* Internal configuration for SAP AI Language Model.
|
|
191
170
|
* @internal
|
|
192
171
|
*/
|
|
193
|
-
interface
|
|
172
|
+
interface SAPAILanguageModelConfig {
|
|
194
173
|
readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
195
174
|
readonly destination?: HttpDestinationOrFetchOptions;
|
|
196
175
|
readonly provider: string;
|
|
197
176
|
}
|
|
198
177
|
/**
|
|
199
|
-
* SAP AI
|
|
178
|
+
* SAP AI Language Model implementing Vercel AI SDK LanguageModelV3.
|
|
200
179
|
*
|
|
201
180
|
* Features: text generation, tool calling, multi-modal input, data masking, content filtering.
|
|
202
181
|
* Supports: Azure OpenAI, Google Vertex AI, AWS Bedrock, AI Core open source models.
|
|
@@ -234,23 +213,31 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
|
|
|
234
213
|
private readonly settings;
|
|
235
214
|
/**
|
|
236
215
|
* Creates a new SAP AI Language Model instance.
|
|
237
|
-
*
|
|
238
|
-
*
|
|
216
|
+
*
|
|
217
|
+
* This is the main implementation that handles all SAP AI Core orchestration logic.
|
|
218
|
+
* @param modelId - The model identifier (e.g., 'gpt-4o', 'claude-3-5-sonnet', 'gemini-2.0-flash').
|
|
219
|
+
* @param settings - Model configuration settings (temperature, max tokens, filtering, etc.).
|
|
239
220
|
* @param config - SAP AI Core deployment and destination configuration.
|
|
240
221
|
* @internal
|
|
241
222
|
*/
|
|
242
|
-
constructor(modelId: SAPAIModelId, settings: SAPAISettings, config:
|
|
223
|
+
constructor(modelId: SAPAIModelId, settings: SAPAISettings, config: SAPAILanguageModelConfig);
|
|
243
224
|
/**
|
|
244
225
|
* Generates a single completion (non-streaming).
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
226
|
+
*
|
|
227
|
+
* Builds orchestration configuration, converts messages, validates parameters,
|
|
228
|
+
* calls SAP AI SDK, and processes the response.
|
|
229
|
+
* Supports request cancellation via AbortSignal at the HTTP transport layer.
|
|
230
|
+
* @param options - The Vercel AI SDK V3 generation call options.
|
|
231
|
+
* @returns The generation result with content, usage, warnings, and provider metadata.
|
|
248
232
|
*/
|
|
249
233
|
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
250
234
|
/**
|
|
251
235
|
* Generates a streaming completion.
|
|
252
|
-
*
|
|
253
|
-
*
|
|
236
|
+
*
|
|
237
|
+
* Builds orchestration configuration, creates streaming client, and transforms
|
|
238
|
+
* the stream with proper event handling (text blocks, tool calls, finish reason).
|
|
239
|
+
* Supports request cancellation via AbortSignal at the HTTP transport layer.
|
|
240
|
+
* @param options - The Vercel AI SDK V3 generation call options.
|
|
254
241
|
* @returns A stream result with async iterable stream parts.
|
|
255
242
|
*/
|
|
256
243
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
@@ -276,18 +263,55 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
|
|
|
276
263
|
private createClient;
|
|
277
264
|
}
|
|
278
265
|
|
|
266
|
+
/** Default provider name used as key in `providerOptions` and `providerMetadata` objects. */
|
|
267
|
+
declare const SAP_AI_PROVIDER_NAME: "sap-ai";
|
|
268
|
+
/**
|
|
269
|
+
* Extracts the provider name from a provider identifier (e.g., "sap-ai.chat" → "sap-ai").
|
|
270
|
+
* @param providerIdentifier - The full provider identifier string.
|
|
271
|
+
* @returns The provider name without any suffix.
|
|
272
|
+
*/
|
|
273
|
+
declare function getProviderName(providerIdentifier: string): string;
|
|
274
|
+
/** Zod schema for SAP AI language model provider options passed via `providerOptions['sap-ai']` object. */
|
|
275
|
+
declare const sapAILanguageModelProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
276
|
+
includeReasoning?: boolean | undefined;
|
|
277
|
+
modelParams?: {
|
|
278
|
+
[x: string]: unknown;
|
|
279
|
+
frequencyPenalty?: number | undefined;
|
|
280
|
+
maxTokens?: number | undefined;
|
|
281
|
+
n?: number | undefined;
|
|
282
|
+
parallel_tool_calls?: boolean | undefined;
|
|
283
|
+
presencePenalty?: number | undefined;
|
|
284
|
+
temperature?: number | undefined;
|
|
285
|
+
topP?: number | undefined;
|
|
286
|
+
} | undefined;
|
|
287
|
+
}>;
|
|
288
|
+
/** SAP AI language model provider options type inferred from Zod schema. */
|
|
289
|
+
type SAPAILanguageModelProviderOptions = InferSchema<typeof sapAILanguageModelProviderOptions>;
|
|
290
|
+
/** Zod schema for SAP AI embedding model provider options passed via `providerOptions['sap-ai']` object. */
|
|
291
|
+
declare const sapAIEmbeddingProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
292
|
+
modelParams?: {
|
|
293
|
+
[x: string]: unknown;
|
|
294
|
+
dimensions?: number | undefined;
|
|
295
|
+
encoding_format?: "base64" | "binary" | "float" | undefined;
|
|
296
|
+
normalize?: boolean | undefined;
|
|
297
|
+
} | undefined;
|
|
298
|
+
type?: "document" | "query" | "text" | undefined;
|
|
299
|
+
}>;
|
|
300
|
+
/** SAP AI embedding model provider options type inferred from Zod schema. */
|
|
301
|
+
type SAPAIEmbeddingProviderOptions = InferSchema<typeof sapAIEmbeddingProviderOptions>;
|
|
302
|
+
|
|
279
303
|
/** Deployment configuration type used by the SAP AI SDK. */
|
|
280
304
|
type DeploymentConfig = DeploymentIdConfig | ResourceGroupConfig;
|
|
281
305
|
/**
|
|
282
306
|
* SAP AI Provider interface for creating and configuring SAP AI Core models.
|
|
283
|
-
* Extends the
|
|
307
|
+
* Extends the Vercel AI SDK ProviderV3 interface with SAP-specific functionality.
|
|
284
308
|
*/
|
|
285
309
|
interface SAPAIProvider extends ProviderV3 {
|
|
286
310
|
/** Creates a language model instance. */
|
|
287
311
|
(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAILanguageModel;
|
|
288
|
-
/** Creates a
|
|
312
|
+
/** Creates a language model instance (custom convenience method). */
|
|
289
313
|
chat(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAILanguageModel;
|
|
290
|
-
/** Creates an embedding model instance. */
|
|
314
|
+
/** Creates an embedding model instance (custom convenience method). */
|
|
291
315
|
embedding(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModel;
|
|
292
316
|
/** Creates an embedding model instance (Vercel AI SDK ProviderV3 standard method). */
|
|
293
317
|
embeddingModel(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModel;
|
|
@@ -315,6 +339,13 @@ interface SAPAIProviderSettings {
|
|
|
315
339
|
readonly deploymentId?: string;
|
|
316
340
|
/** Custom destination configuration for SAP AI Core. */
|
|
317
341
|
readonly destination?: HttpDestinationOrFetchOptions;
|
|
342
|
+
/**
|
|
343
|
+
* Log level for SAP Cloud SDK loggers.
|
|
344
|
+
* Controls verbosity of internal SAP SDK logging (e.g., authentication, service binding).
|
|
345
|
+
* Note: SAP_CLOUD_SDK_LOG_LEVEL environment variable takes precedence if set.
|
|
346
|
+
* @default 'warn'
|
|
347
|
+
*/
|
|
348
|
+
readonly logLevel?: "debug" | "error" | "info" | "warn";
|
|
318
349
|
/**
|
|
319
350
|
* Provider name used as key for `providerOptions` and `providerMetadata`.
|
|
320
351
|
* @default 'sap-ai'
|
|
@@ -341,4 +372,4 @@ declare function createSAPAIProvider(options?: SAPAIProviderSettings): SAPAIProv
|
|
|
341
372
|
/** Default SAP AI provider instance with automatic authentication via SAP AI SDK. */
|
|
342
373
|
declare const sapai: SAPAIProvider;
|
|
343
374
|
|
|
344
|
-
export { type DeploymentConfig, SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, getProviderName, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
|
|
375
|
+
export { type DeploymentConfig, SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, SAPAILanguageModel, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, getProviderName, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EmbeddingModelV3, EmbeddingModelV3CallOptions, EmbeddingModelV3Result, LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { DeploymentIdConfig, ResourceGroupConfig } from '@sap-ai-sdk/ai-api/internal.js';
|
|
3
|
-
import { EmbeddingModelParams, FilteringModule, GroundingModule, MaskingModule, ChatCompletionTool, TranslationModule
|
|
3
|
+
import { EmbeddingModelParams, ChatModel, FilteringModule, GroundingModule, MaskingModule, ChatCompletionTool, TranslationModule } from '@sap-ai-sdk/orchestration';
|
|
4
4
|
export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMessage, DeveloperChatMessage, DocumentTranslationApplyToSelector, FilteringModule, FunctionObject, GroundingModule, LlmModelDetails, LlmModelParams, MaskingModule, OrchestrationClient, OrchestrationConfigRef, OrchestrationEmbeddingClient, OrchestrationErrorResponse, OrchestrationModuleConfig, OrchestrationResponse, OrchestrationStreamChunkResponse, OrchestrationStreamResponse, PromptTemplatingModule, SystemChatMessage, ToolChatMessage, TranslationApplyToCategory, TranslationInputParameters, TranslationModule, TranslationOutputParameters, TranslationTargetLanguage, UserChatMessage, buildAzureContentSafetyFilter, buildDocumentGroundingConfig, buildDpiMaskingProvider, buildLlamaGuard38BFilter, buildTranslationConfig, isConfigReference } from '@sap-ai-sdk/orchestration';
|
|
5
5
|
import { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
|
|
6
6
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
@@ -8,6 +8,8 @@ import { InferSchema } from '@ai-sdk/provider-utils';
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* SAP AI Embedding Model - Vercel AI SDK EmbeddingModelV3 implementation for SAP AI Core.
|
|
11
|
+
*
|
|
12
|
+
* This is the main implementation containing all business logic for SAP AI Core embedding generation.
|
|
11
13
|
* @module sap-ai-embedding-model
|
|
12
14
|
*/
|
|
13
15
|
|
|
@@ -33,9 +35,10 @@ interface SAPAIEmbeddingSettings {
|
|
|
33
35
|
readonly type?: "document" | "query" | "text";
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
38
|
+
* Internal configuration for SAP AI Embedding Model.
|
|
36
39
|
* @internal
|
|
37
40
|
*/
|
|
38
|
-
interface
|
|
41
|
+
interface SAPAIEmbeddingModelConfig {
|
|
39
42
|
readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
40
43
|
readonly destination?: HttpDestinationOrFetchOptions;
|
|
41
44
|
readonly provider: string;
|
|
@@ -63,11 +66,21 @@ declare class SAPAIEmbeddingModel implements EmbeddingModelV3 {
|
|
|
63
66
|
readonly supportsParallelCalls: boolean;
|
|
64
67
|
private readonly config;
|
|
65
68
|
private readonly settings;
|
|
66
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new SAP AI Embedding Model instance.
|
|
71
|
+
*
|
|
72
|
+
* This is the main implementation that handles all SAP AI Core embedding logic.
|
|
73
|
+
* @param modelId - The model identifier (e.g., 'text-embedding-ada-002', 'text-embedding-3-small').
|
|
74
|
+
* @param settings - Model configuration settings (embedding type, model parameters, etc.). Defaults to {}.
|
|
75
|
+
* @param config - SAP AI Core deployment and destination configuration.
|
|
76
|
+
*/
|
|
77
|
+
constructor(modelId: SAPAIEmbeddingModelId, settings: SAPAIEmbeddingSettings | undefined, config: SAPAIEmbeddingModelConfig);
|
|
67
78
|
/**
|
|
68
79
|
* Generates embeddings for the given input values.
|
|
69
|
-
*
|
|
70
|
-
*
|
|
80
|
+
*
|
|
81
|
+
* Validates input count, merges settings, calls SAP AI SDK, and normalizes embeddings.
|
|
82
|
+
* @param options - The Vercel AI SDK V3 embedding call options.
|
|
83
|
+
* @returns The embedding result with vectors, usage data, and warnings.
|
|
71
84
|
*/
|
|
72
85
|
doEmbed(options: EmbeddingModelV3CallOptions): Promise<EmbeddingModelV3Result>;
|
|
73
86
|
/**
|
|
@@ -86,43 +99,6 @@ declare class SAPAIEmbeddingModel implements EmbeddingModelV3 {
|
|
|
86
99
|
private normalizeEmbedding;
|
|
87
100
|
}
|
|
88
101
|
|
|
89
|
-
/** Default provider name used as key in `providerOptions` and `providerMetadata` objects. */
|
|
90
|
-
declare const SAP_AI_PROVIDER_NAME: "sap-ai";
|
|
91
|
-
/**
|
|
92
|
-
* Extracts the provider name from a provider identifier (e.g., "sap-ai.chat" → "sap-ai").
|
|
93
|
-
* @param providerIdentifier - The full provider identifier string.
|
|
94
|
-
* @returns The provider name without any suffix.
|
|
95
|
-
*/
|
|
96
|
-
declare function getProviderName(providerIdentifier: string): string;
|
|
97
|
-
/** Zod schema for SAP AI language model provider options passed via `providerOptions['sap-ai']` object. */
|
|
98
|
-
declare const sapAILanguageModelProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
99
|
-
includeReasoning?: boolean | undefined;
|
|
100
|
-
modelParams?: {
|
|
101
|
-
[x: string]: unknown;
|
|
102
|
-
frequencyPenalty?: number | undefined;
|
|
103
|
-
maxTokens?: number | undefined;
|
|
104
|
-
n?: number | undefined;
|
|
105
|
-
parallel_tool_calls?: boolean | undefined;
|
|
106
|
-
presencePenalty?: number | undefined;
|
|
107
|
-
temperature?: number | undefined;
|
|
108
|
-
topP?: number | undefined;
|
|
109
|
-
} | undefined;
|
|
110
|
-
}>;
|
|
111
|
-
/** SAP AI language model provider options type inferred from Zod schema. */
|
|
112
|
-
type SAPAILanguageModelProviderOptions = InferSchema<typeof sapAILanguageModelProviderOptions>;
|
|
113
|
-
/** Zod schema for SAP AI embedding model provider options passed via `providerOptions['sap-ai']` object. */
|
|
114
|
-
declare const sapAIEmbeddingProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
115
|
-
modelParams?: {
|
|
116
|
-
[x: string]: unknown;
|
|
117
|
-
dimensions?: number | undefined;
|
|
118
|
-
encoding_format?: "base64" | "binary" | "float" | undefined;
|
|
119
|
-
normalize?: boolean | undefined;
|
|
120
|
-
} | undefined;
|
|
121
|
-
type?: "document" | "query" | "text" | undefined;
|
|
122
|
-
}>;
|
|
123
|
-
/** SAP AI embedding model provider options type inferred from Zod schema. */
|
|
124
|
-
type SAPAIEmbeddingProviderOptions = InferSchema<typeof sapAIEmbeddingProviderOptions>;
|
|
125
|
-
|
|
126
102
|
/**
|
|
127
103
|
* Supported model IDs in SAP AI Core.
|
|
128
104
|
* Actual availability depends on your SAP AI Core tenant configuration.
|
|
@@ -185,18 +161,21 @@ interface SAPAISettings {
|
|
|
185
161
|
|
|
186
162
|
/**
|
|
187
163
|
* SAP AI Language Model - Vercel AI SDK LanguageModelV3 implementation for SAP AI Core Orchestration.
|
|
164
|
+
*
|
|
165
|
+
* This is the main implementation containing all business logic for SAP AI Core integration.
|
|
188
166
|
*/
|
|
189
167
|
|
|
190
168
|
/**
|
|
169
|
+
* Internal configuration for SAP AI Language Model.
|
|
191
170
|
* @internal
|
|
192
171
|
*/
|
|
193
|
-
interface
|
|
172
|
+
interface SAPAILanguageModelConfig {
|
|
194
173
|
readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
195
174
|
readonly destination?: HttpDestinationOrFetchOptions;
|
|
196
175
|
readonly provider: string;
|
|
197
176
|
}
|
|
198
177
|
/**
|
|
199
|
-
* SAP AI
|
|
178
|
+
* SAP AI Language Model implementing Vercel AI SDK LanguageModelV3.
|
|
200
179
|
*
|
|
201
180
|
* Features: text generation, tool calling, multi-modal input, data masking, content filtering.
|
|
202
181
|
* Supports: Azure OpenAI, Google Vertex AI, AWS Bedrock, AI Core open source models.
|
|
@@ -234,23 +213,31 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
|
|
|
234
213
|
private readonly settings;
|
|
235
214
|
/**
|
|
236
215
|
* Creates a new SAP AI Language Model instance.
|
|
237
|
-
*
|
|
238
|
-
*
|
|
216
|
+
*
|
|
217
|
+
* This is the main implementation that handles all SAP AI Core orchestration logic.
|
|
218
|
+
* @param modelId - The model identifier (e.g., 'gpt-4o', 'claude-3-5-sonnet', 'gemini-2.0-flash').
|
|
219
|
+
* @param settings - Model configuration settings (temperature, max tokens, filtering, etc.).
|
|
239
220
|
* @param config - SAP AI Core deployment and destination configuration.
|
|
240
221
|
* @internal
|
|
241
222
|
*/
|
|
242
|
-
constructor(modelId: SAPAIModelId, settings: SAPAISettings, config:
|
|
223
|
+
constructor(modelId: SAPAIModelId, settings: SAPAISettings, config: SAPAILanguageModelConfig);
|
|
243
224
|
/**
|
|
244
225
|
* Generates a single completion (non-streaming).
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
226
|
+
*
|
|
227
|
+
* Builds orchestration configuration, converts messages, validates parameters,
|
|
228
|
+
* calls SAP AI SDK, and processes the response.
|
|
229
|
+
* Supports request cancellation via AbortSignal at the HTTP transport layer.
|
|
230
|
+
* @param options - The Vercel AI SDK V3 generation call options.
|
|
231
|
+
* @returns The generation result with content, usage, warnings, and provider metadata.
|
|
248
232
|
*/
|
|
249
233
|
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
250
234
|
/**
|
|
251
235
|
* Generates a streaming completion.
|
|
252
|
-
*
|
|
253
|
-
*
|
|
236
|
+
*
|
|
237
|
+
* Builds orchestration configuration, creates streaming client, and transforms
|
|
238
|
+
* the stream with proper event handling (text blocks, tool calls, finish reason).
|
|
239
|
+
* Supports request cancellation via AbortSignal at the HTTP transport layer.
|
|
240
|
+
* @param options - The Vercel AI SDK V3 generation call options.
|
|
254
241
|
* @returns A stream result with async iterable stream parts.
|
|
255
242
|
*/
|
|
256
243
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
@@ -276,18 +263,55 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
|
|
|
276
263
|
private createClient;
|
|
277
264
|
}
|
|
278
265
|
|
|
266
|
+
/** Default provider name used as key in `providerOptions` and `providerMetadata` objects. */
|
|
267
|
+
declare const SAP_AI_PROVIDER_NAME: "sap-ai";
|
|
268
|
+
/**
|
|
269
|
+
* Extracts the provider name from a provider identifier (e.g., "sap-ai.chat" → "sap-ai").
|
|
270
|
+
* @param providerIdentifier - The full provider identifier string.
|
|
271
|
+
* @returns The provider name without any suffix.
|
|
272
|
+
*/
|
|
273
|
+
declare function getProviderName(providerIdentifier: string): string;
|
|
274
|
+
/** Zod schema for SAP AI language model provider options passed via `providerOptions['sap-ai']` object. */
|
|
275
|
+
declare const sapAILanguageModelProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
276
|
+
includeReasoning?: boolean | undefined;
|
|
277
|
+
modelParams?: {
|
|
278
|
+
[x: string]: unknown;
|
|
279
|
+
frequencyPenalty?: number | undefined;
|
|
280
|
+
maxTokens?: number | undefined;
|
|
281
|
+
n?: number | undefined;
|
|
282
|
+
parallel_tool_calls?: boolean | undefined;
|
|
283
|
+
presencePenalty?: number | undefined;
|
|
284
|
+
temperature?: number | undefined;
|
|
285
|
+
topP?: number | undefined;
|
|
286
|
+
} | undefined;
|
|
287
|
+
}>;
|
|
288
|
+
/** SAP AI language model provider options type inferred from Zod schema. */
|
|
289
|
+
type SAPAILanguageModelProviderOptions = InferSchema<typeof sapAILanguageModelProviderOptions>;
|
|
290
|
+
/** Zod schema for SAP AI embedding model provider options passed via `providerOptions['sap-ai']` object. */
|
|
291
|
+
declare const sapAIEmbeddingProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
292
|
+
modelParams?: {
|
|
293
|
+
[x: string]: unknown;
|
|
294
|
+
dimensions?: number | undefined;
|
|
295
|
+
encoding_format?: "base64" | "binary" | "float" | undefined;
|
|
296
|
+
normalize?: boolean | undefined;
|
|
297
|
+
} | undefined;
|
|
298
|
+
type?: "document" | "query" | "text" | undefined;
|
|
299
|
+
}>;
|
|
300
|
+
/** SAP AI embedding model provider options type inferred from Zod schema. */
|
|
301
|
+
type SAPAIEmbeddingProviderOptions = InferSchema<typeof sapAIEmbeddingProviderOptions>;
|
|
302
|
+
|
|
279
303
|
/** Deployment configuration type used by the SAP AI SDK. */
|
|
280
304
|
type DeploymentConfig = DeploymentIdConfig | ResourceGroupConfig;
|
|
281
305
|
/**
|
|
282
306
|
* SAP AI Provider interface for creating and configuring SAP AI Core models.
|
|
283
|
-
* Extends the
|
|
307
|
+
* Extends the Vercel AI SDK ProviderV3 interface with SAP-specific functionality.
|
|
284
308
|
*/
|
|
285
309
|
interface SAPAIProvider extends ProviderV3 {
|
|
286
310
|
/** Creates a language model instance. */
|
|
287
311
|
(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAILanguageModel;
|
|
288
|
-
/** Creates a
|
|
312
|
+
/** Creates a language model instance (custom convenience method). */
|
|
289
313
|
chat(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAILanguageModel;
|
|
290
|
-
/** Creates an embedding model instance. */
|
|
314
|
+
/** Creates an embedding model instance (custom convenience method). */
|
|
291
315
|
embedding(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModel;
|
|
292
316
|
/** Creates an embedding model instance (Vercel AI SDK ProviderV3 standard method). */
|
|
293
317
|
embeddingModel(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModel;
|
|
@@ -315,6 +339,13 @@ interface SAPAIProviderSettings {
|
|
|
315
339
|
readonly deploymentId?: string;
|
|
316
340
|
/** Custom destination configuration for SAP AI Core. */
|
|
317
341
|
readonly destination?: HttpDestinationOrFetchOptions;
|
|
342
|
+
/**
|
|
343
|
+
* Log level for SAP Cloud SDK loggers.
|
|
344
|
+
* Controls verbosity of internal SAP SDK logging (e.g., authentication, service binding).
|
|
345
|
+
* Note: SAP_CLOUD_SDK_LOG_LEVEL environment variable takes precedence if set.
|
|
346
|
+
* @default 'warn'
|
|
347
|
+
*/
|
|
348
|
+
readonly logLevel?: "debug" | "error" | "info" | "warn";
|
|
318
349
|
/**
|
|
319
350
|
* Provider name used as key for `providerOptions` and `providerMetadata`.
|
|
320
351
|
* @default 'sap-ai'
|
|
@@ -341,4 +372,4 @@ declare function createSAPAIProvider(options?: SAPAIProviderSettings): SAPAIProv
|
|
|
341
372
|
/** Default SAP AI provider instance with automatic authentication via SAP AI SDK. */
|
|
342
373
|
declare const sapai: SAPAIProvider;
|
|
343
374
|
|
|
344
|
-
export { type DeploymentConfig, SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, getProviderName, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
|
|
375
|
+
export { type DeploymentConfig, SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, SAPAILanguageModel, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, getProviderName, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
|
package/dist/index.js
CHANGED
|
@@ -14146,7 +14146,7 @@ var require_cloud_sdk_logger = __commonJS({
|
|
|
14146
14146
|
exports.createLogger = createLogger;
|
|
14147
14147
|
exports.getLogger = getLogger;
|
|
14148
14148
|
exports.setLogLevel = setLogLevel;
|
|
14149
|
-
exports.setGlobalLogLevel =
|
|
14149
|
+
exports.setGlobalLogLevel = setGlobalLogLevel2;
|
|
14150
14150
|
exports.getGlobalLogLevel = getGlobalLogLevel;
|
|
14151
14151
|
exports.setGlobalTransports = setGlobalTransports;
|
|
14152
14152
|
exports.setLogFormat = setLogFormat;
|
|
@@ -14233,7 +14233,7 @@ var require_cloud_sdk_logger = __commonJS({
|
|
|
14233
14233
|
messageContextOrLogger.level = level;
|
|
14234
14234
|
}
|
|
14235
14235
|
}
|
|
14236
|
-
function
|
|
14236
|
+
function setGlobalLogLevel2(level) {
|
|
14237
14237
|
container.options.level = level;
|
|
14238
14238
|
container.loggers.forEach((logger) => {
|
|
14239
14239
|
logger.level = level;
|
|
@@ -30280,6 +30280,14 @@ var SAPAIEmbeddingModel = class {
|
|
|
30280
30280
|
supportsParallelCalls = true;
|
|
30281
30281
|
config;
|
|
30282
30282
|
settings;
|
|
30283
|
+
/**
|
|
30284
|
+
* Creates a new SAP AI Embedding Model instance.
|
|
30285
|
+
*
|
|
30286
|
+
* This is the main implementation that handles all SAP AI Core embedding logic.
|
|
30287
|
+
* @param modelId - The model identifier (e.g., 'text-embedding-ada-002', 'text-embedding-3-small').
|
|
30288
|
+
* @param settings - Model configuration settings (embedding type, model parameters, etc.). Defaults to {}.
|
|
30289
|
+
* @param config - SAP AI Core deployment and destination configuration.
|
|
30290
|
+
*/
|
|
30283
30291
|
constructor(modelId, settings = {}, config) {
|
|
30284
30292
|
if (settings.modelParams) {
|
|
30285
30293
|
validateEmbeddingModelParamsSettings(settings.modelParams);
|
|
@@ -30292,8 +30300,10 @@ var SAPAIEmbeddingModel = class {
|
|
|
30292
30300
|
}
|
|
30293
30301
|
/**
|
|
30294
30302
|
* Generates embeddings for the given input values.
|
|
30295
|
-
*
|
|
30296
|
-
*
|
|
30303
|
+
*
|
|
30304
|
+
* Validates input count, merges settings, calls SAP AI SDK, and normalizes embeddings.
|
|
30305
|
+
* @param options - The Vercel AI SDK V3 embedding call options.
|
|
30306
|
+
* @returns The embedding result with vectors, usage data, and warnings.
|
|
30297
30307
|
*/
|
|
30298
30308
|
async doEmbed(options) {
|
|
30299
30309
|
const { abortSignal, providerOptions, values } = options;
|
|
@@ -30384,9 +30394,6 @@ var SAPAIEmbeddingModel = class {
|
|
|
30384
30394
|
}
|
|
30385
30395
|
};
|
|
30386
30396
|
|
|
30387
|
-
// src/sap-ai-provider.ts
|
|
30388
|
-
import { NoSuchModelError as NoSuchModelError2 } from "@ai-sdk/provider";
|
|
30389
|
-
|
|
30390
30397
|
// src/sap-ai-language-model.ts
|
|
30391
30398
|
import { parseProviderOptions as parseProviderOptions2 } from "@ai-sdk/provider-utils";
|
|
30392
30399
|
import {
|
|
@@ -30609,8 +30616,10 @@ var SAPAILanguageModel = class {
|
|
|
30609
30616
|
settings;
|
|
30610
30617
|
/**
|
|
30611
30618
|
* Creates a new SAP AI Language Model instance.
|
|
30612
|
-
*
|
|
30613
|
-
*
|
|
30619
|
+
*
|
|
30620
|
+
* This is the main implementation that handles all SAP AI Core orchestration logic.
|
|
30621
|
+
* @param modelId - The model identifier (e.g., 'gpt-4o', 'claude-3-5-sonnet', 'gemini-2.0-flash').
|
|
30622
|
+
* @param settings - Model configuration settings (temperature, max tokens, filtering, etc.).
|
|
30614
30623
|
* @param config - SAP AI Core deployment and destination configuration.
|
|
30615
30624
|
* @internal
|
|
30616
30625
|
*/
|
|
@@ -30624,9 +30633,12 @@ var SAPAILanguageModel = class {
|
|
|
30624
30633
|
}
|
|
30625
30634
|
/**
|
|
30626
30635
|
* Generates a single completion (non-streaming).
|
|
30627
|
-
*
|
|
30628
|
-
*
|
|
30629
|
-
*
|
|
30636
|
+
*
|
|
30637
|
+
* Builds orchestration configuration, converts messages, validates parameters,
|
|
30638
|
+
* calls SAP AI SDK, and processes the response.
|
|
30639
|
+
* Supports request cancellation via AbortSignal at the HTTP transport layer.
|
|
30640
|
+
* @param options - The Vercel AI SDK V3 generation call options.
|
|
30641
|
+
* @returns The generation result with content, usage, warnings, and provider metadata.
|
|
30630
30642
|
*/
|
|
30631
30643
|
async doGenerate(options) {
|
|
30632
30644
|
try {
|
|
@@ -30657,36 +30669,10 @@ var SAPAILanguageModel = class {
|
|
|
30657
30669
|
return translation && Object.keys(translation).length > 0 ? { translation } : {};
|
|
30658
30670
|
})()
|
|
30659
30671
|
};
|
|
30660
|
-
const response = await (
|
|
30661
|
-
|
|
30662
|
-
|
|
30663
|
-
|
|
30664
|
-
completionPromise,
|
|
30665
|
-
new Promise((_, reject) => {
|
|
30666
|
-
if (options.abortSignal?.aborted) {
|
|
30667
|
-
reject(
|
|
30668
|
-
new Error(
|
|
30669
|
-
`Request aborted: ${String(options.abortSignal.reason ?? "unknown reason")}`
|
|
30670
|
-
)
|
|
30671
|
-
);
|
|
30672
|
-
return;
|
|
30673
|
-
}
|
|
30674
|
-
options.abortSignal?.addEventListener(
|
|
30675
|
-
"abort",
|
|
30676
|
-
() => {
|
|
30677
|
-
reject(
|
|
30678
|
-
new Error(
|
|
30679
|
-
`Request aborted: ${String(options.abortSignal?.reason ?? "unknown reason")}`
|
|
30680
|
-
)
|
|
30681
|
-
);
|
|
30682
|
-
},
|
|
30683
|
-
{ once: true }
|
|
30684
|
-
);
|
|
30685
|
-
})
|
|
30686
|
-
]);
|
|
30687
|
-
}
|
|
30688
|
-
return completionPromise;
|
|
30689
|
-
})();
|
|
30672
|
+
const response = await client.chatCompletion(
|
|
30673
|
+
requestBody,
|
|
30674
|
+
options.abortSignal ? { signal: options.abortSignal } : void 0
|
|
30675
|
+
);
|
|
30690
30676
|
const responseHeadersRaw = response.rawResponse.headers;
|
|
30691
30677
|
const responseHeaders = responseHeadersRaw ? Object.fromEntries(
|
|
30692
30678
|
Object.entries(responseHeadersRaw).flatMap(([key, value]) => {
|
|
@@ -30774,8 +30760,11 @@ var SAPAILanguageModel = class {
|
|
|
30774
30760
|
}
|
|
30775
30761
|
/**
|
|
30776
30762
|
* Generates a streaming completion.
|
|
30777
|
-
*
|
|
30778
|
-
*
|
|
30763
|
+
*
|
|
30764
|
+
* Builds orchestration configuration, creates streaming client, and transforms
|
|
30765
|
+
* the stream with proper event handling (text blocks, tool calls, finish reason).
|
|
30766
|
+
* Supports request cancellation via AbortSignal at the HTTP transport layer.
|
|
30767
|
+
* @param options - The Vercel AI SDK V3 generation call options.
|
|
30779
30768
|
* @returns A stream result with async iterable stream parts.
|
|
30780
30769
|
*/
|
|
30781
30770
|
async doStream(options) {
|
|
@@ -31342,6 +31331,8 @@ function mapFinishReason(reason) {
|
|
|
31342
31331
|
}
|
|
31343
31332
|
|
|
31344
31333
|
// src/sap-ai-provider.ts
|
|
31334
|
+
var import_util2 = __toESM(require_dist(), 1);
|
|
31335
|
+
import { NoSuchModelError as NoSuchModelError2 } from "@ai-sdk/provider";
|
|
31345
31336
|
function createSAPAIProvider(options = {}) {
|
|
31346
31337
|
if (options.defaultSettings?.modelParams) {
|
|
31347
31338
|
validateModelParamsSettings(options.defaultSettings.modelParams);
|
|
@@ -31354,6 +31345,10 @@ function createSAPAIProvider(options = {}) {
|
|
|
31354
31345
|
"createSAPAIProvider: both 'deploymentId' and 'resourceGroup' were provided; using 'deploymentId' and ignoring 'resourceGroup'."
|
|
31355
31346
|
);
|
|
31356
31347
|
}
|
|
31348
|
+
if (!process.env.SAP_CLOUD_SDK_LOG_LEVEL) {
|
|
31349
|
+
const logLevel = options.logLevel ?? "warn";
|
|
31350
|
+
(0, import_util2.setGlobalLogLevel)(logLevel);
|
|
31351
|
+
}
|
|
31357
31352
|
const deploymentConfig = options.deploymentId ? { deploymentId: options.deploymentId } : { resourceGroup };
|
|
31358
31353
|
const createModel = (modelId, settings = {}) => {
|
|
31359
31354
|
const mergedSettings = {
|
|
@@ -31427,6 +31422,7 @@ export {
|
|
|
31427
31422
|
OrchestrationStreamChunkResponse,
|
|
31428
31423
|
OrchestrationStreamResponse,
|
|
31429
31424
|
SAPAIEmbeddingModel,
|
|
31425
|
+
SAPAILanguageModel,
|
|
31430
31426
|
SAP_AI_PROVIDER_NAME,
|
|
31431
31427
|
buildAzureContentSafetyFilter,
|
|
31432
31428
|
buildDocumentGroundingConfig,
|