use crate::codec::agent::{from_wire_prepared_agent_workspace, to_wire_agent_workspace};
use crate::codec::support::{from_wire_timestamp, to_wire_timestamp};
use crate::generated::v1;
use crate::runtime_provider::{
AppendRuntimeLogsRequest, AppendRuntimeLogsResponse, GetRuntimeSessionRequest, HostedApp,
ListRuntimeSessionsRequest, ListRuntimeSessionsResponse, PrepareRuntimeWorkspaceRequest,
PrepareRuntimeWorkspaceResponse, RemoveRuntimeWorkspaceRequest, RuntimeImagePullAuth,
RuntimeLogEntry, RuntimeSession, RuntimeSessionLifecycle, RuntimeSupport,
StartHostedAppRequest, StartRuntimeSessionRequest, StopRuntimeSessionRequest,
};
pub(crate) fn to_wire_append_runtime_logs_request(
value: AppendRuntimeLogsRequest,
) -> v1::AppendRuntimeLogsRequest {
v1::AppendRuntimeLogsRequest {
session_id: value.session_id,
logs: value
.logs
.into_iter()
.map(to_wire_runtime_log_entry)
.collect(),
}
}
pub(crate) fn from_wire_append_runtime_logs_response(
value: v1::AppendRuntimeLogsResponse,
) -> AppendRuntimeLogsResponse {
AppendRuntimeLogsResponse {
last_seq: value.last_seq,
}
}
pub(crate) fn to_wire_get_runtime_session_request(
value: GetRuntimeSessionRequest,
) -> v1::GetRuntimeSessionRequest {
v1::GetRuntimeSessionRequest {
session_id: value.session_id,
}
}
pub(crate) fn from_wire_hosted_app(value: v1::HostedApp) -> HostedApp {
HostedApp {
id: value.id,
session_id: value.session_id,
app_name: value.app_name,
dial_target: value.dial_target,
}
}
pub(crate) fn to_wire_list_runtime_sessions_request(
value: ListRuntimeSessionsRequest,
) -> v1::ListRuntimeSessionsRequest {
v1::ListRuntimeSessionsRequest {
page_size: value.page_size,
page_token: value.page_token,
}
}
pub(crate) fn from_wire_list_runtime_sessions_response(
value: v1::ListRuntimeSessionsResponse,
) -> ListRuntimeSessionsResponse {
ListRuntimeSessionsResponse {
sessions: value
.sessions
.into_iter()
.map(from_wire_runtime_session)
.collect(),
next_page_token: value.next_page_token,
}
}
pub(crate) fn to_wire_prepare_runtime_workspace_request(
value: PrepareRuntimeWorkspaceRequest,
) -> v1::PrepareRuntimeWorkspaceRequest {
v1::PrepareRuntimeWorkspaceRequest {
session_id: value.session_id,
agent_session_id: value.agent_session_id,
workspace: value.workspace.map(to_wire_agent_workspace),
}
}
pub(crate) fn from_wire_prepare_runtime_workspace_response(
value: v1::PrepareRuntimeWorkspaceResponse,
) -> PrepareRuntimeWorkspaceResponse {
PrepareRuntimeWorkspaceResponse {
workspace: value.workspace.map(from_wire_prepared_agent_workspace),
}
}
pub(crate) fn to_wire_remove_runtime_workspace_request(
value: RemoveRuntimeWorkspaceRequest,
) -> v1::RemoveRuntimeWorkspaceRequest {
v1::RemoveRuntimeWorkspaceRequest {
session_id: value.session_id,
agent_session_id: value.agent_session_id,
}
}
pub(crate) fn to_wire_runtime_image_pull_auth(
value: RuntimeImagePullAuth,
) -> v1::RuntimeImagePullAuth {
v1::RuntimeImagePullAuth {
docker_config_json: value.docker_config_json,
}
}
pub(crate) fn to_wire_runtime_log_entry(value: RuntimeLogEntry) -> v1::RuntimeLogEntry {
v1::RuntimeLogEntry {
stream: value.stream,
message: value.message,
observed_at: value.observed_at.map(to_wire_timestamp),
source_seq: value.source_seq,
}
}
pub(crate) fn from_wire_runtime_session(value: v1::RuntimeSession) -> RuntimeSession {
RuntimeSession {
id: value.id,
state: value.state,
metadata: value.metadata,
lifecycle: value.lifecycle.map(from_wire_runtime_session_lifecycle),
state_reason: value.state_reason,
state_message: value.state_message,
}
}
pub(crate) fn from_wire_runtime_session_lifecycle(
value: v1::RuntimeSessionLifecycle,
) -> RuntimeSessionLifecycle {
RuntimeSessionLifecycle {
started_at: value.started_at.map(from_wire_timestamp),
recommended_drain_at: value.recommended_drain_at.map(from_wire_timestamp),
expires_at: value.expires_at.map(from_wire_timestamp),
}
}
pub(crate) fn from_wire_runtime_support(value: v1::RuntimeSupport) -> RuntimeSupport {
RuntimeSupport {
can_host_apps: value.can_host_apps,
egress_mode: value.egress_mode,
supports_prepare_workspace: value.supports_prepare_workspace,
}
}
pub(crate) fn to_wire_start_hosted_app_request(
value: StartHostedAppRequest,
) -> v1::StartHostedAppRequest {
v1::StartHostedAppRequest {
session_id: value.session_id,
app_name: value.app_name,
command: value.command,
args: value.args,
env: value.env,
allowed_hosts: value.allowed_hosts,
default_action: value.default_action,
host_binary: value.host_binary,
workdir: value.workdir,
}
}
pub(crate) fn to_wire_start_runtime_session_request(
value: StartRuntimeSessionRequest,
) -> v1::StartRuntimeSessionRequest {
v1::StartRuntimeSessionRequest {
app_name: value.app_name,
template: value.template,
image: value.image,
metadata: value.metadata,
image_pull_auth: value.image_pull_auth.map(to_wire_runtime_image_pull_auth),
}
}
pub(crate) fn to_wire_stop_runtime_session_request(
value: StopRuntimeSessionRequest,
) -> v1::StopRuntimeSessionRequest {
v1::StopRuntimeSessionRequest {
session_id: value.session_id,
}
}