|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { |
| 7 | + WorkspaceFlowState, |
| 8 | + ReactFlowComponent, |
| 9 | + initComponentData, |
| 10 | + TextEmbeddingTransformer, |
| 11 | + KnnIndexer, |
| 12 | + generateId, |
| 13 | + ReactFlowEdge, |
| 14 | + TemplateFlows, |
| 15 | + WorkflowTemplate, |
| 16 | +} from './'; |
| 17 | + |
| 18 | +// TODO: implement this and remove hardcoded return values |
| 19 | +/** |
| 20 | + * Converts a ReactFlow workspace flow to a backend-compatible set of ingest and/or search sub-workflows, |
| 21 | + * along with a provision sub-workflow if resources are to be created. |
| 22 | + */ |
| 23 | +export function toTemplateFlows( |
| 24 | + workspaceFlow: WorkspaceFlowState |
| 25 | +): TemplateFlows { |
| 26 | + return { |
| 27 | + provision: { |
| 28 | + user_params: {} as Map<string, any>, |
| 29 | + nodes: [], |
| 30 | + edges: [], |
| 31 | + }, |
| 32 | + }; |
| 33 | +} |
| 34 | + |
| 35 | +// TODO: implement this and remove hardcoded return values |
| 36 | +/** |
| 37 | + * Converts a backend set of provision/ingest/search sub-workflows into a UI-compatible set of |
| 38 | + * ReactFlow nodes and edges |
| 39 | + */ |
| 40 | +export function toWorkspaceFlow( |
| 41 | + templateFlows: TemplateFlows |
| 42 | +): WorkspaceFlowState { |
| 43 | + const id1 = generateId('text_embedding_processor'); |
| 44 | + const id2 = generateId('text_embedding_processor'); |
| 45 | + const id3 = generateId('knn_index'); |
| 46 | + const dummyNodes = [ |
| 47 | + { |
| 48 | + id: id1, |
| 49 | + position: { x: 0, y: 500 }, |
| 50 | + data: initComponentData(new TextEmbeddingTransformer().toObj(), id1), |
| 51 | + type: 'customComponent', |
| 52 | + }, |
| 53 | + { |
| 54 | + id: id2, |
| 55 | + position: { x: 0, y: 200 }, |
| 56 | + data: initComponentData(new TextEmbeddingTransformer().toObj(), id2), |
| 57 | + type: 'customComponent', |
| 58 | + }, |
| 59 | + { |
| 60 | + id: id3, |
| 61 | + position: { x: 500, y: 500 }, |
| 62 | + data: initComponentData(new KnnIndexer().toObj(), id3), |
| 63 | + type: 'customComponent', |
| 64 | + }, |
| 65 | + ] as ReactFlowComponent[]; |
| 66 | + |
| 67 | + return { |
| 68 | + nodes: dummyNodes, |
| 69 | + edges: [] as ReactFlowEdge[], |
| 70 | + }; |
| 71 | +} |
| 72 | + |
| 73 | +// TODO: implement this |
| 74 | +/** |
| 75 | + * Validates the UI workflow state. |
| 76 | + * Note we don't have to validate connections since that is done via input/output handlers. |
| 77 | + */ |
| 78 | +export function validateWorkspaceFlow( |
| 79 | + workspaceFlow: WorkspaceFlowState |
| 80 | +): boolean { |
| 81 | + return true; |
| 82 | +} |
| 83 | + |
| 84 | +// TODO: implement this |
| 85 | +/** |
| 86 | + * Validates the backend template. May be used when parsing persisted templates on server-side, |
| 87 | + * or when importing/exporting on the UI. |
| 88 | + */ |
| 89 | +export function validateWorkflowTemplate( |
| 90 | + workflowTemplate: WorkflowTemplate |
| 91 | +): boolean { |
| 92 | + return true; |
| 93 | +} |
0 commit comments