@jerome-benoit/sap-ai-provider 3.0.0-rc.2 → 3.0.0-rc.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/package.json +3 -3
- package/dist/index.d.mts +0 -651
- package/dist/index.mjs +0 -687
- package/dist/index.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jerome-benoit/sap-ai-provider",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SAP AI Core provider for AI SDK (powered by @sap-ai-sdk/orchestration)",
|
|
6
6
|
"keywords": [
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@ai-sdk/provider": "^3.0.2",
|
|
69
69
|
"@ai-sdk/provider-utils": "^4.0.5",
|
|
70
|
-
"@sap-ai-sdk/orchestration": "^2.
|
|
70
|
+
"@sap-ai-sdk/orchestration": "^2.5.0",
|
|
71
71
|
"zod": "^4.3.5",
|
|
72
72
|
"zod-to-json-schema": "^3.25.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@edge-runtime/vm": "^5.0.0",
|
|
76
76
|
"@eslint/js": "^9.39.2",
|
|
77
|
-
"@types/node": "^25.0.
|
|
77
|
+
"@types/node": "^25.0.8",
|
|
78
78
|
"dotenv": "^17.2.3",
|
|
79
79
|
"eslint": "^9.39.2",
|
|
80
80
|
"globals": "^17.0.0",
|
package/dist/index.d.mts
DELETED
|
@@ -1,651 +0,0 @@
|
|
|
1
|
-
import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2StreamPart, ProviderV2 } from '@ai-sdk/provider';
|
|
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, OrchestrationErrorResponse } from '@sap-ai-sdk/orchestration';
|
|
5
|
-
export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMessage, DeveloperChatMessage, FilteringModule, FunctionObject, GroundingModule, LlmModelDetails, LlmModelParams, MaskingModule, OrchestrationClient, OrchestrationErrorResponse, OrchestrationModuleConfig, OrchestrationResponse, OrchestrationStreamChunkResponse, OrchestrationStreamResponse, PromptTemplatingModule, SystemChatMessage, ToolChatMessage, TranslationModule, UserChatMessage, buildAzureContentSafetyFilter, buildDocumentGroundingConfig, buildDpiMaskingProvider, buildLlamaGuard38BFilter, buildTranslationConfig } from '@sap-ai-sdk/orchestration';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Settings for configuring SAP AI Core model behavior.
|
|
9
|
-
*/
|
|
10
|
-
interface SAPAISettings {
|
|
11
|
-
/**
|
|
12
|
-
* Specific version of the model to use.
|
|
13
|
-
* If not provided, the latest version will be used.
|
|
14
|
-
*/
|
|
15
|
-
modelVersion?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Model generation parameters that control the output.
|
|
18
|
-
*/
|
|
19
|
-
modelParams?: {
|
|
20
|
-
/**
|
|
21
|
-
* Maximum number of tokens to generate.
|
|
22
|
-
* Higher values allow for longer responses but increase latency and cost.
|
|
23
|
-
*/
|
|
24
|
-
maxTokens?: number;
|
|
25
|
-
/**
|
|
26
|
-
* Sampling temperature between 0 and 2.
|
|
27
|
-
* Higher values make output more random, lower values more deterministic.
|
|
28
|
-
* No default; omitted when unspecified or unsupported by the target model.
|
|
29
|
-
*/
|
|
30
|
-
temperature?: number;
|
|
31
|
-
/**
|
|
32
|
-
* Nucleus sampling parameter between 0 and 1.
|
|
33
|
-
* Controls diversity via cumulative probability cutoff.
|
|
34
|
-
* @default 1
|
|
35
|
-
*/
|
|
36
|
-
topP?: number;
|
|
37
|
-
/**
|
|
38
|
-
* Frequency penalty between -2.0 and 2.0.
|
|
39
|
-
* Positive values penalize tokens based on their frequency.
|
|
40
|
-
* @default 0
|
|
41
|
-
*/
|
|
42
|
-
frequencyPenalty?: number;
|
|
43
|
-
/**
|
|
44
|
-
* Presence penalty between -2.0 and 2.0.
|
|
45
|
-
* Positive values penalize tokens that have appeared in the text.
|
|
46
|
-
* @default 0
|
|
47
|
-
*/
|
|
48
|
-
presencePenalty?: number;
|
|
49
|
-
/**
|
|
50
|
-
* Number of completions to generate.
|
|
51
|
-
* Multiple completions provide alternative responses.
|
|
52
|
-
* Note: Not supported by Amazon and Anthropic models.
|
|
53
|
-
* @default 1
|
|
54
|
-
*/
|
|
55
|
-
n?: number;
|
|
56
|
-
/**
|
|
57
|
-
* Whether to enable parallel tool calls.
|
|
58
|
-
* When enabled, the model can call multiple tools in parallel.
|
|
59
|
-
*/
|
|
60
|
-
parallel_tool_calls?: boolean;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Masking configuration for SAP AI Core orchestration.
|
|
64
|
-
* When provided, sensitive information in prompts can be anonymized or
|
|
65
|
-
* pseudonymized by SAP Data Privacy Integration (DPI).
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* import { buildDpiMaskingProvider } from '@sap-ai-sdk/orchestration';
|
|
70
|
-
*
|
|
71
|
-
* const model = provider('gpt-4o', {
|
|
72
|
-
* masking: {
|
|
73
|
-
* masking_providers: [
|
|
74
|
-
* buildDpiMaskingProvider({
|
|
75
|
-
* method: 'anonymization',
|
|
76
|
-
* entities: ['profile-email', 'profile-phone']
|
|
77
|
-
* })
|
|
78
|
-
* ]
|
|
79
|
-
* }
|
|
80
|
-
* });
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
masking?: MaskingModule;
|
|
84
|
-
/**
|
|
85
|
-
* Filtering configuration for input and output content safety.
|
|
86
|
-
* Supports Azure Content Safety and Llama Guard filters.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* import { buildAzureContentSafetyFilter } from '@sap-ai-sdk/orchestration';
|
|
91
|
-
*
|
|
92
|
-
* const model = provider('gpt-4o', {
|
|
93
|
-
* filtering: {
|
|
94
|
-
* input: {
|
|
95
|
-
* filters: [
|
|
96
|
-
* buildAzureContentSafetyFilter('input', {
|
|
97
|
-
* hate: 'ALLOW_SAFE',
|
|
98
|
-
* violence: 'ALLOW_SAFE_LOW_MEDIUM'
|
|
99
|
-
* })
|
|
100
|
-
* ]
|
|
101
|
-
* }
|
|
102
|
-
* }
|
|
103
|
-
* });
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
filtering?: FilteringModule;
|
|
107
|
-
/**
|
|
108
|
-
* Response format for templating prompt (OpenAI-compatible).
|
|
109
|
-
* Allows specifying structured output formats.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```typescript
|
|
113
|
-
* const model = provider('gpt-4o', {
|
|
114
|
-
* responseFormat: {
|
|
115
|
-
* type: 'json_schema',
|
|
116
|
-
* json_schema: {
|
|
117
|
-
* name: 'response',
|
|
118
|
-
* schema: { type: 'object', properties: { answer: { type: 'string' } } }
|
|
119
|
-
* }
|
|
120
|
-
* }
|
|
121
|
-
* });
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
responseFormat?: {
|
|
125
|
-
type: "text";
|
|
126
|
-
} | {
|
|
127
|
-
type: "json_object";
|
|
128
|
-
} | {
|
|
129
|
-
type: "json_schema";
|
|
130
|
-
json_schema: {
|
|
131
|
-
name: string;
|
|
132
|
-
description?: string;
|
|
133
|
-
schema?: unknown;
|
|
134
|
-
strict?: boolean | null;
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Tool definitions in SAP AI SDK format.
|
|
139
|
-
*
|
|
140
|
-
* Use this to pass tools directly with proper JSON Schema definitions.
|
|
141
|
-
* This bypasses the AI SDK's Zod conversion which may have issues.
|
|
142
|
-
*
|
|
143
|
-
* Note: This should be used in conjunction with AI SDK's tool handling
|
|
144
|
-
* to provide the actual tool implementations (execute functions).
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```typescript
|
|
148
|
-
* const model = provider('gpt-4o', {
|
|
149
|
-
* tools: [
|
|
150
|
-
* {
|
|
151
|
-
* type: 'function',
|
|
152
|
-
* function: {
|
|
153
|
-
* name: 'get_weather',
|
|
154
|
-
* description: 'Get weather for a location',
|
|
155
|
-
* parameters: {
|
|
156
|
-
* type: 'object',
|
|
157
|
-
* properties: {
|
|
158
|
-
* location: { type: 'string', description: 'City name' }
|
|
159
|
-
* },
|
|
160
|
-
* required: ['location']
|
|
161
|
-
* }
|
|
162
|
-
* }
|
|
163
|
-
* }
|
|
164
|
-
* ]
|
|
165
|
-
* });
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
tools?: ChatCompletionTool[];
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Supported model IDs in SAP AI Core.
|
|
172
|
-
*
|
|
173
|
-
* These models are available through the SAP AI Core Orchestration service.
|
|
174
|
-
* Model availability depends on your subscription and region.
|
|
175
|
-
*
|
|
176
|
-
* **Azure OpenAI Models:**
|
|
177
|
-
* - gpt-4o, gpt-4o-mini
|
|
178
|
-
* - gpt-4.1, gpt-4.1-mini, gpt-4.1-nano
|
|
179
|
-
* - o1, o3, o3-mini, o4-mini
|
|
180
|
-
*
|
|
181
|
-
* **Google Vertex AI Models:**
|
|
182
|
-
* - gemini-2.0-flash, gemini-2.0-flash-lite
|
|
183
|
-
* - gemini-2.5-flash, gemini-2.5-pro
|
|
184
|
-
*
|
|
185
|
-
* **AWS Bedrock Models:**
|
|
186
|
-
* - anthropic--claude-3-haiku, anthropic--claude-3-sonnet, anthropic--claude-3-opus
|
|
187
|
-
* - anthropic--claude-3.5-sonnet, anthropic--claude-3.7-sonnet
|
|
188
|
-
* - anthropic--claude-4-sonnet, anthropic--claude-4-opus
|
|
189
|
-
* - amazon--nova-pro, amazon--nova-lite, amazon--nova-micro, amazon--nova-premier
|
|
190
|
-
*
|
|
191
|
-
* **AI Core Open Source Models:**
|
|
192
|
-
* - mistralai--mistral-large-instruct, mistralai--mistral-medium-instruct, mistralai--mistral-small-instruct
|
|
193
|
-
* - cohere--command-a-reasoning
|
|
194
|
-
*/
|
|
195
|
-
type SAPAIModelId = ChatModel;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Internal configuration for the SAP AI Chat Language Model.
|
|
199
|
-
* @internal
|
|
200
|
-
*/
|
|
201
|
-
interface SAPAIConfig {
|
|
202
|
-
/** Provider identifier */
|
|
203
|
-
provider: string;
|
|
204
|
-
/** Deployment configuration for SAP AI SDK */
|
|
205
|
-
deploymentConfig: ResourceGroupConfig | DeploymentIdConfig;
|
|
206
|
-
/** Optional custom destination */
|
|
207
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* SAP AI Chat Language Model implementation.
|
|
211
|
-
*
|
|
212
|
-
* This class implements the Vercel AI SDK's `LanguageModelV2` interface,
|
|
213
|
-
* providing a bridge between the AI SDK and SAP AI Core's Orchestration API
|
|
214
|
-
* using the official SAP AI SDK (@sap-ai-sdk/orchestration).
|
|
215
|
-
*
|
|
216
|
-
* **Features:**
|
|
217
|
-
* - Text generation (streaming and non-streaming)
|
|
218
|
-
* - Tool calling (function calling)
|
|
219
|
-
* - Multi-modal input (text + images)
|
|
220
|
-
* - Data masking (SAP DPI)
|
|
221
|
-
* - Content filtering
|
|
222
|
-
*
|
|
223
|
-
* **Model Support:**
|
|
224
|
-
* - Azure OpenAI models (gpt-4o, gpt-4o-mini, o1, o3, etc.)
|
|
225
|
-
* - Google Vertex AI models (gemini-2.0-flash, gemini-2.5-pro, etc.)
|
|
226
|
-
* - AWS Bedrock models (anthropic--claude-*, amazon--nova-*, etc.)
|
|
227
|
-
* - AI Core open source models (mistralai--, cohere--, etc.)
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* // Create via provider
|
|
232
|
-
* const provider = createSAPAIProvider();
|
|
233
|
-
* const model = provider('gpt-4o');
|
|
234
|
-
*
|
|
235
|
-
* // Use with AI SDK
|
|
236
|
-
* const result = await generateText({
|
|
237
|
-
* model,
|
|
238
|
-
* prompt: 'Hello, world!'
|
|
239
|
-
* });
|
|
240
|
-
* ```
|
|
241
|
-
*
|
|
242
|
-
* @implements {LanguageModelV2}
|
|
243
|
-
*/
|
|
244
|
-
declare class SAPAIChatLanguageModel implements LanguageModelV2 {
|
|
245
|
-
/** AI SDK specification version */
|
|
246
|
-
readonly specificationVersion = "v2";
|
|
247
|
-
/** Default object generation mode */
|
|
248
|
-
readonly defaultObjectGenerationMode = "json";
|
|
249
|
-
/** Whether the model supports image URLs */
|
|
250
|
-
readonly supportsImageUrls = true;
|
|
251
|
-
/** The model identifier (e.g., 'gpt-4o', 'anthropic--claude-3.5-sonnet') */
|
|
252
|
-
readonly modelId: SAPAIModelId;
|
|
253
|
-
/** Whether the model supports structured outputs */
|
|
254
|
-
readonly supportsStructuredOutputs = true;
|
|
255
|
-
/** Internal configuration */
|
|
256
|
-
private readonly config;
|
|
257
|
-
/** Model-specific settings */
|
|
258
|
-
private readonly settings;
|
|
259
|
-
/**
|
|
260
|
-
* Creates a new SAP AI Chat Language Model instance.
|
|
261
|
-
*
|
|
262
|
-
* @param modelId - The model identifier
|
|
263
|
-
* @param settings - Model-specific configuration settings
|
|
264
|
-
* @param config - Internal configuration (deployment config, destination, etc.)
|
|
265
|
-
*
|
|
266
|
-
* @internal This constructor is not meant to be called directly.
|
|
267
|
-
* Use the provider function instead.
|
|
268
|
-
*/
|
|
269
|
-
constructor(modelId: SAPAIModelId, settings: SAPAISettings, config: SAPAIConfig);
|
|
270
|
-
/**
|
|
271
|
-
* Checks if a URL is supported for file/image uploads.
|
|
272
|
-
*
|
|
273
|
-
* @param url - The URL to check
|
|
274
|
-
* @returns True if the URL protocol is HTTPS
|
|
275
|
-
*/
|
|
276
|
-
supportsUrl(url: URL): boolean;
|
|
277
|
-
/**
|
|
278
|
-
* Returns supported URL patterns for different content types.
|
|
279
|
-
*
|
|
280
|
-
* @returns Record of content types to regex patterns
|
|
281
|
-
*/
|
|
282
|
-
get supportedUrls(): Record<string, RegExp[]>;
|
|
283
|
-
/**
|
|
284
|
-
* Gets the provider identifier.
|
|
285
|
-
*
|
|
286
|
-
* @returns The provider name ('sap-ai')
|
|
287
|
-
*/
|
|
288
|
-
get provider(): string;
|
|
289
|
-
/**
|
|
290
|
-
* Builds orchestration module config for SAP AI SDK.
|
|
291
|
-
*
|
|
292
|
-
* @param options - Call options from the AI SDK
|
|
293
|
-
* @returns Object containing orchestration config and warnings
|
|
294
|
-
*
|
|
295
|
-
* @internal
|
|
296
|
-
*/
|
|
297
|
-
private buildOrchestrationConfig;
|
|
298
|
-
/**
|
|
299
|
-
* Creates an OrchestrationClient instance.
|
|
300
|
-
*
|
|
301
|
-
* @param config - Orchestration module configuration
|
|
302
|
-
* @returns OrchestrationClient instance
|
|
303
|
-
*
|
|
304
|
-
* @internal
|
|
305
|
-
*/
|
|
306
|
-
private createClient;
|
|
307
|
-
/**
|
|
308
|
-
* Generates a single completion (non-streaming).
|
|
309
|
-
*
|
|
310
|
-
* This method implements the `LanguageModelV2.doGenerate` interface,
|
|
311
|
-
* sending a request to SAP AI Core and returning the complete response.
|
|
312
|
-
*
|
|
313
|
-
* **Features:**
|
|
314
|
-
* - Tool calling support
|
|
315
|
-
* - Multi-modal input (text + images)
|
|
316
|
-
* - Data masking (if configured)
|
|
317
|
-
* - Content filtering (if configured)
|
|
318
|
-
*
|
|
319
|
-
* @param options - Generation options including prompt, tools, and settings
|
|
320
|
-
* @returns Promise resolving to the generation result with content, usage, and metadata
|
|
321
|
-
*
|
|
322
|
-
* @example
|
|
323
|
-
* ```typescript
|
|
324
|
-
* const result = await model.doGenerate({
|
|
325
|
-
* prompt: [
|
|
326
|
-
* { role: 'user', content: [{ type: 'text', text: 'Hello!' }] }
|
|
327
|
-
* ]
|
|
328
|
-
* });
|
|
329
|
-
*
|
|
330
|
-
* console.log(result.content); // Generated content
|
|
331
|
-
* console.log(result.usage); // Token usage
|
|
332
|
-
* ```
|
|
333
|
-
*/
|
|
334
|
-
doGenerate(options: LanguageModelV2CallOptions): Promise<{
|
|
335
|
-
content: LanguageModelV2Content[];
|
|
336
|
-
finishReason: LanguageModelV2FinishReason;
|
|
337
|
-
usage: LanguageModelV2Usage;
|
|
338
|
-
rawCall: {
|
|
339
|
-
rawPrompt: unknown;
|
|
340
|
-
rawSettings: Record<string, unknown>;
|
|
341
|
-
};
|
|
342
|
-
warnings: LanguageModelV2CallWarning[];
|
|
343
|
-
}>;
|
|
344
|
-
/**
|
|
345
|
-
* Generates a streaming completion.
|
|
346
|
-
*
|
|
347
|
-
* This method implements the `LanguageModelV2.doStream` interface,
|
|
348
|
-
* sending a streaming request to SAP AI Core and returning a stream of response parts.
|
|
349
|
-
*
|
|
350
|
-
* **Stream Events:**
|
|
351
|
-
* - `stream-start` - Stream initialization
|
|
352
|
-
* - `response-metadata` - Response metadata (model, timestamp)
|
|
353
|
-
* - `text-start` - Text generation starts
|
|
354
|
-
* - `text-delta` - Incremental text chunks
|
|
355
|
-
* - `text-end` - Text generation completes
|
|
356
|
-
* - `tool-call` - Tool call detected
|
|
357
|
-
* - `finish` - Stream completes with usage and finish reason
|
|
358
|
-
* - `error` - Error occurred
|
|
359
|
-
*
|
|
360
|
-
* @param options - Streaming options including prompt, tools, and settings
|
|
361
|
-
* @returns Promise resolving to stream and raw call metadata
|
|
362
|
-
*
|
|
363
|
-
* @example
|
|
364
|
-
* ```typescript
|
|
365
|
-
* const { stream } = await model.doStream({
|
|
366
|
-
* prompt: [
|
|
367
|
-
* { role: 'user', content: [{ type: 'text', text: 'Write a story' }] }
|
|
368
|
-
* ]
|
|
369
|
-
* });
|
|
370
|
-
*
|
|
371
|
-
* for await (const part of stream) {
|
|
372
|
-
* if (part.type === 'text-delta') {
|
|
373
|
-
* process.stdout.write(part.delta);
|
|
374
|
-
* }
|
|
375
|
-
* }
|
|
376
|
-
* ```
|
|
377
|
-
*/
|
|
378
|
-
doStream(options: LanguageModelV2CallOptions): Promise<{
|
|
379
|
-
stream: ReadableStream<LanguageModelV2StreamPart>;
|
|
380
|
-
rawCall: {
|
|
381
|
-
rawPrompt: unknown;
|
|
382
|
-
rawSettings: Record<string, unknown>;
|
|
383
|
-
};
|
|
384
|
-
}>;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* SAP AI Provider interface.
|
|
389
|
-
*
|
|
390
|
-
* This is the main interface for creating and configuring SAP AI Core models.
|
|
391
|
-
* It extends the standard Vercel AI SDK ProviderV2 interface with SAP-specific functionality.
|
|
392
|
-
*
|
|
393
|
-
* @example
|
|
394
|
-
* ```typescript
|
|
395
|
-
* const provider = createSAPAIProvider({
|
|
396
|
-
* resourceGroup: 'default'
|
|
397
|
-
* });
|
|
398
|
-
*
|
|
399
|
-
* // Create a model instance
|
|
400
|
-
* const model = provider('gpt-4o', {
|
|
401
|
-
* modelParams: {
|
|
402
|
-
* temperature: 0.7,
|
|
403
|
-
* maxTokens: 1000
|
|
404
|
-
* }
|
|
405
|
-
* });
|
|
406
|
-
*
|
|
407
|
-
* // Or use the explicit chat method
|
|
408
|
-
* const chatModel = provider.chat('gpt-4o');
|
|
409
|
-
* ```
|
|
410
|
-
*/
|
|
411
|
-
interface SAPAIProvider extends ProviderV2 {
|
|
412
|
-
/**
|
|
413
|
-
* Create a language model instance.
|
|
414
|
-
*
|
|
415
|
-
* @param modelId - The SAP AI Core model identifier (e.g., 'gpt-4o', 'anthropic--claude-3.5-sonnet')
|
|
416
|
-
* @param settings - Optional model configuration settings
|
|
417
|
-
* @returns Configured SAP AI chat language model instance
|
|
418
|
-
*/
|
|
419
|
-
(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAIChatLanguageModel;
|
|
420
|
-
/**
|
|
421
|
-
* Explicit method for creating chat models.
|
|
422
|
-
*
|
|
423
|
-
* This method is equivalent to calling the provider function directly,
|
|
424
|
-
* but provides a more explicit API for chat-based interactions.
|
|
425
|
-
*
|
|
426
|
-
* @param modelId - The SAP AI Core model identifier
|
|
427
|
-
* @param settings - Optional model configuration settings
|
|
428
|
-
* @returns Configured SAP AI chat language model instance
|
|
429
|
-
*/
|
|
430
|
-
chat(modelId: SAPAIModelId, settings?: SAPAISettings): SAPAIChatLanguageModel;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Configuration settings for the SAP AI Provider.
|
|
434
|
-
*
|
|
435
|
-
* This interface defines all available options for configuring the SAP AI Core connection
|
|
436
|
-
* using the official SAP AI SDK. The SDK handles authentication automatically when
|
|
437
|
-
* running on SAP BTP (via service binding) or locally (via AICORE_SERVICE_KEY env var).
|
|
438
|
-
*
|
|
439
|
-
* @example
|
|
440
|
-
* ```typescript
|
|
441
|
-
* // Using default configuration (auto-detects service binding or env var)
|
|
442
|
-
* const provider = createSAPAIProvider();
|
|
443
|
-
*
|
|
444
|
-
* // With specific resource group
|
|
445
|
-
* const provider = createSAPAIProvider({
|
|
446
|
-
* resourceGroup: 'production'
|
|
447
|
-
* });
|
|
448
|
-
*
|
|
449
|
-
* // With custom destination
|
|
450
|
-
* const provider = createSAPAIProvider({
|
|
451
|
-
* destination: {
|
|
452
|
-
* url: 'https://my-ai-core-instance.cfapps.eu10.hana.ondemand.com'
|
|
453
|
-
* }
|
|
454
|
-
* });
|
|
455
|
-
* ```
|
|
456
|
-
*/
|
|
457
|
-
interface SAPAIProviderSettings {
|
|
458
|
-
/**
|
|
459
|
-
* SAP AI Core resource group.
|
|
460
|
-
*
|
|
461
|
-
* Logical grouping of AI resources in SAP AI Core.
|
|
462
|
-
* Used for resource isolation and access control.
|
|
463
|
-
* Different resource groups can have different permissions and quotas.
|
|
464
|
-
*
|
|
465
|
-
* @default 'default'
|
|
466
|
-
* @example
|
|
467
|
-
* ```typescript
|
|
468
|
-
* resourceGroup: 'default' // Default resource group
|
|
469
|
-
* resourceGroup: 'production' // Production environment
|
|
470
|
-
* resourceGroup: 'development' // Development environment
|
|
471
|
-
* ```
|
|
472
|
-
*/
|
|
473
|
-
resourceGroup?: string;
|
|
474
|
-
/**
|
|
475
|
-
* SAP AI Core deployment ID.
|
|
476
|
-
*
|
|
477
|
-
* A specific deployment ID to use for orchestration requests.
|
|
478
|
-
* If not provided, the SDK will resolve the deployment automatically.
|
|
479
|
-
*
|
|
480
|
-
* @example
|
|
481
|
-
* ```typescript
|
|
482
|
-
* deploymentId: 'd65d81e7c077e583'
|
|
483
|
-
* ```
|
|
484
|
-
*/
|
|
485
|
-
deploymentId?: string;
|
|
486
|
-
/**
|
|
487
|
-
* Custom destination configuration for SAP AI Core.
|
|
488
|
-
*
|
|
489
|
-
* Override the default destination detection. Useful for:
|
|
490
|
-
* - Custom proxy configurations
|
|
491
|
-
* - Non-standard SAP AI Core setups
|
|
492
|
-
* - Testing environments
|
|
493
|
-
*
|
|
494
|
-
* @example
|
|
495
|
-
* ```typescript
|
|
496
|
-
* destination: {
|
|
497
|
-
* url: 'https://api.ai.prod.eu-central-1.aws.ml.hana.ondemand.com'
|
|
498
|
-
* }
|
|
499
|
-
* ```
|
|
500
|
-
*/
|
|
501
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
502
|
-
/**
|
|
503
|
-
* Default model settings applied to every model instance created by this provider.
|
|
504
|
-
* Per-call settings provided to the model will override these.
|
|
505
|
-
*/
|
|
506
|
-
defaultSettings?: SAPAISettings;
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Deployment configuration type used by SAP AI SDK.
|
|
510
|
-
*/
|
|
511
|
-
type DeploymentConfig = ResourceGroupConfig | DeploymentIdConfig;
|
|
512
|
-
/**
|
|
513
|
-
* Creates a SAP AI Core provider instance for use with Vercel AI SDK.
|
|
514
|
-
*
|
|
515
|
-
* This is the main entry point for integrating SAP AI Core with the Vercel AI SDK.
|
|
516
|
-
* It uses the official SAP AI SDK (@sap-ai-sdk/orchestration) under the hood,
|
|
517
|
-
* which handles authentication and API communication automatically.
|
|
518
|
-
*
|
|
519
|
-
* **Authentication:**
|
|
520
|
-
* The SAP AI SDK automatically handles authentication:
|
|
521
|
-
* 1. On SAP BTP: Uses service binding (VCAP_SERVICES)
|
|
522
|
-
* 2. Locally: Uses AICORE_SERVICE_KEY environment variable
|
|
523
|
-
*
|
|
524
|
-
* **Key Features:**
|
|
525
|
-
* - Automatic authentication via SAP AI SDK
|
|
526
|
-
* - Support for all SAP AI Core orchestration models
|
|
527
|
-
* - Streaming and non-streaming responses
|
|
528
|
-
* - Tool calling support
|
|
529
|
-
* - Data masking (DPI)
|
|
530
|
-
* - Content filtering
|
|
531
|
-
*
|
|
532
|
-
* @param options - Configuration options for the provider
|
|
533
|
-
* @returns A configured SAP AI provider
|
|
534
|
-
*
|
|
535
|
-
* @example
|
|
536
|
-
* **Basic Usage**
|
|
537
|
-
* ```typescript
|
|
538
|
-
* import { createSAPAIProvider } from '@mymediset/sap-ai-provider';
|
|
539
|
-
* import { generateText } from 'ai';
|
|
540
|
-
*
|
|
541
|
-
* const provider = createSAPAIProvider();
|
|
542
|
-
*
|
|
543
|
-
* const result = await generateText({
|
|
544
|
-
* model: provider('gpt-4o'),
|
|
545
|
-
* prompt: 'Hello, world!'
|
|
546
|
-
* });
|
|
547
|
-
* ```
|
|
548
|
-
*
|
|
549
|
-
* @example
|
|
550
|
-
* **With Resource Group**
|
|
551
|
-
* ```typescript
|
|
552
|
-
* const provider = createSAPAIProvider({
|
|
553
|
-
* resourceGroup: 'production'
|
|
554
|
-
* });
|
|
555
|
-
*
|
|
556
|
-
* const model = provider('anthropic--claude-3.5-sonnet', {
|
|
557
|
-
* modelParams: {
|
|
558
|
-
* temperature: 0.3,
|
|
559
|
-
* maxTokens: 2000
|
|
560
|
-
* }
|
|
561
|
-
* });
|
|
562
|
-
* ```
|
|
563
|
-
*
|
|
564
|
-
* @example
|
|
565
|
-
* **With Default Settings**
|
|
566
|
-
* ```typescript
|
|
567
|
-
* const provider = createSAPAIProvider({
|
|
568
|
-
* defaultSettings: {
|
|
569
|
-
* modelParams: {
|
|
570
|
-
* temperature: 0.7
|
|
571
|
-
* }
|
|
572
|
-
* }
|
|
573
|
-
* });
|
|
574
|
-
* ```
|
|
575
|
-
*/
|
|
576
|
-
declare function createSAPAIProvider(options?: SAPAIProviderSettings): SAPAIProvider;
|
|
577
|
-
/**
|
|
578
|
-
* Default SAP AI provider instance.
|
|
579
|
-
*
|
|
580
|
-
* Uses the default configuration which auto-detects authentication
|
|
581
|
-
* from service binding (SAP BTP) or AICORE_SERVICE_KEY environment variable.
|
|
582
|
-
*
|
|
583
|
-
* @example
|
|
584
|
-
* ```typescript
|
|
585
|
-
* import { sapai } from '@mymediset/sap-ai-provider';
|
|
586
|
-
* import { generateText } from 'ai';
|
|
587
|
-
*
|
|
588
|
-
* const result = await generateText({
|
|
589
|
-
* model: sapai('gpt-4o'),
|
|
590
|
-
* prompt: 'Hello!'
|
|
591
|
-
* });
|
|
592
|
-
* ```
|
|
593
|
-
*/
|
|
594
|
-
declare const sapai: SAPAIProvider;
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Custom error class for SAP AI Core errors.
|
|
598
|
-
* Provides structured access to error details returned by the API.
|
|
599
|
-
*
|
|
600
|
-
* The SAP AI SDK handles most error responses internally, but this class
|
|
601
|
-
* can be used to wrap and provide additional context for errors.
|
|
602
|
-
*
|
|
603
|
-
* @example
|
|
604
|
-
* ```typescript
|
|
605
|
-
* try {
|
|
606
|
-
* await model.doGenerate({ prompt });
|
|
607
|
-
* } catch (error) {
|
|
608
|
-
* if (error instanceof SAPAIError) {
|
|
609
|
-
* console.error('Error Code:', error.code);
|
|
610
|
-
* console.error('Request ID:', error.requestId);
|
|
611
|
-
* console.error('Location:', error.location);
|
|
612
|
-
* }
|
|
613
|
-
* }
|
|
614
|
-
* ```
|
|
615
|
-
*/
|
|
616
|
-
declare class SAPAIError extends Error {
|
|
617
|
-
/** HTTP status code or custom error code */
|
|
618
|
-
readonly code?: number;
|
|
619
|
-
/** Where the error occurred (e.g., module name) */
|
|
620
|
-
readonly location?: string;
|
|
621
|
-
/** Unique identifier for tracking the request */
|
|
622
|
-
readonly requestId?: string;
|
|
623
|
-
/** Additional error context or debugging information */
|
|
624
|
-
readonly details?: string;
|
|
625
|
-
/** Original cause of the error */
|
|
626
|
-
readonly cause?: unknown;
|
|
627
|
-
constructor(message: string, options?: {
|
|
628
|
-
code?: number;
|
|
629
|
-
location?: string;
|
|
630
|
-
requestId?: string;
|
|
631
|
-
details?: string;
|
|
632
|
-
cause?: unknown;
|
|
633
|
-
});
|
|
634
|
-
/**
|
|
635
|
-
* Creates a SAPAIError from an OrchestrationErrorResponse.
|
|
636
|
-
*
|
|
637
|
-
* @param errorResponse - The error response from SAP AI SDK
|
|
638
|
-
* @returns A new SAPAIError instance
|
|
639
|
-
*/
|
|
640
|
-
static fromOrchestrationError(errorResponse: OrchestrationErrorResponse): SAPAIError;
|
|
641
|
-
/**
|
|
642
|
-
* Creates a SAPAIError from a generic error.
|
|
643
|
-
*
|
|
644
|
-
* @param error - The original error
|
|
645
|
-
* @param context - Optional context about where the error occurred
|
|
646
|
-
* @returns A new SAPAIError instance
|
|
647
|
-
*/
|
|
648
|
-
static fromError(error: unknown, context?: string): SAPAIError;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
export { type DeploymentConfig, SAPAIError, type SAPAIModelId, type SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, createSAPAIProvider, sapai };
|