|
801 | 801 | region IN VARCHAR2 |
802 | 802 | ) RETURN CLOB; |
803 | 803 |
|
| 804 | + -- Helper: gets the list of compartments using configured credentials |
| 805 | + FUNCTION list_compartments |
| 806 | + RETURN CLOB; |
| 807 | + |
804 | 808 |
|
805 | 809 | END oci_object_storage_agents; |
806 | 810 | / |
|
930 | 934 | RETURN l_result_json.to_clob(); |
931 | 935 | END list_compartments; |
932 | 936 |
|
| 937 | + -- Helper: gets the list of compartments using configured credentials |
| 938 | + FUNCTION list_compartments |
| 939 | + RETURN CLOB |
| 940 | + IS |
| 941 | + l_result_json JSON_OBJECT_T := JSON_OBJECT_T(); |
| 942 | + l_current_user VARCHAR2(128) := SYS_CONTEXT('USERENV', 'CURRENT_USER'); |
| 943 | + l_cfg_json CLOB; |
| 944 | + l_cfg JSON_OBJECT_T; |
| 945 | + l_params JSON_OBJECT_T; |
| 946 | + l_credential_name VARCHAR2(256); |
| 947 | + BEGIN |
| 948 | + l_cfg_json := get_agent_config( |
| 949 | + l_current_user, |
| 950 | + 'SELECTAI_AGENT_CONFIG', |
| 951 | + 'OCI_OBJECT_STORAGE' |
| 952 | + ); |
| 953 | + l_cfg := JSON_OBJECT_T.parse(l_cfg_json); |
| 954 | + |
| 955 | + IF l_cfg.get_string('status') = 'success' THEN |
| 956 | + l_params := l_cfg.get_object('config_params'); |
| 957 | + l_credential_name := l_params.get_string('CREDENTIAL_NAME'); |
| 958 | + END IF; |
| 959 | + |
| 960 | + IF l_credential_name IS NULL OR TRIM(l_credential_name) IS NULL THEN |
| 961 | + l_result_json.put('status', 'error'); |
| 962 | + l_result_json.put('message', 'Credential name is not configured. Set CREDENTIAL_NAME in SELECTAI_AGENT_CONFIG before calling this tool.'); |
| 963 | + RETURN l_result_json.to_clob(); |
| 964 | + END IF; |
| 965 | + |
| 966 | + RETURN list_compartments(credential_name => l_credential_name); |
| 967 | + |
| 968 | + EXCEPTION |
| 969 | + WHEN OTHERS THEN |
| 970 | + l_result_json := JSON_OBJECT_T(); |
| 971 | + l_result_json.put('status', 'error'); |
| 972 | + l_result_json.put('message', 'Error: ' || SQLERRM); |
| 973 | + RETURN l_result_json.to_clob(); |
| 974 | + END list_compartments; |
| 975 | + |
933 | 976 | -- Helper: gets the compartment ocid with the given compatment name |
934 | 977 | FUNCTION get_compartment_ocid_by_name( |
935 | 978 | compartment_name IN VARCHAR2 |
@@ -4180,6 +4223,20 @@ IS |
4180 | 4223 | END IF; |
4181 | 4224 | END drop_tool_if_exists; |
4182 | 4225 | BEGIN |
| 4226 | + ------------------------------------------------------------------------ |
| 4227 | + -- AI TOOL: LIST_COMPARTMENTS_TOOL |
| 4228 | + -- maps to oci_object_storage_agents.list_compartments |
| 4229 | + ------------------------------------------------------------------------ |
| 4230 | + drop_tool_if_exists(tool_name => 'LIST_COMPARTMENTS_TOOL'); |
| 4231 | + DBMS_CLOUD_AI_AGENT.CREATE_TOOL( |
| 4232 | + tool_name => 'LIST_COMPARTMENTS_TOOL', |
| 4233 | + attributes => '{ |
| 4234 | + "instruction": "List compartments visible to the configured tenancy and credentials, including OCID and lifecycle metadata.", |
| 4235 | + "function": "oci_object_storage_agents.list_compartments" |
| 4236 | + }', |
| 4237 | + description => 'Tool for listing OCI compartments' |
| 4238 | + ); |
| 4239 | + |
4183 | 4240 | ------------------------------------------------------------------------ |
4184 | 4241 | -- AI TOOL: LIST_OBJECTS_TOOL |
4185 | 4242 | -- maps to oci_object_storage_agents.list_objects |
|
0 commit comments