Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
382 changes: 193 additions & 189 deletions cli/golem-cli/src/command.rs

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions cli/golem-cli/src/command_handler/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::log::{
logged_failed_to, logged_finished_or_failed_to, logln,
};
use crate::model::GuestLanguage;
use crate::model::agent::view::AgentTypeView;
use crate::model::app::{
AppBuildStep, ApplicationComponentSelectMode, BuildConfig, CleanMode, DynamicHelpSections,
};
Expand All @@ -59,6 +60,7 @@ use futures_util::{StreamExt, TryStreamExt, stream};
use golem_client::api::{ApplicationClient, ComponentClient, EnvironmentClient};
use golem_client::model::{ApplicationCreation, DeploymentCreation, DeploymentRollback};
use golem_common::model::account::AccountId;
use golem_common::model::agent::AgentTypeName;
use golem_common::model::agent::DeployedRegisteredAgentType;
use golem_common::model::agent::schema_evolution::validate_schema_evolution;
use golem_common::model::application::ApplicationName;
Expand Down Expand Up @@ -414,6 +416,31 @@ impl AppCommandHandler {
Ok(())
}

pub async fn cmd_get_agent_type(&self, agent_type_name: AgentTypeName) -> anyhow::Result<()> {
let environment = self
.ctx
.environment_handler()
.resolve_environment(EnvironmentResolveMode::Any)
.await?;

let Some(agent_type) = self
.get_agent_type_by_name(&environment, agent_type_name.0.as_str())
.await?
else {
log_error(format!(
"Agent type {} not found",
agent_type_name.0.log_color_highlight()
));
bail!(NonSuccessfulExit);
};

self.ctx
.log_handler()
.log_view(&AgentTypeView::new(&agent_type, true));

Ok(())
}

pub async fn list_agent_types(
&self,
environment: &ResolvedEnvironmentIdentity,
Expand Down
15 changes: 12 additions & 3 deletions cli/golem-cli/src/command_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use self::agent_secret::AgentSecretCommandHandler;
use self::resource_definition::ResourceDefinitionCommandHandler;
use self::retry_policy::RetryPolicyCommandHandler;
use crate::command::agent_type::AgentTypeSubcommand;
#[cfg(feature = "server-commands")]
use crate::command::server::ServerSubcommand;
use crate::command::{
Expand Down Expand Up @@ -364,9 +365,6 @@ impl<Hooks: CommandHandlerHooks + 'static> CommandHandler<Hooks> {
.cmd_redeploy_workers(component_name.component_name)
.await
}
GolemCliSubcommand::ListAgentTypes {} => {
self.ctx.app_handler().cmd_list_agent_types().await
}
GolemCliSubcommand::Exec { subcommand } => {
self.ctx.app_handler().exec_custom_command(subcommand).await
}
Expand All @@ -387,6 +385,17 @@ impl<Hooks: CommandHandlerHooks + 'static> CommandHandler<Hooks> {
GolemCliSubcommand::Agent { subcommand } => {
self.ctx.worker_handler().handle_command(subcommand).await
}
GolemCliSubcommand::AgentType { subcommand } => match subcommand {
AgentTypeSubcommand::List => {
self.ctx.app_handler().cmd_list_agent_types().await
}
AgentTypeSubcommand::Get { agent_type_name } => {
self.ctx
.app_handler()
.cmd_get_agent_type(agent_type_name)
.await
}
},
GolemCliSubcommand::Api { subcommand } => {
self.ctx.api_handler().handle_command(subcommand).await
}
Expand Down
6 changes: 3 additions & 3 deletions cli/golem-cli/src/command_handler/partial_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::model::app::{ApplicationComponentSelectMode, DynamicHelpSections};
use crate::model::component::ComponentNameMatchKind;
use crate::model::format::Format;
use crate::model::text::fmt::{DecoratedIndent, log_text_view};
use crate::model::text::help::{AvailableFunctionNamesHelp, EnvironmentNameHelp, WorkerNameHelp};
use crate::model::text::help::{AgentNameHelp, AvailableFunctionNamesHelp, EnvironmentNameHelp};
use colored::Colorize;
use indoc::indoc;
use std::sync::Arc;
Expand Down Expand Up @@ -186,9 +186,9 @@ impl ErrorHandler {
}
Ok(())
}
GolemCliCommandPartialMatch::WorkerInvokeMissingWorkerName => {
GolemCliCommandPartialMatch::AgentInvokeMissingAgentName => {
logln("");
log_text_view(&WorkerNameHelp);
log_text_view(&AgentNameHelp);
logln("");

self.ctx.silence_app_context_init().await;
Expand Down
2 changes: 1 addition & 1 deletion cli/golem-cli/src/command_handler/resource_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::command::api::resource_definition::ResourceDefinitionSubcommand;
use crate::command::resource_definition::ResourceDefinitionSubcommand;
use crate::command_handler::Handlers;
use crate::context::Context;
use crate::error::NonSuccessfulExit;
Expand Down
2 changes: 1 addition & 1 deletion cli/golem-cli/src/command_handler/retry_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::command::api::retry_policy::RetryPolicySubcommand;
use crate::command::retry_policy::RetryPolicySubcommand;
use crate::command_handler::Handlers;
use crate::context::Context;
use crate::error::NonSuccessfulExit;
Expand Down
34 changes: 17 additions & 17 deletions cli/golem-cli/src/command_handler/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod stream;
mod stream_output;

use crate::command::shared_args::{
AgentIdArgs, PostDeployArgs, StreamArgs, WorkerFunctionArgument, WorkerFunctionName,
AgentFunctionArgument, AgentFunctionName, AgentIdArgs, PostDeployArgs, StreamArgs,
};
use crate::command::worker::AgentSubcommand;
use crate::command_handler::Handlers;
Expand All @@ -34,7 +34,7 @@ use crate::model::deploy::{TryUpdateAllWorkersResult, WorkerUpdateAttempt};
use crate::model::invoke_result_view::InvokeResultView;
use crate::model::text::fmt::{log_fuzzy_match, log_text_view};
use crate::model::text::help::{
AvailableAgentConstructorsHelp, AvailableFunctionNamesHelp, WorkerNameHelp,
AgentNameHelp, AvailableAgentConstructorsHelp, AvailableFunctionNamesHelp,
};
use crate::model::text::worker::{
FileNodeView, WorkerCreateView, WorkerFilesView, WorkerGetView, format_agent_name_match,
Expand Down Expand Up @@ -312,8 +312,8 @@ impl WorkerCommandHandler {
async fn cmd_invoke(
&self,
agent_name: AgentIdArgs,
function_name: &WorkerFunctionName,
arguments: Vec<WorkerFunctionArgument>,
function_name: &AgentFunctionName,
arguments: Vec<AgentFunctionArgument>,
trigger: bool,
idempotency_key: Option<IdempotencyKey>,
no_stream: bool,
Expand Down Expand Up @@ -579,7 +579,7 @@ impl WorkerCommandHandler {

async fn cmd_repl_stream(
&self,
agent_type_name: String,
agent_type_name: AgentTypeName,
parameters: String,
idempotency_key: IdempotencyKey,
phantom_id: Option<Uuid>,
Expand All @@ -599,10 +599,10 @@ impl WorkerCommandHandler {
let Some(agent_type) = self
.ctx
.app_handler()
.get_agent_type_by_name(&environment, &agent_type_name)
.get_agent_type_by_name(&environment, agent_type_name.0.as_str())
.await?
else {
bail!("Agent type not found: {}", agent_type_name);
bail!("Agent type not found: {}", agent_type_name.0);
};

let typed_parameters = DataValue::try_from_untyped_json(
Expand Down Expand Up @@ -813,7 +813,7 @@ impl WorkerCommandHandler {

async fn cmd_list(
&self,
agent_type_name: Option<String>,
agent_type_name: Option<AgentTypeName>,
component_name: Option<ComponentName>,
filters: Vec<String>,
scan_cursor: Option<ScanCursor>,
Expand Down Expand Up @@ -898,7 +898,7 @@ impl WorkerCommandHandler {

async fn resolve_list_components(
&self,
agent_type_name: Option<String>,
agent_type_name: Option<AgentTypeName>,
component_name: Option<ComponentName>,
filters: Vec<String>,
) -> anyhow::Result<(Vec<ComponentDto>, Vec<String>)> {
Expand All @@ -912,16 +912,16 @@ impl WorkerCommandHandler {
.environment_handler()
.resolve_environment(EnvironmentResolveMode::Any)
.await?;
debug!("Finding agent type {}", agent_type_name);
debug!("Finding agent type {}", agent_type_name.0);
let Some(agent_type) = self
.ctx
.app_handler()
.get_agent_type_by_name(&environment, &agent_type_name)
.get_agent_type_by_name(&environment, agent_type_name.0.as_str())
.await?
else {
log_error(format!(
"Agent type {} not found",
agent_type_name.log_color_highlight()
agent_type_name.0.log_color_highlight()
));
bail!(NonSuccessfulExit)
};
Expand Down Expand Up @@ -2232,7 +2232,7 @@ impl WorkerCommandHandler {
agent_name.log_color_error_highlight()
));
logln("");
log_text_view(&WorkerNameHelp);
log_text_view(&AgentNameHelp);
bail!(NonSuccessfulExit);
}
};
Expand All @@ -2253,7 +2253,7 @@ impl WorkerCommandHandler {
"Deploy the component that defines this agent type or specify environment/application/account prefixes.",
);
logln("");
log_text_view(&WorkerNameHelp);
log_text_view(&AgentNameHelp);
bail!(NonSuccessfulExit);
};

Expand Down Expand Up @@ -2303,7 +2303,7 @@ impl WorkerCommandHandler {
name = name.log_color_highlight()
));
logln("");
log_text_view(&WorkerNameHelp);
log_text_view(&AgentNameHelp);
bail!(NonSuccessfulExit);
}
Ok(value)
Expand All @@ -2324,7 +2324,7 @@ impl WorkerCommandHandler {
err = err.log_color_error_highlight()
));
logln("");
log_text_view(&WorkerNameHelp);
log_text_view(&AgentNameHelp);
bail!(NonSuccessfulExit);
}
}
Expand Down Expand Up @@ -2391,7 +2391,7 @@ impl WorkerCommandHandler {
agent_name.0.log_color_error_highlight()
));
logln("");
log_text_view(&WorkerNameHelp);
log_text_view(&AgentNameHelp);
bail!(NonSuccessfulExit);
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/golem-cli/src/model/text/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ use golem_wasm::analysis::AnalysedType;
use indoc::indoc;
use std::path::PathBuf;

pub struct WorkerNameHelp;
pub struct AgentNameHelp;

impl MessageWithFields for WorkerNameHelp {
impl MessageWithFields for AgentNameHelp {
fn message(&self) -> String {
"Accepted agent name formats:"
.log_color_help_group()
Expand Down
4 changes: 3 additions & 1 deletion cli/golem-cli/tests/app/build_and_deploy_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ async fn build_and_deploy_all_templates_for_lang(language: GuestLanguage) {
let outputs = ctx.cli([cmd::DEPLOY, flag::YES]).await;
assert!(outputs.success_or_dump());

let outputs = ctx.cli([cmd::LIST_AGENT_TYPES, flag::FORMAT, "json"]).await;
let outputs = ctx
.cli([cmd::AGENT_TYPE, cmd::LIST, flag::FORMAT, "json"])
.await;
let deployed_agent_types = outputs
.stdout_json::<Vec<DeployedRegisteredAgentType>>()
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion cli/golem-cli/tests/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mod cmd {
pub static NO_ARGS: &[&str] = &[];

pub static AGENT: &str = "agent";
pub static AGENT_TYPE: &str = "agent-type";
pub static BUILD: &str = "build";
pub static COMPLETION: &str = "completion";
pub static COMPONENT: &str = "component";
Expand All @@ -75,7 +76,6 @@ mod cmd {
pub static GET: &str = "get";
pub static INVOKE: &str = "invoke";
pub static LIST: &str = "list";
pub static LIST_AGENT_TYPES: &str = "list-agent-types";
pub static NEW: &str = "new";
pub static PLUGIN: &str = "plugin";
pub static REGISTER: &str = "register";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ steps:
- id: "verify-ephemeral"
shell:
command: "golem"
args: ["list-agent-types", "--environment", "test-app/local", "--format", "json"]
args: ["agent-type", "list", "--environment", "test-app/local", "--format", "json"]
expect:
exit_code: 0
stdout_contains: '"mode":"Ephemeral"'
Expand All @@ -50,7 +50,7 @@ steps:
- id: "verify-durable"
shell:
command: "golem"
args: ["list-agent-types", "--environment", "test-app/local", "--format", "json"]
args: ["agent-type", "list", "--environment", "test-app/local", "--format", "json"]
expect:
exit_code: 0
stdout_contains: '"mode":"Durable"'
2 changes: 1 addition & 1 deletion golem-skills/tests/harness/scenarios/stateless-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ steps:
- id: "verify-ephemeral-mode"
shell:
command: "golem"
args: ["list-agent-types", "--environment", "test-app/local", "--format", "json"]
args: ["agent-type", "list", "--environment", "test-app/local", "--format", "json"]
expect:
exit_code: 0
stdout_contains: '"mode":"Ephemeral"'
Expand Down
Loading