generated from nhcarrigan/template
feat: handle StopFailure hook event for API error turns (#224)
Parses [StopFailure Hook] from stderr, emits claude:stop-failure, and transitions the character to error state with a toast notification.
This commit is contained in:
@@ -300,6 +300,16 @@ pub struct ElicitationResultEvent {
|
||||
pub conversation_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct StopFailureEvent {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stop_reason: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error_type: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub conversation_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AgentStartEvent {
|
||||
pub tool_use_id: String,
|
||||
@@ -645,4 +655,46 @@ mod tests {
|
||||
assert!(!serialized.contains("request_id"));
|
||||
assert!(!serialized.contains("conversation_id"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stop_failure_event_serialization() {
|
||||
let event = StopFailureEvent {
|
||||
stop_reason: Some("api_error".to_string()),
|
||||
error_type: Some("rate_limit".to_string()),
|
||||
conversation_id: Some("conv-abc".to_string()),
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert!(serialized.contains("\"stop_reason\":\"api_error\""));
|
||||
assert!(serialized.contains("\"error_type\":\"rate_limit\""));
|
||||
assert!(serialized.contains("\"conversation_id\":\"conv-abc\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stop_failure_event_omits_none_fields() {
|
||||
let event = StopFailureEvent {
|
||||
stop_reason: None,
|
||||
error_type: None,
|
||||
conversation_id: None,
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert!(!serialized.contains("stop_reason"));
|
||||
assert!(!serialized.contains("error_type"));
|
||||
assert!(!serialized.contains("conversation_id"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stop_failure_event_partial_fields() {
|
||||
let event = StopFailureEvent {
|
||||
stop_reason: Some("api_error".to_string()),
|
||||
error_type: None,
|
||||
conversation_id: None,
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert!(serialized.contains("\"stop_reason\":\"api_error\""));
|
||||
assert!(!serialized.contains("error_type"));
|
||||
assert!(!serialized.contains("conversation_id"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user