@howaboua/pi-codex-web-run 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/UPSTREAM_SYNC.md +2 -2
- package/biome.json +1 -1
- package/index.ts +46 -3
- package/package.json +17 -10
- package/src/codex-runtime/auth-diagnostics.ts +47 -0
- package/src/codex-runtime/resolve.ts +32 -11
- package/src/codex-runtime/types.ts +2 -2
- package/src/contract.ts +0 -2
- package/src/execute.ts +28 -15
- package/src/tool.ts +2 -2
- package/upstream/codex-api-endpoint/search.rs +0 -318
- package/upstream/codex-api-endpoint/search_types.rs +0 -305
- package/upstream/web-search/extension.rs +0 -220
- package/upstream/web-search/history.rs +0 -205
- package/upstream/web-search/lib.rs +0 -7
- package/upstream/web-search/output.rs +0 -74
- package/upstream/web-search/schema.rs +0 -36
- package/upstream/web-search/tool.rs +0 -332
- package/upstream/web-search/web_run_description.md +0 -105
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
use std::sync::Arc;
|
|
2
|
-
|
|
3
|
-
use codex_api::AllowedCaller;
|
|
4
|
-
use codex_api::ApproximateLocation;
|
|
5
|
-
use codex_api::ExternalWebAccess;
|
|
6
|
-
use codex_api::ExternalWebAccessMode;
|
|
7
|
-
use codex_api::LocationType;
|
|
8
|
-
use codex_api::SearchContextSize;
|
|
9
|
-
use codex_api::SearchFilters;
|
|
10
|
-
use codex_api::SearchSettings;
|
|
11
|
-
use codex_core::config::Config;
|
|
12
|
-
use codex_extension_api::ConfigContributor;
|
|
13
|
-
use codex_extension_api::ExtensionData;
|
|
14
|
-
use codex_extension_api::ExtensionFuture;
|
|
15
|
-
use codex_extension_api::ExtensionRegistryBuilder;
|
|
16
|
-
use codex_extension_api::ThreadLifecycleContributor;
|
|
17
|
-
use codex_extension_api::ThreadOriginator;
|
|
18
|
-
use codex_extension_api::ThreadStartInput;
|
|
19
|
-
use codex_extension_api::ToolContributor;
|
|
20
|
-
use codex_login::AuthManager;
|
|
21
|
-
use codex_model_provider::create_model_provider;
|
|
22
|
-
use codex_model_provider_info::ModelProviderInfo;
|
|
23
|
-
use codex_protocol::config_types::WebSearchContextSize;
|
|
24
|
-
use codex_protocol::config_types::WebSearchMode;
|
|
25
|
-
|
|
26
|
-
use crate::tool::WebSearchTool;
|
|
27
|
-
|
|
28
|
-
#[derive(Clone)]
|
|
29
|
-
struct WebSearchExtension {
|
|
30
|
-
auth_manager: Arc<AuthManager>,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
#[derive(Clone)]
|
|
34
|
-
struct WebSearchExtensionConfig {
|
|
35
|
-
available: bool,
|
|
36
|
-
provider: ModelProviderInfo,
|
|
37
|
-
settings: SearchSettings,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
impl From<&Config> for WebSearchExtensionConfig {
|
|
41
|
-
fn from(config: &Config) -> Self {
|
|
42
|
-
let web_search_mode = config.web_search_mode.value();
|
|
43
|
-
Self {
|
|
44
|
-
// Core selects this executor per turn using the feature flag or model metadata.
|
|
45
|
-
available: (config.model_provider.is_openai()
|
|
46
|
-
|| config.model_provider.uses_openai_actor_authorization()
|
|
47
|
-
|| config.model_provider.supports_standalone_web_search)
|
|
48
|
-
&& web_search_mode != WebSearchMode::Disabled,
|
|
49
|
-
provider: config.model_provider.clone(),
|
|
50
|
-
settings: search_settings(config, web_search_mode),
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
fn search_settings(config: &Config, web_search_mode: WebSearchMode) -> SearchSettings {
|
|
56
|
-
let web_search_config = config.web_search_config.as_ref();
|
|
57
|
-
SearchSettings {
|
|
58
|
-
user_location: web_search_config
|
|
59
|
-
.and_then(|config| config.user_location.as_ref())
|
|
60
|
-
.map(|location| ApproximateLocation {
|
|
61
|
-
r#type: LocationType::Approximate,
|
|
62
|
-
country: location.country.clone(),
|
|
63
|
-
region: location.region.clone(),
|
|
64
|
-
city: location.city.clone(),
|
|
65
|
-
timezone: location.timezone.clone(),
|
|
66
|
-
}),
|
|
67
|
-
search_context_size: web_search_config
|
|
68
|
-
.and_then(|config| config.search_context_size)
|
|
69
|
-
.map(|size| match size {
|
|
70
|
-
WebSearchContextSize::Low => SearchContextSize::Low,
|
|
71
|
-
WebSearchContextSize::Medium => SearchContextSize::Medium,
|
|
72
|
-
WebSearchContextSize::High => SearchContextSize::High,
|
|
73
|
-
}),
|
|
74
|
-
filters: web_search_config
|
|
75
|
-
.and_then(|config| config.filters.as_ref())
|
|
76
|
-
.map(|filters| SearchFilters {
|
|
77
|
-
allowed_domains: filters.allowed_domains.clone(),
|
|
78
|
-
blocked_domains: None,
|
|
79
|
-
}),
|
|
80
|
-
allowed_callers: Some(vec![AllowedCaller::Direct]),
|
|
81
|
-
external_web_access: Some(external_web_access_for_mode(web_search_mode)),
|
|
82
|
-
..Default::default()
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
fn external_web_access_for_mode(web_search_mode: WebSearchMode) -> ExternalWebAccess {
|
|
87
|
-
match web_search_mode {
|
|
88
|
-
WebSearchMode::Disabled | WebSearchMode::Cached => ExternalWebAccess::Boolean(false),
|
|
89
|
-
WebSearchMode::Indexed => ExternalWebAccess::Mode(ExternalWebAccessMode::Indexed),
|
|
90
|
-
WebSearchMode::Live => ExternalWebAccess::Boolean(true),
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
impl ThreadLifecycleContributor<Config> for WebSearchExtension {
|
|
95
|
-
fn on_thread_start<'a>(
|
|
96
|
-
&'a self,
|
|
97
|
-
input: ThreadStartInput<'a, Config>,
|
|
98
|
-
) -> ExtensionFuture<'a, ()> {
|
|
99
|
-
Box::pin(async move {
|
|
100
|
-
input
|
|
101
|
-
.thread_store
|
|
102
|
-
.insert(WebSearchExtensionConfig::from(input.config));
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
impl ConfigContributor<Config> for WebSearchExtension {
|
|
108
|
-
fn on_config_changed(
|
|
109
|
-
&self,
|
|
110
|
-
_session_store: &ExtensionData,
|
|
111
|
-
thread_store: &ExtensionData,
|
|
112
|
-
_previous_config: &Config,
|
|
113
|
-
new_config: &Config,
|
|
114
|
-
) {
|
|
115
|
-
thread_store.insert(WebSearchExtensionConfig::from(new_config));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
impl ToolContributor for WebSearchExtension {
|
|
120
|
-
fn tools(
|
|
121
|
-
&self,
|
|
122
|
-
session_store: &ExtensionData,
|
|
123
|
-
thread_store: &ExtensionData,
|
|
124
|
-
) -> Vec<Arc<dyn codex_extension_api::ToolExecutor<codex_extension_api::ToolCall>>> {
|
|
125
|
-
let Some(config) = thread_store.get::<WebSearchExtensionConfig>() else {
|
|
126
|
-
return Vec::new();
|
|
127
|
-
};
|
|
128
|
-
if !config.available {
|
|
129
|
-
return Vec::new();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
vec![Arc::new(WebSearchTool {
|
|
133
|
-
session_id: session_store.level_id().to_string(),
|
|
134
|
-
provider: create_model_provider(
|
|
135
|
-
config.provider.clone(),
|
|
136
|
-
Some(self.auth_manager.clone()),
|
|
137
|
-
),
|
|
138
|
-
settings: config.settings.clone(),
|
|
139
|
-
originator: thread_store
|
|
140
|
-
.get::<ThreadOriginator>()
|
|
141
|
-
.map(|originator| originator.0.clone()),
|
|
142
|
-
})]
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
pub fn install(registry: &mut ExtensionRegistryBuilder<Config>, auth_manager: Arc<AuthManager>) {
|
|
147
|
-
let extension = Arc::new(WebSearchExtension { auth_manager });
|
|
148
|
-
registry.thread_lifecycle_contributor(extension.clone());
|
|
149
|
-
registry.config_contributor(extension.clone());
|
|
150
|
-
registry.tool_contributor(extension);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
#[cfg(test)]
|
|
154
|
-
mod tests {
|
|
155
|
-
use codex_extension_api::ExtensionData;
|
|
156
|
-
use codex_extension_api::ExtensionRegistryBuilder;
|
|
157
|
-
use codex_extension_api::ToolName;
|
|
158
|
-
use codex_login::CodexAuth;
|
|
159
|
-
use codex_model_provider_info::ModelProviderInfo;
|
|
160
|
-
use pretty_assertions::assert_eq;
|
|
161
|
-
|
|
162
|
-
use super::AuthManager;
|
|
163
|
-
use super::Config;
|
|
164
|
-
use super::WebSearchExtensionConfig;
|
|
165
|
-
use super::external_web_access_for_mode;
|
|
166
|
-
use super::install;
|
|
167
|
-
use crate::tool::RUN_TOOL_NAME;
|
|
168
|
-
use crate::tool::WEB_NAMESPACE;
|
|
169
|
-
use codex_api::ExternalWebAccess;
|
|
170
|
-
use codex_api::ExternalWebAccessMode;
|
|
171
|
-
use codex_protocol::config_types::WebSearchMode;
|
|
172
|
-
|
|
173
|
-
#[test]
|
|
174
|
-
fn external_web_access_preserves_legacy_values_until_indexed() {
|
|
175
|
-
assert_eq!(
|
|
176
|
-
[
|
|
177
|
-
WebSearchMode::Disabled,
|
|
178
|
-
WebSearchMode::Cached,
|
|
179
|
-
WebSearchMode::Indexed,
|
|
180
|
-
WebSearchMode::Live,
|
|
181
|
-
]
|
|
182
|
-
.map(external_web_access_for_mode),
|
|
183
|
-
[
|
|
184
|
-
ExternalWebAccess::Boolean(false),
|
|
185
|
-
ExternalWebAccess::Boolean(false),
|
|
186
|
-
ExternalWebAccess::Mode(ExternalWebAccessMode::Indexed),
|
|
187
|
-
ExternalWebAccess::Boolean(true),
|
|
188
|
-
]
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
#[test]
|
|
193
|
-
fn installed_extension_contributes_web_run_when_enabled() {
|
|
194
|
-
let mut builder = ExtensionRegistryBuilder::<Config>::new();
|
|
195
|
-
install(
|
|
196
|
-
&mut builder,
|
|
197
|
-
AuthManager::from_auth_for_testing(CodexAuth::from_api_key("dummy")),
|
|
198
|
-
);
|
|
199
|
-
let registry = builder.build();
|
|
200
|
-
let session_store = ExtensionData::new("session");
|
|
201
|
-
let thread_store = ExtensionData::new("11111111-1111-4111-8111-111111111111");
|
|
202
|
-
thread_store.insert(WebSearchExtensionConfig {
|
|
203
|
-
available: true,
|
|
204
|
-
provider: ModelProviderInfo::create_openai_provider(/*base_url*/ None),
|
|
205
|
-
settings: Default::default(),
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
let tool_names = registry
|
|
209
|
-
.tool_contributors()
|
|
210
|
-
.iter()
|
|
211
|
-
.flat_map(|contributor| contributor.tools(&session_store, &thread_store))
|
|
212
|
-
.map(|tool| (tool.tool_name(), tool.supports_parallel_tool_calls()))
|
|
213
|
-
.collect::<Vec<_>>();
|
|
214
|
-
|
|
215
|
-
assert_eq!(
|
|
216
|
-
tool_names,
|
|
217
|
-
vec![(ToolName::namespaced(WEB_NAMESPACE, RUN_TOOL_NAME), true)]
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
use codex_api::SearchInput;
|
|
2
|
-
use codex_core::parse_turn_item;
|
|
3
|
-
use codex_protocol::items::TurnItem;
|
|
4
|
-
use codex_protocol::models::ContentItem;
|
|
5
|
-
use codex_protocol::models::ResponseItem;
|
|
6
|
-
use codex_protocol::models::plaintext_agent_message_content;
|
|
7
|
-
use codex_tools::retain_tail_from_last_n_user_messages;
|
|
8
|
-
use codex_tools::truncate_assistant_output_text_to_token_budget;
|
|
9
|
-
|
|
10
|
-
const ASSISTANT_CONTEXT_TOKEN_LIMIT: usize = 1_000;
|
|
11
|
-
const ASSISTANT_ROLE: &str = "assistant";
|
|
12
|
-
const USER_ROLE: &str = "user";
|
|
13
|
-
|
|
14
|
-
/// Builds the conversation tail for standalone web search.
|
|
15
|
-
///
|
|
16
|
-
/// The tail keeps the previous user text message, up to 1k tokens of assistant
|
|
17
|
-
/// text that followed it, and the current user text message.
|
|
18
|
-
pub(crate) fn recent_input(items: &[ResponseItem]) -> Option<SearchInput> {
|
|
19
|
-
let mut messages = Vec::new();
|
|
20
|
-
for item in items {
|
|
21
|
-
push_visible_message(&mut messages, item);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
retain_tail_from_last_n_user_messages(&mut messages, /*user_message_count*/ 2);
|
|
25
|
-
truncate_assistant_output_text_to_token_budget(&mut messages, ASSISTANT_CONTEXT_TOKEN_LIMIT);
|
|
26
|
-
(!messages.is_empty()).then_some(SearchInput::Items(messages))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
fn push_visible_message(messages: &mut Vec<ResponseItem>, item: &ResponseItem) {
|
|
30
|
-
match item {
|
|
31
|
-
ResponseItem::Message { role, .. } if role == ASSISTANT_ROLE => {
|
|
32
|
-
let mut message = item.clone();
|
|
33
|
-
message.set_id(/*new_id*/ None);
|
|
34
|
-
messages.push(message);
|
|
35
|
-
}
|
|
36
|
-
ResponseItem::AgentMessage {
|
|
37
|
-
author,
|
|
38
|
-
content,
|
|
39
|
-
internal_chat_message_metadata_passthrough: metadata,
|
|
40
|
-
..
|
|
41
|
-
} => {
|
|
42
|
-
if let Some(text) = plaintext_agent_message_content(content) {
|
|
43
|
-
messages.push(ResponseItem::Message {
|
|
44
|
-
id: None,
|
|
45
|
-
role: ASSISTANT_ROLE.to_string(),
|
|
46
|
-
content: vec![ContentItem::OutputText {
|
|
47
|
-
text: format!("Agent message from {author}:\n{text}"),
|
|
48
|
-
}],
|
|
49
|
-
phase: None,
|
|
50
|
-
internal_chat_message_metadata_passthrough: metadata.clone(),
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
ResponseItem::Message {
|
|
55
|
-
id: _,
|
|
56
|
-
role,
|
|
57
|
-
content,
|
|
58
|
-
phase,
|
|
59
|
-
internal_chat_message_metadata_passthrough: metadata,
|
|
60
|
-
} if role == USER_ROLE
|
|
61
|
-
&& matches!(parse_turn_item(item), Some(TurnItem::UserMessage(_))) =>
|
|
62
|
-
{
|
|
63
|
-
let content = content
|
|
64
|
-
.iter()
|
|
65
|
-
.filter(|item| matches!(item, ContentItem::InputText { .. }))
|
|
66
|
-
.cloned()
|
|
67
|
-
.collect::<Vec<_>>();
|
|
68
|
-
if !content.is_empty() {
|
|
69
|
-
messages.push(ResponseItem::Message {
|
|
70
|
-
id: None,
|
|
71
|
-
role: role.clone(),
|
|
72
|
-
content,
|
|
73
|
-
phase: phase.clone(),
|
|
74
|
-
internal_chat_message_metadata_passthrough: metadata.clone(),
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
_ => {}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#[cfg(test)]
|
|
83
|
-
mod tests {
|
|
84
|
-
use codex_api::SearchInput;
|
|
85
|
-
use codex_protocol::ResponseItemId;
|
|
86
|
-
use codex_protocol::models::ContentItem;
|
|
87
|
-
use codex_protocol::models::ResponseItem;
|
|
88
|
-
use pretty_assertions::assert_eq;
|
|
89
|
-
|
|
90
|
-
use super::ASSISTANT_ROLE;
|
|
91
|
-
use super::USER_ROLE;
|
|
92
|
-
use super::recent_input;
|
|
93
|
-
|
|
94
|
-
fn message(role: &str, text: &str) -> ResponseItem {
|
|
95
|
-
ResponseItem::Message {
|
|
96
|
-
id: None,
|
|
97
|
-
role: role.to_string(),
|
|
98
|
-
content: vec![if role == ASSISTANT_ROLE {
|
|
99
|
-
ContentItem::OutputText {
|
|
100
|
-
text: text.to_string(),
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
ContentItem::InputText {
|
|
104
|
-
text: text.to_string(),
|
|
105
|
-
}
|
|
106
|
-
}],
|
|
107
|
-
phase: None,
|
|
108
|
-
internal_chat_message_metadata_passthrough: None,
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
#[test]
|
|
113
|
-
fn keeps_current_user_and_previous_visible_turn() {
|
|
114
|
-
let mut previous_user = message(USER_ROLE, "previous user");
|
|
115
|
-
previous_user.set_id(Some(ResponseItemId::with_suffix("msg", "previous_user")));
|
|
116
|
-
let mut previous_assistant = message(ASSISTANT_ROLE, "previous assistant");
|
|
117
|
-
previous_assistant.set_id(Some(ResponseItemId::with_suffix(
|
|
118
|
-
"msg",
|
|
119
|
-
"previous_assistant",
|
|
120
|
-
)));
|
|
121
|
-
let items = vec![
|
|
122
|
-
message("system", "system"),
|
|
123
|
-
message(USER_ROLE, "old user"),
|
|
124
|
-
message(ASSISTANT_ROLE, "old assistant"),
|
|
125
|
-
previous_user,
|
|
126
|
-
ResponseItem::FunctionCall {
|
|
127
|
-
id: None,
|
|
128
|
-
name: "tool".to_string(),
|
|
129
|
-
namespace: None,
|
|
130
|
-
arguments: "{}".to_string(),
|
|
131
|
-
call_id: "call-1".to_string(),
|
|
132
|
-
encrypted_function_args: None,
|
|
133
|
-
internal_chat_message_metadata_passthrough: None,
|
|
134
|
-
},
|
|
135
|
-
previous_assistant,
|
|
136
|
-
message("developer", "developer"),
|
|
137
|
-
message(USER_ROLE, "current user"),
|
|
138
|
-
message(ASSISTANT_ROLE, "current commentary"),
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
assert_eq!(
|
|
142
|
-
recent_input(&items),
|
|
143
|
-
Some(SearchInput::Items(vec![
|
|
144
|
-
message(USER_ROLE, "previous user"),
|
|
145
|
-
message(ASSISTANT_ROLE, "previous assistant"),
|
|
146
|
-
message(USER_ROLE, "current user"),
|
|
147
|
-
]))
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
#[test]
|
|
152
|
-
fn keeps_only_text_from_recent_user_messages() {
|
|
153
|
-
let previous_user = ResponseItem::Message {
|
|
154
|
-
id: None,
|
|
155
|
-
role: USER_ROLE.to_string(),
|
|
156
|
-
content: vec![
|
|
157
|
-
ContentItem::InputText {
|
|
158
|
-
text: "previous user".to_string(),
|
|
159
|
-
},
|
|
160
|
-
ContentItem::InputImage {
|
|
161
|
-
image_url: "data:image/png;base64,image".to_string(),
|
|
162
|
-
detail: None,
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
phase: None,
|
|
166
|
-
internal_chat_message_metadata_passthrough: None,
|
|
167
|
-
};
|
|
168
|
-
let items = vec![
|
|
169
|
-
previous_user,
|
|
170
|
-
message(ASSISTANT_ROLE, "previous assistant"),
|
|
171
|
-
message(USER_ROLE, "current user"),
|
|
172
|
-
];
|
|
173
|
-
|
|
174
|
-
assert_eq!(
|
|
175
|
-
recent_input(&items),
|
|
176
|
-
Some(SearchInput::Items(vec![
|
|
177
|
-
message(USER_ROLE, "previous user"),
|
|
178
|
-
message(ASSISTANT_ROLE, "previous assistant"),
|
|
179
|
-
message(USER_ROLE, "current user"),
|
|
180
|
-
]))
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
#[test]
|
|
185
|
-
fn ignores_contextual_user_messages_when_selecting_recent_turns() {
|
|
186
|
-
let items = vec![
|
|
187
|
-
message(USER_ROLE, "previous user"),
|
|
188
|
-
message(ASSISTANT_ROLE, "previous assistant"),
|
|
189
|
-
message(
|
|
190
|
-
USER_ROLE,
|
|
191
|
-
"<environment_context>\n<cwd>/tmp</cwd>\n</environment_context>",
|
|
192
|
-
),
|
|
193
|
-
message(USER_ROLE, "current user"),
|
|
194
|
-
];
|
|
195
|
-
|
|
196
|
-
assert_eq!(
|
|
197
|
-
recent_input(&items),
|
|
198
|
-
Some(SearchInput::Items(vec![
|
|
199
|
-
message(USER_ROLE, "previous user"),
|
|
200
|
-
message(ASSISTANT_ROLE, "previous assistant"),
|
|
201
|
-
message(USER_ROLE, "current user"),
|
|
202
|
-
]))
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
use codex_extension_api::ToolOutput;
|
|
2
|
-
use codex_extension_api::ToolPayload;
|
|
3
|
-
use codex_protocol::models::FunctionCallOutputContentItem;
|
|
4
|
-
use codex_protocol::models::FunctionCallOutputPayload;
|
|
5
|
-
use codex_protocol::models::ResponseInputItem;
|
|
6
|
-
|
|
7
|
-
pub(crate) struct SearchOutput {
|
|
8
|
-
output: String,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
impl SearchOutput {
|
|
12
|
-
pub(crate) fn new(output: String) -> Self {
|
|
13
|
-
Self { output }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
impl ToolOutput for SearchOutput {
|
|
18
|
-
fn log_preview(&self) -> String {
|
|
19
|
-
"[standalone web search output]".to_string()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
fn success_for_logging(&self) -> bool {
|
|
23
|
-
true
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
fn contains_external_context(&self) -> bool {
|
|
27
|
-
true
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
fn to_response_item(&self, call_id: &str, _payload: &ToolPayload) -> ResponseInputItem {
|
|
31
|
-
ResponseInputItem::FunctionCallOutput {
|
|
32
|
-
call_id: call_id.to_string(),
|
|
33
|
-
output: FunctionCallOutputPayload::from_content_items(vec![
|
|
34
|
-
FunctionCallOutputContentItem::InputText {
|
|
35
|
-
text: self.output.clone(),
|
|
36
|
-
},
|
|
37
|
-
]),
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
#[cfg(test)]
|
|
43
|
-
mod tests {
|
|
44
|
-
use codex_extension_api::ToolPayload;
|
|
45
|
-
use codex_protocol::models::FunctionCallOutputContentItem;
|
|
46
|
-
use codex_protocol::models::FunctionCallOutputPayload;
|
|
47
|
-
use codex_protocol::models::ResponseInputItem;
|
|
48
|
-
use pretty_assertions::assert_eq;
|
|
49
|
-
|
|
50
|
-
use super::SearchOutput;
|
|
51
|
-
use super::ToolOutput;
|
|
52
|
-
|
|
53
|
-
#[test]
|
|
54
|
-
fn emits_plaintext_function_call_output() {
|
|
55
|
-
let output = SearchOutput::new("search output".to_string());
|
|
56
|
-
|
|
57
|
-
assert_eq!(
|
|
58
|
-
output.to_response_item(
|
|
59
|
-
"call-1",
|
|
60
|
-
&ToolPayload::Function {
|
|
61
|
-
arguments: "{}".to_string(),
|
|
62
|
-
},
|
|
63
|
-
),
|
|
64
|
-
ResponseInputItem::FunctionCallOutput {
|
|
65
|
-
call_id: "call-1".to_string(),
|
|
66
|
-
output: FunctionCallOutputPayload::from_content_items(vec![
|
|
67
|
-
FunctionCallOutputContentItem::InputText {
|
|
68
|
-
text: "search output".to_string(),
|
|
69
|
-
},
|
|
70
|
-
]),
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
use codex_api::SearchCommands;
|
|
2
|
-
use schemars::r#gen::SchemaSettings;
|
|
3
|
-
use serde_json::Map;
|
|
4
|
-
use serde_json::Value;
|
|
5
|
-
|
|
6
|
-
pub(crate) fn commands_schema() -> Value {
|
|
7
|
-
let schema = SchemaSettings::draft2019_09()
|
|
8
|
-
.with(|settings| {
|
|
9
|
-
settings.inline_subschemas = true;
|
|
10
|
-
settings.option_add_null_type = false;
|
|
11
|
-
})
|
|
12
|
-
.into_generator()
|
|
13
|
-
.into_root_schema_for::<SearchCommands>();
|
|
14
|
-
let schema = match serde_json::to_value(schema) {
|
|
15
|
-
Ok(schema) => schema,
|
|
16
|
-
Err(err) => panic!("search commands schema should serialize: {err}"),
|
|
17
|
-
};
|
|
18
|
-
let Value::Object(mut schema) = schema else {
|
|
19
|
-
unreachable!("search commands schema must be an object");
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
let mut tool_schema = Map::new();
|
|
23
|
-
for key in [
|
|
24
|
-
"properties",
|
|
25
|
-
"required",
|
|
26
|
-
"type",
|
|
27
|
-
"additionalProperties",
|
|
28
|
-
"$defs",
|
|
29
|
-
"definitions",
|
|
30
|
-
] {
|
|
31
|
-
if let Some(value) = schema.remove(key) {
|
|
32
|
-
tool_schema.insert(key.to_string(), value);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
Value::Object(tool_schema)
|
|
36
|
-
}
|