@jerome-benoit/sap-ai-provider-v2 4.2.3 → 4.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -29752,7 +29752,6 @@ __export(index_exports, {
29752
29752
  buildTranslationConfig: () => import_orchestration3.buildTranslationConfig,
29753
29753
  createSAPAIProvider: () => createSAPAIProvider,
29754
29754
  getProviderName: () => getProviderName,
29755
- isConfigReference: () => import_orchestration3.isConfigReference,
29756
29755
  sapAIEmbeddingProviderOptions: () => sapAIEmbeddingProviderOptions,
29757
29756
  sapAILanguageModelProviderOptions: () => sapAILanguageModelProviderOptions,
29758
29757
  sapai: () => sapai
@@ -30004,46 +30003,45 @@ function convertToAISDKError(error, context) {
30004
30003
  });
30005
30004
  }
30006
30005
  }
30007
- const responseHeaders = context?.responseHeaders ?? getAxiosResponseHeaders(error);
30008
30006
  if (rootError instanceof Error) {
30009
30007
  const errorMsg = rootError.message.toLowerCase();
30010
- const originalMsg = rootError.message;
30008
+ const originalErrorMsg = rootError.message;
30011
30009
  if (errorMsg.includes("authentication") || errorMsg.includes("unauthorized") || errorMsg.includes("aicore_service_key") || errorMsg.includes("invalid credentials") || errorMsg.includes("service credentials") || errorMsg.includes("service binding")) {
30012
30010
  return new import_provider.LoadAPIKeyError({
30013
- message: `SAP AI Core authentication failed: ${originalMsg}
30011
+ message: `SAP AI Core authentication failed: ${originalErrorMsg}
30014
30012
 
30015
30013
  Make sure your AICORE_SERVICE_KEY environment variable is set correctly.
30016
30014
  See: https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-service-key`
30017
30015
  });
30018
30016
  }
30019
30017
  if (errorMsg.includes("econnrefused") || errorMsg.includes("enotfound") || errorMsg.includes("network") || errorMsg.includes("timeout")) {
30020
- return new import_provider.APICallError({
30021
- cause: error,
30022
- isRetryable: true,
30023
- message: `Network error connecting to SAP AI Core: ${originalMsg}`,
30024
- requestBodyValues: context?.requestBody,
30025
- responseHeaders,
30026
- statusCode: HTTP_STATUS.SERVICE_UNAVAILABLE,
30027
- url: context?.url ?? ""
30028
- });
30018
+ return createAPICallError(
30019
+ error,
30020
+ {
30021
+ isRetryable: true,
30022
+ message: `Network error connecting to SAP AI Core: ${originalErrorMsg}`,
30023
+ statusCode: HTTP_STATUS.SERVICE_UNAVAILABLE
30024
+ },
30025
+ context
30026
+ );
30029
30027
  }
30030
30028
  if (errorMsg.includes("could not resolve destination")) {
30031
- return new import_provider.APICallError({
30032
- cause: error,
30033
- isRetryable: false,
30034
- message: `SAP AI Core destination error: ${originalMsg}
30029
+ return createAPICallError(
30030
+ error,
30031
+ {
30032
+ isRetryable: false,
30033
+ message: `SAP AI Core destination error: ${originalErrorMsg}
30035
30034
 
30036
30035
  Check your destination configuration or provide a valid destinationName.`,
30037
- requestBodyValues: context?.requestBody,
30038
- responseHeaders,
30039
- statusCode: HTTP_STATUS.BAD_REQUEST,
30040
- url: context?.url ?? ""
30041
- });
30036
+ statusCode: HTTP_STATUS.BAD_REQUEST
30037
+ },
30038
+ context
30039
+ );
30042
30040
  }
30043
30041
  if (errorMsg.includes("failed to resolve deployment") || errorMsg.includes("no deployment matched")) {
30044
- const modelId = extractModelIdentifier(originalMsg);
30042
+ const modelId = extractModelIdentifier(originalErrorMsg);
30045
30043
  return new import_provider.NoSuchModelError({
30046
- message: `SAP AI Core deployment error: ${originalMsg}
30044
+ message: `SAP AI Core deployment error: ${originalErrorMsg}
30047
30045
 
30048
30046
  Make sure you have a running orchestration deployment in your AI Core instance.
30049
30047
  See: https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-orchestration`,
@@ -30052,129 +30050,165 @@ See: https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-depl
30052
30050
  });
30053
30051
  }
30054
30052
  if (errorMsg.includes("filtered by the output filter")) {
30055
- return new import_provider.APICallError({
30056
- cause: error,
30057
- isRetryable: false,
30058
- message: `Content was filtered: ${originalMsg}
30053
+ return createAPICallError(
30054
+ error,
30055
+ {
30056
+ isRetryable: false,
30057
+ message: `Content was filtered: ${originalErrorMsg}
30059
30058
 
30060
30059
  The model's response was blocked by content safety filters. Try a different prompt.`,
30061
- requestBodyValues: context?.requestBody,
30062
- responseHeaders,
30063
- statusCode: HTTP_STATUS.BAD_REQUEST,
30064
- url: context?.url ?? ""
30065
- });
30060
+ statusCode: HTTP_STATUS.BAD_REQUEST
30061
+ },
30062
+ context
30063
+ );
30066
30064
  }
30067
- const statusMatch = /status code (\d+)/i.exec(originalMsg);
30065
+ const statusMatch = /status code (\d+)/i.exec(originalErrorMsg);
30068
30066
  if (statusMatch) {
30069
30067
  const extractedStatus = Number.parseInt(statusMatch[1], 10);
30070
- return new import_provider.APICallError({
30071
- cause: error,
30072
- isRetryable: isRetryable(extractedStatus),
30073
- message: `SAP AI Core request failed: ${originalMsg}`,
30074
- requestBodyValues: context?.requestBody,
30075
- responseHeaders,
30076
- statusCode: extractedStatus,
30077
- url: context?.url ?? ""
30078
- });
30068
+ return createAPICallError(
30069
+ error,
30070
+ {
30071
+ isRetryable: isRetryable(extractedStatus),
30072
+ message: `SAP AI Core request failed: ${originalErrorMsg}`,
30073
+ statusCode: extractedStatus
30074
+ },
30075
+ context
30076
+ );
30079
30077
  }
30080
30078
  if (errorMsg.includes("consumed stream")) {
30081
- return new import_provider.APICallError({
30082
- cause: error,
30083
- isRetryable: false,
30084
- message: `SAP AI Core stream consumption error: ${originalMsg}`,
30085
- requestBodyValues: context?.requestBody,
30086
- responseHeaders,
30087
- statusCode: HTTP_STATUS.INTERNAL_ERROR,
30088
- url: context?.url ?? ""
30089
- });
30079
+ return createAPICallError(
30080
+ error,
30081
+ {
30082
+ isRetryable: false,
30083
+ message: `SAP AI Core stream consumption error: ${originalErrorMsg}`,
30084
+ statusCode: HTTP_STATUS.INTERNAL_ERROR
30085
+ },
30086
+ context
30087
+ );
30090
30088
  }
30091
30089
  if (errorMsg.includes("iterating over") || errorMsg.includes("parse message into json") || errorMsg.includes("received from") || errorMsg.includes("no body") || errorMsg.includes("invalid sse payload")) {
30092
- return new import_provider.APICallError({
30093
- cause: error,
30094
- isRetryable: true,
30095
- message: `SAP AI Core streaming error: ${originalMsg}`,
30096
- requestBodyValues: context?.requestBody,
30097
- responseHeaders,
30098
- statusCode: HTTP_STATUS.INTERNAL_ERROR,
30099
- url: context?.url ?? ""
30100
- });
30090
+ return createAPICallError(
30091
+ error,
30092
+ {
30093
+ isRetryable: true,
30094
+ message: `SAP AI Core streaming error: ${originalErrorMsg}`,
30095
+ statusCode: HTTP_STATUS.INTERNAL_ERROR
30096
+ },
30097
+ context
30098
+ );
30101
30099
  }
30102
30100
  if (errorMsg.includes("prompt template or messages must be defined") || errorMsg.includes("filtering parameters cannot be empty") || errorMsg.includes("templating yaml string must be non-empty") || errorMsg.includes("could not access response data") || errorMsg.includes("could not parse json") || errorMsg.includes("error parsing yaml") || errorMsg.includes("yaml does not conform") || errorMsg.includes("validation errors")) {
30103
- return new import_provider.APICallError({
30104
- cause: error,
30105
- isRetryable: false,
30106
- message: `SAP AI Core configuration error: ${originalMsg}`,
30107
- requestBodyValues: context?.requestBody,
30108
- responseHeaders,
30109
- statusCode: HTTP_STATUS.BAD_REQUEST,
30110
- url: context?.url ?? ""
30111
- });
30101
+ return createAPICallError(
30102
+ error,
30103
+ {
30104
+ isRetryable: false,
30105
+ message: `SAP AI Core configuration error: ${originalErrorMsg}`,
30106
+ statusCode: HTTP_STATUS.BAD_REQUEST
30107
+ },
30108
+ context
30109
+ );
30112
30110
  }
30113
30111
  if (errorMsg.includes("buffer is not available as globals")) {
30114
- return new import_provider.APICallError({
30115
- cause: error,
30116
- isRetryable: false,
30117
- message: `SAP AI Core environment error: ${originalMsg}`,
30118
- requestBodyValues: context?.requestBody,
30119
- responseHeaders,
30120
- statusCode: HTTP_STATUS.INTERNAL_ERROR,
30121
- url: context?.url ?? ""
30122
- });
30112
+ return createAPICallError(
30113
+ error,
30114
+ {
30115
+ isRetryable: false,
30116
+ message: `SAP AI Core environment error: ${originalErrorMsg}`,
30117
+ statusCode: HTTP_STATUS.INTERNAL_ERROR
30118
+ },
30119
+ context
30120
+ );
30123
30121
  }
30124
30122
  if (errorMsg.includes("response stream is undefined")) {
30125
- return new import_provider.APICallError({
30126
- cause: error,
30127
- isRetryable: false,
30128
- message: `SAP AI Core response stream error: ${originalMsg}`,
30129
- requestBodyValues: context?.requestBody,
30130
- responseHeaders,
30131
- statusCode: HTTP_STATUS.INTERNAL_ERROR,
30132
- url: context?.url ?? ""
30133
- });
30123
+ return createAPICallError(
30124
+ error,
30125
+ {
30126
+ isRetryable: false,
30127
+ message: `SAP AI Core response stream error: ${originalErrorMsg}`,
30128
+ statusCode: HTTP_STATUS.INTERNAL_ERROR
30129
+ },
30130
+ context
30131
+ );
30134
30132
  }
30135
30133
  if (errorMsg.includes("response is required to process") || errorMsg.includes("stream is still open") || errorMsg.includes("data is not available yet")) {
30136
- return new import_provider.APICallError({
30137
- cause: error,
30138
- isRetryable: true,
30139
- message: `SAP AI Core response processing error: ${originalMsg}`,
30140
- requestBodyValues: context?.requestBody,
30141
- responseHeaders,
30142
- statusCode: HTTP_STATUS.INTERNAL_ERROR,
30143
- url: context?.url ?? ""
30144
- });
30134
+ return createAPICallError(
30135
+ error,
30136
+ {
30137
+ isRetryable: true,
30138
+ message: `SAP AI Core response processing error: ${originalErrorMsg}`,
30139
+ statusCode: HTTP_STATUS.INTERNAL_ERROR
30140
+ },
30141
+ context
30142
+ );
30145
30143
  }
30146
30144
  if (errorMsg.includes("failed to fetch the list of deployments")) {
30147
- return new import_provider.APICallError({
30148
- cause: error,
30149
- isRetryable: true,
30150
- message: `SAP AI Core deployment retrieval error: ${originalMsg}`,
30151
- requestBodyValues: context?.requestBody,
30152
- responseHeaders,
30153
- statusCode: HTTP_STATUS.SERVICE_UNAVAILABLE,
30154
- url: context?.url ?? ""
30155
- });
30145
+ return createAPICallError(
30146
+ error,
30147
+ {
30148
+ isRetryable: true,
30149
+ message: `SAP AI Core deployment retrieval error: ${originalErrorMsg}`,
30150
+ statusCode: HTTP_STATUS.SERVICE_UNAVAILABLE
30151
+ },
30152
+ context
30153
+ );
30156
30154
  }
30157
30155
  if (errorMsg.includes("received non-uint8array")) {
30158
- return new import_provider.APICallError({
30159
- cause: error,
30160
- isRetryable: false,
30161
- message: `SAP AI Core stream buffer error: ${originalMsg}`,
30162
- requestBodyValues: context?.requestBody,
30163
- responseHeaders,
30164
- statusCode: HTTP_STATUS.INTERNAL_ERROR,
30165
- url: context?.url ?? ""
30166
- });
30156
+ return createAPICallError(
30157
+ error,
30158
+ {
30159
+ isRetryable: false,
30160
+ message: `SAP AI Core stream buffer error: ${originalErrorMsg}`,
30161
+ statusCode: HTTP_STATUS.INTERNAL_ERROR
30162
+ },
30163
+ context
30164
+ );
30167
30165
  }
30168
30166
  }
30169
30167
  const message = rootError instanceof Error ? rootError.message : typeof rootError === "string" ? rootError : "Unknown error occurred";
30170
30168
  const fullMessage = context?.operation ? `SAP AI Core ${context.operation} failed: ${message}` : `SAP AI Core error: ${message}`;
30169
+ return createAPICallError(
30170
+ error,
30171
+ {
30172
+ isRetryable: false,
30173
+ message: fullMessage,
30174
+ statusCode: HTTP_STATUS.INTERNAL_ERROR
30175
+ },
30176
+ context
30177
+ );
30178
+ }
30179
+ function normalizeHeaders(headers) {
30180
+ if (!headers || typeof headers !== "object") return void 0;
30181
+ const record = headers;
30182
+ const entries = Object.entries(record).flatMap(([key, value]) => {
30183
+ if (typeof value === "string") return [[key, value]];
30184
+ if (Array.isArray(value)) {
30185
+ const strings = value.filter((item) => typeof item === "string").join("; ");
30186
+ return strings.length > 0 ? [[key, strings]] : [];
30187
+ }
30188
+ if (typeof value === "number" || typeof value === "boolean") {
30189
+ return [[key, String(value)]];
30190
+ }
30191
+ return [];
30192
+ });
30193
+ if (entries.length === 0) return void 0;
30194
+ return Object.fromEntries(entries);
30195
+ }
30196
+ function createAPICallError(error, options, context) {
30197
+ const responseBody = getAxiosResponseBody(error);
30198
+ const responseHeaders = context?.responseHeaders ?? getAxiosResponseHeaders(error);
30199
+ const enrichMessage = options.enrichMessage ?? true;
30200
+ const message = enrichMessage && responseBody ? `${options.message}
30201
+
30202
+ SAP AI Core Error Response:
30203
+ ${responseBody}` : options.message;
30171
30204
  return new import_provider.APICallError({
30172
30205
  cause: error,
30173
- isRetryable: false,
30174
- message: fullMessage,
30206
+ isRetryable: options.isRetryable,
30207
+ message,
30175
30208
  requestBodyValues: context?.requestBody,
30209
+ responseBody,
30176
30210
  responseHeaders,
30177
- statusCode: HTTP_STATUS.INTERNAL_ERROR,
30211
+ statusCode: options.statusCode,
30178
30212
  url: context?.url ?? ""
30179
30213
  });
30180
30214
  }
@@ -30198,13 +30232,23 @@ function extractModelIdentifier(message, location) {
30198
30232
  }
30199
30233
  return void 0;
30200
30234
  }
30201
- function getAxiosResponseHeaders(error) {
30235
+ function getAxiosError(error) {
30202
30236
  if (!(error instanceof Error)) return void 0;
30203
30237
  const rootCause = (0, import_util.isErrorWithCause)(error) ? error.rootCause : error;
30204
- if (typeof rootCause !== "object") return void 0;
30238
+ if (typeof rootCause !== "object" || rootCause === null) return void 0;
30205
30239
  const maybeAxios = rootCause;
30206
30240
  if (maybeAxios.isAxiosError !== true) return void 0;
30207
- return normalizeHeaders(maybeAxios.response?.headers);
30241
+ return maybeAxios;
30242
+ }
30243
+ function getAxiosResponseBody(error) {
30244
+ const axiosError = getAxiosError(error);
30245
+ if (!axiosError?.response?.data) return void 0;
30246
+ return serializeAxiosResponseData(axiosError.response.data);
30247
+ }
30248
+ function getAxiosResponseHeaders(error) {
30249
+ const axiosError = getAxiosError(error);
30250
+ if (!axiosError) return void 0;
30251
+ return normalizeHeaders(axiosError.response?.headers);
30208
30252
  }
30209
30253
  function getStatusCodeFromSAPError(code) {
30210
30254
  if (!code) return HTTP_STATUS.INTERNAL_ERROR;
@@ -30250,22 +30294,22 @@ function isOrchestrationErrorResponse(error) {
30250
30294
  function isRetryable(statusCode) {
30251
30295
  return statusCode === HTTP_STATUS.REQUEST_TIMEOUT || statusCode === HTTP_STATUS.CONFLICT || statusCode === HTTP_STATUS.RATE_LIMIT || statusCode >= HTTP_STATUS.INTERNAL_ERROR && statusCode < 600;
30252
30296
  }
30253
- function normalizeHeaders(headers) {
30254
- if (!headers || typeof headers !== "object") return void 0;
30255
- const record = headers;
30256
- const entries = Object.entries(record).flatMap(([key, value]) => {
30257
- if (typeof value === "string") return [[key, value]];
30258
- if (Array.isArray(value)) {
30259
- const strings = value.filter((item) => typeof item === "string").join("; ");
30260
- return strings.length > 0 ? [[key, strings]] : [];
30261
- }
30262
- if (typeof value === "number" || typeof value === "boolean") {
30263
- return [[key, String(value)]];
30297
+ function serializeAxiosResponseData(data, maxLength = 2e3) {
30298
+ if (data === void 0) return void 0;
30299
+ let serialized;
30300
+ try {
30301
+ if (typeof data === "string") {
30302
+ serialized = data;
30303
+ } else {
30304
+ serialized = JSON.stringify(data, null, 2);
30264
30305
  }
30265
- return [];
30266
- });
30267
- if (entries.length === 0) return void 0;
30268
- return Object.fromEntries(entries);
30306
+ } catch {
30307
+ serialized = `[Unable to serialize: ${typeof data}]`;
30308
+ }
30309
+ if (serialized.length > maxLength) {
30310
+ return serialized.slice(0, maxLength) + "...[truncated]";
30311
+ }
30312
+ return serialized;
30269
30313
  }
30270
30314
  function tryExtractSAPErrorFromMessage(message) {
30271
30315
  const jsonMatch = /\{[\s\S]*\}/.exec(message);
@@ -30376,7 +30420,7 @@ var SAPAIEmbeddingModel = class {
30376
30420
  *
30377
30421
  * This is the main implementation that handles all SAP AI Core embedding logic.
30378
30422
  * @param modelId - The model identifier (e.g., 'text-embedding-ada-002', 'text-embedding-3-small').
30379
- * @param settings - Model configuration settings (embedding type, model parameters, etc.). Defaults to {}.
30423
+ * @param settings - Model configuration settings (embedding type, model parameters, etc.).
30380
30424
  * @param config - SAP AI Core deployment and destination configuration.
30381
30425
  */
30382
30426
  constructor(modelId, settings = {}, config) {
@@ -30736,6 +30780,20 @@ function convertToSAPMessages(prompt, options = {}) {
30736
30780
  }
30737
30781
 
30738
30782
  // src/sap-ai-language-model.ts
30783
+ var PARAM_MAPPINGS = [
30784
+ { camelCaseKey: "maxTokens", optionKey: "maxOutputTokens", outputKey: "max_tokens" },
30785
+ { camelCaseKey: "temperature", optionKey: "temperature", outputKey: "temperature" },
30786
+ { camelCaseKey: "topP", optionKey: "topP", outputKey: "top_p" },
30787
+ { camelCaseKey: "topK", optionKey: "topK", outputKey: "top_k" },
30788
+ {
30789
+ camelCaseKey: "frequencyPenalty",
30790
+ optionKey: "frequencyPenalty",
30791
+ outputKey: "frequency_penalty"
30792
+ },
30793
+ { camelCaseKey: "presencePenalty", optionKey: "presencePenalty", outputKey: "presence_penalty" },
30794
+ { camelCaseKey: "seed", optionKey: "seed", outputKey: "seed" },
30795
+ { camelCaseKey: "parallel_tool_calls", outputKey: "parallel_tool_calls" }
30796
+ ];
30739
30797
  var StreamIdGenerator = class {
30740
30798
  generateResponseId() {
30741
30799
  return crypto.randomUUID();
@@ -30811,49 +30869,12 @@ var SAPAILanguageModel = class {
30811
30869
  try {
30812
30870
  const { messages, orchestrationConfig, warnings } = await this.buildOrchestrationConfig(options);
30813
30871
  const client = this.createClient(orchestrationConfig);
30814
- const promptTemplating = orchestrationConfig.promptTemplating;
30815
- const requestBody = {
30816
- messages,
30817
- model: {
30818
- ...orchestrationConfig.promptTemplating.model
30819
- },
30820
- ...promptTemplating.prompt.tools ? { tools: promptTemplating.prompt.tools } : {},
30821
- ...promptTemplating.prompt.response_format ? { response_format: promptTemplating.prompt.response_format } : {},
30822
- ...(() => {
30823
- const masking = orchestrationConfig.masking;
30824
- return masking && Object.keys(masking).length > 0 ? { masking } : {};
30825
- })(),
30826
- ...(() => {
30827
- const filtering = orchestrationConfig.filtering;
30828
- return filtering && Object.keys(filtering).length > 0 ? { filtering } : {};
30829
- })(),
30830
- ...(() => {
30831
- const grounding = orchestrationConfig.grounding;
30832
- return grounding && Object.keys(grounding).length > 0 ? { grounding } : {};
30833
- })(),
30834
- ...(() => {
30835
- const translation = orchestrationConfig.translation;
30836
- return translation && Object.keys(translation).length > 0 ? { translation } : {};
30837
- })()
30838
- };
30872
+ const requestBody = this.buildRequestBody(messages, orchestrationConfig);
30839
30873
  const response = await client.chatCompletion(
30840
30874
  requestBody,
30841
30875
  options.abortSignal ? { signal: options.abortSignal } : void 0
30842
30876
  );
30843
- const responseHeadersRaw = response.rawResponse.headers;
30844
- const responseHeaders = responseHeadersRaw ? Object.fromEntries(
30845
- Object.entries(responseHeadersRaw).flatMap(([key, value]) => {
30846
- if (typeof value === "string") return [[key, value]];
30847
- if (Array.isArray(value)) {
30848
- const strings = value.filter((item) => typeof item === "string").join("; ");
30849
- return strings.length > 0 ? [[key, strings]] : [];
30850
- }
30851
- if (typeof value === "number" || typeof value === "boolean") {
30852
- return [[key, String(value)]];
30853
- }
30854
- return [];
30855
- })
30856
- ) : void 0;
30877
+ const responseHeaders = normalizeHeaders(response.rawResponse.headers);
30857
30878
  const content = [];
30858
30879
  const textContent = response.getContent();
30859
30880
  if (textContent) {
@@ -30938,23 +30959,7 @@ var SAPAILanguageModel = class {
30938
30959
  try {
30939
30960
  const { messages, orchestrationConfig, warnings } = await this.buildOrchestrationConfig(options);
30940
30961
  const client = this.createClient(orchestrationConfig);
30941
- const promptTemplating = orchestrationConfig.promptTemplating;
30942
- const requestBody = {
30943
- messages,
30944
- model: {
30945
- ...orchestrationConfig.promptTemplating.model
30946
- },
30947
- ...promptTemplating.prompt.tools ? { tools: promptTemplating.prompt.tools } : {},
30948
- ...promptTemplating.prompt.response_format ? { response_format: promptTemplating.prompt.response_format } : {},
30949
- ...(() => {
30950
- const masking = orchestrationConfig.masking;
30951
- return masking && Object.keys(masking).length > 0 ? { masking } : {};
30952
- })(),
30953
- ...(() => {
30954
- const filtering = orchestrationConfig.filtering;
30955
- return filtering && Object.keys(filtering).length > 0 ? { filtering } : {};
30956
- })()
30957
- };
30962
+ const requestBody = this.buildRequestBody(messages, orchestrationConfig);
30958
30963
  const streamResponse = await client.stream(requestBody, options.abortSignal, {
30959
30964
  promptTemplating: { include_usage: true }
30960
30965
  });
@@ -31309,20 +31314,14 @@ var SAPAILanguageModel = class {
31309
31314
  this.settings.modelParams ?? {},
31310
31315
  sapOptions?.modelParams ?? {}
31311
31316
  );
31312
- const maxTokens = options.maxOutputTokens ?? sapOptions?.modelParams?.maxTokens ?? this.settings.modelParams?.maxTokens;
31313
- if (maxTokens !== void 0) modelParams.max_tokens = maxTokens;
31314
- const temperature = options.temperature ?? sapOptions?.modelParams?.temperature ?? this.settings.modelParams?.temperature;
31315
- if (temperature !== void 0) modelParams.temperature = temperature;
31316
- const topP = options.topP ?? sapOptions?.modelParams?.topP ?? this.settings.modelParams?.topP;
31317
- if (topP !== void 0) modelParams.top_p = topP;
31318
- if (options.topK !== void 0) modelParams.top_k = options.topK;
31319
- const frequencyPenalty = options.frequencyPenalty ?? sapOptions?.modelParams?.frequencyPenalty ?? this.settings.modelParams?.frequencyPenalty;
31320
- if (frequencyPenalty !== void 0) {
31321
- modelParams.frequency_penalty = frequencyPenalty;
31322
- }
31323
- const presencePenalty = options.presencePenalty ?? sapOptions?.modelParams?.presencePenalty ?? this.settings.modelParams?.presencePenalty;
31324
- if (presencePenalty !== void 0) {
31325
- modelParams.presence_penalty = presencePenalty;
31317
+ applyParameterOverrides(
31318
+ modelParams,
31319
+ options,
31320
+ sapOptions?.modelParams,
31321
+ this.settings.modelParams
31322
+ );
31323
+ if (options.stopSequences && options.stopSequences.length > 0) {
31324
+ modelParams.stop = options.stopSequences;
31326
31325
  }
31327
31326
  if (supportsN) {
31328
31327
  const nValue = sapOptions?.modelParams?.n ?? this.settings.modelParams?.n;
@@ -31332,16 +31331,6 @@ var SAPAILanguageModel = class {
31332
31331
  } else {
31333
31332
  delete modelParams.n;
31334
31333
  }
31335
- const parallelToolCalls = sapOptions?.modelParams?.parallel_tool_calls ?? this.settings.modelParams?.parallel_tool_calls;
31336
- if (parallelToolCalls !== void 0) {
31337
- modelParams.parallel_tool_calls = parallelToolCalls;
31338
- }
31339
- if (options.stopSequences && options.stopSequences.length > 0) {
31340
- modelParams.stop = options.stopSequences;
31341
- }
31342
- if (options.seed !== void 0) {
31343
- modelParams.seed = options.seed;
31344
- }
31345
31334
  validateModelParamsWithWarnings(
31346
31335
  {
31347
31336
  frequencyPenalty: options.frequencyPenalty,
@@ -31392,25 +31381,35 @@ var SAPAILanguageModel = class {
31392
31381
  ...responseFormat ? { response_format: responseFormat } : {}
31393
31382
  }
31394
31383
  },
31395
- ...(() => {
31396
- const masking = this.settings.masking;
31397
- return masking && Object.keys(masking).length > 0 ? { masking } : {};
31398
- })(),
31399
- ...(() => {
31400
- const filtering = this.settings.filtering;
31401
- return filtering && Object.keys(filtering).length > 0 ? { filtering } : {};
31402
- })(),
31403
- ...(() => {
31404
- const grounding = this.settings.grounding;
31405
- return grounding && Object.keys(grounding).length > 0 ? { grounding } : {};
31406
- })(),
31407
- ...(() => {
31408
- const translation = this.settings.translation;
31409
- return translation && Object.keys(translation).length > 0 ? { translation } : {};
31410
- })()
31384
+ ...this.settings.masking && Object.keys(this.settings.masking).length > 0 ? { masking: this.settings.masking } : {},
31385
+ ...this.settings.filtering && Object.keys(this.settings.filtering).length > 0 ? { filtering: this.settings.filtering } : {},
31386
+ ...this.settings.grounding && Object.keys(this.settings.grounding).length > 0 ? { grounding: this.settings.grounding } : {},
31387
+ ...this.settings.translation && Object.keys(this.settings.translation).length > 0 ? { translation: this.settings.translation } : {}
31411
31388
  };
31412
31389
  return { messages, orchestrationConfig, warnings };
31413
31390
  }
31391
+ /**
31392
+ * Builds the request body for SAP AI SDK chat completion or streaming.
31393
+ * @param messages - The chat messages to send.
31394
+ * @param orchestrationConfig - The orchestration configuration.
31395
+ * @returns The request body object.
31396
+ * @internal
31397
+ */
31398
+ buildRequestBody(messages, orchestrationConfig) {
31399
+ const promptTemplating = orchestrationConfig.promptTemplating;
31400
+ return {
31401
+ messages,
31402
+ model: {
31403
+ ...orchestrationConfig.promptTemplating.model
31404
+ },
31405
+ ...promptTemplating.prompt.tools ? { tools: promptTemplating.prompt.tools } : {},
31406
+ ...promptTemplating.prompt.response_format ? { response_format: promptTemplating.prompt.response_format } : {},
31407
+ ...orchestrationConfig.masking && Object.keys(orchestrationConfig.masking).length > 0 ? { masking: orchestrationConfig.masking } : {},
31408
+ ...orchestrationConfig.filtering && Object.keys(orchestrationConfig.filtering).length > 0 ? { filtering: orchestrationConfig.filtering } : {},
31409
+ ...orchestrationConfig.grounding && Object.keys(orchestrationConfig.grounding).length > 0 ? { grounding: orchestrationConfig.grounding } : {},
31410
+ ...orchestrationConfig.translation && Object.keys(orchestrationConfig.translation).length > 0 ? { translation: orchestrationConfig.translation } : {}
31411
+ };
31412
+ }
31414
31413
  /**
31415
31414
  * Creates an SAP AI SDK OrchestrationClient with the given configuration.
31416
31415
  * @param config - The SAP AI SDK orchestration module configuration.
@@ -31421,6 +31420,18 @@ var SAPAILanguageModel = class {
31421
31420
  return new import_orchestration2.OrchestrationClient(config, this.config.deploymentConfig, this.config.destination);
31422
31421
  }
31423
31422
  };
31423
+ function applyParameterOverrides(modelParams, options, sapModelParams, settingsModelParams) {
31424
+ const params = modelParams;
31425
+ for (const mapping of PARAM_MAPPINGS) {
31426
+ const value = (mapping.optionKey ? options[mapping.optionKey] : void 0) ?? (mapping.camelCaseKey ? sapModelParams?.[mapping.camelCaseKey] : void 0) ?? (mapping.camelCaseKey ? settingsModelParams?.[mapping.camelCaseKey] : void 0);
31427
+ if (value !== void 0) {
31428
+ params[mapping.outputKey] = value;
31429
+ }
31430
+ if (mapping.camelCaseKey && mapping.camelCaseKey !== mapping.outputKey) {
31431
+ Reflect.deleteProperty(params, mapping.camelCaseKey);
31432
+ }
31433
+ }
31434
+ }
31424
31435
  function buildSAPToolParameters(schema) {
31425
31436
  const schemaType = schema.type;
31426
31437
  if (schemaType !== void 0 && schemaType !== "object") {
@@ -31679,7 +31690,6 @@ var import_orchestration5 = require("@sap-ai-sdk/orchestration");
31679
31690
  buildTranslationConfig,
31680
31691
  createSAPAIProvider,
31681
31692
  getProviderName,
31682
- isConfigReference,
31683
31693
  sapAIEmbeddingProviderOptions,
31684
31694
  sapAILanguageModelProviderOptions,
31685
31695
  sapai