hank9999
commited on
Commit
·
9ab6db4
1
Parent(s):
2f02dbf
refactor: 移除无用的 KiroRequest 方法及测试
Browse files
src/kiro/model/requests/kiro.rs
CHANGED
|
@@ -36,93 +36,9 @@ pub struct KiroRequest {
|
|
| 36 |
#[serde(skip_serializing_if = "Option::is_none")]
|
| 37 |
pub profile_arn: Option<String>,
|
| 38 |
}
|
| 39 |
-
|
| 40 |
-
impl KiroRequest {
|
| 41 |
-
/// 创建新的请求
|
| 42 |
-
pub fn new(conversation_state: ConversationState) -> Self {
|
| 43 |
-
Self {
|
| 44 |
-
conversation_state,
|
| 45 |
-
profile_arn: None,
|
| 46 |
-
}
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/// 设置 Profile ARN
|
| 50 |
-
pub fn with_profile_arn(mut self, arn: impl Into<String>) -> Self {
|
| 51 |
-
self.profile_arn = Some(arn.into());
|
| 52 |
-
self
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/// 序列化为 JSON 字符串
|
| 56 |
-
pub fn to_json(&self) -> Result<String, serde_json::Error> {
|
| 57 |
-
serde_json::to_string(self)
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/// 序列化为格式化的 JSON 字符串(用于调试)
|
| 61 |
-
pub fn to_json_pretty(&self) -> Result<String, serde_json::Error> {
|
| 62 |
-
serde_json::to_string_pretty(self)
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
/// 获取会话 ID
|
| 66 |
-
pub fn conversation_id(&self) -> &str {
|
| 67 |
-
&self.conversation_state.conversation_id
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/// 获取当前消息内容
|
| 71 |
-
pub fn current_content(&self) -> &str {
|
| 72 |
-
&self
|
| 73 |
-
.conversation_state
|
| 74 |
-
.current_message
|
| 75 |
-
.user_input_message
|
| 76 |
-
.content
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
/// 获取模型 ID
|
| 80 |
-
pub fn model_id(&self) -> &str {
|
| 81 |
-
&self
|
| 82 |
-
.conversation_state
|
| 83 |
-
.current_message
|
| 84 |
-
.user_input_message
|
| 85 |
-
.model_id
|
| 86 |
-
}
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
#[cfg(test)]
|
| 90 |
mod tests {
|
| 91 |
use super::*;
|
| 92 |
-
use crate::kiro::model::requests::conversation::{CurrentMessage, UserInputMessage};
|
| 93 |
-
|
| 94 |
-
#[test]
|
| 95 |
-
fn test_kiro_request_new() {
|
| 96 |
-
let state = ConversationState::new("conv-123").with_current_message(CurrentMessage::new(
|
| 97 |
-
UserInputMessage::new("Hello", "claude-3-5-sonnet"),
|
| 98 |
-
));
|
| 99 |
-
|
| 100 |
-
let request = KiroRequest::new(state);
|
| 101 |
-
|
| 102 |
-
assert_eq!(request.conversation_id(), "conv-123");
|
| 103 |
-
assert_eq!(request.current_content(), "Hello");
|
| 104 |
-
assert_eq!(request.model_id(), "claude-3-5-sonnet");
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
#[test]
|
| 108 |
-
fn test_kiro_request_serialize() {
|
| 109 |
-
let state = ConversationState::new("conv-123")
|
| 110 |
-
.with_agent_task_type("vibe")
|
| 111 |
-
.with_chat_trigger_type("MANUAL")
|
| 112 |
-
.with_current_message(CurrentMessage::new(
|
| 113 |
-
UserInputMessage::new("Hello", "claude-3-5-sonnet").with_origin("AI_EDITOR"),
|
| 114 |
-
));
|
| 115 |
-
|
| 116 |
-
let request = KiroRequest::new(state);
|
| 117 |
-
let json = request.to_json().unwrap();
|
| 118 |
-
|
| 119 |
-
assert!(json.contains("\"conversationState\""));
|
| 120 |
-
assert!(json.contains("\"conversationId\":\"conv-123\""));
|
| 121 |
-
assert!(json.contains("\"agentTaskType\":\"vibe\""));
|
| 122 |
-
assert!(json.contains("\"content\":\"Hello\""));
|
| 123 |
-
assert!(json.contains("\"modelId\":\"claude-3-5-sonnet\""));
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
#[test]
|
| 127 |
fn test_kiro_request_deserialize() {
|
| 128 |
let json = r#"{
|
|
@@ -139,7 +55,7 @@ mod tests {
|
|
| 139 |
}"#;
|
| 140 |
|
| 141 |
let request: KiroRequest = serde_json::from_str(json).unwrap();
|
| 142 |
-
assert_eq!(request.conversation_id
|
| 143 |
-
assert_eq!(request.
|
| 144 |
}
|
| 145 |
}
|
|
|
|
| 36 |
#[serde(skip_serializing_if = "Option::is_none")]
|
| 37 |
pub profile_arn: Option<String>,
|
| 38 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
#[cfg(test)]
|
| 40 |
mod tests {
|
| 41 |
use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
#[test]
|
| 43 |
fn test_kiro_request_deserialize() {
|
| 44 |
let json = r#"{
|
|
|
|
| 55 |
}"#;
|
| 56 |
|
| 57 |
let request: KiroRequest = serde_json::from_str(json).unwrap();
|
| 58 |
+
assert_eq!(request.conversation_state.conversation_id, "conv-456");
|
| 59 |
+
assert_eq!(request.conversation_state.current_message.user_input_message.content, "Test message");
|
| 60 |
}
|
| 61 |
}
|