@jerome-benoit/sap-ai-provider 4.6.8 → 4.7.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.
- package/LICENSE +202 -0
- package/README.md +1 -1
- package/dist/{chunk-M3AV2YUV.js → chunk-36DFHUVQ.js} +414 -277
- package/dist/chunk-36DFHUVQ.js.map +1 -0
- package/dist/{chunk-IIBSUXGT.js → chunk-4JIMBRMV.js} +44 -7
- package/dist/chunk-4JIMBRMV.js.map +1 -0
- package/dist/{chunk-6BVUDEKZ.js → chunk-BZZJKLDG.js} +60 -6
- package/dist/chunk-BZZJKLDG.js.map +1 -0
- package/dist/chunk-GMMX46AH.js +93 -0
- package/dist/chunk-GMMX46AH.js.map +1 -0
- package/dist/{chunk-7OGNFVGC.js → chunk-TVXWNZQT.js} +5276 -5608
- package/dist/chunk-TVXWNZQT.js.map +1 -0
- package/dist/chunk-WDUOKIKD.js +188 -0
- package/dist/chunk-WDUOKIKD.js.map +1 -0
- package/dist/{foundation-models-embedding-model-strategy-GXJRGM4X.js → foundation-models-embedding-model-strategy-YWPDIJEN.js} +8 -4
- package/dist/foundation-models-embedding-model-strategy-YWPDIJEN.js.map +1 -0
- package/dist/{foundation-models-language-model-strategy-FGUGQPBL.js → foundation-models-language-model-strategy-WDSQWU64.js} +16 -13
- package/dist/foundation-models-language-model-strategy-WDSQWU64.js.map +1 -0
- package/dist/index.cjs +6357 -6418
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -66
- package/dist/index.d.ts +66 -66
- package/dist/index.js +11 -172
- package/dist/index.js.map +1 -1
- package/dist/{orchestration-embedding-model-strategy-663QYZL7.js → orchestration-embedding-model-strategy-66QYAO64.js} +14 -4
- package/dist/orchestration-embedding-model-strategy-66QYAO64.js.map +1 -0
- package/dist/{orchestration-language-model-strategy-X3LKHORW.js → orchestration-language-model-strategy-4TKRZK7U.js} +52 -77
- package/dist/orchestration-language-model-strategy-4TKRZK7U.js.map +1 -0
- package/package.json +27 -21
- package/LICENSE.md +0 -187
- package/dist/chunk-6BVUDEKZ.js.map +0 -1
- package/dist/chunk-7OGNFVGC.js.map +0 -1
- package/dist/chunk-IIBSUXGT.js.map +0 -1
- package/dist/chunk-M3AV2YUV.js.map +0 -1
- package/dist/chunk-X66RDDSB.js +0 -61
- package/dist/chunk-X66RDDSB.js.map +0 -1
- package/dist/foundation-models-embedding-model-strategy-GXJRGM4X.js.map +0 -1
- package/dist/foundation-models-language-model-strategy-FGUGQPBL.js.map +0 -1
- package/dist/orchestration-embedding-model-strategy-663QYZL7.js.map +0 -1
- package/dist/orchestration-language-model-strategy-X3LKHORW.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/orchestration-language-model-strategy.ts"],"sourcesContent":["/** Orchestration language model strategy using `@sap-ai-sdk/orchestration`. */\nimport type { LanguageModelV3CallOptions, SharedV3Warning } from \"@ai-sdk/provider\";\nimport type {\n ChatCompletionTool,\n ChatMessage,\n OrchestrationClient,\n OrchestrationConfigRef,\n OrchestrationModuleConfig,\n OrchestrationModuleConfigList,\n} from \"@sap-ai-sdk/orchestration\";\n\nimport type { ParsePartProviderOptions } from \"./sap-ai-provider-options.js\";\nimport type {\n OrchestrationModelSettings,\n PromptTemplateRef,\n PromptTemplateRefByID,\n} from \"./sap-ai-settings.js\";\nimport type { LanguageModelStrategyConfig } from \"./sap-ai-strategy.js\";\n\nimport {\n BaseLanguageModelStrategy,\n type CommonBuildResult,\n type StreamCallResponse,\n} from \"./base-language-model-strategy.js\";\nimport { deepMerge } from \"./deep-merge.js\";\nimport {\n orchestrationConfigRefSchema,\n parseSAPPartProviderOptions,\n} from \"./sap-ai-provider-options.js\";\nimport { validateMaskingProvidersDeprecation } from \"./sap-ai-validation.js\";\nimport {\n convertResponseFormat,\n convertToolsToSAPFormat,\n hasKeys,\n type ParamMapping,\n type SAPToolChoice,\n type SDKCitation,\n type SDKResponse,\n type SDKStreamChunk,\n} from \"./strategy-utils.js\";\n\n/**\n * Extended prompt templating interface for type-safe access.\n * @internal\n */\ninterface ExtendedPromptTemplating {\n prompt: {\n response_format?: unknown;\n template?: unknown[];\n template_ref?: unknown;\n tools?: unknown;\n };\n}\n\n/** @internal */\ntype OrchestrationClientInstance = InstanceType<typeof OrchestrationClient>;\n\n/**\n * Orchestration request body type.\n * @internal\n */\ntype OrchestrationRequest = Record<string, unknown>;\n\n/**\n * Typed resolved state for values computed in buildCommonParts and consumed in buildRequest/createClient.\n * @internal\n */\ninterface OrchestrationResolvedState {\n readonly configRef: OrchestrationConfigRef | undefined;\n readonly promptTemplateRef: PromptTemplateRef | undefined;\n readonly tools: ChatCompletionTool[] | undefined;\n}\n\n/**\n * Builds the template_ref object from a PromptTemplateRef.\n * @param ref - Template reference (by ID or by name/scenario/version).\n * @returns The template_ref object for SDK consumption.\n * @internal\n */\nfunction buildTemplateRefObject(ref: PromptTemplateRef): Record<string, unknown> {\n return isTemplateRefById(ref)\n ? {\n id: ref.id,\n ...(ref.scope && { scope: ref.scope }),\n }\n : {\n name: ref.name,\n scenario: ref.scenario,\n version: ref.version,\n ...(ref.scope && { scope: ref.scope }),\n };\n}\n\n/**\n * Type guard for template reference by ID.\n * @param ref - Template reference.\n * @returns True if reference is by ID.\n * @internal\n */\nfunction isTemplateRefById(ref: PromptTemplateRef): ref is PromptTemplateRefByID {\n return \"id\" in ref;\n}\n\n/**\n * Merges and resolves placeholder values from settings and provider options.\n * @param settings - Model settings containing placeholderValues.\n * @param sapOptions - Provider options containing placeholderValues.\n * @returns Merged placeholder values or undefined if empty.\n * @internal\n */\nfunction resolvePlaceholderValues(\n settings: OrchestrationModelSettings,\n sapOptions: Record<string, unknown> | undefined,\n): Record<string, string> | undefined {\n const merged = deepMerge(\n settings.placeholderValues as Record<string, unknown> | undefined,\n sapOptions?.placeholderValues as Record<string, unknown> | undefined,\n ) as Record<string, string>;\n\n return hasKeys(merged) ? merged : undefined;\n}\n\n/**\n * Module keys for orchestration configuration.\n * @internal\n */\nconst ORCHESTRATION_MODULE_KEYS = [\"masking\", \"filtering\", \"grounding\", \"translation\"] as const;\n\n/**\n * Module settings that are ignored when using orchestrationConfigRef.\n * @internal\n */\nconst CONFIG_REF_IGNORED_MODULES = [\n ...ORCHESTRATION_MODULE_KEYS,\n \"promptTemplateRef\",\n \"responseFormat\",\n \"tools\",\n \"modelParams\",\n \"modelVersion\",\n] as const;\n\n/**\n * Provider options that are ignored when using orchestrationConfigRef.\n * Subset of CONFIG_REF_IGNORED_MODULES that can be passed via providerOptions.\n * @internal\n */\nconst CONFIG_REF_IGNORED_PROVIDER_OPTIONS = [\"promptTemplateRef\", \"modelParams\"] as const;\n\n/**\n * Copies non-empty orchestration modules from source to target.\n * @param target - Target object to copy modules into.\n * @param source - Source object containing module configurations.\n * @internal\n */\nfunction copyOrchestrationModules(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n): void {\n for (const key of ORCHESTRATION_MODULE_KEYS) {\n const value = source[key];\n if (value && hasKeys(value)) {\n target[key] = value;\n }\n }\n}\n\n/**\n * Checks if a value is a valid OrchestrationConfigRef.\n * @param value - The value to check.\n * @returns True if the value is a valid OrchestrationConfigRef.\n * @internal\n */\nfunction isOrchestrationConfigRef(value: unknown): value is OrchestrationConfigRef {\n return orchestrationConfigRefSchema.safeParse(value).success;\n}\n\n/**\n * Orchestration API parameter mappings.\n * @internal\n */\nconst ORCHESTRATION_PARAM_MAPPINGS: readonly ParamMapping[] = [\n ...BaseLanguageModelStrategy.COMMON_PARAM_MAPPINGS,\n { camelCaseKey: \"topK\", optionKey: \"topK\", outputKey: \"top_k\" },\n] as const;\n\n/**\n * Language model strategy for the Orchestration API.\n *\n * Provides support for:\n * - Content filtering\n * - Data masking\n * - Document grounding\n * - Translation\n * - Prompt templates\n * - Orchestration config references\n * @internal\n */\nexport class OrchestrationLanguageModelStrategy extends BaseLanguageModelStrategy<\n OrchestrationClientInstance,\n OrchestrationRequest,\n OrchestrationModelSettings\n> {\n private readonly ClientClass: typeof OrchestrationClient;\n\n constructor(ClientClass: typeof OrchestrationClient) {\n super();\n this.ClientClass = ClientClass;\n }\n\n protected buildRequest(\n config: LanguageModelStrategyConfig,\n settings: OrchestrationModelSettings,\n options: LanguageModelV3CallOptions,\n commonParts: CommonBuildResult<ChatMessage[], SAPToolChoice | undefined>,\n ): { readonly request: OrchestrationRequest; readonly warnings: SharedV3Warning[] } {\n const warnings: SharedV3Warning[] = [];\n\n const { configRef } = commonParts.resolvedState as OrchestrationResolvedState;\n\n if (configRef) {\n return this.buildConfigRefRequest(settings, options, commonParts, configRef, warnings);\n }\n\n return this.buildStandardRequest(config, settings, options, commonParts, warnings);\n }\n\n /**\n * Collects stream-specific warnings for orchestration.\n * @param settings - Model settings.\n * @param sapOptions - Provider options.\n * @returns Array of warnings for streaming operations.\n * @internal\n */\n protected override collectStreamWarnings(\n settings: OrchestrationModelSettings,\n sapOptions?: Record<string, unknown>,\n ): SharedV3Warning[] {\n const warnings: SharedV3Warning[] = [];\n\n // Skip warning if a valid orchestrationConfigRef is set in settings or providerOptions\n // (local module settings are ignored when using server-side config)\n const configRefCandidate =\n sapOptions?.orchestrationConfigRef ?? settings.orchestrationConfigRef;\n if (configRefCandidate && isOrchestrationConfigRef(configRefCandidate)) {\n return warnings;\n }\n\n if (settings.translation && hasKeys(settings.translation)) {\n if (!settings.streamOptions?.delimiters || settings.streamOptions.delimiters.length === 0) {\n warnings.push({\n message:\n \"Translation module is configured but streamOptions.delimiters is not set. \" +\n \"For proper sentence boundary detection during streaming with translation, \" +\n \"consider setting delimiters (e.g., ['.', '!', '?', '\\\\n']).\",\n type: \"other\",\n });\n }\n }\n\n return warnings;\n }\n\n protected createClient(\n config: LanguageModelStrategyConfig,\n settings: OrchestrationModelSettings,\n commonParts: CommonBuildResult<ChatMessage[], SAPToolChoice | undefined>,\n ): OrchestrationClientInstance {\n const { configRef, promptTemplateRef, tools } =\n commonParts.resolvedState as OrchestrationResolvedState;\n\n if (configRef) {\n return new this.ClientClass(configRef, config.deploymentConfig, config.destination);\n }\n\n const promptConfig = promptTemplateRef\n ? this.buildTemplateRefPromptConfig(promptTemplateRef, tools)\n : this.buildInlineTemplateConfig(tools, undefined);\n\n const clientConfig: OrchestrationModuleConfig = {\n promptTemplating: {\n model: {\n name: config.modelId,\n ...(settings.modelVersion ? { version: settings.modelVersion } : {}),\n },\n prompt: promptConfig,\n },\n };\n\n if (settings.fallbackModuleConfigs && settings.fallbackModuleConfigs.length > 0) {\n const configList = [\n clientConfig,\n ...settings.fallbackModuleConfigs,\n ] as OrchestrationModuleConfigList;\n return new this.ClientClass(configList, config.deploymentConfig, config.destination);\n }\n\n return new this.ClientClass(clientConfig, config.deploymentConfig, config.destination);\n }\n\n protected async executeApiCall(\n client: OrchestrationClientInstance,\n request: OrchestrationRequest,\n abortSignal: AbortSignal | undefined,\n ): Promise<SDKResponse> {\n const response = await client.chatCompletion(\n request,\n abortSignal ? { signal: abortSignal } : undefined,\n );\n\n const { requestId, responseId } = this.extractMetadata(response);\n\n return {\n getCitations: () =>\n (response as { getCitations?: () => SDKCitation[] | undefined }).getCitations?.(),\n getContent: () => response.getContent(),\n getFinishReason: () => response.getFinishReason(),\n getIntermediateFailures: () =>\n (\n response as { getIntermediateFailures?: () => undefined | unknown[] }\n ).getIntermediateFailures?.(),\n getTokenUsage: () => response.getTokenUsage(),\n getToolCalls: () => response.getToolCalls(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- SAP SDK types headers as any\n rawResponse: { headers: response.rawResponse.headers },\n requestId,\n responseId,\n };\n }\n\n protected async executeStreamCall(\n client: OrchestrationClientInstance,\n request: OrchestrationRequest,\n abortSignal: AbortSignal | undefined,\n settings: OrchestrationModelSettings,\n ): Promise<StreamCallResponse> {\n const sdkStreamOptions = this.buildSdkStreamOptions(settings.streamOptions);\n const streamResponse = await client.stream(request, abortSignal, sdkStreamOptions);\n\n const { requestId, responseHeaders, responseId } = this.extractMetadata(streamResponse);\n\n return {\n getCitations: () =>\n (streamResponse as { getCitations?: () => SDKCitation[] | undefined }).getCitations?.(),\n getFinishReason: () => streamResponse.getFinishReason(),\n getIntermediateFailures: () =>\n (\n streamResponse as { getIntermediateFailures?: () => undefined | unknown[] }\n ).getIntermediateFailures?.(),\n getTokenUsage: () => streamResponse.getTokenUsage(),\n requestId,\n responseHeaders,\n responseId,\n stream: streamResponse.stream as AsyncIterable<SDKStreamChunk>,\n };\n }\n\n protected getCompletionIdPath(): readonly string[] {\n return [\"final_result\", \"id\"];\n }\n\n protected getEscapeTemplatePlaceholders(\n sapOptions: Record<string, unknown> | undefined,\n settings: OrchestrationModelSettings,\n ): boolean {\n return (\n (sapOptions?.escapeTemplatePlaceholders as boolean | undefined) ??\n settings.escapeTemplatePlaceholders ??\n true\n );\n }\n\n protected getParamMappings(): readonly ParamMapping[] {\n return ORCHESTRATION_PARAM_MAPPINGS;\n }\n\n protected override getPartProviderOptionsParser(): ParsePartProviderOptions | undefined {\n return parseSAPPartProviderOptions;\n }\n\n protected getUrl(): string {\n return \"sap-ai:orchestration\";\n }\n\n /**\n * Resolves orchestration-specific extra state: `configRef`, `promptTemplateRef`,\n * and `tools`. Pushes the masking-providers deprecation warning when masking\n * is locally configured (skipped under `configRef` because the server-side\n * configuration overrides it).\n * @param _config - Strategy configuration (unused).\n * @param settings - Model settings.\n * @param sapOptions - Parsed provider options.\n * @param options - AI SDK call options.\n * @param warnings - Shared warnings sink.\n * @returns Resolved orchestration state.\n * @internal\n */\n protected override resolveAdditionalState(\n _config: LanguageModelStrategyConfig,\n settings: OrchestrationModelSettings,\n sapOptions: Record<string, unknown> | undefined,\n options: LanguageModelV3CallOptions,\n warnings: SharedV3Warning[],\n ): OrchestrationResolvedState {\n const configRef = this.resolveConfigRef(sapOptions, settings);\n const promptTemplateRef = this.resolvePromptTemplateRef(sapOptions, settings);\n\n if (configRef === undefined) {\n validateMaskingProvidersDeprecation(settings, warnings);\n }\n\n const tools = this.resolveTools(settings, options, warnings);\n\n return { configRef, promptTemplateRef, tools };\n }\n\n /**\n * Builds request for orchestrationConfigRef mode.\n *\n * In configRef mode, the full configuration is managed server-side.\n * We only send messages and placeholderValues.\n * @param settings - Model settings.\n * @param options - Call options.\n * @param commonParts - Common build result.\n * @param _configRef - The config reference (unused, passed for signature consistency).\n * @param warnings - Warnings array to populate.\n * @returns Request body and warnings.\n * @internal\n */\n private buildConfigRefRequest(\n settings: OrchestrationModelSettings,\n options: LanguageModelV3CallOptions,\n commonParts: CommonBuildResult<ChatMessage[], SAPToolChoice | undefined>,\n _configRef: OrchestrationConfigRef,\n warnings: SharedV3Warning[],\n ): { readonly request: OrchestrationRequest; readonly warnings: SharedV3Warning[] } {\n warnings.push(\n ...this.collectConfigRefIgnoredWarnings(settings, options, commonParts.sapOptions),\n );\n\n const placeholderValues = resolvePlaceholderValues(settings, commonParts.sapOptions);\n\n // In configRef mode, SDK uses messagesHistory (not messages)\n const request: OrchestrationRequest = {\n messagesHistory: commonParts.messages,\n ...(placeholderValues ? { placeholderValues } : {}),\n };\n\n return { request, warnings };\n }\n\n /**\n * Builds inline template configuration.\n * @param tools - Optional tools.\n * @param responseFormat - Optional response format.\n * @returns Prompt configuration.\n * @internal\n */\n private buildInlineTemplateConfig(\n tools: ChatCompletionTool[] | undefined,\n responseFormat: unknown,\n ): Record<string, unknown> {\n return {\n template: [],\n ...(tools && tools.length > 0 ? { tools } : {}),\n ...(responseFormat ? { response_format: responseFormat } : {}),\n };\n }\n\n /**\n * Builds the orchestration module configuration.\n * @param config - Strategy configuration.\n * @param settings - Model settings.\n * @param params - Build parameters.\n * @param params.modelParams - LLM model parameters.\n * @param params.promptTemplateRef - Optional prompt template reference.\n * @param params.responseFormat - Optional response format specification.\n * @param params.toolChoice - Optional tool choice specification.\n * @param params.tools - Optional tools for function calling.\n * @returns Orchestration module configuration.\n * @internal\n */\n private buildOrchestrationModuleConfig(\n config: LanguageModelStrategyConfig,\n settings: OrchestrationModelSettings,\n params: {\n readonly modelParams: Record<string, unknown>;\n readonly promptTemplateRef?: PromptTemplateRef;\n readonly responseFormat?: unknown;\n readonly toolChoice?: SAPToolChoice;\n readonly tools?: ChatCompletionTool[];\n },\n ): OrchestrationModuleConfig {\n const { modelParams, promptTemplateRef, responseFormat, toolChoice, tools } = params;\n\n const promptConfig = promptTemplateRef\n ? this.buildTemplateRefPromptConfig(promptTemplateRef, tools, responseFormat)\n : this.buildInlineTemplateConfig(tools, responseFormat);\n\n // Include tool_choice in model.params because the SDK filters request-level options.\n // Workaround for SAP AI SDK issue (may be fixed in future SDK versions).\n // See: https://github.com/SAP/ai-sdk-js/issues/1500\n const effectiveModelParams = toolChoice\n ? { ...modelParams, tool_choice: toolChoice }\n : modelParams;\n\n const moduleConfig: OrchestrationModuleConfig = {\n promptTemplating: {\n model: {\n name: config.modelId,\n params: effectiveModelParams,\n ...(settings.modelVersion ? { version: settings.modelVersion } : {}),\n },\n prompt: promptConfig,\n },\n };\n\n copyOrchestrationModules(\n moduleConfig as unknown as Record<string, unknown>,\n settings as unknown as Record<string, unknown>,\n );\n\n return moduleConfig;\n }\n\n /**\n * Builds the final request body for the orchestration API.\n * @param messages - Chat messages.\n * @param orchestrationConfig - Module configuration.\n * @param placeholderValues - Optional placeholder values.\n * @param hasTemplateRef - Whether template_ref mode is active.\n * @returns Request body.\n * @internal\n */\n private buildRequestBody(\n messages: ChatMessage[],\n orchestrationConfig: OrchestrationModuleConfig,\n placeholderValues: Record<string, string> | undefined,\n hasTemplateRef: boolean,\n ): Record<string, unknown> {\n const promptTemplating = orchestrationConfig.promptTemplating as ExtendedPromptTemplating;\n\n // In template_ref mode, SDK uses messagesHistory (not messages)\n // In inline template mode, SDK adds messages to the template array\n const messagesField = hasTemplateRef ? { messagesHistory: messages } : { messages };\n\n // Note: tool_choice is passed via model.params (not request level) because the SDK\n // filters out request-level options. Workaround may be removed when SDK is fixed.\n // See: https://github.com/SAP/ai-sdk-js/issues/1500\n const requestBody: Record<string, unknown> = {\n ...messagesField,\n model: {\n ...orchestrationConfig.promptTemplating.model,\n },\n ...(placeholderValues ? { placeholderValues } : {}),\n ...(promptTemplating.prompt.tools ? { tools: promptTemplating.prompt.tools } : {}),\n ...(promptTemplating.prompt.response_format\n ? { response_format: promptTemplating.prompt.response_format }\n : {}),\n };\n\n copyOrchestrationModules(\n requestBody,\n orchestrationConfig as unknown as Record<string, unknown>,\n );\n\n return requestBody;\n }\n\n /**\n * Builds SAP SDK stream options from user-facing stream options.\n * @param streamOptions - User-provided stream options.\n * @returns SDK-compatible stream options object.\n * @internal\n */\n private buildSdkStreamOptions(streamOptions: OrchestrationModelSettings[\"streamOptions\"]): {\n global?: { chunk_size?: number; delimiters?: string[] };\n outputFiltering?: { overlap: number };\n promptTemplating: { include_usage: boolean };\n } {\n const delimiters = streamOptions?.delimiters;\n const hasNonEmptyDelimiters = Array.isArray(delimiters) && delimiters.length > 0;\n const hasGlobalOptions = streamOptions?.chunkSize !== undefined || hasNonEmptyDelimiters;\n\n return {\n promptTemplating: { include_usage: true },\n ...(hasGlobalOptions && {\n global: {\n ...(streamOptions?.chunkSize !== undefined && { chunk_size: streamOptions.chunkSize }),\n ...(hasNonEmptyDelimiters && {\n delimiters: Array.from(delimiters),\n }),\n },\n }),\n ...(streamOptions?.outputFilteringOverlap !== undefined && {\n outputFiltering: { overlap: streamOptions.outputFilteringOverlap },\n }),\n };\n }\n\n /**\n * Builds request for standard (non-configRef) mode.\n * @param config - Strategy configuration.\n * @param settings - Model settings.\n * @param options - Call options.\n * @param commonParts - Common build result.\n * @param warnings - Warnings array to populate.\n * @returns Request body and warnings.\n * @internal\n */\n private buildStandardRequest(\n config: LanguageModelStrategyConfig,\n settings: OrchestrationModelSettings,\n options: LanguageModelV3CallOptions,\n commonParts: CommonBuildResult<ChatMessage[], SAPToolChoice | undefined>,\n warnings: SharedV3Warning[],\n ): { readonly request: OrchestrationRequest; readonly warnings: SharedV3Warning[] } {\n const { promptTemplateRef, tools } = commonParts.resolvedState as OrchestrationResolvedState;\n\n const { responseFormat, warning: responseFormatWarning } = convertResponseFormat(\n options.responseFormat,\n settings.responseFormat,\n );\n if (responseFormatWarning) {\n warnings.push(responseFormatWarning);\n }\n\n const { toolChoice } = commonParts;\n\n const orchestrationConfig = this.buildOrchestrationModuleConfig(config, settings, {\n modelParams: commonParts.modelParams,\n promptTemplateRef,\n responseFormat,\n toolChoice,\n tools,\n });\n\n const placeholderValues = resolvePlaceholderValues(settings, commonParts.sapOptions);\n\n const request = this.buildRequestBody(\n commonParts.messages,\n orchestrationConfig,\n placeholderValues,\n Boolean(promptTemplateRef),\n );\n\n return { request, warnings };\n }\n\n /**\n * Builds prompt configuration for template reference with optional tools/response_format.\n * @param ref - Template reference.\n * @param tools - Optional tools.\n * @param responseFormat - Optional response format.\n * @returns Prompt configuration.\n * @internal\n */\n private buildTemplateRefPromptConfig(\n ref: PromptTemplateRef,\n tools?: ChatCompletionTool[],\n responseFormat?: unknown,\n ): Record<string, unknown> {\n return {\n template_ref: buildTemplateRefObject(ref),\n ...(tools && tools.length > 0 ? { tools } : {}),\n ...(responseFormat ? { response_format: responseFormat } : {}),\n };\n }\n\n /**\n * Collects warnings for settings that will be ignored when using orchestrationConfigRef.\n * @param settings - The orchestration model settings.\n * @param options - The call options (for tools and responseFormat).\n * @param sapOptions - Parsed provider options (for promptTemplateRef in providerOptions).\n * @returns Array of warnings for ignored settings.\n * @internal\n */\n private collectConfigRefIgnoredWarnings(\n settings: OrchestrationModelSettings,\n options: LanguageModelV3CallOptions,\n sapOptions: Record<string, unknown> | undefined,\n ): SharedV3Warning[] {\n const warnings: SharedV3Warning[] = [];\n const ignoredSettings: string[] = [];\n\n for (const key of CONFIG_REF_IGNORED_MODULES) {\n const value = settings[key as keyof OrchestrationModelSettings];\n if (value !== undefined) {\n if (typeof value === \"object\" && Object.keys(value).length === 0) {\n continue; // Skip empty objects\n }\n ignoredSettings.push(key);\n }\n }\n\n for (const key of CONFIG_REF_IGNORED_PROVIDER_OPTIONS) {\n if (sapOptions?.[key] && !settings[key as keyof OrchestrationModelSettings]) {\n ignoredSettings.push(`providerOptions.${key}`);\n }\n }\n\n if (options.tools && options.tools.length > 0) {\n ignoredSettings.push(\"options.tools\");\n }\n if (options.responseFormat) {\n ignoredSettings.push(\"options.responseFormat\");\n }\n if (options.toolChoice) {\n ignoredSettings.push(\"options.toolChoice\");\n }\n\n if (ignoredSettings.length > 0) {\n warnings.push({\n message: `orchestrationConfigRef is set; the following local settings are ignored: ${ignoredSettings.join(\", \")}. The full configuration is managed by the referenced config.`,\n type: \"other\",\n });\n }\n\n return warnings;\n }\n\n /**\n * Resolves the orchestrationConfigRef from provider options or settings.\n * Provider options take priority over settings.\n * @param sapOptions - Parsed provider options from commonParts.\n * @param settings - The model settings.\n * @returns The resolved config reference or undefined.\n * @internal\n */\n private resolveConfigRef(\n sapOptions: Record<string, unknown> | undefined,\n settings: OrchestrationModelSettings,\n ): OrchestrationConfigRef | undefined {\n const configRefCandidate =\n sapOptions?.orchestrationConfigRef ?? settings.orchestrationConfigRef;\n\n if (configRefCandidate && isOrchestrationConfigRef(configRefCandidate)) {\n return configRefCandidate;\n }\n\n return undefined;\n }\n\n /**\n * Resolves promptTemplateRef from provider options or settings.\n *\n * Provider options take priority over settings.\n * @param sapOptions - Parsed provider options from commonParts.\n * @param settings - The model settings.\n * @returns The resolved prompt template reference or undefined.\n * @internal\n */\n private resolvePromptTemplateRef(\n sapOptions: Record<string, unknown> | undefined,\n settings: OrchestrationModelSettings,\n ): PromptTemplateRef | undefined {\n const rawTemplateRef = sapOptions?.promptTemplateRef ?? settings.promptTemplateRef;\n\n if (\n rawTemplateRef &&\n typeof rawTemplateRef === \"object\" &&\n (\"id\" in rawTemplateRef || \"name\" in rawTemplateRef)\n ) {\n return rawTemplateRef as PromptTemplateRef;\n }\n\n return undefined;\n }\n\n /**\n * Resolves tools from settings or options with orchestration-specific priority.\n *\n * Orchestration allows tools to be defined in settings (unlike Foundation Models),\n * with options.tools taking priority.\n * @param settings - Model settings.\n * @param options - Call options.\n * @param warnings - Warnings array to populate.\n * @returns Resolved tools or undefined.\n * @internal\n */\n private resolveTools(\n settings: OrchestrationModelSettings,\n options: LanguageModelV3CallOptions,\n warnings: SharedV3Warning[],\n ): ChatCompletionTool[] | undefined {\n const settingsTools = settings.tools;\n const optionsTools = options.tools;\n\n if (settingsTools && settingsTools.length > 0 && optionsTools && optionsTools.length > 0) {\n warnings.push({\n message:\n \"Both settings.tools and call options.tools were provided; preferring call options.tools.\",\n type: \"other\",\n });\n }\n\n // Use settingsTools directly if available and no optionsTools\n // (settingsTools are already in SAP format)\n if (settingsTools && settingsTools.length > 0 && (!optionsTools || optionsTools.length === 0)) {\n return settingsTools;\n }\n\n if (optionsTools && optionsTools.length > 0) {\n const result = convertToolsToSAPFormat<ChatCompletionTool>(optionsTools, {\n parser: parseSAPPartProviderOptions,\n warnings,\n });\n warnings.push(...result.warnings);\n return result.tools;\n }\n\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+EA,SAAS,uBAAuB,KAAiD;AAC/E,SAAO,kBAAkB,GAAG,IACxB;AAAA,IACE,IAAI,IAAI;AAAA,IACR,GAAI,IAAI,SAAS,EAAE,OAAO,IAAI,MAAM;AAAA,EACtC,IACA;AAAA,IACE,MAAM,IAAI;AAAA,IACV,UAAU,IAAI;AAAA,IACd,SAAS,IAAI;AAAA,IACb,GAAI,IAAI,SAAS,EAAE,OAAO,IAAI,MAAM;AAAA,EACtC;AACN;AAQA,SAAS,kBAAkB,KAAsD;AAC/E,SAAO,QAAQ;AACjB;AASA,SAAS,yBACP,UACA,YACoC;AACpC,QAAM,SAAS;AAAA,IACb,SAAS;AAAA,IACT,YAAY;AAAA,EACd;AAEA,SAAO,QAAQ,MAAM,IAAI,SAAS;AACpC;AAMA,IAAM,4BAA4B,CAAC,WAAW,aAAa,aAAa,aAAa;AAMrF,IAAM,6BAA6B;AAAA,EACjC,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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A,IACH;AAIA,QAAI,iBAAiB,cAAc,SAAS,MAAM,CAAC,gBAAgB,aAAa,WAAW,IAAI;AAC7F,aAAO;AAAA,IACT;AAEA,QAAI,gBAAgB,aAAa,SAAS,GAAG;AAC3C,YAAM,SAAS,wBAA4C,cAAc;AAAA,QACvE,QAAQ;AAAA,QACR;AAAA,MACF,CAAC;AACD,eAAS,KAAK,GAAG,OAAO,QAAQ;AAChC,aAAO,OAAO;AAAA,IAChB;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jerome-benoit/sap-ai-provider",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SAP AI Provider for Vercel AI SDK (powered by @sap-ai-sdk/orchestration and @sap-ai-sdk/foundation-models)",
|
|
6
6
|
"keywords": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"author": "jerome-benoit",
|
|
29
29
|
"volta": {
|
|
30
|
-
"node": "24.
|
|
30
|
+
"node": "24.16.0"
|
|
31
31
|
},
|
|
32
32
|
"main": "./dist/index.cjs",
|
|
33
33
|
"module": "./dist/index.js",
|
|
@@ -45,9 +45,11 @@
|
|
|
45
45
|
"files": [
|
|
46
46
|
"dist/**/*",
|
|
47
47
|
"README.md",
|
|
48
|
-
"LICENSE
|
|
48
|
+
"LICENSE"
|
|
49
49
|
],
|
|
50
50
|
"scripts": {
|
|
51
|
+
"prepare": "lefthook install",
|
|
52
|
+
"postinstall": "patch-package",
|
|
51
53
|
"build": "tsup",
|
|
52
54
|
"build:watch": "tsup --watch",
|
|
53
55
|
"build:v2": "tsup --config tsup.config.v2.ts",
|
|
@@ -73,34 +75,38 @@
|
|
|
73
75
|
"test:node": "vitest --config vitest.node.config.ts --run",
|
|
74
76
|
"test:node:watch": "vitest --config vitest.node.config.ts",
|
|
75
77
|
"test:watch": "vitest",
|
|
78
|
+
"sandcastle": "tsx .sandcastle/main.ts",
|
|
76
79
|
"type-check": "tsc --noEmit"
|
|
77
80
|
},
|
|
78
81
|
"dependencies": {
|
|
79
|
-
"@ai-sdk/provider": "^3.0.
|
|
80
|
-
"@ai-sdk/provider-utils": "^4.0.
|
|
81
|
-
"@sap-ai-sdk/foundation-models": "^2.
|
|
82
|
-
"@sap-ai-sdk/orchestration": "^2.
|
|
83
|
-
"zod": "^4.3
|
|
82
|
+
"@ai-sdk/provider": "^3.0.10",
|
|
83
|
+
"@ai-sdk/provider-utils": "^4.0.27",
|
|
84
|
+
"@sap-ai-sdk/foundation-models": "^2.11.0",
|
|
85
|
+
"@sap-ai-sdk/orchestration": "^2.11.0",
|
|
86
|
+
"zod": "^4.4.3"
|
|
84
87
|
},
|
|
85
88
|
"devDependencies": {
|
|
89
|
+
"@ai-hero/sandcastle": "^0.6.5",
|
|
86
90
|
"@edge-runtime/vm": "^5.0.0",
|
|
87
91
|
"@eslint/js": "^10.0.1",
|
|
88
|
-
"@types/node": "^25.
|
|
89
|
-
"@vitest/coverage-v8": "^4.1.
|
|
90
|
-
"dotenv": "^17.4.
|
|
91
|
-
"eslint": "^10.
|
|
92
|
-
"eslint-plugin-jsdoc": "^
|
|
93
|
-
"eslint-plugin-perfectionist": "^5.
|
|
94
|
-
"globals": "^17.
|
|
92
|
+
"@types/node": "^25.9.1",
|
|
93
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
94
|
+
"dotenv": "^17.4.2",
|
|
95
|
+
"eslint": "^10.4.0",
|
|
96
|
+
"eslint-plugin-jsdoc": "^63.0.0",
|
|
97
|
+
"eslint-plugin-perfectionist": "^5.9.0",
|
|
98
|
+
"globals": "^17.6.0",
|
|
99
|
+
"lefthook": "^2.1.8",
|
|
95
100
|
"markdown-link-check": "^3.14.2",
|
|
96
|
-
"markdownlint-cli2": "^0.22.
|
|
101
|
+
"markdownlint-cli2": "^0.22.1",
|
|
97
102
|
"mermaid-validate": "^1.3.2",
|
|
98
|
-
"
|
|
103
|
+
"patch-package": "^8.0.1",
|
|
104
|
+
"prettier": "^3.8.3",
|
|
99
105
|
"tsup": "^8.5.1",
|
|
100
|
-
"tsx": "^4.
|
|
101
|
-
"typescript": "^6.0.
|
|
102
|
-
"typescript-eslint": "^8.
|
|
103
|
-
"vitest": "^4.1.
|
|
106
|
+
"tsx": "^4.22.3",
|
|
107
|
+
"typescript": "^6.0.3",
|
|
108
|
+
"typescript-eslint": "^8.60.0",
|
|
109
|
+
"vitest": "^4.1.7"
|
|
104
110
|
},
|
|
105
111
|
"peerDependencies": {
|
|
106
112
|
"ai": "^5.0.0 || ^6.0.0"
|
package/LICENSE.md
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
-
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
13
|
-
copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all other
|
|
16
|
-
entities that control, are controlled by, or are under common control with
|
|
17
|
-
that entity. For the purposes of this definition, "control" means (i) the
|
|
18
|
-
power, direct or indirect, to cause the direction or management of such
|
|
19
|
-
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
|
20
|
-
(50%) or more of the outstanding shares, or (iii) beneficial ownership of
|
|
21
|
-
such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
-
permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation source, and
|
|
28
|
-
configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical transformation or
|
|
31
|
-
translation of a Source form, including but not limited to compiled object
|
|
32
|
-
code, generated documentation, and conversions to other media types.
|
|
33
|
-
|
|
34
|
-
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
35
|
-
made available under the License, as indicated by a copyright notice that is
|
|
36
|
-
included in or attached to the work (an example is provided in the Appendix
|
|
37
|
-
below).
|
|
38
|
-
|
|
39
|
-
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
40
|
-
that is based on (or derived from) the Work and for which the editorial
|
|
41
|
-
revisions, annotations, elaborations, or other modifications represent, as a
|
|
42
|
-
whole, an original work of authorship. For the purposes of this License,
|
|
43
|
-
Derivative Works shall not include works that remain separable from, or
|
|
44
|
-
merely link (or bind by name) to the interfaces of, the Work and Derivative
|
|
45
|
-
Works thereof.
|
|
46
|
-
|
|
47
|
-
"Contribution" shall mean any work of authorship, including the original
|
|
48
|
-
version of the Work and any modifications or additions to that Work or
|
|
49
|
-
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
50
|
-
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
51
|
-
Entity authorized to submit on behalf of the copyright owner. For the
|
|
52
|
-
purposes of this definition, "submitted" means any form of electronic,
|
|
53
|
-
verbal, or written communication sent to the Licensor or its representatives,
|
|
54
|
-
including but not limited to communication on electronic mailing lists,
|
|
55
|
-
source code control systems, and issue tracking systems that are managed by,
|
|
56
|
-
or on behalf of, the Licensor for the purpose of discussing and improving the
|
|
57
|
-
Work, but excluding communication that is conspicuously marked or otherwise
|
|
58
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
59
|
-
|
|
60
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
|
61
|
-
behalf of whom a Contribution has been received by Licensor and subsequently
|
|
62
|
-
incorporated within the Work.
|
|
63
|
-
|
|
64
|
-
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
65
|
-
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
66
|
-
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
67
|
-
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
68
|
-
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
69
|
-
Object form.
|
|
70
|
-
|
|
71
|
-
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
72
|
-
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
73
|
-
no-charge, royalty-free, irrevocable (except as stated in this section)
|
|
74
|
-
patent license to make, have made, use, offer to sell, sell, import, and
|
|
75
|
-
otherwise transfer the Work, where such license applies only to those patent
|
|
76
|
-
claims licensable by such Contributor that are necessarily infringed by their
|
|
77
|
-
Contribution(s) alone or by combination of their Contribution(s) with the
|
|
78
|
-
Work to which such Contribution(s) was submitted. If You institute patent
|
|
79
|
-
litigation against any entity (including a cross-claim or counterclaim in a
|
|
80
|
-
lawsuit) alleging that the Work or a Contribution incorporated within the
|
|
81
|
-
Work constitutes direct or contributory patent infringement, then any patent
|
|
82
|
-
licenses granted to You under this License for that Work shall terminate as
|
|
83
|
-
of the date such litigation is filed.
|
|
84
|
-
|
|
85
|
-
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
86
|
-
Derivative Works thereof in any medium, with or without modifications, and in
|
|
87
|
-
Source or Object form, provided that You meet the following conditions:
|
|
88
|
-
|
|
89
|
-
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
90
|
-
of this License; and
|
|
91
|
-
|
|
92
|
-
(b) You must cause any modified files to carry prominent notices stating that
|
|
93
|
-
You changed the files; and
|
|
94
|
-
|
|
95
|
-
(c) You must retain, in the Source form of any Derivative Works that You
|
|
96
|
-
distribute, all copyright, patent, trademark, and attribution notices from
|
|
97
|
-
the Source form of the Work, excluding those notices that do not pertain to
|
|
98
|
-
any part of the Derivative Works; and
|
|
99
|
-
|
|
100
|
-
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
|
101
|
-
then any Derivative Works that You distribute must include a readable copy of
|
|
102
|
-
the attribution notices contained within such NOTICE file, excluding those
|
|
103
|
-
notices that do not pertain to any part of the Derivative Works, in at least
|
|
104
|
-
one of the following places: within a NOTICE text file distributed as part of
|
|
105
|
-
the Derivative Works; within the Source form or documentation, if provided
|
|
106
|
-
along with the Derivative Works; or, within a display generated by the
|
|
107
|
-
Derivative Works, if and wherever such third-party notices normally appear.
|
|
108
|
-
The contents of the NOTICE file are for informational purposes only and do
|
|
109
|
-
not modify the License. You may add Your own attribution notices within
|
|
110
|
-
Derivative Works that You distribute, alongside or as an addendum to the
|
|
111
|
-
NOTICE text from the Work, provided that such additional attribution notices
|
|
112
|
-
cannot be construed as modifying the License.
|
|
113
|
-
|
|
114
|
-
You may add Your own copyright statement to Your modifications and may
|
|
115
|
-
provide additional or different license terms and conditions for use,
|
|
116
|
-
reproduction, or distribution of Your modifications, or for any such
|
|
117
|
-
Derivative Works as a whole, provided Your use, reproduction, and
|
|
118
|
-
distribution of the Work otherwise complies with the conditions stated in
|
|
119
|
-
this License.
|
|
120
|
-
|
|
121
|
-
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
122
|
-
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
123
|
-
Licensor shall be under the terms and conditions of this License, without any
|
|
124
|
-
additional terms or conditions. Notwithstanding the above, nothing herein
|
|
125
|
-
shall supersede or modify the terms of any separate license agreement you may
|
|
126
|
-
have executed with Licensor regarding such Contributions.
|
|
127
|
-
|
|
128
|
-
6. Trademarks. This License does not grant permission to use the trade names,
|
|
129
|
-
trademarks, service marks, or product names of the Licensor, except as
|
|
130
|
-
required for reasonable and customary use in describing the origin of the
|
|
131
|
-
Work and reproducing the content of the NOTICE file.
|
|
132
|
-
|
|
133
|
-
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
134
|
-
writing, Licensor provides the Work (and each Contributor provides its
|
|
135
|
-
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
136
|
-
KIND, either express or implied, including, without limitation, any
|
|
137
|
-
warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or
|
|
138
|
-
FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining
|
|
139
|
-
the appropriateness of using or redistributing the Work and assume any risks
|
|
140
|
-
associated with Your exercise of permissions under this License.
|
|
141
|
-
|
|
142
|
-
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
143
|
-
tort (including negligence), contract, or otherwise, unless required by
|
|
144
|
-
applicable law (such as deliberate and grossly negligent acts) or agreed to
|
|
145
|
-
in writing, shall any Contributor be liable to You for damages, including any
|
|
146
|
-
direct, indirect, special, incidental, or consequential damages of any
|
|
147
|
-
character arising as a result of this License or out of the use or inability
|
|
148
|
-
to use the Work (including but not limited to damages for loss of goodwill,
|
|
149
|
-
work stoppage, computer failure or malfunction, or any and all other
|
|
150
|
-
commercial damages or losses), even if such Contributor has been advised of
|
|
151
|
-
the possibility of such damages.
|
|
152
|
-
|
|
153
|
-
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
154
|
-
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
155
|
-
acceptance of support, warranty, indemnity, or other liability obligations
|
|
156
|
-
and/or rights consistent with this License. However, in accepting such
|
|
157
|
-
obligations, You may act only on Your own behalf and on Your sole
|
|
158
|
-
responsibility, not on behalf of any other Contributor, and only if You agree
|
|
159
|
-
to indemnify, defend, and hold each Contributor harmless for any liability
|
|
160
|
-
incurred by, or claims asserted against, such Contributor by reason of your
|
|
161
|
-
accepting any such warranty or additional liability.
|
|
162
|
-
|
|
163
|
-
END OF TERMS AND CONDITIONS
|
|
164
|
-
|
|
165
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
166
|
-
|
|
167
|
-
To apply the Apache License to your work, attach the following
|
|
168
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
169
|
-
replaced with your own identifying information. (Don't include
|
|
170
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
171
|
-
comment syntax for the file format. We also recommend that a
|
|
172
|
-
file or class name and description of purpose be included on the
|
|
173
|
-
same "printed page" as the copyright notice for easier
|
|
174
|
-
identification within third-party archives.
|
|
175
|
-
|
|
176
|
-
Copyright 2026 Jérôme Benoit
|
|
177
|
-
|
|
178
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
179
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
180
|
-
License at
|
|
181
|
-
|
|
182
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
183
|
-
|
|
184
|
-
Unless required by applicable law or agreed to in writing, software distributed
|
|
185
|
-
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
186
|
-
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
187
|
-
specific language governing permissions and limitations under the License.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/base-language-model-strategy.ts"],"sourcesContent":["/** Base class for language model strategies using the Template Method pattern. */\nimport type {\n LanguageModelV3CallOptions,\n LanguageModelV3GenerateResult,\n LanguageModelV3StreamResult,\n SharedV3Warning,\n} from \"@ai-sdk/provider\";\nimport type { ChatMessage } from \"@sap-ai-sdk/orchestration\";\n\nimport { parseProviderOptions } from \"@ai-sdk/provider-utils\";\n\nimport type { SAPAIModelSettings } from \"./sap-ai-settings.js\";\nimport type { LanguageModelAPIStrategy, LanguageModelStrategyConfig } from \"./sap-ai-strategy.js\";\n\nimport { convertToSAPMessages } from \"./convert-to-sap-messages.js\";\nimport { convertToAISDKError, normalizeHeaders } from \"./sap-ai-error.js\";\nimport { getProviderName, sapAILanguageModelProviderOptions } from \"./sap-ai-provider-options.js\";\nimport {\n buildGenerateResult,\n buildModelParams,\n createAISDKRequestBodySummary,\n createStreamTransformer,\n mapToolChoice,\n type ParamMapping,\n type SAPToolChoice,\n type SDKCitation,\n type SDKResponse,\n type SDKStreamChunk,\n type SDKTokenUsage,\n StreamIdGenerator,\n} from \"./strategy-utils.js\";\nimport { VERSION } from \"./version.js\";\n\n/**\n * Result of building common parts for a language model request.\n * @template TMessages - The message array type (e.g., `ChatMessage[]`, `AzureOpenAiChatCompletionRequestMessage[]`)\n * @template TToolChoice - The tool choice type (e.g., `SAPToolChoice`)\n * @internal\n */\nexport interface CommonBuildResult<TMessages extends unknown[] = unknown[], TToolChoice = unknown> {\n readonly messages: TMessages;\n readonly modelParams: Record<string, unknown>;\n readonly providerName: string;\n readonly sapOptions: Record<string, unknown> | undefined;\n readonly toolChoice: TToolChoice;\n readonly warnings: SharedV3Warning[];\n}\n\n/**\n * Stream response shape returned by executeStreamCall.\n * @internal\n */\nexport interface StreamCallResponse {\n readonly getCitations?: () => SDKCitation[] | undefined;\n readonly getFinishReason: () => null | string | undefined;\n readonly getIntermediateFailures?: () => undefined | unknown[];\n readonly getTokenUsage: () => null | SDKTokenUsage | undefined;\n readonly responseHeaders?: Record<string, string>;\n /** Server-provided completion ID extracted from _data, if available. */\n readonly responseId?: string;\n readonly stream: AsyncIterable<SDKStreamChunk>;\n}\n\n/**\n * Abstract base class for language model strategies using the Template Method pattern.\n * @template TClient - The SDK client type (e.g., AzureOpenAiChatClient, OrchestrationClient).\n * @template TRequest - The API request type (e.g., AzureOpenAiChatCompletionParameters).\n * @template TSettings - The model settings type extending SAPAIModelSettings.\n * @internal\n */\nexport abstract class BaseLanguageModelStrategy<\n TClient,\n TRequest,\n TSettings extends SAPAIModelSettings = SAPAIModelSettings,\n> implements LanguageModelAPIStrategy<TSettings> {\n /**\n * Common parameter mappings for language model APIs.\n * @internal\n */\n static readonly COMMON_PARAM_MAPPINGS: readonly ParamMapping[] = [\n { camelCaseKey: \"maxTokens\", optionKey: \"maxOutputTokens\", outputKey: \"max_tokens\" },\n { camelCaseKey: \"temperature\", optionKey: \"temperature\", outputKey: \"temperature\" },\n { camelCaseKey: \"topP\", optionKey: \"topP\", outputKey: \"top_p\" },\n {\n camelCaseKey: \"frequencyPenalty\",\n optionKey: \"frequencyPenalty\",\n outputKey: \"frequency_penalty\",\n },\n {\n camelCaseKey: \"presencePenalty\",\n optionKey: \"presencePenalty\",\n outputKey: \"presence_penalty\",\n },\n { camelCaseKey: \"seed\", optionKey: \"seed\", outputKey: \"seed\" },\n { camelCaseKey: \"parallel_tool_calls\", outputKey: \"parallel_tool_calls\" },\n ] as const;\n\n async doGenerate(\n config: LanguageModelStrategyConfig,\n settings: TSettings,\n options: LanguageModelV3CallOptions,\n ): Promise<LanguageModelV3GenerateResult> {\n try {\n const commonParts = await this.buildCommonParts(config, settings, options);\n const { request, warnings } = this.buildRequest(config, settings, options, commonParts);\n\n const client = this.createClient(config, settings, commonParts);\n\n const response = await this.executeApiCall(client, request, options.abortSignal ?? undefined);\n\n return buildGenerateResult({\n modelId: config.modelId,\n providerName: commonParts.providerName,\n requestBody: request,\n response,\n responseHeaders: normalizeHeaders(response.rawResponse.headers),\n version: VERSION,\n warnings: [...commonParts.warnings, ...warnings],\n });\n } catch (error) {\n throw convertToAISDKError(error, {\n operation: \"doGenerate\",\n requestBody: createAISDKRequestBodySummary(options),\n url: this.getUrl(),\n });\n }\n }\n\n async doStream(\n config: LanguageModelStrategyConfig,\n settings: TSettings,\n options: LanguageModelV3CallOptions,\n ): Promise<LanguageModelV3StreamResult> {\n try {\n const commonParts = await this.buildCommonParts(config, settings, options);\n const { request, warnings } = this.buildRequest(config, settings, options, commonParts);\n\n const client = this.createClient(config, settings, commonParts);\n\n const streamResponse = await this.executeStreamCall(\n client,\n request,\n options.abortSignal ?? undefined,\n settings,\n );\n\n const idGenerator = new StreamIdGenerator();\n const responseId = streamResponse.responseId ?? idGenerator.generateResponseId();\n\n const streamWarnings = this.collectStreamWarnings(settings, commonParts.sapOptions);\n\n const transformedStream = createStreamTransformer({\n convertToAISDKError,\n idGenerator,\n includeRawChunks: options.includeRawChunks ?? false,\n modelId: config.modelId,\n options,\n providerName: commonParts.providerName,\n responseHeaders: streamResponse.responseHeaders,\n responseId,\n sdkStream: streamResponse.stream,\n streamResponseGetCitations: streamResponse.getCitations,\n streamResponseGetFinishReason: streamResponse.getFinishReason,\n streamResponseGetIntermediateFailures: streamResponse.getIntermediateFailures,\n streamResponseGetTokenUsage: streamResponse.getTokenUsage,\n url: this.getUrl(),\n version: VERSION,\n warnings: [...commonParts.warnings, ...warnings, ...streamWarnings],\n });\n\n return {\n request: {\n body: request,\n },\n response: {\n headers: streamResponse.responseHeaders,\n },\n stream: transformedStream,\n };\n } catch (error) {\n throw convertToAISDKError(error, {\n operation: \"doStream\",\n requestBody: createAISDKRequestBodySummary(options),\n url: this.getUrl(),\n });\n }\n }\n\n /**\n * Builds common parts shared between doGenerate and doStream.\n * @param config - Strategy configuration.\n * @param settings - Model settings.\n * @param options - AI SDK call options.\n * @returns Common build result with typed messages and tool choice.\n * @internal\n */\n protected async buildCommonParts(\n config: LanguageModelStrategyConfig,\n settings: TSettings,\n options: LanguageModelV3CallOptions,\n ): Promise<CommonBuildResult<ChatMessage[], SAPToolChoice | undefined>> {\n const providerName = getProviderName(config.provider);\n\n const sapOptions = await parseProviderOptions({\n provider: providerName,\n providerOptions: options.providerOptions,\n schema: sapAILanguageModelProviderOptions,\n });\n\n const warnings: SharedV3Warning[] = [];\n\n const messages = convertToSAPMessages(options.prompt, {\n escapeTemplatePlaceholders: this.getEscapeTemplatePlaceholders(sapOptions, settings),\n includeReasoning: this.getIncludeReasoning(sapOptions, settings),\n });\n\n const { modelParams, warnings: paramWarnings } = buildModelParams({\n options,\n paramMappings: this.getParamMappings(),\n providerModelParams: sapOptions?.modelParams as Record<string, unknown> | undefined,\n settingsModelParams: settings.modelParams as Record<string, unknown> | undefined,\n });\n warnings.push(...paramWarnings);\n\n const toolChoice = mapToolChoice(options.toolChoice);\n\n return {\n messages,\n modelParams,\n providerName,\n sapOptions,\n toolChoice,\n warnings,\n };\n }\n\n /**\n * Builds the API-specific request body.\n * @param config - Strategy configuration.\n * @param settings - Model settings.\n * @param options - AI SDK call options.\n * @param commonParts - Common build result from base class.\n * @returns Request body and accumulated warnings.\n * @internal\n */\n protected abstract buildRequest(\n config: LanguageModelStrategyConfig,\n settings: TSettings,\n options: LanguageModelV3CallOptions,\n commonParts: CommonBuildResult<ChatMessage[], SAPToolChoice | undefined>,\n ): { readonly request: TRequest; readonly warnings: SharedV3Warning[] };\n\n /**\n * Collects stream-specific warnings.\n * Override in subclasses to add API-specific streaming warnings.\n * @param _settings - Model settings (unused in base implementation).\n * @param _sapOptions - Provider options (unused in base implementation).\n * @returns Array of warnings for streaming operations.\n * @internal\n */\n protected collectStreamWarnings(\n _settings: TSettings,\n _sapOptions?: Record<string, unknown>,\n ): SharedV3Warning[] {\n return [];\n }\n\n /**\n * Creates the appropriate SDK client for this API.\n * @param config - Strategy configuration.\n * @param settings - Model settings.\n * @param commonParts - Common build result (messages, options, etc.).\n * @returns SDK client instance.\n * @internal\n */\n protected abstract createClient(\n config: LanguageModelStrategyConfig,\n settings: TSettings,\n commonParts: CommonBuildResult<ChatMessage[], SAPToolChoice | undefined>,\n ): TClient;\n\n /**\n * Executes the non-streaming API call.\n * @param client - SDK client instance.\n * @param request - Request body.\n * @param abortSignal - Optional abort signal.\n * @returns SDK response.\n * @internal\n */\n protected abstract executeApiCall(\n client: TClient,\n request: TRequest,\n abortSignal: AbortSignal | undefined,\n ): Promise<SDKResponse>;\n\n /**\n * Executes the streaming API call.\n * @param client - SDK client instance.\n * @param request - Request body.\n * @param abortSignal - Optional abort signal.\n * @param settings - Model settings for API-specific stream options.\n * @returns Stream response with accessors.\n * @internal\n */\n protected abstract executeStreamCall(\n client: TClient,\n request: TRequest,\n abortSignal: AbortSignal | undefined,\n settings: TSettings,\n ): Promise<StreamCallResponse>;\n\n /**\n * Returns whether to escape template placeholders for this API.\n * @param _sapOptions - Parsed provider options (unused in base implementation).\n * @param _settings - Model settings (unused in base implementation).\n * @returns false by default; Orchestration strategy overrides to return true.\n * @internal\n */\n protected getEscapeTemplatePlaceholders(\n _sapOptions: Record<string, unknown> | undefined,\n _settings: TSettings,\n ): boolean {\n return false;\n }\n\n /**\n * Returns whether to include reasoning in the response.\n * @param sapOptions - Parsed provider options.\n * @param settings - Model settings.\n * @returns Whether to include reasoning (checks sapOptions then settings, defaults to false).\n * @internal\n */\n protected getIncludeReasoning(\n sapOptions: Record<string, unknown> | undefined,\n settings: TSettings,\n ): boolean {\n return (\n (sapOptions?.includeReasoning as boolean | undefined) ??\n (settings as SAPAIModelSettings & { includeReasoning?: boolean }).includeReasoning ??\n false\n );\n }\n\n /**\n * Returns the parameter mappings specific to this API strategy.\n * @returns Array of parameter mappings.\n * @internal\n */\n protected abstract getParamMappings(): readonly ParamMapping[];\n\n /**\n * Returns the URL identifier for this API (used in error messages).\n * @returns URL string identifier.\n * @internal\n */\n protected abstract getUrl(): string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AASA,SAAS,4BAA4B;AA6D9B,IAAe,4BAAf,MAI0C;AAAA;AAAA;AAAA;AAAA;AAAA,EAK/C,OAAgB,wBAAiD;AAAA,IAC/D,EAAE,cAAc,aAAa,WAAW,mBAAmB,WAAW,aAAa;AAAA,IACnF,EAAE,cAAc,eAAe,WAAW,eAAe,WAAW,cAAc;AAAA,IAClF,EAAE,cAAc,QAAQ,WAAW,QAAQ,WAAW,QAAQ;AAAA,IAC9D;AAAA,MACE,cAAc;AAAA,MACd,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA;AAAA,MACE,cAAc;AAAA,MACd,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,EAAE,cAAc,QAAQ,WAAW,QAAQ,WAAW,OAAO;AAAA,IAC7D,EAAE,cAAc,uBAAuB,WAAW,sBAAsB;AAAA,EAC1E;AAAA,EAEA,MAAM,WACJ,QACA,UACA,SACwC;AACxC,QAAI;AACF,YAAM,cAAc,MAAM,KAAK,iBAAiB,QAAQ,UAAU,OAAO;AACzE,YAAM,EAAE,SAAS,SA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