@jerome-benoit/sap-ai-provider 4.0.0-rc.2 → 4.0.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
@@ -10,7 +10,6 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
10
10
  * These models are available through the SAP AI Core Orchestration service.
11
11
  * **Note:** The models listed here are representative examples. Actual model availability
12
12
  * depends on your SAP AI Core tenant configuration, region, and subscription.
13
- *
14
13
  * @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/models-and-scenarios SAP AI Core Models Documentation}
15
14
  *
16
15
  * **Azure OpenAI Models:**
@@ -21,6 +20,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
21
20
  * **Google Vertex AI Models:**
22
21
  * - gemini-2.0-flash, gemini-2.0-flash-lite
23
22
  * - gemini-2.5-flash, gemini-2.5-pro
23
+ * - ⚠️ **Limitation:** Gemini models support only 1 tool per request
24
24
  *
25
25
  * **AWS Bedrock Models:**
26
26
  * - anthropic--claude-3-haiku, anthropic--claude-3-sonnet, anthropic--claude-3-opus
@@ -30,6 +30,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
30
30
  *
31
31
  * **AI Core Open Source Models:**
32
32
  * - mistralai--mistral-large-instruct, mistralai--mistral-medium-instruct, mistralai--mistral-small-instruct
33
+ * - meta--llama3.1-70b-instruct
33
34
  * - cohere--command-a-reasoning
34
35
  */
35
36
  type SAPAIModelId = ChatModel;
@@ -39,7 +40,6 @@ type SAPAIModelId = ChatModel;
39
40
  * These settings control model parameters, data masking, content filtering,
40
41
  * and tool usage. Settings can be provided at provider-level (defaults) or
41
42
  * per-model call (overrides).
42
- *
43
43
  * @example
44
44
  * **Basic usage with model parameters**
45
45
  * ```typescript
@@ -50,7 +50,6 @@ type SAPAIModelId = ChatModel;
50
50
  * }
51
51
  * });
52
52
  * ```
53
- *
54
53
  * @example
55
54
  * **With data masking (DPI)**
56
55
  * ```typescript
@@ -67,7 +66,6 @@ type SAPAIModelId = ChatModel;
67
66
  * }
68
67
  * });
69
68
  * ```
70
- *
71
69
  * @example
72
70
  * **With content filtering**
73
71
  * ```typescript
@@ -86,9 +84,7 @@ interface SAPAISettings {
86
84
  /**
87
85
  * Filtering configuration for input and output content safety.
88
86
  * Supports Azure Content Safety and Llama Guard filters.
89
- *
90
87
  * @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/content-filtering SAP Content Filtering Documentation}
91
- *
92
88
  * @example
93
89
  * ```typescript
94
90
  * import { buildAzureContentSafetyFilter } from '@sap-ai-sdk/orchestration';
@@ -113,9 +109,7 @@ interface SAPAISettings {
113
109
  * Enables retrieval-augmented generation using SAP Document Grounding Service.
114
110
  *
115
111
  * Use `buildDocumentGroundingConfig()` to create the configuration.
116
- *
117
112
  * @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/document-grounding SAP Document Grounding Documentation}
118
- *
119
113
  * @example
120
114
  * ```typescript
121
115
  * import { buildDocumentGroundingConfig } from '@mymediset/sap-ai-provider';
@@ -142,35 +136,14 @@ interface SAPAISettings {
142
136
  /**
143
137
  * Whether to include assistant reasoning parts in the SAP prompt conversion.
144
138
  *
145
- * Reasoning parts contain internal model chain-of-thought reasoning that may not be
146
- * suitable for end-user display or persistence. When disabled (default), only the
147
- * final response content is forwarded.
148
- *
149
- * **Default:** `false` (recommended for production)
150
- *
151
- * **When to enable:**
152
- * - Debugging model behavior
153
- * - Analyzing reasoning patterns
154
- * - Research and development
155
- *
156
- * **When to keep disabled:**
157
- * - Production applications
158
- * - User-facing chatbots
159
- * - When storing conversation history
160
- *
139
+ * Reasoning parts contain internal model chain-of-thought reasoning. When disabled,
140
+ * only the final response content is forwarded. Enable for debugging/analysis;
141
+ * disable for production applications and user-facing chatbots.
142
+ * @default false
161
143
  * @example
162
144
  * ```typescript
163
- * // Enable for debugging (see model's reasoning)
164
- * const debugModel = provider('gpt-4o', {
165
- * includeReasoning: true
166
- * });
167
- *
168
- * // Disabled by default (production use)
169
- * const prodModel = provider('gpt-4o');
170
- * // or explicitly:
171
- * const prodModel2 = provider('gpt-4o', {
172
- * includeReasoning: false
173
- * });
145
+ * const debugModel = provider('gpt-4o', { includeReasoning: true });
146
+ * const prodModel = provider('gpt-4o'); // includeReasoning defaults to false
174
147
  * ```
175
148
  */
176
149
  includeReasoning?: boolean;
@@ -178,9 +151,7 @@ interface SAPAISettings {
178
151
  * Masking configuration for SAP AI Core orchestration.
179
152
  * When provided, sensitive information in prompts can be anonymized or
180
153
  * pseudonymized by SAP Data Privacy Integration (DPI).
181
- *
182
154
  * @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/data-privacy-integration SAP DPI Documentation}
183
- *
184
155
  * @example
185
156
  * ```typescript
186
157
  * import { buildDpiMaskingProvider } from '@sap-ai-sdk/orchestration';
@@ -216,7 +187,9 @@ interface SAPAISettings {
216
187
  /**
217
188
  * Number of completions to generate.
218
189
  * Multiple completions provide alternative responses.
219
- * Note: Not supported by Amazon and Anthropic models.
190
+ *
191
+ * Note: Not supported by Amazon and Anthropic models. When used with these
192
+ * models, the parameter is silently omitted from the request.
220
193
  * If not specified, typically defaults to 1 on the model side.
221
194
  */
222
195
  n?: number;
@@ -254,8 +227,6 @@ interface SAPAISettings {
254
227
  /**
255
228
  * Response format for templating prompt (OpenAI-compatible)
256
229
  * Allows specifying structured output formats
257
- *
258
-
259
230
  * @example
260
231
  * ```typescript
261
232
  * const model = provider('gpt-4o', {
@@ -285,13 +256,12 @@ interface SAPAISettings {
285
256
  /**
286
257
  * Tool definitions in SAP AI SDK format
287
258
  *
288
-
259
+ *
289
260
  * Use this to pass tools directly with proper JSON Schema definitions.
290
261
  * This bypasses the AI SDK's Zod conversion which may have issues.
291
262
  *
292
263
  * Note: This should be used in conjunction with AI SDK's tool handling
293
264
  * to provide the actual tool implementations (execute functions).
294
- *
295
265
  * @example
296
266
  * ```typescript
297
267
  * const model = provider('gpt-4o', {
@@ -320,9 +290,7 @@ interface SAPAISettings {
320
290
  * Enables automatic translation using SAP Document Translation service.
321
291
  *
322
292
  * Use `buildTranslationConfig()` to create input/output configurations.
323
- *
324
293
  * @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/translation SAP Translation Documentation}
325
- *
326
294
  * @example
327
295
  * ```typescript
328
296
  * import { buildTranslationConfig } from '@mymediset/sap-ai-provider';
@@ -371,10 +339,8 @@ interface SAPAIConfig {
371
339
  * - Google Vertex AI models (gemini-2.0-flash, gemini-2.5-pro, etc.)
372
340
  * - AWS Bedrock models (anthropic--claude-*, amazon--nova-*, etc.)
373
341
  * - AI Core open source models (mistralai--, cohere--, etc.)
374
- *
375
342
  * @see {@link https://sdk.vercel.ai/docs/ai-sdk-core/language-model-v3 Vercel AI SDK LanguageModelV3}
376
343
  * @see {@link https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/orchestration SAP AI Core Orchestration}
377
- *
378
344
  * @example
379
345
  * ```typescript
380
346
  * // Create via provider
@@ -387,8 +353,6 @@ interface SAPAIConfig {
387
353
  * prompt: 'Hello, world!'
388
354
  * });
389
355
  * ```
390
- *
391
- * @implements {LanguageModelV3}
392
356
  */
393
357
  declare class SAPAILanguageModel implements LanguageModelV3 {
394
358
  readonly modelId: SAPAIModelId;
@@ -401,7 +365,11 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
401
365
  * SAP AI Core will fail the request at runtime.
402
366
  */
403
367
  readonly supportsImageUrls: boolean;
404
- /** Multiple completions via the `n` parameter (provider-specific support). */
368
+ /**
369
+ * Multiple completions via the `n` parameter.
370
+ * Note: Amazon and Anthropic models do not support this feature.
371
+ * The provider silently omits the parameter for unsupported models.
372
+ */
405
373
  readonly supportsMultipleCompletions: boolean;
406
374
  /** Parallel tool calls. */
407
375
  readonly supportsParallelToolCalls: boolean;
@@ -412,50 +380,12 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
412
380
  /** Tool/function calling. */
413
381
  readonly supportsToolCalls: boolean;
414
382
  /**
415
- * Generates text completion using SAP AI Core's Orchestration API.
416
- *
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
383
+ * Returns the provider identifier.
384
+ * @returns The provider name
454
385
  */
455
386
  get provider(): string;
456
387
  /**
457
388
  * Returns supported URL patterns for different content types.
458
- *
459
389
  * @returns Record of content types to regex patterns
460
390
  */
461
391
  get supportedUrls(): Record<string, RegExp[]>;
@@ -463,13 +393,10 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
463
393
  private readonly settings;
464
394
  /**
465
395
  * Creates a new SAP AI Chat Language Model instance.
466
- *
396
+ * @internal
467
397
  * @param modelId - The model identifier
468
398
  * @param settings - Model-specific configuration settings
469
399
  * @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
400
  */
474
401
  constructor(modelId: SAPAIModelId, settings: SAPAISettings, config: SAPAIConfig);
475
402
  /**
@@ -487,13 +414,12 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
487
414
  *
488
415
  * **Note on Abort Signal:**
489
416
  * 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.
493
- *
417
+ * aborted. However, this does not cancel the underlying HTTP request to SAP AI Core -
418
+ * the request continues executing on the server. This is a current limitation of the
419
+ * SAP AI SDK's API. See https://github.com/SAP/ai-sdk-js/issues/1429
494
420
  * @param options - Generation options including prompt, tools, and settings
495
421
  * @returns Promise resolving to the generation result with content, usage, and metadata
496
- *
422
+ * @since 1.0.0
497
423
  * @example
498
424
  * ```typescript
499
425
  * const result = await model.doGenerate({
@@ -510,33 +436,29 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
510
436
  /**
511
437
  * Generates a streaming completion.
512
438
  *
513
- * This method implements the `LanguageModelV3.doStream` interface,
514
- * sending a streaming request to SAP AI Core and returning a stream of response parts.
439
+ * Implements `LanguageModelV3.doStream`, sending a streaming request to SAP AI Core
440
+ * and returning a stream of response parts.
515
441
  *
516
442
  * **Stream Events:**
517
- * - `stream-start` - Stream initialization with warnings
518
- * - `response-metadata` - Response metadata (model, timestamp)
443
+ * - `stream-start` - Initialization with warnings
444
+ * - `response-metadata` - Model, timestamp, response ID
519
445
  * - `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
446
+ * - `text-delta` - Incremental text chunks
447
+ * - `text-end` - Text block completes
448
+ * - `tool-input-start/delta/end` - Tool input lifecycle
525
449
  * - `tool-call` - Complete tool call
526
450
  * - `finish` - Stream completes with usage and finish reason
527
451
  * - `error` - Error occurred
528
452
  *
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
453
+ * **Response ID:**
454
+ * Client-generated UUID in `response-metadata.id` and `providerMetadata['sap-ai'].responseId`.
455
+ * TODO: Use backend's `x-request-id` when `OrchestrationStreamResponse` exposes `rawResponse`.
534
456
  *
457
+ * **Abort Signal:**
458
+ * Same limitation as `doGenerate` - see its documentation for details.
535
459
  * @see {@link https://sdk.vercel.ai/docs/ai-sdk-core/streaming Vercel AI SDK Streaming}
536
- *
537
460
  * @param options - Streaming options including prompt, tools, and settings
538
461
  * @returns Promise resolving to stream and request metadata
539
- *
540
462
  * @example
541
463
  * ```typescript
542
464
  * const { stream } = await model.doStream({
@@ -549,25 +471,19 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
549
471
  * if (part.type === 'text-delta') {
550
472
  * process.stdout.write(part.delta);
551
473
  * }
552
- * if (part.type === 'text-end') {
553
- * console.log('Block complete:', part.id, part.text);
554
- * }
555
474
  * }
556
475
  * ```
557
- *
558
- * @since 4.0.0
476
+ * @since 1.0.0
559
477
  */
560
478
  doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
561
479
  /**
562
480
  * Checks if a URL is supported for file/image uploads.
563
- *
564
481
  * @param url - The URL to check
565
482
  * @returns True if the URL protocol is HTTPS or data with valid image format
566
483
  */
567
484
  supportsUrl(url: URL): boolean;
568
485
  /**
569
486
  * Builds orchestration module config for SAP AI SDK.
570
- *
571
487
  * @param options - Call options from the AI SDK
572
488
  * @returns Object containing orchestration config, messages, and warnings
573
489
  * @internal
@@ -575,7 +491,6 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
575
491
  private buildOrchestrationConfig;
576
492
  /**
577
493
  * Creates an OrchestrationClient instance.
578
- *
579
494
  * @param config - Orchestration module configuration
580
495
  * @returns OrchestrationClient instance
581
496
  * @internal
@@ -592,7 +507,6 @@ type DeploymentConfig = DeploymentIdConfig | ResourceGroupConfig;
592
507
  *
593
508
  * This is the main interface for creating and configuring SAP AI Core models.
594
509
  * It extends the standard AI SDK ProviderV3 interface with SAP-specific functionality.
595
- *
596
510
  * @example
597
511
  * ```typescript
598
512
  * const provider = createSAPAIProvider({
@@ -614,7 +528,6 @@ type DeploymentConfig = DeploymentIdConfig | ResourceGroupConfig;
614
528
  interface SAPAIProvider extends ProviderV3 {
615
529
  /**
616
530
  * Create a language model instance.
617
- *
618
531
  * @param modelId - The SAP AI Core model identifier (e.g., 'gpt-4o', 'anthropic--claude-3.5-sonnet')
619
532
  * @param settings - Optional model configuration settings
620
533
  * @returns Configured SAP AI chat language model instance
@@ -625,7 +538,6 @@ interface SAPAIProvider extends ProviderV3 {
625
538
  *
626
539
  * This method is equivalent to calling the provider function directly,
627
540
  * but provides a more explicit API for chat-based interactions.
628
- *
629
541
  * @param modelId - The SAP AI Core model identifier
630
542
  * @param settings - Optional model configuration settings
631
543
  * @returns Configured SAP AI chat language model instance
@@ -636,9 +548,7 @@ interface SAPAIProvider extends ProviderV3 {
636
548
  * Configuration settings for the SAP AI Provider.
637
549
  *
638
550
  * This interface defines all available options for configuring the SAP AI Core connection
639
- * using the official SAP AI SDK. The SDK handles authentication automatically when
640
- * running on SAP BTP (via service binding) or locally (via AICORE_SERVICE_KEY env var).
641
- *
551
+ * using the official SAP AI SDK. See {@link createSAPAIProvider} for authentication details.
642
552
  * @example
643
553
  * ```typescript
644
554
  * // Using default configuration (auto-detects service binding or env var)
@@ -668,7 +578,6 @@ interface SAPAIProviderSettings {
668
578
  *
669
579
  * A specific deployment ID to use for orchestration requests.
670
580
  * If not provided, the SDK will resolve the deployment automatically.
671
- *
672
581
  * @example
673
582
  * ```typescript
674
583
  * deploymentId: 'd65d81e7c077e583'
@@ -682,7 +591,6 @@ interface SAPAIProviderSettings {
682
591
  * - Custom proxy configurations
683
592
  * - Non-standard SAP AI Core setups
684
593
  * - Testing environments
685
- *
686
594
  * @example
687
595
  * ```typescript
688
596
  * destination: {
@@ -697,7 +605,6 @@ interface SAPAIProviderSettings {
697
605
  * Logical grouping of AI resources in SAP AI Core.
698
606
  * Used for resource isolation and access control.
699
607
  * Different resource groups can have different permissions and quotas.
700
- *
701
608
  * @default 'default'
702
609
  * @example
703
610
  * ```typescript
@@ -734,10 +641,8 @@ interface SAPAIProviderSettings {
734
641
  * - Tool calling support
735
642
  * - Data masking (DPI)
736
643
  * - Content filtering
737
- *
738
644
  * @param options - Configuration options for the provider
739
645
  * @returns A configured SAP AI provider
740
- *
741
646
  * @example
742
647
  * **Basic Usage**
743
648
  * ```typescript
@@ -751,7 +656,6 @@ interface SAPAIProviderSettings {
751
656
  * prompt: 'Hello, world!'
752
657
  * });
753
658
  * ```
754
- *
755
659
  * @example
756
660
  * **With Resource Group**
757
661
  * ```typescript
@@ -766,7 +670,6 @@ interface SAPAIProviderSettings {
766
670
  * }
767
671
  * });
768
672
  * ```
769
- *
770
673
  * @example
771
674
  * **With Default Settings**
772
675
  * ```typescript
@@ -783,9 +686,8 @@ declare function createSAPAIProvider(options?: SAPAIProviderSettings): SAPAIProv
783
686
  /**
784
687
  * Default SAP AI provider instance.
785
688
  *
786
- * Uses the default configuration which auto-detects authentication
787
- * from service binding (SAP BTP) or AICORE_SERVICE_KEY environment variable.
788
- *
689
+ * Uses default configuration with automatic authentication.
690
+ * See {@link createSAPAIProvider} for authentication details.
789
691
  * @example
790
692
  * ```typescript
791
693
  * import { sapai } from '@mymediset/sap-ai-provider';