Skip to content

Commit 613b948

Browse files
Optimize/form schema validation (#375)
Co-authored-by: shanexi <[email protected]>
1 parent b736b91 commit 613b948

File tree

4 files changed

+84
-4
lines changed

4 files changed

+84
-4
lines changed

proconfig/utils/expressions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def triangular(low: float = 0.0, high: float = 1.0, mode: float = None) -> float
102102
def is_safe_value(value: Any, depth: int = 0) -> bool:
103103
"""Recursively check if value is safe"""
104104
if depth > 20: # Increase depth limit from 10 to 20
105-
return True # Allow deeper structures instead of blocking them
105+
return False # Allow deeper structures instead of blocking them
106106

107107
if isinstance(value, (int, float, str, bool, type(None))): # Add None as safe type
108108
return True

servers/automata.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import os
23
import json
34
import queue
@@ -521,7 +522,7 @@ def prepare_payload(automata: Automata, event_data: MyShellUserInput, sess_state
521522
@app.get('/api/app/run')
522523
async def app_run(event_data: RunAppRequest, request: Request):
523524

524-
automata = sess_id_to_automata[event_data.session_id]
525+
automata = copy.deepcopy(sess_id_to_automata[event_data.session_id])
525526

526527
sess_id = event_data.session_id
527528
sess_state = sess_states.get(sess_id, SessionState())
@@ -652,7 +653,9 @@ def build_form_schema(target_inputs):
652653
"name": getattr(v, "name"),
653654
"type": type_map.get(v.type, v.type),
654655
"description": v.description,
655-
"default": v.default_value
656+
"default": v.default_value,
657+
"required": v.user_input,
658+
"validations": v.validations,
656659
}
657660
if v.choices:
658661
properties[k]["enum"] = v.choices

web/apps/web/src/components/chat/app-builder-chat-utils.spec.ts

+74
Original file line numberDiff line numberDiff line change
@@ -1425,4 +1425,78 @@ describe('app-builder-chat-utils', () => {
14251425
}
14261426
`);
14271427
});
1428+
1429+
it('patch validation', () => {
1430+
const actions = [
1431+
{
1432+
action: 'MESSAGE_COMPONENTS_BUTTON_ACTION_TYPE_POP_UP_FORM',
1433+
actionLink: null,
1434+
formSchema: {
1435+
properties: {
1436+
untitled_inputs_1: {
1437+
name: 'Untitled',
1438+
type: 'string',
1439+
description: null,
1440+
default: null,
1441+
required: true,
1442+
validations: [
1443+
{
1444+
required: true,
1445+
max_length: 2500,
1446+
max_file_size: 10485760,
1447+
max_number: 0.0,
1448+
min_number: 0.0,
1449+
max_items: null,
1450+
min_items: null,
1451+
error_message: 'Err!',
1452+
},
1453+
],
1454+
},
1455+
},
1456+
required: ['untitled_inputs_1'],
1457+
},
1458+
interactionInput: null,
1459+
},
1460+
];
1461+
const ret = popupFormAction(actions);
1462+
expect(ret).toMatchInlineSnapshot(`
1463+
[
1464+
{
1465+
"action": "MESSAGE_COMPONENTS_BUTTON_ACTION_TYPE_POP_UP_FORM",
1466+
"componentInput": {
1467+
"componentsFunction": [],
1468+
"componentsInput": [
1469+
{
1470+
"booleanDefault": false,
1471+
"description": null,
1472+
"fieldName": "untitled_inputs_1",
1473+
"fileDefaultParam": "",
1474+
"fileDefaultParamType": "MESSAGE_METADATA_TYPE_UNSPECIFIED",
1475+
"fileUploadSizeMaximum": 0,
1476+
"hasIntegerLimitation": false,
1477+
"hasNumberLimitation": false,
1478+
"integerDefault": 0,
1479+
"isRequired": true,
1480+
"name": "Untitled",
1481+
"numberDefault": 0,
1482+
"numberSelectorAllOf": [],
1483+
"numberSelectorDefault": 0,
1484+
"stringCharLengthLimitation": 2500,
1485+
"stringDefault": null,
1486+
"supportedFileTypes": [],
1487+
"textSelectorAllOf": [],
1488+
"textSelectorDefault": "",
1489+
"type": "BOT_IM_COMPONENT_INPUT_TYPE_TEXT_INPUT",
1490+
},
1491+
],
1492+
"description": "Enter to run",
1493+
"energyConsumePerUse": 0,
1494+
"githubUrl": "",
1495+
"name": "Information",
1496+
"saveButtonContent": "Run",
1497+
},
1498+
},
1499+
]
1500+
`);
1501+
});
14281502
});

web/apps/web/src/components/chat/app-builder-chat-utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export function popupFormAction(actions: any[]) {
116116
name: action.formSchema.properties[k].name,
117117
description: action.formSchema.properties[k].description,
118118
stringDefault: action.formSchema.properties[k].default,
119+
stringCharLengthLimitation:
120+
action.formSchema.properties[k].validations?.find(
121+
(v: any) => v.max_length,
122+
)?.max_length || 0,
119123
numberDefault: 0,
120124
hasNumberLimitation: false,
121125
integerDefault: 0,
@@ -131,7 +135,6 @@ export function popupFormAction(actions: any[]) {
131135
fileDefaultParam: '',
132136
fileDefaultParamType: 'MESSAGE_METADATA_TYPE_UNSPECIFIED',
133137
fileUploadSizeMaximum: 0,
134-
stringCharLengthLimitation: 0,
135138
};
136139
if (
137140
['string', 'image'].indexOf(prop.type) > -1 &&

0 commit comments

Comments
 (0)