Fix duplicated output in Code Mode by filtering content by audience (#7117)
This commit is contained in:
@@ -7,7 +7,7 @@ use pctx_code_mode::model::{CallbackConfig, ExecuteInput, GetFunctionDetailsInpu
|
|||||||
use pctx_code_mode::{CallbackRegistry, CodeMode};
|
use pctx_code_mode::{CallbackRegistry, CodeMode};
|
||||||
use rmcp::model::{
|
use rmcp::model::{
|
||||||
CallToolRequestParams, CallToolResult, Content, Implementation, InitializeResult, JsonObject,
|
CallToolRequestParams, CallToolResult, Content, Implementation, InitializeResult, JsonObject,
|
||||||
ListToolsResult, ProtocolVersion, RawContent, ServerCapabilities, Tool as McpTool,
|
ListToolsResult, ProtocolVersion, RawContent, Role, ServerCapabilities, Tool as McpTool,
|
||||||
ToolAnnotations, ToolsCapability,
|
ToolAnnotations, ToolsCapability,
|
||||||
};
|
};
|
||||||
use schemars::{schema_for, JsonSchema};
|
use schemars::{schema_for, JsonSchema};
|
||||||
@@ -270,9 +270,16 @@ fn create_tool_callback(
|
|||||||
if let Some(sc) = &result.structured_content {
|
if let Some(sc) = &result.structured_content {
|
||||||
Ok(serde_json::to_value(sc).unwrap_or(Value::Null))
|
Ok(serde_json::to_value(sc).unwrap_or(Value::Null))
|
||||||
} else {
|
} else {
|
||||||
|
// Filter to assistant-audience or no-audience content,
|
||||||
|
// skipping user-only content to avoid duplicated output
|
||||||
let text: String = result
|
let text: String = result
|
||||||
.content
|
.content
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|c| {
|
||||||
|
c.audience().is_none_or(|audiences| {
|
||||||
|
audiences.is_empty() || audiences.contains(&Role::Assistant)
|
||||||
|
})
|
||||||
|
})
|
||||||
.filter_map(|c| match &c.raw {
|
.filter_map(|c| match &c.raw {
|
||||||
RawContent::Text(t) => Some(t.text.clone()),
|
RawContent::Text(t) => Some(t.text.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
Reference in New Issue
Block a user