arterm-sedov commited on
Commit
9b847bf
·
1 Parent(s): d91570a

implemented get_form tool

Browse files
tools/templates_tools/__init__.py CHANGED
@@ -9,11 +9,13 @@ and listing template attributes.
9
  from tools.templates_tools.tool_create_edit_record import create_edit_record
10
  from tools.templates_tools.tool_list_attributes import list_attributes
11
  from tools.templates_tools.tool_list_records import list_template_records
 
12
  from tools.templates_tools.tools_record_template import edit_or_create_record_template
13
 
14
  __all__ = [
15
  "create_edit_record",
16
  "edit_or_create_record_template",
 
17
  "list_attributes",
18
  "list_template_records",
19
  ]
 
9
  from tools.templates_tools.tool_create_edit_record import create_edit_record
10
  from tools.templates_tools.tool_list_attributes import list_attributes
11
  from tools.templates_tools.tool_list_records import list_template_records
12
+ from tools.templates_tools.tools_form import get_form
13
  from tools.templates_tools.tools_record_template import edit_or_create_record_template
14
 
15
  __all__ = [
16
  "create_edit_record",
17
  "edit_or_create_record_template",
18
+ "get_form",
19
  "list_attributes",
20
  "list_template_records",
21
  ]
tools/templates_tools/tools_form.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ..tool_utils import *
2
+
3
+ FORM_ENDPOINT = "webapi/Form"
4
+
5
+
6
+ class GetFormSchema(BaseModel):
7
+ application_system_name: str = Field(
8
+ description="System name of the application. RU: Системное имя приложения",
9
+ )
10
+ template_system_name: str = Field(
11
+ description="System name of the template. RU: Системное имя шаблона",
12
+ )
13
+ form_system_name: str = Field(
14
+ description="System name of the form. RU: Системное имя формы",
15
+ )
16
+
17
+ @field_validator(
18
+ "application_system_name",
19
+ "template_system_name",
20
+ "form_system_name",
21
+ mode="before",
22
+ )
23
+ @classmethod
24
+ def non_empty_str(cls, v: Any) -> Any:
25
+ if isinstance(v, str) and v.strip() == "":
26
+ msg = "must be a non-empty string"
27
+ raise ValueError(msg)
28
+ return v
29
+
30
+
31
+ @tool(
32
+ "get_form",
33
+ return_direct=False,
34
+ args_schema=GetFormSchema,
35
+ )
36
+ def get_form(
37
+ application_system_name: str,
38
+ template_system_name: str,
39
+ form_system_name: str,
40
+ ) -> dict[str, Any]:
41
+ r"""
42
+ Fetch a form model.
43
+
44
+ Returns:
45
+ dict: {
46
+ "success": bool - True if the template was created or edited successfully
47
+ "status_code": int - HTTP response status code
48
+ "error": str|None - Error message if operation failed
49
+ form model fields: dict|list|None — Form structure without wrapper key (normalized)
50
+ }
51
+ """
52
+ form_global_alias = f"Form@{template_system_name}.{form_system_name}"
53
+ endpoint = f"{FORM_ENDPOINT}/{application_system_name}/{form_global_alias}"
54
+ result = execute_get_operation(AttributeResult, endpoint)
55
+
56
+ # Lean normalization: translate API terms to platform terminology
57
+ if result.get("success"):
58
+ result = _normalize_form_terms(result)
59
+
60
+ return result
61
+
62
+
63
+ def _normalize_form_terms(data: dict) -> dict:
64
+ """
65
+ Lean normalization of API terms to platform terminology.
66
+ Translates 'alias' → 'systemName' and 'Property' → 'Attribute'
67
+ while preserving 'globalAlias' structures.
68
+ """
69
+ if not isinstance(data, dict):
70
+ return data
71
+
72
+ normalized = {}
73
+ for key, value in data.items():
74
+ # Rename 'alias' to 'systemName' (but not 'globalAlias')
75
+ if key == "alias":
76
+ normalized["systemName"] = value
77
+ elif "Alias" in key and not "globalalias" in key.lower():
78
+ normalized[key.replace("Alias", "SystemName")] = value
79
+ # Rename 'Property' to 'Attribute' in camelCase
80
+ elif "Property" in key:
81
+ normalized[key.replace("Property", "Attribute")] = value
82
+ # Recursively process nested structures
83
+ elif isinstance(value, dict):
84
+ normalized[key] = _normalize_form_terms(value)
85
+ elif isinstance(value, list):
86
+ normalized[key] = [
87
+ _normalize_form_terms(item) if isinstance(item, dict) else item
88
+ for item in value
89
+ ]
90
+ else:
91
+ normalized[key] = value
92
+
93
+ return normalized
94
+
95
+
96
+ if __name__ == "__main__":
97
+ results = get_form.invoke({
98
+ "application_system_name": "Велестест",
99
+ "template_system_name": "Prichina_otkaza",
100
+ "form_system_name": "defaultForm"
101
+ })
102
+ print(results)
103
+
104
+
tools/templates_tools/tools_record_template.py CHANGED
@@ -51,7 +51,7 @@ def edit_or_create_record_template(
51
  dict: {
52
  "success": bool - True if the template was created or edited successfully
53
  "status_code": int - HTTP response status code
54
- "raw_response": dict|str|None - Raw response for auditing or payload body (sanitized)
55
  "error": str|None - Error message if operation failed
56
  }
57
  """
 
51
  dict: {
52
  "success": bool - True if the template was created or edited successfully
53
  "status_code": int - HTTP response status code
54
+ "raw_response": dict|str|None - template model (sanitized)
55
  "error": str|None - Error message if operation failed
56
  }
57
  """
tools/tool_utils.py CHANGED
@@ -429,8 +429,10 @@ def rename_data(
429
  if isinstance(data, dict):
430
  # Определяем тип атрибута
431
  renamed_data = {}
432
-
433
  # Добавляем описание типа атрибута как первый элемент
 
 
434
  for key, value in ENTITY_TYPE_MAPPING.items():
435
  if caller_name.__contains__(key):
436
  model_description = value[0]
 
429
  if isinstance(data, dict):
430
  # Определяем тип атрибута
431
  renamed_data = {}
432
+
433
  # Добавляем описание типа атрибута как первый элемент
434
+ model_description = None
435
+ model_response = None
436
  for key, value in ENTITY_TYPE_MAPPING.items():
437
  if caller_name.__contains__(key):
438
  model_description = value[0]