@router-for-me/pi-cliproxyapi-provider 1.4.13 → 1.4.14

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.
@@ -13,7 +13,8 @@
13
13
  */
14
14
 
15
15
  import { createHash } from "node:crypto";
16
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
16
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
17
+ import { createRequire } from "node:module";
17
18
  import { tmpdir } from "node:os";
18
19
  import { dirname, join } from "node:path";
19
20
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -202,6 +203,21 @@ export function patchCodexSource(source: string, providerIds: string[]): string
202
203
  return src;
203
204
  }
204
205
 
206
+ export function resolveCodexModuleFromNodeEntry(entryPath: string): string | undefined {
207
+ try {
208
+ const require = createRequire(pathToFileURL(realpathSync(entryPath)));
209
+ for (const nodeModulesDir of require.resolve.paths("@earendil-works/pi-ai") ?? []) {
210
+ const candidate = join(nodeModulesDir, "@earendil-works", "pi-ai", "dist", "api", "openai-codex-responses.js");
211
+ if (existsSync(candidate)) {
212
+ return candidate;
213
+ }
214
+ }
215
+ } catch {
216
+ // Ignore invalid or unavailable runtime entrypoints.
217
+ }
218
+ return undefined;
219
+ }
220
+
205
221
  function resolveOriginalCodexModulePath(): { path: string; dir: string } {
206
222
  // Under pi's extension loader, `@earendil-works/pi-ai` may resolve to dist/compat.js
207
223
  // and package subpath resolve for `/api/*` can fail. Prefer locating the physical
@@ -224,6 +240,16 @@ function resolveOriginalCodexModulePath(): { path: string; dir: string } {
224
240
  // ignore
225
241
  }
226
242
 
243
+ // pi 0.84.3's bundled Node CLI exposes pi-ai as a virtual module to
244
+ // extensions. Resolve its physical nested dependency from the CLI entry so
245
+ // the source-patching transport can still read the installed implementation.
246
+ if (process.argv[1]) {
247
+ const bundledHostModule = resolveCodexModuleFromNodeEntry(process.argv[1]);
248
+ if (bundledHostModule) {
249
+ candidates.push(bundledHostModule);
250
+ }
251
+ }
252
+
227
253
  for (const path of candidates) {
228
254
  if (path && existsSync(path)) {
229
255
  return { path, dir: dirname(path) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@router-for-me/pi-cliproxyapi-provider",
3
- "version": "1.4.13",
3
+ "version": "1.4.14",
4
4
  "description": "Pi provider extension that auto-registers CLIProxyAPI models, plus TUI elapsed/TPS status",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@biomejs/biome": "2.5.3",
46
- "@earendil-works/pi-ai": "0.82.0",
47
- "@earendil-works/pi-coding-agent": "0.82.0",
46
+ "@earendil-works/pi-ai": "0.84.3",
47
+ "@earendil-works/pi-coding-agent": "0.84.3",
48
48
  "@types/node": "^22.15.21",
49
49
  "typescript": "6.0.3",
50
50
  "vitest": "4.1.9"