@jerome-benoit/sap-ai-provider 4.5.0 → 4.6.0
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-SC6SVJGO.js → chunk-BV5Y6RMC.js} +3 -3
- package/dist/{chunk-T2KXS7WW.js → chunk-DBAIFR3B.js} +2 -2
- package/dist/{chunk-SD6CRCHX.js → chunk-DQXZH6CW.js} +50 -43
- package/dist/chunk-DQXZH6CW.js.map +1 -0
- package/dist/{chunk-3VLXFYCM.js → chunk-KS5QNMYZ.js} +42 -8
- package/dist/chunk-KS5QNMYZ.js.map +1 -0
- package/dist/{chunk-NRLDO6VY.js → chunk-WYDTQDMJ.js} +6 -4
- package/dist/chunk-WYDTQDMJ.js.map +1 -0
- package/dist/{foundation-models-embedding-model-strategy-FO5RWBZ2.js → foundation-models-embedding-model-strategy-XLD3PGCK.js} +4 -4
- package/dist/{foundation-models-language-model-strategy-COZPNAJ3.js → foundation-models-language-model-strategy-SNBZBWX4.js} +5 -5
- package/dist/index.cjs +96 -49
- 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 +6 -6
- package/dist/index.js.map +1 -1
- package/dist/{orchestration-embedding-model-strategy-GEONA32Q.js → orchestration-embedding-model-strategy-6BKD5NW7.js} +4 -4
- package/dist/{orchestration-language-model-strategy-PZBP7G5O.js → orchestration-language-model-strategy-OYSEPGQG.js} +9 -5
- package/dist/orchestration-language-model-strategy-OYSEPGQG.js.map +1 -0
- package/package.json +14 -14
- package/dist/chunk-3VLXFYCM.js.map +0 -1
- package/dist/chunk-NRLDO6VY.js.map +0 -1
- package/dist/chunk-SD6CRCHX.js.map +0 -1
- package/dist/orchestration-language-model-strategy-PZBP7G5O.js.map +0 -1
- /package/dist/{chunk-SC6SVJGO.js.map → chunk-BV5Y6RMC.js.map} +0 -0
- /package/dist/{chunk-T2KXS7WW.js.map → chunk-DBAIFR3B.js.map} +0 -0
- /package/dist/{foundation-models-embedding-model-strategy-FO5RWBZ2.js.map → foundation-models-embedding-model-strategy-XLD3PGCK.js.map} +0 -0
- /package/dist/{foundation-models-language-model-strategy-COZPNAJ3.js.map → foundation-models-language-model-strategy-SNBZBWX4.js.map} +0 -0
- /package/dist/{orchestration-embedding-model-strategy-GEONA32Q.js.map → orchestration-embedding-model-strategy-6BKD5NW7.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -122,51 +122,34 @@ function convertToSAPMessages(prompt, options = {}) {
|
|
|
122
122
|
for (const part of message.content) {
|
|
123
123
|
switch (part.type) {
|
|
124
124
|
case "file": {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
const fileDataUrl = buildDataUrl(part);
|
|
126
|
+
if (part.mediaType.startsWith("image/")) {
|
|
127
|
+
const supportedFormats = [
|
|
128
|
+
"image/png",
|
|
129
|
+
"image/jpeg",
|
|
130
|
+
"image/jpg",
|
|
131
|
+
"image/gif",
|
|
132
|
+
"image/webp"
|
|
133
|
+
];
|
|
134
|
+
if (!supportedFormats.includes(part.mediaType.toLowerCase())) {
|
|
135
|
+
console.warn(
|
|
136
|
+
`Image format ${part.mediaType} may not be supported by all models. Recommended formats: PNG, JPEG, GIF, WebP`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
contentParts.push({
|
|
140
|
+
image_url: {
|
|
141
|
+
url: fileDataUrl
|
|
142
|
+
},
|
|
143
|
+
type: "image_url"
|
|
128
144
|
});
|
|
129
|
-
}
|
|
130
|
-
const supportedFormats = [
|
|
131
|
-
"image/png",
|
|
132
|
-
"image/jpeg",
|
|
133
|
-
"image/jpg",
|
|
134
|
-
"image/gif",
|
|
135
|
-
"image/webp"
|
|
136
|
-
];
|
|
137
|
-
if (!supportedFormats.includes(part.mediaType.toLowerCase())) {
|
|
138
|
-
console.warn(
|
|
139
|
-
`Image format ${part.mediaType} may not be supported by all models. Recommended formats: PNG, JPEG, GIF, WebP`
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
let imageUrl;
|
|
143
|
-
if (part.data instanceof URL) {
|
|
144
|
-
imageUrl = part.data.toString();
|
|
145
|
-
} else if (typeof part.data === "string") {
|
|
146
|
-
imageUrl = `data:${part.mediaType};base64,${part.data}`;
|
|
147
|
-
} else if (part.data instanceof Uint8Array) {
|
|
148
|
-
const base64Data = import_node_buffer.Buffer.from(part.data).toString("base64");
|
|
149
|
-
imageUrl = `data:${part.mediaType};base64,${base64Data}`;
|
|
150
|
-
} else if (import_node_buffer.Buffer.isBuffer(part.data)) {
|
|
151
|
-
const base64Data = import_node_buffer.Buffer.from(part.data).toString("base64");
|
|
152
|
-
imageUrl = `data:${part.mediaType};base64,${base64Data}`;
|
|
153
145
|
} else {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
functionality: "Unsupported file data type for image. Expected URL, base64 string, or Uint8Array."
|
|
161
|
-
});
|
|
162
|
-
}
|
|
146
|
+
contentParts.push({
|
|
147
|
+
file: {
|
|
148
|
+
file_data: fileDataUrl
|
|
149
|
+
},
|
|
150
|
+
type: "file"
|
|
151
|
+
});
|
|
163
152
|
}
|
|
164
|
-
contentParts.push({
|
|
165
|
-
image_url: {
|
|
166
|
-
url: imageUrl
|
|
167
|
-
},
|
|
168
|
-
type: "image_url"
|
|
169
|
-
});
|
|
170
153
|
break;
|
|
171
154
|
}
|
|
172
155
|
case "text": {
|
|
@@ -213,6 +196,30 @@ function unescapeOrchestrationPlaceholders(text) {
|
|
|
213
196
|
if (!text) return text;
|
|
214
197
|
return text.replaceAll(JINJA2_DELIMITERS_ESCAPED_PATTERN, "{$1");
|
|
215
198
|
}
|
|
199
|
+
function buildDataUrl(part) {
|
|
200
|
+
if (part.data instanceof URL) {
|
|
201
|
+
return part.data.toString();
|
|
202
|
+
}
|
|
203
|
+
if (typeof part.data === "string") {
|
|
204
|
+
return `data:${part.mediaType};base64,${part.data}`;
|
|
205
|
+
}
|
|
206
|
+
if (part.data instanceof Uint8Array) {
|
|
207
|
+
const base64Data = import_node_buffer.Buffer.from(part.data).toString("base64");
|
|
208
|
+
return `data:${part.mediaType};base64,${base64Data}`;
|
|
209
|
+
}
|
|
210
|
+
if (import_node_buffer.Buffer.isBuffer(part.data)) {
|
|
211
|
+
const base64Data = import_node_buffer.Buffer.from(part.data).toString("base64");
|
|
212
|
+
return `data:${part.mediaType};base64,${base64Data}`;
|
|
213
|
+
}
|
|
214
|
+
const maybeBufferLike = part.data;
|
|
215
|
+
if (maybeBufferLike !== null && typeof maybeBufferLike === "object" && "toString" in maybeBufferLike) {
|
|
216
|
+
const base64Data = maybeBufferLike.toString("base64");
|
|
217
|
+
return `data:${part.mediaType};base64,${base64Data}`;
|
|
218
|
+
}
|
|
219
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
220
|
+
functionality: "Unsupported file data type. Expected URL, base64 string, or Uint8Array."
|
|
221
|
+
});
|
|
222
|
+
}
|
|
216
223
|
var import_provider, import_node_buffer, ZERO_WIDTH_SPACE, JINJA2_DELIMITERS_PATTERN, JINJA2_DELIMITERS_ESCAPED_PATTERN;
|
|
217
224
|
var init_convert_to_sap_messages = __esm({
|
|
218
225
|
"src/convert-to-sap-messages.ts"() {
|
|
@@ -30794,6 +30801,19 @@ function buildGenerateResult(config) {
|
|
|
30794
30801
|
tokenUsage,
|
|
30795
30802
|
toolCalls
|
|
30796
30803
|
};
|
|
30804
|
+
const citations = response.getCitations?.();
|
|
30805
|
+
if (citations?.length) {
|
|
30806
|
+
for (const citation of citations) {
|
|
30807
|
+
content.push({
|
|
30808
|
+
id: String(citation.ref_id ?? citation.url),
|
|
30809
|
+
sourceType: "url",
|
|
30810
|
+
title: citation.title,
|
|
30811
|
+
type: "source",
|
|
30812
|
+
url: citation.url
|
|
30813
|
+
});
|
|
30814
|
+
}
|
|
30815
|
+
}
|
|
30816
|
+
const intermediateFailures = response.getIntermediateFailures?.();
|
|
30797
30817
|
return {
|
|
30798
30818
|
content,
|
|
30799
30819
|
finishReason,
|
|
@@ -30801,6 +30821,7 @@ function buildGenerateResult(config) {
|
|
|
30801
30821
|
[providerName]: {
|
|
30802
30822
|
finishReason: finishReasonRaw ?? "unknown",
|
|
30803
30823
|
finishReasonMapped: finishReason,
|
|
30824
|
+
...intermediateFailures?.length ? { intermediateFailures } : {},
|
|
30804
30825
|
...typeof responseHeaders?.["x-request-id"] === "string" ? { requestId: responseHeaders["x-request-id"] } : {},
|
|
30805
30826
|
version: version2
|
|
30806
30827
|
}
|
|
@@ -30817,14 +30838,14 @@ function buildGenerateResult(config) {
|
|
|
30817
30838
|
},
|
|
30818
30839
|
usage: {
|
|
30819
30840
|
inputTokens: {
|
|
30820
|
-
cacheRead:
|
|
30841
|
+
cacheRead: tokenUsage?.prompt_tokens_details?.cached_tokens,
|
|
30821
30842
|
cacheWrite: void 0,
|
|
30822
|
-
noCache: tokenUsage?.prompt_tokens,
|
|
30843
|
+
noCache: tokenUsage?.prompt_tokens_details?.cached_tokens != null ? (tokenUsage.prompt_tokens ?? 0) - tokenUsage.prompt_tokens_details.cached_tokens : tokenUsage?.prompt_tokens,
|
|
30823
30844
|
total: tokenUsage?.prompt_tokens
|
|
30824
30845
|
},
|
|
30825
30846
|
outputTokens: {
|
|
30826
|
-
reasoning:
|
|
30827
|
-
text: tokenUsage?.completion_tokens,
|
|
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,
|
|
30828
30849
|
total: tokenUsage?.completion_tokens
|
|
30829
30850
|
}
|
|
30830
30851
|
},
|
|
@@ -31003,7 +31024,9 @@ function createStreamTransformer(config) {
|
|
|
31003
31024
|
responseHeaders,
|
|
31004
31025
|
responseId,
|
|
31005
31026
|
sdkStream,
|
|
31027
|
+
streamResponseGetCitations,
|
|
31006
31028
|
streamResponseGetFinishReason,
|
|
31029
|
+
streamResponseGetIntermediateFailures,
|
|
31007
31030
|
streamResponseGetTokenUsage,
|
|
31008
31031
|
url,
|
|
31009
31032
|
version: version2,
|
|
@@ -31056,15 +31079,33 @@ function createStreamTransformer(config) {
|
|
|
31056
31079
|
const finalUsage = streamResponseGetTokenUsage();
|
|
31057
31080
|
if (finalUsage) {
|
|
31058
31081
|
streamState.usage.inputTokens.total = finalUsage.prompt_tokens;
|
|
31059
|
-
streamState.usage.inputTokens.
|
|
31082
|
+
streamState.usage.inputTokens.cacheRead = finalUsage.prompt_tokens_details?.cached_tokens;
|
|
31083
|
+
streamState.usage.inputTokens.noCache = finalUsage.prompt_tokens_details?.cached_tokens != null ? (finalUsage.prompt_tokens ?? 0) - finalUsage.prompt_tokens_details.cached_tokens : finalUsage.prompt_tokens;
|
|
31060
31084
|
streamState.usage.outputTokens.total = finalUsage.completion_tokens;
|
|
31061
|
-
streamState.usage.outputTokens.
|
|
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;
|
|
31062
31087
|
}
|
|
31088
|
+
const streamCitations = streamResponseGetCitations?.();
|
|
31089
|
+
if (streamCitations?.length) {
|
|
31090
|
+
for (const citation of streamCitations) {
|
|
31091
|
+
controller.enqueue({
|
|
31092
|
+
id: String(citation.ref_id ?? citation.url),
|
|
31093
|
+
sourceType: "url",
|
|
31094
|
+
title: citation.title,
|
|
31095
|
+
type: "source",
|
|
31096
|
+
url: citation.url
|
|
31097
|
+
});
|
|
31098
|
+
}
|
|
31099
|
+
}
|
|
31100
|
+
const streamIntermediateFailures = streamResponseGetIntermediateFailures?.();
|
|
31063
31101
|
controller.enqueue({
|
|
31064
31102
|
finishReason: streamState.finishReason,
|
|
31065
31103
|
providerMetadata: {
|
|
31066
31104
|
[providerName]: {
|
|
31067
31105
|
finishReason: streamState.finishReason.raw,
|
|
31106
|
+
...streamIntermediateFailures?.length ? {
|
|
31107
|
+
intermediateFailures: streamIntermediateFailures
|
|
31108
|
+
} : {},
|
|
31068
31109
|
...typeof responseHeaders?.["x-request-id"] === "string" ? { requestId: responseHeaders["x-request-id"] } : {},
|
|
31069
31110
|
responseId,
|
|
31070
31111
|
version: version2
|
|
@@ -31392,7 +31433,7 @@ var VERSION;
|
|
|
31392
31433
|
var init_version = __esm({
|
|
31393
31434
|
"src/version.ts"() {
|
|
31394
31435
|
"use strict";
|
|
31395
|
-
VERSION = true ? "4.
|
|
31436
|
+
VERSION = true ? "4.6.0" : "0.0.0-test";
|
|
31396
31437
|
}
|
|
31397
31438
|
});
|
|
31398
31439
|
|
|
@@ -31639,7 +31680,9 @@ var init_base_language_model_strategy = __esm({
|
|
|
31639
31680
|
responseHeaders: streamResponse.responseHeaders,
|
|
31640
31681
|
responseId,
|
|
31641
31682
|
sdkStream: streamResponse.stream,
|
|
31683
|
+
streamResponseGetCitations: streamResponse.getCitations,
|
|
31642
31684
|
streamResponseGetFinishReason: streamResponse.getFinishReason,
|
|
31685
|
+
streamResponseGetIntermediateFailures: streamResponse.getIntermediateFailures,
|
|
31643
31686
|
streamResponseGetTokenUsage: streamResponse.getTokenUsage,
|
|
31644
31687
|
url: this.getUrl(),
|
|
31645
31688
|
version: VERSION,
|
|
@@ -32005,8 +32048,10 @@ var init_orchestration_language_model_strategy = __esm({
|
|
|
32005
32048
|
);
|
|
32006
32049
|
const completionId = response._data?.final_result?.id ?? response.getRequestId();
|
|
32007
32050
|
return {
|
|
32051
|
+
getCitations: () => response.getCitations?.(),
|
|
32008
32052
|
getContent: () => response.getContent(),
|
|
32009
32053
|
getFinishReason: () => response.getFinishReason(),
|
|
32054
|
+
getIntermediateFailures: () => response.getIntermediateFailures?.(),
|
|
32010
32055
|
getTokenUsage: () => response.getTokenUsage(),
|
|
32011
32056
|
getToolCalls: () => response.getToolCalls(),
|
|
32012
32057
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- SAP SDK types headers as any
|
|
@@ -32019,7 +32064,9 @@ var init_orchestration_language_model_strategy = __esm({
|
|
|
32019
32064
|
const streamResponse = await client.stream(request, abortSignal, sdkStreamOptions);
|
|
32020
32065
|
const streamCompletionId = streamResponse._data?.final_result?.id;
|
|
32021
32066
|
return {
|
|
32067
|
+
getCitations: () => streamResponse.getCitations?.(),
|
|
32022
32068
|
getFinishReason: () => streamResponse.getFinishReason(),
|
|
32069
|
+
getIntermediateFailures: () => streamResponse.getIntermediateFailures?.(),
|
|
32023
32070
|
getTokenUsage: () => streamResponse.getTokenUsage(),
|
|
32024
32071
|
responseHeaders: normalizeHeaders(streamResponse.rawResponse.headers),
|
|
32025
32072
|
responseId: streamCompletionId,
|