Feat: Flatten the request schema of the webhook #10427 (#11917)

### What problem does this PR solve?

Feat: Flatten the request schema of the webhook #10427

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-12-12 09:59:54 +08:00
committed by GitHub
parent 74afb8d710
commit a6bd765a02
10 changed files with 276 additions and 135 deletions

View File

@ -35,7 +35,7 @@ import {
Operator,
TypesWithArray,
} from './constant';
import { BeginFormSchemaType } from './form/begin-form';
import { BeginFormSchemaType } from './form/begin-form/schema';
import { DataOperationsFormSchemaType } from './form/data-operations-form';
import { ExtractorFormSchemaType } from './form/extractor-form';
import { HierarchicalMergerFormSchemaType } from './form/hierarchical-merger-form';
@ -326,10 +326,31 @@ export function transformArrayToObject(
}, {});
}
function transformRequestSchemaToJsonschema(
schema: BeginFormSchemaType['schema'],
) {
const jsonSchema: Record<string, any> = {};
Object.entries(schema || {}).forEach(([key, value]) => {
if (Array.isArray(value)) {
jsonSchema[key] = {
type: 'object',
required: value.filter((x) => x.required).map((x) => x.key),
properties: value.reduce<Record<string, any>>((pre, cur) => {
pre[cur.key] = { type: cur.type };
return pre;
}, {}),
};
}
});
return jsonSchema;
}
function transformBeginParams(params: BeginFormSchemaType) {
if (params.mode === AgentDialogueMode.Webhook) {
return {
...params,
schema: transformRequestSchemaToJsonschema(params.schema),
security: {
...params.security,
ip_whitelist: params.security?.ip_whitelist.map((x) => x.value),