diff --git a/README.md b/README.md index aa979faf..47aab1e6 100644 --- a/README.md +++ b/README.md @@ -362,6 +362,7 @@ Argument: - `DIRECTORY`: Directory to create project in (default: ".") Options: - `--code-type TEXT`: This can be either `function` or `script`. The default value is `script` if the argument is missing. +- `--use-in-feature TEXT`, `-u TEXT`: Invoke option for this package. For scripts: `BatchTransform` (default) or `StreamingTransform`. For functions: `SearchIndexChunking` or `KnowledgeHarmonizationPostProcessing`. #### `datacustomcode scan` @@ -414,7 +415,7 @@ Options: - `--network TEXT`: docker network (default: "default") - `--cpu-size TEXT`: CPU size for the deployment (default: `CPU_2XL`). Available options: CPU_L(Large), CPU_XL(Extra Large), CPU_2XL(2X Large), CPU_4XL(4X Large) - `--sf-cli-org TEXT`: Salesforce CLI org alias or username (e.g. `myorg`). Fetches credentials via `sf org display` — no `datacustomcode configure` step needed. Takes precedence over `--profile` if both are supplied. -- `--function-invoke-opt TEXT`: Currently we support only `UnstructuredChunking` for functions. +- Function invoke option: inferred from the function signature on deploy. `SearchIndexChunking` is sent as `UnstructuredChunking`. `KnowledgeHarmonizationPostProcessing` is sent as `KnowledgeHarmonizationPostProcessing`. ## Testing LLM Gateway diff --git a/src/datacustomcode/cli.py b/src/datacustomcode/cli.py index a22fcb5b..ee2c8e37 100644 --- a/src/datacustomcode/cli.py +++ b/src/datacustomcode/cli.py @@ -289,7 +289,8 @@ def deploy( default=None, help=( "Invoke option for this package. For scripts: 'BatchTransform' " - "(default) or 'StreamingTransform'. For functions: 'SearchIndexChunking'." + "(default) or 'StreamingTransform'. For functions: 'SearchIndexChunking' " + "or 'KnowledgeHarmonizationPostProcessing'." ), ) def init(directory: str, code_type: str, use_in_feature: Optional[str]): diff --git a/src/datacustomcode/constants.py b/src/datacustomcode/constants.py index 23b139d3..cdb302ba 100644 --- a/src/datacustomcode/constants.py +++ b/src/datacustomcode/constants.py @@ -31,11 +31,13 @@ # Feature to template folder mapping FEATURE_TEMPLATE_MAPPING = { "SearchIndexChunking": "chunking", + "KnowledgeHarmonizationPostProcessing": "knowledge_harmonization_post_processing", } # Feature name to Connect API name mapping USE_IN_FEATURE_MAPPING_FOR_CONNECT_API = { "SearchIndexChunking": "UnstructuredChunking", + "KnowledgeHarmonizationPostProcessing": "KnowledgeHarmonizationPostProcessing", } # Script (data transform) invoke options @@ -51,4 +53,8 @@ ("SearchIndexChunkingV1Request", "SearchIndexChunkingV1Response"): ( "SearchIndexChunking" ), + ( + "KnowledgeHarmonizationPostProcessingV1Request", + "KnowledgeHarmonizationPostProcessingV1Response", + ): "KnowledgeHarmonizationPostProcessing", } diff --git a/src/datacustomcode/function/feature_types/knowledge_harmonization_post_processing.py b/src/datacustomcode/function/feature_types/knowledge_harmonization_post_processing.py new file mode 100644 index 00000000..6acabb50 --- /dev/null +++ b/src/datacustomcode/function/feature_types/knowledge_harmonization_post_processing.py @@ -0,0 +1,113 @@ +# Copyright (c) 2026, Salesforce, Inc. +# SPDX-License-Identifier: Apache-2 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Pydantic models for Knowledge Harmonization Post-Processing V1 +""" + +from typing import ( + Dict, + Optional, + Union, +) + +from pydantic import ( + BaseModel, + ConfigDict, + Field, +) + + +class KnowledgeHarmonizationPostProcessingV1Metadata(BaseModel): + """Metadata for the harmonized content element""" + + source_dmo_fields: Optional[Dict[str, Union[str, int, float]]] = Field( + default=None, + description=( + "Source Data Model Object fields as key-value pairs, " + "e.g. FilePath__c, ContentType__c, LastModified__c." + ), + examples=[ + { + "FilePath__c": "quarterly_report.pdf", + "ContentType__c": "application/pdf", + "LastModified__c": "2026-08-12T00:00:00.000000", + } + ], + ) + model_config = ConfigDict(extra="ignore") + + +class KnowledgeHarmonizationPostProcessingV1DocElement(BaseModel): + """The harmonized content element to be transformed""" + + text: str = Field( + default="", + description=( + "Harmonized content produced by the built-in pipeline steps, " + "before the extension runs." + ), + examples=["
Revenue grew 12%.
"], + ) + metadata: Optional[KnowledgeHarmonizationPostProcessingV1Metadata] = Field( + default=None, + description="Source document metadata. Optional, may be absent.", + ) + model_config = ConfigDict(extra="ignore") + + +class KnowledgeHarmonizationPostProcessingV1Output(BaseModel): + """The transformed content element returned by the function""" + + text: str = Field( + default="", + description=( + "Transformed content. Replaces the harmonized content at the same " + "location. On any failure the caller falls back to the original." + ), + examples=["Revenue grew 12% (redacted).
"], + ) + model_config = ConfigDict(extra="ignore") + + +class KnowledgeHarmonizationPostProcessingV1Request(BaseModel): + """Request for Knowledge Harmonization Post-Processing""" + + input: KnowledgeHarmonizationPostProcessingV1DocElement = Field( + ..., + description=( + "The single harmonized content element to transform. " + "One file per call, not a list." + ), + ) + properties: Optional[Dict[str, Union[str, int, float, bool]]] = Field( + default=None, + description=( + "Optional per-call key-value settings. Advisory: functions ignore " + "keys they do not know. Do not put secrets or PII here." + ), + examples=[{"mode": "redact", "locale": "en-US"}], + ) + model_config = ConfigDict(extra="ignore") + + +class KnowledgeHarmonizationPostProcessingV1Response(BaseModel): + """Response for Knowledge Harmonization Post-Processing""" + + output: KnowledgeHarmonizationPostProcessingV1Output = Field( + ..., + description="The single transformed content element (1:1 with Request.input).", + ) + model_config = ConfigDict(extra="ignore") diff --git a/src/datacustomcode/templates/function/knowledge_harmonization_post_processing/payload/config.json b/src/datacustomcode/templates/function/knowledge_harmonization_post_processing/payload/config.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/src/datacustomcode/templates/function/knowledge_harmonization_post_processing/payload/config.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/src/datacustomcode/templates/function/knowledge_harmonization_post_processing/payload/entrypoint.py b/src/datacustomcode/templates/function/knowledge_harmonization_post_processing/payload/entrypoint.py new file mode 100644 index 00000000..d1bba647 --- /dev/null +++ b/src/datacustomcode/templates/function/knowledge_harmonization_post_processing/payload/entrypoint.py @@ -0,0 +1,48 @@ +import logging + +from datacustomcode.function import Runtime +from datacustomcode.function.feature_types.knowledge_harmonization_post_processing import ( + KnowledgeHarmonizationPostProcessingV1Output, + KnowledgeHarmonizationPostProcessingV1Request, + KnowledgeHarmonizationPostProcessingV1Response, +) + +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + +# Injected banner. Inline styles because the harmonized HTML is consumed standalone. +BANNER = ( + 'Online Remittance Instructions
", + "metadata": { + "source_dmo_fields": { + "FilePath__c": "quarterly_report.html", + "ContentType__c": "text/html", + "LastModified__c": "2026-03-25T02:01:24.918000" + } + } + } +} diff --git a/tests/test_describe_supported_signatures.py b/tests/test_describe_supported_signatures.py index 767a28a3..fff993f3 100644 --- a/tests/test_describe_supported_signatures.py +++ b/tests/test_describe_supported_signatures.py @@ -19,5 +19,10 @@ def describe(request_type, response_type): assert describe("SearchIndexChunkingV1Request", "dict") == chunk_pair assert describe("dict", "SearchIndexChunkingV1Response") == chunk_pair # Unrecognised types fall back to listing every supported pair + kh_pair = ( + "KnowledgeHarmonizationPostProcessingV1Request/" + "KnowledgeHarmonizationPostProcessingV1Response " + "for use_in_feature: KnowledgeHarmonizationPostProcessing" + ) fallback = describe("dict", "dict") - assert fallback == chunk_pair + assert fallback == f"{chunk_pair} or {kh_pair}"