mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-12-01 01:05:10 +08:00
feat(api): enhance statistics storage management with scope options
- Introduced a new type `StatisticsStorageScope` to specify the scope for clearing statistics. - Updated the `clearStatisticsStorage` API method to accept a scope parameter, allowing for selective clearing of detailed records or all statistics. - Modified the demo API to handle the new scope parameter appropriately. - Updated the SettingsPage component to include a selection for clearing scope, enhancing user control over statistics management. - Added new translations for the updated messages related to statistics clearing in both English and Chinese.
This commit is contained in:
1 parent
217f984112
commit
71ddf71ec1
15 files changed
+514
-111
No files matched your search
@@ -43,6 +43,33 @@ impl DecodedAppend {
|
||||
request.conversation_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn is_background_task_completion(&self) -> bool {
|
||||
let Some(agent::agent_client_message::Message::RunRequest(request)) =
|
||||
self.message.message.as_ref()
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
matches!(
|
||||
request
|
||||
.action
|
||||
.as_ref()
|
||||
.and_then(|action| action.action.as_ref()),
|
||||
Some(agent::conversation_action::Action::BackgroundTaskCompletionAction(_))
|
||||
)
|
||||
}
|
||||
|
||||
fn is_runtime_cancellation(&self) -> bool {
|
||||
matches!(
|
||||
self.message.message.as_ref(),
|
||||
Some(agent::agent_client_message::Message::ConversationAction(action))
|
||||
if matches!(
|
||||
action.action.as_ref(),
|
||||
Some(agent::conversation_action::Action::CancelAction(_))
|
||||
| Some(agent::conversation_action::Action::UserMessageAction(_))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn trace_metadata(&self) -> serde_json::Value {
|
||||
let Some(message) = self.message.message.as_ref() else {
|
||||
return serde_json::json!({
|
||||
@@ -163,7 +190,29 @@ pub async fn append(
|
||||
request: DecodedAppend,
|
||||
parent: Option<CursorParent>,
|
||||
) -> Result<ai::BidiAppendResponse> {
|
||||
if let Some(conversation_id) = request.conversation_id() {
|
||||
if request.is_background_task_completion()
|
||||
&& registry.conversation_cancelled(conversation_id)
|
||||
{
|
||||
tracing::info!(
|
||||
request_id = %request.request_id,
|
||||
%conversation_id,
|
||||
"dropping background task completion for cancelled conversation"
|
||||
);
|
||||
return Ok(ai::BidiAppendResponse {});
|
||||
}
|
||||
if !request.is_background_task_completion() {
|
||||
registry.clear_conversation_cancelled(conversation_id);
|
||||
}
|
||||
}
|
||||
let handle = registry.get_or_create(&request.request_id).await?;
|
||||
if let Some(conversation_id) = request.conversation_id() {
|
||||
handle.set_conversation_id(conversation_id)?;
|
||||
}
|
||||
if request.is_runtime_cancellation() {
|
||||
handle.mark_conversation_cancelled();
|
||||
handle.cancel();
|
||||
}
|
||||
if let Some(parent) = parent {
|
||||
handle.set_parent(parent)?;
|
||||
}
|
||||
@@ -225,4 +274,21 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(decoded.model_id(), Some("grok-4.6"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detects_background_task_completion_actions() {
|
||||
let decoded = decode(&encoded(agent::AgentRunRequest {
|
||||
action: Some(agent::ConversationAction {
|
||||
action: Some(
|
||||
agent::conversation_action::Action::BackgroundTaskCompletionAction(
|
||||
agent::BackgroundTaskCompletionAction::default(),
|
||||
),
|
||||
),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}))
|
||||
.unwrap();
|
||||
assert!(decoded.is_background_task_completion());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user