@howaboua/pi-codex-web-run 0.0.7 → 0.0.9

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @howaboua/pi-codex-web-run
2
2
 
3
+ ## 0.0.9
4
+
5
+ - - Keep provider bookkeeping out of structured search results while preserving result references and content.
6
+ - Report unreadable responses and invalid tool configuration without parser or filesystem diagnostics.
7
+ - GPT mode uses note-style search-reference guidance.
8
+
9
+ ## 0.0.8
10
+
11
+ - - Added compact tool guidance for PCC GPT prompt mode. Other modes are unchanged.
12
+ - Removed unused Rust reference sources from the package download. Web search behaviour is unchanged.
13
+
3
14
  ## 0.0.7
4
15
 
5
16
  - Explain when image generation and web search need a separate legacy OpenAI Codex login rather than ChatGPT sign-in. Access failures now give concise guidance without exposing backend responses or addresses. Existing provider routing is unchanged.
@@ -17,7 +28,6 @@
17
28
  ## 0.0.4
18
29
 
19
30
  - GPT-6 Sol and Luna now share Astra's Codex support.
20
-
21
31
  - Removed `/terra`; use `/luna` instead.
22
32
  - Added Responses Lite, non-destructive reasoning changes and terse context guidance for GPT-6 Sol and Luna.
23
33
  - Image descriptions now use GPT-6 Luna directly instead of preferring older mini models.
@@ -35,6 +45,5 @@
35
45
  ## 0.0.1
36
46
 
37
47
  - Initial release of Web Run for Codex web search and page navigation in normal Pi, Code Mode, and Notebook Mode.
38
-
39
48
  - Search the web or images, open results, follow links, and find text while retaining reusable source references.
40
49
  - Use stock, renamed, or proxied Codex providers through a small JSON route file.
package/README.md CHANGED
@@ -22,11 +22,11 @@ For a proxy that renames Codex providers or models, create `pi-codex-tools.json`
22
22
 
23
23
  ```json
24
24
  {
25
- "providers": {
26
- "company-codex": {
27
- "gpt-6-luna": "company-luna"
28
- }
29
- }
25
+ "providers": {
26
+ "company-codex": {
27
+ "gpt-6-luna": "company-luna"
28
+ }
29
+ }
30
30
  }
31
31
  ```
32
32
 
package/UPSTREAM_SYNC.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  The contract follows OpenAI Codex web search at commit b545c94041017d000e2c8b2f6272705d21b85dfb.
4
4
 
5
- Reference snapshots live under upstream/. The executable implementation is TypeScript: it preserves Codex alpha/search requests, explicit search/navigation commands, proxy routing, and reusable result references without bundling the Rust client.
5
+ The upstream source is `codex-rs/ext/web-search/`, `codex-rs/codex-api/src/endpoint/search.rs` and `codex-rs/codex-api/src/search.rs` in [OpenAI Codex](https://github.com/openai/codex). Use Git at the revision above for the baseline, then compare relevant changes. `upstream/` retains attribution and the revision only. The executable implementation is TypeScript: it preserves Codex alpha/search requests, explicit search/navigation commands, proxy routing, and reusable result references without bundling the Rust client.
6
6
 
7
7
  ## September 28 review
8
8
 
9
- Reviewed through Codex `1b1835f751ebdc0cfc50b3fe55d4571dbb294563`; reference snapshots remain pinned to the revision above.
9
+ Reviewed through Codex `1b1835f751ebdc0cfc50b3fe55d4571dbb294563`; the reference baseline remains the revision above.
10
10
 
11
11
  HTTP redirects resolve proxy and `no_proxy` routing for each destination, following the route-aware transport change in `6ea62c4396`. ChatGPT redirect bounds, cookie handling and cross-origin credential stripping remain enforced. The runtime remains identical to the image-generation package's copy.
package/biome.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/2.5.10/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/2.6.3/schema.json",
3
3
  "vcs": {
4
4
  "enabled": true,
5
5
  "clientKind": "git",
package/index.ts CHANGED
@@ -19,21 +19,64 @@ export default async function webRunExtension(pi: ExtensionAPI): Promise<void> {
19
19
  promptSnippet: false,
20
20
  });
21
21
  pi.registerTool(tool);
22
- const registration = await registerWebRunInCodeMode(pi, tool);
22
+ let gpt = false;
23
+ let registration: Awaited<ReturnType<typeof registerWebRunInCodeMode>>;
24
+ const ordinary = {
25
+ description: tool.description,
26
+ guidelines: tool.promptGuidelines,
27
+ };
28
+ try {
29
+ const { registerGptPromptMode } = await import(
30
+ "@howaboua/pi-codex-conversion/prompt-mode"
31
+ );
32
+ registerGptPromptMode(pi, (active) => {
33
+ if (gpt !== active) {
34
+ gpt = active;
35
+ tool.description = active
36
+ ? "Web search/navigation"
37
+ : ordinary.description;
38
+ if (active)
39
+ tool.promptGuidelines = [
40
+ "web_run: calls=returned turn refs; final citations=Markdown result URLs; never refs/cite…",
41
+ ];
42
+ else if (ordinary.guidelines)
43
+ tool.promptGuidelines = ordinary.guidelines;
44
+ else delete tool.promptGuidelines;
45
+ pi.registerTool(tool);
46
+ registration?.refresh();
47
+ }
48
+ return [tool];
49
+ });
50
+ } catch (error) {
51
+ if (
52
+ !(error instanceof Error) ||
53
+ !("code" in error) ||
54
+ ![
55
+ "ERR_MODULE_NOT_FOUND",
56
+ "MODULE_NOT_FOUND",
57
+ "ERR_PACKAGE_PATH_NOT_EXPORTED",
58
+ ].includes(String(error.code)) ||
59
+ !error.message.includes(CODE_MODE_PACKAGE)
60
+ )
61
+ throw error;
62
+ }
63
+ registration = await registerWebRunInCodeMode(pi, tool, () => gpt);
23
64
  pi.on("session_shutdown", () => registration?.unregister());
24
65
  }
25
66
 
26
67
  async function registerWebRunInCodeMode(
27
68
  pi: ExtensionAPI,
28
69
  tool: ReturnType<typeof createWebSearchTool>,
70
+ gpt: () => boolean,
29
71
  ) {
30
72
  try {
31
73
  const { adaptToolForCodeMode, registerCodeModeExtensionTools } =
32
74
  await import(CODE_MODE_MODULE);
33
75
  return registerCodeModeExtensionTools(pi, () => [
34
76
  adaptToolForCodeMode(tool, {
35
- usage:
36
- 'await tools.web__run({search_query?:[{q:string,recency?:number,domains?:string[]}],image_query?:[{q:string}],open?:[{ref_id:string,lineno?:number}],click?:[{ref_id:string,id:number}],find?:[{ref_id:string,pattern:string}],response_length?:"short"|"medium"|"long"}) // calls use returned ref_ids; final answers use Markdown result URLs, never refs/cite markers',
77
+ usage: gpt()
78
+ ? 'await tools.web__run({search_query?:[{q:string,recency?:number,domains?:string[]}],image_query?:[{q:string}],open?:[{ref_id:string,lineno?:number}],click?:[{ref_id:string,id:number}],find?:[{ref_id:string,pattern:string}],response_length?:"short"|"medium"|"long"}) // calls=returned ref_ids; final citations=Markdown result URLs; never refs/cite markers'
79
+ : 'await tools.web__run({search_query?:[{q:string,recency?:number,domains?:string[]}],image_query?:[{q:string}],open?:[{ref_id:string,lineno?:number}],click?:[{ref_id:string,id:number}],find?:[{ref_id:string,pattern:string}],response_length?:"short"|"medium"|"long"}) // calls use returned ref_ids; final answers use Markdown result URLs, never refs/cite markers',
37
80
  promptMetadata: false,
38
81
  toolName: { namespace: "web", name: "run" },
39
82
  resultValue: webRunCodeModeResult,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-codex-web-run",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Codex web search and navigation for Pi, Code Mode and Notebook Mode.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -44,21 +44,23 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "proxy-from-env": "2.1.0",
47
- "undici": "8.10.2"
47
+ "undici": "8.12.3"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@earendil-works/pi-coding-agent": ">=1.0.0",
51
51
  "@earendil-works/pi-tui": ">=1.0.0",
52
- "typebox": "*"
52
+ "typebox": "*",
53
+ "@howaboua/pi-codex-conversion": ">=4.0.5"
53
54
  },
54
55
  "devDependencies": {
55
- "@biomejs/biome": "^2.5.10",
56
- "@earendil-works/pi-coding-agent": "1.0.4",
57
- "@earendil-works/pi-tui": "1.0.4",
58
- "@types/node": "^26.2.0",
59
- "tsx": "^4.23.12",
60
- "typebox": "1.3.18",
61
- "typescript": "^7.0.2"
56
+ "@biomejs/biome": "^2.6.3",
57
+ "@earendil-works/pi-coding-agent": "1.4.0",
58
+ "@earendil-works/pi-tui": "1.4.0",
59
+ "@types/node": "^26.6.5",
60
+ "tsx": "^4.23.15",
61
+ "typebox": "1.4.3",
62
+ "typescript": "^7.0.2",
63
+ "@howaboua/pi-codex-conversion": "4.0.5"
62
64
  },
63
65
  "pi": {
64
66
  "extensions": [
@@ -72,5 +74,10 @@
72
74
  "exports": "./index.ts",
73
75
  "publishConfig": {
74
76
  "access": "public"
77
+ },
78
+ "peerDependenciesMeta": {
79
+ "@howaboua/pi-codex-conversion": {
80
+ "optional": true
81
+ }
75
82
  }
76
83
  }
@@ -70,16 +70,15 @@ export function readCodexToolRouteConfig(
70
70
  error.code === "ENOENT"
71
71
  )
72
72
  return { providers: Object.create(null) };
73
- throw error;
73
+ throw new Error(
74
+ "Tool configuration could not be read. Ask the user to check " + path,
75
+ );
74
76
  }
75
77
  try {
76
78
  return normalizeCodexToolRouteConfig(JSON.parse(source));
77
- } catch (error) {
79
+ } catch {
78
80
  throw new Error(
79
- "Invalid pi-codex-tools config at " +
80
- path +
81
- ": " +
82
- (error instanceof Error ? error.message : String(error)),
81
+ "Tool configuration is invalid. Ask the user to check " + path,
83
82
  );
84
83
  }
85
84
  }
package/src/execute.ts CHANGED
@@ -151,7 +151,7 @@ export async function executeCodexWebSearch(
151
151
  try {
152
152
  parsed = JSON.parse(response.text);
153
153
  } catch {
154
- throw new Error("failed to decode web_run search response");
154
+ throw new Error("Web search returned an unreadable response. Try again.");
155
155
  }
156
156
  const details = normalizeSearchResponse(parsed);
157
157
  const text =
package/src/request.ts CHANGED
@@ -34,7 +34,14 @@ export function normalizeSearchResponse(value: unknown): WebRunOutput {
34
34
  typeof parsed["output_text"] === "string" ||
35
35
  Array.isArray(parsed["search_results"])
36
36
  )
37
- return parsed as WebRunOutput;
37
+ return {
38
+ ...(typeof parsed["output_text"] === "string"
39
+ ? { output_text: parsed["output_text"] }
40
+ : {}),
41
+ ...(Array.isArray(parsed["search_results"])
42
+ ? { search_results: parsed["search_results"] }
43
+ : {}),
44
+ };
38
45
  if (typeof parsed["output"] !== "string")
39
46
  throw new Error("web_run search returned no output");
40
47
  return {
@@ -1,318 +0,0 @@
1
- use crate::auth::SharedAuthProvider;
2
- use crate::endpoint::session::EndpointSession;
3
- use crate::error::ApiError;
4
- use crate::provider::Provider;
5
- use crate::search::SearchRequest;
6
- use crate::search::SearchResponse;
7
- use codex_client::HttpTransport;
8
- use codex_client::RequestTelemetry;
9
- use http::HeaderMap;
10
- use http::Method;
11
- use serde_json::to_value;
12
- use std::sync::Arc;
13
-
14
- pub struct SearchClient<T: HttpTransport> {
15
- session: EndpointSession<T>,
16
- }
17
-
18
- impl<T: HttpTransport> SearchClient<T> {
19
- pub fn new(transport: T, provider: Provider, auth: SharedAuthProvider) -> Self {
20
- Self {
21
- session: EndpointSession::new(transport, provider, auth),
22
- }
23
- }
24
-
25
- pub fn with_telemetry(self, request: Option<Arc<dyn RequestTelemetry>>) -> Self {
26
- Self {
27
- session: self.session.with_request_telemetry(request),
28
- }
29
- }
30
-
31
- fn path() -> &'static str {
32
- "alpha/search"
33
- }
34
-
35
- pub async fn search(
36
- &self,
37
- request: &SearchRequest,
38
- extra_headers: HeaderMap,
39
- ) -> Result<SearchResponse, ApiError> {
40
- let body = to_value(request)
41
- .map_err(|e| ApiError::Stream(format!("failed to encode search request: {e}")))?;
42
- let resp = self
43
- .session
44
- .execute(Method::POST, Self::path(), extra_headers, Some(body))
45
- .await?;
46
- serde_json::from_slice(&resp.body)
47
- .map_err(|e| ApiError::Stream(format!("failed to decode search response: {e}")))
48
- }
49
- }
50
-
51
- #[cfg(test)]
52
- mod tests {
53
- use super::*;
54
- use crate::auth::AuthProvider;
55
- use crate::provider::RetryConfig;
56
- use crate::search::AllowedCaller;
57
- use crate::search::ApproximateLocation;
58
- use crate::search::ExternalWebAccess;
59
- use crate::search::LocationType;
60
- use crate::search::OpenOperation;
61
- use crate::search::SearchCommands;
62
- use crate::search::SearchContextSize;
63
- use crate::search::SearchFilters;
64
- use crate::search::SearchImageSettings;
65
- use crate::search::SearchInput;
66
- use crate::search::SearchQuery;
67
- use crate::search::SearchSettings;
68
- use codex_client::Request;
69
- use codex_client::RequestBody;
70
- use codex_client::Response;
71
- use codex_client::StreamResponse;
72
- use codex_client::TransportError;
73
- use codex_protocol::ResponseItemId;
74
- use codex_protocol::models::ContentItem;
75
- use codex_protocol::models::ResponseItem;
76
- use http::StatusCode;
77
- use pretty_assertions::assert_eq;
78
- use serde_json::json;
79
- use std::sync::Mutex;
80
- use std::time::Duration;
81
-
82
- #[derive(Clone, Default)]
83
- struct DummyAuth;
84
-
85
- impl AuthProvider for DummyAuth {
86
- fn add_auth_headers(&self, _headers: &mut HeaderMap) {}
87
- }
88
-
89
- #[derive(Clone)]
90
- struct CapturingTransport {
91
- last_request: Arc<Mutex<Option<Request>>>,
92
- response_body: Arc<Vec<u8>>,
93
- }
94
-
95
- impl CapturingTransport {
96
- fn new(response_body: Vec<u8>) -> Self {
97
- Self {
98
- last_request: Arc::new(Mutex::new(None)),
99
- response_body: Arc::new(response_body),
100
- }
101
- }
102
- }
103
-
104
- impl HttpTransport for CapturingTransport {
105
- async fn execute(&self, req: Request) -> Result<Response, TransportError> {
106
- *self.last_request.lock().expect("lock request store") = Some(req);
107
- Ok(Response {
108
- status: StatusCode::OK,
109
- headers: HeaderMap::new(),
110
- body: self.response_body.as_ref().clone().into(),
111
- })
112
- }
113
-
114
- async fn stream(&self, _req: Request) -> Result<StreamResponse, TransportError> {
115
- Err(TransportError::Build("stream should not run".to_string()))
116
- }
117
- }
118
-
119
- fn provider() -> Provider {
120
- Provider {
121
- name: "test".to_string(),
122
- base_url: "https://example.com/v1".to_string(),
123
- query_params: None,
124
- headers: HeaderMap::new(),
125
- retry: RetryConfig {
126
- max_attempts: 1,
127
- base_delay: Duration::from_millis(1),
128
- retry_429: false,
129
- retry_5xx: true,
130
- retry_transport: true,
131
- },
132
- stream_idle_timeout: Duration::from_secs(1),
133
- }
134
- }
135
-
136
- #[tokio::test]
137
- async fn search_posts_typed_request_and_parses_output() {
138
- let transport = CapturingTransport::new(
139
- serde_json::to_vec(&json!({
140
- "encrypted_output": "ciphertext",
141
- "output": "search result",
142
- "results": [{
143
- "type": "text_result",
144
- "ref_id": "turn0search0",
145
- "url": "https://example.com/result",
146
- "future_field": {"preserved": true},
147
- }],
148
- }))
149
- .expect("serialize response"),
150
- );
151
- let client = SearchClient::new(transport.clone(), provider(), Arc::new(DummyAuth));
152
-
153
- let response = client
154
- .search(
155
- &SearchRequest {
156
- id: "search-session".to_string(),
157
- model: "gpt-test".to_string(),
158
- reasoning: None,
159
- input: Some(SearchInput::Items(vec![ResponseItem::Message {
160
- id: Some(ResponseItemId::with_suffix("msg", "search")),
161
- role: "user".to_string(),
162
- content: vec![
163
- ContentItem::InputText {
164
- text: "find this".to_string(),
165
- },
166
- ContentItem::InputImage {
167
- image_url: "https://example.com/image.png".to_string(),
168
- detail: None,
169
- },
170
- ],
171
- phase: None,
172
- internal_chat_message_metadata_passthrough: None,
173
- }])),
174
- commands: Some(SearchCommands {
175
- search_query: Some(vec![SearchQuery {
176
- q: "OpenAI news".to_string(),
177
- recency: Some(7),
178
- domains: Some(vec!["openai.com".to_string()]),
179
- }]),
180
- open: Some(vec![OpenOperation {
181
- ref_id: "https://openai.com".to_string(),
182
- lineno: Some(12),
183
- }]),
184
- ..Default::default()
185
- }),
186
- settings: Some(SearchSettings {
187
- user_location: Some(ApproximateLocation {
188
- r#type: LocationType::Approximate,
189
- country: Some("US".to_string()),
190
- region: None,
191
- city: Some("San Francisco".to_string()),
192
- timezone: None,
193
- }),
194
- search_context_size: Some(SearchContextSize::Low),
195
- filters: Some(SearchFilters {
196
- allowed_domains: Some(vec!["openai.com".to_string()]),
197
- blocked_domains: Some(vec!["example.com".to_string()]),
198
- }),
199
- image_settings: Some(SearchImageSettings {
200
- max_results: Some(4),
201
- caption: Some(true),
202
- }),
203
- allowed_callers: Some(vec![AllowedCaller::Direct]),
204
- external_web_access: Some(ExternalWebAccess::Boolean(true)),
205
- }),
206
- max_output_tokens: Some(2500),
207
- },
208
- HeaderMap::new(),
209
- )
210
- .await
211
- .expect("search request should succeed");
212
-
213
- assert_eq!(
214
- response,
215
- SearchResponse {
216
- encrypted_output: Some("ciphertext".to_string()),
217
- output: "search result".to_string(),
218
- results: Some(vec![json!({
219
- "type": "text_result",
220
- "ref_id": "turn0search0",
221
- "url": "https://example.com/result",
222
- "future_field": {"preserved": true},
223
- })]),
224
- }
225
- );
226
-
227
- let request = transport
228
- .last_request
229
- .lock()
230
- .expect("lock request store")
231
- .clone()
232
- .expect("request should be captured");
233
- let body = request
234
- .body
235
- .as_ref()
236
- .and_then(RequestBody::json)
237
- .expect("request body should be JSON");
238
- assert_eq!(
239
- body,
240
- &json!({
241
- "id": "search-session",
242
- "model": "gpt-test",
243
- "input": [{
244
- "type": "message",
245
- "id": "msg_search",
246
- "role": "user",
247
- "content": [
248
- {"type": "input_text", "text": "find this"},
249
- {
250
- "type": "input_image",
251
- "image_url": "https://example.com/image.png"
252
- }
253
- ]
254
- }],
255
- "commands": {
256
- "search_query": [{
257
- "q": "OpenAI news",
258
- "recency": 7,
259
- "domains": ["openai.com"]
260
- }],
261
- "open": [{"ref_id": "https://openai.com", "lineno": 12}]
262
- },
263
- "settings": {
264
- "user_location": {
265
- "type": "approximate",
266
- "country": "US",
267
- "city": "San Francisco"
268
- },
269
- "search_context_size": "low",
270
- "filters": {
271
- "allowed_domains": ["openai.com"],
272
- "blocked_domains": ["example.com"]
273
- },
274
- "image_settings": {"max_results": 4, "caption": true},
275
- "allowed_callers": ["direct"],
276
- "external_web_access": true
277
- },
278
- "max_output_tokens": 2500
279
- })
280
- );
281
- }
282
- #[test]
283
- fn search_response_defaults_missing_results_for_older_endpoints() {
284
- let response: SearchResponse = serde_json::from_value(json!({
285
- "encrypted_output": null,
286
- "output": "search result",
287
- }))
288
- .expect("response without results should deserialize");
289
-
290
- assert_eq!(
291
- response,
292
- SearchResponse {
293
- encrypted_output: None,
294
- output: "search result".to_string(),
295
- results: None,
296
- }
297
- );
298
- }
299
-
300
- #[test]
301
- fn search_response_preserves_supported_empty_results() {
302
- let response: SearchResponse = serde_json::from_value(json!({
303
- "encrypted_output": null,
304
- "output": "search result",
305
- "results": [],
306
- }))
307
- .expect("response with empty results should deserialize");
308
-
309
- assert_eq!(
310
- response,
311
- SearchResponse {
312
- encrypted_output: None,
313
- output: "search result".to_string(),
314
- results: Some(Vec::new()),
315
- }
316
- );
317
- }
318
- }