Skip to content

Optimize/form schema validation #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proconfig/utils/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def triangular(low: float = 0.0, high: float = 1.0, mode: float = None) -> float
def is_safe_value(value: Any, depth: int = 0) -> bool:
"""Recursively check if value is safe"""
if depth > 20: # Increase depth limit from 10 to 20
return True # Allow deeper structures instead of blocking them
return False # Allow deeper structures instead of blocking them

if isinstance(value, (int, float, str, bool, type(None))): # Add None as safe type
return True
Expand Down
7 changes: 5 additions & 2 deletions servers/automata.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import os
import json
import queue
Expand Down Expand Up @@ -521,7 +522,7 @@ def prepare_payload(automata: Automata, event_data: MyShellUserInput, sess_state
@app.get('/api/app/run')
async def app_run(event_data: RunAppRequest, request: Request):

automata = sess_id_to_automata[event_data.session_id]
automata = copy.deepcopy(sess_id_to_automata[event_data.session_id])

sess_id = event_data.session_id
sess_state = sess_states.get(sess_id, SessionState())
Expand Down Expand Up @@ -652,7 +653,9 @@ def build_form_schema(target_inputs):
"name": getattr(v, "name"),
"type": type_map.get(v.type, v.type),
"description": v.description,
"default": v.default_value
"default": v.default_value,
"required": v.user_input,
"validations": v.validations,
}
if v.choices:
properties[k]["enum"] = v.choices
Expand Down
74 changes: 74 additions & 0 deletions web/apps/web/src/components/chat/app-builder-chat-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1425,4 +1425,78 @@ describe('app-builder-chat-utils', () => {
}
`);
});

it('patch validation', () => {
const actions = [
{
action: 'MESSAGE_COMPONENTS_BUTTON_ACTION_TYPE_POP_UP_FORM',
actionLink: null,
formSchema: {
properties: {
untitled_inputs_1: {
name: 'Untitled',
type: 'string',
description: null,
default: null,
required: true,
validations: [
{
required: true,
max_length: 2500,
max_file_size: 10485760,
max_number: 0.0,
min_number: 0.0,
max_items: null,
min_items: null,
error_message: 'Err!',
},
],
},
},
required: ['untitled_inputs_1'],
},
interactionInput: null,
},
];
const ret = popupFormAction(actions);
expect(ret).toMatchInlineSnapshot(`
[
{
"action": "MESSAGE_COMPONENTS_BUTTON_ACTION_TYPE_POP_UP_FORM",
"componentInput": {
"componentsFunction": [],
"componentsInput": [
{
"booleanDefault": false,
"description": null,
"fieldName": "untitled_inputs_1",
"fileDefaultParam": "",
"fileDefaultParamType": "MESSAGE_METADATA_TYPE_UNSPECIFIED",
"fileUploadSizeMaximum": 0,
"hasIntegerLimitation": false,
"hasNumberLimitation": false,
"integerDefault": 0,
"isRequired": true,
"name": "Untitled",
"numberDefault": 0,
"numberSelectorAllOf": [],
"numberSelectorDefault": 0,
"stringCharLengthLimitation": 2500,
"stringDefault": null,
"supportedFileTypes": [],
"textSelectorAllOf": [],
"textSelectorDefault": "",
"type": "BOT_IM_COMPONENT_INPUT_TYPE_TEXT_INPUT",
},
],
"description": "Enter to run",
"energyConsumePerUse": 0,
"githubUrl": "",
"name": "Information",
"saveButtonContent": "Run",
},
},
]
`);
});
});
5 changes: 4 additions & 1 deletion web/apps/web/src/components/chat/app-builder-chat-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export function popupFormAction(actions: any[]) {
name: action.formSchema.properties[k].name,
description: action.formSchema.properties[k].description,
stringDefault: action.formSchema.properties[k].default,
stringCharLengthLimitation:
action.formSchema.properties[k].validations?.find(
(v: any) => v.max_length,
)?.max_length || 0,
numberDefault: 0,
hasNumberLimitation: false,
integerDefault: 0,
Expand All @@ -131,7 +135,6 @@ export function popupFormAction(actions: any[]) {
fileDefaultParam: '',
fileDefaultParamType: 'MESSAGE_METADATA_TYPE_UNSPECIFIED',
fileUploadSizeMaximum: 0,
stringCharLengthLimitation: 0,
};
if (
['string', 'image'].indexOf(prop.type) > -1 &&
Expand Down