Hi,
I am trying to call a typescript function via an action using an OSDK frontend. I’ve added to this OSDK app the action. However, I am having some issues! Specifically, my typescript function calls a logic function and gives the following error:
{
"errorCode": "INVALID_ARGUMENT",
"errorName": "FunctionExecutionFailed",
"errorInstanceId": "5168b599-5ad3-44e2-b4a9-c1ddce08a051",
"parameters": {
"functionRid": "ri.function-registry.main.function.4f6eba3c-f7cd-4678-8174-ca6dbda8bdd7",
"functionVersion": "0.0.14",
"message": "Logic function not executable",
"stacktrace": "Optional.empty"
}
}
However, I have added this very logic function to my application and can, in fact, run it!
Here’s the code on the backend:
@OntologyEditFunction()
public async determineControlStatusFromDocumentChunks(clientControlId: string): Promise<void> {
const clientControls = Objects.search()
.clientControl()
.filter(clientControl => clientControl.clientControlId.exactMatch(clientControlId))
.all();
if (!clientControls || clientControls.length === 0) {
throw new Error("Could not find client control.");
}
const clientControl = clientControls[0];
const clientId = clientControl.clientId;
if (!clientId) {
throw new Error("Client ID is missing from client control.");
}
const relatedControlId = clientControl.controlId;
if (!relatedControlId) {
throw new Error("Control ID is missing from client control.");
}
const controls = Objects.search()
.control()
.filter(control => control.controlId.exactMatch(relatedControlId))
.all();
if (!controls || controls.length === 0) {
throw new Error("Could not find related control.");
}
const relatedControl = controls[0];
const relatedControlDescription = relatedControl.controlDescription;
if (!relatedControlDescription) {
throw new Error("Control description is missing from related control.");
}
const output = await Queries.documentChunksToControlEvidence({
controlDescription: relatedControlDescription,
clientId: clientId
});
if (!output) {
throw new Error("Document chunks to control evidence query returned no results.");
}
const controlStatus = output.categoryOfEvidence;
if (!controlStatus) {
throw new Error("Category of evidence is missing from query output.");
}
const controlStatusReasoning = output.reasoningForEvidenceCategory;
if (!controlStatusReasoning) {
throw new Error("Reasoning for evidence category is missing from query output.");
}
// Extract document chunk IDs from the reasoning
const extractDocumentChunkIds = (text: string): string[] => {
const regex = /documentChunkId:\[([^\]\s]+)\]/g;
const matches = [...text.matchAll(regex)];
return matches.map(match => match[1]);
};
const relatedChunkIds = extractDocumentChunkIds(controlStatusReasoning);
// Update properties
clientControl.status = controlStatus;
clientControl.reasoning = controlStatusReasoning;
clientControl.relatedChunkReferences = relatedChunkIds;
}
Not only this, but the function also works when I test it in the repository
Best,
Jack