openpencil/apps/web/server/utils
Fini 71cd1886f0 fix(ai): proxy dispatcher uses ESM import, actually installs in dev path
Previous version did `require('undici')` inside a try/catch on the
theory that would let it run on both CJS and ESM. In Vite/Nitro's dev
path the helper loads as an ESM module, where `require` is undefined —
the call threw `ReferenceError: require is not defined`, the catch
block silenced it, `configured=true` still got flipped, and every
subsequent call short-circuited. Net effect: the proxy was never
installed in the very dev environment the fix was meant to repair, so
image-search kept ECONNREFUSED-ing on Openverse + Wikimedia and
landing zero filled placeholders.

Switch to a static `import { setGlobalDispatcher, EnvHttpProxyAgent }
from 'undici'`. undici is a transitive dep of h3 in this workspace
(verified resolved in node_modules), and it's also the package Node 18+
uses internally for fetch — pinning it as a direct dep on apps/web
makes the resolution intentional rather than reliant on the h3 chain.

Also swapped the hand-rolled ProxyAgent for undici's built-in
`EnvHttpProxyAgent`: it reads HTTPS_PROXY / HTTP_PROXY / NO_PROXY
itself (case-insensitive) and applies the no-proxy bypass list, which
saves us from re-implementing those rules.

Verified with both `bun -e` (workspace deps) AND a direct ESM Node
context: with HTTPS_PROXY set, `fetch(api.openverse.org/...)` now
returns 240 results for "salmon sushi" instead of the earlier
ECONNREFUSED. The "configured" guard still makes calls idempotent so
multiple endpoints can opt in without coordinating.
2026-05-05 12:22:40 +08:00
..
__tests__ V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
acp-connection-manager.ts V0.7.1 (#102) 2026-04-13 21:30:23 +08:00
agent-sessions.ts V0.7.1 (#102) 2026-04-13 21:30:23 +08:00
agent-tool-guard.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
cli-resolver-helpers.ts V0.7.2-bugfix (#109) 2026-04-14 21:42:56 +08:00
codegen-plan-store.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
codex-client.ts V0.7.2-bugfix (#109) 2026-04-14 21:42:56 +08:00
copilot-client.ts V0.7.2-bugfix (#109) 2026-04-14 21:42:56 +08:00
gemini-client.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
local-asset.test.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
local-asset.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
mcp-screenshot-rpc.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
mcp-server-manager.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
mcp-sync-state.ts V0.7.2-bugfix (#109) 2026-04-14 21:42:56 +08:00
opencode-client.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
proxy-dispatcher.ts fix(ai): proxy dispatcher uses ESM import, actually installs in dev path 2026-05-05 12:22:40 +08:00
resolve-claude-agent-env.ts V0.7.2-bugfix (#109) 2026-04-14 21:42:56 +08:00
resolve-claude-cli.ts V0.7.2-bugfix (#109) 2026-04-14 21:42:56 +08:00
resolve-gemini-cli.ts V0.7.2-bugfix (#109) 2026-04-14 21:42:56 +08:00
server-logger.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
sse-keepalive.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
sse-stream.ts V0.7.0 (#95) 2026-04-11 23:25:13 +08:00