@jerome-benoit/sap-ai-provider 4.4.15 → 4.4.17
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 +10 -0
- package/dist/{chunk-CXZSTU4M.js → chunk-43B7TGUQ.js} +3 -3
- package/dist/{chunk-JV2ULRVE.js → chunk-MNXW5WBP.js} +65 -70
- package/dist/{chunk-JV2ULRVE.js.map → chunk-MNXW5WBP.js.map} +1 -1
- package/dist/{chunk-3JJ7OXMW.js → chunk-OOIFG33A.js} +2 -2
- package/dist/chunk-YPD3UZCL.js +54 -0
- package/dist/chunk-YPD3UZCL.js.map +1 -0
- package/dist/foundation-models-embedding-model-strategy-FYYPJCZ3.js +59 -0
- package/dist/foundation-models-embedding-model-strategy-FYYPJCZ3.js.map +1 -0
- package/dist/{foundation-models-language-model-strategy-ZCRPVWAV.js → foundation-models-language-model-strategy-QODADI4V.js} +4 -4
- package/dist/index.cjs +173 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/orchestration-embedding-model-strategy-RMTIMOLO.js +60 -0
- package/dist/orchestration-embedding-model-strategy-RMTIMOLO.js.map +1 -0
- package/dist/{orchestration-language-model-strategy-NEW76M3M.js → orchestration-language-model-strategy-FUT3R3MK.js} +4 -4
- package/dist/orchestration-language-model-strategy-FUT3R3MK.js.map +1 -0
- package/package.json +5 -5
- package/dist/foundation-models-embedding-model-strategy-OEKTLGZN.js +0 -69
- package/dist/foundation-models-embedding-model-strategy-OEKTLGZN.js.map +0 -1
- package/dist/orchestration-embedding-model-strategy-QRHQIEEK.js +0 -79
- package/dist/orchestration-embedding-model-strategy-QRHQIEEK.js.map +0 -1
- package/dist/orchestration-language-model-strategy-NEW76M3M.js.map +0 -1
- /package/dist/{chunk-CXZSTU4M.js.map → chunk-43B7TGUQ.js.map} +0 -0
- /package/dist/{chunk-3JJ7OXMW.js.map → chunk-OOIFG33A.js.map} +0 -0
- /package/dist/{foundation-models-language-model-strategy-ZCRPVWAV.js.map → foundation-models-language-model-strategy-QODADI4V.js.map} +0 -0
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
getProviderName,
|
|
5
5
|
sapAIEmbeddingProviderOptions,
|
|
6
6
|
validateModelParamsWithWarnings
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-MNXW5WBP.js";
|
|
8
8
|
|
|
9
9
|
// src/strategy-utils.ts
|
|
10
10
|
import { TooManyEmbeddingValuesForCallError } from "@ai-sdk/provider";
|
|
@@ -633,4 +633,4 @@ export {
|
|
|
633
633
|
normalizeEmbedding,
|
|
634
634
|
prepareEmbeddingCall
|
|
635
635
|
};
|
|
636
|
-
//# sourceMappingURL=chunk-
|
|
636
|
+
//# sourceMappingURL=chunk-OOIFG33A.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
buildEmbeddingResult,
|
|
4
|
+
prepareEmbeddingCall
|
|
5
|
+
} from "./chunk-OOIFG33A.js";
|
|
6
|
+
import {
|
|
7
|
+
VERSION,
|
|
8
|
+
convertToAISDKError
|
|
9
|
+
} from "./chunk-MNXW5WBP.js";
|
|
10
|
+
|
|
11
|
+
// src/base-embedding-model-strategy.ts
|
|
12
|
+
var BaseEmbeddingModelStrategy = class {
|
|
13
|
+
/**
|
|
14
|
+
* Template method implementing the shared embedding algorithm.
|
|
15
|
+
* @param config - Strategy configuration.
|
|
16
|
+
* @param settings - Embedding model settings.
|
|
17
|
+
* @param options - AI SDK call options.
|
|
18
|
+
* @param maxEmbeddingsPerCall - Maximum embeddings per call.
|
|
19
|
+
* @returns Complete embedding result for AI SDK.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
async doEmbed(config, settings, options, maxEmbeddingsPerCall) {
|
|
23
|
+
const { abortSignal, values } = options;
|
|
24
|
+
const { embeddingOptions, providerName } = await prepareEmbeddingCall(
|
|
25
|
+
{ maxEmbeddingsPerCall, modelId: config.modelId, provider: config.provider },
|
|
26
|
+
options
|
|
27
|
+
);
|
|
28
|
+
const embeddingType = embeddingOptions?.type ?? settings.type ?? "text";
|
|
29
|
+
try {
|
|
30
|
+
const client = this.createClient(config, settings, embeddingOptions);
|
|
31
|
+
const response = await this.executeCall(client, values, embeddingType, abortSignal);
|
|
32
|
+
const embeddings = this.extractEmbeddings(response);
|
|
33
|
+
const totalTokens = this.extractTokenCount(response);
|
|
34
|
+
return buildEmbeddingResult({
|
|
35
|
+
embeddings,
|
|
36
|
+
modelId: config.modelId,
|
|
37
|
+
providerName,
|
|
38
|
+
totalTokens,
|
|
39
|
+
version: VERSION
|
|
40
|
+
});
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw convertToAISDKError(error, {
|
|
43
|
+
operation: "doEmbed",
|
|
44
|
+
requestBody: { values: values.length },
|
|
45
|
+
url: this.getUrl()
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
BaseEmbeddingModelStrategy
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=chunk-YPD3UZCL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/base-embedding-model-strategy.ts"],"sourcesContent":["/** Base class for embedding model strategies using the Template Method pattern. */\nimport type {\n EmbeddingModelV3CallOptions,\n EmbeddingModelV3Embedding,\n EmbeddingModelV3Result,\n} from \"@ai-sdk/provider\";\n\nimport type { SAPAIEmbeddingSettings } from \"./sap-ai-settings.js\";\nimport type { EmbeddingModelAPIStrategy, EmbeddingModelStrategyConfig } from \"./sap-ai-strategy.js\";\n\nimport { convertToAISDKError } from \"./sap-ai-error.js\";\nimport {\n buildEmbeddingResult,\n type EmbeddingProviderOptions,\n type EmbeddingType,\n prepareEmbeddingCall,\n} from \"./strategy-utils.js\";\nimport { VERSION } from \"./version.js\";\n\n/**\n * Abstract base class for embedding model strategies using the Template Method pattern.\n * @template TClient - The SDK client type (e.g., AzureOpenAiEmbeddingClient, OrchestrationEmbeddingClient).\n * @template TResponse - The API response type from the SDK client.\n * @internal\n */\nexport abstract class BaseEmbeddingModelStrategy<\n TClient,\n TResponse,\n> implements EmbeddingModelAPIStrategy {\n /**\n * Template method implementing the shared embedding algorithm.\n * @param config - Strategy configuration.\n * @param settings - Embedding model settings.\n * @param options - AI SDK call options.\n * @param maxEmbeddingsPerCall - Maximum embeddings per call.\n * @returns Complete embedding result for AI SDK.\n * @internal\n */\n async doEmbed(\n config: EmbeddingModelStrategyConfig,\n settings: SAPAIEmbeddingSettings,\n options: EmbeddingModelV3CallOptions,\n maxEmbeddingsPerCall: number,\n ): Promise<EmbeddingModelV3Result> {\n const { abortSignal, values } = options;\n\n const { embeddingOptions, providerName } = await prepareEmbeddingCall(\n { maxEmbeddingsPerCall, modelId: config.modelId, provider: config.provider },\n options,\n );\n\n const embeddingType =\n embeddingOptions?.type ?? (settings.type as EmbeddingType | undefined) ?? \"text\";\n\n try {\n const client = this.createClient(config, settings, embeddingOptions);\n\n const response = await this.executeCall(client, values, embeddingType, abortSignal);\n\n const embeddings = this.extractEmbeddings(response);\n const totalTokens = this.extractTokenCount(response);\n\n return buildEmbeddingResult({\n embeddings,\n modelId: config.modelId,\n providerName,\n totalTokens,\n version: VERSION,\n });\n } catch (error) {\n throw convertToAISDKError(error, {\n operation: \"doEmbed\",\n requestBody: { values: values.length },\n url: this.getUrl(),\n });\n }\n }\n\n /**\n * Creates the appropriate SDK client for this API.\n * @param config - Strategy configuration.\n * @param settings - Embedding model settings.\n * @param embeddingOptions - Parsed provider options from the call.\n * @returns SDK client instance.\n * @internal\n */\n protected abstract createClient(\n config: EmbeddingModelStrategyConfig,\n settings: SAPAIEmbeddingSettings,\n embeddingOptions: EmbeddingProviderOptions | undefined,\n ): TClient;\n\n /**\n * Executes the embedding API call.\n * @param client - SDK client instance.\n * @param values - Input strings to embed.\n * @param embeddingType - Type of embedding (text, query, document).\n * @param abortSignal - Optional abort signal.\n * @returns SDK response containing embeddings.\n * @internal\n */\n protected abstract executeCall(\n client: TClient,\n values: string[],\n embeddingType: EmbeddingType,\n abortSignal: AbortSignal | undefined,\n ): Promise<TResponse>;\n\n /**\n * Extracts embeddings from the SDK response.\n * @param response - SDK response containing embedding data.\n * @returns Array of normalized embedding vectors.\n * @internal\n */\n protected abstract extractEmbeddings(response: TResponse): EmbeddingModelV3Embedding[];\n\n /**\n * Extracts total token count from the SDK response.\n * @param response - SDK response containing usage data.\n * @returns Total token count used for the embedding request.\n * @internal\n */\n protected abstract extractTokenCount(response: TResponse): number;\n\n /**\n * Returns the URL identifier for this API (used in error messages).\n * @returns URL string identifier.\n * @internal\n */\n protected abstract getUrl(): string;\n}\n"],"mappings":";;;;;;;;;;;AAyBO,IAAe,6BAAf,MAGgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUrC,MAAM,QACJ,QACA,UACA,SACA,sBACiC;AACjC,UAAM,EAAE,aAAa,OAAO,IAAI;AAEhC,UAAM,EAAE,kBAAkB,aAAa,IAAI,MAAM;AAAA,MAC/C,EAAE,sBAAsB,SAAS,OAAO,SAAS,UAAU,OAAO,SAAS;AAAA,MAC3E;AAAA,IACF;AAEA,UAAM,gBACJ,kBAAkB,QAAS,SAAS,QAAsC;AAE5E,QAAI;AACF,YAAM,SAAS,KAAK,aAAa,QAAQ,UAAU,gBAAgB;AAEnE,YAAM,WAAW,MAAM,KAAK,YAAY,QAAQ,QAAQ,eAAe,WAAW;AAElF,YAAM,aAAa,KAAK,kBAAkB,QAAQ;AAClD,YAAM,cAAc,KAAK,kBAAkB,QAAQ;AAEnD,aAAO,qBAAqB;AAAA,QAC1B;AAAA,QACA,SAAS,OAAO;AAAA,QAChB;AAAA,QACA;AAAA,QACA,SAAS;AAAA,MACX,CAAC;AAAA,IACH,SAAS,OAAO;AACd,YAAM,oBAAoB,OAAO;AAAA,QAC/B,WAAW;AAAA,QACX,aAAa,EAAE,QAAQ,OAAO,OAAO;AAAA,QACrC,KAAK,KAAK,OAAO;AAAA,MACnB,CAAC;AAAA,IACH;AAAA,EACF;AAsDF;","names":[]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
BaseEmbeddingModelStrategy
|
|
4
|
+
} from "./chunk-YPD3UZCL.js";
|
|
5
|
+
import {
|
|
6
|
+
buildModelDeployment,
|
|
7
|
+
hasKeys,
|
|
8
|
+
normalizeEmbedding
|
|
9
|
+
} from "./chunk-OOIFG33A.js";
|
|
10
|
+
import {
|
|
11
|
+
deepMerge
|
|
12
|
+
} from "./chunk-MNXW5WBP.js";
|
|
13
|
+
|
|
14
|
+
// src/foundation-models-embedding-model-strategy.ts
|
|
15
|
+
var FoundationModelsEmbeddingModelStrategy = class extends BaseEmbeddingModelStrategy {
|
|
16
|
+
ClientClass;
|
|
17
|
+
constructor(ClientClass) {
|
|
18
|
+
super();
|
|
19
|
+
this.ClientClass = ClientClass;
|
|
20
|
+
}
|
|
21
|
+
createClient(config, settings, embeddingOptions) {
|
|
22
|
+
const mergedParams = deepMerge(
|
|
23
|
+
settings.modelParams ?? {},
|
|
24
|
+
embeddingOptions?.modelParams ?? {}
|
|
25
|
+
);
|
|
26
|
+
return {
|
|
27
|
+
client: new this.ClientClass(
|
|
28
|
+
buildModelDeployment(config, settings.modelVersion),
|
|
29
|
+
config.destination
|
|
30
|
+
),
|
|
31
|
+
mergedParams: hasKeys(mergedParams) ? mergedParams : void 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async executeCall(clientWithContext, values, _embeddingType, abortSignal) {
|
|
35
|
+
const request = this.buildRequest(values, clientWithContext.mergedParams);
|
|
36
|
+
return clientWithContext.client.run(request, abortSignal ? { signal: abortSignal } : void 0);
|
|
37
|
+
}
|
|
38
|
+
extractEmbeddings(response) {
|
|
39
|
+
const embeddingData = response._data.data;
|
|
40
|
+
const sortedEmbeddings = embeddingData.slice().sort((a, b) => a.index - b.index);
|
|
41
|
+
return sortedEmbeddings.map((item) => normalizeEmbedding(item.embedding));
|
|
42
|
+
}
|
|
43
|
+
extractTokenCount(response) {
|
|
44
|
+
return response._data.usage.total_tokens;
|
|
45
|
+
}
|
|
46
|
+
getUrl() {
|
|
47
|
+
return "sap-ai:foundation-models/embeddings";
|
|
48
|
+
}
|
|
49
|
+
buildRequest(values, mergedParams) {
|
|
50
|
+
return {
|
|
51
|
+
input: values,
|
|
52
|
+
...mergedParams ?? {}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
FoundationModelsEmbeddingModelStrategy
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=foundation-models-embedding-model-strategy-FYYPJCZ3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/foundation-models-embedding-model-strategy.ts"],"sourcesContent":["/** Foundation Models embedding model strategy using `@sap-ai-sdk/foundation-models`. */\nimport type { EmbeddingModelV3Embedding } from \"@ai-sdk/provider\";\nimport type {\n AzureOpenAiEmbeddingClient,\n AzureOpenAiEmbeddingParameters,\n AzureOpenAiEmbeddingResponse,\n} from \"@sap-ai-sdk/foundation-models\";\n\nimport type { SAPAIEmbeddingSettings } from \"./sap-ai-settings.js\";\nimport type { EmbeddingModelStrategyConfig } from \"./sap-ai-strategy.js\";\nimport type { EmbeddingProviderOptions } from \"./strategy-utils.js\";\n\nimport { BaseEmbeddingModelStrategy } from \"./base-embedding-model-strategy.js\";\nimport { deepMerge } from \"./deep-merge.js\";\nimport { buildModelDeployment, hasKeys, normalizeEmbedding } from \"./strategy-utils.js\";\n\n/**\n * Client with pre-merged params for thread-safe concurrent requests.\n * @internal\n */\ninterface FMEmbeddingClientWithContext {\n client: AzureOpenAiEmbeddingClient;\n mergedParams: Record<string, unknown> | undefined;\n}\n\n/** @internal */\ntype FoundationModelsEmbeddingClientClass = typeof AzureOpenAiEmbeddingClient;\n\n/**\n * Embedding model strategy for the Foundation Models API.\n *\n * Provides direct access to Azure OpenAI embedding models.\n * @internal\n */\nexport class FoundationModelsEmbeddingModelStrategy extends BaseEmbeddingModelStrategy<\n FMEmbeddingClientWithContext,\n AzureOpenAiEmbeddingResponse\n> {\n private readonly ClientClass: FoundationModelsEmbeddingClientClass;\n\n constructor(ClientClass: FoundationModelsEmbeddingClientClass) {\n super();\n this.ClientClass = ClientClass;\n }\n\n protected createClient(\n config: EmbeddingModelStrategyConfig,\n settings: SAPAIEmbeddingSettings,\n embeddingOptions: EmbeddingProviderOptions | undefined,\n ): FMEmbeddingClientWithContext {\n const mergedParams = deepMerge(\n (settings.modelParams as Record<string, unknown> | undefined) ?? {},\n embeddingOptions?.modelParams ?? {},\n );\n\n return {\n client: new this.ClientClass(\n buildModelDeployment(config, settings.modelVersion),\n config.destination,\n ),\n mergedParams: hasKeys(mergedParams) ? mergedParams : undefined,\n };\n }\n\n protected async executeCall(\n clientWithContext: FMEmbeddingClientWithContext,\n values: string[],\n _embeddingType: unknown,\n abortSignal: AbortSignal | undefined,\n ): Promise<AzureOpenAiEmbeddingResponse> {\n const request = this.buildRequest(values, clientWithContext.mergedParams);\n return clientWithContext.client.run(request, abortSignal ? { signal: abortSignal } : undefined);\n }\n\n protected extractEmbeddings(response: AzureOpenAiEmbeddingResponse): EmbeddingModelV3Embedding[] {\n // SDK types include `& Record<string, any>` which requires explicit extraction\n const embeddingData = response._data.data;\n const sortedEmbeddings = embeddingData.slice().sort((a, b) => a.index - b.index);\n return sortedEmbeddings.map((item) => normalizeEmbedding(item.embedding as number[]));\n }\n\n protected extractTokenCount(response: AzureOpenAiEmbeddingResponse): number {\n return response._data.usage.total_tokens;\n }\n\n protected getUrl(): string {\n return \"sap-ai:foundation-models/embeddings\";\n }\n\n private buildRequest(\n values: string[],\n mergedParams: Record<string, unknown> | undefined,\n ): AzureOpenAiEmbeddingParameters {\n return {\n input: values,\n ...(mergedParams ?? {}),\n } as AzureOpenAiEmbeddingParameters;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCO,IAAM,yCAAN,cAAqD,2BAG1D;AAAA,EACiB;AAAA,EAEjB,YAAY,aAAmD;AAC7D,UAAM;AACN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEU,aACR,QACA,UACA,kBAC8B;AAC9B,UAAM,eAAe;AAAA,MAClB,SAAS,eAAuD,CAAC;AAAA,MAClE,kBAAkB,eAAe,CAAC;AAAA,IACpC;AAEA,WAAO;AAAA,MACL,QAAQ,IAAI,KAAK;AAAA,QACf,qBAAqB,QAAQ,SAAS,YAAY;AAAA,QAClD,OAAO;AAAA,MACT;AAAA,MACA,cAAc,QAAQ,YAAY,IAAI,eAAe;AAAA,IACvD;AAAA,EACF;AAAA,EAEA,MAAgB,YACd,mBACA,QACA,gBACA,aACuC;AACvC,UAAM,UAAU,KAAK,aAAa,QAAQ,kBAAkB,YAAY;AACxE,WAAO,kBAAkB,OAAO,IAAI,SAAS,cAAc,EAAE,QAAQ,YAAY,IAAI,MAAS;AAAA,EAChG;AAAA,EAEU,kBAAkB,UAAqE;AAE/F,UAAM,gBAAgB,SAAS,MAAM;AACrC,UAAM,mBAAmB,cAAc,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AAC/E,WAAO,iBAAiB,IAAI,CAAC,SAAS,mBAAmB,KAAK,SAAqB,CAAC;AAAA,EACtF;AAAA,EAEU,kBAAkB,UAAgD;AAC1E,WAAO,SAAS,MAAM,MAAM;AAAA,EAC9B;AAAA,EAEU,SAAiB;AACzB,WAAO;AAAA,EACT;AAAA,EAEQ,aACN,QACA,cACgC;AAChC,WAAO;AAAA,MACL,OAAO;AAAA,MACP,GAAI,gBAAgB,CAAC;AAAA,IACvB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
BaseLanguageModelStrategy
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-43B7TGUQ.js";
|
|
5
5
|
import "./chunk-SD6CRCHX.js";
|
|
6
6
|
import {
|
|
7
7
|
buildModelDeployment,
|
|
8
8
|
convertResponseFormat,
|
|
9
9
|
convertToolsToSAPFormat
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-OOIFG33A.js";
|
|
11
|
+
import "./chunk-MNXW5WBP.js";
|
|
12
12
|
|
|
13
13
|
// src/foundation-models-language-model-strategy.ts
|
|
14
14
|
var FOUNDATION_MODELS_PARAM_MAPPINGS = [
|
|
@@ -84,4 +84,4 @@ var FoundationModelsLanguageModelStrategy = class extends BaseLanguageModelStrat
|
|
|
84
84
|
export {
|
|
85
85
|
FoundationModelsLanguageModelStrategy
|
|
86
86
|
};
|
|
87
|
-
//# sourceMappingURL=foundation-models-language-model-strategy-
|
|
87
|
+
//# sourceMappingURL=foundation-models-language-model-strategy-QODADI4V.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -323,78 +323,6 @@ var init_sap_ai_provider_options = __esm({
|
|
|
323
323
|
}
|
|
324
324
|
});
|
|
325
325
|
|
|
326
|
-
// src/deep-merge.ts
|
|
327
|
-
function deepMerge(...sources) {
|
|
328
|
-
return mergeInternal(sources);
|
|
329
|
-
}
|
|
330
|
-
function cloneDeep(obj, seen, depth) {
|
|
331
|
-
if (depth > MAX_DEPTH) {
|
|
332
|
-
throw new Error("Maximum merge depth exceeded");
|
|
333
|
-
}
|
|
334
|
-
if (seen.has(obj)) {
|
|
335
|
-
throw new Error("Circular reference detected during deep merge");
|
|
336
|
-
}
|
|
337
|
-
seen.add(obj);
|
|
338
|
-
const result = {};
|
|
339
|
-
for (const key of Object.keys(obj)) {
|
|
340
|
-
if (!isSafeKey(key)) continue;
|
|
341
|
-
const value = obj[key];
|
|
342
|
-
result[key] = isPlainObject(value) ? cloneDeep(value, seen, depth + 1) : value;
|
|
343
|
-
}
|
|
344
|
-
return result;
|
|
345
|
-
}
|
|
346
|
-
function isPlainObject(value) {
|
|
347
|
-
if (value === null || typeof value !== "object") return false;
|
|
348
|
-
const proto = Object.getPrototypeOf(value);
|
|
349
|
-
return proto === Object.prototype || proto === null;
|
|
350
|
-
}
|
|
351
|
-
function isSafeKey(key) {
|
|
352
|
-
return !DANGEROUS_KEYS.has(key);
|
|
353
|
-
}
|
|
354
|
-
function mergeInternal(sources) {
|
|
355
|
-
let result = {};
|
|
356
|
-
for (const source of sources) {
|
|
357
|
-
if (source == null) continue;
|
|
358
|
-
result = mergeTwo(result, source, /* @__PURE__ */ new WeakSet(), 0);
|
|
359
|
-
}
|
|
360
|
-
return result;
|
|
361
|
-
}
|
|
362
|
-
function mergeTwo(target, source, seen, depth) {
|
|
363
|
-
if (depth > MAX_DEPTH) {
|
|
364
|
-
throw new Error("Maximum merge depth exceeded");
|
|
365
|
-
}
|
|
366
|
-
if (seen.has(source)) {
|
|
367
|
-
throw new Error("Circular reference detected during deep merge");
|
|
368
|
-
}
|
|
369
|
-
seen.add(source);
|
|
370
|
-
for (const key of Object.keys(source)) {
|
|
371
|
-
if (!isSafeKey(key)) continue;
|
|
372
|
-
const sourceValue = source[key];
|
|
373
|
-
const targetValue = target[key];
|
|
374
|
-
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
375
|
-
target[key] = mergeTwo(
|
|
376
|
-
cloneDeep(targetValue, /* @__PURE__ */ new WeakSet(), depth + 1),
|
|
377
|
-
sourceValue,
|
|
378
|
-
seen,
|
|
379
|
-
depth + 1
|
|
380
|
-
);
|
|
381
|
-
} else if (isPlainObject(sourceValue)) {
|
|
382
|
-
target[key] = cloneDeep(sourceValue, seen, depth + 1);
|
|
383
|
-
} else {
|
|
384
|
-
target[key] = sourceValue;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return target;
|
|
388
|
-
}
|
|
389
|
-
var DANGEROUS_KEYS, MAX_DEPTH;
|
|
390
|
-
var init_deep_merge = __esm({
|
|
391
|
-
"src/deep-merge.ts"() {
|
|
392
|
-
"use strict";
|
|
393
|
-
DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
394
|
-
MAX_DEPTH = 100;
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
|
|
398
326
|
// node_modules/@sap-cloud-sdk/util/dist/array.js
|
|
399
327
|
var require_array = __commonJS({
|
|
400
328
|
"node_modules/@sap-cloud-sdk/util/dist/array.js"(exports2) {
|
|
@@ -30266,7 +30194,7 @@ See: https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-serv
|
|
|
30266
30194
|
return new import_provider2.NoSuchModelError({
|
|
30267
30195
|
message: `SAP AI Core deployment error: ${originalErrorMsg}
|
|
30268
30196
|
|
|
30269
|
-
Make sure you have a running orchestration deployment in your AI Core instance.
|
|
30197
|
+
Make sure you have a running orchestration deployment in your SAP AI Core instance.
|
|
30270
30198
|
See: https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-orchestration`,
|
|
30271
30199
|
modelId: modelId ?? "unknown",
|
|
30272
30200
|
modelType: "languageModel"
|
|
@@ -30634,6 +30562,73 @@ The model's response was blocked by content safety filters. Try a different prom
|
|
|
30634
30562
|
}
|
|
30635
30563
|
});
|
|
30636
30564
|
|
|
30565
|
+
// src/deep-merge.ts
|
|
30566
|
+
function deepMerge(...sources) {
|
|
30567
|
+
return mergeInternal(sources);
|
|
30568
|
+
}
|
|
30569
|
+
function cloneDeep(obj, seen, depth) {
|
|
30570
|
+
if (depth > MAX_DEPTH) {
|
|
30571
|
+
throw new Error("Maximum merge depth exceeded");
|
|
30572
|
+
}
|
|
30573
|
+
if (seen.has(obj)) {
|
|
30574
|
+
throw new Error("Circular reference detected during deep merge");
|
|
30575
|
+
}
|
|
30576
|
+
seen.add(obj);
|
|
30577
|
+
const result = {};
|
|
30578
|
+
for (const key of Object.keys(obj)) {
|
|
30579
|
+
if (!isSafeKey(key)) continue;
|
|
30580
|
+
const value = obj[key];
|
|
30581
|
+
result[key] = isPlainObject(value) ? cloneDeep(value, seen, depth + 1) : value;
|
|
30582
|
+
}
|
|
30583
|
+
return result;
|
|
30584
|
+
}
|
|
30585
|
+
function isPlainObject(value) {
|
|
30586
|
+
if (value === null || typeof value !== "object") return false;
|
|
30587
|
+
const proto = Object.getPrototypeOf(value);
|
|
30588
|
+
return proto === Object.prototype || proto === null;
|
|
30589
|
+
}
|
|
30590
|
+
function isSafeKey(key) {
|
|
30591
|
+
return !DANGEROUS_KEYS.has(key);
|
|
30592
|
+
}
|
|
30593
|
+
function mergeInternal(sources) {
|
|
30594
|
+
let result = {};
|
|
30595
|
+
for (const source of sources) {
|
|
30596
|
+
if (source == null) continue;
|
|
30597
|
+
result = mergeTwo(result, source, /* @__PURE__ */ new WeakSet(), 0);
|
|
30598
|
+
}
|
|
30599
|
+
return result;
|
|
30600
|
+
}
|
|
30601
|
+
function mergeTwo(target, source, seen, depth) {
|
|
30602
|
+
if (depth > MAX_DEPTH) {
|
|
30603
|
+
throw new Error("Maximum merge depth exceeded");
|
|
30604
|
+
}
|
|
30605
|
+
if (seen.has(source)) {
|
|
30606
|
+
throw new Error("Circular reference detected during deep merge");
|
|
30607
|
+
}
|
|
30608
|
+
seen.add(source);
|
|
30609
|
+
for (const key of Object.keys(source)) {
|
|
30610
|
+
if (!isSafeKey(key)) continue;
|
|
30611
|
+
const sourceValue = source[key];
|
|
30612
|
+
const targetValue = target[key];
|
|
30613
|
+
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
30614
|
+
target[key] = mergeTwo(cloneDeep(targetValue, seen, depth + 1), sourceValue, seen, depth + 1);
|
|
30615
|
+
} else if (isPlainObject(sourceValue)) {
|
|
30616
|
+
target[key] = cloneDeep(sourceValue, seen, depth + 1);
|
|
30617
|
+
} else {
|
|
30618
|
+
target[key] = sourceValue;
|
|
30619
|
+
}
|
|
30620
|
+
}
|
|
30621
|
+
return target;
|
|
30622
|
+
}
|
|
30623
|
+
var DANGEROUS_KEYS, MAX_DEPTH;
|
|
30624
|
+
var init_deep_merge = __esm({
|
|
30625
|
+
"src/deep-merge.ts"() {
|
|
30626
|
+
"use strict";
|
|
30627
|
+
DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
30628
|
+
MAX_DEPTH = 100;
|
|
30629
|
+
}
|
|
30630
|
+
});
|
|
30631
|
+
|
|
30637
30632
|
// src/strategy-utils.ts
|
|
30638
30633
|
function applyParameterOverrides(modelParams, options, sapModelParams, settingsModelParams, mappings) {
|
|
30639
30634
|
for (const mapping of mappings) {
|
|
@@ -31260,71 +31255,110 @@ var VERSION;
|
|
|
31260
31255
|
var init_version = __esm({
|
|
31261
31256
|
"src/version.ts"() {
|
|
31262
31257
|
"use strict";
|
|
31263
|
-
VERSION = true ? "4.4.
|
|
31258
|
+
VERSION = true ? "4.4.17" : "0.0.0-test";
|
|
31264
31259
|
}
|
|
31265
31260
|
});
|
|
31266
31261
|
|
|
31267
|
-
// src/
|
|
31268
|
-
var
|
|
31269
|
-
|
|
31270
|
-
|
|
31271
|
-
});
|
|
31272
|
-
var FoundationModelsEmbeddingModelStrategy;
|
|
31273
|
-
var init_foundation_models_embedding_model_strategy = __esm({
|
|
31274
|
-
"src/foundation-models-embedding-model-strategy.ts"() {
|
|
31262
|
+
// src/base-embedding-model-strategy.ts
|
|
31263
|
+
var BaseEmbeddingModelStrategy;
|
|
31264
|
+
var init_base_embedding_model_strategy = __esm({
|
|
31265
|
+
"src/base-embedding-model-strategy.ts"() {
|
|
31275
31266
|
"use strict";
|
|
31276
|
-
init_deep_merge();
|
|
31277
31267
|
init_sap_ai_error();
|
|
31278
31268
|
init_strategy_utils();
|
|
31279
31269
|
init_version();
|
|
31280
|
-
|
|
31281
|
-
|
|
31282
|
-
|
|
31283
|
-
|
|
31284
|
-
|
|
31270
|
+
BaseEmbeddingModelStrategy = class {
|
|
31271
|
+
/**
|
|
31272
|
+
* Template method implementing the shared embedding algorithm.
|
|
31273
|
+
* @param config - Strategy configuration.
|
|
31274
|
+
* @param settings - Embedding model settings.
|
|
31275
|
+
* @param options - AI SDK call options.
|
|
31276
|
+
* @param maxEmbeddingsPerCall - Maximum embeddings per call.
|
|
31277
|
+
* @returns Complete embedding result for AI SDK.
|
|
31278
|
+
* @internal
|
|
31279
|
+
*/
|
|
31285
31280
|
async doEmbed(config, settings, options, maxEmbeddingsPerCall) {
|
|
31286
31281
|
const { abortSignal, values } = options;
|
|
31287
31282
|
const { embeddingOptions, providerName } = await prepareEmbeddingCall(
|
|
31288
31283
|
{ maxEmbeddingsPerCall, modelId: config.modelId, provider: config.provider },
|
|
31289
31284
|
options
|
|
31290
31285
|
);
|
|
31286
|
+
const embeddingType = embeddingOptions?.type ?? settings.type ?? "text";
|
|
31291
31287
|
try {
|
|
31292
|
-
const client = this.createClient(config, settings
|
|
31293
|
-
const
|
|
31294
|
-
const
|
|
31295
|
-
const
|
|
31296
|
-
const tokenUsage = response._data.usage;
|
|
31297
|
-
const embeddings = embeddingData.map(
|
|
31298
|
-
(embedding) => normalizeEmbedding(embedding)
|
|
31299
|
-
);
|
|
31288
|
+
const client = this.createClient(config, settings, embeddingOptions);
|
|
31289
|
+
const response = await this.executeCall(client, values, embeddingType, abortSignal);
|
|
31290
|
+
const embeddings = this.extractEmbeddings(response);
|
|
31291
|
+
const totalTokens = this.extractTokenCount(response);
|
|
31300
31292
|
return buildEmbeddingResult({
|
|
31301
31293
|
embeddings,
|
|
31302
31294
|
modelId: config.modelId,
|
|
31303
31295
|
providerName,
|
|
31304
|
-
totalTokens
|
|
31296
|
+
totalTokens,
|
|
31305
31297
|
version: VERSION
|
|
31306
31298
|
});
|
|
31307
31299
|
} catch (error) {
|
|
31308
31300
|
throw convertToAISDKError(error, {
|
|
31309
31301
|
operation: "doEmbed",
|
|
31310
31302
|
requestBody: { values: values.length },
|
|
31311
|
-
url:
|
|
31303
|
+
url: this.getUrl()
|
|
31312
31304
|
});
|
|
31313
31305
|
}
|
|
31314
31306
|
}
|
|
31315
|
-
|
|
31307
|
+
};
|
|
31308
|
+
}
|
|
31309
|
+
});
|
|
31310
|
+
|
|
31311
|
+
// src/foundation-models-embedding-model-strategy.ts
|
|
31312
|
+
var foundation_models_embedding_model_strategy_exports = {};
|
|
31313
|
+
__export(foundation_models_embedding_model_strategy_exports, {
|
|
31314
|
+
FoundationModelsEmbeddingModelStrategy: () => FoundationModelsEmbeddingModelStrategy
|
|
31315
|
+
});
|
|
31316
|
+
var FoundationModelsEmbeddingModelStrategy;
|
|
31317
|
+
var init_foundation_models_embedding_model_strategy = __esm({
|
|
31318
|
+
"src/foundation-models-embedding-model-strategy.ts"() {
|
|
31319
|
+
"use strict";
|
|
31320
|
+
init_base_embedding_model_strategy();
|
|
31321
|
+
init_deep_merge();
|
|
31322
|
+
init_strategy_utils();
|
|
31323
|
+
FoundationModelsEmbeddingModelStrategy = class extends BaseEmbeddingModelStrategy {
|
|
31324
|
+
ClientClass;
|
|
31325
|
+
constructor(ClientClass) {
|
|
31326
|
+
super();
|
|
31327
|
+
this.ClientClass = ClientClass;
|
|
31328
|
+
}
|
|
31329
|
+
createClient(config, settings, embeddingOptions) {
|
|
31316
31330
|
const mergedParams = deepMerge(
|
|
31317
|
-
settings.modelParams,
|
|
31318
|
-
embeddingOptions?.modelParams
|
|
31331
|
+
settings.modelParams ?? {},
|
|
31332
|
+
embeddingOptions?.modelParams ?? {}
|
|
31319
31333
|
);
|
|
31320
31334
|
return {
|
|
31321
|
-
|
|
31322
|
-
|
|
31335
|
+
client: new this.ClientClass(
|
|
31336
|
+
buildModelDeployment(config, settings.modelVersion),
|
|
31337
|
+
config.destination
|
|
31338
|
+
),
|
|
31339
|
+
mergedParams: hasKeys(mergedParams) ? mergedParams : void 0
|
|
31323
31340
|
};
|
|
31324
31341
|
}
|
|
31325
|
-
|
|
31326
|
-
const
|
|
31327
|
-
return
|
|
31342
|
+
async executeCall(clientWithContext, values, _embeddingType, abortSignal) {
|
|
31343
|
+
const request = this.buildRequest(values, clientWithContext.mergedParams);
|
|
31344
|
+
return clientWithContext.client.run(request, abortSignal ? { signal: abortSignal } : void 0);
|
|
31345
|
+
}
|
|
31346
|
+
extractEmbeddings(response) {
|
|
31347
|
+
const embeddingData = response._data.data;
|
|
31348
|
+
const sortedEmbeddings = embeddingData.slice().sort((a, b) => a.index - b.index);
|
|
31349
|
+
return sortedEmbeddings.map((item) => normalizeEmbedding(item.embedding));
|
|
31350
|
+
}
|
|
31351
|
+
extractTokenCount(response) {
|
|
31352
|
+
return response._data.usage.total_tokens;
|
|
31353
|
+
}
|
|
31354
|
+
getUrl() {
|
|
31355
|
+
return "sap-ai:foundation-models/embeddings";
|
|
31356
|
+
}
|
|
31357
|
+
buildRequest(values, mergedParams) {
|
|
31358
|
+
return {
|
|
31359
|
+
input: values,
|
|
31360
|
+
...mergedParams ?? {}
|
|
31361
|
+
};
|
|
31328
31362
|
}
|
|
31329
31363
|
};
|
|
31330
31364
|
}
|
|
@@ -31339,70 +31373,51 @@ var OrchestrationEmbeddingModelStrategy;
|
|
|
31339
31373
|
var init_orchestration_embedding_model_strategy = __esm({
|
|
31340
31374
|
"src/orchestration-embedding-model-strategy.ts"() {
|
|
31341
31375
|
"use strict";
|
|
31376
|
+
init_base_embedding_model_strategy();
|
|
31342
31377
|
init_deep_merge();
|
|
31343
|
-
init_sap_ai_error();
|
|
31344
31378
|
init_strategy_utils();
|
|
31345
|
-
|
|
31346
|
-
OrchestrationEmbeddingModelStrategy = class {
|
|
31379
|
+
OrchestrationEmbeddingModelStrategy = class extends BaseEmbeddingModelStrategy {
|
|
31347
31380
|
ClientClass;
|
|
31348
31381
|
constructor(ClientClass) {
|
|
31382
|
+
super();
|
|
31349
31383
|
this.ClientClass = ClientClass;
|
|
31350
31384
|
}
|
|
31351
|
-
|
|
31352
|
-
const
|
|
31353
|
-
|
|
31354
|
-
|
|
31355
|
-
options
|
|
31385
|
+
createClient(config, settings, embeddingOptions) {
|
|
31386
|
+
const mergedParams = deepMerge(
|
|
31387
|
+
settings.modelParams ?? {},
|
|
31388
|
+
embeddingOptions?.modelParams ?? {}
|
|
31356
31389
|
);
|
|
31357
|
-
const embeddingType = embeddingOptions?.type ?? settings.type ?? "text";
|
|
31358
|
-
try {
|
|
31359
|
-
const client = this.createClient(
|
|
31360
|
-
config,
|
|
31361
|
-
settings.modelParams,
|
|
31362
|
-
embeddingOptions?.modelParams,
|
|
31363
|
-
settings.modelVersion,
|
|
31364
|
-
settings.masking
|
|
31365
|
-
);
|
|
31366
|
-
const response = await client.embed(
|
|
31367
|
-
{ input: values, type: embeddingType },
|
|
31368
|
-
abortSignal ? { signal: abortSignal } : void 0
|
|
31369
|
-
);
|
|
31370
|
-
const embeddingData = response.getEmbeddings();
|
|
31371
|
-
const tokenUsage = response.getTokenUsage();
|
|
31372
|
-
const sortedEmbeddings = [...embeddingData].sort((a, b) => a.index - b.index);
|
|
31373
|
-
const embeddings = sortedEmbeddings.map(
|
|
31374
|
-
(data) => normalizeEmbedding(data.embedding)
|
|
31375
|
-
);
|
|
31376
|
-
return buildEmbeddingResult({
|
|
31377
|
-
embeddings,
|
|
31378
|
-
modelId: config.modelId,
|
|
31379
|
-
providerName,
|
|
31380
|
-
totalTokens: tokenUsage.total_tokens,
|
|
31381
|
-
version: VERSION
|
|
31382
|
-
});
|
|
31383
|
-
} catch (error) {
|
|
31384
|
-
throw convertToAISDKError(error, {
|
|
31385
|
-
operation: "doEmbed",
|
|
31386
|
-
requestBody: { values: values.length },
|
|
31387
|
-
url: "sap-ai:orchestration/embeddings"
|
|
31388
|
-
});
|
|
31389
|
-
}
|
|
31390
|
-
}
|
|
31391
|
-
createClient(config, settingsModelParams, perCallModelParams, modelVersion, masking) {
|
|
31392
|
-
const mergedParams = deepMerge(settingsModelParams ?? {}, perCallModelParams ?? {});
|
|
31393
31390
|
const embeddingConfig = {
|
|
31394
31391
|
model: {
|
|
31395
31392
|
name: config.modelId,
|
|
31396
31393
|
...hasKeys(mergedParams) ? { params: mergedParams } : {},
|
|
31397
|
-
...modelVersion ? { version: modelVersion } : {}
|
|
31394
|
+
...settings.modelVersion ? { version: settings.modelVersion } : {}
|
|
31398
31395
|
}
|
|
31399
31396
|
};
|
|
31400
31397
|
const moduleConfig = {
|
|
31401
31398
|
embeddings: embeddingConfig,
|
|
31402
|
-
...masking && hasKeys(masking) ? { masking } : {}
|
|
31399
|
+
...settings.masking && hasKeys(settings.masking) ? { masking: settings.masking } : {}
|
|
31403
31400
|
};
|
|
31404
31401
|
return new this.ClientClass(moduleConfig, config.deploymentConfig, config.destination);
|
|
31405
31402
|
}
|
|
31403
|
+
async executeCall(client, values, embeddingType, abortSignal) {
|
|
31404
|
+
return client.embed(
|
|
31405
|
+
{ input: values, type: embeddingType },
|
|
31406
|
+
abortSignal ? { signal: abortSignal } : void 0
|
|
31407
|
+
);
|
|
31408
|
+
}
|
|
31409
|
+
extractEmbeddings(response) {
|
|
31410
|
+
const embeddingData = response.getEmbeddings();
|
|
31411
|
+
const sortedEmbeddings = [...embeddingData].sort((a, b) => a.index - b.index);
|
|
31412
|
+
return sortedEmbeddings.map((data) => normalizeEmbedding(data.embedding));
|
|
31413
|
+
}
|
|
31414
|
+
extractTokenCount(response) {
|
|
31415
|
+
const tokenUsage = response.getTokenUsage();
|
|
31416
|
+
return tokenUsage.total_tokens;
|
|
31417
|
+
}
|
|
31418
|
+
getUrl() {
|
|
31419
|
+
return "sap-ai:orchestration/embeddings";
|
|
31420
|
+
}
|
|
31406
31421
|
};
|
|
31407
31422
|
}
|
|
31408
31423
|
});
|
|
@@ -32561,6 +32576,9 @@ function createSAPAIProvider(options = {}) {
|
|
|
32561
32576
|
const providerApi = options.api ?? "orchestration";
|
|
32562
32577
|
const deploymentConfig = options.deploymentId ? { deploymentId: options.deploymentId } : { resourceGroup };
|
|
32563
32578
|
const createModel = (modelId, settings = {}) => {
|
|
32579
|
+
if (settings.modelParams) {
|
|
32580
|
+
validateModelParamsSettings(settings.modelParams);
|
|
32581
|
+
}
|
|
32564
32582
|
const mergedSettings = mergeSettingsWithApi(
|
|
32565
32583
|
options.defaultSettings,
|
|
32566
32584
|
settings,
|
|
@@ -32574,6 +32592,9 @@ function createSAPAIProvider(options = {}) {
|
|
|
32574
32592
|
});
|
|
32575
32593
|
};
|
|
32576
32594
|
const createEmbeddingModel = (modelId, settings = {}) => {
|
|
32595
|
+
if (settings.modelParams) {
|
|
32596
|
+
validateEmbeddingModelParamsSettings(settings.modelParams);
|
|
32597
|
+
}
|
|
32577
32598
|
const mergedSettings = mergeSettingsWithApi(
|
|
32578
32599
|
options.defaultSettings,
|
|
32579
32600
|
settings,
|