diff --git a/packages/client/hmi-client/src/components/model/petrinet/tera-model-equation.vue b/packages/client/hmi-client/src/components/model/petrinet/tera-model-equation.vue index 2fb1adc4a9..44ae170884 100644 --- a/packages/client/hmi-client/src/components/model/petrinet/tera-model-equation.vue +++ b/packages/client/hmi-client/src/components/model/petrinet/tera-model-equation.vue @@ -29,7 +29,7 @@ import { ref, watch } from 'vue'; import TeraMathEditor from '@/components/mathml/tera-math-editor.vue'; import TeraEquationContainer from '@/components/model/petrinet/tera-equation-container.vue'; import type { Model } from '@/types/Types'; -import { equationsToAMR } from '@/services/knowledge'; +import { equationsToAMR, EquationsToAMRRequest } from '@/services/knowledge'; import { cleanLatexEquations } from '@/utils/math'; import { isEmpty } from 'lodash'; import { useToastService } from '@/services/toast'; @@ -76,7 +76,8 @@ const updateLatexFormula = (equationsList: string[]) => { const updateModelFromEquations = async () => { isUpdating.value = true; isEditing.value = false; - const modelId = await equationsToAMR(equations.value, 'petrinet', props.model.id); + const request: EquationsToAMRRequest = { equations: equations.value, modelId: props.model.id }; + const modelId = await equationsToAMR(request); if (modelId) { emit('model-updated'); useToastService().success('Success', `Model Updated from equation`); diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue index 646a43b6fa..808716c88b 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue @@ -119,7 +119,7 @@ import { getDocumentAsset, getEquationFromImageUrl } from '@/services/document-a import type { Card, DocumentAsset, DocumentExtraction, Model } from '@/types/Types'; import { cloneDeep, unionBy } from 'lodash'; import Image from 'primevue/image'; -import { equationsToAMR } from '@/services/knowledge'; +import { equationsToAMR, type EquationsToAMRRequest } from '@/services/knowledge'; import Button from 'primevue/button'; import Dropdown from 'primevue/dropdown'; import { getModel, updateModel } from '@/services/model'; @@ -246,7 +246,12 @@ async function onRun() { .filter((e) => e.includeInProcess && !e.asset.extractionError) .map((e) => e.asset.text); - const modelId = await equationsToAMR(equations, clonedState.value.modelFramework); + const request: EquationsToAMRRequest = { + equations, + framework: clonedState.value.modelFramework, + documentId: document.value?.id + }; + const modelId = await equationsToAMR(request); if (!modelId) return; if (document.value?.id) await generateCard(document.value.id); diff --git a/packages/client/hmi-client/src/services/knowledge.ts b/packages/client/hmi-client/src/services/knowledge.ts index 82c82f39ef..92a8bc934d 100644 --- a/packages/client/hmi-client/src/services/knowledge.ts +++ b/packages/client/hmi-client/src/services/knowledge.ts @@ -5,22 +5,31 @@ import { ClientEventType } from '@/types/Types'; import { logger } from '@/utils/logger'; import { AxiosResponse } from 'axios'; -/** - * Transform a list of LaTeX or mathml strings to an AMR +/** Define the request type * @param equations string[] - list of LaTeX or mathml strings representing a model * @param framework string= - the framework to use for the extraction, default to 'petrinet' * @param modelId string= - the model id to use for the extraction + * @param documentId string= - the document id source of the equations + */ +export interface EquationsToAMRRequest { + equations: string[]; + framework?: string; + modelId?: Model['id']; + documentId?: DocumentAsset['id']; +} + +/** + * Transform a list of LaTeX or mathml strings to an AMR + * @param request EquationsToAMRRequest * @return {Promise} */ -export const equationsToAMR = async ( - equations: string[], - framework: string = 'petrinet', - modelId?: string -): Promise => { +export const equationsToAMR = async (request: EquationsToAMRRequest): Promise => { + const { equations, framework: model = 'petrinet', modelId, documentId } = request; try { const response: AxiosResponse = await API.post(`/knowledge/equations-to-model`, { - model: framework, + model, modelId, + documentId, equations }); return response.data;