@jerome-benoit/sap-ai-provider 3.0.0 → 4.0.0-rc.2
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 +168 -113
- package/dist/index.cjs +713 -595
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +324 -223
- package/dist/index.d.ts +324 -223
- package/dist/index.js +713 -594
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
|
|
3
|
-
import { ResourceGroupConfig, DeploymentIdConfig } from '@sap-ai-sdk/ai-api/internal.js';
|
|
4
|
-
import { MaskingModule, FilteringModule, ChatCompletionTool, ChatModel } from '@sap-ai-sdk/orchestration';
|
|
1
|
+
import { FilteringModule, GroundingModule, MaskingModule, ChatCompletionTool, TranslationModule, ChatModel } from '@sap-ai-sdk/orchestration';
|
|
5
2
|
export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMessage, DeveloperChatMessage, DocumentTranslationApplyToSelector, FilteringModule, FunctionObject, GroundingModule, LlmModelDetails, LlmModelParams, MaskingModule, OrchestrationClient, OrchestrationConfigRef, OrchestrationErrorResponse, OrchestrationModuleConfig, OrchestrationResponse, OrchestrationStreamChunkResponse, OrchestrationStreamResponse, PromptTemplatingModule, SystemChatMessage, ToolChatMessage, TranslationApplyToCategory, TranslationInputParameters, TranslationModule, TranslationOutputParameters, TranslationTargetLanguage, UserChatMessage, buildAzureContentSafetyFilter, buildDocumentGroundingConfig, buildDpiMaskingProvider, buildLlamaGuard38BFilter, buildTranslationConfig, isConfigReference } from '@sap-ai-sdk/orchestration';
|
|
3
|
+
import { DeploymentIdConfig, ResourceGroupConfig } from '@sap-ai-sdk/ai-api/internal.js';
|
|
4
|
+
import { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
|
|
5
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3 } from '@ai-sdk/provider';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Supported model IDs in SAP AI Core.
|
|
9
|
+
*
|
|
10
|
+
* These models are available through the SAP AI Core Orchestration service.
|
|
11
|
+
* **Note:** The models listed here are representative examples. Actual model availability
|
|
12
|
+
* depends on your SAP AI Core tenant configuration, region, and subscription.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/models-and-scenarios SAP AI Core Models Documentation}
|
|
15
|
+
*
|
|
16
|
+
* **Azure OpenAI Models:**
|
|
17
|
+
* - gpt-4o, gpt-4o-mini
|
|
18
|
+
* - gpt-4.1, gpt-4.1-mini, gpt-4.1-nano
|
|
19
|
+
* - o1, o3, o3-mini, o4-mini
|
|
20
|
+
*
|
|
21
|
+
* **Google Vertex AI Models:**
|
|
22
|
+
* - gemini-2.0-flash, gemini-2.0-flash-lite
|
|
23
|
+
* - gemini-2.5-flash, gemini-2.5-pro
|
|
24
|
+
*
|
|
25
|
+
* **AWS Bedrock Models:**
|
|
26
|
+
* - anthropic--claude-3-haiku, anthropic--claude-3-sonnet, anthropic--claude-3-opus
|
|
27
|
+
* - anthropic--claude-3.5-sonnet, anthropic--claude-3.7-sonnet
|
|
28
|
+
* - anthropic--claude-4-sonnet, anthropic--claude-4-opus
|
|
29
|
+
* - amazon--nova-pro, amazon--nova-lite, amazon--nova-micro, amazon--nova-premier
|
|
30
|
+
*
|
|
31
|
+
* **AI Core Open Source Models:**
|
|
32
|
+
* - mistralai--mistral-large-instruct, mistralai--mistral-medium-instruct, mistralai--mistral-small-instruct
|
|
33
|
+
* - cohere--command-a-reasoning
|
|
34
|
+
*/
|
|
35
|
+
type SAPAIModelId = ChatModel;
|
|
7
36
|
/**
|
|
8
37
|
* Settings for configuring SAP AI Core model behavior.
|
|
9
38
|
*
|
|
@@ -55,10 +84,61 @@ export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMe
|
|
|
55
84
|
*/
|
|
56
85
|
interface SAPAISettings {
|
|
57
86
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
87
|
+
* Filtering configuration for input and output content safety.
|
|
88
|
+
* Supports Azure Content Safety and Llama Guard filters.
|
|
89
|
+
*
|
|
90
|
+
* @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/content-filtering SAP Content Filtering Documentation}
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* import { buildAzureContentSafetyFilter } from '@sap-ai-sdk/orchestration';
|
|
95
|
+
*
|
|
96
|
+
* const model = provider('gpt-4o', {
|
|
97
|
+
* filtering: {
|
|
98
|
+
* input: {
|
|
99
|
+
* filters: [
|
|
100
|
+
* buildAzureContentSafetyFilter('input', {
|
|
101
|
+
* hate: 'ALLOW_SAFE',
|
|
102
|
+
* violence: 'ALLOW_SAFE_LOW_MEDIUM'
|
|
103
|
+
* })
|
|
104
|
+
* ]
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
60
109
|
*/
|
|
61
|
-
|
|
110
|
+
filtering?: FilteringModule;
|
|
111
|
+
/**
|
|
112
|
+
* Grounding module configuration for document-based retrieval (RAG).
|
|
113
|
+
* Enables retrieval-augmented generation using SAP Document Grounding Service.
|
|
114
|
+
*
|
|
115
|
+
* Use `buildDocumentGroundingConfig()` to create the configuration.
|
|
116
|
+
*
|
|
117
|
+
* @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/document-grounding SAP Document Grounding Documentation}
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { buildDocumentGroundingConfig } from '@mymediset/sap-ai-provider';
|
|
122
|
+
*
|
|
123
|
+
* const model = provider('gpt-4o', {
|
|
124
|
+
* grounding: buildDocumentGroundingConfig({
|
|
125
|
+
* filters: [
|
|
126
|
+
* {
|
|
127
|
+
* id: 'my-vector-store',
|
|
128
|
+
* data_repository_type: 'vector',
|
|
129
|
+
* data_repositories: ['document-repo-1'],
|
|
130
|
+
* chunk_overlap: 50
|
|
131
|
+
* }
|
|
132
|
+
* ],
|
|
133
|
+
* placeholders: {
|
|
134
|
+
* input: ['?question'],
|
|
135
|
+
* output: 'groundingOutput'
|
|
136
|
+
* }
|
|
137
|
+
* })
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
grounding?: GroundingModule;
|
|
62
142
|
/**
|
|
63
143
|
* Whether to include assistant reasoning parts in the SAP prompt conversion.
|
|
64
144
|
*
|
|
@@ -94,27 +174,34 @@ interface SAPAISettings {
|
|
|
94
174
|
* ```
|
|
95
175
|
*/
|
|
96
176
|
includeReasoning?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Masking configuration for SAP AI Core orchestration.
|
|
179
|
+
* When provided, sensitive information in prompts can be anonymized or
|
|
180
|
+
* pseudonymized by SAP Data Privacy Integration (DPI).
|
|
181
|
+
*
|
|
182
|
+
* @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/data-privacy-integration SAP DPI Documentation}
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* import { buildDpiMaskingProvider } from '@sap-ai-sdk/orchestration';
|
|
187
|
+
*
|
|
188
|
+
* const model = provider('gpt-4o', {
|
|
189
|
+
* masking: {
|
|
190
|
+
* masking_providers: [
|
|
191
|
+
* buildDpiMaskingProvider({
|
|
192
|
+
* method: 'anonymization',
|
|
193
|
+
* entities: ['profile-email', 'profile-phone']
|
|
194
|
+
* })
|
|
195
|
+
* ]
|
|
196
|
+
* }
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
masking?: MaskingModule;
|
|
97
201
|
/**
|
|
98
202
|
* Model generation parameters that control the output.
|
|
99
203
|
*/
|
|
100
204
|
modelParams?: {
|
|
101
|
-
/**
|
|
102
|
-
* Maximum number of tokens to generate.
|
|
103
|
-
* Higher values allow for longer responses but increase latency and cost.
|
|
104
|
-
*/
|
|
105
|
-
maxTokens?: number;
|
|
106
|
-
/**
|
|
107
|
-
* Sampling temperature between 0 and 2.
|
|
108
|
-
* Higher values make output more random, lower values more deterministic.
|
|
109
|
-
* If not specified, the model's default temperature is used.
|
|
110
|
-
*/
|
|
111
|
-
temperature?: number;
|
|
112
|
-
/**
|
|
113
|
-
* Nucleus sampling parameter between 0 and 1.
|
|
114
|
-
* Controls diversity via cumulative probability cutoff.
|
|
115
|
-
* If not specified, the model's default topP is used (typically 1).
|
|
116
|
-
*/
|
|
117
|
-
topP?: number;
|
|
118
205
|
/**
|
|
119
206
|
* Frequency penalty between -2.0 and 2.0.
|
|
120
207
|
* Positive values penalize tokens based on their frequency.
|
|
@@ -122,11 +209,10 @@ interface SAPAISettings {
|
|
|
122
209
|
*/
|
|
123
210
|
frequencyPenalty?: number;
|
|
124
211
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* If not specified, the model's default is used (typically 0).
|
|
212
|
+
* Maximum number of tokens to generate.
|
|
213
|
+
* Higher values allow for longer responses but increase latency and cost.
|
|
128
214
|
*/
|
|
129
|
-
|
|
215
|
+
maxTokens?: number;
|
|
130
216
|
/**
|
|
131
217
|
* Number of completions to generate.
|
|
132
218
|
* Multiple completions provide alternative responses.
|
|
@@ -141,52 +227,30 @@ interface SAPAISettings {
|
|
|
141
227
|
* Note: This uses the SAP/OpenAI-style key `parallel_tool_calls`.
|
|
142
228
|
*/
|
|
143
229
|
parallel_tool_calls?: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Presence penalty between -2.0 and 2.0.
|
|
232
|
+
* Positive values penalize tokens that have appeared in the text.
|
|
233
|
+
* If not specified, the model's default is used (typically 0).
|
|
234
|
+
*/
|
|
235
|
+
presencePenalty?: number;
|
|
236
|
+
/**
|
|
237
|
+
* Sampling temperature between 0 and 2.
|
|
238
|
+
* Higher values make output more random, lower values more deterministic.
|
|
239
|
+
* If not specified, the model's default temperature is used.
|
|
240
|
+
*/
|
|
241
|
+
temperature?: number;
|
|
242
|
+
/**
|
|
243
|
+
* Nucleus sampling parameter between 0 and 1.
|
|
244
|
+
* Controls diversity via cumulative probability cutoff.
|
|
245
|
+
* If not specified, the model's default topP is used (typically 1).
|
|
246
|
+
*/
|
|
247
|
+
topP?: number;
|
|
144
248
|
};
|
|
145
249
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* pseudonymized by SAP Data Privacy Integration (DPI).
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* import { buildDpiMaskingProvider } from '@sap-ai-sdk/orchestration';
|
|
153
|
-
*
|
|
154
|
-
* const model = provider('gpt-4o', {
|
|
155
|
-
* masking: {
|
|
156
|
-
* masking_providers: [
|
|
157
|
-
* buildDpiMaskingProvider({
|
|
158
|
-
* method: 'anonymization',
|
|
159
|
-
* entities: ['profile-email', 'profile-phone']
|
|
160
|
-
* })
|
|
161
|
-
* ]
|
|
162
|
-
* }
|
|
163
|
-
* });
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
masking?: MaskingModule;
|
|
167
|
-
/**
|
|
168
|
-
* Filtering configuration for input and output content safety.
|
|
169
|
-
* Supports Azure Content Safety and Llama Guard filters.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```typescript
|
|
173
|
-
* import { buildAzureContentSafetyFilter } from '@sap-ai-sdk/orchestration';
|
|
174
|
-
*
|
|
175
|
-
* const model = provider('gpt-4o', {
|
|
176
|
-
* filtering: {
|
|
177
|
-
* input: {
|
|
178
|
-
* filters: [
|
|
179
|
-
* buildAzureContentSafetyFilter('input', {
|
|
180
|
-
* hate: 'ALLOW_SAFE',
|
|
181
|
-
* violence: 'ALLOW_SAFE_LOW_MEDIUM'
|
|
182
|
-
* })
|
|
183
|
-
* ]
|
|
184
|
-
* }
|
|
185
|
-
* }
|
|
186
|
-
* });
|
|
187
|
-
* ```
|
|
250
|
+
* Specific version of the model to use.
|
|
251
|
+
* If not provided, the latest version will be used.
|
|
188
252
|
*/
|
|
189
|
-
|
|
253
|
+
modelVersion?: string;
|
|
190
254
|
/**
|
|
191
255
|
* Response format for templating prompt (OpenAI-compatible)
|
|
192
256
|
* Allows specifying structured output formats
|
|
@@ -206,17 +270,17 @@ interface SAPAISettings {
|
|
|
206
270
|
* ```
|
|
207
271
|
*/
|
|
208
272
|
responseFormat?: {
|
|
209
|
-
type: "text";
|
|
210
|
-
} | {
|
|
211
|
-
type: "json_object";
|
|
212
|
-
} | {
|
|
213
|
-
type: "json_schema";
|
|
214
273
|
json_schema: {
|
|
215
|
-
name: string;
|
|
216
274
|
description?: string;
|
|
275
|
+
name: string;
|
|
217
276
|
schema?: unknown;
|
|
218
277
|
strict?: boolean | null;
|
|
219
278
|
};
|
|
279
|
+
type: "json_schema";
|
|
280
|
+
} | {
|
|
281
|
+
type: "json_object";
|
|
282
|
+
} | {
|
|
283
|
+
type: "text";
|
|
220
284
|
};
|
|
221
285
|
/**
|
|
222
286
|
* Tool definitions in SAP AI SDK format
|
|
@@ -251,48 +315,47 @@ interface SAPAISettings {
|
|
|
251
315
|
* ```
|
|
252
316
|
*/
|
|
253
317
|
tools?: ChatCompletionTool[];
|
|
318
|
+
/**
|
|
319
|
+
* Translation module configuration for input/output translation.
|
|
320
|
+
* Enables automatic translation using SAP Document Translation service.
|
|
321
|
+
*
|
|
322
|
+
* Use `buildTranslationConfig()` to create input/output configurations.
|
|
323
|
+
*
|
|
324
|
+
* @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/translation SAP Translation Documentation}
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* import { buildTranslationConfig } from '@mymediset/sap-ai-provider';
|
|
329
|
+
*
|
|
330
|
+
* const model = provider('gpt-4o', {
|
|
331
|
+
* translation: {
|
|
332
|
+
* input: buildTranslationConfig('input', {
|
|
333
|
+
* sourceLanguage: 'de-DE',
|
|
334
|
+
* targetLanguage: 'en-US'
|
|
335
|
+
* }),
|
|
336
|
+
* output: buildTranslationConfig('output', {
|
|
337
|
+
* targetLanguage: 'de-DE'
|
|
338
|
+
* })
|
|
339
|
+
* }
|
|
340
|
+
* });
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
translation?: TranslationModule;
|
|
254
344
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Supported model IDs in SAP AI Core.
|
|
257
|
-
*
|
|
258
|
-
* These models are available through the SAP AI Core Orchestration service.
|
|
259
|
-
* **Note:** The models listed here are representative examples. Actual model availability
|
|
260
|
-
* depends on your SAP AI Core tenant configuration, region, and subscription.
|
|
261
|
-
*
|
|
262
|
-
* **Azure OpenAI Models:**
|
|
263
|
-
* - gpt-4o, gpt-4o-mini
|
|
264
|
-
* - gpt-4.1, gpt-4.1-mini, gpt-4.1-nano
|
|
265
|
-
* - o1, o3, o3-mini, o4-mini
|
|
266
|
-
*
|
|
267
|
-
* **Google Vertex AI Models:**
|
|
268
|
-
* - gemini-2.0-flash, gemini-2.0-flash-lite
|
|
269
|
-
* - gemini-2.5-flash, gemini-2.5-pro
|
|
270
|
-
*
|
|
271
|
-
* **AWS Bedrock Models:**
|
|
272
|
-
* - anthropic--claude-3-haiku, anthropic--claude-3-sonnet, anthropic--claude-3-opus
|
|
273
|
-
* - anthropic--claude-3.5-sonnet, anthropic--claude-3.7-sonnet
|
|
274
|
-
* - anthropic--claude-4-sonnet, anthropic--claude-4-opus
|
|
275
|
-
* - amazon--nova-pro, amazon--nova-lite, amazon--nova-micro, amazon--nova-premier
|
|
276
|
-
*
|
|
277
|
-
* **AI Core Open Source Models:**
|
|
278
|
-
* - mistralai--mistral-large-instruct, mistralai--mistral-medium-instruct, mistralai--mistral-small-instruct
|
|
279
|
-
* - cohere--command-a-reasoning
|
|
280
|
-
*/
|
|
281
|
-
type SAPAIModelId = ChatModel;
|
|
282
345
|
|
|
283
346
|
/**
|
|
284
347
|
* Internal configuration for the SAP AI Chat Language Model.
|
|
285
348
|
* @internal
|
|
286
349
|
*/
|
|
287
350
|
interface SAPAIConfig {
|
|
288
|
-
|
|
289
|
-
deploymentConfig: ResourceGroupConfig | DeploymentIdConfig;
|
|
351
|
+
deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
290
352
|
destination?: HttpDestinationOrFetchOptions;
|
|
353
|
+
provider: string;
|
|
291
354
|
}
|
|
292
355
|
/**
|
|
293
356
|
* SAP AI Chat Language Model implementation.
|
|
294
357
|
*
|
|
295
|
-
* This class implements the AI SDK's `
|
|
358
|
+
* This class implements the AI SDK's `LanguageModelV3` interface,
|
|
296
359
|
* providing a bridge between the AI SDK and SAP AI Core's Orchestration API
|
|
297
360
|
* using the official SAP AI SDK (@sap-ai-sdk/orchestration).
|
|
298
361
|
*
|
|
@@ -309,6 +372,9 @@ interface SAPAIConfig {
|
|
|
309
372
|
* - AWS Bedrock models (anthropic--claude-*, amazon--nova-*, etc.)
|
|
310
373
|
* - AI Core open source models (mistralai--, cohere--, etc.)
|
|
311
374
|
*
|
|
375
|
+
* @see {@link https://sdk.vercel.ai/docs/ai-sdk-core/language-model-v3 Vercel AI SDK LanguageModelV3}
|
|
376
|
+
* @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/orchestration SAP AI Core Orchestration}
|
|
377
|
+
*
|
|
312
378
|
* @example
|
|
313
379
|
* ```typescript
|
|
314
380
|
* // Create via provider
|
|
@@ -322,43 +388,11 @@ interface SAPAIConfig {
|
|
|
322
388
|
* });
|
|
323
389
|
* ```
|
|
324
390
|
*
|
|
325
|
-
* @implements {
|
|
391
|
+
* @implements {LanguageModelV3}
|
|
326
392
|
*/
|
|
327
|
-
declare class
|
|
328
|
-
readonly specificationVersion = "v2";
|
|
393
|
+
declare class SAPAILanguageModel implements LanguageModelV3 {
|
|
329
394
|
readonly modelId: SAPAIModelId;
|
|
330
|
-
|
|
331
|
-
private readonly settings;
|
|
332
|
-
/**
|
|
333
|
-
* Creates a new SAP AI Chat Language Model instance.
|
|
334
|
-
*
|
|
335
|
-
* @param modelId - The model identifier
|
|
336
|
-
* @param settings - Model-specific configuration settings
|
|
337
|
-
* @param config - Internal configuration (deployment config, destination, etc.)
|
|
338
|
-
*
|
|
339
|
-
* @internal This constructor is not meant to be called directly.
|
|
340
|
-
* Use the provider function instead.
|
|
341
|
-
*/
|
|
342
|
-
constructor(modelId: SAPAIModelId, settings: SAPAISettings, config: SAPAIConfig);
|
|
343
|
-
/**
|
|
344
|
-
* Checks if a URL is supported for file/image uploads.
|
|
345
|
-
*
|
|
346
|
-
* @param url - The URL to check
|
|
347
|
-
* @returns True if the URL protocol is HTTPS or data (content-type rules are enforced via supportedUrls)
|
|
348
|
-
*/
|
|
349
|
-
supportsUrl(url: URL): boolean;
|
|
350
|
-
/**
|
|
351
|
-
* Returns supported URL patterns for different content types.
|
|
352
|
-
*
|
|
353
|
-
* @returns Record of content types to regex patterns
|
|
354
|
-
*/
|
|
355
|
-
get supportedUrls(): Record<string, RegExp[]>;
|
|
356
|
-
/**
|
|
357
|
-
* Gets the provider identifier.
|
|
358
|
-
*
|
|
359
|
-
* @returns The provider name ('sap-ai')
|
|
360
|
-
*/
|
|
361
|
-
get provider(): string;
|
|
395
|
+
readonly specificationVersion = "v3";
|
|
362
396
|
/**
|
|
363
397
|
* Model capabilities.
|
|
364
398
|
*
|
|
@@ -367,36 +401,81 @@ declare class SAPAIChatLanguageModel implements LanguageModelV2 {
|
|
|
367
401
|
* SAP AI Core will fail the request at runtime.
|
|
368
402
|
*/
|
|
369
403
|
readonly supportsImageUrls: boolean;
|
|
370
|
-
/** Structured JSON outputs (json_schema response format). */
|
|
371
|
-
readonly supportsStructuredOutputs: boolean;
|
|
372
|
-
/** Tool/function calling. */
|
|
373
|
-
readonly supportsToolCalls: boolean;
|
|
374
|
-
/** Streaming responses. */
|
|
375
|
-
readonly supportsStreaming: boolean;
|
|
376
404
|
/** Multiple completions via the `n` parameter (provider-specific support). */
|
|
377
405
|
readonly supportsMultipleCompletions: boolean;
|
|
378
406
|
/** Parallel tool calls. */
|
|
379
407
|
readonly supportsParallelToolCalls: boolean;
|
|
408
|
+
/** Streaming responses. */
|
|
409
|
+
readonly supportsStreaming: boolean;
|
|
410
|
+
/** Structured JSON outputs (json_schema response format). */
|
|
411
|
+
readonly supportsStructuredOutputs: boolean;
|
|
412
|
+
/** Tool/function calling. */
|
|
413
|
+
readonly supportsToolCalls: boolean;
|
|
380
414
|
/**
|
|
381
|
-
*
|
|
415
|
+
* Generates text completion using SAP AI Core's Orchestration API.
|
|
382
416
|
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
417
|
+
* This method implements the `LanguageModelV3.doGenerate` interface,
|
|
418
|
+
* providing synchronous (non-streaming) text generation with support for:
|
|
419
|
+
* - Multi-turn conversations with system/user/assistant messages
|
|
420
|
+
* - Tool calling (function calling) with structured outputs
|
|
421
|
+
* - Multi-modal inputs (text + images)
|
|
422
|
+
* - Data masking via SAP DPI
|
|
423
|
+
* - Content filtering via Azure Content Safety or Llama Guard
|
|
424
|
+
*
|
|
425
|
+
* **Return Structure:**
|
|
426
|
+
* - Finish reason: `{ unified: string, raw?: string }`
|
|
427
|
+
* - Usage: Nested structure with token breakdown `{ inputTokens: { total, ... }, outputTokens: { total, ... } }`
|
|
428
|
+
* - Warnings: Array of warnings with `type` and optional `feature` field
|
|
429
|
+
*
|
|
430
|
+
* @param options - Generation options including prompt, tools, temperature, etc.
|
|
431
|
+
* @returns Promise resolving to generation result with content, usage, and metadata
|
|
432
|
+
*
|
|
433
|
+
* @throws {InvalidPromptError} If prompt format is invalid
|
|
434
|
+
* @throws {InvalidArgumentError} If arguments are malformed
|
|
435
|
+
* @throws {APICallError} If the SAP AI Core API call fails
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ```typescript
|
|
439
|
+
* const result = await model.doGenerate({
|
|
440
|
+
* prompt: [
|
|
441
|
+
* { role: 'user', content: [{ type: 'text', text: 'Hello!' }] }
|
|
442
|
+
* ],
|
|
443
|
+
* temperature: 0.7,
|
|
444
|
+
* maxTokens: 100
|
|
445
|
+
* });
|
|
446
|
+
*
|
|
447
|
+
* console.log(result.content); // Array of V3 content parts
|
|
448
|
+
* console.log(result.finishReason.unified); // "stop", "length", "tool-calls", etc.
|
|
449
|
+
* console.log(result.usage.inputTokens.total); // Total input tokens
|
|
450
|
+
* ```
|
|
451
|
+
*
|
|
452
|
+
* @since 1.0.0
|
|
453
|
+
* @since 4.0.0 Updated to LanguageModelV3 interface
|
|
386
454
|
*/
|
|
387
|
-
|
|
455
|
+
get provider(): string;
|
|
388
456
|
/**
|
|
389
|
-
*
|
|
457
|
+
* Returns supported URL patterns for different content types.
|
|
390
458
|
*
|
|
391
|
-
* @
|
|
392
|
-
* @returns OrchestrationClient instance
|
|
393
|
-
* @internal
|
|
459
|
+
* @returns Record of content types to regex patterns
|
|
394
460
|
*/
|
|
395
|
-
|
|
461
|
+
get supportedUrls(): Record<string, RegExp[]>;
|
|
462
|
+
private readonly config;
|
|
463
|
+
private readonly settings;
|
|
464
|
+
/**
|
|
465
|
+
* Creates a new SAP AI Chat Language Model instance.
|
|
466
|
+
*
|
|
467
|
+
* @param modelId - The model identifier
|
|
468
|
+
* @param settings - Model-specific configuration settings
|
|
469
|
+
* @param config - Internal configuration (deployment config, destination, etc.)
|
|
470
|
+
*
|
|
471
|
+
* @internal This constructor is not meant to be called directly.
|
|
472
|
+
* Use the provider function instead.
|
|
473
|
+
*/
|
|
474
|
+
constructor(modelId: SAPAIModelId, settings: SAPAISettings, config: SAPAIConfig);
|
|
396
475
|
/**
|
|
397
476
|
* Generates a single completion (non-streaming).
|
|
398
477
|
*
|
|
399
|
-
* This method implements the `
|
|
478
|
+
* This method implements the `LanguageModelV3.doGenerate` interface,
|
|
400
479
|
* sending a request to SAP AI Core and returning the complete response.
|
|
401
480
|
*
|
|
402
481
|
* **Features:**
|
|
@@ -404,6 +483,13 @@ declare class SAPAIChatLanguageModel implements LanguageModelV2 {
|
|
|
404
483
|
* - Multi-modal input (text + images)
|
|
405
484
|
* - Data masking (if configured)
|
|
406
485
|
* - Content filtering (if configured)
|
|
486
|
+
* - Abort signal support (via Promise.race)
|
|
487
|
+
*
|
|
488
|
+
* **Note on Abort Signal:**
|
|
489
|
+
* The abort signal implementation uses Promise.race to reject the promise when
|
|
490
|
+
* the signal is aborted. However, this does not cancel the underlying HTTP request
|
|
491
|
+
* to SAP AI Core - the request continues executing on the server. This is a
|
|
492
|
+
* limitation of the SAP AI SDK's chatCompletion API.
|
|
407
493
|
*
|
|
408
494
|
* @param options - Generation options including prompt, tools, and settings
|
|
409
495
|
* @returns Promise resolving to the generation result with content, usage, and metadata
|
|
@@ -420,38 +506,34 @@ declare class SAPAIChatLanguageModel implements LanguageModelV2 {
|
|
|
420
506
|
* console.log(result.usage); // Token usage
|
|
421
507
|
* ```
|
|
422
508
|
*/
|
|
423
|
-
doGenerate(options:
|
|
424
|
-
content: LanguageModelV2Content[];
|
|
425
|
-
finishReason: LanguageModelV2FinishReason;
|
|
426
|
-
usage: LanguageModelV2Usage;
|
|
427
|
-
providerMetadata?: Record<string, Record<string, JSONValue>>;
|
|
428
|
-
request: {
|
|
429
|
-
body?: unknown;
|
|
430
|
-
};
|
|
431
|
-
response: {
|
|
432
|
-
timestamp: Date;
|
|
433
|
-
modelId: string;
|
|
434
|
-
headers?: Record<string, string>;
|
|
435
|
-
body?: unknown;
|
|
436
|
-
};
|
|
437
|
-
warnings: LanguageModelV2CallWarning[];
|
|
438
|
-
}>;
|
|
509
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
439
510
|
/**
|
|
440
511
|
* Generates a streaming completion.
|
|
441
512
|
*
|
|
442
|
-
* This method implements the `
|
|
513
|
+
* This method implements the `LanguageModelV3.doStream` interface,
|
|
443
514
|
* sending a streaming request to SAP AI Core and returning a stream of response parts.
|
|
444
515
|
*
|
|
445
516
|
* **Stream Events:**
|
|
446
|
-
* - `stream-start` - Stream initialization
|
|
517
|
+
* - `stream-start` - Stream initialization with warnings
|
|
447
518
|
* - `response-metadata` - Response metadata (model, timestamp)
|
|
448
|
-
* - `text-start` - Text
|
|
449
|
-
* - `text-delta` - Incremental text chunks
|
|
450
|
-
* - `text-end` - Text
|
|
451
|
-
* - `tool-
|
|
519
|
+
* - `text-start` - Text block begins (with unique ID)
|
|
520
|
+
* - `text-delta` - Incremental text chunks (with block ID)
|
|
521
|
+
* - `text-end` - Text block completes (with accumulated text)
|
|
522
|
+
* - `tool-input-start` - Tool input begins
|
|
523
|
+
* - `tool-input-delta` - Tool input chunk
|
|
524
|
+
* - `tool-input-end` - Tool input completes
|
|
525
|
+
* - `tool-call` - Complete tool call
|
|
452
526
|
* - `finish` - Stream completes with usage and finish reason
|
|
453
527
|
* - `error` - Error occurred
|
|
454
528
|
*
|
|
529
|
+
* **Stream Structure:**
|
|
530
|
+
* - Text blocks have explicit lifecycle with unique IDs
|
|
531
|
+
* - Finish reason format: `{ unified: string, raw?: string }`
|
|
532
|
+
* - Usage format: `{ inputTokens: { total, ... }, outputTokens: { total, ... } }`
|
|
533
|
+
* - Warnings only in `stream-start` event
|
|
534
|
+
*
|
|
535
|
+
* @see {@link https://sdk.vercel.ai/docs/ai-sdk-core/streaming Vercel AI SDK Streaming}
|
|
536
|
+
*
|
|
455
537
|
* @param options - Streaming options including prompt, tools, and settings
|
|
456
538
|
* @returns Promise resolving to stream and request metadata
|
|
457
539
|
*
|
|
@@ -467,26 +549,49 @@ declare class SAPAIChatLanguageModel implements LanguageModelV2 {
|
|
|
467
549
|
* if (part.type === 'text-delta') {
|
|
468
550
|
* process.stdout.write(part.delta);
|
|
469
551
|
* }
|
|
552
|
+
* if (part.type === 'text-end') {
|
|
553
|
+
* console.log('Block complete:', part.id, part.text);
|
|
554
|
+
* }
|
|
470
555
|
* }
|
|
471
556
|
* ```
|
|
557
|
+
*
|
|
558
|
+
* @since 4.0.0
|
|
472
559
|
*/
|
|
473
|
-
doStream(options:
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
560
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
561
|
+
/**
|
|
562
|
+
* Checks if a URL is supported for file/image uploads.
|
|
563
|
+
*
|
|
564
|
+
* @param url - The URL to check
|
|
565
|
+
* @returns True if the URL protocol is HTTPS or data with valid image format
|
|
566
|
+
*/
|
|
567
|
+
supportsUrl(url: URL): boolean;
|
|
568
|
+
/**
|
|
569
|
+
* Builds orchestration module config for SAP AI SDK.
|
|
570
|
+
*
|
|
571
|
+
* @param options - Call options from the AI SDK
|
|
572
|
+
* @returns Object containing orchestration config, messages, and warnings
|
|
573
|
+
* @internal
|
|
574
|
+
*/
|
|
575
|
+
private buildOrchestrationConfig;
|
|
576
|
+
/**
|
|
577
|
+
* Creates an OrchestrationClient instance.
|
|
578
|
+
*
|
|
579
|
+
* @param config - Orchestration module configuration
|
|
580
|
+
* @returns OrchestrationClient instance
|
|
581
|
+
* @internal
|
|
582
|
+
*/
|
|
583
|
+
private createClient;
|
|
483
584
|
}
|
|
484
585
|
|
|
586
|
+
/**
|
|
587
|
+
* Deployment configuration type used by SAP AI SDK.
|
|
588
|
+
*/
|
|
589
|
+
type DeploymentConfig = DeploymentIdConfig | ResourceGroupConfig;
|
|
485
590
|
/**
|
|
486
591
|
* SAP AI Provider interface.
|
|
487
592
|
*
|
|
488
593
|
* This is the main interface for creating and configuring SAP AI Core models.
|
|
489
|
-
* It extends the standard AI SDK
|
|
594
|
+
* It extends the standard AI SDK ProviderV3 interface with SAP-specific functionality.
|
|
490
595
|
*
|
|
491
596
|
* @example
|
|
492
597
|
* ```typescript
|
|
@@ -506,7 +611,7 @@ declare class SAPAIChatLanguageModel implements LanguageModelV2 {
|
|
|
506
611
|
* const chatModel = provider.chat('gpt-4o');
|
|
507
612
|
* ```
|
|
508
613
|
*/
|
|
509
|
-
interface SAPAIProvider extends
|
|
614
|
+
interface SAPAIProvider extends ProviderV3 {
|
|
510
615
|
/**
|
|
511
616
|
* Create a language model instance.
|
|
512
617
|
*
|
|
@@ -514,7 +619,7 @@ interface SAPAIProvider extends ProviderV2 {
|
|
|
514
619
|
* @param settings - Optional model configuration settings
|
|
515
620
|
* @returns Configured SAP AI chat language model instance
|
|
516
621
|
*/
|
|
517
|
-
(modelId: SAPAIModelId, settings?: SAPAISettings):
|
|
622
|
+
(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAILanguageModel;
|
|
518
623
|
/**
|
|
519
624
|
* Explicit method for creating chat models.
|
|
520
625
|
*
|
|
@@ -525,7 +630,7 @@ interface SAPAIProvider extends ProviderV2 {
|
|
|
525
630
|
* @param settings - Optional model configuration settings
|
|
526
631
|
* @returns Configured SAP AI chat language model instance
|
|
527
632
|
*/
|
|
528
|
-
chat(modelId: SAPAIModelId, settings?: SAPAISettings):
|
|
633
|
+
chat(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAILanguageModel;
|
|
529
634
|
}
|
|
530
635
|
/**
|
|
531
636
|
* Configuration settings for the SAP AI Provider.
|
|
@@ -554,28 +659,10 @@ interface SAPAIProvider extends ProviderV2 {
|
|
|
554
659
|
*/
|
|
555
660
|
interface SAPAIProviderSettings {
|
|
556
661
|
/**
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
* When enabled (default), the provider will warn when mutually-exclusive
|
|
560
|
-
* settings are provided (e.g. both `deploymentId` and `resourceGroup`).
|
|
561
|
-
*/
|
|
562
|
-
warnOnAmbiguousConfig?: boolean;
|
|
563
|
-
/**
|
|
564
|
-
* SAP AI Core resource group.
|
|
565
|
-
*
|
|
566
|
-
* Logical grouping of AI resources in SAP AI Core.
|
|
567
|
-
* Used for resource isolation and access control.
|
|
568
|
-
* Different resource groups can have different permissions and quotas.
|
|
569
|
-
*
|
|
570
|
-
* @default 'default'
|
|
571
|
-
* @example
|
|
572
|
-
* ```typescript
|
|
573
|
-
* resourceGroup: 'default' // Default resource group
|
|
574
|
-
* resourceGroup: 'production' // Production environment
|
|
575
|
-
* resourceGroup: 'development' // Development environment
|
|
576
|
-
* ```
|
|
662
|
+
* Default model settings applied to every model instance created by this provider.
|
|
663
|
+
* Per-call settings provided to the model will override these.
|
|
577
664
|
*/
|
|
578
|
-
|
|
665
|
+
defaultSettings?: SAPAISettings;
|
|
579
666
|
/**
|
|
580
667
|
* SAP AI Core deployment ID.
|
|
581
668
|
*
|
|
@@ -605,15 +692,29 @@ interface SAPAIProviderSettings {
|
|
|
605
692
|
*/
|
|
606
693
|
destination?: HttpDestinationOrFetchOptions;
|
|
607
694
|
/**
|
|
608
|
-
*
|
|
609
|
-
*
|
|
695
|
+
* SAP AI Core resource group.
|
|
696
|
+
*
|
|
697
|
+
* Logical grouping of AI resources in SAP AI Core.
|
|
698
|
+
* Used for resource isolation and access control.
|
|
699
|
+
* Different resource groups can have different permissions and quotas.
|
|
700
|
+
*
|
|
701
|
+
* @default 'default'
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* resourceGroup: 'default' // Default resource group
|
|
705
|
+
* resourceGroup: 'production' // Production environment
|
|
706
|
+
* resourceGroup: 'development' // Development environment
|
|
707
|
+
* ```
|
|
610
708
|
*/
|
|
611
|
-
|
|
709
|
+
resourceGroup?: string;
|
|
710
|
+
/**
|
|
711
|
+
* Whether to emit warnings for ambiguous configurations.
|
|
712
|
+
*
|
|
713
|
+
* When enabled (default), the provider will warn when mutually-exclusive
|
|
714
|
+
* settings are provided (e.g. both `deploymentId` and `resourceGroup`).
|
|
715
|
+
*/
|
|
716
|
+
warnOnAmbiguousConfig?: boolean;
|
|
612
717
|
}
|
|
613
|
-
/**
|
|
614
|
-
* Deployment configuration type used by SAP AI SDK.
|
|
615
|
-
*/
|
|
616
|
-
type DeploymentConfig = ResourceGroupConfig | DeploymentIdConfig;
|
|
617
718
|
/**
|
|
618
719
|
* Creates a SAP AI Core provider instance for use with the AI SDK.
|
|
619
720
|
*
|