Ver código fonte

fix(runtime): only handle standard json schema data (#532)

* fix(runtime): remove json schema isPropertyRequired

* fix(runtime): remove json schema key & name
Louis Young 6 meses atrás
pai
commit
a791662ab3

+ 1 - 1
apps/demo-free-layout/src/components/testrun/testrun-form/use-form-meta.ts

@@ -51,7 +51,7 @@ export const useFormMeta = (): TestRunFormMetaItem[] => {
         type: property.type as JsonSchemaBasicType,
         name,
         defaultValue: property.default,
-        required: property.isPropertyRequired ?? false,
+        required: workflowInputs.required?.includes(name) ?? false,
         itemsType: property.items?.type as JsonSchemaBasicType,
       });
     });

+ 42 - 6
apps/docs/src/en/guide/runtime/api.mdx

@@ -430,18 +430,54 @@ const schema = JSON.stringify({
       id: 'start',
       type: 'start',
       meta: { position: { x: 0, y: 0 } },
-      data: {}
+      data: {
+        outputs: {
+          type: 'object',
+          properties: {
+            userInput: {
+              type: 'string',
+              extra: {
+                index: 0,
+              },
+            }
+          },
+          required: ['userInput'],
+        },
+      }
     },
     {
       id: 'llm',
       type: 'llm',
       meta: { position: { x: 200, y: 0 } },
       data: {
-        modelName: 'gpt-3.5-turbo',
-        temperature: 0.7,
-        systemPrompt: '你是一个助手',
-        prompt: '介绍一下自己'
-      }
+        title: 'LLM_0',
+        inputsValues: {
+          prompt: {
+            type: 'ref',
+            content: ['start_0', 'userInput'],
+          }
+        },
+        inputs: {
+          type: 'object',
+          required: ['editor'],
+          properties: {
+            prompt: {
+              type: 'string',
+              extra: {
+                formComponent: 'prompt-editor',
+              },
+            },
+          },
+        },
+        outputs: {
+          type: 'object',
+          properties: {
+            result: {
+              type: 'string',
+            },
+          },
+        },
+      },
     },
     {
       id: 'end',

+ 0 - 3
apps/docs/src/zh/guide/runtime/api.mdx

@@ -435,9 +435,6 @@ const schema = JSON.stringify({
           type: 'object',
           properties: {
             userInput: {
-              key: 14,
-              name: 'userInput',
-              isPropertyRequired: true,
               type: 'string',
               extra: {
                 index: 0,

+ 0 - 1
packages/materials/form-materials/src/typings/json-schema/index.ts

@@ -23,7 +23,6 @@ export interface IJsonSchema<T = string> {
   items?: IJsonSchema<T>;
   required?: string[];
   $ref?: string;
-  isPropertyRequired?: boolean;
   extra?: {
     index?: number;
     // Used in BaseType.isEqualWithJSONSchema, the type comparison will be weak

+ 0 - 3
packages/runtime/interface/src/schema/json-schema.ts

@@ -25,9 +25,6 @@ export interface IJsonSchema<T = string> {
   items?: IJsonSchema<T>;
   required?: string[];
   $ref?: string;
-  key?: number;
-  name?: string;
-  isPropertyRequired?: boolean;
   extra?: {
     index?: number;
     // Used in BaseType.isEqualWithJSONSchema, the type comparison will be weak

+ 0 - 12
packages/runtime/js-core/src/domain/__tests__/schemas/basic-llm.ts

@@ -22,36 +22,24 @@ export const basicLLMSchema: WorkflowSchema = {
           type: 'object',
           properties: {
             model_name: {
-              key: 14,
-              name: 'model_name',
-              isPropertyRequired: true,
               type: 'string',
               extra: {
                 index: 0,
               },
             },
             api_key: {
-              key: 19,
-              name: 'api_key',
-              isPropertyRequired: true,
               type: 'string',
               extra: {
                 index: 1,
               },
             },
             api_host: {
-              key: 20,
-              name: 'api_host',
-              isPropertyRequired: true,
               type: 'string',
               extra: {
                 index: 2,
               },
             },
             formula: {
-              key: 4,
-              name: 'formula',
-              isPropertyRequired: true,
               type: 'string',
               extra: {
                 index: 3,

+ 0 - 17
packages/runtime/js-core/src/domain/__tests__/schemas/basic.ts

@@ -22,26 +22,18 @@ export const basicSchema: WorkflowSchema = {
           type: 'object',
           properties: {
             model_name: {
-              key: 14,
-              name: 'model_name',
-              isPropertyRequired: true,
               type: 'string',
               extra: {
                 index: 0,
               },
             },
             llm_settings: {
-              key: 17,
-              name: 'llm_settings',
-              isPropertyRequired: false,
               type: 'object',
               extra: {
                 index: 1,
               },
               properties: {
                 temperature: {
-                  key: 18,
-                  name: 'temperature',
                   type: 'number',
                   extra: {
                     index: 1,
@@ -51,27 +43,18 @@ export const basicSchema: WorkflowSchema = {
               required: [],
             },
             work: {
-              key: 5,
-              name: 'work',
-              isPropertyRequired: true,
               type: 'object',
               extra: {
                 index: 2,
               },
               properties: {
                 role: {
-                  key: 6,
-                  name: 'role',
-                  isPropertyRequired: true,
                   type: 'string',
                   extra: {
                     index: 0,
                   },
                 },
                 task: {
-                  key: 8,
-                  name: 'task',
-                  isPropertyRequired: true,
                   type: 'string',
                   extra: {
                     index: 1,

+ 0 - 6
packages/runtime/js-core/src/domain/__tests__/schemas/branch-two-layers.ts

@@ -22,9 +22,6 @@ export const branchTwoLayersSchema: WorkflowSchema = {
           type: 'object',
           properties: {
             model_id: {
-              key: 0,
-              name: 'model_id',
-              isPropertyRequired: false,
               type: 'integer',
               default: 'Hello Flow.',
               extra: {
@@ -32,9 +29,6 @@ export const branchTwoLayersSchema: WorkflowSchema = {
               },
             },
             prompt: {
-              key: 5,
-              name: 'prompt',
-              isPropertyRequired: false,
               type: 'string',
               extra: {
                 index: 1,

+ 0 - 6
packages/runtime/js-core/src/domain/__tests__/schemas/branch.ts

@@ -22,9 +22,6 @@ export const branchSchema: WorkflowSchema = {
           type: 'object',
           properties: {
             model_id: {
-              key: 0,
-              name: 'model_id',
-              isPropertyRequired: false,
               type: 'integer',
               default: 'Hello Flow.',
               extra: {
@@ -32,9 +29,6 @@ export const branchSchema: WorkflowSchema = {
               },
             },
             prompt: {
-              key: 5,
-              name: 'prompt',
-              isPropertyRequired: false,
               type: 'string',
               extra: {
                 index: 1,

+ 0 - 3
packages/runtime/js-core/src/domain/__tests__/schemas/loop.ts

@@ -22,9 +22,6 @@ export const loopSchema: WorkflowSchema = {
           type: 'object',
           properties: {
             tasks: {
-              key: 7,
-              name: 'tasks',
-              isPropertyRequired: true,
               type: 'array',
               extra: {
                 index: 0,

+ 0 - 14
packages/runtime/js-core/src/domain/__tests__/schemas/two-llm.ts

@@ -22,9 +22,6 @@ export const twoLLMSchema: WorkflowSchema = {
           type: 'object',
           properties: {
             query: {
-              key: 5,
-              name: 'query',
-              isPropertyRequired: false,
               type: 'string',
               default: 'Hello Flow.',
               extra: {
@@ -32,9 +29,6 @@ export const twoLLMSchema: WorkflowSchema = {
               },
             },
             enable: {
-              key: 6,
-              name: 'enable',
-              isPropertyRequired: false,
               type: 'boolean',
               default: true,
               extra: {
@@ -42,9 +36,6 @@ export const twoLLMSchema: WorkflowSchema = {
               },
             },
             array_obj: {
-              key: 7,
-              name: 'array_obj',
-              isPropertyRequired: false,
               type: 'array',
               items: {
                 type: 'object',
@@ -62,17 +53,12 @@ export const twoLLMSchema: WorkflowSchema = {
               },
             },
             num: {
-              key: 10,
-              name: 'num',
-              isPropertyRequired: false,
               type: 'number',
               extra: {
                 index: 3,
               },
             },
             model: {
-              key: 24,
-              name: 'model',
               type: 'string',
               extra: {
                 index: 5,

+ 0 - 52
packages/runtime/js-core/src/domain/__tests__/schemas/validate-inputs.ts

@@ -49,92 +49,63 @@ export const validateInputsSchema: WorkflowSchema = {
           type: 'object',
           properties: {
             AA: {
-              key: 10,
-              name: 'AA',
-              isPropertyRequired: true,
               type: 'string',
               extra: {
                 index: 0,
               },
             },
             BB: {
-              key: 11,
-              name: 'BB',
-              isPropertyRequired: false,
               type: 'integer',
               extra: {
                 index: 1,
               },
             },
             CC: {
-              key: 12,
-              name: 'CC',
-              isPropertyRequired: false,
               type: 'object',
               extra: {
                 index: 2,
               },
               properties: {
                 CA: {
-                  key: 13,
-                  name: 'CA',
-                  isPropertyRequired: true,
                   type: 'string',
                   extra: {
                     index: 0,
                   },
                 },
                 CB: {
-                  key: 14,
-                  name: 'CB',
-                  isPropertyRequired: true,
                   type: 'integer',
                   extra: {
                     index: 1,
                   },
                 },
                 CC: {
-                  key: 50,
-                  name: 'CC',
                   type: 'number',
                   extra: {
                     index: 3,
                   },
-                  isPropertyRequired: true,
                 },
                 CD: {
-                  key: 51,
-                  name: 'CD',
                   type: 'boolean',
                   extra: {
                     index: 4,
                   },
-                  isPropertyRequired: true,
                 },
                 CE: {
-                  key: 52,
-                  name: 'CE',
                   type: 'object',
                   extra: {
                     index: 5,
                   },
-                  isPropertyRequired: true,
                   properties: {
                     CEA: {
-                      key: 53,
-                      name: 'CEA',
                       type: 'string',
                       extra: {
                         index: 1,
                       },
-                      isPropertyRequired: true,
                     },
                   },
                   required: ['CEA'],
                 },
                 CF: {
-                  key: 54,
-                  name: 'CF',
                   type: 'array',
                   extra: {
                     index: 6,
@@ -142,15 +113,11 @@ export const validateInputsSchema: WorkflowSchema = {
                   items: {
                     type: 'string',
                   },
-                  isPropertyRequired: true,
                 },
               },
               required: ['CA', 'CB', 'CC', 'CD', 'CE', 'CF'],
             },
             DD: {
-              key: 15,
-              name: 'DD',
-              isPropertyRequired: false,
               type: 'array',
               extra: {
                 index: 3,
@@ -159,29 +126,22 @@ export const validateInputsSchema: WorkflowSchema = {
                 type: 'object',
                 properties: {
                   DA: {
-                    key: 16,
-                    name: 'DA',
                     type: 'string',
                     extra: {
                       index: 1,
                     },
                   },
                   DB: {
-                    key: 17,
-                    name: 'DB',
                     type: 'object',
                     extra: {
                       index: 2,
                     },
                     properties: {
                       DBA: {
-                        key: 19,
-                        name: 'DBA',
                         type: 'string',
                         extra: {
                           index: 1,
                         },
-                        isPropertyRequired: true,
                       },
                     },
                     required: ['DBA'],
@@ -191,26 +151,18 @@ export const validateInputsSchema: WorkflowSchema = {
               },
             },
             EE: {
-              key: 20,
-              name: 'EE',
-              isPropertyRequired: true,
               type: 'object',
               extra: {
                 index: 4,
               },
               properties: {
                 EA: {
-                  key: 21,
-                  name: 'EA',
                   type: 'object',
                   extra: {
                     index: 1,
                   },
                   properties: {
                     EAA: {
-                      key: 22,
-                      name: 'EAA',
-                      isPropertyRequired: true,
                       type: 'string',
                       extra: {
                         index: 1,
@@ -218,16 +170,12 @@ export const validateInputsSchema: WorkflowSchema = {
                     },
                   },
                   required: ['EAA'],
-                  isPropertyRequired: true,
                 },
                 EB: {
-                  key: 23,
-                  name: 'EB',
                   type: 'string',
                   extra: {
                     index: 2,
                   },
-                  isPropertyRequired: false,
                 },
               },
               required: ['EA'],

+ 0 - 7
packages/runtime/js-core/src/infrastructure/utils/json-schema-validator.test.ts

@@ -14,27 +14,22 @@ describe('JSONSchemaValidator', () => {
     properties: {
       AA: {
         type: 'string',
-        isPropertyRequired: true,
         extra: { index: 0 },
       },
       BB: {
         type: 'integer',
-        isPropertyRequired: false,
         extra: { index: 1 },
       },
       CC: {
         type: 'object',
-        isPropertyRequired: false,
         extra: { index: 2 },
         properties: {
           CA: {
             type: 'string',
-            isPropertyRequired: true,
             extra: { index: 0 },
           },
           CB: {
             type: 'integer',
-            isPropertyRequired: true,
             extra: { index: 1 },
           },
         },
@@ -42,7 +37,6 @@ describe('JSONSchemaValidator', () => {
       },
       DD: {
         type: 'array',
-        isPropertyRequired: false,
         extra: { index: 3 },
         items: {
           type: 'object',
@@ -57,7 +51,6 @@ describe('JSONSchemaValidator', () => {
               properties: {
                 DBA: {
                   type: 'string',
-                  isPropertyRequired: true,
                   extra: { index: 1 },
                 },
               },

+ 3 - 4
packages/runtime/js-core/src/infrastructure/utils/json-schema-validator.ts

@@ -147,11 +147,10 @@ const validateObject = (value: unknown, schema: IJsonSchema, path: string): Vali
     }
   }
 
-  // Check isPropertyRequired field in properties (if exists)
+  // Check is field required
   if (schema.properties) {
-    for (const [propertyName, propertySchema] of Object.entries(schema.properties)) {
-      const isRequired =
-        (propertySchema as unknown as Record<string, unknown>).isPropertyRequired === true;
+    for (const [propertyName] of Object.entries(schema.properties)) {
+      const isRequired = schema.required?.includes(propertyName) ?? false;
       if (isRequired && !(propertyName in objectValue)) {
         return {
           result: false,