@jerome-benoit/sap-ai-provider 4.6.0 → 4.6.1
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/{chunk-BV5Y6RMC.js → chunk-HJZCRF7J.js} +11 -4
- package/dist/chunk-HJZCRF7J.js.map +1 -0
- package/dist/{chunk-DBAIFR3B.js → chunk-I5ZTK7M5.js} +64 -64
- package/dist/{chunk-DBAIFR3B.js.map → chunk-I5ZTK7M5.js.map} +1 -1
- package/dist/{chunk-WYDTQDMJ.js → chunk-IAXILSPQ.js} +3 -3
- package/dist/chunk-IAXILSPQ.js.map +1 -0
- package/dist/{chunk-KS5QNMYZ.js → chunk-U2HDUNO7.js} +23 -21
- package/dist/chunk-U2HDUNO7.js.map +1 -0
- package/dist/{foundation-models-embedding-model-strategy-XLD3PGCK.js → foundation-models-embedding-model-strategy-C4SXGZ66.js} +5 -10
- package/dist/foundation-models-embedding-model-strategy-C4SXGZ66.js.map +1 -0
- package/dist/{foundation-models-language-model-strategy-SNBZBWX4.js → foundation-models-language-model-strategy-3D4V6PSZ.js} +5 -5
- package/dist/foundation-models-language-model-strategy-3D4V6PSZ.js.map +1 -0
- package/dist/index.cjs +99 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/{orchestration-embedding-model-strategy-6BKD5NW7.js → orchestration-embedding-model-strategy-7FY6NJD7.js} +5 -10
- package/dist/orchestration-embedding-model-strategy-7FY6NJD7.js.map +1 -0
- package/dist/{orchestration-language-model-strategy-OYSEPGQG.js → orchestration-language-model-strategy-FI5HLHWP.js} +4 -4
- package/dist/orchestration-language-model-strategy-FI5HLHWP.js.map +1 -0
- package/package.json +2 -2
- package/dist/chunk-BV5Y6RMC.js.map +0 -1
- package/dist/chunk-KS5QNMYZ.js.map +0 -1
- package/dist/chunk-WYDTQDMJ.js.map +0 -1
- package/dist/foundation-models-embedding-model-strategy-XLD3PGCK.js.map +0 -1
- package/dist/foundation-models-language-model-strategy-SNBZBWX4.js.map +0 -1
- package/dist/orchestration-embedding-model-strategy-6BKD5NW7.js.map +0 -1
- package/dist/orchestration-language-model-strategy-OYSEPGQG.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -330,6 +330,73 @@ var init_sap_ai_provider_options = __esm({
|
|
|
330
330
|
}
|
|
331
331
|
});
|
|
332
332
|
|
|
333
|
+
// src/deep-merge.ts
|
|
334
|
+
function deepMerge(...sources) {
|
|
335
|
+
let result = {};
|
|
336
|
+
for (const source of sources) {
|
|
337
|
+
if (source == null) continue;
|
|
338
|
+
result = mergeTwo(result, source, /* @__PURE__ */ new Set(), 0);
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
function cloneDeep(obj, ancestors, depth) {
|
|
343
|
+
if (depth > MAX_DEPTH) {
|
|
344
|
+
throw new Error("Maximum merge depth exceeded");
|
|
345
|
+
}
|
|
346
|
+
if (ancestors.has(obj)) {
|
|
347
|
+
throw new Error("Circular reference detected during deep merge");
|
|
348
|
+
}
|
|
349
|
+
ancestors.add(obj);
|
|
350
|
+
const result = {};
|
|
351
|
+
for (const key of Object.keys(obj)) {
|
|
352
|
+
if (!isSafeKey(key)) continue;
|
|
353
|
+
const value = obj[key];
|
|
354
|
+
result[key] = isPlainObject(value) ? cloneDeep(value, ancestors, depth + 1) : value;
|
|
355
|
+
}
|
|
356
|
+
ancestors.delete(obj);
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
function isPlainObject(value) {
|
|
360
|
+
if (value === null || typeof value !== "object") return false;
|
|
361
|
+
const proto = Object.getPrototypeOf(value);
|
|
362
|
+
return proto === Object.prototype || proto === null;
|
|
363
|
+
}
|
|
364
|
+
function isSafeKey(key) {
|
|
365
|
+
return !DANGEROUS_KEYS.has(key);
|
|
366
|
+
}
|
|
367
|
+
function mergeTwo(target, source, ancestors, depth) {
|
|
368
|
+
if (depth > MAX_DEPTH) {
|
|
369
|
+
throw new Error("Maximum merge depth exceeded");
|
|
370
|
+
}
|
|
371
|
+
if (ancestors.has(source)) {
|
|
372
|
+
throw new Error("Circular reference detected during deep merge");
|
|
373
|
+
}
|
|
374
|
+
ancestors.add(source);
|
|
375
|
+
for (const key of Object.keys(source)) {
|
|
376
|
+
if (!isSafeKey(key)) continue;
|
|
377
|
+
const sourceValue = source[key];
|
|
378
|
+
const targetValue = target[key];
|
|
379
|
+
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
380
|
+
const cloned = cloneDeep(targetValue, /* @__PURE__ */ new Set(), depth + 1);
|
|
381
|
+
target[key] = mergeTwo(cloned, sourceValue, ancestors, depth + 1);
|
|
382
|
+
} else if (isPlainObject(sourceValue)) {
|
|
383
|
+
target[key] = cloneDeep(sourceValue, /* @__PURE__ */ new Set(), depth + 1);
|
|
384
|
+
} else {
|
|
385
|
+
target[key] = sourceValue;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
ancestors.delete(source);
|
|
389
|
+
return target;
|
|
390
|
+
}
|
|
391
|
+
var DANGEROUS_KEYS, MAX_DEPTH;
|
|
392
|
+
var init_deep_merge = __esm({
|
|
393
|
+
"src/deep-merge.ts"() {
|
|
394
|
+
"use strict";
|
|
395
|
+
DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
396
|
+
MAX_DEPTH = 100;
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
|
|
333
400
|
// node_modules/@sap-cloud-sdk/util/dist/array.js
|
|
334
401
|
var require_array = __commonJS({
|
|
335
402
|
"node_modules/@sap-cloud-sdk/util/dist/array.js"(exports2) {
|
|
@@ -30693,73 +30760,6 @@ The model's response was blocked by content safety filters. Try a different prom
|
|
|
30693
30760
|
}
|
|
30694
30761
|
});
|
|
30695
30762
|
|
|
30696
|
-
// src/deep-merge.ts
|
|
30697
|
-
function deepMerge(...sources) {
|
|
30698
|
-
let result = {};
|
|
30699
|
-
for (const source of sources) {
|
|
30700
|
-
if (source == null) continue;
|
|
30701
|
-
result = mergeTwo(result, source, /* @__PURE__ */ new Set(), 0);
|
|
30702
|
-
}
|
|
30703
|
-
return result;
|
|
30704
|
-
}
|
|
30705
|
-
function cloneDeep(obj, ancestors, depth) {
|
|
30706
|
-
if (depth > MAX_DEPTH) {
|
|
30707
|
-
throw new Error("Maximum merge depth exceeded");
|
|
30708
|
-
}
|
|
30709
|
-
if (ancestors.has(obj)) {
|
|
30710
|
-
throw new Error("Circular reference detected during deep merge");
|
|
30711
|
-
}
|
|
30712
|
-
ancestors.add(obj);
|
|
30713
|
-
const result = {};
|
|
30714
|
-
for (const key of Object.keys(obj)) {
|
|
30715
|
-
if (!isSafeKey(key)) continue;
|
|
30716
|
-
const value = obj[key];
|
|
30717
|
-
result[key] = isPlainObject(value) ? cloneDeep(value, ancestors, depth + 1) : value;
|
|
30718
|
-
}
|
|
30719
|
-
ancestors.delete(obj);
|
|
30720
|
-
return result;
|
|
30721
|
-
}
|
|
30722
|
-
function isPlainObject(value) {
|
|
30723
|
-
if (value === null || typeof value !== "object") return false;
|
|
30724
|
-
const proto = Object.getPrototypeOf(value);
|
|
30725
|
-
return proto === Object.prototype || proto === null;
|
|
30726
|
-
}
|
|
30727
|
-
function isSafeKey(key) {
|
|
30728
|
-
return !DANGEROUS_KEYS.has(key);
|
|
30729
|
-
}
|
|
30730
|
-
function mergeTwo(target, source, ancestors, depth) {
|
|
30731
|
-
if (depth > MAX_DEPTH) {
|
|
30732
|
-
throw new Error("Maximum merge depth exceeded");
|
|
30733
|
-
}
|
|
30734
|
-
if (ancestors.has(source)) {
|
|
30735
|
-
throw new Error("Circular reference detected during deep merge");
|
|
30736
|
-
}
|
|
30737
|
-
ancestors.add(source);
|
|
30738
|
-
for (const key of Object.keys(source)) {
|
|
30739
|
-
if (!isSafeKey(key)) continue;
|
|
30740
|
-
const sourceValue = source[key];
|
|
30741
|
-
const targetValue = target[key];
|
|
30742
|
-
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
30743
|
-
const cloned = cloneDeep(targetValue, /* @__PURE__ */ new Set(), depth + 1);
|
|
30744
|
-
target[key] = mergeTwo(cloned, sourceValue, ancestors, depth + 1);
|
|
30745
|
-
} else if (isPlainObject(sourceValue)) {
|
|
30746
|
-
target[key] = cloneDeep(sourceValue, /* @__PURE__ */ new Set(), depth + 1);
|
|
30747
|
-
} else {
|
|
30748
|
-
target[key] = sourceValue;
|
|
30749
|
-
}
|
|
30750
|
-
}
|
|
30751
|
-
ancestors.delete(source);
|
|
30752
|
-
return target;
|
|
30753
|
-
}
|
|
30754
|
-
var DANGEROUS_KEYS, MAX_DEPTH;
|
|
30755
|
-
var init_deep_merge = __esm({
|
|
30756
|
-
"src/deep-merge.ts"() {
|
|
30757
|
-
"use strict";
|
|
30758
|
-
DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
30759
|
-
MAX_DEPTH = 100;
|
|
30760
|
-
}
|
|
30761
|
-
});
|
|
30762
|
-
|
|
30763
30763
|
// src/strategy-utils.ts
|
|
30764
30764
|
function applyParameterOverrides(modelParams, options, sapModelParams, settingsModelParams, mappings) {
|
|
30765
30765
|
for (const mapping of mappings) {
|
|
@@ -30836,19 +30836,7 @@ function buildGenerateResult(config) {
|
|
|
30836
30836
|
modelId,
|
|
30837
30837
|
timestamp: /* @__PURE__ */ new Date()
|
|
30838
30838
|
},
|
|
30839
|
-
usage:
|
|
30840
|
-
inputTokens: {
|
|
30841
|
-
cacheRead: tokenUsage?.prompt_tokens_details?.cached_tokens,
|
|
30842
|
-
cacheWrite: void 0,
|
|
30843
|
-
noCache: tokenUsage?.prompt_tokens_details?.cached_tokens != null ? (tokenUsage.prompt_tokens ?? 0) - tokenUsage.prompt_tokens_details.cached_tokens : tokenUsage?.prompt_tokens,
|
|
30844
|
-
total: tokenUsage?.prompt_tokens
|
|
30845
|
-
},
|
|
30846
|
-
outputTokens: {
|
|
30847
|
-
reasoning: tokenUsage?.completion_tokens_details?.reasoning_tokens,
|
|
30848
|
-
text: tokenUsage?.completion_tokens_details?.reasoning_tokens != null ? (tokenUsage.completion_tokens ?? 0) - tokenUsage.completion_tokens_details.reasoning_tokens : tokenUsage?.completion_tokens,
|
|
30849
|
-
total: tokenUsage?.completion_tokens
|
|
30850
|
-
}
|
|
30851
|
-
},
|
|
30839
|
+
usage: mapTokenUsage(tokenUsage),
|
|
30852
30840
|
warnings
|
|
30853
30841
|
};
|
|
30854
30842
|
}
|
|
@@ -31078,12 +31066,9 @@ function createStreamTransformer(config) {
|
|
|
31078
31066
|
}
|
|
31079
31067
|
const finalUsage = streamResponseGetTokenUsage();
|
|
31080
31068
|
if (finalUsage) {
|
|
31081
|
-
|
|
31082
|
-
streamState.usage.inputTokens
|
|
31083
|
-
streamState.usage.
|
|
31084
|
-
streamState.usage.outputTokens.total = finalUsage.completion_tokens;
|
|
31085
|
-
streamState.usage.outputTokens.reasoning = finalUsage.completion_tokens_details?.reasoning_tokens;
|
|
31086
|
-
streamState.usage.outputTokens.text = finalUsage.completion_tokens_details?.reasoning_tokens != null ? (finalUsage.completion_tokens ?? 0) - finalUsage.completion_tokens_details.reasoning_tokens : finalUsage.completion_tokens;
|
|
31069
|
+
const mapped = mapTokenUsage(finalUsage);
|
|
31070
|
+
streamState.usage.inputTokens = mapped.inputTokens;
|
|
31071
|
+
streamState.usage.outputTokens = mapped.outputTokens;
|
|
31087
31072
|
}
|
|
31088
31073
|
const streamCitations = streamResponseGetCitations?.();
|
|
31089
31074
|
if (streamCitations?.length) {
|
|
@@ -31343,6 +31328,23 @@ function mapFinishReason(reason) {
|
|
|
31343
31328
|
return { raw, unified: "other" };
|
|
31344
31329
|
}
|
|
31345
31330
|
}
|
|
31331
|
+
function mapTokenUsage(tokenUsage) {
|
|
31332
|
+
const cachedTokens = tokenUsage?.prompt_tokens_details?.cached_tokens;
|
|
31333
|
+
const reasoningTokens = tokenUsage?.completion_tokens_details?.reasoning_tokens;
|
|
31334
|
+
return {
|
|
31335
|
+
inputTokens: {
|
|
31336
|
+
cacheRead: cachedTokens,
|
|
31337
|
+
cacheWrite: void 0,
|
|
31338
|
+
noCache: cachedTokens != null ? (tokenUsage?.prompt_tokens ?? 0) - cachedTokens : tokenUsage?.prompt_tokens,
|
|
31339
|
+
total: tokenUsage?.prompt_tokens
|
|
31340
|
+
},
|
|
31341
|
+
outputTokens: {
|
|
31342
|
+
reasoning: reasoningTokens,
|
|
31343
|
+
text: reasoningTokens != null ? (tokenUsage?.completion_tokens ?? 0) - reasoningTokens : tokenUsage?.completion_tokens,
|
|
31344
|
+
total: tokenUsage?.completion_tokens
|
|
31345
|
+
}
|
|
31346
|
+
};
|
|
31347
|
+
}
|
|
31346
31348
|
function mapToolChoice(toolChoice) {
|
|
31347
31349
|
if (!toolChoice) {
|
|
31348
31350
|
return void 0;
|
|
@@ -31433,7 +31435,7 @@ var VERSION;
|
|
|
31433
31435
|
var init_version = __esm({
|
|
31434
31436
|
"src/version.ts"() {
|
|
31435
31437
|
"use strict";
|
|
31436
|
-
VERSION = true ? "4.6.
|
|
31438
|
+
VERSION = true ? "4.6.1" : "0.0.0-test";
|
|
31437
31439
|
}
|
|
31438
31440
|
});
|
|
31439
31441
|
|
|
@@ -31442,6 +31444,7 @@ var BaseEmbeddingModelStrategy;
|
|
|
31442
31444
|
var init_base_embedding_model_strategy = __esm({
|
|
31443
31445
|
"src/base-embedding-model-strategy.ts"() {
|
|
31444
31446
|
"use strict";
|
|
31447
|
+
init_deep_merge();
|
|
31445
31448
|
init_sap_ai_error();
|
|
31446
31449
|
init_strategy_utils();
|
|
31447
31450
|
init_version();
|
|
@@ -31482,6 +31485,12 @@ var init_base_embedding_model_strategy = __esm({
|
|
|
31482
31485
|
});
|
|
31483
31486
|
}
|
|
31484
31487
|
}
|
|
31488
|
+
mergeModelParams(settings, embeddingOptions) {
|
|
31489
|
+
return deepMerge(
|
|
31490
|
+
settings.modelParams ?? {},
|
|
31491
|
+
embeddingOptions?.modelParams ?? {}
|
|
31492
|
+
);
|
|
31493
|
+
}
|
|
31485
31494
|
};
|
|
31486
31495
|
}
|
|
31487
31496
|
});
|
|
@@ -31496,7 +31505,6 @@ var init_foundation_models_embedding_model_strategy = __esm({
|
|
|
31496
31505
|
"src/foundation-models-embedding-model-strategy.ts"() {
|
|
31497
31506
|
"use strict";
|
|
31498
31507
|
init_base_embedding_model_strategy();
|
|
31499
|
-
init_deep_merge();
|
|
31500
31508
|
init_strategy_utils();
|
|
31501
31509
|
FoundationModelsEmbeddingModelStrategy = class extends BaseEmbeddingModelStrategy {
|
|
31502
31510
|
ClientClass;
|
|
@@ -31505,10 +31513,7 @@ var init_foundation_models_embedding_model_strategy = __esm({
|
|
|
31505
31513
|
this.ClientClass = ClientClass;
|
|
31506
31514
|
}
|
|
31507
31515
|
createClient(config, settings, embeddingOptions) {
|
|
31508
|
-
const mergedParams =
|
|
31509
|
-
settings.modelParams ?? {},
|
|
31510
|
-
embeddingOptions?.modelParams ?? {}
|
|
31511
|
-
);
|
|
31516
|
+
const mergedParams = this.mergeModelParams(settings, embeddingOptions);
|
|
31512
31517
|
return {
|
|
31513
31518
|
client: new this.ClientClass(
|
|
31514
31519
|
buildModelDeployment(config, settings.modelVersion),
|
|
@@ -31552,7 +31557,6 @@ var init_orchestration_embedding_model_strategy = __esm({
|
|
|
31552
31557
|
"src/orchestration-embedding-model-strategy.ts"() {
|
|
31553
31558
|
"use strict";
|
|
31554
31559
|
init_base_embedding_model_strategy();
|
|
31555
|
-
init_deep_merge();
|
|
31556
31560
|
init_strategy_utils();
|
|
31557
31561
|
OrchestrationEmbeddingModelStrategy = class extends BaseEmbeddingModelStrategy {
|
|
31558
31562
|
ClientClass;
|
|
@@ -31561,10 +31565,7 @@ var init_orchestration_embedding_model_strategy = __esm({
|
|
|
31561
31565
|
this.ClientClass = ClientClass;
|
|
31562
31566
|
}
|
|
31563
31567
|
createClient(config, settings, embeddingOptions) {
|
|
31564
|
-
const mergedParams =
|
|
31565
|
-
settings.modelParams ?? {},
|
|
31566
|
-
embeddingOptions?.modelParams ?? {}
|
|
31567
|
-
);
|
|
31568
|
+
const mergedParams = this.mergeModelParams(settings, embeddingOptions);
|
|
31568
31569
|
const embeddingConfig = {
|
|
31569
31570
|
model: {
|
|
31570
31571
|
name: config.modelId,
|
|
@@ -31803,7 +31804,7 @@ var init_foundation_models_language_model_strategy = __esm({
|
|
|
31803
31804
|
super();
|
|
31804
31805
|
this.ClientClass = ClientClass;
|
|
31805
31806
|
}
|
|
31806
|
-
buildRequest(
|
|
31807
|
+
buildRequest(_config, settings, options, commonParts) {
|
|
31807
31808
|
const warnings = [];
|
|
31808
31809
|
const toolsResult = convertToolsToSAPFormat(
|
|
31809
31810
|
options.tools
|