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

Method create_user_message

crates/opencode-session/src/prompt.rs:172–261  ·  view source on GitHub ↗
(
        &self,
        input: &PromptInput,
        session: &mut Session,
    )

Source from the content-addressed store, hash-verified

170 }
171
172 pub async fn create_user_message(
173 &self,
174 input: &PromptInput,
175 session: &mut Session,
176 ) -> anyhow::Result<()> {
177 // Collect text parts for the primary message
178 let text = input
179 .parts
180 .iter()
181 .filter_map(|p| match p {
182 PartInput::Text { text } => Some(text.clone()),
183 _ => None,
184 })
185 .collect::<Vec<_>>()
186 .join("\n");
187
188 let has_non_text = input
189 .parts
190 .iter()
191 .any(|p| !matches!(p, PartInput::Text { .. }));
192
193 if text.is_empty() && !has_non_text {
194 return Err(anyhow::anyhow!("No content in prompt"));
195 }
196
197 let project_root = session.directory.clone();
198
199 // Create the user message with text (or empty if only non-text parts)
200 let msg = if text.is_empty() {
201 session.add_user_message(" ")
202 } else {
203 session.add_user_message(&text)
204 };
205
206 // Add non-text parts to the message
207 for part in &input.parts {
208 match part {
209 PartInput::Text { .. } => {} // already handled above
210 PartInput::File {
211 url,
212 filename,
213 mime,
214 } => {
215 self.add_file_part(
216 msg,
217 url,
218 filename.as_deref(),
219 mime.as_deref(),
220 &project_root,
221 )
222 .await;
223 }
224 PartInput::Agent { name } => {
225 msg.add_agent(name.clone());
226 // Add synthetic text instructing the LLM to invoke the agent
227 msg.add_text(format!(
228 "Use the above message and context to generate a prompt and call the task tool with subagent: {}",
229 name

Calls 8

is_emptyMethod · 0.80
add_file_partMethod · 0.80
add_agentMethod · 0.80
add_textMethod · 0.80
add_subtaskMethod · 0.80
cloneMethod · 0.45
add_user_messageMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected