Skip to content

Commit f7c8e87

Browse files
authored
Reworked native and WIT cased naming for agent types and AgentID normalization (#2155)
* version: only match "v*" for git versions (so golem-rust and other release tags are not considered), and use fallback * rework "bridging" between native and WIT cased names * AgentID WAVE normalization * WIP: use "native" types for RIB scripts, and "wit" types for instance creation * Revert "WIP: use "native" types for RIB scripts, and "wit" types for instance creation" This reverts commit adf84d8. * rename wit arg types * use WIT cased types for RIB everywhere * cleanup and extend CLI test for complex agent names * make fix * make fix * add agent types to component metadata * use to_wit_naming instead of kebab in generators * cleanup of AgentType naming * more cleanups * make fix * fix invoke worker name * clippy * update golem ts agentic deps
1 parent 8cd05d6 commit f7c8e87

File tree

31 files changed

+936
-237
lines changed

31 files changed

+936
-237
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/golem-cli/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn append_write_git_describe_tags_hook(file: &File) -> SdResult<()> {
5656

5757
fn append_write_git_describe_tags(mut file: &File) -> SdResult<()> {
5858
let output = Command::new("git")
59-
.args(["describe", "--tags", "--always"])
59+
.args(["describe", "--tags", "--match", "v*", "--always"])
6060
.output()?;
6161

6262
let version = {

cli/golem-cli/src/command_handler/partial_match.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,18 @@ impl ErrorHandler {
172172
)
173173
.await
174174
{
175-
let agent_type = self
175+
let agent_id = self
176176
.ctx
177177
.worker_handler()
178178
.validate_worker_and_function_names(
179179
&component,
180180
&worker_name_match.worker_name,
181181
None,
182-
)
183-
.await?;
182+
)?;
184183

185184
log_text_view(&AvailableFunctionNamesHelp::new(
186185
&component,
187-
agent_type.as_ref(),
186+
agent_id.as_ref(),
188187
));
189188
logln("");
190189
}

cli/golem-cli/src/command_handler/rib_repl.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use crate::command::shared_args::{DeployArgs, StreamArgs};
1616
use crate::command_handler::Handlers;
17-
use crate::context::Context;
17+
use crate::context::{Context, RibReplState};
1818
use crate::error::NonSuccessfulExit;
1919
use crate::fs;
2020
use crate::log::{logln, set_log_output, Output};
@@ -25,9 +25,10 @@ use crate::model::{
2525
ComponentName, ComponentNameMatchKind, ComponentVersionSelection, Format, IdempotencyKey,
2626
WorkerName,
2727
};
28-
use anyhow::bail;
28+
use anyhow::{anyhow, bail};
2929
use async_trait::async_trait;
3030
use colored::Colorize;
31+
use golem_common::model::agent::AgentId;
3132
use golem_rib_repl::{
3233
Command, CommandRegistry, ReplComponentDependencies, ReplContext, RibDependencyManager,
3334
RibRepl, RibReplConfig, WorkerFunctionInvoke,
@@ -122,23 +123,26 @@ impl RibReplHandler {
122123
.iter()
123124
.map(|agent_type| {
124125
rib::CustomInstanceSpec::new(
125-
agent_type.type_name.to_string(),
126+
agent_type.wrapper_type_name(),
126127
agent_type.constructor.wit_arg_types(),
127128
Some(rib::InterfaceName {
128-
name: agent_type.type_name.to_string(),
129+
name: agent_type.wrapper_type_name(),
129130
version: None,
130131
}),
131132
)
132133
})
133134
.collect::<Vec<_>>();
134135

135136
self.ctx
136-
.set_rib_repl_dependencies(ReplComponentDependencies {
137-
component_dependencies: vec![ComponentDependency::new(
138-
component_dependency_key,
139-
component.metadata.exports().to_vec(),
140-
)],
141-
custom_instance_spec,
137+
.set_rib_repl_state(RibReplState {
138+
dependencies: ReplComponentDependencies {
139+
component_dependencies: vec![ComponentDependency::new(
140+
component_dependency_key,
141+
component.metadata.exports().to_vec(),
142+
)],
143+
custom_instance_spec,
144+
},
145+
component_metadata: component.metadata.clone(),
142146
})
143147
.await;
144148

@@ -305,17 +309,21 @@ impl WorkerFunctionInvoke for RibReplHandler {
305309
args: Vec<ValueAndType>,
306310
_return_type: Option<AnalysedType>,
307311
) -> anyhow::Result<Option<ValueAndType>> {
308-
let worker_name = WorkerName::from(worker_name);
312+
let worker_name: WorkerName = AgentId::parse(
313+
worker_name,
314+
&self.ctx.get_rib_repl_component_metadata().await,
315+
)
316+
.map_err(|err| anyhow!(err))?
317+
.to_string()
318+
.into();
309319

310320
let component = self
311321
.ctx
312322
.component_handler()
313323
.component(
314324
None,
315325
component_id.into(),
316-
Some(ComponentVersionSelection::ByWorkerName(&WorkerName(
317-
worker_name.to_string(),
318-
))),
326+
Some(ComponentVersionSelection::ByWorkerName(&worker_name)),
319327
)
320328
.await?;
321329

cli/golem-cli/src/command_handler/worker/mod.rs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ use anyhow::{anyhow, bail};
5151
use colored::Colorize;
5252
use golem_client::api::{AgentTypesClient, ComponentClient, WorkerClient};
5353
use 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("");

cli/golem-cli/src/context.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use golem_client::api::WorkerClientLive as WorkerClientCloud;
5050
use golem_client::api::{AccountClient, AccountSummaryClientLive as AccountSummaryClientCloud};
5151
use golem_client::api::{AccountClientLive as AccountClientCloud, LoginClientLive};
5252
use golem_client::{Context as ContextCloud, Security};
53+
use golem_common::model::component_metadata::ComponentMetadata;
5354
use golem_rib_repl::ReplComponentDependencies;
5455
use golem_templates::model::{ComposableAppGroupName, GuestLanguage};
5556
use golem_templates::ComposableAppTemplate;
@@ -468,9 +469,9 @@ impl Context {
468469
Ok(app_ctx.application.task_result_marker_dir())
469470
}
470471

471-
pub async fn set_rib_repl_dependencies(&self, dependencies: ReplComponentDependencies) {
472+
pub async fn set_rib_repl_state(&self, state: RibReplState) {
472473
let mut rib_repl_state = self.rib_repl_state.write().await;
473-
rib_repl_state.dependencies = dependencies;
474+
*rib_repl_state = state;
474475
}
475476

476477
pub async fn get_rib_repl_dependencies(&self) -> ReplComponentDependencies {
@@ -481,6 +482,11 @@ impl Context {
481482
}
482483
}
483484

485+
pub async fn get_rib_repl_component_metadata(&self) -> ComponentMetadata {
486+
let rib_repl_state = self.rib_repl_state.read().await;
487+
rib_repl_state.component_metadata.clone()
488+
}
489+
484490
pub fn templates(
485491
&self,
486492
dev_mode: bool,
@@ -861,7 +867,8 @@ impl ApplicationContextState {
861867
}
862868

863869
pub struct RibReplState {
864-
dependencies: ReplComponentDependencies,
870+
pub dependencies: ReplComponentDependencies,
871+
pub component_metadata: ComponentMetadata,
865872
}
866873

867874
impl Default for RibReplState {
@@ -871,6 +878,7 @@ impl Default for RibReplState {
871878
component_dependencies: vec![],
872879
custom_instance_spec: vec![],
873880
},
881+
component_metadata: ComponentMetadata::default(),
874882
}
875883
}
876884
}

cli/golem-cli/src/model/agent/moonbit.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ use crate::model::agent::wit::AgentWrapperGeneratorContext;
1616
use anyhow::{anyhow, Context};
1717
use camino::Utf8Path;
1818
use golem_client::model::AnalysedType;
19+
use golem_common::model::agent::wit_naming::ToWitNaming;
1920
use golem_common::model::agent::{AgentType, DataSchema, ElementSchema, NamedElementSchemas};
20-
use heck::{ToKebabCase, ToLowerCamelCase, ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase};
21+
use heck::{ToLowerCamelCase, ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase};
2122
use moonbit_component_generator::{
2223
to_moonbit_ident, MoonBitComponent, MoonBitPackage, Warning, WarningControl,
2324
};
@@ -846,7 +847,7 @@ fn build_data_value(
846847
for named_element_schema in elements {
847848
let case_name = named_element_schema
848849
.name
849-
.to_kebab_case()
850+
.to_wit_naming()
850851
.to_upper_camel_case();
851852
writeln!(
852853
result,
@@ -894,7 +895,7 @@ fn write_builder(
894895
writeln!(result, "{indent} match {access} {{")?;
895896

896897
for (case_idx, case) in variant.cases.iter().enumerate() {
897-
let case_name = case.name.to_kebab_case().to_upper_camel_case();
898+
let case_name = case.name.to_wit_naming().to_upper_camel_case();
898899
match &case.typ {
899900
Some(_) => {
900901
writeln!(
@@ -915,7 +916,7 @@ fn write_builder(
915916
writeln!(result, "{indent} match {access} {{")?;
916917

917918
for case in &variant.cases {
918-
let case_name = case.name.to_kebab_case().to_upper_camel_case();
919+
let case_name = case.name.to_wit_naming().to_upper_camel_case();
919920
match &case.typ {
920921
Some(_) => {
921922
writeln!(
@@ -1202,7 +1203,7 @@ fn extract_data_value(
12021203
writeln!(result, "{indent}values.map(pair => {{")?;
12031204
writeln!(result, "{indent} match pair.0 {{")?;
12041205
for element in elements {
1205-
let case_name = element.name.to_kebab_case().to_upper_camel_case();
1206+
let case_name = element.name.to_wit_naming().to_upper_camel_case();
12061207
writeln!(result, "{indent} \"{}\" => {{", element.name)?;
12071208
match &element.schema {
12081209
ElementSchema::ComponentModel(schema) => {
@@ -1279,7 +1280,7 @@ fn extract_wit_value(
12791280
writeln!(result, "{indent} match idx {{")?;
12801281

12811282
for (idx, case) in variant.cases.iter().enumerate() {
1282-
let case_name = case.name.to_kebab_case().to_upper_camel_case();
1283+
let case_name = case.name.to_wit_naming().to_upper_camel_case();
12831284

12841285
writeln!(result, "{indent} {idx} => {{")?;
12851286
if let Some(inner_type) = &case.typ {

0 commit comments

Comments
 (0)