@jerome-benoit/sap-ai-provider-v2 5.0.3 → 5.1.0

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 (44) hide show
  1. package/README.md +44 -24
  2. package/dist/chunk-4ILJD6PI.js +333 -0
  3. package/dist/chunk-4ILJD6PI.js.map +1 -0
  4. package/dist/chunk-BHA5MIN6.js +224 -0
  5. package/dist/chunk-BHA5MIN6.js.map +1 -0
  6. package/dist/{chunk-4JLNWASF.js → chunk-DLGBK3C3.js} +91 -7
  7. package/dist/chunk-DLGBK3C3.js.map +1 -0
  8. package/dist/{chunk-E76ZDPIW.js → chunk-EUBI5ENK.js} +54 -27
  9. package/dist/chunk-EUBI5ENK.js.map +1 -0
  10. package/dist/{chunk-YP3AADWD.js → chunk-FKHOJ3ZC.js} +24 -3
  11. package/dist/chunk-FKHOJ3ZC.js.map +1 -0
  12. package/dist/{chunk-UIBQ5AFS.js → chunk-QFMHNGLB.js} +56 -218
  13. package/dist/chunk-QFMHNGLB.js.map +1 -0
  14. package/dist/{chunk-3H5C5U22.js → chunk-QQQYMQPU.js} +19 -10
  15. package/dist/chunk-QQQYMQPU.js.map +1 -0
  16. package/dist/{chunk-NF355OFT.js → chunk-ZOBD7PXJ.js} +116 -21
  17. package/dist/chunk-ZOBD7PXJ.js.map +1 -0
  18. package/dist/{foundation-models-embedding-model-strategy-SAVQFBF4.js → foundation-models-embedding-model-strategy-3WAKJXBY.js} +5 -4
  19. package/dist/{foundation-models-embedding-model-strategy-SAVQFBF4.js.map → foundation-models-embedding-model-strategy-3WAKJXBY.js.map} +1 -1
  20. package/dist/{foundation-models-language-model-strategy-ZDOWVYTA.js → foundation-models-language-model-strategy-PJ26VXEA.js} +21 -8
  21. package/dist/foundation-models-language-model-strategy-PJ26VXEA.js.map +1 -0
  22. package/dist/index.cjs +2008 -497
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +798 -185
  25. package/dist/index.d.ts +798 -185
  26. package/dist/index.js +148 -24
  27. package/dist/index.js.map +1 -1
  28. package/dist/{orchestration-embedding-model-strategy-GT27AFII.js → orchestration-embedding-model-strategy-AZ76XLMD.js} +6 -5
  29. package/dist/{orchestration-embedding-model-strategy-GT27AFII.js.map → orchestration-embedding-model-strategy-AZ76XLMD.js.map} +1 -1
  30. package/dist/{orchestration-language-model-strategy-7QTPQHCC.js → orchestration-language-model-strategy-CT6RHCYO.js} +48 -17
  31. package/dist/orchestration-language-model-strategy-CT6RHCYO.js.map +1 -0
  32. package/dist/responses-language-model-strategy-UYTV6TPM.js +738 -0
  33. package/dist/responses-language-model-strategy-UYTV6TPM.js.map +1 -0
  34. package/dist/sap-ai-error-UPKYWPSS.js +16 -0
  35. package/dist/sap-ai-error-UPKYWPSS.js.map +1 -0
  36. package/package.json +79 -39
  37. package/dist/chunk-3H5C5U22.js.map +0 -1
  38. package/dist/chunk-4JLNWASF.js.map +0 -1
  39. package/dist/chunk-E76ZDPIW.js.map +0 -1
  40. package/dist/chunk-NF355OFT.js.map +0 -1
  41. package/dist/chunk-UIBQ5AFS.js.map +0 -1
  42. package/dist/chunk-YP3AADWD.js.map +0 -1
  43. package/dist/foundation-models-language-model-strategy-ZDOWVYTA.js.map +0 -1
  44. package/dist/orchestration-language-model-strategy-7QTPQHCC.js.map +0 -1
@@ -1,28 +1,32 @@
1
1
  import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url);
2
+ import {
3
+ deepMerge,
4
+ dropUnsupportedParamsSchema,
5
+ responsesModelOptionsSchema
6
+ } from "./chunk-BHA5MIN6.js";
2
7
  import {
3
8
  ApiSwitchError,
4
- UnsupportedFeatureError,
5
- deepMerge
6
- } from "./chunk-UIBQ5AFS.js";
9
+ UnsupportedFeatureError
10
+ } from "./chunk-QFMHNGLB.js";
7
11
 
8
12
  // src/sap-ai-validation.ts
9
13
  function validateEscapeTemplatePlaceholders(api, escapeTemplatePlaceholders) {
10
- if (api === "foundation-models" && escapeTemplatePlaceholders === true) {
14
+ if (api !== "orchestration" && escapeTemplatePlaceholders === true) {
11
15
  throw new UnsupportedFeatureError(
12
16
  ESCAPE_TEMPLATE_PLACEHOLDERS_DESCRIPTION,
13
- "foundation-models",
17
+ api,
14
18
  "orchestration"
15
19
  );
16
20
  }
17
21
  }
18
- function validateFoundationModelsOnlyOptions(settings) {
22
+ function validateFoundationModelsOnlyOptions(api, settings) {
19
23
  if (!settings) return;
20
24
  const fmSettings = settings;
21
25
  for (const feature of FOUNDATION_MODELS_ONLY_FEATURE_KEYS) {
22
26
  if (fmSettings[feature] !== void 0) {
23
27
  throw new UnsupportedFeatureError(
24
28
  FOUNDATION_MODELS_ONLY_FEATURES[feature],
25
- "orchestration",
29
+ api,
26
30
  "foundation-models"
27
31
  );
28
32
  }
@@ -40,20 +44,17 @@ function validateOrchestrationOnlyEmbeddingOptions(settings) {
40
44
  }
41
45
  }
42
46
  }
43
- function validateOrchestrationOnlyOptions(settings) {
47
+ function validateOrchestrationOnlyOptions(api, settings) {
44
48
  if (!settings) return;
45
49
  const orchSettings = settings;
46
50
  for (const feature of ORCHESTRATION_ONLY_FEATURE_KEYS) {
47
51
  if (orchSettings[feature] !== void 0) {
48
- throw new UnsupportedFeatureError(
49
- ORCHESTRATION_ONLY_FEATURES[feature],
50
- "foundation-models",
51
- "orchestration"
52
- );
52
+ throw new UnsupportedFeatureError(ORCHESTRATION_ONLY_FEATURES[feature], api, "orchestration");
53
53
  }
54
54
  }
55
55
  }
56
56
  var ORCHESTRATION_ONLY_FEATURE_KEYS = [
57
+ "dropUnsupportedParams",
57
58
  "fallbackModuleConfigs",
58
59
  "filtering",
59
60
  "grounding",
@@ -66,6 +67,7 @@ var ORCHESTRATION_ONLY_FEATURE_KEYS = [
66
67
  "translation"
67
68
  ];
68
69
  var ORCHESTRATION_ONLY_FEATURES = {
70
+ dropUnsupportedParams: "Unsupported parameter handling (dropUnsupportedParams)",
69
71
  fallbackModuleConfigs: "Fallback module configurations (fallbackModuleConfigs)",
70
72
  filtering: "Content filtering",
71
73
  grounding: "Document grounding",
@@ -82,6 +84,7 @@ var FOUNDATION_MODELS_ONLY_FEATURES = {
82
84
  dataSources: "Azure On Your Data (dataSources)"
83
85
  };
84
86
  var ORCHESTRATION_ONLY_INVOCATION_FEATURE_KEYS = [
87
+ "dropUnsupportedParams",
85
88
  "orchestrationConfigRef",
86
89
  "placeholderValues",
87
90
  "promptTemplateRef"
@@ -94,7 +97,7 @@ var ESCAPE_TEMPLATE_PLACEHOLDERS_DESCRIPTION = "escapeTemplatePlaceholders (Jinj
94
97
  function validateApiSwitch(fromApi, toApi, modelSettings, embeddingSettings) {
95
98
  if (fromApi === toApi) return;
96
99
  if (!modelSettings && !embeddingSettings) return;
97
- if (fromApi === "orchestration" && toApi === "foundation-models") {
100
+ if (toApi !== "orchestration") {
98
101
  const orchSettings = modelSettings;
99
102
  for (const feature of ORCHESTRATION_ONLY_FEATURE_KEYS) {
100
103
  if (orchSettings?.[feature] !== void 0) {
@@ -107,7 +110,7 @@ function validateApiSwitch(fromApi, toApi, modelSettings, embeddingSettings) {
107
110
  }
108
111
  }
109
112
  }
110
- if (fromApi === "foundation-models" && toApi === "orchestration") {
113
+ if (toApi !== "foundation-models") {
111
114
  const fmSettings = modelSettings;
112
115
  for (const feature of FOUNDATION_MODELS_ONLY_FEATURE_KEYS) {
113
116
  if (fmSettings?.[feature] !== void 0) {
@@ -115,8 +118,15 @@ function validateApiSwitch(fromApi, toApi, modelSettings, embeddingSettings) {
115
118
  }
116
119
  }
117
120
  }
121
+ if (toApi !== "responses" && modelSettings && "responses" in modelSettings && modelSettings.responses !== void 0) {
122
+ throw new ApiSwitchError(fromApi, toApi, "responses");
123
+ }
118
124
  }
119
- var VALID_API_TYPES = ["orchestration", "foundation-models"];
125
+ var VALID_API_TYPES = [
126
+ "orchestration",
127
+ "foundation-models",
128
+ "responses"
129
+ ];
120
130
  function mergeSettingsWithApi(defaultSettings, callSettings, fallbackApi) {
121
131
  return {
122
132
  ...deepMerge(defaultSettings, callSettings),
@@ -166,27 +176,44 @@ function validateSettings(options) {
166
176
  );
167
177
  }
168
178
  }
169
- if (api === "foundation-models") {
170
- validateOrchestrationOnlyOptions(modelSettings);
171
- validateOrchestrationOnlyInvocationOptions(invocationSettings);
179
+ if (api === "responses" && embeddingSettings !== void 0) {
180
+ throw new UnsupportedFeatureError("Embeddings", "responses", "foundation-models");
181
+ }
182
+ if (api !== "orchestration") {
183
+ validateOrchestrationOnlyOptions(api, modelSettings);
184
+ validateOrchestrationOnlyInvocationOptions(api, invocationSettings);
172
185
  validateOrchestrationOnlyEmbeddingOptions(embeddingSettings);
186
+ }
187
+ if (api !== "foundation-models") {
188
+ validateFoundationModelsOnlyOptions(api, modelSettings);
189
+ }
190
+ const modelResponses = modelSettings && "responses" in modelSettings ? modelSettings.responses : void 0;
191
+ const invocationResponses = invocationSettings?.responses;
192
+ if (api !== "responses") {
193
+ if (modelResponses !== void 0 || invocationResponses !== void 0) {
194
+ throw new UnsupportedFeatureError("Responses options (responses)", api, "responses");
195
+ }
173
196
  } else {
174
- validateFoundationModelsOnlyOptions(modelSettings);
197
+ if (modelResponses !== void 0) responsesModelOptionsSchema.parse(modelResponses);
198
+ if (invocationResponses !== void 0) responsesModelOptionsSchema.parse(invocationResponses);
199
+ }
200
+ const modelDropUnsupportedParams = modelSettings?.dropUnsupportedParams;
201
+ if (modelDropUnsupportedParams !== void 0) {
202
+ dropUnsupportedParamsSchema.parse(modelDropUnsupportedParams);
203
+ }
204
+ if (invocationSettings?.dropUnsupportedParams !== void 0) {
205
+ dropUnsupportedParamsSchema.parse(invocationSettings.dropUnsupportedParams);
175
206
  }
176
207
  const modelEscape = modelSettings?.escapeTemplatePlaceholders;
177
208
  const invocationEscape = invocationSettings?.escapeTemplatePlaceholders;
178
209
  const effectiveEscape = invocationEscape ?? modelEscape;
179
210
  validateEscapeTemplatePlaceholders(api, effectiveEscape);
180
211
  }
181
- function validateOrchestrationOnlyInvocationOptions(invocationSettings) {
212
+ function validateOrchestrationOnlyInvocationOptions(api, invocationSettings) {
182
213
  if (!invocationSettings) return;
183
214
  for (const feature of ORCHESTRATION_ONLY_INVOCATION_FEATURE_KEYS) {
184
215
  if (invocationSettings[feature] !== void 0) {
185
- throw new UnsupportedFeatureError(
186
- ORCHESTRATION_ONLY_FEATURES[feature],
187
- "foundation-models",
188
- "orchestration"
189
- );
216
+ throw new UnsupportedFeatureError(ORCHESTRATION_ONLY_FEATURES[feature], api, "orchestration");
190
217
  }
191
218
  }
192
219
  }
@@ -197,4 +224,4 @@ export {
197
224
  validateMaskingProvidersDeprecation,
198
225
  validateSettings
199
226
  };
200
- //# sourceMappingURL=chunk-E76ZDPIW.js.map
227
+ //# sourceMappingURL=chunk-EUBI5ENK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sap-ai-validation.ts"],"sourcesContent":["/** Validation and resolution functions for SAP AI API-specific features. */\nimport type { SharedV3Warning } from \"@ai-sdk/provider\";\n\nimport type {\n FoundationModelsModelSettings,\n OrchestrationModelSettings,\n SAPAIApiType,\n SAPAIEmbeddingSettings,\n SAPAIModelSettings,\n SAPAISettings,\n} from \"./sap-ai-settings.js\";\n\nimport { deepMerge } from \"./deep-merge.js\";\nimport { ApiSwitchError, UnsupportedFeatureError } from \"./sap-ai-error.js\";\nimport {\n dropUnsupportedParamsSchema,\n responsesModelOptionsSchema,\n} from \"./sap-ai-provider-options.js\";\n\n/**\n * Type guard for Foundation Models API settings.\n * @param settings - Settings to check.\n * @returns True if settings are for Foundation Models API.\n */\nexport function isFoundationModelsSettings(\n settings: SAPAIModelSettings | SAPAISettings,\n): settings is FoundationModelsModelSettings {\n return settings.api === \"foundation-models\";\n}\n\n/**\n * Type guard for Orchestration API settings.\n * @param settings - Settings to check.\n * @returns True if settings are for Orchestration API.\n */\nexport function isOrchestrationSettings(\n settings: SAPAIModelSettings | SAPAISettings,\n): settings is OrchestrationModelSettings {\n return settings.api === undefined || settings.api === \"orchestration\";\n}\n\n/**\n * Validates escapeTemplatePlaceholders option based on API type.\n *\n * Jinja2 template escaping is only supported by the Orchestration API.\n * @param api - SAP AI API type.\n * @param escapeTemplatePlaceholders - Whether to escape template placeholders.\n * @throws {UnsupportedFeatureError} When escapeTemplatePlaceholders is true with a direct model API.\n * @internal\n */\nfunction validateEscapeTemplatePlaceholders(\n api: SAPAIApiType,\n escapeTemplatePlaceholders: boolean | undefined,\n): void {\n if (api !== \"orchestration\" && escapeTemplatePlaceholders === true) {\n throw new UnsupportedFeatureError(\n ESCAPE_TEMPLATE_PLACEHOLDERS_DESCRIPTION,\n api,\n \"orchestration\",\n );\n }\n}\n\n/**\n * Validates that Foundation Models-only options are not used with another API.\n *\n * Foundation Models-only features:\n * - `dataSources` - Azure On Your Data configuration\n * @param api - Selected SAP API.\n * @param settings - Settings to validate.\n * @throws {UnsupportedFeatureError} When dataSources is set with another API.\n * @internal\n */\nfunction validateFoundationModelsOnlyOptions(\n api: SAPAIApiType,\n settings: SAPAIModelSettings | SAPAISettings | undefined,\n): void {\n if (!settings) return;\n\n const fmSettings = settings as FoundationModelsModelSettings;\n\n for (const feature of FOUNDATION_MODELS_ONLY_FEATURE_KEYS) {\n if (fmSettings[feature] !== undefined) {\n throw new UnsupportedFeatureError(\n FOUNDATION_MODELS_ONLY_FEATURES[feature],\n api,\n \"foundation-models\",\n );\n }\n }\n}\n\n/**\n * Validates that Orchestration-only embedding options are not used with a direct model API.\n *\n * Orchestration-only embedding features:\n * - `masking` - Data masking module\n * @param settings - Embedding settings to validate.\n * @throws {UnsupportedFeatureError} When masking is set with a direct model API.\n * @internal\n */\nfunction validateOrchestrationOnlyEmbeddingOptions(\n settings: SAPAIEmbeddingSettings | undefined,\n): void {\n if (!settings) return;\n\n for (const feature of ORCHESTRATION_ONLY_EMBEDDING_FEATURE_KEYS) {\n if (settings[feature] !== undefined) {\n throw new UnsupportedFeatureError(\n ORCHESTRATION_ONLY_EMBEDDING_FEATURES[feature],\n \"foundation-models\",\n \"orchestration\",\n );\n }\n }\n}\n\n/**\n * Validates that Orchestration-only options are not used with a direct model API.\n *\n * Orchestration-only features:\n * - `dropUnsupportedParams` - Unsupported parameter handling for the primary local model\n * - `fallbackModuleConfigs` - Prompt module fallback configuration list\n * - `filtering` - Content filtering module\n * - `grounding` - Document grounding module\n * - `masking` - Data masking module\n * - `orchestrationConfigRef` - Prompt Registry configuration reference\n * - `placeholderValues` - Jinja2 template placeholder values\n * - `promptTemplateRef` - Prompt Registry template reference\n * - `streamOptions` - Post-LLM module streaming configuration\n * - `tools` - SAP-format tool definitions (use AI SDK tools instead)\n * - `translation` - Translation module\n * @param api - Selected SAP API.\n * @param settings - Settings to validate.\n * @throws {UnsupportedFeatureError} When any Orchestration-only feature is set with a direct model API.\n * @internal\n */\nfunction validateOrchestrationOnlyOptions(\n api: SAPAIApiType,\n settings: SAPAIModelSettings | SAPAISettings | undefined,\n): void {\n if (!settings) return;\n\n const orchSettings = settings as OrchestrationModelSettings;\n\n for (const feature of ORCHESTRATION_ONLY_FEATURE_KEYS) {\n if (orchSettings[feature] !== undefined) {\n throw new UnsupportedFeatureError(ORCHESTRATION_ONLY_FEATURES[feature], api, \"orchestration\");\n }\n }\n}\n\n/**\n * Keys for Orchestration-only features.\n * @internal\n */\nconst ORCHESTRATION_ONLY_FEATURE_KEYS = [\n \"dropUnsupportedParams\",\n \"fallbackModuleConfigs\",\n \"filtering\",\n \"grounding\",\n \"masking\",\n \"orchestrationConfigRef\",\n \"placeholderValues\",\n \"promptTemplateRef\",\n \"streamOptions\",\n \"tools\",\n \"translation\",\n] as const;\n\n/**\n * Mapping of Orchestration-only feature keys to human-readable descriptions.\n * Used for generating consistent error messages.\n * @internal\n */\nconst ORCHESTRATION_ONLY_FEATURES: Readonly<\n Record<(typeof ORCHESTRATION_ONLY_FEATURE_KEYS)[number], string>\n> = {\n dropUnsupportedParams: \"Unsupported parameter handling (dropUnsupportedParams)\",\n fallbackModuleConfigs: \"Fallback module configurations (fallbackModuleConfigs)\",\n filtering: \"Content filtering\",\n grounding: \"Document grounding\",\n masking: \"Data masking\",\n orchestrationConfigRef: \"Orchestration config reference (orchestrationConfigRef)\",\n placeholderValues: \"Placeholder values (placeholderValues)\",\n promptTemplateRef: \"Prompt template reference (promptTemplateRef)\",\n streamOptions: \"Stream options for post-LLM modules\",\n tools: \"SAP-format tool definitions (use AI SDK tools instead)\",\n translation: \"Translation\",\n} as const;\n\n/**\n * Keys for Foundation Models-only features.\n * @internal\n */\nconst FOUNDATION_MODELS_ONLY_FEATURE_KEYS = [\"dataSources\"] as const;\n\n/**\n * Mapping of Foundation Models-only feature keys to human-readable descriptions.\n * Used for generating consistent error messages.\n * @internal\n */\nconst FOUNDATION_MODELS_ONLY_FEATURES: Readonly<\n Record<(typeof FOUNDATION_MODELS_ONLY_FEATURE_KEYS)[number], string>\n> = {\n dataSources: \"Azure On Your Data (dataSources)\",\n} as const;\n\n/**\n * Subset of Orchestration-only features that can be set at invocation level.\n * @internal\n */\nconst ORCHESTRATION_ONLY_INVOCATION_FEATURE_KEYS = [\n \"dropUnsupportedParams\",\n \"orchestrationConfigRef\",\n \"placeholderValues\",\n \"promptTemplateRef\",\n] as const;\n\n/**\n * Keys for Orchestration-only embedding features.\n * @internal\n */\nconst ORCHESTRATION_ONLY_EMBEDDING_FEATURE_KEYS = [\"masking\"] as const;\n\n/**\n * Mapping of Orchestration-only embedding feature keys to human-readable descriptions.\n * Uses the same descriptions as the main ORCHESTRATION_ONLY_FEATURES for consistency.\n * @internal\n */\nconst ORCHESTRATION_ONLY_EMBEDDING_FEATURES: Readonly<\n Record<(typeof ORCHESTRATION_ONLY_EMBEDDING_FEATURE_KEYS)[number], string>\n> = {\n masking: ORCHESTRATION_ONLY_FEATURES.masking,\n} as const;\n\n/**\n * Human-readable description for escapeTemplatePlaceholders feature.\n * Used for generating consistent error messages.\n * @internal\n */\nconst ESCAPE_TEMPLATE_PLACEHOLDERS_DESCRIPTION =\n \"escapeTemplatePlaceholders (Jinja2 template escaping)\";\n\n/**\n * Validates that switching APIs at invocation time is allowed.\n *\n * API switching is blocked when the model was configured with features\n * that are specific to one API and incompatible with the target API.\n * @param fromApi - Source API type (configured at model creation).\n * @param toApi - Target API type (requested at invocation time).\n * @param modelSettings - Language model settings to validate for conflicts.\n * @param embeddingSettings - Embedding model settings to validate for conflicts.\n * @throws {ApiSwitchError} When the model has features incompatible with the target API.\n * @internal\n */\nfunction validateApiSwitch(\n fromApi: SAPAIApiType,\n toApi: SAPAIApiType,\n modelSettings: SAPAIModelSettings | SAPAISettings | undefined,\n embeddingSettings: SAPAIEmbeddingSettings | undefined,\n): void {\n if (fromApi === toApi) return;\n if (!modelSettings && !embeddingSettings) return;\n\n if (toApi !== \"orchestration\") {\n const orchSettings = modelSettings as OrchestrationModelSettings | undefined;\n\n for (const feature of ORCHESTRATION_ONLY_FEATURE_KEYS) {\n if (orchSettings?.[feature] !== undefined) {\n throw new ApiSwitchError(fromApi, toApi, feature);\n }\n }\n for (const feature of ORCHESTRATION_ONLY_EMBEDDING_FEATURE_KEYS) {\n if (embeddingSettings?.[feature] !== undefined) {\n throw new ApiSwitchError(fromApi, toApi, feature);\n }\n }\n }\n\n if (toApi !== \"foundation-models\") {\n const fmSettings = modelSettings as FoundationModelsModelSettings | undefined;\n\n for (const feature of FOUNDATION_MODELS_ONLY_FEATURE_KEYS) {\n if (fmSettings?.[feature] !== undefined) {\n throw new ApiSwitchError(fromApi, toApi, feature);\n }\n }\n }\n\n if (\n toApi !== \"responses\" &&\n modelSettings &&\n \"responses\" in modelSettings &&\n modelSettings.responses !== undefined\n ) {\n throw new ApiSwitchError(fromApi, toApi, \"responses\");\n }\n}\n\n/**\n * @internal\n */\nconst VALID_API_TYPES: readonly SAPAIApiType[] = [\n \"orchestration\",\n \"foundation-models\",\n \"responses\",\n];\n\n/** Options for the main validation function. */\nexport interface ValidateSettingsOptions {\n readonly api: SAPAIApiType;\n readonly embeddingSettings?: SAPAIEmbeddingSettings;\n readonly invocationSettings?: {\n readonly api?: SAPAIApiType;\n readonly dropUnsupportedParams?: boolean;\n readonly escapeTemplatePlaceholders?: boolean;\n readonly orchestrationConfigRef?: unknown;\n readonly placeholderValues?: unknown;\n readonly promptTemplateRef?: unknown;\n readonly responses?: unknown;\n };\n readonly modelApi?: SAPAIApiType;\n readonly modelSettings?: SAPAIModelSettings | SAPAISettings;\n}\n\n/**\n * Gets the effective escapeTemplatePlaceholders value based on API and settings.\n * @param api - SAP AI API type.\n * @param modelSettings - Model settings.\n * @param invocationEscape - Invocation-level escape setting.\n * @returns Effective escapeTemplatePlaceholders value.\n */\nexport function getEffectiveEscapeTemplatePlaceholders(\n api: SAPAIApiType,\n modelSettings: SAPAIModelSettings | SAPAISettings | undefined,\n invocationEscape: boolean | undefined,\n): boolean {\n if (api !== \"orchestration\") {\n return false;\n }\n\n if (invocationEscape !== undefined) {\n return invocationEscape;\n }\n\n const modelValue = (modelSettings as OrchestrationModelSettings | undefined)\n ?.escapeTemplatePlaceholders;\n if (modelValue !== undefined) {\n return modelValue;\n }\n\n return true;\n}\n\n/**\n * Merges settings with proper API precedence (callSettings > defaultSettings > fallbackApi).\n * @param defaultSettings - Provider-level default settings.\n * @param callSettings - Per-call settings that override defaults.\n * @param fallbackApi - Fallback API type when neither settings specify one.\n * @returns Merged settings with correct API precedence.\n * @internal\n */\nexport function mergeSettingsWithApi<T extends { api?: string }>(\n defaultSettings: Record<string, unknown> | undefined,\n callSettings: Partial<T>,\n fallbackApi: string,\n): T {\n return {\n ...deepMerge(defaultSettings, callSettings as Record<string, unknown>),\n api: callSettings.api ?? (defaultSettings?.api as string | undefined) ?? fallbackApi,\n } as T;\n}\n\n/**\n * Resolves the effective API type using the full precedence chain.\n * @param providerApi - Provider-level API type.\n * @param modelApi - Model-level API type.\n * @param invocationApi - Invocation-level API type.\n * @returns Resolved API type.\n */\nexport function resolveApi(\n providerApi: SAPAIApiType | undefined,\n modelApi: SAPAIApiType | undefined,\n invocationApi: SAPAIApiType | undefined,\n): SAPAIApiType {\n return invocationApi ?? modelApi ?? providerApi ?? \"orchestration\";\n}\n\n/**\n * Validates that the API value is a valid SAPAIApiType.\n * @param api - API value to validate.\n */\nexport function validateApiInput(api: unknown): void {\n if (api === undefined) return;\n\n if (typeof api !== \"string\" || !VALID_API_TYPES.includes(api as SAPAIApiType)) {\n throw new Error(\n `Invalid API type: ${JSON.stringify(api)}. ` +\n `Valid values are: ${VALID_API_TYPES.map((t) => `\"${t}\"`).join(\", \")}`,\n );\n }\n}\n\n/**\n * Pushes a deprecation warning when `settings.masking` carries `masking_providers`\n * without a `providers` block.\n * @param modelSettings - Resolved model settings (LM or embedding) that may carry a `masking` module.\n * @param warnings - Sink that collects the deprecation warning when it applies.\n * @internal\n */\nexport function validateMaskingProvidersDeprecation(\n modelSettings: undefined | { masking?: unknown },\n warnings: SharedV3Warning[],\n): void {\n const masking = modelSettings?.masking;\n if (!masking || typeof masking !== \"object\") {\n return;\n }\n const maskingRecord = masking as Record<string, unknown>;\n const hasDeprecated = maskingRecord.masking_providers !== undefined;\n const hasPreferred = maskingRecord.providers !== undefined;\n if (hasDeprecated && !hasPreferred) {\n warnings.push({\n message:\n \"settings.masking.masking_providers is deprecated and will be removed by SAP on 2027-03-20. \" +\n \"Migrate to settings.masking.providers.\",\n type: \"other\",\n });\n }\n}\n\n/**\n * Main validation function that performs all API-specific validations.\n *\n * This function orchestrates all validation checks:\n * 1. Validates API type inputs\n * 2. Checks for API switching conflicts\n * 3. Validates API-specific feature usage\n * 4. Validates template placeholder escaping\n * @param options - Validation options.\n * @throws {Error} When an invalid API type is provided.\n * @throws {ApiSwitchError} When attempting to switch APIs with incompatible settings.\n * @throws {UnsupportedFeatureError} When using features not supported by the current API.\n * @see {@link ApiSwitchError}\n * @see {@link UnsupportedFeatureError}\n */\nexport function validateSettings(options: ValidateSettingsOptions): void {\n const { api, embeddingSettings, invocationSettings, modelApi, modelSettings } = options;\n\n validateApiInput(api);\n if (invocationSettings?.api !== undefined) {\n validateApiInput(invocationSettings.api);\n }\n\n if (invocationSettings?.api !== undefined) {\n const effectiveModelApi = modelApi ?? \"orchestration\";\n if (effectiveModelApi !== invocationSettings.api) {\n validateApiSwitch(\n effectiveModelApi,\n invocationSettings.api,\n modelSettings,\n embeddingSettings,\n );\n }\n }\n\n if (api === \"responses\" && embeddingSettings !== undefined) {\n throw new UnsupportedFeatureError(\"Embeddings\", \"responses\", \"foundation-models\");\n }\n\n if (api !== \"orchestration\") {\n validateOrchestrationOnlyOptions(api, modelSettings);\n validateOrchestrationOnlyInvocationOptions(api, invocationSettings);\n validateOrchestrationOnlyEmbeddingOptions(embeddingSettings);\n }\n if (api !== \"foundation-models\") {\n validateFoundationModelsOnlyOptions(api, modelSettings);\n }\n\n const modelResponses =\n modelSettings && \"responses\" in modelSettings ? modelSettings.responses : undefined;\n const invocationResponses = invocationSettings?.responses;\n if (api !== \"responses\") {\n if (modelResponses !== undefined || invocationResponses !== undefined) {\n throw new UnsupportedFeatureError(\"Responses options (responses)\", api, \"responses\");\n }\n } else {\n if (modelResponses !== undefined) responsesModelOptionsSchema.parse(modelResponses);\n if (invocationResponses !== undefined) responsesModelOptionsSchema.parse(invocationResponses);\n }\n\n const modelDropUnsupportedParams = (modelSettings as OrchestrationModelSettings | undefined)\n ?.dropUnsupportedParams;\n if (modelDropUnsupportedParams !== undefined) {\n dropUnsupportedParamsSchema.parse(modelDropUnsupportedParams);\n }\n if (invocationSettings?.dropUnsupportedParams !== undefined) {\n dropUnsupportedParamsSchema.parse(invocationSettings.dropUnsupportedParams);\n }\n\n const modelEscape = (modelSettings as OrchestrationModelSettings | undefined)\n ?.escapeTemplatePlaceholders;\n const invocationEscape = invocationSettings?.escapeTemplatePlaceholders;\n const effectiveEscape = invocationEscape ?? modelEscape;\n validateEscapeTemplatePlaceholders(api, effectiveEscape);\n}\n\n/**\n * Validates that Orchestration-only options are not passed at invocation level with a direct model API.\n * @param api - Selected SAP API.\n * @param invocationSettings - Invocation-level settings to validate.\n * @throws {UnsupportedFeatureError} When any Orchestration-only feature is set at invocation level.\n * @internal\n */\nfunction validateOrchestrationOnlyInvocationOptions(\n api: SAPAIApiType,\n invocationSettings: ValidateSettingsOptions[\"invocationSettings\"],\n): void {\n if (!invocationSettings) return;\n\n for (const feature of ORCHESTRATION_ONLY_INVOCATION_FEATURE_KEYS) {\n if (invocationSettings[feature] !== undefined) {\n throw new UnsupportedFeatureError(ORCHESTRATION_ONLY_FEATURES[feature], api, \"orchestration\");\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAkDA,SAAS,mCACP,KACA,4BACM;AACN,MAAI,QAAQ,mBAAmB,+BAA+B,MAAM;AAClE,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAYA,SAAS,oCACP,KACA,UACM;AACN,MAAI,CAAC,SAAU;AAEf,QAAM,aAAa;AAEnB,aAAW,WAAW,qCAAqC;AACzD,QAAI,WAAW,OAAO,MAAM,QAAW;AACrC,YAAM,IAAI;AAAA,QACR,gCAAgC,OAAO;AAAA,QACvC;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWA,SAAS,0CACP,UACM;AACN,MAAI,CAAC,SAAU;AAEf,aAAW,WAAW,2CAA2C;AAC/D,QAAI,SAAS,OAAO,MAAM,QAAW;AACnC,YAAM,IAAI;AAAA,QACR,sCAAsC,OAAO;AAAA,QAC7C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAsBA,SAAS,iCACP,KACA,UACM;AACN,MAAI,CAAC,SAAU;AAEf,QAAM,eAAe;AAErB,aAAW,WAAW,iCAAiC;AACrD,QAAI,aAAa,OAAO,MAAM,QAAW;AACvC,YAAM,IAAI,wBAAwB,4BAA4B,OAAO,GAAG,KAAK,eAAe;AAAA,IAC9F;AAAA,EACF;AACF;AAMA,IAAM,kCAAkC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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import {
3
+ orchestrationReasoningBlockSchema
4
+ } from "./chunk-BHA5MIN6.js";
2
5
 
3
6
  // src/convert-to-sap-messages.ts
4
7
  import {
@@ -162,6 +165,7 @@ function convertToSAPMessages(prompt, options = {}) {
162
165
  let text = "";
163
166
  const textParts = parser ? [] : void 0;
164
167
  let anyCacheControl = false;
168
+ let reasoningContent;
165
169
  const toolCalls = [];
166
170
  for (const part of message.content) {
167
171
  switch (part.type) {
@@ -173,6 +177,21 @@ function convertToSAPMessages(prompt, options = {}) {
173
177
  break;
174
178
  }
175
179
  case "reasoning": {
180
+ const nativeNamespace = options.nativeReasoningProviderName;
181
+ const nativeOptions = nativeNamespace === void 0 ? void 0 : part.providerOptions?.[nativeNamespace];
182
+ if (nativeOptions !== null && typeof nativeOptions === "object" && !Array.isArray(nativeOptions) && Object.hasOwn(nativeOptions, "reasoningContent")) {
183
+ const parsed = orchestrationReasoningBlockSchema.safeParse(
184
+ nativeOptions.reasoningContent
185
+ );
186
+ if (!parsed.success) {
187
+ throw new InvalidPromptError({
188
+ message: "Invalid native Orchestration reasoning metadata.",
189
+ prompt
190
+ });
191
+ }
192
+ (reasoningContent ??= []).push(parsed.data);
193
+ break;
194
+ }
176
195
  if (includeReasoning && part.text) {
177
196
  const reasoning = `<think>${part.text}</think>`;
178
197
  text += reasoning;
@@ -219,11 +238,12 @@ function convertToSAPMessages(prompt, options = {}) {
219
238
  }
220
239
  }
221
240
  }
222
- if (text || toolCalls.length > 0) {
241
+ if (text || toolCalls.length > 0 || reasoningContent?.length) {
223
242
  const assistantMessage = {
224
243
  content: anyCacheControl && textParts ? textParts.map((p) => wrapAsTextContent(maybeEscape(p.text), p.cacheControl)) : maybeEscape(text),
225
244
  role: "assistant",
226
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
245
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
246
+ ...reasoningContent && { reasoning_content: reasoningContent }
227
247
  };
228
248
  messages.push(assistantMessage);
229
249
  }
@@ -376,8 +396,9 @@ function buildDataUrl(part) {
376
396
  }
377
397
 
378
398
  export {
399
+ getURLHref,
379
400
  convertToSAPMessages,
380
401
  escapeOrchestrationPlaceholders,
381
402
  unescapeOrchestrationPlaceholders
382
403
  };
383
- //# sourceMappingURL=chunk-YP3AADWD.js.map
404
+ //# sourceMappingURL=chunk-FKHOJ3ZC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/convert-to-sap-messages.ts"],"sourcesContent":["import type {\n AssistantChatMessage,\n ChatMessage,\n ReasoningBlock,\n SystemChatMessage,\n ToolChatMessage,\n UserChatMessage,\n UserChatMessageContentItem,\n} from \"@sap-ai-sdk/orchestration\";\n\nimport {\n InvalidPromptError,\n LanguageModelV3Prompt,\n type SharedV3Warning,\n UnsupportedFunctionalityError,\n} from \"@ai-sdk/provider\";\n\nimport type { CacheControl, ParsePartProviderOptions } from \"./sap-ai-provider-options.js\";\n\nimport { orchestrationReasoningBlockSchema } from \"./sap-ai-provider-options.js\";\n\n/**\n * Options for converting Vercel AI SDK prompts to SAP AI SDK messages.\n * @see {@link convertToSAPMessages}\n */\nexport interface ConvertToSAPMessagesOptions {\n /**\n * Whether to escape Jinja2 template delimiters (`{{`, `{%`, `{#`) in message content.\n * This prevents SAP orchestration from interpreting user content as template syntax.\n * @default true\n */\n readonly escapeTemplatePlaceholders?: boolean;\n /**\n * Whether to include assistant reasoning parts (wrapped in `<think>` tags).\n * @default false\n */\n readonly includeReasoning?: boolean;\n /** Configured namespace for lossless native Orchestration reasoning history. */\n readonly nativeReasoningProviderName?: string;\n /**\n * Optional callback that reads per-part `providerOptions['sap-ai']` (e.g. Anthropic\n * `cacheControl`) and forwards the result onto the SAP message item. Strategies that\n * do not honour part-level directives (Foundation Models) leave this undefined.\n * @default undefined\n */\n readonly parsePartProviderOptions?: ParsePartProviderOptions;\n /**\n * Optional sink for validation warnings raised by `parsePartProviderOptions`.\n * Issues reported by the parser are forwarded to the AI SDK call result.\n * The SAP parser deduplicates identical messages rather than warning per occurrence.\n */\n readonly warnings?: SharedV3Warning[];\n}\n\n/**\n * @internal\n */\nconst ZERO_WIDTH_SPACE = \"\\u200B\";\n\n/** Native cross-realm ArrayBuffer brand descriptor. */\nconst ARRAY_BUFFER_BYTE_LENGTH_DESCRIPTOR = Object.getOwnPropertyDescriptor(\n ArrayBuffer.prototype,\n \"byteLength\",\n);\n\n/** Native Uint8Array length descriptor, immune to subclass overrides. */\nconst TYPED_ARRAY_LENGTH_DESCRIPTOR = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(Uint8Array.prototype) as object,\n \"length\",\n);\n\nconst SUPPORTED_IMAGE_FORMATS = [\"image/png\", \"image/jpeg\", \"image/jpg\", \"image/gif\", \"image/webp\"];\n\n/** Native cross-realm typed array brand descriptor. */\nconst TYPED_ARRAY_TAG_DESCRIPTOR = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(Uint8Array.prototype) as object,\n Symbol.toStringTag,\n);\n\n/** Native cross-realm URL href descriptor. */\nconst URL_HREF_DESCRIPTOR = Object.getOwnPropertyDescriptor(URL.prototype, \"href\");\n\n/**\n * Returns the canonical href for genuine URL values across JavaScript realms.\n * @param value - The value to inspect.\n * @returns The URL href, or undefined when the value lacks URL internal slots.\n */\nexport function getURLHref(value: unknown): string | undefined {\n if (typeof value !== \"object\" || value === null || URL_HREF_DESCRIPTOR?.get === undefined) {\n return undefined;\n }\n try {\n const href: unknown = URL_HREF_DESCRIPTOR.get.call(value);\n return typeof href === \"string\" ? href : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns the RFC 4648 value of a base64 character.\n * @param charCode - The character's UTF-16 code unit.\n * @returns The base64 sextet value, or -1 when invalid.\n */\nfunction base64SextetValue(charCode: number): number {\n if (charCode >= 0x41 && charCode <= 0x5a) return charCode - 0x41;\n if (charCode >= 0x61 && charCode <= 0x7a) return charCode - 0x61 + 26;\n if (charCode >= 0x30 && charCode <= 0x39) return charCode - 0x30 + 52;\n if (charCode === 0x2b) return 62;\n if (charCode === 0x2f) return 63;\n return -1;\n}\n\n/**\n * Detects genuine ArrayBuffer values across JavaScript realms.\n * @param value - The value to inspect.\n * @returns Whether the value has ArrayBuffer internal slots.\n */\nfunction isArrayBuffer(value: unknown): value is ArrayBuffer {\n if (\n typeof value !== \"object\" ||\n value === null ||\n ARRAY_BUFFER_BYTE_LENGTH_DESCRIPTOR?.get === undefined\n ) {\n return false;\n }\n try {\n ARRAY_BUFFER_BYTE_LENGTH_DESCRIPTOR.get.call(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validates canonical RFC 4648 base64 in linear time and constant stack space.\n * @param value - The candidate base64 value.\n * @returns Whether the value is canonical RFC 4648 base64.\n */\nfunction isCanonicalBase64(value: string): boolean {\n const length = value.length;\n if (length % 4 !== 0) return false;\n\n let padding = 0;\n if (length > 0 && value.charCodeAt(length - 1) === 0x3d) padding++;\n if (length > 1 && value.charCodeAt(length - 2) === 0x3d) padding++;\n\n const payloadLength = length - padding;\n for (let index = 0; index < payloadLength; index++) {\n if (base64SextetValue(value.charCodeAt(index)) < 0) return false;\n }\n\n if (padding === 0) return true;\n const lastValue = base64SextetValue(value.charCodeAt(payloadLength - 1));\n return padding === 1 ? (lastValue & 0x03) === 0 : (lastValue & 0x0f) === 0;\n}\n\n/**\n * Detects genuine Uint8Array values across JavaScript realms.\n * @param value - The value to inspect.\n * @returns Whether the value has Uint8Array internal slots.\n */\nfunction isUint8Array(value: unknown): value is Uint8Array {\n if (\n typeof value !== \"object\" ||\n value === null ||\n TYPED_ARRAY_TAG_DESCRIPTOR?.get === undefined\n ) {\n return false;\n }\n try {\n return TYPED_ARRAY_TAG_DESCRIPTOR.get.call(value) === \"Uint8Array\";\n } catch {\n return false;\n }\n}\n\n/**\n * Serializes tool output, preserving BigInt values as strings and using a text\n * representation when JSON serialization is unavailable (for example, cycles).\n * @param value - The tool output to serialize.\n * @returns JSON or fallback text.\n * @throws {InvalidPromptError} When neither JSON nor text serialization is possible.\n * @internal\n */\nfunction safeJsonStringify(value: unknown): string {\n try {\n const serialized: unknown = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? val.toString() : (val as unknown),\n );\n if (typeof serialized === \"string\") return serialized;\n } catch {\n // Fall back to the output's text representation.\n }\n try {\n return String(value);\n } catch {\n throw new InvalidPromptError({ message: \"Tool output cannot be serialized.\", prompt: value });\n }\n}\n\n/**\n * Serializes tool arguments, rejecting values that cannot be represented as JSON.\n * @param input - Tool arguments or an already serialized JSON string.\n * @returns Serialized arguments.\n */\nfunction serializeToolCallInput(input: unknown): string {\n try {\n if (typeof input === \"string\") {\n JSON.parse(input);\n return input;\n }\n const serialized: unknown = JSON.stringify(input);\n if (typeof serialized === \"string\") return serialized;\n } catch {\n // Report invalid arguments as a prompt error instead of emitting an invalid SAP request.\n }\n throw new InvalidPromptError({\n message: \"Tool call input must be JSON-serializable.\",\n prompt: input,\n });\n}\n\n/**\n * Wraps a text payload as a SAP `TextContent` block, attaching `cache_control` when set.\n * @param text - Pre-escaped text payload.\n * @param cacheControl - Optional Anthropic prompt-cache directive.\n * @returns SAP `TextContent` block.\n */\nfunction wrapAsTextContent(\n text: string,\n cacheControl: CacheControl | undefined,\n): { cache_control?: CacheControl; text: string; type: \"text\" } {\n return cacheControl\n ? { cache_control: cacheControl, text, type: \"text\" }\n : { text, type: \"text\" };\n}\n\n/**\n * @internal\n */\nconst JINJA2_DELIMITERS_PATTERN = /\\{(?=[{%#])/g;\n\n/**\n * @internal\n */\nconst JINJA2_DELIMITERS_ESCAPED_PATTERN = new RegExp(`\\\\{${ZERO_WIDTH_SPACE}(?=[{%#])`, \"g\");\n\n/**\n * Encodes bytes as base64 using `btoa`, without the Node.js `Buffer` global.\n * @internal\n * @param bytes - The bytes to encode.\n * @returns The base64 string (empty string for empty input).\n */\nexport function base64FromBytes(bytes: Uint8Array): string {\n const CHUNK_SIZE = 0x8000;\n let byteLength: unknown;\n try {\n // Native validation rejects detached and out-of-bounds views, including empty ones.\n Uint8Array.prototype.at.call(bytes, 0);\n byteLength = TYPED_ARRAY_LENGTH_DESCRIPTOR?.get?.call(bytes);\n } catch {\n throw new UnsupportedFunctionalityError({\n functionality: \"Invalid Uint8Array file data.\",\n });\n }\n if (typeof byteLength !== \"number\") {\n throw new UnsupportedFunctionalityError({\n functionality: \"Invalid Uint8Array file data.\",\n });\n }\n\n const codeUnits = new Array<number>(Math.min(CHUNK_SIZE, byteLength));\n let binary = \"\";\n for (let offset = 0; offset < byteLength; offset += CHUNK_SIZE) {\n const chunkLength = Math.min(CHUNK_SIZE, byteLength - offset);\n codeUnits.length = chunkLength;\n for (let index = 0; index < chunkLength; index++) {\n const byte = bytes[offset + index];\n if (byte === undefined) {\n throw new UnsupportedFunctionalityError({\n functionality: \"Invalid Uint8Array file data.\",\n });\n }\n codeUnits[index] = byte;\n }\n binary += String.fromCharCode(...codeUnits);\n }\n return btoa(binary);\n}\n\n/**\n * Converts Vercel AI SDK prompt to SAP AI SDK ChatMessage array.\n *\n * Maps V3 message roles to SAP messages:\n * - `system` → `SystemChatMessage`\n * - `user` (text/images/files) → `UserChatMessage`\n * - `assistant` (text/tool-calls, optionally reasoning) → `AssistantChatMessage`\n * - `tool` (direct text values; other output variants as JSON) → `ToolChatMessage`\n * Unsupported assistant parts and non-result tool parts are ignored, with\n * warnings when a warning sink is supplied.\n * @param prompt - The Vercel AI SDK LanguageModelV3Prompt to convert.\n * @param options - Conversion options.\n * @param options.escapeTemplatePlaceholders - Whether to escape Jinja2 template delimiters (default: true).\n * @param options.includeReasoning - Whether to include assistant reasoning parts (default: false).\n * @param options.parsePartProviderOptions - Optional callback to read per-part `providerOptions['sap-ai']`. Strategies opt in to honour part-level directives such as Anthropic `cacheControl`.\n * @param options.warnings - Optional sink the parser pushes Zod validation issues into.\n * @returns SAP AI SDK ChatMessage array ready for orchestration requests.\n * @throws {UnsupportedFunctionalityError} When encountering unsupported user content or file data types.\n * @throws {InvalidPromptError} When message roles or tool arguments are invalid, or tool output cannot be serialized.\n */\nexport function convertToSAPMessages(\n prompt: LanguageModelV3Prompt,\n options: ConvertToSAPMessagesOptions = {},\n): ChatMessage[] {\n const messages: ChatMessage[] = [];\n const includeReasoning = options.includeReasoning ?? false;\n const escapeTemplatePlaceholders = options.escapeTemplatePlaceholders ?? true;\n\n const maybeEscape = (text: string): string =>\n escapeTemplatePlaceholders ? escapeOrchestrationPlaceholders(text) : text;\n\n const parser = options.parsePartProviderOptions;\n const parsePart = parser\n ? (providerOptions: unknown) => parser(providerOptions, options.warnings)\n : () => undefined;\n\n const pushWarningOnce = (feature: string, details: string): void => {\n if (!options.warnings) return;\n if (!options.warnings.some((w) => (w as { feature?: string }).feature === feature)) {\n options.warnings.push({ details, feature, type: \"unsupported\" });\n }\n };\n\n for (const message of prompt) {\n switch (message.role) {\n case \"assistant\": {\n let text = \"\";\n const textParts: undefined | { cacheControl?: CacheControl; text: string }[] = parser\n ? []\n : undefined;\n let anyCacheControl = false;\n let reasoningContent: ReasoningBlock[] | undefined;\n const toolCalls: {\n function: { arguments: string; name: string };\n id: string;\n type: \"function\";\n }[] = [];\n\n for (const part of message.content) {\n switch (part.type) {\n case \"file\": {\n pushWarningOnce(\n \"file content in assistant message\",\n \"SAP orchestration assistant messages carry text and tool calls only; file parts are ignored.\",\n );\n break;\n }\n case \"reasoning\": {\n const nativeNamespace = options.nativeReasoningProviderName;\n const nativeOptions: unknown =\n nativeNamespace === undefined ? undefined : part.providerOptions?.[nativeNamespace];\n if (\n nativeOptions !== null &&\n typeof nativeOptions === \"object\" &&\n !Array.isArray(nativeOptions) &&\n Object.hasOwn(nativeOptions, \"reasoningContent\")\n ) {\n const parsed = orchestrationReasoningBlockSchema.safeParse(\n (nativeOptions as Record<string, unknown>).reasoningContent,\n );\n if (!parsed.success) {\n throw new InvalidPromptError({\n message: \"Invalid native Orchestration reasoning metadata.\",\n prompt,\n });\n }\n (reasoningContent ??= []).push(parsed.data);\n break;\n }\n if (includeReasoning && part.text) {\n const reasoning = `<think>${part.text}</think>`;\n text += reasoning;\n textParts?.push({ text: reasoning });\n }\n break;\n }\n case \"text\": {\n if (!part.text) break;\n const partOpts = parsePart(part.providerOptions);\n const cacheControl = partOpts?.cacheControl;\n text += part.text;\n textParts?.push(\n cacheControl ? { cacheControl, text: part.text } : { text: part.text },\n );\n if (cacheControl) anyCacheControl = true;\n break;\n }\n case \"tool-call\": {\n const partOpts = parsePart(part.providerOptions);\n if (partOpts?.cacheControl) {\n pushWarningOnce(\n \"cacheControl on assistant tool-call\",\n \"SAP orchestration does not expose cache_control on the assistant tool-call envelope.\",\n );\n }\n const argumentsJson = serializeToolCallInput(part.input);\n\n // Escape tool call arguments if needed (they may contain placeholder syntax)\n toolCalls.push({\n function: {\n arguments: maybeEscape(argumentsJson),\n name: part.toolName,\n },\n id: part.toolCallId,\n type: \"function\",\n });\n break;\n }\n default: {\n pushWarningOnce(\n \"unsupported assistant content\",\n \"Unsupported assistant content type; part ignored.\",\n );\n break;\n }\n }\n }\n\n if (text || toolCalls.length > 0 || reasoningContent?.length) {\n const assistantMessage: AssistantChatMessage = {\n content:\n anyCacheControl && textParts\n ? textParts.map((p) => wrapAsTextContent(maybeEscape(p.text), p.cacheControl))\n : maybeEscape(text),\n role: \"assistant\",\n tool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n ...(reasoningContent && { reasoning_content: reasoningContent }),\n };\n messages.push(assistantMessage);\n }\n break;\n }\n\n case \"system\": {\n const partOpts = parsePart(message.providerOptions);\n const cacheControl = partOpts?.cacheControl;\n const text = maybeEscape(message.content);\n const systemMessage: SystemChatMessage = {\n content: cacheControl ? [wrapAsTextContent(text, cacheControl)] : text,\n role: \"system\",\n };\n messages.push(systemMessage);\n break;\n }\n\n case \"tool\": {\n for (const part of message.content) {\n if (part.type === \"tool-result\") {\n const partOpts = parsePart(part.providerOptions);\n const cacheControl = partOpts?.cacheControl;\n const outputText =\n part.output.type === \"text\" ? part.output.value : safeJsonStringify(part.output);\n const escaped = maybeEscape(outputText);\n const toolMessage: ToolChatMessage = {\n content: cacheControl ? [wrapAsTextContent(escaped, cacheControl)] : escaped,\n role: \"tool\",\n tool_call_id: part.toolCallId,\n };\n messages.push(toolMessage);\n } else {\n pushWarningOnce(\n \"non-tool-result content in tool message\",\n \"Only tool-result parts are forwarded to SAP; other tool content is ignored.\",\n );\n }\n }\n break;\n }\n\n case \"user\": {\n const contentParts: UserChatMessageContentItem[] = [];\n\n for (const part of message.content) {\n const partOpts = parsePart(part.providerOptions);\n const cacheControl = partOpts?.cacheControl;\n switch (part.type) {\n case \"file\": {\n const fileDataUrl = buildDataUrl(part);\n\n const normalizedMediaType = part.mediaType.toLowerCase();\n if (normalizedMediaType.startsWith(\"image/\")) {\n const isWildcardImageUrl =\n getURLHref(part.data) !== undefined && normalizedMediaType === \"image/*\";\n if (!isWildcardImageUrl && !SUPPORTED_IMAGE_FORMATS.includes(normalizedMediaType)) {\n console.warn(\n `Image format ${part.mediaType} may not be supported by all models. ` +\n `Recommended formats: PNG, JPEG, GIF, WebP`,\n );\n }\n\n contentParts.push({\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n image_url: {\n url: fileDataUrl,\n },\n type: \"image_url\",\n });\n } else {\n contentParts.push({\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n file: {\n file_data: fileDataUrl,\n ...(part.filename ? { filename: part.filename } : {}),\n },\n type: \"file\",\n });\n }\n break;\n }\n case \"text\": {\n contentParts.push({\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n text: maybeEscape(part.text),\n type: \"text\",\n });\n break;\n }\n default: {\n throw new UnsupportedFunctionalityError({\n functionality: `Content type ${(part as { type: string }).type}`,\n });\n }\n }\n }\n\n const firstPart = contentParts[0];\n const userMessage: UserChatMessage =\n contentParts.length === 1 &&\n firstPart?.type === \"text\" &&\n firstPart.cache_control === undefined\n ? {\n content: firstPart.text ?? \"\",\n role: \"user\",\n }\n : {\n content: contentParts,\n role: \"user\",\n };\n\n messages.push(userMessage);\n break;\n }\n\n default: {\n const _exhaustiveCheck: never = message;\n throw new InvalidPromptError({\n message: `Unsupported role: ${(_exhaustiveCheck as { role: string }).role}`,\n prompt: JSON.stringify(message),\n });\n }\n }\n }\n\n return messages;\n}\n\n/**\n * Escapes Jinja2 template delimiters by inserting zero-width spaces.\n *\n * Converts `{{`, `{%`, `{#` to `{\\u200B{`, `{\\u200B%`, `{\\u200B#` respectively.\n * This prevents SAP orchestration from interpreting user content as template syntax.\n * @param text - The text to escape.\n * @returns The escaped text with zero-width spaces inserted.\n * @see {@link unescapeOrchestrationPlaceholders} for the reverse operation.\n */\nexport function escapeOrchestrationPlaceholders(text: string): string {\n if (!text) return text;\n return text.replaceAll(JINJA2_DELIMITERS_PATTERN, `{${ZERO_WIDTH_SPACE}`);\n}\n\n/**\n * Reverses escaping by removing zero-width spaces from template delimiters.\n * Useful for processing model responses that may contain escaped delimiters.\n * @param text - The text to unescape.\n * @returns The unescaped text with zero-width spaces removed.\n * @see {@link escapeOrchestrationPlaceholders} for the escaping operation.\n */\nexport function unescapeOrchestrationPlaceholders(text: string): string {\n if (!text) return text;\n return text.replaceAll(JINJA2_DELIMITERS_ESCAPED_PATTERN, \"{\");\n}\n\n/**\n * Returns a file URL or builds a base64 data URL from inline file data.\n *\n * Genuine URL objects pass through without being fetched. Base64 strings are\n * embedded verbatim without validation; Uint8Array and ArrayBuffer inputs are\n * encoded. Buffer-like objects must have a custom `toString(\"base64\")` method\n * returning canonical base64. Other objects are rejected.\n * @internal\n * @param part - The file part containing data and mediaType.\n * @param part.data - The file data.\n * @param part.mediaType - The MIME type of the file.\n * @returns The original URL string or an inline data URL.\n * @throws {UnsupportedFunctionalityError} If the data type is not supported.\n */\nfunction buildDataUrl(part: { data: unknown; mediaType: string }): string {\n const { data, mediaType } = part;\n const href = getURLHref(data);\n if (href !== undefined) return href;\n\n if (typeof data === \"string\") return `data:${mediaType};base64,${data}`;\n\n if (isUint8Array(data)) {\n return `data:${mediaType};base64,${base64FromBytes(data)}`;\n }\n\n if (isArrayBuffer(data)) {\n let bytes: Uint8Array;\n try {\n bytes = new Uint8Array(data);\n } catch {\n throw new UnsupportedFunctionalityError({\n functionality: \"Detached ArrayBuffer file data is unsupported.\",\n });\n }\n return `data:${mediaType};base64,${base64FromBytes(bytes)}`;\n }\n\n if (typeof data === \"object\" && data !== null) {\n const toString = (data as { toString?: unknown }).toString;\n if (typeof toString === \"function\" && toString !== Object.prototype.toString) {\n const encoded: unknown = toString.call(data, \"base64\");\n if (typeof encoded === \"string\" && isCanonicalBase64(encoded)) {\n return `data:${mediaType};base64,${encoded}`;\n }\n }\n }\n\n throw new UnsupportedFunctionalityError({\n functionality:\n \"Unsupported file data type. Expected base64 string, Uint8Array, ArrayBuffer, URL, or a buffer-like object returning canonical base64.\",\n });\n}\n"],"mappings":";;;;;;AAUA;AAAA,EACE;AAAA,EAGA;AAAA,OACK;AA0CP,IAAM,mBAAmB;AAGzB,IAAM,sCAAsC,OAAO;AAAA,EACjD,YAAY;AAAA,EACZ;AACF;AAGA,IAAM,gCAAgC,OAAO;AAAA,EAC3C,OAAO,eAAe,WAAW,SAAS;AAAA,EAC1C;AACF;AAEA,IAAM,0BAA0B,CAAC,aAAa,cAAc,aAAa,aAAa,YAAY;AAGlG,IAAM,6BAA6B,OAAO;AAAA,EACxC,OAAO,eAAe,WAAW,SAAS;AAAA,EAC1C,OAAO;AACT;AAGA,IAAM,sBAAsB,OAAO,yBAAyB,IAAI,WAAW,MAAM;AAO1E,SAAS,WAAW,OAAoC;AAC7D,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,qBAAqB,QAAQ,QAAW;AACzF,WAAO;AAAA,EACT;AACA,MAAI;AACF,UAAM,OAAgB,oBAAoB,IAAI,KAAK,KAAK;AACxD,WAAO,OAAO,SAAS,WAAW,OAAO;AAAA,EAC3C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAOA,SAAS,kBAAkB,UAA0B;AACnD,MAAI,YAAY,MAAQ,YAAY,GAAM,QAAO,WAAW;AAC5D,MAAI,YAAY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