MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / resolve_remote_session

Function resolve_remote_session

crates/opencode-cli/src/main.rs:1086–1136  ·  view source on GitHub ↗
(
    client: &reqwest::Client,
    base_url: &str,
    continue_last: bool,
    session: Option<String>,
    fork: bool,
    title: Option<String>,
)

Source from the content-addressed store, hash-verified

1084}
1085
1086async fn resolve_remote_session(
1087 client: &reqwest::Client,
1088 base_url: &str,
1089 continue_last: bool,
1090 session: Option<String>,
1091 fork: bool,
1092 title: Option<String>,
1093) -> anyhow::Result<String> {
1094 let base_id = if let Some(session_id) = session {
1095 Some(session_id)
1096 } else if continue_last {
1097 let list_endpoint = server_url(base_url, "/session/?roots=true&limit=100");
1098 let sessions: Vec<RemoteSessionInfo> =
1099 parse_http_json(client.get(list_endpoint).send().await?).await?;
1100 sessions
1101 .into_iter()
1102 .find(|s| s.parent_id.is_none())
1103 .map(|s| s.id)
1104 } else {
1105 None
1106 };
1107
1108 if let Some(base_id) = base_id {
1109 if fork {
1110 let fork_endpoint = server_url(base_url, &format!("/session/{}/fork", base_id));
1111 let forked: RemoteSessionInfo = parse_http_json(
1112 client
1113 .post(fork_endpoint)
1114 .json(&serde_json::json!({ "message_id": null }))
1115 .send()
1116 .await?,
1117 )
1118 .await?;
1119 return Ok(forked.id);
1120 }
1121 return Ok(base_id);
1122 }
1123
1124 let create_endpoint = server_url(base_url, "/session/");
1125 let created: RemoteSessionInfo = parse_http_json(
1126 client
1127 .post(create_endpoint)
1128 .json(&serde_json::json!({
1129 "title": title
1130 }))
1131 .send()
1132 .await?,
1133 )
1134 .await?;
1135 Ok(created.id)
1136}
1137
1138async fn maybe_share_remote_session(
1139 client: &reqwest::Client,

Callers 1

Calls 5

server_urlFunction · 0.85
parse_http_jsonFunction · 0.85
findMethod · 0.80
sendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected