mirror of
https://github.com/openai/codex.git
synced 2026-11-05 20:10:33 +00:00
## Why `ContextualUserFragment` needs to be usable behind `dyn` for render-only paths, but associated constants made the trait non-object-safe. ## What changed - Replaced associated constants with trait methods so `dyn ContextualUserFragment` can render fragments. - Preserved the existing typed `T::matches_text(text)` registration pattern via `type_markers()`. - Kept default `render()` on the main trait so implementations only provide role, markers, and body. - Added unit coverage for rendering a `Box<dyn ContextualUserFragment>`. ## Verification - `cargo test -p codex-core contextual_user_fragment_is_dyn_compatible` - `just fix -p codex-core`
39 lines
1.6 KiB
Rust
39 lines
1.6 KiB
Rust
use codex_app_server_protocol::AppInfo;
|
|
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
|
|
use codex_protocol::protocol::APPS_INSTRUCTIONS_CLOSE_TAG;
|
|
use codex_protocol::protocol::APPS_INSTRUCTIONS_OPEN_TAG;
|
|
|
|
use super::ContextualUserFragment;
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub(crate) struct AppsInstructions;
|
|
|
|
impl AppsInstructions {
|
|
pub(crate) fn from_connectors(connectors: &[AppInfo]) -> Option<Self> {
|
|
connectors
|
|
.iter()
|
|
.any(|connector| connector.is_accessible && connector.is_enabled)
|
|
.then_some(Self)
|
|
}
|
|
}
|
|
|
|
impl ContextualUserFragment for AppsInstructions {
|
|
fn role() -> &'static str {
|
|
"developer"
|
|
}
|
|
|
|
fn markers(&self) -> (&'static str, &'static str) {
|
|
Self::type_markers()
|
|
}
|
|
|
|
fn type_markers() -> (&'static str, &'static str) {
|
|
(APPS_INSTRUCTIONS_OPEN_TAG, APPS_INSTRUCTIONS_CLOSE_TAG)
|
|
}
|
|
|
|
fn body(&self) -> String {
|
|
format!(
|
|
"\n## Apps (Connectors)\nApps (Connectors) can be explicitly triggered in user messages in the format `[$app-name](app://{{connector_id}})`. Apps can also be implicitly triggered as long as the context suggests usage of available apps.\nAn app is equivalent to a set of MCP tools within the `{CODEX_APPS_MCP_SERVER_NAME}` MCP.\nAn installed app's MCP tools are either provided to you already, or can be lazy-loaded through the `tool_search` tool. If `tool_search` is available, the apps that are searchable by `tools_search` will be listed by it.\nDo not additionally call list_mcp_resources or list_mcp_resource_templates for apps.\n"
|
|
)
|
|
}
|
|
}
|