@jerome-benoit/sap-ai-provider-v2 5.0.0 → 5.0.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.
Files changed (40) hide show
  1. package/README.md +90 -48
  2. package/dist/chunk-77JSAAPE.js +778 -0
  3. package/dist/chunk-77JSAAPE.js.map +1 -0
  4. package/dist/{chunk-Q5JV4I6D.js → chunk-LEME2MFD.js} +59 -387
  5. package/dist/chunk-LEME2MFD.js.map +1 -0
  6. package/dist/{chunk-TXZZURBA.js → chunk-NLMWIVG7.js} +17 -7
  7. package/dist/chunk-NLMWIVG7.js.map +1 -0
  8. package/dist/chunk-QZOZ3PZT.js +634 -0
  9. package/dist/chunk-QZOZ3PZT.js.map +1 -0
  10. package/dist/{chunk-FY2HO62O.js → chunk-U6WJSLR7.js} +19 -11
  11. package/dist/chunk-U6WJSLR7.js.map +1 -0
  12. package/dist/{chunk-QDUZRLMI.js → chunk-YP3AADWD.js} +47 -40
  13. package/dist/chunk-YP3AADWD.js.map +1 -0
  14. package/dist/{foundation-models-embedding-model-strategy-JJBN3TQI.js → foundation-models-embedding-model-strategy-A3WDDAYK.js} +8 -9
  15. package/dist/foundation-models-embedding-model-strategy-A3WDDAYK.js.map +1 -0
  16. package/dist/{foundation-models-language-model-strategy-6ELKE34K.js → foundation-models-language-model-strategy-6U6KK6KH.js} +18 -21
  17. package/dist/foundation-models-language-model-strategy-6U6KK6KH.js.map +1 -0
  18. package/dist/index.cjs +1325 -31669
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +60 -55
  21. package/dist/index.d.ts +60 -55
  22. package/dist/index.js +48 -194
  23. package/dist/index.js.map +1 -1
  24. package/dist/{orchestration-embedding-model-strategy-QI72OB3E.js → orchestration-embedding-model-strategy-JO3QH5MR.js} +7 -11
  25. package/dist/orchestration-embedding-model-strategy-JO3QH5MR.js.map +1 -0
  26. package/dist/{orchestration-language-model-strategy-X4FZNLSA.js → orchestration-language-model-strategy-MBVA7BYX.js} +27 -28
  27. package/dist/orchestration-language-model-strategy-MBVA7BYX.js.map +1 -0
  28. package/package.json +15 -12
  29. package/dist/chunk-BIBSYTMU.js +0 -31085
  30. package/dist/chunk-BIBSYTMU.js.map +0 -1
  31. package/dist/chunk-FY2HO62O.js.map +0 -1
  32. package/dist/chunk-Q5JV4I6D.js.map +0 -1
  33. package/dist/chunk-QDUZRLMI.js.map +0 -1
  34. package/dist/chunk-TXZZURBA.js.map +0 -1
  35. package/dist/chunk-WNR7DC4V.js +0 -251
  36. package/dist/chunk-WNR7DC4V.js.map +0 -1
  37. package/dist/foundation-models-embedding-model-strategy-JJBN3TQI.js.map +0 -1
  38. package/dist/foundation-models-language-model-strategy-6ELKE34K.js.map +0 -1
  39. package/dist/orchestration-embedding-model-strategy-QI72OB3E.js.map +0 -1
  40. package/dist/orchestration-language-model-strategy-X4FZNLSA.js.map +0 -1
package/README.md CHANGED
@@ -46,6 +46,7 @@ SAP's enterprise-grade AI models through the familiar Vercel AI SDK interface.
46
46
  - [Debug Mode](#debug-mode)
47
47
  - [Examples](#examples)
48
48
  - [Migration Guides](#migration-guides)
49
+ - [Upgrading from v4.x to v5.x](#upgrading-from-v4x-to-v5x)
49
50
  - [Upgrading from v3.x to v4.x](#upgrading-from-v3x-to-v4x)
50
51
  - [Upgrading from v2.x to v3.x](#upgrading-from-v2x-to-v3x)
51
52
  - [Upgrading from v1.x to v2.x](#upgrading-from-v1x-to-v2x)
@@ -82,7 +83,7 @@ SAP's enterprise-grade AI models through the familiar Vercel AI SDK interface.
82
83
  ## Quick Start
83
84
 
84
85
  ```bash
85
- npm install @jerome-benoit/sap-ai-provider ai@^6
86
+ npm install @jerome-benoit/sap-ai-provider ai@^6 dotenv
86
87
  ```
87
88
 
88
89
  ```typescript
@@ -103,16 +104,17 @@ try {
103
104
 
104
105
  console.log(result.text);
105
106
  } catch (error) {
106
- if (error instanceof APICallError) {
107
- console.error("SAP AI Core API error:", error.message);
108
- console.error("Status:", error.statusCode);
107
+ process.exitCode = 1;
108
+ if (APICallError.isInstance(error)) {
109
+ console.error("SAP AI Core API error:", error.statusCode, error.name);
109
110
  } else {
110
- console.error("Unexpected error:", error);
111
+ console.error("Unexpected error:", error instanceof Error ? error.name : "Unknown error");
111
112
  }
112
113
  }
113
114
  ```
114
115
 
115
- > **Note:** Requires `AICORE_SERVICE_KEY` environment variable. See
116
+ > **Note:** For local service-key setup, set `AICORE_SERVICE_KEY`. SAP BTP service
117
+ > bindings and custom destinations are alternatives. See
116
118
  > [Environment Setup](./ENVIRONMENT_SETUP.md) for configuration.
117
119
 
118
120
  ## Quick Reference
@@ -125,8 +127,8 @@ try {
125
127
  | **Text Generation** | `generateText({ model: provider("gpt-4.1"), prompt })` | [Basic Usage](#text-generation) |
126
128
  | **Streaming** | `streamText({ model: provider("gpt-4.1"), prompt })` | [Streaming](#streaming-responses) |
127
129
  | **Tool Calling** | `generateText({ tools: { myTool: tool({...}) } })` | [Tool Calling](#tool-calling) |
128
- | **Error Handling** | `catch (error instanceof APICallError)` | [API Reference](./API_REFERENCE.md#error-handling--reference) |
129
- | **Choose Model** | See 80+ models (GPT, Claude, Gemini, Llama) | [Models](./API_REFERENCE.md#models) |
130
+ | **Error Handling** | `if (APICallError.isInstance(error)) { /* handle error */ }` | [API Reference](./API_REFERENCE.md#error-handling--reference) |
131
+ | **Choose Model** | Discover models available in your tenant | [Models](./API_REFERENCE.md#models) |
130
132
  | **Embeddings** | `embed({ model: provider.embedding("text-embedding-3-small") })` | [Embeddings](#embeddings) |
131
133
 
132
134
  ## Installation
@@ -134,11 +136,20 @@ try {
134
136
  **Requirements:** Node.js 22.12+. The provider entrypoint must match the installed
135
137
  AI SDK major.
136
138
 
137
- | AI SDK | Install | Provider import |
138
- | ------ | -------------------------------------------------- | ----------------------------------- |
139
- | 7 | `npm install @jerome-benoit/sap-ai-provider ai@^7` | `@jerome-benoit/sap-ai-provider/v4` |
140
- | 6 | `npm install @jerome-benoit/sap-ai-provider ai@^6` | `@jerome-benoit/sap-ai-provider` |
141
- | 5 | `npm install @jerome-benoit/sap-ai-provider ai@^5` | `@jerome-benoit/sap-ai-provider/v2` |
139
+ The published package targets Node.js. Its ESM output uses Node
140
+ `module.createRequire`, and the SAP SDK dependency chain relies on Node APIs.
141
+ The source-level Edge test suite does not establish deployability to pure Edge
142
+ runtimes such as Cloudflare Workers; use a Node.js server runtime for deployment.
143
+
144
+ | AI SDK | Install | Provider import |
145
+ | ------ | -------------------------------------------------- | ----------------------------------------------------------------------- |
146
+ | 7 | `npm install @jerome-benoit/sap-ai-provider ai@^7` | `@jerome-benoit/sap-ai-provider/v4` |
147
+ | 6 | `npm install @jerome-benoit/sap-ai-provider ai@^6` | `@jerome-benoit/sap-ai-provider` or `@jerome-benoit/sap-ai-provider/v3` |
148
+ | 5 | `npm install @jerome-benoit/sap-ai-provider ai@^5` | `@jerome-benoit/sap-ai-provider/v2` |
149
+
150
+ `/v3` is an explicit alias for the AI SDK 6 root entrypoint. Both resolve to
151
+ the same runtime modules and TypeScript declarations, including the same `sapai`
152
+ instance within each module format; existing root imports remain valid.
142
153
 
143
154
  The Quick Start and inline snippets on this page use AI SDK 6 with the root V3
144
155
  entrypoint. The runnable files in `examples/` use the repository's installed
@@ -269,7 +280,7 @@ The provider is callable and also exposes explicit methods:
269
280
  const chatModel = provider("gpt-4.1");
270
281
 
271
282
  // Explicit method syntax
272
- const chatModel = provider.chat("gpt-4.1");
283
+ const explicitChatModel = provider.chat("gpt-4.1");
273
284
  const embeddingModel = provider.embedding("text-embedding-3-small");
274
285
  ```
275
286
 
@@ -350,24 +361,31 @@ import { streamText } from "ai";
350
361
  import { APICallError } from "@ai-sdk/provider";
351
362
 
352
363
  try {
364
+ let streamError: unknown;
353
365
  const result = streamText({
354
366
  model: provider("gpt-4.1"),
355
367
  prompt: "Explain machine learning concepts.",
368
+ onError({ error }) {
369
+ streamError = error;
370
+ },
356
371
  });
357
372
 
358
373
  for await (const delta of result.textStream) {
359
374
  process.stdout.write(delta);
360
375
  }
361
376
 
362
- // Await final result to catch any errors that occurred during streaming
363
- const finalResult = await result;
364
- console.log("\n\nUsage:", finalResult.usage);
377
+ // textStream does not throw stream errors; preserve the original API error.
378
+ if (streamError !== undefined) throw streamError;
379
+
380
+ // streamText returns a result object; its usage property is a promise.
381
+ console.log("\n\nUsage:", await result.usage);
365
382
  } catch (error) {
366
- if (error instanceof APICallError) {
367
- console.error("API Error:", error.message);
368
- // See Error Handling section for complete error type reference
383
+ process.exitCode = 1;
384
+ if (APICallError.isInstance(error)) {
385
+ console.error("API error:", error.statusCode, error.name);
386
+ } else {
387
+ console.error("Streaming failed:", error instanceof Error ? error.name : "Unknown error");
369
388
  }
370
- throw error;
371
389
  }
372
390
  ```
373
391
 
@@ -495,7 +513,7 @@ const result = await generateText({
495
513
 
496
514
  ⚠️ **Model Limitations:** Some models have tool calling restrictions. See
497
515
  [API Reference - Model-Specific Tool Limitations](./API_REFERENCE.md#model-specific-tool-limitations)
498
- for the complete comparison table.
516
+ for upstream support documentation.
499
517
 
500
518
  ### Multi-modal Input (Images)
501
519
 
@@ -563,7 +581,7 @@ Ground LLM responses in your own documents using vector databases.
563
581
  const provider = createSAPAIProvider({
564
582
  defaultSettings: {
565
583
  grounding: buildDocumentGroundingConfig({
566
- filters: [{ id: "vector-store-1", data_repositories: ["*"] }],
584
+ filters: [{ id: "knowledge-filter", data_repositories: ["*"] }],
567
585
  placeholders: { input: ["groundingRequest"], output: "groundingOutput" },
568
586
  }),
569
587
  },
@@ -621,7 +639,10 @@ const model = provider("gpt-4.1");
621
639
  ### Provider Options (Per-Call Overrides)
622
640
 
623
641
  Override constructor settings on a per-call basis using `providerOptions`.
624
- Options are validated at runtime with Zod schemas.
642
+ Only the documented per-call fields are supported: unknown top-level fields
643
+ are stripped by the Zod schemas, while additional `modelParams` keys pass
644
+ through. Standard AI SDK generation options (for example, `temperature`) take
645
+ precedence over the corresponding `providerOptions` model parameters.
625
646
 
626
647
  ```typescript
627
648
  import { generateText } from "ai";
@@ -654,13 +675,14 @@ authentication, model parameters, data masking, content filtering, and more.
654
675
 
655
676
  **Common Configuration:**
656
677
 
657
- - `name`: Provider name (default: `'sap-ai'`). Used as key in
658
- `providerOptions`/`providerMetadata`.
678
+ - `name`: Provider identifier prefix (default: `'sap-ai'`). The segment before
679
+ the first dot is used as the key in `providerOptions`/`providerMetadata`.
659
680
  - `resourceGroup`: SAP AI Core resource group (default: 'default')
660
681
  - `deploymentId`: Specific deployment ID (auto-resolved if not set)
661
682
  - `requestConfig`: Custom HTTP request configuration (headers, params, timeout, etc.)
662
683
  forwarded to the underlying SAP AI SDK client on every call. Provider-level scope
663
- only; use `requestConfig.headers` for SAP-specific headers such as
684
+ only; per-call `headers` can override individual headers. Use `requestConfig.headers`
685
+ for SAP-specific headers such as
664
686
  `AI-Object-Store-Secret-Name` (feedback service). See
665
687
  [API Reference](./API_REFERENCE.md#sapaiprovidersettings) for portability caveats.
666
688
  - `modelParams`: Temperature, maxTokens, topP, and other generation parameters
@@ -690,7 +712,9 @@ error handling across providers.
690
712
 
691
713
  - **Authentication (401)**: Check `AICORE_SERVICE_KEY` or `VCAP_SERVICES`
692
714
  - **Model not found (404)**: Confirm tenant/region supports the model ID
693
- - **Rate limit (429)**: Automatic retry with exponential backoff
715
+ - **Rate limit (429)**: High-level AI SDK calls retry eligible errors with
716
+ exponential backoff, bounded by `maxRetries`; direct provider calls do not
717
+ implement retries
694
718
  - **Streaming**: Iterate `textStream` correctly; don't mix `generateText` and
695
719
  `streamText`
696
720
 
@@ -704,10 +728,10 @@ streaming, and tool calling.
704
728
  ## Performance
705
729
 
706
730
  - Prefer streaming (`streamText`) for long outputs to reduce latency and memory.
707
- - Tune `modelParams` carefully: lower `temperature` for deterministic results;
731
+ - Tune `modelParams` carefully: lower `temperature` for less variable results;
708
732
  set `maxTokens` to expected response size.
709
- - Use `defaultSettings` at provider creation for shared knobs across models to
710
- avoid per-call overhead.
733
+ - Use `defaultSettings` at provider creation to share configuration across models;
734
+ settings are still merged and validated when models and calls are prepared.
711
735
  - Avoid unnecessary history: keep `messages` concise to reduce prompt size and
712
736
  cost.
713
737
 
@@ -734,19 +758,19 @@ repository's AI SDK 7 dependency and the local `../src/index-v4` entrypoint.
734
758
  In an AI SDK 7 application, import from `@jerome-benoit/sap-ai-provider/v4`.
735
759
  See [Installation](#installation) for other AI SDK versions.
736
760
 
737
- | Example | Description | Key Features |
738
- | ----------------------------------- | --------------------------- | --------------------------------------- |
739
- | `example-generate-text.ts` | Basic text generation | Simple prompts, synchronous generation |
740
- | `example-simple-chat-completion.ts` | Simple chat conversation | System messages, user prompts |
741
- | `example-chat-completion-tool.ts` | Tool calling with functions | Weather API tool, function execution |
742
- | `example-streaming-chat.ts` | Streaming responses | Real-time text generation, SSE |
743
- | `example-image-recognition.ts` | Multi-modal with images | Vision models, image analysis |
744
- | `example-data-masking.ts` | Data privacy integration | DPI masking, anonymization |
745
- | `example-content-filtering.ts` | Content filtering | Azure Content Safety, orchestration |
746
- | `example-document-grounding.ts` | Document grounding (RAG) | Vector store, retrieval-augmented gen |
747
- | `example-translation.ts` | Input/output translation | Multi-language support, SAP translation |
748
- | `example-embeddings.ts` | Text embeddings | Vector generation, semantic similarity |
749
- | `example-foundation-models.ts` | Foundation Models API | Direct model access, logprobs, seed |
761
+ | Example | Description | Key Features |
762
+ | ----------------------------------- | --------------------------- | ---------------------------------------- |
763
+ | `example-generate-text.ts` | Basic text generation | Simple prompts, non-streaming generation |
764
+ | `example-simple-chat-completion.ts` | Simple chat conversation | System messages, user prompts |
765
+ | `example-chat-completion-tool.ts` | Tool calling with functions | Demo weather tool, function execution |
766
+ | `example-streaming-chat.ts` | Streaming responses | Real-time text generation, SSE |
767
+ | `example-image-recognition.ts` | Multi-modal with images | Vision models, image analysis |
768
+ | `example-data-masking.ts` | Data privacy integration | DPI masking, anonymization |
769
+ | `example-content-filtering.ts` | Content filtering | Azure Content Safety, orchestration |
770
+ | `example-document-grounding.ts` | Document grounding (RAG) | Vector store, retrieval-augmented gen |
771
+ | `example-translation.ts` | Input/output translation | Multi-language support, SAP translation |
772
+ | `example-embeddings.ts` | Text embeddings | Vector generation, semantic similarity |
773
+ | `example-foundation-models.ts` | Foundation Models API | Direct model access, logprobs, seed |
750
774
 
751
775
  **Running Examples:**
752
776
 
@@ -754,11 +778,29 @@ See [Installation](#installation) for other AI SDK versions.
754
778
  npx tsx examples/example-generate-text.ts
755
779
  ```
756
780
 
757
- > **Note:** Examples require `AICORE_SERVICE_KEY` environment variable. See
758
- > [Environment Setup](./ENVIRONMENT_SETUP.md) for configuration.
781
+ > **Note:** Configure `AICORE_SERVICE_KEY` locally or bind the application to
782
+ > SAP AI Core on SAP BTP. See [Environment Setup](./ENVIRONMENT_SETUP.md).
759
783
 
760
784
  ## Migration Guides
761
785
 
786
+ ### Upgrading from v4.x to v5.x
787
+
788
+ Version 5.0 adds **AI SDK 7** support through the **V4** facade and requires
789
+ **Node.js 22.12 or newer** for both packages. The root entrypoint remains
790
+ **V3 for AI SDK 6**; upgrading the provider does not require switching SDKs.
791
+
792
+ **Key changes:**
793
+
794
+ - **Runtime**: Upgrade local, CI and deployment environments from Node.js 20
795
+ to Node.js 22.12 or newer.
796
+ - **Entrypoints**: Use `/v4` with SDK 7, the root with SDK 6, or `/v2` with
797
+ SDK 5. The standalone V2 package remains available for SDK 5/6.
798
+ - **Multimodal inputs**: V4 tagged JPEG/PDF inputs are normalized correctly;
799
+ unsupported binary objects are rejected instead of silently stringified.
800
+
801
+ See the [4.x to 5.x migration guide](./MIGRATION_GUIDE.md#version-4x-to-5x-breaking-changes)
802
+ for installation commands, compatibility details and the migration checklist.
803
+
762
804
  ### Upgrading from v3.x to v4.x
763
805
 
764
806
  Version 4.0 migrates from **LanguageModelV2** to **LanguageModelV3**
@@ -796,7 +838,7 @@ complete upgrade instructions.**
796
838
 
797
839
  - `SAPAIError` removed → Use `APICallError` from `@ai-sdk/provider`
798
840
  - Error properties: `error.code` → `error.statusCode`
799
- - Automatic retries for rate limits (429) and server errors (5xx)
841
+ - Retryable error classification for the AI SDK's rate-limit/server-error retries
800
842
 
801
843
  ### Upgrading from v1.x to v2.x
802
844
 
@@ -830,7 +872,7 @@ for details.
830
872
  ### Documentation
831
873
 
832
874
  - [Migration Guide](./MIGRATION_GUIDE.md) - Version upgrade instructions (v1.x →
833
- v2.x → v3.x → v4.x)
875
+ v2.x → v3.x → v4.x → v5.x)
834
876
  - [API Reference](./API_REFERENCE.md) - Complete API documentation with all
835
877
  types and functions
836
878
  - [Environment Setup](./ENVIRONMENT_SETUP.md) - Authentication and configuration