pygeai 0.6.0b14__py3-none-any.whl → 0.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. pygeai/__init__.py +1 -2
  2. pygeai/_docs/source/content/api_reference/project.rst +392 -0
  3. pygeai/_docs/source/content/authentication.rst +130 -1
  4. pygeai/_docs/source/content/debugger.rst +327 -157
  5. pygeai/_docs/source/pygeai.core.common.rst +8 -0
  6. pygeai/_docs/source/pygeai.tests.auth.rst +56 -0
  7. pygeai/_docs/source/pygeai.tests.cli.rst +8 -0
  8. pygeai/admin/clients.py +1 -3
  9. pygeai/analytics/clients.py +1 -1
  10. pygeai/assistant/clients.py +2 -7
  11. pygeai/assistant/data/clients.py +0 -8
  12. pygeai/assistant/data_analyst/clients.py +0 -2
  13. pygeai/assistant/managers.py +1 -1
  14. pygeai/assistant/rag/clients.py +0 -2
  15. pygeai/assistant/rag/mappers.py +9 -11
  16. pygeai/auth/clients.py +26 -7
  17. pygeai/auth/endpoints.py +2 -1
  18. pygeai/chat/clients.py +2 -2
  19. pygeai/chat/managers.py +1 -1
  20. pygeai/cli/commands/admin.py +13 -25
  21. pygeai/cli/commands/analytics.py +31 -71
  22. pygeai/cli/commands/assistant.py +84 -138
  23. pygeai/cli/commands/auth.py +23 -46
  24. pygeai/cli/commands/base.py +0 -1
  25. pygeai/cli/commands/chat.py +218 -209
  26. pygeai/cli/commands/common.py +5 -5
  27. pygeai/cli/commands/configuration.py +79 -29
  28. pygeai/cli/commands/docs.py +3 -4
  29. pygeai/cli/commands/embeddings.py +13 -19
  30. pygeai/cli/commands/evaluation.py +133 -344
  31. pygeai/cli/commands/feedback.py +7 -15
  32. pygeai/cli/commands/files.py +26 -53
  33. pygeai/cli/commands/gam.py +28 -69
  34. pygeai/cli/commands/lab/ai_lab.py +96 -142
  35. pygeai/cli/commands/lab/common.py +1 -1
  36. pygeai/cli/commands/lab/spec.py +12 -32
  37. pygeai/cli/commands/llm.py +9 -18
  38. pygeai/cli/commands/migrate.py +43 -99
  39. pygeai/cli/commands/organization.py +223 -196
  40. pygeai/cli/commands/rag.py +35 -58
  41. pygeai/cli/commands/rerank.py +21 -25
  42. pygeai/cli/commands/secrets.py +39 -67
  43. pygeai/cli/commands/usage_limits.py +50 -136
  44. pygeai/cli/commands/validators.py +1 -1
  45. pygeai/cli/geai.py +32 -3
  46. pygeai/cli/geai_proxy.py +6 -2
  47. pygeai/cli/install_man.py +1 -1
  48. pygeai/cli/parsers.py +1 -1
  49. pygeai/core/base/clients.py +90 -21
  50. pygeai/core/base/mappers.py +39 -55
  51. pygeai/core/base/session.py +129 -18
  52. pygeai/core/common/config.py +50 -13
  53. pygeai/core/common/constants.py +8 -0
  54. pygeai/core/common/exceptions.py +6 -0
  55. pygeai/core/embeddings/clients.py +0 -1
  56. pygeai/core/embeddings/managers.py +0 -1
  57. pygeai/core/feedback/clients.py +0 -2
  58. pygeai/core/feedback/models.py +1 -1
  59. pygeai/core/files/clients.py +0 -3
  60. pygeai/core/files/managers.py +1 -1
  61. pygeai/core/files/mappers.py +4 -5
  62. pygeai/core/llm/clients.py +0 -1
  63. pygeai/core/models.py +4 -4
  64. pygeai/core/plugins/clients.py +0 -3
  65. pygeai/core/plugins/models.py +2 -2
  66. pygeai/core/rerank/clients.py +0 -2
  67. pygeai/core/secrets/clients.py +0 -2
  68. pygeai/core/services/rest.py +80 -14
  69. pygeai/core/singleton.py +24 -0
  70. pygeai/dbg/__init__.py +2 -2
  71. pygeai/dbg/debugger.py +276 -38
  72. pygeai/evaluation/clients.py +2 -4
  73. pygeai/evaluation/dataset/clients.py +0 -1
  74. pygeai/evaluation/plan/clients.py +0 -2
  75. pygeai/evaluation/result/clients.py +0 -2
  76. pygeai/gam/clients.py +1 -3
  77. pygeai/health/clients.py +1 -3
  78. pygeai/lab/clients.py +0 -1
  79. pygeai/lab/managers.py +0 -1
  80. pygeai/lab/models.py +0 -1
  81. pygeai/lab/strategies/clients.py +1 -2
  82. pygeai/lab/tools/clients.py +2 -2
  83. pygeai/lab/tools/mappers.py +1 -1
  84. pygeai/migration/strategies.py +5 -6
  85. pygeai/migration/tools.py +1 -1
  86. pygeai/organization/clients.py +118 -12
  87. pygeai/organization/endpoints.py +1 -0
  88. pygeai/organization/limits/clients.py +4 -6
  89. pygeai/organization/limits/managers.py +1 -4
  90. pygeai/organization/managers.py +2 -2
  91. pygeai/proxy/config.py +1 -0
  92. pygeai/proxy/managers.py +6 -5
  93. pygeai/tests/admin/test_clients.py +11 -11
  94. pygeai/tests/assistants/rag/test_clients.py +1 -1
  95. pygeai/tests/assistants/rag/test_models.py +1 -2
  96. pygeai/tests/assistants/test_clients.py +1 -1
  97. pygeai/tests/assistants/test_managers.py +1 -3
  98. pygeai/tests/auth/test_cli_configuration.py +252 -0
  99. pygeai/tests/auth/test_client_initialization.py +411 -0
  100. pygeai/tests/auth/test_clients.py +29 -27
  101. pygeai/tests/auth/test_config_manager.py +305 -0
  102. pygeai/tests/auth/test_header_injection.py +294 -0
  103. pygeai/tests/auth/test_oauth.py +3 -1
  104. pygeai/tests/auth/test_session_logging.py +119 -0
  105. pygeai/tests/auth/test_session_validation.py +408 -0
  106. pygeai/tests/auth/test_singleton_reset.py +201 -0
  107. pygeai/tests/chat/test_clients.py +1 -1
  108. pygeai/tests/chat/test_iris.py +1 -1
  109. pygeai/tests/chat/test_ui.py +0 -2
  110. pygeai/tests/cli/commands/lab/test_ai_lab.py +1 -3
  111. pygeai/tests/cli/commands/lab/test_common.py +0 -1
  112. pygeai/tests/cli/commands/test_chat.py +1 -1
  113. pygeai/tests/cli/commands/test_common.py +0 -1
  114. pygeai/tests/cli/commands/test_embeddings.py +2 -2
  115. pygeai/tests/cli/commands/test_evaluation.py +1 -9
  116. pygeai/tests/cli/commands/test_llm.py +1 -1
  117. pygeai/tests/cli/commands/test_migrate.py +1 -1
  118. pygeai/tests/cli/commands/test_rerank.py +0 -1
  119. pygeai/tests/cli/commands/test_secrets.py +1 -1
  120. pygeai/tests/cli/commands/test_show_help.py +0 -1
  121. pygeai/tests/cli/commands/test_validators.py +0 -1
  122. pygeai/tests/cli/test_credentials_flag.py +312 -0
  123. pygeai/tests/cli/test_error_handler.py +0 -1
  124. pygeai/tests/core/base/test_mappers.py +2 -2
  125. pygeai/tests/core/base/test_models.py +4 -4
  126. pygeai/tests/core/common/test_config.py +2 -7
  127. pygeai/tests/core/common/test_decorators.py +0 -1
  128. pygeai/tests/core/embeddings/test_managers.py +1 -1
  129. pygeai/tests/core/feedback/test_clients.py +2 -2
  130. pygeai/tests/core/files/test_clients.py +6 -6
  131. pygeai/tests/core/files/test_models.py +0 -1
  132. pygeai/tests/core/files/test_responses.py +0 -1
  133. pygeai/tests/core/llm/test_clients.py +1 -1
  134. pygeai/tests/core/plugins/test_clients.py +4 -4
  135. pygeai/tests/core/rerank/test_mappers.py +1 -3
  136. pygeai/tests/core/secrets/test_clients.py +2 -3
  137. pygeai/tests/core/services/test_rest.py +10 -10
  138. pygeai/tests/core/utils/test_console.py +0 -1
  139. pygeai/tests/dbg/test_debugger.py +95 -8
  140. pygeai/tests/evaluation/dataset/test_clients.py +24 -27
  141. pygeai/tests/evaluation/plan/test_clients.py +16 -18
  142. pygeai/tests/evaluation/result/test_clients.py +4 -5
  143. pygeai/tests/health/test_clients.py +2 -2
  144. pygeai/tests/integration/lab/agents/test_create_agent.py +1 -3
  145. pygeai/tests/integration/lab/agents/test_get_agent.py +1 -1
  146. pygeai/tests/integration/lab/processes/test_create_process.py +2 -2
  147. pygeai/tests/integration/lab/processes/test_create_task.py +2 -3
  148. pygeai/tests/integration/lab/processes/test_delete_process.py +0 -1
  149. pygeai/tests/integration/lab/processes/test_get_process.py +2 -4
  150. pygeai/tests/integration/lab/processes/test_list_process_instances.py +1 -3
  151. pygeai/tests/integration/lab/processes/test_update_process.py +3 -9
  152. pygeai/tests/integration/lab/reasoning_strategies/test_update_reasoning_strategy.py +1 -2
  153. pygeai/tests/integration/lab/tools/test_delete_tool.py +1 -1
  154. pygeai/tests/integration/lab/tools/test_list_tools.py +1 -1
  155. pygeai/tests/integration/lab/tools/test_update_tool.py +1 -1
  156. pygeai/tests/lab/agents/test_clients.py +17 -17
  157. pygeai/tests/lab/processes/test_clients.py +67 -67
  158. pygeai/tests/lab/processes/test_mappers.py +23 -23
  159. pygeai/tests/lab/spec/test_loader.py +0 -2
  160. pygeai/tests/lab/spec/test_parsers.py +1 -2
  161. pygeai/tests/lab/strategies/test_clients.py +10 -10
  162. pygeai/tests/lab/test_managers.py +3 -5
  163. pygeai/tests/lab/test_mappers.py +1 -4
  164. pygeai/tests/lab/tools/test_clients.py +21 -21
  165. pygeai/tests/lab/tools/test_mappers.py +0 -1
  166. pygeai/tests/organization/limits/test_clients.py +33 -33
  167. pygeai/tests/organization/limits/test_managers.py +7 -7
  168. pygeai/tests/organization/test_clients.py +78 -60
  169. pygeai/tests/proxy/test_clients.py +1 -1
  170. pygeai/tests/proxy/test_integration.py +1 -4
  171. pygeai/tests/proxy/test_managers.py +1 -2
  172. pygeai/tests/proxy/test_servers.py +1 -2
  173. pygeai/tests/snippets/assistants/rag/delete_rag_assistant.py +0 -1
  174. pygeai/tests/snippets/assistants/rag/get_documents.py +0 -1
  175. pygeai/tests/snippets/assistants/rag/get_rag_assistant_data.py +0 -1
  176. pygeai/tests/snippets/chat/get_request_status.py +0 -1
  177. pygeai/tests/snippets/dbg/file_debugging.py +72 -0
  178. pygeai/tests/snippets/dbg/module_debugging.py +60 -0
  179. pygeai/tests/snippets/embeddings/cohere_example.py +2 -2
  180. pygeai/tests/snippets/embeddings/openai_base64_example.py +1 -1
  181. pygeai/tests/snippets/evaluation/dataset/complete_workflow_example.py +8 -8
  182. pygeai/tests/snippets/evaluation/plan/complete_workflow_example.py +5 -5
  183. pygeai/tests/snippets/evaluation/result/complete_workflow_example.py +3 -3
  184. pygeai/tests/snippets/lab/agentic_flow_example_1.py +1 -1
  185. pygeai/tests/snippets/lab/agentic_flow_example_2.py +3 -4
  186. pygeai/tests/snippets/lab/agents/create_agent_with_permissions.py +2 -2
  187. pygeai/tests/snippets/lab/agents/delete_agent.py +1 -2
  188. pygeai/tests/snippets/lab/agents/get_agent.py +1 -1
  189. pygeai/tests/snippets/lab/agents/get_agent_with_new_fields.py +10 -10
  190. pygeai/tests/snippets/lab/agents/get_sharing_link.py +0 -1
  191. pygeai/tests/snippets/lab/agents/list_agents.py +1 -1
  192. pygeai/tests/snippets/lab/agents/publish_agent_revision.py +0 -1
  193. pygeai/tests/snippets/lab/agents/update_agent_properties.py +1 -1
  194. pygeai/tests/snippets/lab/crud_ui.py +3 -5
  195. pygeai/tests/snippets/lab/processes/kbs/get_kb.py +0 -1
  196. pygeai/tests/snippets/lab/processes/kbs/list_kbs.py +0 -1
  197. pygeai/tests/snippets/lab/processes/list_processes.py +1 -1
  198. pygeai/tests/snippets/lab/samples/summarize_files.py +0 -3
  199. pygeai/tests/snippets/lab/strategies/get_reasoning_strategy.py +0 -1
  200. pygeai/tests/snippets/lab/strategies/list_reasoning_strategies.py +1 -1
  201. pygeai/tests/snippets/lab/tools/get_tool.py +1 -1
  202. pygeai/tests/snippets/lab/tools/publish_tool_revision.py +0 -1
  203. pygeai/tests/snippets/lab/tools/set_parameters.py +1 -2
  204. pygeai/tests/snippets/lab/use_cases/c_code_fixer_agent_flow.py +2 -3
  205. pygeai/tests/snippets/lab/use_cases/file_summarizer_example_2.py +1 -1
  206. pygeai/tests/snippets/lab/use_cases/update_cli_expert.py +0 -1
  207. pygeai/tests/snippets/lab/use_cases/update_lab_expert.py +0 -1
  208. pygeai/tests/snippets/lab/use_cases/update_web_designer.py +0 -1
  209. pygeai/tests/snippets/lab/use_cases/update_web_reader.py +0 -1
  210. pygeai/tests/snippets/migrate/orchestrator_examples.py +1 -1
  211. {pygeai-0.6.0b14.dist-info → pygeai-0.6.1.dist-info}/METADATA +32 -7
  212. {pygeai-0.6.0b14.dist-info → pygeai-0.6.1.dist-info}/RECORD +216 -205
  213. {pygeai-0.6.0b14.dist-info → pygeai-0.6.1.dist-info}/WHEEL +0 -0
  214. {pygeai-0.6.0b14.dist-info → pygeai-0.6.1.dist-info}/entry_points.txt +0 -0
  215. {pygeai-0.6.0b14.dist-info → pygeai-0.6.1.dist-info}/licenses/LICENSE +0 -0
  216. {pygeai-0.6.0b14.dist-info → pygeai-0.6.1.dist-info}/top_level.txt +0 -0
@@ -26,10 +26,8 @@ def get_assistants_from_project():
26
26
 
27
27
 
28
28
  def get_assistant_detail(option_list: list):
29
- name = None
30
- for option_flag, option_arg in option_list:
31
- if option_flag.name == "name":
32
- name = option_arg
29
+ opts = {opt.name: arg for opt, arg in option_list}
30
+ name = opts.get("name")
33
31
 
34
32
  if not name:
35
33
  raise MissingRequirementException("Cannot retrieve assistant detail without name")
@@ -896,10 +894,8 @@ update_assistant_options = [
896
894
 
897
895
 
898
896
  def delete_assistant(option_list: list):
899
- name = None
900
- for option_flag, option_arg in option_list:
901
- if option_flag.name == "name":
902
- name = option_arg
897
+ opts = {opt.name: arg for opt, arg in option_list}
898
+ name = opts.get("name")
903
899
 
904
900
  if not name:
905
901
  raise MissingRequirementException("Cannot delete assistant detail without name")
@@ -920,16 +916,13 @@ delete_assistant_options = [
920
916
 
921
917
 
922
918
  def list_documents(option_list: list):
923
- name = None
924
- skip = 0
925
- count = 10
926
- for option_flag, option_arg in option_list:
927
- if option_flag.name == "name":
928
- name = option_arg
929
- if option_flag.name == "skip":
930
- skip = int(option_arg) if str(option_arg).isdigit() else 0
931
- if option_flag.name == "count":
932
- count = int(option_arg) if str(option_arg).isdigit() else 10
919
+ opts = {opt.name: arg for opt, arg in option_list}
920
+ name = opts.get("name")
921
+ skip_arg = opts.get("skip", "0")
922
+ count_arg = opts.get("count", "10")
923
+
924
+ skip = int(skip_arg) if str(skip_arg).isdigit() else 0
925
+ count = int(count_arg) if str(count_arg).isdigit() else 10
933
926
 
934
927
  if not name:
935
928
  raise MissingRequirementException("Cannot list documents without assistant name")
@@ -966,10 +959,8 @@ list_documents_options = [
966
959
 
967
960
 
968
961
  def delete_all_documents(option_list: list):
969
- name = None
970
- for option_flag, option_arg in option_list:
971
- if option_flag.name == "name":
972
- name = option_arg
962
+ opts = {opt.name: arg for opt, arg in option_list}
963
+ name = opts.get("name")
973
964
 
974
965
  if not name:
975
966
  raise MissingRequirementException("Cannot delete all documents without assistant name")
@@ -992,13 +983,9 @@ delete_all_documents_options = [
992
983
 
993
984
 
994
985
  def get_document_data(option_list: list):
995
- name = None
996
- document_id = None
997
- for option_flag, option_arg in option_list:
998
- if option_flag.name == "name":
999
- name = option_arg
1000
- if option_flag.name == "document_id":
1001
- document_id = option_arg
986
+ opts = {opt.name: arg for opt, arg in option_list}
987
+ name = opts.get("name")
988
+ document_id = opts.get("document_id")
1002
989
 
1003
990
  if not (name and document_id):
1004
991
  raise MissingRequirementException("Cannot retrieve document data without assistant name and id")
@@ -1028,29 +1015,23 @@ get_document_data_options = [
1028
1015
 
1029
1016
 
1030
1017
  def upload_document(option_list: list):
1031
- name = None
1032
- file_path = None
1033
- upload_type = 'multipart'
1018
+ opts = {opt.name: arg for opt, arg in option_list}
1019
+ name = opts.get("name")
1020
+ file_path = opts.get("file_path")
1021
+ upload_type = opts.get("upload_type", 'multipart')
1022
+ content_type = opts.get("content_type")
1023
+
1034
1024
  metadata = {}
1035
- content_type = None
1036
- for option_flag, option_arg in option_list:
1037
- if option_flag.name == "name":
1038
- name = option_arg
1039
- if option_flag.name == "file_path":
1040
- file_path = option_arg
1041
- if option_flag.name == "upload_type":
1042
- upload_type = option_arg
1043
- if option_flag.name == "metadata":
1044
- metadata_str = str(option_arg)
1045
- if not Path(metadata_str).is_file():
1046
- try:
1047
- metadata = json.loads(metadata_str)
1048
- except Exception as e:
1049
- raise WrongArgumentError(f"Metadata should be either a valid dictionary or a file path.")
1050
- else:
1051
- metadata = metadata_str
1052
- if option_flag.name == "content_type":
1053
- content_type = option_arg
1025
+ metadata_arg = opts.get("metadata")
1026
+ if metadata_arg:
1027
+ metadata_str = str(metadata_arg)
1028
+ if not Path(metadata_str).is_file():
1029
+ try:
1030
+ metadata = json.loads(metadata_str)
1031
+ except Exception:
1032
+ raise WrongArgumentError("Metadata should be either a valid dictionary or a file path.")
1033
+ else:
1034
+ metadata = metadata_str
1054
1035
 
1055
1036
  if not (name and file_path):
1056
1037
  raise MissingRequirementException("Cannot upload document without assistant name and file name")
@@ -1102,13 +1083,9 @@ upload_document_options = [
1102
1083
 
1103
1084
 
1104
1085
  def delete_document(option_list: list):
1105
- name = None
1106
- document_id = None
1107
- for option_flag, option_arg in option_list:
1108
- if option_flag.name == "name":
1109
- name = option_arg
1110
- if option_flag.name == "document_id":
1111
- document_id = option_arg
1086
+ opts = {opt.name: arg for opt, arg in option_list}
1087
+ name = opts.get("name")
1088
+ document_id = opts.get("document_id")
1112
1089
 
1113
1090
  if not (name and document_id):
1114
1091
  raise MissingRequirementException("Cannot delete document without assistant name and id")
@@ -16,32 +16,28 @@ def show_help():
16
16
 
17
17
 
18
18
  def rerank_chunks(option_list: list):
19
- query = None
20
- model = None
19
+ opts = {opt.name: arg for opt, arg in option_list}
20
+ query = opts.get('query')
21
+ model = opts.get('model')
22
+ top_n = opts.get('top_n', 3)
23
+ documents_arg = opts.get('documents')
24
+
21
25
  documents = []
22
- top_n = 3
23
- for option_flag, option_arg in option_list:
24
- if option_flag.name == "query":
25
- query = option_arg
26
- if option_flag.name == "model":
27
- model = option_arg
28
- if option_flag.name == "documents":
29
- if "[" not in option_arg:
30
- documents.append(option_arg)
31
- else:
32
- try:
33
- documents_json = json.loads(option_arg)
34
- if not isinstance(documents_json, list):
35
- raise ValueError
26
+ if documents_arg:
27
+ if "[" not in documents_arg:
28
+ documents.append(documents_arg)
29
+ else:
30
+ try:
31
+ documents_json = json.loads(documents_arg)
32
+ if not isinstance(documents_json, list):
33
+ raise ValueError
36
34
 
37
- documents = documents_json
38
- except Exception as e:
39
- raise WrongArgumentError(
40
- "Documents must be a list of strings: '[\"text_chunk_1\", \"text_chunk_2\"]'. "
41
- "Each element in the list must be a string representing a text chunk.."
42
- )
43
- if option_flag.name == "top_n":
44
- top_n = option_arg
35
+ documents = documents_json
36
+ except Exception:
37
+ raise WrongArgumentError(
38
+ "Documents must be a list of strings: '[\\\"text_chunk_1\\\", \\\"text_chunk_2\\\"]'. "
39
+ "Each element in the list must be a string representing a text chunk.."
40
+ )
45
41
 
46
42
  if not (model and query and documents):
47
43
  raise MissingRequirementException("Cannot rerank chunks without model, query and documents")
@@ -53,7 +49,7 @@ def rerank_chunks(option_list: list):
53
49
  documents=documents,
54
50
  top_n=top_n
55
51
  )
56
- Console.write_stdout(f"Rerank details: \n{result}")
52
+ Console.write_stdout(f"Rerank details: \\n{result}")
57
53
 
58
54
 
59
55
  rerank_chunks_options = [
@@ -20,11 +20,8 @@ def get_secret(option_list: list):
20
20
  """
21
21
  Retrieves a secret by its ID.
22
22
  """
23
- secret_id = None
24
-
25
- for option_flag, option_arg in option_list:
26
- if option_flag.name == "secret_id":
27
- secret_id = option_arg
23
+ opts = {opt.name: arg for opt, arg in option_list}
24
+ secret_id = opts.get("secret_id")
28
25
 
29
26
  if not secret_id:
30
27
  raise MissingRequirementException("Cannot retrieve secret without specifying secret-id")
@@ -48,17 +45,10 @@ def create_secret(option_list: list):
48
45
  """
49
46
  Creates a new secret with the specified details.
50
47
  """
51
- name = None
52
- secret_string = None
53
- description = None
54
-
55
- for option_flag, option_arg in option_list:
56
- if option_flag.name == "name":
57
- name = option_arg
58
- elif option_flag.name == "secret_string":
59
- secret_string = option_arg
60
- elif option_flag.name == "description":
61
- description = option_arg
48
+ opts = {opt.name: arg for opt, arg in option_list}
49
+ name = opts.get("name")
50
+ secret_string = opts.get("secret_string")
51
+ description = opts.get("description")
62
52
 
63
53
  if not (name and secret_string):
64
54
  raise MissingRequirementException("Cannot create secret without specifying name and secret-string")
@@ -98,20 +88,11 @@ def update_secret(option_list: list):
98
88
  """
99
89
  Updates an existing secret by its ID.
100
90
  """
101
- secret_id = None
102
- name = None
103
- secret_string = None
104
- description = None
105
-
106
- for option_flag, option_arg in option_list:
107
- if option_flag.name == "secret_id":
108
- secret_id = option_arg
109
- elif option_flag.name == "name":
110
- name = option_arg
111
- elif option_flag.name == "secret_string":
112
- secret_string = option_arg
113
- elif option_flag.name == "description":
114
- description = option_arg
91
+ opts = {opt.name: arg for opt, arg in option_list}
92
+ secret_id = opts.get("secret_id")
93
+ name = opts.get("name")
94
+ secret_string = opts.get("secret_string")
95
+ description = opts.get("description")
115
96
 
116
97
  if not (secret_id and name and secret_string):
117
98
  raise MissingRequirementException("Cannot update secret without specifying secret-id, name, and secret-string")
@@ -158,26 +139,21 @@ def list_secrets(option_list: list):
158
139
  """
159
140
  Lists secrets with optional filtering and pagination.
160
141
  """
161
- name = None
162
- id = None
163
- start = 0
164
- count = 10
165
-
166
- for option_flag, option_arg in option_list:
167
- if option_flag.name == "name":
168
- name = option_arg
169
- elif option_flag.name == "id":
170
- id = option_arg
171
- elif option_flag.name == "start":
172
- try:
173
- start = int(option_arg) if option_arg else 0
174
- except ValueError:
175
- raise WrongArgumentError("start must be an integer")
176
- elif option_flag.name == "count":
177
- try:
178
- count = int(option_arg) if option_arg else 10
179
- except ValueError:
180
- raise WrongArgumentError("count must be an integer")
142
+ opts = {opt.name: arg for opt, arg in option_list}
143
+ name = opts.get("name")
144
+ id = opts.get("id")
145
+ start_arg = opts.get("start")
146
+ count_arg = opts.get("count")
147
+
148
+ try:
149
+ start = int(start_arg) if start_arg else 0
150
+ except ValueError:
151
+ raise WrongArgumentError("start must be an integer")
152
+
153
+ try:
154
+ count = int(count_arg) if count_arg else 10
155
+ except ValueError:
156
+ raise WrongArgumentError("count must be an integer")
181
157
 
182
158
  client = SecretClient()
183
159
  result = client.list_secrets(
@@ -221,19 +197,18 @@ def set_secret_accesses(option_list: list):
221
197
  """
222
198
  Sets access configurations for a secret by its ID.
223
199
  """
224
- secret_id = None
200
+ opts = {opt.name: arg for opt, arg in option_list}
201
+ secret_id = opts.get("secret_id")
202
+ access_list_arg = opts.get("access_list")
203
+
225
204
  access_list = None
226
-
227
- for option_flag, option_arg in option_list:
228
- if option_flag.name == "secret_id":
229
- secret_id = option_arg
230
- elif option_flag.name == "access_list":
231
- try:
232
- access_list = json.loads(option_arg) if option_arg else None
233
- if not isinstance(access_list, list):
234
- raise WrongArgumentError("access-list must be a JSON array")
235
- except json.JSONDecodeError:
236
- raise WrongArgumentError("access-list must be a valid JSON array")
205
+ if access_list_arg:
206
+ try:
207
+ access_list = json.loads(access_list_arg)
208
+ if not isinstance(access_list, list):
209
+ raise WrongArgumentError("access-list must be a JSON array")
210
+ except json.JSONDecodeError:
211
+ raise WrongArgumentError("access-list must be a valid JSON array")
237
212
 
238
213
  if not (secret_id and access_list):
239
214
  raise MissingRequirementException("Cannot set secret accesses without specifying secret-id and access-list")
@@ -266,11 +241,8 @@ def get_secret_accesses(option_list: list):
266
241
  """
267
242
  Retrieves access configurations for a secret by its ID.
268
243
  """
269
- secret_id = None
270
-
271
- for option_flag, option_arg in option_list:
272
- if option_flag.name == "secret_id":
273
- secret_id = option_arg
244
+ opts = {opt.name: arg for opt, arg in option_list}
245
+ secret_id = opts.get("secret_id")
274
246
 
275
247
  if not secret_id:
276
248
  raise MissingRequirementException("Cannot retrieve secret accesses without specifying secret-id")
@@ -18,28 +18,15 @@ def show_help():
18
18
 
19
19
 
20
20
  def set_organization_usage_limit(option_list: list):
21
- organization = None
22
- subscription_type = None
23
- usage_unit = None
24
- soft_limit = None
25
- hard_limit = None
26
- renewal_status = None
21
+ opts = {opt.name: arg for opt, arg in option_list}
22
+ organization = opts.get("organization")
23
+ subscription_type = opts.get("subscription_type")
24
+ usage_unit = opts.get("usage_unit")
25
+ soft_limit = opts.get("soft_limit")
26
+ hard_limit = opts.get("hard_limit")
27
+ renewal_status = opts.get("renewal_status")
28
+
27
29
  usage_limit = {}
28
-
29
- for option_flag, option_arg in option_list:
30
- if option_flag.name == "organization":
31
- organization = option_arg
32
- if option_flag.name == "subscription_type":
33
- subscription_type = option_arg
34
- if option_flag.name == "usage_unit":
35
- usage_unit = option_arg
36
- if option_flag.name == "soft_limit":
37
- soft_limit = option_arg
38
- if option_flag.name == "hard_limit":
39
- hard_limit = option_arg
40
- if option_flag.name == "renewal_status":
41
- renewal_status = option_arg
42
-
43
30
  if subscription_type or usage_unit or soft_limit or hard_limit or renewal_status:
44
31
  usage_limit.update({
45
32
  "subscriptionType": subscription_type,
@@ -71,11 +58,8 @@ set_organization_usage_limit_options = [
71
58
 
72
59
 
73
60
  def get_organization_latest_usage_limit(option_list: list):
74
- organization = None
75
-
76
- for option_flag, option_arg in option_list:
77
- if option_flag.name == "organization":
78
- organization = option_arg
61
+ opts = {opt.name: arg for opt, arg in option_list}
62
+ organization = opts.get("organization")
79
63
 
80
64
  if not organization:
81
65
  raise MissingRequirementException("Cannot get latest usage limit for organization without organization ID")
@@ -93,11 +77,8 @@ get_organization_latest_usage_limit_options = [
93
77
 
94
78
 
95
79
  def get_all_usage_limits_from_organization(option_list: list):
96
- organization = None
97
-
98
- for option_flag, option_arg in option_list:
99
- if option_flag.name == "organization":
100
- organization = option_arg
80
+ opts = {opt.name: arg for opt, arg in option_list}
81
+ organization = opts.get("organization")
101
82
 
102
83
  if not organization:
103
84
  raise MissingRequirementException("Cannot get all usage limits for organization without organization ID")
@@ -115,14 +96,9 @@ get_all_usage_limits_from_organization_options = [
115
96
 
116
97
 
117
98
  def delete_usage_limit_from_organization(option_list: list):
118
- organization = None
119
- limit_id = None
120
-
121
- for option_flag, option_arg in option_list:
122
- if option_flag.name == "organization":
123
- organization = option_arg
124
- if option_flag.name == "limit_id":
125
- limit_id = option_arg
99
+ opts = {opt.name: arg for opt, arg in option_list}
100
+ organization = opts.get("organization")
101
+ limit_id = opts.get("limit_id")
126
102
 
127
103
  if not (organization and limit_id):
128
104
  raise MissingRequirementException("Cannot delete usage limit for organization without organization ID and limit ID")
@@ -142,23 +118,12 @@ delete_usage_limit_from_organization_options = [
142
118
 
143
119
 
144
120
  def update_organization_usage_limit(option_list: list):
145
- organization = None
146
- limit_id = None
147
- hard_limit = None
148
- soft_limit = None
149
- renewal_status = None
150
-
151
- for option_flag, option_arg in option_list:
152
- if option_flag.name == "organization":
153
- organization = option_arg
154
- if option_flag.name == "limit_id":
155
- limit_id = option_arg
156
- if option_flag.name == "hard_limit":
157
- hard_limit = option_arg
158
- if option_flag.name == "soft_limit":
159
- soft_limit = option_arg
160
- if option_flag.name == "renewal_status":
161
- renewal_status = option_arg
121
+ opts = {opt.name: arg for opt, arg in option_list}
122
+ organization = opts.get("organization")
123
+ limit_id = opts.get("limit_id")
124
+ hard_limit = opts.get("hard_limit")
125
+ soft_limit = opts.get("soft_limit")
126
+ renewal_status = opts.get("renewal_status")
162
127
 
163
128
  if not (organization and limit_id):
164
129
  raise MissingRequirementException("Cannot update usage limit for organization without organization ID and limit ID")
@@ -217,32 +182,16 @@ def set_organization_renewal_status(organization, limit_id, renewal_status):
217
182
 
218
183
 
219
184
  def set_project_usage_limit(option_list: list):
220
- organization = None
221
- project = None
222
- subscription_type = None
223
- usage_unit = None
224
- soft_limit = None
225
- hard_limit = None
226
- renewal_status = None
185
+ opts = {opt.name: arg for opt, arg in option_list}
186
+ organization = opts.get("organization")
187
+ project = opts.get("project")
188
+ subscription_type = opts.get("subscription_type")
189
+ usage_unit = opts.get("usage_unit")
190
+ soft_limit = opts.get("soft_limit")
191
+ hard_limit = opts.get("hard_limit")
192
+ renewal_status = opts.get("renewal_status")
193
+
227
194
  usage_limit = {}
228
-
229
- for option_flag, option_arg in option_list:
230
- if option_flag.name == "organization":
231
- organization = option_arg
232
- if option_flag.name == "project":
233
- project = option_arg
234
-
235
- if option_flag.name == "subscription_type":
236
- subscription_type = option_arg
237
- if option_flag.name == "usage_unit":
238
- usage_unit = option_arg
239
- if option_flag.name == "soft_limit":
240
- soft_limit = option_arg
241
- if option_flag.name == "hard_limit":
242
- hard_limit = option_arg
243
- if option_flag.name == "renewal_status":
244
- renewal_status = option_arg
245
-
246
195
  if subscription_type or usage_unit or soft_limit or hard_limit or renewal_status:
247
196
  usage_limit.update({
248
197
  "subscriptionType": subscription_type,
@@ -276,14 +225,9 @@ set_project_usage_limit_options = [
276
225
 
277
226
 
278
227
  def get_all_usage_limits_from_project(option_list: list):
279
- organization = None
280
- project = None
281
-
282
- for option_flag, option_arg in option_list:
283
- if option_flag.name == "organization":
284
- organization = option_arg
285
- if option_flag.name == "project":
286
- project = option_arg
228
+ opts = {opt.name: arg for opt, arg in option_list}
229
+ organization = opts.get("organization")
230
+ project = opts.get("project")
287
231
 
288
232
  if not (organization and project):
289
233
  raise MissingRequirementException("Cannot get usage limits for project without organization and project ID")
@@ -303,14 +247,9 @@ get_all_usage_limits_from_project_options = [
303
247
 
304
248
 
305
249
  def get_latest_usage_limit_from_project(option_list: list):
306
- organization = None
307
- project = None
308
-
309
- for option_flag, option_arg in option_list:
310
- if option_flag.name == "organization":
311
- organization = option_arg
312
- if option_flag.name == "project":
313
- project = option_arg
250
+ opts = {opt.name: arg for opt, arg in option_list}
251
+ organization = opts.get("organization")
252
+ project = opts.get("project")
314
253
 
315
254
  if not (organization and project):
316
255
  raise MissingRequirementException("Cannot get latest usage limit for project without organization and project ID")
@@ -330,14 +269,9 @@ get_latest_usage_limit_from_project_options = [
330
269
 
331
270
 
332
271
  def get_active_usage_limit_from_project(option_list: list):
333
- organization = None
334
- project = None
335
-
336
- for option_flag, option_arg in option_list:
337
- if option_flag.name == "organization":
338
- organization = option_arg
339
- if option_flag.name == "project":
340
- project = option_arg
272
+ opts = {opt.name: arg for opt, arg in option_list}
273
+ organization = opts.get("organization")
274
+ project = opts.get("project")
341
275
 
342
276
  if not (organization and project):
343
277
  raise MissingRequirementException("Cannot get active usage limit for project without organization and project ID")
@@ -357,17 +291,10 @@ get_active_usage_limit_from_project_options = [
357
291
 
358
292
 
359
293
  def delete_usage_limit_from_project(option_list: list):
360
- organization = None
361
- project = None
362
- limit_id = None
363
-
364
- for option_flag, option_arg in option_list:
365
- if option_flag.name == "organization":
366
- organization = option_arg
367
- if option_flag.name == "project":
368
- project = option_arg
369
- if option_flag.name == "limit_id":
370
- limit_id = option_arg
294
+ opts = {opt.name: arg for opt, arg in option_list}
295
+ organization = opts.get("organization")
296
+ project = opts.get("project")
297
+ limit_id = opts.get("limit_id")
371
298
 
372
299
  if not (organization and project and limit_id):
373
300
  raise MissingRequirementException("Cannot delete usage limit for project without organization, project and limit ID")
@@ -389,26 +316,13 @@ delete_usage_limit_from_project_options = [
389
316
 
390
317
 
391
318
  def update_project_usage_limit(option_list: list):
392
- organization = None
393
- project = None
394
- limit_id = None
395
- hard_limit = None
396
- soft_limit = None
397
- renewal_status = None
398
-
399
- for option_flag, option_arg in option_list:
400
- if option_flag.name == "organization":
401
- organization = option_arg
402
- if option_flag.name == "project":
403
- project = option_arg
404
- if option_flag.name == "limit_id":
405
- limit_id = option_arg
406
- if option_flag.name == "hard_limit":
407
- hard_limit = option_arg
408
- if option_flag.name == "soft_limit":
409
- soft_limit = option_arg
410
- if option_flag.name == "renewal_status":
411
- renewal_status = option_arg
319
+ opts = {opt.name: arg for opt, arg in option_list}
320
+ organization = opts.get("organization")
321
+ project = opts.get("project")
322
+ limit_id = opts.get("limit_id")
323
+ hard_limit = opts.get("hard_limit")
324
+ soft_limit = opts.get("soft_limit")
325
+ renewal_status = opts.get("renewal_status")
412
326
 
413
327
  if not (organization and project and limit_id):
414
328
  raise MissingRequirementException("Cannot update usage limit for project without organization ID, project ID and limit ID")
@@ -1,5 +1,5 @@
1
1
  from pathlib import Path
2
- from typing import Any, Dict, List, Optional, Union
2
+ from typing import Dict, List, Optional, Union
3
3
  import json
4
4
 
5
5
  from pygeai.core.common.exceptions import WrongArgumentError, ValidationError