@@ -51,8 +51,7 @@ use anyhow::{anyhow, bail};
5151use colored:: Colorize ;
5252use golem_client:: api:: { AgentTypesClient , ComponentClient , WorkerClient } ;
5353use golem_client:: model:: {
54- AgentType , InvokeParameters as InvokeParametersCloud ,
55- RevertLastInvocations as RevertLastInvocationsCloud ,
54+ InvokeParameters as InvokeParametersCloud , RevertLastInvocations as RevertLastInvocationsCloud ,
5655 RevertToOplogIndex as RevertToOplogIndexCloud , RevertWorkerTarget as RevertWorkerTargetCloud ,
5756 UpdateWorkerRequest as UpdateWorkerRequestCloud ,
5857 WorkerCreationRequest as WorkerCreationRequestCloud ,
@@ -207,8 +206,7 @@ impl WorkerCommandHandler {
207206 )
208207 . await ?;
209208
210- self . validate_worker_and_function_names ( & component, & worker_name_match. worker_name , None )
211- . await ?;
209+ self . validate_worker_and_function_names ( & component, & worker_name_match. worker_name , None ) ?;
212210
213211 log_action (
214212 "Creating" ,
@@ -283,17 +281,19 @@ impl WorkerCommandHandler {
283281 )
284282 . await ?;
285283
286- // First validate without the function name
287- let agent_type = self
288- . validate_worker_and_function_names ( & component, & worker_name_match. worker_name , None )
289- . await ?;
284+ // First, validate without the function name
285+ let agent_id_and_type = self . validate_worker_and_function_names (
286+ & component,
287+ & worker_name_match. worker_name ,
288+ None ,
289+ ) ?;
290290
291291 let matched_function_name = fuzzy_match_function_name (
292292 function_name,
293293 component. metadata . exports ( ) ,
294- agent_type
294+ agent_id_and_type
295295 . as_ref ( )
296- . and_then ( |a| agent_interface_name ( & component, & a . type_name ) )
296+ . and_then ( |a| agent_interface_name ( & component, a . wrapper_agent_type ( ) ) )
297297 . as_deref ( ) ,
298298 ) ;
299299 let function_name = match matched_function_name {
@@ -320,7 +320,7 @@ impl WorkerCommandHandler {
320320 logln ( "" ) ;
321321 log_text_view ( & AvailableFunctionNamesHelp :: new (
322322 & component,
323- agent_type . as_ref ( ) ,
323+ agent_id_and_type . as_ref ( ) ,
324324 ) ) ;
325325
326326 bail ! ( NonSuccessfulExit ) ;
@@ -334,21 +334,32 @@ impl WorkerCommandHandler {
334334 logln ( "" ) ;
335335 log_text_view ( & AvailableFunctionNamesHelp :: new (
336336 & component,
337- agent_type . as_ref ( ) ,
337+ agent_id_and_type . as_ref ( ) ,
338338 ) ) ;
339339
340340 bail ! ( NonSuccessfulExit ) ;
341341 }
342342 } ,
343343 } ;
344344
345- // Re-validate with function name
346- self . validate_worker_and_function_names (
345+ // Re-validate with function- name
346+ let agent_id = self . validate_worker_and_function_names (
347347 & component,
348348 & worker_name_match. worker_name ,
349349 Some ( & function_name) ,
350- )
351- . await ?;
350+ ) ?;
351+
352+ // Update worker_name with normalized agent id if needed
353+ let worker_name_match = {
354+ if let Some ( agent_id) = agent_id {
355+ WorkerNameMatch {
356+ worker_name : agent_id. to_string ( ) . into ( ) ,
357+ ..worker_name_match
358+ }
359+ } else {
360+ worker_name_match
361+ }
362+ } ;
352363
353364 if trigger {
354365 log_action (
@@ -1774,23 +1785,22 @@ impl WorkerCommandHandler {
17741785 }
17751786 }
17761787
1777- pub async fn validate_worker_and_function_names (
1788+ pub fn validate_worker_and_function_names (
17781789 & self ,
17791790 component : & Component ,
17801791 worker_name : & WorkerName ,
17811792 function_name : Option < & str > ,
1782- ) -> anyhow:: Result < Option < AgentType > > {
1793+ ) -> anyhow:: Result < Option < AgentId > > {
17831794 if !component. metadata . is_agent ( ) {
17841795 return Ok ( None ) ;
17851796 }
17861797
1787- match AgentId :: parse_and_resolve_type ( & worker_name. 0 , & component. metadata ) . await {
1788- Ok ( ( agent_id, agent_type ) ) => match function_name {
1798+ match AgentId :: parse ( & worker_name. 0 , & component. metadata ) {
1799+ Ok ( agent_id) => match function_name {
17891800 Some ( function_name) => {
17901801 if let Some ( ( namespace, package, interface) ) = component
17911802 . metadata
17921803 . find_function ( function_name)
1793- . await
17941804 . ok ( )
17951805 . flatten ( )
17961806 . and_then ( |f| match f. name . site {
@@ -1805,10 +1815,10 @@ impl WorkerCommandHandler {
18051815 } )
18061816 {
18071817 let component_name = format ! ( "{namespace}:{package}" ) ;
1808- if interface == agent_type . type_name
1818+ if interface == agent_id . wrapper_agent_type ( )
18091819 && component. component_name . 0 == component_name
18101820 {
1811- return Ok ( Some ( agent_type ) ) ;
1821+ return Ok ( Some ( agent_id ) ) ;
18121822 }
18131823 }
18141824
@@ -1819,14 +1829,11 @@ impl WorkerCommandHandler {
18191829 function_name. log_color_error_highlight( )
18201830 ) ) ;
18211831 logln ( "" ) ;
1822- log_text_view ( & AvailableFunctionNamesHelp :: new (
1823- component,
1824- Some ( & agent_type) ,
1825- ) ) ;
1832+ log_text_view ( & AvailableFunctionNamesHelp :: new ( component, Some ( & agent_id) ) ) ;
18261833 bail ! ( NonSuccessfulExit ) ;
18271834 }
18281835
1829- None => Ok ( Some ( agent_type ) ) ,
1836+ None => Ok ( Some ( agent_id ) ) ,
18301837 } ,
18311838 Err ( err) => {
18321839 logln ( "" ) ;
0 commit comments