@jerome-benoit/sap-ai-provider-v2 5.0.1 → 5.0.2
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/README.md +39 -32
- package/dist/chunk-77JSAAPE.js +778 -0
- package/dist/chunk-77JSAAPE.js.map +1 -0
- package/dist/{chunk-AFZC2DH2.js → chunk-LEME2MFD.js} +59 -387
- package/dist/chunk-LEME2MFD.js.map +1 -0
- package/dist/{chunk-U23M3VYO.js → chunk-NLMWIVG7.js} +17 -7
- package/dist/chunk-NLMWIVG7.js.map +1 -0
- package/dist/chunk-QZOZ3PZT.js +634 -0
- package/dist/chunk-QZOZ3PZT.js.map +1 -0
- package/dist/{chunk-JRUSQTKB.js → chunk-U6WJSLR7.js} +19 -11
- package/dist/chunk-U6WJSLR7.js.map +1 -0
- package/dist/{chunk-MF3VO3ER.js → chunk-YP3AADWD.js} +47 -40
- package/dist/chunk-YP3AADWD.js.map +1 -0
- package/dist/{foundation-models-embedding-model-strategy-2GUADNXT.js → foundation-models-embedding-model-strategy-A3WDDAYK.js} +8 -9
- package/dist/foundation-models-embedding-model-strategy-A3WDDAYK.js.map +1 -0
- package/dist/{foundation-models-language-model-strategy-5AYZ5KHA.js → foundation-models-language-model-strategy-6U6KK6KH.js} +18 -21
- package/dist/foundation-models-language-model-strategy-6U6KK6KH.js.map +1 -0
- package/dist/index.cjs +1323 -31666
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -32
- package/dist/index.d.ts +17 -32
- package/dist/index.js +48 -194
- package/dist/index.js.map +1 -1
- package/dist/{orchestration-embedding-model-strategy-F7WHDLX7.js → orchestration-embedding-model-strategy-JO3QH5MR.js} +7 -11
- package/dist/orchestration-embedding-model-strategy-JO3QH5MR.js.map +1 -0
- package/dist/{orchestration-language-model-strategy-Z72AFW62.js → orchestration-language-model-strategy-MBVA7BYX.js} +23 -25
- package/dist/orchestration-language-model-strategy-MBVA7BYX.js.map +1 -0
- package/package.json +15 -12
- package/dist/chunk-2KOXKYVT.js +0 -31083
- package/dist/chunk-2KOXKYVT.js.map +0 -1
- package/dist/chunk-643USI3B.js +0 -251
- package/dist/chunk-643USI3B.js.map +0 -1
- package/dist/chunk-AFZC2DH2.js.map +0 -1
- package/dist/chunk-JRUSQTKB.js.map +0 -1
- package/dist/chunk-MF3VO3ER.js.map +0 -1
- package/dist/chunk-U23M3VYO.js.map +0 -1
- package/dist/foundation-models-embedding-model-strategy-2GUADNXT.js.map +0 -1
- package/dist/foundation-models-language-model-strategy-5AYZ5KHA.js.map +0 -1
- package/dist/orchestration-embedding-model-strategy-F7WHDLX7.js.map +0 -1
- package/dist/orchestration-language-model-strategy-Z72AFW62.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ export { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
|
|
|
6
6
|
import { AzureOpenAiChatCompletionParameters } from '@sap-ai-sdk/foundation-models';
|
|
7
7
|
import { OrchestrationConfigRefOverride, OrchestrationModuleConfig, FilteringModule, GroundingModule, MaskingModule, OrchestrationConfigRefById, OrchestrationConfigRefByName, ChatCompletionTool, TranslationModule, ChatModel } from '@sap-ai-sdk/orchestration';
|
|
8
8
|
export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMessage, ChatMessageContent, ChatMessages, Citation, DeveloperChatMessage, DocumentTranslationApplyToSelector, FileContent, FilteringModule, FunctionObject, GroundingModule, ImageContentUrl, LlmModelDetails, LlmModelParams, MaskingModule, OrchestrationClient, OrchestrationConfigRef, OrchestrationConfigRefById, OrchestrationConfigRefByName, OrchestrationConfigRefOverride, OrchestrationEmbeddingClient, OrchestrationEmbeddingResponse, OrchestrationError, OrchestrationErrorResponse, OrchestrationModuleConfig, OrchestrationModuleConfigList, OrchestrationResponse, OrchestrationStream, OrchestrationStreamChunkResponse, OrchestrationStreamResponse, PromptTemplatingModule, SystemChatMessage, ToolChatMessage, TranslationApplyToCategory, TranslationInputParameters, TranslationModule, TranslationOutputParameters, TranslationTargetLanguage, UserChatMessage, UserChatMessageContent, UserChatMessageContentItem, buildAzureContentSafetyFilter, buildDocumentGroundingConfig, buildDpiMaskingProvider, buildLlamaGuard38BFilter, buildTranslationConfig } from '@sap-ai-sdk/orchestration';
|
|
9
|
-
import {
|
|
9
|
+
import { LanguageModelV2 as LanguageModelV2$1, LanguageModelV2CallOptions as LanguageModelV2CallOptions$1, LanguageModelV3CallOptions } from '@ai-sdk/provider';
|
|
10
10
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
11
11
|
import { InferSchema } from '@ai-sdk/provider-utils';
|
|
12
12
|
|
|
@@ -1878,7 +1878,10 @@ interface SAPAIEmbeddingSettings {
|
|
|
1878
1878
|
readonly masking?: MaskingModule | {
|
|
1879
1879
|
providers: MaskingModule["masking_providers"];
|
|
1880
1880
|
};
|
|
1881
|
-
/**
|
|
1881
|
+
/**
|
|
1882
|
+
* Maximum batch size: a positive integer, or `Infinity` for no provider-side limit.
|
|
1883
|
+
* @default 2048
|
|
1884
|
+
*/
|
|
1882
1885
|
readonly maxEmbeddingsPerCall?: number;
|
|
1883
1886
|
readonly modelParams?: FoundationModelsEmbeddingParams | Record<string, unknown>;
|
|
1884
1887
|
readonly modelVersion?: string;
|
|
@@ -2101,39 +2104,19 @@ declare class UnsupportedFeatureError extends Error {
|
|
|
2101
2104
|
constructor(feature: string, api: SAPAIApiType, suggestedApi: SAPAIApiType);
|
|
2102
2105
|
}
|
|
2103
2106
|
|
|
2104
|
-
/** Adapters
|
|
2107
|
+
/** Adapters for the semantic differences between the V3 core and V2 facade. */
|
|
2105
2108
|
|
|
2109
|
+
/** Stream events supported by the V2 facade. */
|
|
2106
2110
|
type ConvertedV2StreamPart = Exclude<LanguageModelV2StreamPart, {
|
|
2107
2111
|
type: "stream-start";
|
|
2108
2112
|
}> | {
|
|
2109
2113
|
type: "stream-start";
|
|
2110
|
-
warnings:
|
|
2114
|
+
warnings: ConvertedV2Warning[];
|
|
2111
2115
|
};
|
|
2112
|
-
/**
|
|
2113
|
-
|
|
2114
|
-
* @param internalWarnings - Internal warning objects.
|
|
2115
|
-
* @returns V2 warning objects.
|
|
2116
|
-
* @internal
|
|
2117
|
-
*/
|
|
2118
|
-
declare function convertWarningsToV2(internalWarnings: SharedV3Warning[]): ReturnType<typeof convertWarningToV2>[];
|
|
2119
|
-
/**
|
|
2120
|
-
* Converts internal warning to V2 warning format.
|
|
2121
|
-
*
|
|
2122
|
-
* Maps `unsupported`/`compatibility` warnings to V2 `other` type with descriptive message.
|
|
2123
|
-
* @param internalWarning - Internal warning object.
|
|
2124
|
-
* @returns V2 warning object.
|
|
2125
|
-
* @internal
|
|
2126
|
-
*/
|
|
2127
|
-
declare function convertWarningToV2(internalWarning: SharedV3Warning): Extract<LanguageModelV2CallWarning, {
|
|
2116
|
+
/** V2 warning representation used when adapting V3 feature diagnostics. */
|
|
2117
|
+
type ConvertedV2Warning = Extract<LanguageModelV2CallWarning, {
|
|
2128
2118
|
type: "other";
|
|
2129
2119
|
}>;
|
|
2130
|
-
/**
|
|
2131
|
-
* Transforms internal stream to V2 ReadableStream.
|
|
2132
|
-
* @param internalStream - Internal ReadableStream to transform.
|
|
2133
|
-
* @returns V2-formatted ReadableStream.
|
|
2134
|
-
* @internal
|
|
2135
|
-
*/
|
|
2136
|
-
declare function createV2StreamFromInternal(internalStream: ReadableStream<LanguageModelV3StreamPart>): ReadableStream<ConvertedV2StreamPart>;
|
|
2137
2120
|
|
|
2138
2121
|
/**
|
|
2139
2122
|
* SAP AI Language Model V2 - Vercel AI SDK LanguageModelV2 implementation for SAP AI Core.
|
|
@@ -2217,7 +2200,7 @@ declare class SAPAILanguageModelV2 implements LanguageModelV2$1 {
|
|
|
2217
2200
|
headers?: SharedV2Headers;
|
|
2218
2201
|
};
|
|
2219
2202
|
usage: LanguageModelV2Usage;
|
|
2220
|
-
warnings:
|
|
2203
|
+
warnings: ConvertedV2Warning[];
|
|
2221
2204
|
}>;
|
|
2222
2205
|
doStream(options: CompatibleV2CallOptions): Promise<{
|
|
2223
2206
|
request?: {
|
|
@@ -2226,7 +2209,7 @@ declare class SAPAILanguageModelV2 implements LanguageModelV2$1 {
|
|
|
2226
2209
|
response?: {
|
|
2227
2210
|
headers?: SharedV2Headers;
|
|
2228
2211
|
};
|
|
2229
|
-
stream:
|
|
2212
|
+
stream: ReadableStream<ConvertedV2StreamPart>;
|
|
2230
2213
|
}>;
|
|
2231
2214
|
}
|
|
2232
2215
|
|
|
@@ -2273,9 +2256,10 @@ interface SAPAIProviderSettings {
|
|
|
2273
2256
|
*
|
|
2274
2257
|
* Provider-level only (not overridable per-call via `providerOptions['sap-ai']`). The
|
|
2275
2258
|
* AI SDK `abortSignal` option always wins over any `signal` on `requestConfig`; the
|
|
2276
|
-
* latter is dropped before the request is forwarded.
|
|
2277
|
-
*
|
|
2278
|
-
*
|
|
2259
|
+
* latter is dropped before the request is forwarded. Standard AI SDK call-level
|
|
2260
|
+
* `headers` override matching `requestConfig.headers` case-insensitively. Other
|
|
2261
|
+
* options, including Node-only agents (`httpAgent`, `httpsAgent`), are forwarded
|
|
2262
|
+
* unchanged. The published package and SAP SDK transport require a Node-compatible runtime.
|
|
2279
2263
|
*
|
|
2280
2264
|
* See the "Note on `requestConfig`" section under `SAPAIProviderSettings` in
|
|
2281
2265
|
* `API_REFERENCE.md` for the full SAP AI Core `AI-*` header guidance.
|
|
@@ -2291,6 +2275,7 @@ interface SAPAIProviderSettings {
|
|
|
2291
2275
|
/** Whether to emit warnings for ambiguous configurations (e.g. both deploymentId and resourceGroup). */
|
|
2292
2276
|
readonly warnOnAmbiguousConfig?: boolean;
|
|
2293
2277
|
}
|
|
2278
|
+
|
|
2294
2279
|
/** SAP AI Provider interface extending Vercel AI SDK ProviderV2. */
|
|
2295
2280
|
interface SAPAIProviderV2 extends ProviderV2 {
|
|
2296
2281
|
(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAILanguageModelV2;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
|
|
|
6
6
|
import { AzureOpenAiChatCompletionParameters } from '@sap-ai-sdk/foundation-models';
|
|
7
7
|
import { OrchestrationConfigRefOverride, OrchestrationModuleConfig, FilteringModule, GroundingModule, MaskingModule, OrchestrationConfigRefById, OrchestrationConfigRefByName, ChatCompletionTool, TranslationModule, ChatModel } from '@sap-ai-sdk/orchestration';
|
|
8
8
|
export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMessage, ChatMessageContent, ChatMessages, Citation, DeveloperChatMessage, DocumentTranslationApplyToSelector, FileContent, FilteringModule, FunctionObject, GroundingModule, ImageContentUrl, LlmModelDetails, LlmModelParams, MaskingModule, OrchestrationClient, OrchestrationConfigRef, OrchestrationConfigRefById, OrchestrationConfigRefByName, OrchestrationConfigRefOverride, OrchestrationEmbeddingClient, OrchestrationEmbeddingResponse, OrchestrationError, OrchestrationErrorResponse, OrchestrationModuleConfig, OrchestrationModuleConfigList, OrchestrationResponse, OrchestrationStream, OrchestrationStreamChunkResponse, OrchestrationStreamResponse, PromptTemplatingModule, SystemChatMessage, ToolChatMessage, TranslationApplyToCategory, TranslationInputParameters, TranslationModule, TranslationOutputParameters, TranslationTargetLanguage, UserChatMessage, UserChatMessageContent, UserChatMessageContentItem, buildAzureContentSafetyFilter, buildDocumentGroundingConfig, buildDpiMaskingProvider, buildLlamaGuard38BFilter, buildTranslationConfig } from '@sap-ai-sdk/orchestration';
|
|
9
|
-
import {
|
|
9
|
+
import { LanguageModelV2 as LanguageModelV2$1, LanguageModelV2CallOptions as LanguageModelV2CallOptions$1, LanguageModelV3CallOptions } from '@ai-sdk/provider';
|
|
10
10
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
11
11
|
import { InferSchema } from '@ai-sdk/provider-utils';
|
|
12
12
|
|
|
@@ -1878,7 +1878,10 @@ interface SAPAIEmbeddingSettings {
|
|
|
1878
1878
|
readonly masking?: MaskingModule | {
|
|
1879
1879
|
providers: MaskingModule["masking_providers"];
|
|
1880
1880
|
};
|
|
1881
|
-
/**
|
|
1881
|
+
/**
|
|
1882
|
+
* Maximum batch size: a positive integer, or `Infinity` for no provider-side limit.
|
|
1883
|
+
* @default 2048
|
|
1884
|
+
*/
|
|
1882
1885
|
readonly maxEmbeddingsPerCall?: number;
|
|
1883
1886
|
readonly modelParams?: FoundationModelsEmbeddingParams | Record<string, unknown>;
|
|
1884
1887
|
readonly modelVersion?: string;
|
|
@@ -2101,39 +2104,19 @@ declare class UnsupportedFeatureError extends Error {
|
|
|
2101
2104
|
constructor(feature: string, api: SAPAIApiType, suggestedApi: SAPAIApiType);
|
|
2102
2105
|
}
|
|
2103
2106
|
|
|
2104
|
-
/** Adapters
|
|
2107
|
+
/** Adapters for the semantic differences between the V3 core and V2 facade. */
|
|
2105
2108
|
|
|
2109
|
+
/** Stream events supported by the V2 facade. */
|
|
2106
2110
|
type ConvertedV2StreamPart = Exclude<LanguageModelV2StreamPart, {
|
|
2107
2111
|
type: "stream-start";
|
|
2108
2112
|
}> | {
|
|
2109
2113
|
type: "stream-start";
|
|
2110
|
-
warnings:
|
|
2114
|
+
warnings: ConvertedV2Warning[];
|
|
2111
2115
|
};
|
|
2112
|
-
/**
|
|
2113
|
-
|
|
2114
|
-
* @param internalWarnings - Internal warning objects.
|
|
2115
|
-
* @returns V2 warning objects.
|
|
2116
|
-
* @internal
|
|
2117
|
-
*/
|
|
2118
|
-
declare function convertWarningsToV2(internalWarnings: SharedV3Warning[]): ReturnType<typeof convertWarningToV2>[];
|
|
2119
|
-
/**
|
|
2120
|
-
* Converts internal warning to V2 warning format.
|
|
2121
|
-
*
|
|
2122
|
-
* Maps `unsupported`/`compatibility` warnings to V2 `other` type with descriptive message.
|
|
2123
|
-
* @param internalWarning - Internal warning object.
|
|
2124
|
-
* @returns V2 warning object.
|
|
2125
|
-
* @internal
|
|
2126
|
-
*/
|
|
2127
|
-
declare function convertWarningToV2(internalWarning: SharedV3Warning): Extract<LanguageModelV2CallWarning, {
|
|
2116
|
+
/** V2 warning representation used when adapting V3 feature diagnostics. */
|
|
2117
|
+
type ConvertedV2Warning = Extract<LanguageModelV2CallWarning, {
|
|
2128
2118
|
type: "other";
|
|
2129
2119
|
}>;
|
|
2130
|
-
/**
|
|
2131
|
-
* Transforms internal stream to V2 ReadableStream.
|
|
2132
|
-
* @param internalStream - Internal ReadableStream to transform.
|
|
2133
|
-
* @returns V2-formatted ReadableStream.
|
|
2134
|
-
* @internal
|
|
2135
|
-
*/
|
|
2136
|
-
declare function createV2StreamFromInternal(internalStream: ReadableStream<LanguageModelV3StreamPart>): ReadableStream<ConvertedV2StreamPart>;
|
|
2137
2120
|
|
|
2138
2121
|
/**
|
|
2139
2122
|
* SAP AI Language Model V2 - Vercel AI SDK LanguageModelV2 implementation for SAP AI Core.
|
|
@@ -2217,7 +2200,7 @@ declare class SAPAILanguageModelV2 implements LanguageModelV2$1 {
|
|
|
2217
2200
|
headers?: SharedV2Headers;
|
|
2218
2201
|
};
|
|
2219
2202
|
usage: LanguageModelV2Usage;
|
|
2220
|
-
warnings:
|
|
2203
|
+
warnings: ConvertedV2Warning[];
|
|
2221
2204
|
}>;
|
|
2222
2205
|
doStream(options: CompatibleV2CallOptions): Promise<{
|
|
2223
2206
|
request?: {
|
|
@@ -2226,7 +2209,7 @@ declare class SAPAILanguageModelV2 implements LanguageModelV2$1 {
|
|
|
2226
2209
|
response?: {
|
|
2227
2210
|
headers?: SharedV2Headers;
|
|
2228
2211
|
};
|
|
2229
|
-
stream:
|
|
2212
|
+
stream: ReadableStream<ConvertedV2StreamPart>;
|
|
2230
2213
|
}>;
|
|
2231
2214
|
}
|
|
2232
2215
|
|
|
@@ -2273,9 +2256,10 @@ interface SAPAIProviderSettings {
|
|
|
2273
2256
|
*
|
|
2274
2257
|
* Provider-level only (not overridable per-call via `providerOptions['sap-ai']`). The
|
|
2275
2258
|
* AI SDK `abortSignal` option always wins over any `signal` on `requestConfig`; the
|
|
2276
|
-
* latter is dropped before the request is forwarded.
|
|
2277
|
-
*
|
|
2278
|
-
*
|
|
2259
|
+
* latter is dropped before the request is forwarded. Standard AI SDK call-level
|
|
2260
|
+
* `headers` override matching `requestConfig.headers` case-insensitively. Other
|
|
2261
|
+
* options, including Node-only agents (`httpAgent`, `httpsAgent`), are forwarded
|
|
2262
|
+
* unchanged. The published package and SAP SDK transport require a Node-compatible runtime.
|
|
2279
2263
|
*
|
|
2280
2264
|
* See the "Note on `requestConfig`" section under `SAPAIProviderSettings` in
|
|
2281
2265
|
* `API_REFERENCE.md` for the full SAP AI Core `AI-*` header guidance.
|
|
@@ -2291,6 +2275,7 @@ interface SAPAIProviderSettings {
|
|
|
2291
2275
|
/** Whether to emit warnings for ambiguous configurations (e.g. both deploymentId and resourceGroup). */
|
|
2292
2276
|
readonly warnOnAmbiguousConfig?: boolean;
|
|
2293
2277
|
}
|
|
2278
|
+
|
|
2294
2279
|
/** SAP AI Provider interface extending Vercel AI SDK ProviderV2. */
|
|
2295
2280
|
interface SAPAIProviderV2 extends ProviderV2 {
|
|
2296
2281
|
(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAILanguageModelV2;
|
package/dist/index.js
CHANGED
|
@@ -3,175 +3,55 @@ import {
|
|
|
3
3
|
mergeSettingsWithApi,
|
|
4
4
|
resolveApi,
|
|
5
5
|
validateSettings
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-NLMWIVG7.js";
|
|
7
7
|
import {
|
|
8
8
|
escapeOrchestrationPlaceholders,
|
|
9
9
|
unescapeOrchestrationPlaceholders
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-YP3AADWD.js";
|
|
11
11
|
import {
|
|
12
12
|
ApiSwitchError,
|
|
13
13
|
SAP_AI_PROVIDER_NAME,
|
|
14
14
|
UnsupportedFeatureError,
|
|
15
15
|
VERSION,
|
|
16
|
-
__toESM,
|
|
17
16
|
getProviderName,
|
|
18
|
-
require_dist,
|
|
19
17
|
sapAIEmbeddingProviderOptions,
|
|
20
18
|
sapAILanguageModelProviderOptions,
|
|
21
19
|
validateEmbeddingModelParamsSettings,
|
|
22
20
|
validateModelParamsSettings
|
|
23
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-77JSAAPE.js";
|
|
24
22
|
|
|
25
23
|
// src/sap-ai-adapters-v3-to-v2.ts
|
|
26
|
-
function convertFinishReasonToV2(internalFinishReason) {
|
|
27
|
-
return internalFinishReason.unified;
|
|
28
|
-
}
|
|
29
|
-
function convertProviderMetadataToV2(metadata) {
|
|
30
|
-
return metadata;
|
|
31
|
-
}
|
|
32
24
|
function convertStreamPartToV2(internalPart) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
case "file":
|
|
40
|
-
return {
|
|
41
|
-
data: internalPart.data,
|
|
42
|
-
mediaType: internalPart.mediaType,
|
|
43
|
-
type: "file"
|
|
44
|
-
};
|
|
25
|
+
const compatiblePart = internalPart;
|
|
26
|
+
switch (compatiblePart.type) {
|
|
27
|
+
case "file": {
|
|
28
|
+
const { providerMetadata: _providerMetadata, ...part } = compatiblePart;
|
|
29
|
+
return part;
|
|
30
|
+
}
|
|
45
31
|
case "finish":
|
|
46
|
-
return withProviderMetadata(
|
|
47
|
-
{
|
|
48
|
-
finishReason: convertFinishReasonToV2(internalPart.finishReason),
|
|
49
|
-
type: "finish",
|
|
50
|
-
usage: convertUsageToV2(internalPart.usage)
|
|
51
|
-
},
|
|
52
|
-
internalPart.providerMetadata
|
|
53
|
-
);
|
|
54
|
-
case "raw":
|
|
55
|
-
return {
|
|
56
|
-
rawValue: internalPart.rawValue,
|
|
57
|
-
type: "raw"
|
|
58
|
-
};
|
|
59
|
-
case "reasoning-delta":
|
|
60
|
-
return withProviderMetadata(
|
|
61
|
-
{ delta: internalPart.delta, id: internalPart.id, type: "reasoning-delta" },
|
|
62
|
-
internalPart.providerMetadata
|
|
63
|
-
);
|
|
64
|
-
case "reasoning-end":
|
|
65
|
-
return withProviderMetadata(
|
|
66
|
-
{ id: internalPart.id, type: "reasoning-end" },
|
|
67
|
-
internalPart.providerMetadata
|
|
68
|
-
);
|
|
69
|
-
case "reasoning-start":
|
|
70
|
-
return withProviderMetadata(
|
|
71
|
-
{ id: internalPart.id, type: "reasoning-start" },
|
|
72
|
-
internalPart.providerMetadata
|
|
73
|
-
);
|
|
74
|
-
case "response-metadata":
|
|
75
32
|
return {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
type: "response-metadata"
|
|
33
|
+
...compatiblePart,
|
|
34
|
+
finishReason: compatiblePart.finishReason.unified,
|
|
35
|
+
usage: convertUsageToV2(compatiblePart.usage)
|
|
80
36
|
};
|
|
81
|
-
case "source":
|
|
82
|
-
if (internalPart.sourceType === "url") {
|
|
83
|
-
return withProviderMetadata(
|
|
84
|
-
{
|
|
85
|
-
id: internalPart.id,
|
|
86
|
-
sourceType: "url",
|
|
87
|
-
title: internalPart.title,
|
|
88
|
-
type: "source",
|
|
89
|
-
url: internalPart.url
|
|
90
|
-
},
|
|
91
|
-
internalPart.providerMetadata
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
return withProviderMetadata(
|
|
95
|
-
{
|
|
96
|
-
filename: internalPart.filename,
|
|
97
|
-
id: internalPart.id,
|
|
98
|
-
mediaType: internalPart.mediaType,
|
|
99
|
-
sourceType: "document",
|
|
100
|
-
title: internalPart.title,
|
|
101
|
-
type: "source"
|
|
102
|
-
},
|
|
103
|
-
internalPart.providerMetadata
|
|
104
|
-
);
|
|
105
37
|
case "stream-start":
|
|
106
|
-
return {
|
|
107
|
-
type: "stream-start",
|
|
108
|
-
warnings: convertWarningsToV2(internalPart.warnings)
|
|
109
|
-
};
|
|
110
|
-
case "text-delta":
|
|
111
|
-
return withProviderMetadata(
|
|
112
|
-
{ delta: internalPart.delta, id: internalPart.id, type: "text-delta" },
|
|
113
|
-
internalPart.providerMetadata
|
|
114
|
-
);
|
|
115
|
-
case "text-end":
|
|
116
|
-
return withProviderMetadata(
|
|
117
|
-
{ id: internalPart.id, type: "text-end" },
|
|
118
|
-
internalPart.providerMetadata
|
|
119
|
-
);
|
|
120
|
-
case "text-start":
|
|
121
|
-
return withProviderMetadata(
|
|
122
|
-
{ id: internalPart.id, type: "text-start" },
|
|
123
|
-
internalPart.providerMetadata
|
|
124
|
-
);
|
|
38
|
+
return { ...compatiblePart, warnings: convertWarningsToV2(compatiblePart.warnings) };
|
|
125
39
|
case "tool-approval-request":
|
|
126
40
|
return null;
|
|
127
|
-
case "tool-call":
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return withProviderMetadata(
|
|
142
|
-
{ delta: internalPart.delta, id: internalPart.id, type: "tool-input-delta" },
|
|
143
|
-
internalPart.providerMetadata
|
|
144
|
-
);
|
|
145
|
-
case "tool-input-end":
|
|
146
|
-
return withProviderMetadata(
|
|
147
|
-
{ id: internalPart.id, type: "tool-input-end" },
|
|
148
|
-
internalPart.providerMetadata
|
|
149
|
-
);
|
|
150
|
-
case "tool-input-start":
|
|
151
|
-
return withProviderMetadata(
|
|
152
|
-
{
|
|
153
|
-
id: internalPart.id,
|
|
154
|
-
toolName: internalPart.toolName,
|
|
155
|
-
type: "tool-input-start",
|
|
156
|
-
...internalPart.providerExecuted !== void 0 && {
|
|
157
|
-
providerExecuted: internalPart.providerExecuted
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
internalPart.providerMetadata
|
|
161
|
-
);
|
|
162
|
-
case "tool-result":
|
|
163
|
-
return withProviderMetadata(
|
|
164
|
-
{
|
|
165
|
-
// V3 tool results are provider-executed, independent of dynamic tool classification.
|
|
166
|
-
providerExecuted: true,
|
|
167
|
-
result: internalPart.result,
|
|
168
|
-
toolCallId: internalPart.toolCallId,
|
|
169
|
-
toolName: internalPart.toolName,
|
|
170
|
-
type: "tool-result",
|
|
171
|
-
...internalPart.isError !== void 0 && { isError: internalPart.isError }
|
|
172
|
-
},
|
|
173
|
-
internalPart.providerMetadata
|
|
174
|
-
);
|
|
41
|
+
case "tool-call": {
|
|
42
|
+
const { dynamic: _dynamic, ...part } = compatiblePart;
|
|
43
|
+
return part;
|
|
44
|
+
}
|
|
45
|
+
case "tool-input-start": {
|
|
46
|
+
const { dynamic: _dynamic, title: _title, ...part } = compatiblePart;
|
|
47
|
+
return part;
|
|
48
|
+
}
|
|
49
|
+
case "tool-result": {
|
|
50
|
+
const { dynamic: _dynamic, preliminary: _preliminary, ...part } = compatiblePart;
|
|
51
|
+
return { ...part, providerExecuted: true };
|
|
52
|
+
}
|
|
53
|
+
default:
|
|
54
|
+
return compatiblePart;
|
|
175
55
|
}
|
|
176
56
|
}
|
|
177
57
|
function convertUsageToV2(internalUsage) {
|
|
@@ -187,20 +67,10 @@ function convertWarningsToV2(internalWarnings) {
|
|
|
187
67
|
return internalWarnings.map(convertWarningToV2);
|
|
188
68
|
}
|
|
189
69
|
function convertWarningToV2(internalWarning) {
|
|
190
|
-
if (internalWarning.type === "
|
|
191
|
-
|
|
192
|
-
message: internalWarning.details ? `Unsupported feature: ${internalWarning.feature}. ${internalWarning.details}` : `Unsupported feature: ${internalWarning.feature}`,
|
|
193
|
-
type: "other"
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
if (internalWarning.type === "compatibility") {
|
|
197
|
-
return {
|
|
198
|
-
message: internalWarning.details ? `Compatibility mode: ${internalWarning.feature}. ${internalWarning.details}` : `Compatibility mode: ${internalWarning.feature}`,
|
|
199
|
-
type: "other"
|
|
200
|
-
};
|
|
201
|
-
}
|
|
70
|
+
if (internalWarning.type === "other") return internalWarning;
|
|
71
|
+
const prefix = internalWarning.type === "unsupported" ? "Unsupported feature" : "Compatibility mode";
|
|
202
72
|
return {
|
|
203
|
-
message: internalWarning.
|
|
73
|
+
message: `${prefix}: ${internalWarning.feature}${internalWarning.details ? `. ${internalWarning.details}` : ""}`,
|
|
204
74
|
type: "other"
|
|
205
75
|
};
|
|
206
76
|
}
|
|
@@ -209,20 +79,15 @@ function createV2StreamFromInternal(internalStream) {
|
|
|
209
79
|
new TransformStream({
|
|
210
80
|
transform(chunk, controller) {
|
|
211
81
|
const converted = convertStreamPartToV2(chunk);
|
|
212
|
-
if (converted
|
|
213
|
-
controller.enqueue(converted);
|
|
214
|
-
}
|
|
82
|
+
if (converted !== null) controller.enqueue(converted);
|
|
215
83
|
}
|
|
216
84
|
})
|
|
217
85
|
);
|
|
218
86
|
}
|
|
219
|
-
function withProviderMetadata(obj, metadata) {
|
|
220
|
-
if (metadata === void 0) return obj;
|
|
221
|
-
return { ...obj, providerMetadata: convertProviderMetadataToV2(metadata) };
|
|
222
|
-
}
|
|
223
87
|
|
|
224
88
|
// src/sap-ai-embedding-model.ts
|
|
225
89
|
import { parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
90
|
+
import { z } from "zod";
|
|
226
91
|
|
|
227
92
|
// src/sap-ai-strategy.ts
|
|
228
93
|
var languageModelStrategyCache = /* @__PURE__ */ new Map();
|
|
@@ -254,26 +119,27 @@ function getOrCreateLanguageModelStrategy(api) {
|
|
|
254
119
|
async function createEmbeddingModelStrategy(api) {
|
|
255
120
|
if (api === "foundation-models") {
|
|
256
121
|
const { AzureOpenAiEmbeddingClient } = await import("@sap-ai-sdk/foundation-models");
|
|
257
|
-
const { FoundationModelsEmbeddingModelStrategy } = await import("./foundation-models-embedding-model-strategy-
|
|
122
|
+
const { FoundationModelsEmbeddingModelStrategy } = await import("./foundation-models-embedding-model-strategy-A3WDDAYK.js");
|
|
258
123
|
return new FoundationModelsEmbeddingModelStrategy(AzureOpenAiEmbeddingClient);
|
|
259
124
|
}
|
|
260
125
|
const { OrchestrationEmbeddingClient: OrchestrationEmbeddingClient2 } = await import("@sap-ai-sdk/orchestration");
|
|
261
|
-
const { OrchestrationEmbeddingModelStrategy } = await import("./orchestration-embedding-model-strategy-
|
|
126
|
+
const { OrchestrationEmbeddingModelStrategy } = await import("./orchestration-embedding-model-strategy-JO3QH5MR.js");
|
|
262
127
|
return new OrchestrationEmbeddingModelStrategy(OrchestrationEmbeddingClient2);
|
|
263
128
|
}
|
|
264
129
|
async function createLanguageModelStrategy(api) {
|
|
265
130
|
if (api === "foundation-models") {
|
|
266
131
|
const { AzureOpenAiChatClient } = await import("@sap-ai-sdk/foundation-models");
|
|
267
|
-
const { FoundationModelsLanguageModelStrategy } = await import("./foundation-models-language-model-strategy-
|
|
132
|
+
const { FoundationModelsLanguageModelStrategy } = await import("./foundation-models-language-model-strategy-6U6KK6KH.js");
|
|
268
133
|
return new FoundationModelsLanguageModelStrategy(AzureOpenAiChatClient);
|
|
269
134
|
}
|
|
270
135
|
const { OrchestrationClient: OrchestrationClient2 } = await import("@sap-ai-sdk/orchestration");
|
|
271
|
-
const { OrchestrationLanguageModelStrategy } = await import("./orchestration-language-model-strategy-
|
|
136
|
+
const { OrchestrationLanguageModelStrategy } = await import("./orchestration-language-model-strategy-MBVA7BYX.js");
|
|
272
137
|
return new OrchestrationLanguageModelStrategy(OrchestrationClient2);
|
|
273
138
|
}
|
|
274
139
|
|
|
275
140
|
// src/sap-ai-embedding-model.ts
|
|
276
141
|
var DEFAULT_MAX_EMBEDDINGS_PER_CALL = 2048;
|
|
142
|
+
var maxEmbeddingsPerCallSchema = z.number().int().positive().or(z.literal(Infinity));
|
|
277
143
|
var SAPAIEmbeddingModel = class {
|
|
278
144
|
maxEmbeddingsPerCall;
|
|
279
145
|
modelId;
|
|
@@ -296,7 +162,9 @@ var SAPAIEmbeddingModel = class {
|
|
|
296
162
|
this.settings = settings;
|
|
297
163
|
this.config = config;
|
|
298
164
|
this.provider = config.provider;
|
|
299
|
-
this.maxEmbeddingsPerCall =
|
|
165
|
+
this.maxEmbeddingsPerCall = maxEmbeddingsPerCallSchema.parse(
|
|
166
|
+
settings.maxEmbeddingsPerCall ?? DEFAULT_MAX_EMBEDDINGS_PER_CALL
|
|
167
|
+
);
|
|
300
168
|
}
|
|
301
169
|
async doEmbed(options) {
|
|
302
170
|
const providerName = getProviderName(this.config.provider);
|
|
@@ -317,6 +185,7 @@ var SAPAIEmbeddingModel = class {
|
|
|
317
185
|
deploymentConfig: this.config.deploymentConfig,
|
|
318
186
|
destination: this.config.destination,
|
|
319
187
|
modelId: this.modelId,
|
|
188
|
+
parsedProviderOptions: sapOptions,
|
|
320
189
|
provider: this.config.provider,
|
|
321
190
|
requestConfig: this.config.requestConfig
|
|
322
191
|
};
|
|
@@ -365,11 +234,8 @@ var SAPAIEmbeddingModelV2 = class {
|
|
|
365
234
|
}
|
|
366
235
|
return {
|
|
367
236
|
embeddings: result.embeddings,
|
|
368
|
-
providerMetadata:
|
|
369
|
-
response: result.response
|
|
370
|
-
body: result.response.body,
|
|
371
|
-
headers: result.response.headers
|
|
372
|
-
} : void 0,
|
|
237
|
+
providerMetadata: result.providerMetadata,
|
|
238
|
+
response: result.response,
|
|
373
239
|
usage: result.usage
|
|
374
240
|
};
|
|
375
241
|
}
|
|
@@ -452,6 +318,7 @@ var SAPAILanguageModel = class {
|
|
|
452
318
|
deploymentConfig: this.config.deploymentConfig,
|
|
453
319
|
destination: this.config.destination,
|
|
454
320
|
modelId: this.modelId,
|
|
321
|
+
parsedProviderOptions: sapOptions,
|
|
455
322
|
provider: this.config.provider,
|
|
456
323
|
requestConfig: this.config.requestConfig
|
|
457
324
|
};
|
|
@@ -485,17 +352,10 @@ var SAPAILanguageModelV2 = class {
|
|
|
485
352
|
const result = await this.internalModel.doGenerate(options);
|
|
486
353
|
return {
|
|
487
354
|
content: result.content,
|
|
488
|
-
finishReason:
|
|
489
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
|
355
|
+
finishReason: result.finishReason.unified,
|
|
490
356
|
providerMetadata: result.providerMetadata,
|
|
491
357
|
request: result.request,
|
|
492
|
-
response: result.response
|
|
493
|
-
body: result.response.body,
|
|
494
|
-
headers: result.response.headers,
|
|
495
|
-
id: result.response.id,
|
|
496
|
-
modelId: result.response.modelId,
|
|
497
|
-
timestamp: result.response.timestamp
|
|
498
|
-
} : void 0,
|
|
358
|
+
response: result.response,
|
|
499
359
|
usage: convertUsageToV2(result.usage),
|
|
500
360
|
warnings: convertWarningsToV2(result.warnings)
|
|
501
361
|
};
|
|
@@ -513,8 +373,8 @@ var SAPAILanguageModelV2 = class {
|
|
|
513
373
|
};
|
|
514
374
|
|
|
515
375
|
// src/sap-ai-provider-v2.ts
|
|
516
|
-
var import_util = __toESM(require_dist(), 1);
|
|
517
376
|
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
377
|
+
import { setGlobalLogLevel } from "@sap-cloud-sdk/util";
|
|
518
378
|
function createSAPAIProvider(options = {}) {
|
|
519
379
|
if (options.defaultSettings?.modelParams) {
|
|
520
380
|
validateModelParamsSettings(options.defaultSettings.modelParams);
|
|
@@ -529,14 +389,11 @@ function createSAPAIProvider(options = {}) {
|
|
|
529
389
|
}
|
|
530
390
|
if (typeof process === "undefined" || !process.env.SAP_CLOUD_SDK_LOG_LEVEL) {
|
|
531
391
|
const logLevel = options.logLevel ?? "warn";
|
|
532
|
-
|
|
392
|
+
setGlobalLogLevel(logLevel);
|
|
533
393
|
}
|
|
534
394
|
const deploymentConfig = options.deploymentId ? { deploymentId: options.deploymentId } : { resourceGroup };
|
|
535
395
|
const providerApi = options.api ?? "orchestration";
|
|
536
396
|
const createModel = (modelId, settings = {}) => {
|
|
537
|
-
if (settings.modelParams) {
|
|
538
|
-
validateModelParamsSettings(settings.modelParams);
|
|
539
|
-
}
|
|
540
397
|
const mergedSettings = mergeSettingsWithApi(
|
|
541
398
|
options.defaultSettings,
|
|
542
399
|
settings,
|
|
@@ -551,9 +408,6 @@ function createSAPAIProvider(options = {}) {
|
|
|
551
408
|
});
|
|
552
409
|
};
|
|
553
410
|
const createEmbeddingModel = (modelId, settings = {}) => {
|
|
554
|
-
if (settings.modelParams) {
|
|
555
|
-
validateEmbeddingModelParamsSettings(settings.modelParams);
|
|
556
|
-
}
|
|
557
411
|
const mergedSettings = mergeSettingsWithApi(
|
|
558
412
|
options.defaultSettings,
|
|
559
413
|
settings,
|