mirror of
https://github.com/hanzoai/dev.git
synced 2026-10-25 03:32:32 +00:00
fix(protocol): sync upstream tool outputs and model metadata
This commit is contained in:
@@ -753,8 +753,9 @@ async fn on_dynamic_tool_call_response(
|
||||
Err(err) => {
|
||||
error!("request failed: {err:?}");
|
||||
let fallback = CoreDynamicToolResponse {
|
||||
call_id: call_id.clone(),
|
||||
output: "dynamic tool request failed".to_string(),
|
||||
content_items: vec![code_protocol::dynamic_tools::DynamicToolCallOutputContentItem::InputText {
|
||||
text: "dynamic tool request failed".to_string(),
|
||||
}],
|
||||
success: false,
|
||||
};
|
||||
if let Err(err) = conversation
|
||||
@@ -779,8 +780,11 @@ async fn on_dynamic_tool_call_response(
|
||||
});
|
||||
|
||||
let response = CoreDynamicToolResponse {
|
||||
call_id: call_id.clone(),
|
||||
output: response.output,
|
||||
content_items: vec![
|
||||
code_protocol::dynamic_tools::DynamicToolCallOutputContentItem::InputText {
|
||||
text: response.output,
|
||||
},
|
||||
],
|
||||
success: response.success,
|
||||
};
|
||||
if let Err(err) = conversation
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::auth_accounts;
|
||||
use crate::account_switching::RateLimitSwitchState;
|
||||
use crate::protocol::McpListToolsResponseEvent;
|
||||
use code_app_server_protocol::AuthMode as AppAuthMode;
|
||||
use code_protocol::models::FunctionCallOutputContentItem;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
enum AgentTaskKind {
|
||||
@@ -3331,9 +3332,15 @@ async fn handle_dynamic_tool_call(
|
||||
|
||||
ResponseInputItem::FunctionCallOutput {
|
||||
call_id: ctx.call_id.clone(),
|
||||
output: FunctionCallOutputPayload {
|
||||
content: response.output,
|
||||
success: Some(response.success),
|
||||
output: {
|
||||
let content_items = response
|
||||
.content_items
|
||||
.into_iter()
|
||||
.map(FunctionCallOutputContentItem::from)
|
||||
.collect::<Vec<_>>();
|
||||
let mut payload = FunctionCallOutputPayload::from_content_items(content_items);
|
||||
payload.success = Some(response.success);
|
||||
payload
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1310,6 +1310,7 @@ pub enum TextVerbosity {
|
||||
#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq, Eq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Personality {
|
||||
None,
|
||||
Friendly,
|
||||
#[default]
|
||||
Pragmatic,
|
||||
|
||||
@@ -94,6 +94,7 @@ pub(crate) fn base_instructions_override_for_personality(
|
||||
return None;
|
||||
}
|
||||
let personality_message = match personality {
|
||||
Some(Personality::None) => "",
|
||||
Some(Personality::Friendly) => PERSONALITY_FRIENDLY,
|
||||
Some(Personality::Pragmatic) => PERSONALITY_PRAGMATIC,
|
||||
None => "",
|
||||
|
||||
@@ -391,6 +391,7 @@ fn apply_model_info_overrides_with_personality(
|
||||
|
||||
fn map_personality(personality: ConfigPersonality) -> ProtocolPersonality {
|
||||
match personality {
|
||||
ConfigPersonality::None => ProtocolPersonality::None,
|
||||
ConfigPersonality::Friendly => ProtocolPersonality::Friendly,
|
||||
ConfigPersonality::Pragmatic => ProtocolPersonality::Pragmatic,
|
||||
}
|
||||
|
||||
@@ -2,56 +2,79 @@ You are Codex, a coding agent based on GPT-5. You and the user share the same wo
|
||||
|
||||
{{ personality }}
|
||||
|
||||
## Tone and style
|
||||
- Anything you say outside of tool use is shown to the user. Do not narrate abstractly; explain what you are doing and why, using plain language.
|
||||
- Output will be rendered in a command line interface or minimal UI so keep responses tight, scannable, and low-noise. Generally avoid the use of emojis. You may format with GitHub-flavored Markdown.
|
||||
# Working with the user
|
||||
|
||||
You interact with the user through a terminal. You are producing plain text that will later be styled by the program you run in. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value. Follow the formatting rules exactly.
|
||||
|
||||
## Final answer formatting rules
|
||||
- You may format with GitHub-flavored Markdown.
|
||||
- Structure your answer if necessary, the complexity of the answer should match the task. If the task is simple, your answer should be a one-liner. Order sections from general to specific to supporting.
|
||||
- Never use nested bullets. Keep lists flat (single level). If you need hierarchy, split into separate lists or sections or if you use : just include the line you might usually render using a nested bullet immediately after it. For numbered lists, only use the `1. 2. 3.` style markers (with a period), never `1)`.
|
||||
- When writing a final assistant response, state the solution first before explaining your answer. The complexity of the answer should match the task. If the task is simple, your answer should be short. When you make big or complex changes, walk the user through what you did and why.
|
||||
- Headers are optional, only use them when you think they are necessary. If you do use them, use short Title Case (1-3 words) wrapped in **…**. Don't add a blank line.
|
||||
- Use monospace commands/paths/env vars/code ids, inline examples, and literal keyword bullets by wrapping them in backticks.
|
||||
- Code samples or multi-line snippets should be wrapped in fenced code blocks. Include an info string as often as possible.
|
||||
- Never output the content of large files, just provide references. Use inline code to make file paths clickable; each reference should have a stand alone path, even if it's the same file. Paths may be absolute, workspace-relative, a//b/ diff-prefixed, or bare filename/suffix; locations may be :line[:column] or #Lline[Ccolumn] (1-based; column defaults to 1). Do not use file://, vscode://, or https://, and do not provide line ranges. Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\repo\project\main.rs:12:5
|
||||
- File References: When referencing files in your response follow the below rules:
|
||||
* Use inline code to make file paths clickable.
|
||||
* Each reference should have a stand alone path. Even if it's the same file.
|
||||
* Accepted: absolute, workspace‑relative, a/ or b/ diff prefixes, or bare filename/suffix.
|
||||
* Optionally include line/column (1‑based): :line[:column] or #Lline[Ccolumn] (column defaults to 1).
|
||||
* Do not use URIs like file://, vscode://, or https://.
|
||||
* Do not provide range of lines
|
||||
* Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\repo\project\main.rs:12:5
|
||||
- Don’t use emojis.
|
||||
|
||||
|
||||
## Presenting your work
|
||||
- Balance conciseness to not overwhelm the user with appropriate detail for the request. Do not narrate abstractly; explain what you are doing and why.
|
||||
- The user does not see command execution outputs. When asked to show the output of a command (e.g. `git show`), relay the important details in your answer or summarize the key lines so the user understands the result.
|
||||
- Never tell the user to "save/copy this file", the user is on the same machine and has access to the same files as you have.
|
||||
- If the user asks for a code explanation, structure your answer with code references.
|
||||
- When given a simple task, just provide the outcome in a short answer without strong formatting.
|
||||
- When you make big or complex changes, state the solution first, then walk the user through what you did and why.
|
||||
- For casual chit-chat, just chat.
|
||||
- If you weren't able to do something, for example run tests, tell the user.
|
||||
- If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps.
|
||||
- If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps. When suggesting multiple options, use numeric lists for the suggestions so the user can quickly respond with a single number.
|
||||
|
||||
# Code style
|
||||
# General
|
||||
|
||||
- When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep`. (If the `rg` command is not found, then use alternatives.)
|
||||
|
||||
## Editing constraints
|
||||
|
||||
- Follow the precedence rules user instructions > system / dev / user / AGENTS.md instructions > match local file conventions > instructions below.
|
||||
- Use language-appropriate best practices.
|
||||
- Optimize for clarity, readability, and maintainability.
|
||||
- Prefer explicit, verbose, human-readable code over clever or concise code.
|
||||
- Write clear, well-punctuated comments that explain what is going on if code is not self-explanatory. You should not add comments like "Assigns the value to the variable", but a brief comment might be useful ahead of a complex code block that the user would otherwise have to spend time parsing out. Usage of these comments should be rare.
|
||||
- Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.
|
||||
|
||||
# Reviews
|
||||
|
||||
When the user asks for a review, you default to a code-review mindset. Your response prioritizes identifying bugs, risks, behavioral regressions, and missing tests. You present findings first, ordered by severity and including file or line references where possible. Open questions or assumptions follow. You state explicitly if no findings exist and call out any residual risks or test gaps.
|
||||
|
||||
# Your environment
|
||||
|
||||
## Using GIT
|
||||
|
||||
- You may be working in a dirty git worktree.
|
||||
- Add succinct code comments that explain what is going on if code is not self-explanatory. You should not add comments like "Assigns the value to the variable", but a brief comment might be useful ahead of a complex code block that the user would otherwise have to spend time parsing out. Usage of these comments should be rare.
|
||||
- Try to use apply_patch for single file edits, but it is fine to explore other options to make the edit if it does not work well. Do not use apply_patch for changes that are auto-generated (i.e. generating package.json or running a lint or format command like gofmt) or when scripting is more efficient (such as search and replacing a string across a codebase).
|
||||
- You may be in a dirty git worktree.
|
||||
* NEVER revert existing changes you did not make unless explicitly requested, since these changes were made by the user.
|
||||
* If asked to make a commit or code edits and there are unrelated changes to your work or changes that you didn't make in those files, don't revert those changes.
|
||||
* If the changes are in files you've touched recently, you should read carefully and understand how you can work with the changes rather than reverting them.
|
||||
* If the changes are in unrelated files, just ignore them and don't revert them.
|
||||
- Do not amend a commit unless explicitly requested to do so.
|
||||
- While you are working, you might notice unexpected changes that you didn't make. It's likely the user made them. If this happens, STOP IMMEDIATELY and ask the user how they would like to proceed.
|
||||
- Be cautious when using git. **NEVER** use destructive commands like `git reset --hard` or `git checkout --` unless specifically requested or approved by the user.
|
||||
- While you are working, you might notice unexpected changes that you didn't make. If this happens, STOP IMMEDIATELY and ask the user how they would like to proceed.
|
||||
- **NEVER** use destructive commands like `git reset --hard` or `git checkout --` unless specifically requested or approved by the user.
|
||||
- You struggle using the git interactive console. **ALWAYS** prefer using non-interactive git commands.
|
||||
|
||||
## Agents.md
|
||||
## Plan tool
|
||||
|
||||
- If the directory you are in has an AGENTS.md file, it is provided to you at the top, and you don't have to search for it.
|
||||
- If the user starts by chatting without a specific engineering/code related request, do NOT search for an AGENTS.md. Only do so once there is a relevant request.
|
||||
When using the planning tool:
|
||||
- Skip using the planning tool for straightforward tasks (roughly the easiest 25%).
|
||||
- Do not make single-step plans.
|
||||
- When you made a plan, update it after having performed one of the sub-tasks that you shared on the plan.
|
||||
|
||||
# Tool use
|
||||
## Special user requests
|
||||
|
||||
- Unless you are otherwise instructed, prefer using `rg` or `rg --files` respectively when searching because `rg` is much faster than alternatives like `grep`. If the `rg` command is not found, then use alternatives.
|
||||
- Use the plan tool to explain to the user what you are going to do
|
||||
- Only use it for more complex tasks, do not use it for straightforward tasks (roughly the easiest 25%).
|
||||
- Do not make single-step plans. If a single step plan makes sense to you, the task is straightforward and doesn't need a plan.
|
||||
- When you made a plan, update it after having performed one of the sub-tasks that you shared on the plan.
|
||||
- Try to use apply_patch for single file edits, but it is fine to explore other options to make the edit if it does not work well. Do not use apply_patch for changes that are auto-generated (i.e. generating package.json or running a lint or format command like gofmt) or when scripting is more efficient (such as search and replacing a string across a codebase).
|
||||
- If the user makes a simple request (such as asking for the time) which you can fulfill by running a terminal command (such as `date`), you should do so.
|
||||
- When the user asks for a review, you default to a code-review mindset. Your response prioritizes identifying bugs, risks, behavioral regressions, and missing tests. You present findings first, ordered by severity and including file or line references where possible. Open questions or assumptions follow. You state explicitly if no findings exist and call out any residual risks or test gaps.
|
||||
|
||||
## Frontend tasks
|
||||
|
||||
When doing frontend design tasks, avoid collapsing into "AI slop" or safe, average-looking layouts.
|
||||
Aim for interfaces that feel intentional, bold, and a bit surprising.
|
||||
- Typography: Use expressive, purposeful fonts and avoid default stacks (Inter, Roboto, Arial, system).
|
||||
- Color & Look: Choose a clear visual direction; define CSS variables; avoid purple-on-white defaults. No purple bias or dark mode bias.
|
||||
- Motion: Use a few meaningful animations (page-load, staggered reveals) instead of generic micro-motions.
|
||||
- Background: Don't rely on flat, single-color backgrounds; use gradients, shapes, or subtle patterns to build atmosphere.
|
||||
- Overall: Avoid boilerplate layouts and interchangeable UI patterns. Vary themes, type families, and visual languages across outputs.
|
||||
- Ensure the page loads properly on both desktop and mobile
|
||||
|
||||
Exception: If working within an existing website or design system, preserve the established patterns, structure, and visual language.
|
||||
|
||||
@@ -255,9 +255,12 @@ async fn run_code_tool_session_inner(
|
||||
}
|
||||
EventMsg::DynamicToolCallRequest(ev) => {
|
||||
let response = DynamicToolResponse {
|
||||
call_id: ev.call_id.clone(),
|
||||
output: "dynamic tools are not supported in MCP tool sessions"
|
||||
.to_string(),
|
||||
content_items: vec![
|
||||
code_protocol::dynamic_tools::DynamicToolCallOutputContentItem::InputText {
|
||||
text: "dynamic tools are not supported in MCP tool sessions"
|
||||
.to_string(),
|
||||
},
|
||||
],
|
||||
success: false,
|
||||
};
|
||||
if let Err(err) = codex
|
||||
|
||||
@@ -67,6 +67,7 @@ pub enum Verbosity {
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
pub enum Personality {
|
||||
None,
|
||||
Friendly,
|
||||
Pragmatic,
|
||||
}
|
||||
|
||||
@@ -24,7 +24,16 @@ pub struct DynamicToolCallRequest {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DynamicToolResponse {
|
||||
pub call_id: String,
|
||||
pub output: String,
|
||||
pub content_items: Vec<DynamicToolCallOutputContentItem>,
|
||||
pub success: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema, TS)]
|
||||
#[serde(tag = "type", rename_all = "camelCase")]
|
||||
#[ts(tag = "type")]
|
||||
pub enum DynamicToolCallOutputContentItem {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
InputText { text: String },
|
||||
#[serde(rename_all = "camelCase")]
|
||||
InputImage { image_url: String },
|
||||
}
|
||||
|
||||
+207
-23
@@ -168,15 +168,12 @@ impl From<ResponseInputItem> for ResponseItem {
|
||||
}
|
||||
ResponseInputItem::McpToolCallOutput { call_id, result } => Self::FunctionCallOutput {
|
||||
call_id,
|
||||
output: FunctionCallOutputPayload {
|
||||
success: Some(result.is_ok()),
|
||||
content: result.map_or_else(
|
||||
|tool_call_err| format!("err: {tool_call_err:?}"),
|
||||
|result| {
|
||||
serde_json::to_string(&result)
|
||||
.unwrap_or_else(|e| format!("JSON serialization error: {e}"))
|
||||
},
|
||||
),
|
||||
output: match result {
|
||||
Ok(result) => FunctionCallOutputPayload::from(&result),
|
||||
Err(tool_call_err) => FunctionCallOutputPayload {
|
||||
content: format!("err: {tool_call_err:?}"),
|
||||
success: Some(false),
|
||||
},
|
||||
},
|
||||
},
|
||||
ResponseInputItem::CustomToolCallOutput { call_id, output } => {
|
||||
@@ -305,28 +302,78 @@ pub struct ShellToolCallParams {
|
||||
pub justification: Option<String>,
|
||||
}
|
||||
|
||||
/// Responses API compatible content items that can be returned by a tool call.
|
||||
/// This is a subset of ContentItem with the types we support as function call outputs.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, TS)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum FunctionCallOutputContentItem {
|
||||
// Do not rename, these are serialized and used directly in the responses API.
|
||||
InputText { text: String },
|
||||
// Do not rename, these are serialized and used directly in the responses API.
|
||||
InputImage { image_url: String },
|
||||
}
|
||||
|
||||
/// Converts structured function-call output content into plain text for
|
||||
/// human-readable surfaces.
|
||||
///
|
||||
/// This conversion is intentionally lossy:
|
||||
/// - only `input_text` items are included
|
||||
/// - image items are ignored
|
||||
pub fn function_call_output_content_items_to_text(
|
||||
content_items: &[FunctionCallOutputContentItem],
|
||||
) -> Option<String> {
|
||||
let text_segments = content_items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
FunctionCallOutputContentItem::InputText { text } if !text.trim().is_empty() => {
|
||||
Some(text.as_str())
|
||||
}
|
||||
FunctionCallOutputContentItem::InputText { .. }
|
||||
| FunctionCallOutputContentItem::InputImage { .. } => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if text_segments.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(text_segments.join("\n"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::dynamic_tools::DynamicToolCallOutputContentItem>
|
||||
for FunctionCallOutputContentItem
|
||||
{
|
||||
fn from(item: crate::dynamic_tools::DynamicToolCallOutputContentItem) -> Self {
|
||||
match item {
|
||||
crate::dynamic_tools::DynamicToolCallOutputContentItem::InputText { text } => {
|
||||
Self::InputText { text }
|
||||
}
|
||||
crate::dynamic_tools::DynamicToolCallOutputContentItem::InputImage { image_url } => {
|
||||
Self::InputImage { image_url }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, TS)]
|
||||
pub struct FunctionCallOutputPayload {
|
||||
pub content: String,
|
||||
pub success: Option<bool>,
|
||||
}
|
||||
|
||||
// The Responses API expects two *different* shapes depending on success vs failure:
|
||||
// • success → output is a plain string (no nested object)
|
||||
// • failure → output is an object { content, success:false }
|
||||
// The upstream TypeScript CLI implements this by special‑casing the serialize path.
|
||||
// We replicate that behavior with a manual Serialize impl.
|
||||
// The Responses API accepts either a plain string or an array of structured
|
||||
// content items for `function_call_output.output`. We choose the array form when
|
||||
// `content` holds a serialized `FunctionCallOutputContentItem` list.
|
||||
// The `success` flag remains internal metadata and is never serialized.
|
||||
|
||||
impl Serialize for FunctionCallOutputPayload {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
// The upstream TypeScript CLI always serializes `output` as a *plain string* regardless
|
||||
// of whether the function call succeeded or failed. The boolean is purely informational
|
||||
// for local bookkeeping and is NOT sent to the OpenAI endpoint. Sending the nested object
|
||||
// form `{ content, success:false }` triggers the 400 we are still seeing. Mirror the JS CLI
|
||||
// exactly: always emit a bare string.
|
||||
if let Some(content_items) = try_parse_content_items(&self.content) {
|
||||
return content_items.serialize(serializer);
|
||||
}
|
||||
|
||||
serializer.serialize_str(&self.content)
|
||||
}
|
||||
@@ -337,11 +384,95 @@ impl<'de> Deserialize<'de> for FunctionCallOutputPayload {
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
Ok(FunctionCallOutputPayload {
|
||||
content: s,
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum OutputWire {
|
||||
Text(String),
|
||||
Items(Vec<FunctionCallOutputContentItem>),
|
||||
}
|
||||
|
||||
let payload = match OutputWire::deserialize(deserializer)? {
|
||||
OutputWire::Text(content) => FunctionCallOutputPayload {
|
||||
content,
|
||||
success: None,
|
||||
},
|
||||
OutputWire::Items(items) => FunctionCallOutputPayload {
|
||||
content: serde_json::to_string(&items).unwrap_or_default(),
|
||||
success: None,
|
||||
},
|
||||
};
|
||||
|
||||
Ok(payload)
|
||||
}
|
||||
}
|
||||
|
||||
impl FunctionCallOutputPayload {
|
||||
pub fn from_content_items(content_items: Vec<FunctionCallOutputContentItem>) -> Self {
|
||||
let content = serde_json::to_string(&content_items).unwrap_or_default();
|
||||
Self {
|
||||
content,
|
||||
success: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn content_items(&self) -> Option<Vec<FunctionCallOutputContentItem>> {
|
||||
try_parse_content_items(&self.content)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&CallToolResult> for FunctionCallOutputPayload {
|
||||
fn from(call_tool_result: &CallToolResult) -> Self {
|
||||
let CallToolResult {
|
||||
content,
|
||||
structured_content,
|
||||
is_error,
|
||||
..
|
||||
} = call_tool_result;
|
||||
|
||||
let is_success = is_error != &Some(true);
|
||||
|
||||
if let Some(structured_content) = structured_content
|
||||
&& !structured_content.is_null()
|
||||
{
|
||||
match serde_json::to_string(structured_content) {
|
||||
Ok(serialized_structured_content) => {
|
||||
return FunctionCallOutputPayload {
|
||||
content: serialized_structured_content,
|
||||
success: Some(is_success),
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
return FunctionCallOutputPayload {
|
||||
content: err.to_string(),
|
||||
success: Some(false),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let serialized_content = match serde_json::to_string(content) {
|
||||
Ok(serialized_content) => serialized_content,
|
||||
Err(err) => {
|
||||
return FunctionCallOutputPayload {
|
||||
content: err.to_string(),
|
||||
success: Some(false),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
let content_items = convert_mcp_content_to_items(content);
|
||||
let payload = match content_items {
|
||||
Some(content_items) => FunctionCallOutputPayload::from_content_items(content_items),
|
||||
None => FunctionCallOutputPayload {
|
||||
content: serialized_content,
|
||||
success: Some(is_success),
|
||||
},
|
||||
};
|
||||
|
||||
FunctionCallOutputPayload {
|
||||
success: Some(is_success),
|
||||
..payload
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,6 +493,59 @@ impl std::ops::Deref for FunctionCallOutputPayload {
|
||||
}
|
||||
}
|
||||
|
||||
fn try_parse_content_items(content: &str) -> Option<Vec<FunctionCallOutputContentItem>> {
|
||||
serde_json::from_str::<Vec<FunctionCallOutputContentItem>>(content).ok()
|
||||
}
|
||||
|
||||
fn convert_mcp_content_to_items(
|
||||
contents: &[mcp_types::ContentBlock],
|
||||
) -> Option<Vec<FunctionCallOutputContentItem>> {
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(tag = "type")]
|
||||
enum McpContent {
|
||||
#[serde(rename = "text")]
|
||||
Text { text: String },
|
||||
#[serde(rename = "image")]
|
||||
Image {
|
||||
data: String,
|
||||
#[serde(rename = "mimeType", alias = "mime_type")]
|
||||
mime_type: Option<String>,
|
||||
},
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
let mut saw_image = false;
|
||||
let mut items = Vec::with_capacity(contents.len());
|
||||
|
||||
for content in contents {
|
||||
let value = match serde_json::to_value(content) {
|
||||
Ok(value) => value,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
||||
let item = match serde_json::from_value::<McpContent>(value.clone()) {
|
||||
Ok(McpContent::Text { text }) => FunctionCallOutputContentItem::InputText { text },
|
||||
Ok(McpContent::Image { data, mime_type }) => {
|
||||
saw_image = true;
|
||||
let image_url = if data.starts_with("data:") {
|
||||
data
|
||||
} else {
|
||||
let mime_type = mime_type.unwrap_or_else(|| "application/octet-stream".into());
|
||||
format!("data:{mime_type};base64,{data}")
|
||||
};
|
||||
FunctionCallOutputContentItem::InputImage { image_url }
|
||||
}
|
||||
Ok(McpContent::Unknown) | Err(_) => FunctionCallOutputContentItem::InputText {
|
||||
text: serde_json::to_string(&value).unwrap_or_else(|_| "<content>".to_string()),
|
||||
},
|
||||
};
|
||||
items.push(item);
|
||||
}
|
||||
|
||||
if saw_image { Some(items) } else { None }
|
||||
}
|
||||
|
||||
// (Moved event mapping logic into codex-core to avoid coupling protocol to UI-facing events.)
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -43,6 +43,35 @@ pub enum ReasoningEffort {
|
||||
XHigh,
|
||||
}
|
||||
|
||||
/// Canonical user-input modality tags advertised by a model.
|
||||
#[derive(
|
||||
Debug,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Display,
|
||||
JsonSchema,
|
||||
TS,
|
||||
EnumIter,
|
||||
Hash,
|
||||
)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
pub enum InputModality {
|
||||
/// Plain text turns and tool payloads.
|
||||
Text,
|
||||
/// Image attachments included in user turns.
|
||||
Image,
|
||||
}
|
||||
|
||||
/// Backward-compatible default when `input_modalities` is omitted on the wire.
|
||||
pub fn default_input_modalities() -> Vec<InputModality> {
|
||||
vec![InputModality::Text, InputModality::Image]
|
||||
}
|
||||
|
||||
/// A reasoning effort option that can be surfaced for a model.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema, PartialEq, Eq)]
|
||||
pub struct ReasoningEffortPreset {
|
||||
@@ -88,6 +117,9 @@ pub struct ModelPreset {
|
||||
pub show_in_picker: bool,
|
||||
/// Whether this model is supported in the API.
|
||||
pub supported_in_api: bool,
|
||||
/// Input modalities accepted when composing user turns for this preset.
|
||||
#[serde(default = "default_input_modalities")]
|
||||
pub input_modalities: Vec<InputModality>,
|
||||
}
|
||||
|
||||
/// Visibility of a model in the picker or APIs.
|
||||
@@ -206,6 +238,9 @@ pub struct ModelInfo {
|
||||
#[serde(default = "default_effective_context_window_percent")]
|
||||
pub effective_context_window_percent: i64,
|
||||
pub experimental_supported_tools: Vec<String>,
|
||||
/// Input modalities accepted by the backend for this model.
|
||||
#[serde(default = "default_input_modalities")]
|
||||
pub input_modalities: Vec<InputModality>,
|
||||
}
|
||||
|
||||
impl ModelInfo {
|
||||
@@ -292,6 +327,7 @@ impl ModelInstructionsVariables {
|
||||
pub fn get_personality_message(&self, personality: Option<Personality>) -> Option<String> {
|
||||
if let Some(personality) = personality {
|
||||
match personality {
|
||||
Personality::None => Some(String::new()),
|
||||
Personality::Friendly => self.personality_friendly.clone(),
|
||||
Personality::Pragmatic => self.personality_pragmatic.clone(),
|
||||
}
|
||||
@@ -349,6 +385,7 @@ impl From<ModelInfo> for ModelPreset {
|
||||
}),
|
||||
show_in_picker: info.visibility == ModelVisibility::List,
|
||||
supported_in_api: info.supported_in_api,
|
||||
input_modalities: info.input_modalities,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,6 +448,12 @@ impl SandboxPolicy {
|
||||
subpaths.push(top_level_git);
|
||||
}
|
||||
}
|
||||
for subdir in [".agents", ".codex"] {
|
||||
let top_level = writable_root.join(subdir);
|
||||
if top_level.is_dir() {
|
||||
subpaths.push(top_level);
|
||||
}
|
||||
}
|
||||
WritableRoot {
|
||||
root: writable_root,
|
||||
read_only_subpaths: subpaths,
|
||||
|
||||
@@ -14069,8 +14069,11 @@ impl ChatWidget<'_> {
|
||||
self.restore_reasoning_in_progress_if_streaming();
|
||||
|
||||
let response = DynamicToolResponse {
|
||||
call_id: ev.call_id.clone(),
|
||||
output: "dynamic tools are not supported in this UI".to_string(),
|
||||
content_items: vec![
|
||||
code_protocol::dynamic_tools::DynamicToolCallOutputContentItem::InputText {
|
||||
text: "dynamic tools are not supported in this UI".to_string(),
|
||||
},
|
||||
],
|
||||
success: false,
|
||||
};
|
||||
if let Err(e) = self.code_op_tx.send(Op::DynamicToolResponse {
|
||||
|
||||
Reference in New Issue
Block a user