@howaboua/pi-codex-web-run 0.0.4 → 0.0.5
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 +4 -0
- package/UPSTREAM_SYNC.md +6 -0
- package/package.json +3 -3
- package/src/codex-runtime/http.ts +21 -7
package/CHANGELOG.md
CHANGED
package/UPSTREAM_SYNC.md
CHANGED
|
@@ -3,3 +3,9 @@
|
|
|
3
3
|
The contract follows OpenAI Codex web search at commit b545c94041017d000e2c8b2f6272705d21b85dfb.
|
|
4
4
|
|
|
5
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.
|
|
6
|
+
|
|
7
|
+
## September 28 review
|
|
8
|
+
|
|
9
|
+
Reviewed through Codex `1b1835f751ebdc0cfc50b3fe55d4571dbb294563`; reference snapshots remain pinned to the revision above.
|
|
10
|
+
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-codex-web-run",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Codex web search and navigation for Pi, Code Mode and Notebook Mode.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@biomejs/biome": "^2.5.10",
|
|
56
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
57
|
-
"@earendil-works/pi-tui": "0.
|
|
56
|
+
"@earendil-works/pi-coding-agent": "0.99.1",
|
|
57
|
+
"@earendil-works/pi-tui": "0.99.1",
|
|
58
58
|
"@types/node": "^26.2.0",
|
|
59
59
|
"tsx": "^4.23.12",
|
|
60
60
|
"typebox": "1.3.18",
|
|
@@ -27,8 +27,7 @@ export async function fetchCodexTool(
|
|
|
27
27
|
maxResponseBytes?: number;
|
|
28
28
|
},
|
|
29
29
|
): Promise<CodexToolHttpResponse> {
|
|
30
|
-
const
|
|
31
|
-
const dispatcher = proxy ? new ProxyAgent(proxy) : undefined;
|
|
30
|
+
const dispatchers = new Map<string, ProxyAgent>();
|
|
32
31
|
let currentUrl = new URL(url);
|
|
33
32
|
let method = options.method;
|
|
34
33
|
let body = options.body;
|
|
@@ -36,6 +35,12 @@ export async function fetchCodexTool(
|
|
|
36
35
|
try {
|
|
37
36
|
for (let redirects = 0; ; redirects += 1) {
|
|
38
37
|
const chatGptRequest = isChatGptCookieUrl(currentUrl);
|
|
38
|
+
const proxy = getProxyForUrl(currentUrl.href);
|
|
39
|
+
let dispatcher = proxy ? dispatchers.get(proxy) : undefined;
|
|
40
|
+
if (proxy && !dispatcher) {
|
|
41
|
+
dispatcher = new ProxyAgent(proxy);
|
|
42
|
+
dispatchers.set(proxy, dispatcher);
|
|
43
|
+
}
|
|
39
44
|
const headers = new Headers(baseHeaders);
|
|
40
45
|
const cookieHeader = cloudflareCookies.requestHeader(currentUrl);
|
|
41
46
|
if (cookieHeader) headers.set("cookie", cookieHeader);
|
|
@@ -45,7 +50,7 @@ export async function fetchCodexTool(
|
|
|
45
50
|
...(body === undefined ? {} : { body }),
|
|
46
51
|
...(options.signal ? { signal: options.signal } : {}),
|
|
47
52
|
...(dispatcher ? { dispatcher } : {}),
|
|
48
|
-
redirect:
|
|
53
|
+
redirect: "manual",
|
|
49
54
|
});
|
|
50
55
|
if (chatGptRequest)
|
|
51
56
|
cloudflareCookies.storeResponse(
|
|
@@ -56,7 +61,7 @@ export async function fetchCodexTool(
|
|
|
56
61
|
response.status,
|
|
57
62
|
response.headers.get("location"),
|
|
58
63
|
);
|
|
59
|
-
if (!location
|
|
64
|
+
if (!location) {
|
|
60
65
|
return {
|
|
61
66
|
status: response.status,
|
|
62
67
|
statusText: response.statusText,
|
|
@@ -74,7 +79,7 @@ export async function fetchCodexTool(
|
|
|
74
79
|
);
|
|
75
80
|
}
|
|
76
81
|
const nextUrl = new URL(location, currentUrl);
|
|
77
|
-
if (!isChatGptCookieUrl(nextUrl)) {
|
|
82
|
+
if (chatGptRequest && !isChatGptCookieUrl(nextUrl)) {
|
|
78
83
|
await response.body?.cancel();
|
|
79
84
|
throw new Error(
|
|
80
85
|
"Codex tool request refused redirect outside ChatGPT: " +
|
|
@@ -84,21 +89,30 @@ export async function fetchCodexTool(
|
|
|
84
89
|
if (nextUrl.origin !== currentUrl.origin) {
|
|
85
90
|
baseHeaders.delete("authorization");
|
|
86
91
|
baseHeaders.delete("chatgpt-account-id");
|
|
92
|
+
baseHeaders.delete("cookie");
|
|
93
|
+
baseHeaders.delete("proxy-authorization");
|
|
94
|
+
baseHeaders.delete("host");
|
|
87
95
|
}
|
|
88
96
|
if (
|
|
89
|
-
response.status === 303
|
|
97
|
+
(response.status === 303 &&
|
|
98
|
+
method?.toUpperCase() !== "GET" &&
|
|
99
|
+
method?.toUpperCase() !== "HEAD") ||
|
|
90
100
|
((response.status === 301 || response.status === 302) &&
|
|
91
101
|
method?.toUpperCase() === "POST")
|
|
92
102
|
) {
|
|
93
103
|
method = "GET";
|
|
94
104
|
body = undefined;
|
|
105
|
+
baseHeaders.delete("content-encoding");
|
|
106
|
+
baseHeaders.delete("content-language");
|
|
107
|
+
baseHeaders.delete("content-location");
|
|
95
108
|
baseHeaders.delete("content-type");
|
|
109
|
+
baseHeaders.delete("content-length");
|
|
96
110
|
}
|
|
97
111
|
await response.body?.cancel();
|
|
98
112
|
currentUrl = nextUrl;
|
|
99
113
|
}
|
|
100
114
|
} finally {
|
|
101
|
-
await
|
|
115
|
+
await Promise.all([...dispatchers.values()].map((agent) => agent.close()));
|
|
102
116
|
}
|
|
103
117
|
}
|
|
104
118
|
|