@jerome-benoit/sap-ai-provider 4.0.0 → 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,15 +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
- *
494
- * @see https://github.com/SAP/ai-sdk-js/issues/1429 for tracking true cancellation support
495
- *
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
496
420
  * @param options - Generation options including prompt, tools, and settings
497
421
  * @returns Promise resolving to the generation result with content, usage, and metadata
498
- *
422
+ * @since 1.0.0
499
423
  * @example
500
424
  * ```typescript
501
425
  * const result = await model.doGenerate({
@@ -512,40 +436,29 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
512
436
  /**
513
437
  * Generates a streaming completion.
514
438
  *
515
- * This method implements the `LanguageModelV3.doStream` interface,
516
- * 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.
517
441
  *
518
442
  * **Stream Events:**
519
- * - `stream-start` - Stream initialization with warnings
520
- * - `response-metadata` - Response metadata (model, timestamp)
443
+ * - `stream-start` - Initialization with warnings
444
+ * - `response-metadata` - Model, timestamp, response ID
521
445
  * - `text-start` - Text block begins (with unique ID)
522
- * - `text-delta` - Incremental text chunks (with block ID)
523
- * - `text-end` - Text block completes (with accumulated text)
524
- * - `tool-input-start` - Tool input begins
525
- * - `tool-input-delta` - Tool input chunk
526
- * - `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
527
449
  * - `tool-call` - Complete tool call
528
450
  * - `finish` - Stream completes with usage and finish reason
529
451
  * - `error` - Error occurred
530
452
  *
531
- * **Stream Structure:**
532
- * - Text blocks have explicit lifecycle with unique IDs
533
- * - Finish reason format: `{ unified: string, raw?: string }`
534
- * - Usage format: `{ inputTokens: { total, ... }, outputTokens: { total, ... } }`
535
- * - 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`.
536
456
  *
537
- * **Note on Abort Signal:**
538
- * The abort signal implementation uses Promise.race to reject the promise when
539
- * the signal is aborted. However, this does not cancel the underlying HTTP request
540
- * to SAP AI Core - the request continues executing on the server. This is a
541
- * limitation of the SAP AI SDK's chatCompletion API.
542
- *
543
- * @see https://github.com/SAP/ai-sdk-js/issues/1429 for tracking true cancellation support
457
+ * **Abort Signal:**
458
+ * Same limitation as `doGenerate` - see its documentation for details.
544
459
  * @see {@link https://sdk.vercel.ai/docs/ai-sdk-core/streaming Vercel AI SDK Streaming}
545
- *
546
460
  * @param options - Streaming options including prompt, tools, and settings
547
461
  * @returns Promise resolving to stream and request metadata
548
- *
549
462
  * @example
550
463
  * ```typescript
551
464
  * const { stream } = await model.doStream({
@@ -558,25 +471,19 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
558
471
  * if (part.type === 'text-delta') {
559
472
  * process.stdout.write(part.delta);
560
473
  * }
561
- * if (part.type === 'text-end') {
562
- * console.log('Block complete:', part.id, part.text);
563
- * }
564
474
  * }
565
475
  * ```
566
- *
567
- * @since 4.0.0
476
+ * @since 1.0.0
568
477
  */
569
478
  doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
570
479
  /**
571
480
  * Checks if a URL is supported for file/image uploads.
572
- *
573
481
  * @param url - The URL to check
574
482
  * @returns True if the URL protocol is HTTPS or data with valid image format
575
483
  */
576
484
  supportsUrl(url: URL): boolean;
577
485
  /**
578
486
  * Builds orchestration module config for SAP AI SDK.
579
- *
580
487
  * @param options - Call options from the AI SDK
581
488
  * @returns Object containing orchestration config, messages, and warnings
582
489
  * @internal
@@ -584,7 +491,6 @@ declare class SAPAILanguageModel implements LanguageModelV3 {
584
491
  private buildOrchestrationConfig;
585
492
  /**
586
493
  * Creates an OrchestrationClient instance.
587
- *
588
494
  * @param config - Orchestration module configuration
589
495
  * @returns OrchestrationClient instance
590
496
  * @internal
@@ -601,7 +507,6 @@ type DeploymentConfig = DeploymentIdConfig | ResourceGroupConfig;
601
507
  *
602
508
  * This is the main interface for creating and configuring SAP AI Core models.
603
509
  * It extends the standard AI SDK ProviderV3 interface with SAP-specific functionality.
604
- *
605
510
  * @example
606
511
  * ```typescript
607
512
  * const provider = createSAPAIProvider({
@@ -623,7 +528,6 @@ type DeploymentConfig = DeploymentIdConfig | ResourceGroupConfig;
623
528
  interface SAPAIProvider extends ProviderV3 {
624
529
  /**
625
530
  * Create a language model instance.
626
- *
627
531
  * @param modelId - The SAP AI Core model identifier (e.g., 'gpt-4o', 'anthropic--claude-3.5-sonnet')
628
532
  * @param settings - Optional model configuration settings
629
533
  * @returns Configured SAP AI chat language model instance
@@ -634,7 +538,6 @@ interface SAPAIProvider extends ProviderV3 {
634
538
  *
635
539
  * This method is equivalent to calling the provider function directly,
636
540
  * but provides a more explicit API for chat-based interactions.
637
- *
638
541
  * @param modelId - The SAP AI Core model identifier
639
542
  * @param settings - Optional model configuration settings
640
543
  * @returns Configured SAP AI chat language model instance
@@ -645,9 +548,7 @@ interface SAPAIProvider extends ProviderV3 {
645
548
  * Configuration settings for the SAP AI Provider.
646
549
  *
647
550
  * This interface defines all available options for configuring the SAP AI Core connection
648
- * using the official SAP AI SDK. The SDK handles authentication automatically when
649
- * running on SAP BTP (via service binding) or locally (via AICORE_SERVICE_KEY env var).
650
- *
551
+ * using the official SAP AI SDK. See {@link createSAPAIProvider} for authentication details.
651
552
  * @example
652
553
  * ```typescript
653
554
  * // Using default configuration (auto-detects service binding or env var)
@@ -677,7 +578,6 @@ interface SAPAIProviderSettings {
677
578
  *
678
579
  * A specific deployment ID to use for orchestration requests.
679
580
  * If not provided, the SDK will resolve the deployment automatically.
680
- *
681
581
  * @example
682
582
  * ```typescript
683
583
  * deploymentId: 'd65d81e7c077e583'
@@ -691,7 +591,6 @@ interface SAPAIProviderSettings {
691
591
  * - Custom proxy configurations
692
592
  * - Non-standard SAP AI Core setups
693
593
  * - Testing environments
694
- *
695
594
  * @example
696
595
  * ```typescript
697
596
  * destination: {
@@ -706,7 +605,6 @@ interface SAPAIProviderSettings {
706
605
  * Logical grouping of AI resources in SAP AI Core.
707
606
  * Used for resource isolation and access control.
708
607
  * Different resource groups can have different permissions and quotas.
709
- *
710
608
  * @default 'default'
711
609
  * @example
712
610
  * ```typescript
@@ -743,10 +641,8 @@ interface SAPAIProviderSettings {
743
641
  * - Tool calling support
744
642
  * - Data masking (DPI)
745
643
  * - Content filtering
746
- *
747
644
  * @param options - Configuration options for the provider
748
645
  * @returns A configured SAP AI provider
749
- *
750
646
  * @example
751
647
  * **Basic Usage**
752
648
  * ```typescript
@@ -760,7 +656,6 @@ interface SAPAIProviderSettings {
760
656
  * prompt: 'Hello, world!'
761
657
  * });
762
658
  * ```
763
- *
764
659
  * @example
765
660
  * **With Resource Group**
766
661
  * ```typescript
@@ -775,7 +670,6 @@ interface SAPAIProviderSettings {
775
670
  * }
776
671
  * });
777
672
  * ```
778
- *
779
673
  * @example
780
674
  * **With Default Settings**
781
675
  * ```typescript
@@ -792,9 +686,8 @@ declare function createSAPAIProvider(options?: SAPAIProviderSettings): SAPAIProv
792
686
  /**
793
687
  * Default SAP AI provider instance.
794
688
  *
795
- * Uses the default configuration which auto-detects authentication
796
- * from service binding (SAP BTP) or AICORE_SERVICE_KEY environment variable.
797
- *
689
+ * Uses default configuration with automatic authentication.
690
+ * See {@link createSAPAIProvider} for authentication details.
798
691
  * @example
799
692
  * ```typescript
800
693
  * import { sapai } from '@mymediset/sap-ai-provider';