@howaboua/pi-codex-web-run 0.0.7 → 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 +5 -0
- package/UPSTREAM_SYNC.md +2 -2
- package/biome.json +1 -1
- package/index.ts +46 -3
- package/package.json +17 -10
- 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,305 +0,0 @@
|
|
|
1
|
-
use crate::common::Reasoning;
|
|
2
|
-
use codex_protocol::models::ResponseItem;
|
|
3
|
-
use schemars::JsonSchema;
|
|
4
|
-
use serde::Deserialize;
|
|
5
|
-
use serde::Serialize;
|
|
6
|
-
use serde_json::Value as JsonValue;
|
|
7
|
-
|
|
8
|
-
#[derive(Debug, Clone, Serialize, PartialEq)]
|
|
9
|
-
pub struct SearchRequest {
|
|
10
|
-
pub id: String,
|
|
11
|
-
pub model: String,
|
|
12
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
13
|
-
pub reasoning: Option<Reasoning>,
|
|
14
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
15
|
-
pub input: Option<SearchInput>,
|
|
16
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
17
|
-
pub commands: Option<SearchCommands>,
|
|
18
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
19
|
-
pub settings: Option<SearchSettings>,
|
|
20
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
21
|
-
pub max_output_tokens: Option<u64>,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
#[derive(Debug, Clone, Serialize, PartialEq)]
|
|
25
|
-
#[serde(untagged)]
|
|
26
|
-
pub enum SearchInput {
|
|
27
|
-
Text(String),
|
|
28
|
-
Items(Vec<ResponseItem>),
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, JsonSchema)]
|
|
32
|
-
pub struct SearchCommands {
|
|
33
|
-
/// Query the internet search engine for a given list of queries.
|
|
34
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
35
|
-
pub search_query: Option<Vec<SearchQuery>>,
|
|
36
|
-
/// Query the image search engine for a given list of queries.
|
|
37
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
38
|
-
pub image_query: Option<Vec<SearchQuery>>,
|
|
39
|
-
/// Open pages by reference id or URL.
|
|
40
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
41
|
-
pub open: Option<Vec<OpenOperation>>,
|
|
42
|
-
/// Open links from previously opened pages.
|
|
43
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
44
|
-
pub click: Option<Vec<ClickOperation>>,
|
|
45
|
-
/// Find text patterns in pages.
|
|
46
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
47
|
-
pub find: Option<Vec<FindOperation>>,
|
|
48
|
-
/// Take screenshots of PDF pages.
|
|
49
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
50
|
-
pub screenshot: Option<Vec<ScreenshotOperation>>,
|
|
51
|
-
/// Look up prices for the given stock symbols.
|
|
52
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
53
|
-
pub finance: Option<Vec<FinanceOperation>>,
|
|
54
|
-
/// Look up weather forecasts.
|
|
55
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
56
|
-
pub weather: Option<Vec<WeatherOperation>>,
|
|
57
|
-
/// Look up sports schedules and standings.
|
|
58
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
59
|
-
pub sports: Option<Vec<SportsOperation>>,
|
|
60
|
-
/// Get time for the given UTC offsets.
|
|
61
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
62
|
-
pub time: Option<Vec<TimeOperation>>,
|
|
63
|
-
/// Set the length of the response to be returned.
|
|
64
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
65
|
-
pub response_length: Option<SearchResponseLength>,
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
|
|
69
|
-
pub struct SearchQuery {
|
|
70
|
-
/// Search query.
|
|
71
|
-
pub q: String,
|
|
72
|
-
/// Whether to filter by recency, as a number of recent days.
|
|
73
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
74
|
-
pub recency: Option<u64>,
|
|
75
|
-
/// Whether to filter by a specific list of domains.
|
|
76
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
77
|
-
pub domains: Option<Vec<String>>,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
|
|
81
|
-
pub struct OpenOperation {
|
|
82
|
-
/// Reference id or URL to open.
|
|
83
|
-
pub ref_id: String,
|
|
84
|
-
/// Line number to position the page at.
|
|
85
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
86
|
-
pub lineno: Option<u64>,
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
90
|
-
pub struct ClickOperation {
|
|
91
|
-
/// Reference id containing the numbered link.
|
|
92
|
-
pub ref_id: String,
|
|
93
|
-
/// Numbered link id to open.
|
|
94
|
-
pub id: u64,
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
98
|
-
pub struct FindOperation {
|
|
99
|
-
/// Reference id or URL to search within.
|
|
100
|
-
pub ref_id: String,
|
|
101
|
-
/// Text pattern to find.
|
|
102
|
-
pub pattern: String,
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
106
|
-
pub struct ScreenshotOperation {
|
|
107
|
-
/// Reference id or URL to screenshot.
|
|
108
|
-
pub ref_id: String,
|
|
109
|
-
/// Zero-indexed PDF page number.
|
|
110
|
-
pub pageno: u64,
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
|
|
114
|
-
pub struct FinanceOperation {
|
|
115
|
-
/// Ticker symbol to look up.
|
|
116
|
-
pub ticker: String,
|
|
117
|
-
/// Asset type to look up.
|
|
118
|
-
pub r#type: FinanceAssetType,
|
|
119
|
-
/// ISO 3166-1 alpha-3 country code, "OTC", or "" for cryptocurrency.
|
|
120
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
121
|
-
pub market: Option<String>,
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
125
|
-
#[serde(rename_all = "lowercase")]
|
|
126
|
-
pub enum FinanceAssetType {
|
|
127
|
-
Equity,
|
|
128
|
-
Fund,
|
|
129
|
-
Crypto,
|
|
130
|
-
Index,
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
|
|
134
|
-
pub struct WeatherOperation {
|
|
135
|
-
/// Location in "Country, Area, City" format.
|
|
136
|
-
pub location: String,
|
|
137
|
-
/// Start date in YYYY-MM-DD format. Defaults to today.
|
|
138
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
139
|
-
pub start: Option<String>,
|
|
140
|
-
/// Number of days to return. Defaults to 7.
|
|
141
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
142
|
-
pub duration: Option<u64>,
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
|
|
146
|
-
pub struct SportsOperation {
|
|
147
|
-
/// Tool name for sports requests.
|
|
148
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
149
|
-
pub tool: Option<SportsToolName>,
|
|
150
|
-
/// Sports function to call.
|
|
151
|
-
pub r#fn: SportsFunction,
|
|
152
|
-
/// League to look up.
|
|
153
|
-
pub league: SportsLeague,
|
|
154
|
-
/// Team to look up, using the common 3 or 4 letter alias used in broadcasts.
|
|
155
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
156
|
-
pub team: Option<String>,
|
|
157
|
-
/// Opponent to use with `team` when narrowing the lookup.
|
|
158
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
159
|
-
pub opponent: Option<String>,
|
|
160
|
-
/// Start date in YYYY-MM-DD format.
|
|
161
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
162
|
-
pub date_from: Option<String>,
|
|
163
|
-
/// End date in YYYY-MM-DD format.
|
|
164
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
165
|
-
pub date_to: Option<String>,
|
|
166
|
-
/// Number of games to return.
|
|
167
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
168
|
-
pub num_games: Option<u64>,
|
|
169
|
-
/// Locale for the lookup.
|
|
170
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
171
|
-
pub locale: Option<String>,
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
175
|
-
#[serde(rename_all = "lowercase")]
|
|
176
|
-
pub enum SportsToolName {
|
|
177
|
-
Sports,
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
181
|
-
#[serde(rename_all = "lowercase")]
|
|
182
|
-
pub enum SportsFunction {
|
|
183
|
-
Schedule,
|
|
184
|
-
Standings,
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
188
|
-
#[serde(rename_all = "lowercase")]
|
|
189
|
-
pub enum SportsLeague {
|
|
190
|
-
Nba,
|
|
191
|
-
Wnba,
|
|
192
|
-
Nfl,
|
|
193
|
-
Nhl,
|
|
194
|
-
Mlb,
|
|
195
|
-
Epl,
|
|
196
|
-
Ncaamb,
|
|
197
|
-
Ncaawb,
|
|
198
|
-
Ipl,
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
202
|
-
pub struct TimeOperation {
|
|
203
|
-
/// UTC offset formatted like "+03:00".
|
|
204
|
-
pub utc_offset: String,
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
208
|
-
#[serde(rename_all = "lowercase")]
|
|
209
|
-
pub enum SearchResponseLength {
|
|
210
|
-
Short,
|
|
211
|
-
Medium,
|
|
212
|
-
Long,
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
216
|
-
#[serde(rename_all = "snake_case")]
|
|
217
|
-
pub enum ExternalWebAccessMode {
|
|
218
|
-
Cached,
|
|
219
|
-
Indexed,
|
|
220
|
-
Live,
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
224
|
-
#[serde(untagged)]
|
|
225
|
-
pub enum ExternalWebAccess {
|
|
226
|
-
Boolean(bool),
|
|
227
|
-
Mode(ExternalWebAccessMode),
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
|
231
|
-
pub struct SearchSettings {
|
|
232
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
233
|
-
pub user_location: Option<ApproximateLocation>,
|
|
234
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
235
|
-
pub search_context_size: Option<SearchContextSize>,
|
|
236
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
237
|
-
pub filters: Option<SearchFilters>,
|
|
238
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
239
|
-
pub image_settings: Option<SearchImageSettings>,
|
|
240
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
241
|
-
pub allowed_callers: Option<Vec<AllowedCaller>>,
|
|
242
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
243
|
-
pub external_web_access: Option<ExternalWebAccess>,
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
247
|
-
pub struct ApproximateLocation {
|
|
248
|
-
pub r#type: LocationType,
|
|
249
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
250
|
-
pub country: Option<String>,
|
|
251
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
252
|
-
pub region: Option<String>,
|
|
253
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
254
|
-
pub city: Option<String>,
|
|
255
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
256
|
-
pub timezone: Option<String>,
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
|
260
|
-
#[serde(rename_all = "lowercase")]
|
|
261
|
-
pub enum LocationType {
|
|
262
|
-
Approximate,
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
|
266
|
-
#[serde(rename_all = "lowercase")]
|
|
267
|
-
pub enum SearchContextSize {
|
|
268
|
-
Low,
|
|
269
|
-
Medium,
|
|
270
|
-
High,
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
|
274
|
-
pub struct SearchFilters {
|
|
275
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
276
|
-
pub allowed_domains: Option<Vec<String>>,
|
|
277
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
278
|
-
pub blocked_domains: Option<Vec<String>>,
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
|
282
|
-
pub struct SearchImageSettings {
|
|
283
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
284
|
-
pub max_results: Option<u64>,
|
|
285
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
286
|
-
pub caption: Option<bool>,
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
|
290
|
-
#[serde(rename_all = "snake_case")]
|
|
291
|
-
pub enum AllowedCaller {
|
|
292
|
-
Direct,
|
|
293
|
-
Shell,
|
|
294
|
-
CodeInterpreter,
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
|
298
|
-
pub struct SearchResponse {
|
|
299
|
-
pub encrypted_output: Option<String>,
|
|
300
|
-
pub output: String,
|
|
301
|
-
/// Structured result DTOs are passed to clients out-of-band from `output`.
|
|
302
|
-
/// Keep them opaque here so newer result variants remain forward-compatible.
|
|
303
|
-
#[serde(default)]
|
|
304
|
-
pub results: Option<Vec<JsonValue>>,
|
|
305
|
-
}
|
|
@@ -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
|
-
}
|