import {
  BaseLanguageModelStrategy
} from "./chunk-KO5GBKZB.js";
import "./chunk-G2BVB5LB.js";
import {
  buildModelDeployment,
  convertResponseFormat,
  convertToolsToSAPFormat
} from "./chunk-VSBPOUOR.js";
import "./chunk-7VLWN7WJ.js";

// src/foundation-models-language-model-strategy.ts
var FOUNDATION_MODELS_PARAM_MAPPINGS = [
  ...BaseLanguageModelStrategy.COMMON_PARAM_MAPPINGS,
  { camelCaseKey: "logprobs", outputKey: "logprobs" },
  { camelCaseKey: "topLogprobs", outputKey: "top_logprobs" },
  { camelCaseKey: "logitBias", outputKey: "logit_bias" },
  { camelCaseKey: "user", outputKey: "user" },
  { camelCaseKey: "n", outputKey: "n" }
];
var FoundationModelsLanguageModelStrategy = class extends BaseLanguageModelStrategy {
  ClientClass;
  constructor(ClientClass) {
    super();
    this.ClientClass = ClientClass;
  }
  buildRequest(config, settings, options, commonParts) {
    const warnings = [];
    const toolsResult = convertToolsToSAPFormat(
      options.tools
    );
    warnings.push(...toolsResult.warnings);
    const { responseFormat, warning: responseFormatWarning } = convertResponseFormat(
      options.responseFormat,
      settings.responseFormat
    );
    if (responseFormatWarning) {
      warnings.push(responseFormatWarning);
    }
    const { toolChoice } = commonParts;
    const request = {
      messages: commonParts.messages,
      ...commonParts.modelParams,
      ...toolsResult.tools?.length ? { tools: toolsResult.tools } : {},
      ...toolChoice ? { tool_choice: toolChoice } : {},
      ...responseFormat ? { response_format: responseFormat } : {},
      ...settings.dataSources?.length ? {
        data_sources: settings.dataSources
      } : {}
    };
    return { request, warnings };
  }
  createClient(config, settings, _commonParts) {
    const modelDeployment = buildModelDeployment(config, settings.modelVersion);
    return new this.ClientClass(modelDeployment, config.destination);
  }
  async executeApiCall(client, request, abortSignal) {
    const response = await client.run(request, abortSignal ? { signal: abortSignal } : void 0);
    return {
      getContent: () => response.getContent(),
      getFinishReason: () => response.getFinishReason(),
      getTokenUsage: () => response.getTokenUsage(),
      getToolCalls: () => response.getToolCalls(),
      // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- SAP SDK types headers as any
      rawResponse: { headers: response.rawResponse.headers }
    };
  }
  async executeStreamCall(client, request, abortSignal) {
    const streamResponse = await client.stream(request, abortSignal);
    return {
      getFinishReason: () => streamResponse.getFinishReason(),
      getTokenUsage: () => streamResponse.getTokenUsage(),
      stream: streamResponse.stream
    };
  }
  getParamMappings() {
    return FOUNDATION_MODELS_PARAM_MAPPINGS;
  }
  getUrl() {
    return "sap-ai:foundation-models";
  }
};
export {
  FoundationModelsLanguageModelStrategy
};
//# sourceMappingURL=foundation-models-language-model-strategy-KVEFWA62.js.map