@jerome-benoit/sap-ai-provider-v2 4.1.2 → 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/README.md +2 -1
- package/dist/index.cjs +45 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -45
- package/dist/index.d.ts +123 -45
- package/dist/index.js +44 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
5
|
[](https://sdk.vercel.ai/docs)
|
|
6
6
|
[](https://sdk.vercel.ai/docs/ai-sdk-core/provider-management)
|
|
7
|
-
[](https://sdk.vercel.ai/docs/ai-sdk-core/embeddings)
|
|
8
8
|
|
|
9
9
|
> **Note:** This is a **V2-compatible fork** for use with **AI SDK 5.x**.
|
|
10
10
|
|
|
@@ -549,6 +549,7 @@ authentication, model parameters, data masking, content filtering, and more.
|
|
|
549
549
|
|
|
550
550
|
**Common Configuration:**
|
|
551
551
|
|
|
552
|
+
- `name`: Provider name (default: `'sap-ai'`). Used as key in `providerOptions`/`providerMetadata`.
|
|
552
553
|
- `resourceGroup`: SAP AI Core resource group (default: 'default')
|
|
553
554
|
- `deploymentId`: Specific deployment ID (auto-resolved if not set)
|
|
554
555
|
- `modelParams`: Temperature, maxTokens, topP, and other generation parameters
|
package/dist/index.cjs
CHANGED
|
@@ -29750,6 +29750,7 @@ __export(index_exports, {
|
|
|
29750
29750
|
buildLlamaGuard38BFilter: () => import_orchestration3.buildLlamaGuard38BFilter,
|
|
29751
29751
|
buildTranslationConfig: () => import_orchestration3.buildTranslationConfig,
|
|
29752
29752
|
createSAPAIProvider: () => createSAPAIProvider,
|
|
29753
|
+
getProviderName: () => getProviderName,
|
|
29753
29754
|
isConfigReference: () => import_orchestration3.isConfigReference,
|
|
29754
29755
|
sapAIEmbeddingProviderOptions: () => sapAIEmbeddingProviderOptions,
|
|
29755
29756
|
sapAILanguageModelProviderOptions: () => sapAILanguageModelProviderOptions,
|
|
@@ -30225,6 +30226,10 @@ function tryExtractSAPErrorFromMessage(message) {
|
|
|
30225
30226
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
30226
30227
|
var import_zod = require("zod");
|
|
30227
30228
|
var SAP_AI_PROVIDER_NAME = "sap-ai";
|
|
30229
|
+
function getProviderName(providerIdentifier) {
|
|
30230
|
+
const dotIndex = providerIdentifier.indexOf(".");
|
|
30231
|
+
return dotIndex === -1 ? providerIdentifier : providerIdentifier.slice(0, dotIndex);
|
|
30232
|
+
}
|
|
30228
30233
|
var modelParamsSchema = import_zod.z.object({
|
|
30229
30234
|
/**
|
|
30230
30235
|
* Frequency penalty between -2.0 and 2.0.
|
|
@@ -30399,6 +30404,7 @@ var SAPAIEmbeddingModel = class {
|
|
|
30399
30404
|
* the SAP AI SDK's OrchestrationEmbeddingClient.
|
|
30400
30405
|
* @param options - The embedding request options
|
|
30401
30406
|
* @returns Promise resolving to embeddings and usage information
|
|
30407
|
+
* @since 1.0.0
|
|
30402
30408
|
* @example
|
|
30403
30409
|
* ```typescript
|
|
30404
30410
|
* const result = await model.doEmbed({
|
|
@@ -30411,8 +30417,9 @@ var SAPAIEmbeddingModel = class {
|
|
|
30411
30417
|
*/
|
|
30412
30418
|
async doEmbed(options) {
|
|
30413
30419
|
const { abortSignal, providerOptions, values } = options;
|
|
30420
|
+
const providerName = getProviderName(this.config.provider);
|
|
30414
30421
|
const sapOptions = await (0, import_provider_utils2.parseProviderOptions)({
|
|
30415
|
-
provider:
|
|
30422
|
+
provider: providerName,
|
|
30416
30423
|
providerOptions,
|
|
30417
30424
|
schema: sapAIEmbeddingProviderOptions
|
|
30418
30425
|
});
|
|
@@ -30442,7 +30449,7 @@ var SAPAIEmbeddingModel = class {
|
|
|
30442
30449
|
(data) => this.normalizeEmbedding(data.embedding)
|
|
30443
30450
|
);
|
|
30444
30451
|
const providerMetadata = {
|
|
30445
|
-
|
|
30452
|
+
[providerName]: {
|
|
30446
30453
|
model: this.modelId
|
|
30447
30454
|
}
|
|
30448
30455
|
};
|
|
@@ -30541,6 +30548,7 @@ var SAPAIEmbeddingModelV2 = class {
|
|
|
30541
30548
|
* @param options.providerOptions - Optional provider-specific options
|
|
30542
30549
|
* @param options.headers - Optional HTTP headers
|
|
30543
30550
|
* @returns Promise resolving to embeddings and metadata in V2 format
|
|
30551
|
+
* @since 1.0.0
|
|
30544
30552
|
*/
|
|
30545
30553
|
async doEmbed(options) {
|
|
30546
30554
|
const v3Options = {
|
|
@@ -30581,6 +30589,9 @@ function castProviderMetadataV3ToV2(v3Metadata) {
|
|
|
30581
30589
|
return v3Metadata;
|
|
30582
30590
|
}
|
|
30583
30591
|
|
|
30592
|
+
// src/sap-ai-provider-v2.ts
|
|
30593
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
30594
|
+
|
|
30584
30595
|
// src/sap-ai-language-model.ts
|
|
30585
30596
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
30586
30597
|
var import_orchestration2 = require("@sap-ai-sdk/orchestration");
|
|
@@ -30960,11 +30971,12 @@ var SAPAILanguageModel = class {
|
|
|
30960
30971
|
tokenUsage,
|
|
30961
30972
|
toolCalls
|
|
30962
30973
|
};
|
|
30974
|
+
const providerName = getProviderName(this.config.provider);
|
|
30963
30975
|
return {
|
|
30964
30976
|
content,
|
|
30965
30977
|
finishReason,
|
|
30966
30978
|
providerMetadata: {
|
|
30967
|
-
|
|
30979
|
+
[providerName]: {
|
|
30968
30980
|
finishReason: finishReasonRaw ?? "unknown",
|
|
30969
30981
|
finishReasonMapped: finishReason,
|
|
30970
30982
|
...typeof responseHeaders?.["x-request-id"] === "string" ? { requestId: responseHeaders["x-request-id"] } : {}
|
|
@@ -31095,6 +31107,7 @@ var SAPAILanguageModel = class {
|
|
|
31095
31107
|
const toolCallsInProgress = /* @__PURE__ */ new Map();
|
|
31096
31108
|
const sdkStream = streamResponse.stream;
|
|
31097
31109
|
const modelId = this.modelId;
|
|
31110
|
+
const providerName = getProviderName(this.config.provider);
|
|
31098
31111
|
const warningsSnapshot = [...warnings];
|
|
31099
31112
|
const warningsOut = [...warningsSnapshot];
|
|
31100
31113
|
const transformedStream = new ReadableStream({
|
|
@@ -31283,7 +31296,7 @@ var SAPAILanguageModel = class {
|
|
|
31283
31296
|
controller.enqueue({
|
|
31284
31297
|
finishReason: streamState.finishReason,
|
|
31285
31298
|
providerMetadata: {
|
|
31286
|
-
|
|
31299
|
+
[providerName]: {
|
|
31287
31300
|
finishReason: streamState.finishReason.raw,
|
|
31288
31301
|
responseId
|
|
31289
31302
|
}
|
|
@@ -31339,8 +31352,9 @@ var SAPAILanguageModel = class {
|
|
|
31339
31352
|
* @internal
|
|
31340
31353
|
*/
|
|
31341
31354
|
async buildOrchestrationConfig(options) {
|
|
31355
|
+
const providerName = getProviderName(this.config.provider);
|
|
31342
31356
|
const sapOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
31343
|
-
provider:
|
|
31357
|
+
provider: providerName,
|
|
31344
31358
|
providerOptions: options.providerOptions,
|
|
31345
31359
|
schema: sapAILanguageModelProviderOptions
|
|
31346
31360
|
});
|
|
@@ -31462,21 +31476,26 @@ var SAPAILanguageModel = class {
|
|
|
31462
31476
|
type: "unsupported"
|
|
31463
31477
|
});
|
|
31464
31478
|
}
|
|
31479
|
+
let responseFormat;
|
|
31465
31480
|
if (options.responseFormat?.type === "json") {
|
|
31481
|
+
responseFormat = options.responseFormat.schema ? {
|
|
31482
|
+
json_schema: {
|
|
31483
|
+
description: options.responseFormat.description,
|
|
31484
|
+
name: options.responseFormat.name ?? "response",
|
|
31485
|
+
schema: options.responseFormat.schema,
|
|
31486
|
+
strict: null
|
|
31487
|
+
},
|
|
31488
|
+
type: "json_schema"
|
|
31489
|
+
} : { type: "json_object" };
|
|
31490
|
+
} else if (this.settings.responseFormat) {
|
|
31491
|
+
responseFormat = this.settings.responseFormat;
|
|
31492
|
+
}
|
|
31493
|
+
if (responseFormat && responseFormat.type !== "text") {
|
|
31466
31494
|
warnings.push({
|
|
31467
31495
|
message: "responseFormat JSON mode is forwarded to the underlying model; support and schema adherence depend on the model/deployment.",
|
|
31468
31496
|
type: "other"
|
|
31469
31497
|
});
|
|
31470
31498
|
}
|
|
31471
|
-
const responseFormat = options.responseFormat?.type === "json" ? options.responseFormat.schema ? {
|
|
31472
|
-
json_schema: {
|
|
31473
|
-
description: options.responseFormat.description,
|
|
31474
|
-
name: options.responseFormat.name ?? "response",
|
|
31475
|
-
schema: options.responseFormat.schema,
|
|
31476
|
-
strict: null
|
|
31477
|
-
},
|
|
31478
|
-
type: "json_schema"
|
|
31479
|
-
} : { type: "json_object" } : void 0;
|
|
31480
31499
|
const orchestrationConfig = {
|
|
31481
31500
|
promptTemplating: {
|
|
31482
31501
|
model: {
|
|
@@ -31758,6 +31777,7 @@ function createSAPAIProvider(options = {}) {
|
|
|
31758
31777
|
if (options.defaultSettings?.modelParams) {
|
|
31759
31778
|
validateModelParamsSettings(options.defaultSettings.modelParams);
|
|
31760
31779
|
}
|
|
31780
|
+
const providerName = options.name ?? SAP_AI_PROVIDER_NAME;
|
|
31761
31781
|
const resourceGroup = options.resourceGroup ?? "default";
|
|
31762
31782
|
const warnOnAmbiguousConfig = options.warnOnAmbiguousConfig ?? true;
|
|
31763
31783
|
if (warnOnAmbiguousConfig && options.deploymentId && options.resourceGroup) {
|
|
@@ -31782,14 +31802,14 @@ function createSAPAIProvider(options = {}) {
|
|
|
31782
31802
|
return new SAPAILanguageModelV2(modelId, mergedSettings, {
|
|
31783
31803
|
deploymentConfig,
|
|
31784
31804
|
destination: options.destination,
|
|
31785
|
-
provider:
|
|
31805
|
+
provider: `${providerName}.chat`
|
|
31786
31806
|
});
|
|
31787
31807
|
};
|
|
31788
31808
|
const createEmbeddingModel = (modelId, settings = {}) => {
|
|
31789
31809
|
return new SAPAIEmbeddingModelV2(modelId, settings, {
|
|
31790
31810
|
deploymentConfig,
|
|
31791
31811
|
destination: options.destination,
|
|
31792
|
-
provider:
|
|
31812
|
+
provider: `${providerName}.embedding`
|
|
31793
31813
|
});
|
|
31794
31814
|
};
|
|
31795
31815
|
const provider = function(modelId, settings) {
|
|
@@ -31798,10 +31818,17 @@ function createSAPAIProvider(options = {}) {
|
|
|
31798
31818
|
}
|
|
31799
31819
|
return createModel(modelId, settings);
|
|
31800
31820
|
};
|
|
31801
|
-
provider.languageModel = createModel;
|
|
31802
31821
|
provider.chat = createModel;
|
|
31822
|
+
provider.languageModel = createModel;
|
|
31803
31823
|
provider.embedding = createEmbeddingModel;
|
|
31804
31824
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
31825
|
+
provider.imageModel = (modelId) => {
|
|
31826
|
+
throw new import_provider4.NoSuchModelError({
|
|
31827
|
+
message: `SAP AI Core Orchestration Service does not support image generation. Model '${modelId}' is not available.`,
|
|
31828
|
+
modelId,
|
|
31829
|
+
modelType: "imageModel"
|
|
31830
|
+
});
|
|
31831
|
+
};
|
|
31805
31832
|
return provider;
|
|
31806
31833
|
}
|
|
31807
31834
|
var sapai = createSAPAIProvider();
|
|
@@ -31827,6 +31854,7 @@ var import_orchestration5 = require("@sap-ai-sdk/orchestration");
|
|
|
31827
31854
|
buildLlamaGuard38BFilter,
|
|
31828
31855
|
buildTranslationConfig,
|
|
31829
31856
|
createSAPAIProvider,
|
|
31857
|
+
getProviderName,
|
|
31830
31858
|
isConfigReference,
|
|
31831
31859
|
sapAIEmbeddingProviderOptions,
|
|
31832
31860
|
sapAILanguageModelProviderOptions,
|