forked from opensearch-project/dashboards-flow-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.ts
686 lines (581 loc) · 15.8 KB
/
interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { Node, Edge } from 'reactflow';
import { FormikValues } from 'formik';
import { ObjectSchema } from 'yup';
import {
COMPONENT_CLASS,
PROCESSOR_TYPE,
TRANSFORM_TYPE,
WORKFLOW_TYPE,
} from './constants';
export type Index = {
name: string;
health: 'green' | 'yellow' | 'red';
};
/**
********** WORKFLOW TYPES/INTERFACES **********
*/
export type MDSQueryParams = {
dataSourceId?: string;
};
export type ConfigFieldType =
| 'string'
| 'textArea'
| 'json'
| 'jsonArray'
| 'jsonString'
| 'jsonLines'
| 'select'
| 'model'
| 'map'
| 'mapArray'
| 'boolean'
| 'number'
| 'inputMapArray'
| 'outputMapArray';
export type ConfigFieldValue = string | {};
export interface IConfigField {
type: ConfigFieldType;
id: string;
value?: ConfigFieldValue;
selectOptions?: ConfigFieldValue[];
}
export interface IConfig {
id: string;
name: string;
fields: IConfigField[];
optionalFields?: IConfigField[];
}
export interface IProcessorConfig extends IConfig {
type: PROCESSOR_TYPE;
}
export type ProcessorsConfig = {
processors: IProcessorConfig[];
};
export type IndexConfig = {
name: IConfigField;
mappings: IConfigField;
settings: IConfigField;
};
export type SearchIndexConfig = {
name: IConfigField;
};
export type IngestConfig = {
enabled: IConfigField;
pipelineName: IConfigField;
enrich: ProcessorsConfig;
index: IndexConfig;
};
export type SearchConfig = {
request: IConfigField;
index: SearchIndexConfig;
pipelineName: IConfigField;
enrichRequest: ProcessorsConfig;
enrichResponse: ProcessorsConfig;
};
export type WorkflowConfig = {
ingest: IngestConfig;
search: SearchConfig;
};
export type MapEntry = {
key: string;
value: string;
};
export type MapFormValue = MapEntry[];
export type MapArrayFormValue = MapFormValue[];
export type ExpressionVar = {
name: string;
transform: string;
};
export type Transform = {
transformType: TRANSFORM_TYPE;
value?: string;
// Templates may persist their own set of nested transforms
// to be dynamically injected into the template
nestedVars?: ExpressionVar[];
};
export type InputMapEntry = {
key: string;
value: Transform;
};
export type OutputMapEntry = InputMapEntry;
export type InputMapFormValue = InputMapEntry[];
export type OutputMapFormValue = OutputMapEntry[];
export type MapCache = {
[idx: number]: Transform[];
};
export type InputMapArrayFormValue = InputMapFormValue[];
export type OutputMapArrayFormValue = OutputMapFormValue[];
export type WorkflowFormValues = {
ingest: FormikValues;
search: FormikValues;
};
export type WorkflowSchemaObj = {
[key: string]: ObjectSchema<any, any, any>;
};
export type WorkflowSchema = ObjectSchema<WorkflowSchemaObj>;
/**
********** MODAL SUB-FORM TYPES/INTERFACES **********
We persist sub-forms in the form modals s.t. data is only
saved back to the parent form if the user explicitly saves.
We define the structure of the forms here.
*/
// Ingest docs modal
export type IngestDocsFormValues = {
docs: FormikValues;
};
// Search request modal
export type RequestFormValues = {
request: ConfigFieldValue;
};
// Configure template modal
export type TemplateFormValues = Omit<Transform, 'transformType'>;
// Configure expression modal
export type ExpressionFormValues = {
expression: string;
};
// Configure multi-expression modal
export type MultiExpressionFormValues = {
expressions: ExpressionVar[];
};
/**
********** WORKSPACE TYPES/INTERFACES **********
*/
export type FieldType = 'string' | 'json' | 'select' | 'model';
export type FieldValue = string | {};
export type ComponentFormValues = FormikValues;
export type WorkspaceFormValues = {
[componentId: string]: ComponentFormValues;
};
export type WorkspaceSchemaObj = {
[componentId: string]: ObjectSchema<any, any, any>;
};
export type WorkspaceSchema = ObjectSchema<WorkspaceSchemaObj>;
export interface IComponentInput {
id: string;
label: string;
acceptMultiple: boolean;
}
export interface IComponentOutput {
id: string;
label: string;
}
/**
* An input field for a component. Specifies enough configuration for the
* UI node to render it properly (help text, links, etc.)
*/
export interface IComponentField {
label: string;
type: FieldType;
id: string;
value?: FieldValue;
placeholder?: string;
helpText?: string;
helpLink?: string;
}
/**
* The base interface the components will implement.
*/
export interface IComponent {
type: COMPONENT_CLASS;
label: string;
iconType?: string;
description?: string;
inputs?: IComponentInput[];
outputs?: IComponentOutput[];
}
/**
* We need to include some extra instance-specific data to the ReactFlow component
* to perform extra functionality, such as deleting the node from the ReactFlowInstance.
*/
export interface IComponentData extends IComponent {
id: string;
selected?: boolean;
}
export type ReactFlowComponent = Node<IComponentData>;
export type ReactFlowEdge = Edge<{}> & {
key: string;
sourceClasses: COMPONENT_CLASS[];
targetClasses: COMPONENT_CLASS[];
};
type ReactFlowViewport = {
x: number;
y: number;
zoom: number;
};
export type UIState = {
schema_version: number;
config: WorkflowConfig;
type: WORKFLOW_TYPE;
// Will be used in future when changing from form-based to flow-based configs via drag-and-drop
workspace_flow?: WorkspaceFlowState;
};
export type WorkspaceFlowState = {
nodes: ReactFlowComponent[];
edges: ReactFlowEdge[];
viewport?: ReactFlowViewport;
};
/**
********** USE CASE TEMPLATE TYPES/INTERFACES **********
*/
export type IngestProcessor = {};
export type SearchProcessor = {};
export type SearchRequestProcessor = SearchProcessor & {};
export type SearchResponseProcessor = SearchProcessor & {};
export type SearchPhaseResultsProcessor = SearchProcessor & {};
export type IngestPipelineConfig = {
description?: string;
processors: IngestProcessor[];
};
export type SearchPipelineConfig = {
description?: string;
request_processors?: SearchRequestProcessor[];
response_processors?: SearchResponseProcessor[];
phase_results_processors?: SearchPhaseResultsProcessor[];
};
export type MLInferenceProcessor = IngestProcessor & {
ml_inference: {
model_id: string;
input_map?: {}[];
output_map?: {}[];
[key: string]: any;
};
};
export type NormalizationProcessor = SearchProcessor & {
normalization: {
technique: string;
};
combination: {
technique: string;
parameters: {
weights: number[];
};
};
};
export type IndexConfiguration = {
settings: { [key: string]: any };
mappings: IndexMappings;
};
export type IndexMappings = {
properties: { [key: string]: any };
};
export type TemplateNode = {
id: string;
type: string;
previous_node_inputs?: {};
user_inputs?: {};
};
export type CreateIngestPipelineNode = TemplateNode & {
user_inputs: {
pipeline_id: string;
model_id?: string;
input_field?: string;
output_field?: string;
configurations: string;
};
};
export type CreateSearchPipelineNode = TemplateNode & {
user_inputs: {
pipeline_id: string;
configurations: string;
};
};
export type CreateIndexNode = TemplateNode & {
previous_node_inputs?: {
[ingest_pipeline_step_id: string]: string;
};
user_inputs: {
index_name: string;
configurations: string;
};
};
export type TemplateEdge = {
source: string;
dest: string;
};
export type TemplateFlow = {
nodes: TemplateNode[];
edges?: TemplateEdge[];
user_params?: {};
};
export type TemplateFlows = {
provision: TemplateFlow;
};
// A stateless template of a workflow
export type WorkflowTemplate = {
// Name is the only required field: see https://opensearch.org/docs/latest/automating-configurations/api/create-workflow/#request-fields
name: string;
description?: string;
// TODO: finalize on version type when that is implemented
// https://github.com/opensearch-project/flow-framework/issues/526
version?: any;
workflows?: TemplateFlows;
use_case?: string;
// UI state and any ReactFlow state may not exist if a workflow is created via API/backend-only.
ui_metadata?: UIState;
};
// An instance of a workflow based on a workflow template
export type Workflow = WorkflowTemplate & {
// won't exist until created in backend
id?: string;
// won't exist until created in backend
lastUpdated?: number;
// won't exist until launched/provisioned in backend
lastLaunched?: number;
// won't exist until launched/provisioned in backend
state?: WORKFLOW_STATE;
// won't exist until launched/provisioned in backend
error?: string;
// won't exist until launched/provisioned in backend
resourcesCreated?: WorkflowResource[];
};
/**
********** ML PLUGIN TYPES/INTERFACES **********
*/
// Based off of https://github.com/opensearch-project/ml-commons/blob/main/common/src/main/java/org/opensearch/ml/common/model/MLModelState.java
export enum MODEL_STATE {
REGISTERED = 'Registered',
REGISTERING = 'Registering',
DEPLOYING = 'Deploying',
DEPLOYED = 'Deployed',
PARTIALLY_DEPLOYED = 'Partially deployed',
UNDEPLOYED = 'Undeployed',
DEPLOY_FAILED = 'Deploy failed',
}
// Based off of https://github.com/opensearch-project/ml-commons/blob/main/common/src/main/java/org/opensearch/ml/common/FunctionName.java
export enum MODEL_ALGORITHM {
LINEAR_REGRESSION = 'Linear regression',
KMEANS = 'K-means',
AD_LIBSVM = 'AD LIBSVM',
SAMPLE_ALGO = 'Sample algorithm',
LOCAL_SAMPLE_CALCULATOR = 'Local sample calculator',
FIT_RCF = 'Fit RCF',
BATCH_RCF = 'Batch RCF',
ANOMALY_LOCALIZATION = 'Anomaly localization',
RCF_SUMMARIZE = 'RCF summarize',
LOGISTIC_REGRESSION = 'Logistic regression',
TEXT_EMBEDDING = 'Text embedding',
METRICS_CORRELATION = 'Metrics correlation',
REMOTE = 'Remote',
SPARSE_ENCODING = 'Sparse encoding',
SPARSE_TOKENIZE = 'Sparse tokenize',
TEXT_SIMILARITY = 'Text similarity',
QUESTION_ANSWERING = 'Question answering',
AGENT = 'Agent',
}
export type ModelConfig = {
modelType?: string;
embeddingDimension?: number;
};
// Based off of JSONSchema. For more info, see https://json-schema.org/understanding-json-schema/reference/type
export type ModelInput = {
type: string;
description?: string;
items?: ModelInput;
properties?: ModelInputMap;
};
export type ModelOutput = ModelInput;
export type ModelInputMap = { [key: string]: ModelInput };
export type ModelOutputMap = { [key: string]: ModelOutput };
// For rendering options, we extract the name (the key in the input/output obj) and combine into a single obj
export type ModelInputFormField = ModelInput & {
label: string;
};
export type ModelOutputFormField = ModelInputFormField;
export type ModelInterface = {
input?: ModelInput;
output?: ModelOutput;
};
export type ConnectorParameters = {
model?: string;
dimensions?: number;
};
export type Model = {
id: string;
name: string;
algorithm: MODEL_ALGORITHM;
state: MODEL_STATE;
modelConfig?: ModelConfig;
interface?: ModelInterface;
connectorId?: string;
};
export type Connector = {
id: string;
name: string;
parameters?: ConnectorParameters;
};
export type ModelDict = {
[modelId: string]: Model;
};
export type ConnectorDict = {
[connectorId: string]: Connector;
};
export type ModelFormValue = {
id: string;
algorithm?: MODEL_ALGORITHM;
};
/**
********** MISC TYPES/INTERFACES ************
*/
// Based off of https://github.com/opensearch-project/flow-framework/blob/main/src/main/java/org/opensearch/flowframework/model/State.java
export enum WORKFLOW_STATE {
NOT_STARTED = 'Not started',
PROVISIONING = 'Provisioning',
FAILED = 'Failed',
COMPLETED = 'Completed',
}
export type WorkflowResource = {
id: string;
stepType: WORKFLOW_STEP_TYPE;
type: WORKFLOW_RESOURCE_TYPE;
};
// Based off of https://github.com/opensearch-project/flow-framework/blob/main/src/main/java/org/opensearch/flowframework/common/WorkflowResources.java
export enum WORKFLOW_RESOURCE_TYPE {
PIPELINE_ID = 'Ingest pipeline',
INDEX_NAME = 'Index',
MODEL_ID = 'Model',
MODEL_GROUP_ID = 'Model group',
CONNECTOR_ID = 'Connector',
}
export enum WORKFLOW_STEP_TYPE {
CREATE_INGEST_PIPELINE_STEP_TYPE = 'create_ingest_pipeline',
CREATE_SEARCH_PIPELINE_STEP_TYPE = 'create_search_pipeline',
CREATE_INDEX_STEP_TYPE = 'create_index',
}
// We cannot disambiguate ingest vs. search pipelines based on workflow resource type. To work around
// that, we maintain this map from workflow step type -> formatted type
export enum WORKFLOW_STEP_TO_RESOURCE_TYPE_MAP {
'create_ingest_pipeline' = 'Ingest pipeline',
'create_search_pipeline' = 'Search pipeline',
'create_index' = 'Index',
}
export type WorkflowDict = {
[workflowId: string]: Workflow;
};
export type QueryPreset = {
name: string;
query: string;
};
export type PromptPreset = {
name: string;
prompt: string;
};
export type QuickConfigureFields = {
embeddingModelId?: string;
llmId?: string;
vectorField?: string;
textField?: string;
imageField?: string;
labelField?: string;
promptField?: string;
embeddingLength?: number;
llmResponseField?: string;
};
export type QueryParamType = 'Text' | 'Binary';
export type QueryParam = {
name: string;
type: QueryParamType;
value: string;
};
export type CachedFormikState = {
errors?: {};
touched?: {};
};
export type IngestPipelineErrors = {
[idx: number]: { processorType: string; errorMsg: string };
};
/**
********** OPENSEARCH TYPES/INTERFACES ************
*/
// from https://opensearch.org/docs/latest/ingest-pipelines/simulate-ingest/#example-specify-a-pipeline-in-the-path
export type SimulateIngestPipelineDoc = {
_index: string;
_id: string;
_source: any;
};
// from https://opensearch.org/docs/latest/ingest-pipelines/simulate-ingest/#example-specify-a-pipeline-in-the-path
export type SimulateIngestPipelineDocResponse = {
doc: SimulateIngestPipelineDoc & {
_ingest: {
timestamp: string;
};
};
error?: {
reason: string;
};
};
// from https://opensearch.org/docs/latest/ingest-pipelines/simulate-ingest/#example-specify-a-pipeline-in-the-path
export type SimulateIngestPipelineResponse = {
docs: SimulateIngestPipelineDocResponse[];
};
// verbose mode
// from https://opensearch.org/docs/latest/ingest-pipelines/simulate-ingest/#query-parameters
export type SimulateIngestPipelineDocResponseVerbose = SimulateIngestPipelineDocResponse & {
processor_type: string;
status: 'success' | 'error';
description?: string;
};
// verbose mode
// from https://opensearch.org/docs/latest/ingest-pipelines/simulate-ingest/#query-parameters
export type SimulateIngestPipelineResponseVerbose = {
docs: [
{
processor_results: SimulateIngestPipelineDocResponseVerbose[];
}
];
};
export type SearchHit = SimulateIngestPipelineDoc;
export type SearchResponse = {
took: number;
timed_out: boolean;
_shards: {
total: number;
successful: number;
skipped: number;
failed: number;
};
hits: {
total: {
value: number;
relation: string;
};
max_score: number;
hits: SearchHit[];
};
aggregations?: {};
ext?: {};
};
export type SearchProcessorInputData = {
_index: string;
_id: string;
_score: number;
_source: {};
};
export type SearchProcessorOutputData = SearchProcessorInputData;
export type SearchProcessorResult = {
processor_name: string;
duration_millis: number;
status: 'success' | 'fail';
error?: string;
input_data: SearchProcessorInputData[] | null;
output_data: SearchProcessorOutputData[] | null;
};
export type SearchResponseVerbose = SearchResponse & {
processor_results: SearchProcessorResult[];
};
export type SearchPipelineErrors = IngestPipelineErrors;
export type IndexResponse = {
indexName: string;
indexDetails: IndexConfiguration;
};
export type IngestPipelineResponse = {
pipelineId: string;
ingestPipelineDetails: IngestPipelineConfig;
};
export type SearchPipelineResponse = {
pipelineId: string;
searchPipelineDetails: SearchPipelineConfig;
};