@jerome-benoit/sap-ai-provider-v2 4.1.3 → 4.2.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/index.d.cts CHANGED
@@ -158,8 +158,9 @@ declare class SAPAIEmbeddingModelV2 implements EmbeddingModelV2<string> {
158
158
  }
159
159
 
160
160
  /**
161
- * The provider identifier used for provider options.
162
- * Use this key in `providerOptions` to pass SAP AI-specific options.
161
+ * Default provider name.
162
+ *
163
+ * Use this as key in `providerOptions` and `providerMetadata` when using the default provider name.
163
164
  * @example
164
165
  * ```typescript
165
166
  * providerOptions: {
@@ -168,6 +169,22 @@ declare class SAPAIEmbeddingModelV2 implements EmbeddingModelV2<string> {
168
169
  * ```
169
170
  */
170
171
  declare const SAP_AI_PROVIDER_NAME: "sap-ai";
172
+ /**
173
+ * Extracts the provider name from a provider identifier.
174
+ *
175
+ * Following the AI SDK convention, provider identifiers use the format `{name}.{type}`
176
+ * (e.g., `"openai.chat"`, `"anthropic.messages"`). This function extracts the provider name
177
+ * for use with `providerOptions` and `providerMetadata`, which use the provider name as key.
178
+ * @param providerIdentifier - The provider identifier (e.g., `"sap-ai.chat"`, `"sap-ai.embedding"`)
179
+ * @returns The provider name (e.g., `"sap-ai"`)
180
+ * @example
181
+ * ```typescript
182
+ * getProviderName("sap-ai.chat") // => "sap-ai"
183
+ * getProviderName("sap-ai-core.embedding") // => "sap-ai-core"
184
+ * getProviderName("sap-ai") // => "sap-ai" (no type suffix)
185
+ * ```
186
+ */
187
+ declare function getProviderName(providerIdentifier: string): string;
171
188
  /**
172
189
  * Zod schema for SAP AI language model provider options.
173
190
  *
@@ -804,6 +821,31 @@ interface SAPAIProviderSettings {
804
821
  * ```
805
822
  */
806
823
  readonly destination?: HttpDestinationOrFetchOptions;
824
+ /**
825
+ * Provider name.
826
+ *
827
+ * Used as the key for `providerOptions` and `providerMetadata` in AI SDK calls.
828
+ * The provider identifier (exposed via `model.provider`) follows the AI SDK convention
829
+ * `{name}.{type}` (e.g., `"sap-ai.chat"`, `"sap-ai.embedding"`).
830
+ * @default 'sap-ai'
831
+ * @example
832
+ * ```typescript
833
+ * const provider = createSAPAIProvider({ name: 'sap-ai-core' });
834
+ * const model = provider('gpt-4o');
835
+ *
836
+ * console.log(model.provider); // => "sap-ai-core.chat"
837
+ *
838
+ * // Use provider name in providerOptions:
839
+ * await generateText({
840
+ * model,
841
+ * prompt: 'Hello',
842
+ * providerOptions: {
843
+ * 'sap-ai-core': { includeReasoning: true }
844
+ * }
845
+ * });
846
+ * ```
847
+ */
848
+ readonly name?: string;
807
849
  /**
808
850
  * SAP AI Core resource group.
809
851
  *
@@ -878,6 +920,15 @@ interface SAPAIProviderV2 extends ProviderV2 {
878
920
  * @param modelId - The embedding model identifier (e.g., 'text-embedding-ada-002')
879
921
  * @param settings - Optional embedding model settings
880
922
  * @returns Configured SAP AI embedding model instance (V2)
923
+ * @example
924
+ * ```typescript
925
+ * import { embed } from 'ai';
926
+ *
927
+ * const { embedding } = await embed({
928
+ * model: provider.embedding('text-embedding-ada-002'),
929
+ * value: 'Hello, world!'
930
+ * });
931
+ * ```
881
932
  */
882
933
  embedding(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModelV2;
883
934
  /**
@@ -898,7 +949,8 @@ interface SAPAIProviderV2 extends ProviderV2 {
898
949
  /**
899
950
  * Create a language model instance (V2).
900
951
  *
901
- * This is the standard method for creating language models.
952
+ * Standard ProviderV2 method for creating language models.
953
+ * Equivalent to calling the provider function directly or using `chat()`.
902
954
  * @param modelId - The SAP AI Core model identifier
903
955
  * @param settings - Optional model configuration settings
904
956
  * @returns Configured SAP AI language model instance (V2)
@@ -907,7 +959,8 @@ interface SAPAIProviderV2 extends ProviderV2 {
907
959
  /**
908
960
  * Create a text embedding model instance (V2).
909
961
  *
910
- * Alias for the embedding() method. Provides compatibility with common provider patterns.
962
+ * Standard ProviderV2 method for creating embedding models.
963
+ * Equivalent to calling `embedding()`.
911
964
  * @param modelId - The embedding model identifier
912
965
  * @param settings - Optional embedding model settings
913
966
  * @returns Configured SAP AI embedding model instance (V2)
@@ -994,4 +1047,4 @@ declare function createSAPAIProvider(options?: SAPAIProviderSettings): SAPAIProv
994
1047
  */
995
1048
  declare const sapai: SAPAIProviderV2;
996
1049
 
997
- export { type DeploymentConfig, SAPAIEmbeddingModelV2 as SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProviderV2 as SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
1050
+ export { type DeploymentConfig, SAPAIEmbeddingModelV2 as SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProviderV2 as SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, getProviderName, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
package/dist/index.d.ts CHANGED
@@ -158,8 +158,9 @@ declare class SAPAIEmbeddingModelV2 implements EmbeddingModelV2<string> {
158
158
  }
159
159
 
160
160
  /**
161
- * The provider identifier used for provider options.
162
- * Use this key in `providerOptions` to pass SAP AI-specific options.
161
+ * Default provider name.
162
+ *
163
+ * Use this as key in `providerOptions` and `providerMetadata` when using the default provider name.
163
164
  * @example
164
165
  * ```typescript
165
166
  * providerOptions: {
@@ -168,6 +169,22 @@ declare class SAPAIEmbeddingModelV2 implements EmbeddingModelV2<string> {
168
169
  * ```
169
170
  */
170
171
  declare const SAP_AI_PROVIDER_NAME: "sap-ai";
172
+ /**
173
+ * Extracts the provider name from a provider identifier.
174
+ *
175
+ * Following the AI SDK convention, provider identifiers use the format `{name}.{type}`
176
+ * (e.g., `"openai.chat"`, `"anthropic.messages"`). This function extracts the provider name
177
+ * for use with `providerOptions` and `providerMetadata`, which use the provider name as key.
178
+ * @param providerIdentifier - The provider identifier (e.g., `"sap-ai.chat"`, `"sap-ai.embedding"`)
179
+ * @returns The provider name (e.g., `"sap-ai"`)
180
+ * @example
181
+ * ```typescript
182
+ * getProviderName("sap-ai.chat") // => "sap-ai"
183
+ * getProviderName("sap-ai-core.embedding") // => "sap-ai-core"
184
+ * getProviderName("sap-ai") // => "sap-ai" (no type suffix)
185
+ * ```
186
+ */
187
+ declare function getProviderName(providerIdentifier: string): string;
171
188
  /**
172
189
  * Zod schema for SAP AI language model provider options.
173
190
  *
@@ -804,6 +821,31 @@ interface SAPAIProviderSettings {
804
821
  * ```
805
822
  */
806
823
  readonly destination?: HttpDestinationOrFetchOptions;
824
+ /**
825
+ * Provider name.
826
+ *
827
+ * Used as the key for `providerOptions` and `providerMetadata` in AI SDK calls.
828
+ * The provider identifier (exposed via `model.provider`) follows the AI SDK convention
829
+ * `{name}.{type}` (e.g., `"sap-ai.chat"`, `"sap-ai.embedding"`).
830
+ * @default 'sap-ai'
831
+ * @example
832
+ * ```typescript
833
+ * const provider = createSAPAIProvider({ name: 'sap-ai-core' });
834
+ * const model = provider('gpt-4o');
835
+ *
836
+ * console.log(model.provider); // => "sap-ai-core.chat"
837
+ *
838
+ * // Use provider name in providerOptions:
839
+ * await generateText({
840
+ * model,
841
+ * prompt: 'Hello',
842
+ * providerOptions: {
843
+ * 'sap-ai-core': { includeReasoning: true }
844
+ * }
845
+ * });
846
+ * ```
847
+ */
848
+ readonly name?: string;
807
849
  /**
808
850
  * SAP AI Core resource group.
809
851
  *
@@ -878,6 +920,15 @@ interface SAPAIProviderV2 extends ProviderV2 {
878
920
  * @param modelId - The embedding model identifier (e.g., 'text-embedding-ada-002')
879
921
  * @param settings - Optional embedding model settings
880
922
  * @returns Configured SAP AI embedding model instance (V2)
923
+ * @example
924
+ * ```typescript
925
+ * import { embed } from 'ai';
926
+ *
927
+ * const { embedding } = await embed({
928
+ * model: provider.embedding('text-embedding-ada-002'),
929
+ * value: 'Hello, world!'
930
+ * });
931
+ * ```
881
932
  */
882
933
  embedding(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModelV2;
883
934
  /**
@@ -898,7 +949,8 @@ interface SAPAIProviderV2 extends ProviderV2 {
898
949
  /**
899
950
  * Create a language model instance (V2).
900
951
  *
901
- * This is the standard method for creating language models.
952
+ * Standard ProviderV2 method for creating language models.
953
+ * Equivalent to calling the provider function directly or using `chat()`.
902
954
  * @param modelId - The SAP AI Core model identifier
903
955
  * @param settings - Optional model configuration settings
904
956
  * @returns Configured SAP AI language model instance (V2)
@@ -907,7 +959,8 @@ interface SAPAIProviderV2 extends ProviderV2 {
907
959
  /**
908
960
  * Create a text embedding model instance (V2).
909
961
  *
910
- * Alias for the embedding() method. Provides compatibility with common provider patterns.
962
+ * Standard ProviderV2 method for creating embedding models.
963
+ * Equivalent to calling `embedding()`.
911
964
  * @param modelId - The embedding model identifier
912
965
  * @param settings - Optional embedding model settings
913
966
  * @returns Configured SAP AI embedding model instance (V2)
@@ -994,4 +1047,4 @@ declare function createSAPAIProvider(options?: SAPAIProviderSettings): SAPAIProv
994
1047
  */
995
1048
  declare const sapai: SAPAIProviderV2;
996
1049
 
997
- export { type DeploymentConfig, SAPAIEmbeddingModelV2 as SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProviderV2 as SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
1050
+ export { type DeploymentConfig, SAPAIEmbeddingModelV2 as SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProviderV2 as SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, getProviderName, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
package/dist/index.js CHANGED
@@ -30207,6 +30207,10 @@ function tryExtractSAPErrorFromMessage(message) {
30207
30207
  import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
30208
30208
  import { z } from "zod";
30209
30209
  var SAP_AI_PROVIDER_NAME = "sap-ai";
30210
+ function getProviderName(providerIdentifier) {
30211
+ const dotIndex = providerIdentifier.indexOf(".");
30212
+ return dotIndex === -1 ? providerIdentifier : providerIdentifier.slice(0, dotIndex);
30213
+ }
30210
30214
  var modelParamsSchema = z.object({
30211
30215
  /**
30212
30216
  * Frequency penalty between -2.0 and 2.0.
@@ -30394,8 +30398,9 @@ var SAPAIEmbeddingModel = class {
30394
30398
  */
30395
30399
  async doEmbed(options) {
30396
30400
  const { abortSignal, providerOptions, values } = options;
30401
+ const providerName = getProviderName(this.config.provider);
30397
30402
  const sapOptions = await parseProviderOptions({
30398
- provider: SAP_AI_PROVIDER_NAME,
30403
+ provider: providerName,
30399
30404
  providerOptions,
30400
30405
  schema: sapAIEmbeddingProviderOptions
30401
30406
  });
@@ -30425,7 +30430,7 @@ var SAPAIEmbeddingModel = class {
30425
30430
  (data) => this.normalizeEmbedding(data.embedding)
30426
30431
  );
30427
30432
  const providerMetadata = {
30428
- "sap-ai": {
30433
+ [providerName]: {
30429
30434
  model: this.modelId
30430
30435
  }
30431
30436
  };
@@ -30952,11 +30957,12 @@ var SAPAILanguageModel = class {
30952
30957
  tokenUsage,
30953
30958
  toolCalls
30954
30959
  };
30960
+ const providerName = getProviderName(this.config.provider);
30955
30961
  return {
30956
30962
  content,
30957
30963
  finishReason,
30958
30964
  providerMetadata: {
30959
- "sap-ai": {
30965
+ [providerName]: {
30960
30966
  finishReason: finishReasonRaw ?? "unknown",
30961
30967
  finishReasonMapped: finishReason,
30962
30968
  ...typeof responseHeaders?.["x-request-id"] === "string" ? { requestId: responseHeaders["x-request-id"] } : {}
@@ -31087,6 +31093,7 @@ var SAPAILanguageModel = class {
31087
31093
  const toolCallsInProgress = /* @__PURE__ */ new Map();
31088
31094
  const sdkStream = streamResponse.stream;
31089
31095
  const modelId = this.modelId;
31096
+ const providerName = getProviderName(this.config.provider);
31090
31097
  const warningsSnapshot = [...warnings];
31091
31098
  const warningsOut = [...warningsSnapshot];
31092
31099
  const transformedStream = new ReadableStream({
@@ -31275,7 +31282,7 @@ var SAPAILanguageModel = class {
31275
31282
  controller.enqueue({
31276
31283
  finishReason: streamState.finishReason,
31277
31284
  providerMetadata: {
31278
- "sap-ai": {
31285
+ [providerName]: {
31279
31286
  finishReason: streamState.finishReason.raw,
31280
31287
  responseId
31281
31288
  }
@@ -31331,8 +31338,9 @@ var SAPAILanguageModel = class {
31331
31338
  * @internal
31332
31339
  */
31333
31340
  async buildOrchestrationConfig(options) {
31341
+ const providerName = getProviderName(this.config.provider);
31334
31342
  const sapOptions = await parseProviderOptions2({
31335
- provider: SAP_AI_PROVIDER_NAME,
31343
+ provider: providerName,
31336
31344
  providerOptions: options.providerOptions,
31337
31345
  schema: sapAILanguageModelProviderOptions
31338
31346
  });
@@ -31755,6 +31763,7 @@ function createSAPAIProvider(options = {}) {
31755
31763
  if (options.defaultSettings?.modelParams) {
31756
31764
  validateModelParamsSettings(options.defaultSettings.modelParams);
31757
31765
  }
31766
+ const providerName = options.name ?? SAP_AI_PROVIDER_NAME;
31758
31767
  const resourceGroup = options.resourceGroup ?? "default";
31759
31768
  const warnOnAmbiguousConfig = options.warnOnAmbiguousConfig ?? true;
31760
31769
  if (warnOnAmbiguousConfig && options.deploymentId && options.resourceGroup) {
@@ -31779,14 +31788,14 @@ function createSAPAIProvider(options = {}) {
31779
31788
  return new SAPAILanguageModelV2(modelId, mergedSettings, {
31780
31789
  deploymentConfig,
31781
31790
  destination: options.destination,
31782
- provider: "sap-ai"
31791
+ provider: `${providerName}.chat`
31783
31792
  });
31784
31793
  };
31785
31794
  const createEmbeddingModel = (modelId, settings = {}) => {
31786
31795
  return new SAPAIEmbeddingModelV2(modelId, settings, {
31787
31796
  deploymentConfig,
31788
31797
  destination: options.destination,
31789
- provider: "sap-ai"
31798
+ provider: `${providerName}.embedding`
31790
31799
  });
31791
31800
  };
31792
31801
  const provider = function(modelId, settings) {
@@ -31795,8 +31804,8 @@ function createSAPAIProvider(options = {}) {
31795
31804
  }
31796
31805
  return createModel(modelId, settings);
31797
31806
  };
31798
- provider.languageModel = createModel;
31799
31807
  provider.chat = createModel;
31808
+ provider.languageModel = createModel;
31800
31809
  provider.embedding = createEmbeddingModel;
31801
31810
  provider.textEmbeddingModel = createEmbeddingModel;
31802
31811
  provider.imageModel = (modelId) => {
@@ -31841,6 +31850,7 @@ export {
31841
31850
  buildLlamaGuard38BFilter,
31842
31851
  buildTranslationConfig,
31843
31852
  createSAPAIProvider,
31853
+ getProviderName,
31844
31854
  isConfigReference,
31845
31855
  sapAIEmbeddingProviderOptions,
31846
31856
  sapAILanguageModelProviderOptions,