@router-for-me/pi-cliproxyapi-provider 1.4.12 → 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.
- package/extensions/codex-stream.ts +27 -1
- package/extensions/tps.ts +7 -13
- package/package.json +3 -3
|
@@ -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/extensions/tps.ts
CHANGED
|
@@ -126,9 +126,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
pi.on("agent_end", (event, ctx) => {
|
|
129
|
+
if (requestStartMs === null) return;
|
|
129
130
|
// Ignore usage from subagent / non-TUI sessions.
|
|
130
131
|
if (!isPrimaryUiSession(ctx)) return;
|
|
131
|
-
if (requestStartMs === null) return;
|
|
132
132
|
|
|
133
133
|
for (const message of event.messages) {
|
|
134
134
|
if (!isAssistantMessage(message)) continue;
|
|
@@ -141,9 +141,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
pi.on("agent_settled", (_event, ctx) => {
|
|
144
|
+
if (requestStartMs === null) return;
|
|
144
145
|
// Subagents must never clear the parent elapsed status or notify TPS.
|
|
145
146
|
if (!isPrimaryUiSession(ctx)) return;
|
|
146
|
-
if (requestStartMs === null) return;
|
|
147
147
|
|
|
148
148
|
const elapsedMs = getElapsedMs();
|
|
149
149
|
const elapsedSecondsExact = elapsedMs / 1000;
|
|
@@ -164,17 +164,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
pi.on("session_shutdown", (_event, ctx) => {
|
|
167
|
-
if (statusCtx !== ctx && !isPrimaryUiSession(ctx)) return;
|
|
168
|
-
|
|
169
167
|
clearRefreshTimer();
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
pausedDurationAtStartMs = 0;
|
|
176
|
-
pauseWasEnabledAtStart = false;
|
|
177
|
-
statusCtx = null;
|
|
178
|
-
}
|
|
168
|
+
clearStatus(ctx);
|
|
169
|
+
requestStartMs = null;
|
|
170
|
+
pausedDurationAtStartMs = 0;
|
|
171
|
+
pauseWasEnabledAtStart = false;
|
|
172
|
+
statusCtx = null;
|
|
179
173
|
});
|
|
180
174
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@router-for-me/pi-cliproxyapi-provider",
|
|
3
|
-
"version": "1.4.
|
|
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.
|
|
47
|
-
"@earendil-works/pi-coding-agent": "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"
|