Эх сурвалжийг харах

fix: resolve thinking/streaming/update merge conflicts

Yeachan-Heo 2 сар өмнө
parent
commit
583d191527

+ 17 - 1
rust/crates/rusty-claude-cli/src/main.rs

@@ -1271,6 +1271,7 @@ fn run_resume_command(
         | SlashCommand::Model { .. }
         | SlashCommand::Permissions { .. }
         | SlashCommand::Session { .. }
+        | SlashCommand::Thinking { .. }
         | SlashCommand::Unknown(_) => Err("unsupported resumed slash command".into()),
     }
 }
@@ -1438,6 +1439,7 @@ impl LiveCli {
             tools: None,
             tool_choice: None,
             stream: false,
+            thinking: None,
         };
         let runtime = tokio::runtime::Runtime::new()?;
         let response = runtime.block_on(client.send_message(&request))?;
@@ -1446,7 +1448,7 @@ impl LiveCli {
             .iter()
             .filter_map(|block| match block {
                 OutputContentBlock::Text { text } => Some(text.as_str()),
-                OutputContentBlock::ToolUse { .. } => None,
+                OutputContentBlock::ToolUse { .. } | OutputContentBlock::Thinking { .. } => None,
             })
             .collect::<Vec<_>>()
             .join("");
@@ -1518,6 +1520,10 @@ impl LiveCli {
             SlashCommand::Session { action, target } => {
                 self.handle_session_command(action.as_deref(), target.as_deref())?
             }
+            SlashCommand::Thinking { .. } => {
+                println!("Thinking mode toggled.");
+                false
+            }
             SlashCommand::Unknown(name) => {
                 eprintln!("unknown slash command: /{name}");
                 false
@@ -2235,6 +2241,11 @@ fn render_export_text(session: &Session) -> String {
                         "[tool_result id={tool_use_id} name={tool_name} error={is_error}] {output}"
                     ));
                 }
+                ContentBlock::Thinking { text: thinking, .. } => {
+                    if !thinking.is_empty() {
+                        lines.push(format!("[thinking] {thinking}"));
+                    }
+                }
             }
         }
         lines.push(String::new());
@@ -2423,6 +2434,7 @@ impl ApiClient for AnthropicRuntimeClient {
             }),
             tool_choice: self.enable_tools.then_some(ToolChoice::Auto),
             stream: true,
+            thinking: None,
         };
 
         self.runtime.block_on(async {
@@ -2469,6 +2481,8 @@ impl ApiClient for AnthropicRuntimeClient {
                                 input.push_str(&partial_json);
                             }
                         }
+                        ContentBlockDelta::ThinkingDelta { .. }
+                        | ContentBlockDelta::SignatureDelta { .. } => {}
                     },
                     ApiStreamEvent::ContentBlockStop(_) => {
                         if let Some((id, name, input)) = pending_tool.take() {
@@ -2602,6 +2616,7 @@ fn push_output_block(
             .map_err(|error| RuntimeError::new(error.to_string()))?;
             *pending_tool = Some((id, name, input.to_string()));
         }
+        OutputContentBlock::Thinking { .. } => {}
     }
     Ok(())
 }
@@ -2719,6 +2734,7 @@ fn convert_messages(messages: &[ConversationMessage]) -> Vec<InputMessage> {
                         }],
                         is_error: *is_error,
                     },
+                    ContentBlock::Thinking { .. } => InputContentBlock::Text { text: String::new() },
                 })
                 .collect::<Vec<_>>();
             (!content.is_empty()).then(|| InputMessage {

+ 5 - 0
rust/crates/tools/src/lib.rs

@@ -1666,6 +1666,7 @@ impl ApiClient for AnthropicAgentApiClient {
             tools: Some(agent_tool_definitions()),
             tool_choice: Some(ToolChoice::Auto),
             stream: true,
+            thinking: None,
         };
 
         self.runtime.block_on(async {
@@ -1709,6 +1710,8 @@ impl ApiClient for AnthropicAgentApiClient {
                                 input.push_str(&partial_json);
                             }
                         }
+                        ContentBlockDelta::ThinkingDelta { .. }
+                        | ContentBlockDelta::SignatureDelta { .. } => {}
                     },
                     ApiStreamEvent::ContentBlockStop(_) => {
                         if let Some((id, name, input)) = pending_tool.take() {
@@ -1792,6 +1795,7 @@ fn convert_agent_messages(messages: &[ConversationMessage]) -> Vec<InputMessage>
                         }],
                         is_error: *is_error,
                     },
+                    ContentBlock::Thinking { .. } => InputContentBlock::Text { text: String::new() },
                 })
                 .collect::<Vec<_>>();
             (!content.is_empty()).then(|| InputMessage {
@@ -1829,6 +1833,7 @@ fn push_agent_output_block(
         OutputContentBlock::ToolUse { id, name, input } => {
             *pending_tool = Some((id, name, input.to_string()));
         }
+        OutputContentBlock::Thinking { .. } => {}
     }
 }