1111"""
1212# ruff: noqa: D301 - Using regular """ strings (not r""") for Click \b formatting
1313
14+ from typing import Any , Optional
15+
1416import click
1517
1618from .._utils ._service_base import (
2224
2325
2426def _not_found (index_name : str , e : Exception ) -> None :
25- """Re-raise as a clean ClickException when the SDK reports index not found."""
27+ """Raise a clean ClickException for any SDK error from context-grounding commands.
28+
29+ Surfaces "not found" as a structured error; wraps all other exceptions so
30+ raw SDK tracebacks never reach the user.
31+ """
2632 if "not found" in str (e ).lower ():
2733 handle_not_found_error ("Index" , index_name )
2834 raise click .ClickException (str (e )) from e
2935
3036
3137@click .group (name = "context-grounding" )
32- def context_grounding ():
38+ def context_grounding () -> None :
3339 """Manage UiPath Context Grounding indexes and perform semantic search.
3440
3541 Context Grounding indexes documents from storage buckets or cloud drives
@@ -59,10 +65,19 @@ def context_grounding():
5965
6066
6167@context_grounding .command ("retrieve" )
62- @click .option ("--index" , "index_name" , required = True , help = "Name of the index to retrieve." )
68+ @click .option (
69+ "--index" , "index_name" , required = True , help = "Name of the index to retrieve."
70+ )
6371@common_service_options
6472@service_command
65- def retrieve (ctx , index_name , folder_path , folder_key , format , output ):
73+ def retrieve (
74+ ctx : click .Context ,
75+ index_name : str ,
76+ folder_path : Optional [str ],
77+ folder_key : Optional [str ],
78+ format : Optional [str ],
79+ output : Optional [str ],
80+ ) -> Any :
6681 """Retrieve details of a context grounding index by name.
6782
6883 \b
@@ -84,7 +99,9 @@ def retrieve(ctx, index_name, folder_path, folder_key, format, output):
8499
85100@context_grounding .command ("search" )
86101@click .argument ("query" )
87- @click .option ("--index" , "index_name" , required = True , help = "Name of the index to search." )
102+ @click .option (
103+ "--index" , "index_name" , required = True , help = "Name of the index to search."
104+ )
88105@click .option (
89106 "--results" ,
90107 "-n" ,
@@ -96,7 +113,16 @@ def retrieve(ctx, index_name, folder_path, folder_key, format, output):
96113)
97114@common_service_options
98115@service_command
99- def search (ctx , query , index_name , number_of_results , folder_path , folder_key , format , output ):
116+ def search (
117+ ctx : click .Context ,
118+ query : str ,
119+ index_name : str ,
120+ number_of_results : int ,
121+ folder_path : Optional [str ],
122+ folder_key : Optional [str ],
123+ format : Optional [str ],
124+ output : Optional [str ],
125+ ) -> Any :
100126 """Search an index with a natural language query.
101127
102128 QUERY is the natural language search string.
@@ -148,10 +174,19 @@ def search(ctx, query, index_name, number_of_results, folder_path, folder_key, f
148174
149175
150176@context_grounding .command ("ingest" )
151- @click .option ("--index" , "index_name" , required = True , help = "Name of the index to re-ingest." )
177+ @click .option (
178+ "--index" , "index_name" , required = True , help = "Name of the index to re-ingest."
179+ )
152180@common_service_options
153181@service_command
154- def ingest (ctx , index_name , folder_path , folder_key , format , output ):
182+ def ingest (
183+ ctx : click .Context ,
184+ index_name : str ,
185+ folder_path : Optional [str ],
186+ folder_key : Optional [str ],
187+ format : Optional [str ],
188+ output : Optional [str ],
189+ ) -> None :
155190 """Trigger re-ingestion of a context grounding index.
156191
157192 \b
@@ -183,16 +218,28 @@ def ingest(ctx, index_name, folder_path, folder_key, format, output):
183218 ) from e
184219
185220 click .echo (f"Triggered ingestion for index '{ index_name } '." , err = True )
186- return None
187221
188222
189223@context_grounding .command ("delete" )
190- @click .option ("--index" , "index_name" , required = True , help = "Name of the index to delete." )
224+ @click .option (
225+ "--index" , "index_name" , required = True , help = "Name of the index to delete."
226+ )
191227@click .option ("--confirm" , is_flag = True , help = "Skip confirmation prompt." )
192- @click .option ("--dry-run" , is_flag = True , help = "Show what would be deleted without deleting." )
228+ @click .option (
229+ "--dry-run" , is_flag = True , help = "Show what would be deleted without deleting."
230+ )
193231@common_service_options
194232@service_command
195- def delete (ctx , index_name , confirm , dry_run , folder_path , folder_key , format , output ):
233+ def delete (
234+ ctx : click .Context ,
235+ index_name : str ,
236+ confirm : bool ,
237+ dry_run : bool ,
238+ folder_path : Optional [str ],
239+ folder_key : Optional [str ],
240+ format : Optional [str ],
241+ output : Optional [str ],
242+ ) -> None :
196243 """Delete a context grounding index by name.
197244
198245 \b
@@ -213,12 +260,12 @@ def delete(ctx, index_name, confirm, dry_run, folder_path, folder_key, format, o
213260
214261 if dry_run :
215262 click .echo (f"Would delete index '{ index_name } '." , err = True )
216- return None
263+ return
217264
218265 if not confirm :
219266 if not click .confirm (f"Delete index '{ index_name } '?" ):
220267 click .echo ("Deletion cancelled." , err = True )
221- return None
268+ return
222269
223270 client .context_grounding .delete_index (
224271 index = index ,
@@ -227,4 +274,3 @@ def delete(ctx, index_name, confirm, dry_run, folder_path, folder_key, format, o
227274 )
228275
229276 click .echo (f"Deleted index '{ index_name } '." , err = True )
230- return None
0 commit comments