@router-for-me/pi-cliproxyapi-provider 1.4.8 → 1.4.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/README.md +1 -0
- package/extensions/index.ts +2 -0
- package/extensions/retry.ts +34 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -209,6 +209,7 @@ Disable just this helper via `pi config` if you only want the CLIProxyAPI provid
|
|
|
209
209
|
|
|
210
210
|
## Failure behavior
|
|
211
211
|
|
|
212
|
+
- CLIProxyAPI `closed network connection` responses are normalized as transient network errors so pi's agent-level retry policy reconnects and restarts the interrupted assistant turn. Completed conversation and tool results remain available; token streaming does not resume from the exact interruption point.
|
|
212
213
|
- Before setup / without credentials: provider still appears in `/login`; no models are listed yet.
|
|
213
214
|
- After successful `/login`: models are registered; credentials are stored in `auth.json` and mirrored to `cliproxyapi.json`.
|
|
214
215
|
- The built-in `/logout` command removes only the matching `auth.json` credential; environment variables and `cliproxyapi.json` are unchanged.
|
package/extensions/index.ts
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
resolveIdentity,
|
|
43
43
|
saveConfigFile,
|
|
44
44
|
} from "./lib.ts";
|
|
45
|
+
import { registerTransientNetworkErrorRetry } from "./retry.ts";
|
|
45
46
|
|
|
46
47
|
class ConfigPersistenceError extends Error {
|
|
47
48
|
constructor(cause: unknown) {
|
|
@@ -394,6 +395,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
394
395
|
streamSimple,
|
|
395
396
|
fastMode,
|
|
396
397
|
});
|
|
398
|
+
registerTransientNetworkErrorRetry(pi, identity.providerId);
|
|
397
399
|
|
|
398
400
|
const connection = resolveConnection(agentDir, identity.providerId);
|
|
399
401
|
if (!connection) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type AssistantMessage, isRetryableAssistantError } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
|
|
4
|
+
const CLOSED_NETWORK_CONNECTION_PATTERN = /\bclosed network connection\b/i;
|
|
5
|
+
const NETWORK_ERROR_PREFIX = "network error:";
|
|
6
|
+
|
|
7
|
+
export function normalizeTransientNetworkError(message: AssistantMessage): AssistantMessage {
|
|
8
|
+
if (message.stopReason !== "error" || !message.errorMessage) {
|
|
9
|
+
return message;
|
|
10
|
+
}
|
|
11
|
+
if (isRetryableAssistantError(message) || !CLOSED_NETWORK_CONNECTION_PATTERN.test(message.errorMessage)) {
|
|
12
|
+
return message;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...message,
|
|
17
|
+
errorMessage: `${NETWORK_ERROR_PREFIX} ${message.errorMessage}`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function registerTransientNetworkErrorRetry(pi: ExtensionAPI, providerId: string): void {
|
|
22
|
+
pi.on("message_end", (event) => {
|
|
23
|
+
const message = event.message;
|
|
24
|
+
if (message.role !== "assistant" || message.provider !== providerId) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const normalized = normalizeTransientNetworkError(message);
|
|
29
|
+
if (normalized === message) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
return { message: normalized };
|
|
33
|
+
});
|
|
34
|
+
}
|
package/package.json
CHANGED