@router-for-me/pi-cliproxyapi-provider 1.4.8 → 1.4.10
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 +5 -4
- package/extensions/index.ts +2 -0
- package/extensions/retry.ts +35 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ You can still configure without `/login`.
|
|
|
91
91
|
Optional fields:
|
|
92
92
|
|
|
93
93
|
| Field | Default | Description |
|
|
94
|
-
|
|
94
|
+
| ------- | --------- | ------------- |
|
|
95
95
|
| `baseUrl` | `http://127.0.0.1:8317` | CLIProxyAPI address |
|
|
96
96
|
| `apiKey` | _(required unless set via /login or env)_ | Bearer token / CPA API key |
|
|
97
97
|
| `providerId` | `cliproxyapi` | Provider id shown in `/model` |
|
|
@@ -101,7 +101,7 @@ Optional fields:
|
|
|
101
101
|
### Environment overrides
|
|
102
102
|
|
|
103
103
|
| Variable | Overrides |
|
|
104
|
-
|
|
104
|
+
| ---------- | ----------- |
|
|
105
105
|
| `CLIPROXYAPI_BASE_URL` | `baseUrl` |
|
|
106
106
|
| `CLIPROXYAPI_API_KEY` | `apiKey` |
|
|
107
107
|
| `CLIPROXYAPI_PROVIDER_ID` | `providerId` |
|
|
@@ -122,7 +122,7 @@ The Fast preference resolves separately as `CLIPROXYAPI_FAST` → `cliproxyapi.j
|
|
|
122
122
|
Preferred form is **host:port only**:
|
|
123
123
|
|
|
124
124
|
| Input | Inference baseUrl | Models URL |
|
|
125
|
-
|
|
125
|
+
| ------- | ------------------- | ------------ |
|
|
126
126
|
| `http://127.0.0.1:8317` | `http://127.0.0.1:8317/backend-api/` | `http://127.0.0.1:8317/v1/models?client_version=pi` |
|
|
127
127
|
| `http://127.0.0.1:8317/backend-api` | `http://127.0.0.1:8317/backend-api/` | same models URL |
|
|
128
128
|
| `http://127.0.0.1:8317/v1` | `http://127.0.0.1:8317/backend-api/` | same models URL |
|
|
@@ -179,7 +179,7 @@ In the TUI footer, CLIProxyAPI context usage also uses this effective threshold
|
|
|
179
179
|
From CPA catalog entry → pi model:
|
|
180
180
|
|
|
181
181
|
| CPA field | Pi field |
|
|
182
|
-
|
|
182
|
+
| ----------- | ---------- |
|
|
183
183
|
| `slug` | `id` |
|
|
184
184
|
| `display_name` | `name` |
|
|
185
185
|
| `context_window` | `contextWindow` |
|
|
@@ -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,35 @@
|
|
|
1
|
+
import { type AssistantMessage, isRetryableAssistantError } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
|
|
4
|
+
const TRANSIENT_STREAM_ERROR_PATTERN =
|
|
5
|
+
/\bclosed network connection\b|\bstream disconnected before completion: stream closed before response\.completed\b|\binvalid SSE data JSON\b/i;
|
|
6
|
+
const NETWORK_ERROR_PREFIX = "network error:";
|
|
7
|
+
|
|
8
|
+
export function normalizeTransientNetworkError(message: AssistantMessage): AssistantMessage {
|
|
9
|
+
if (message.stopReason !== "error" || !message.errorMessage) {
|
|
10
|
+
return message;
|
|
11
|
+
}
|
|
12
|
+
if (isRetryableAssistantError(message) || !TRANSIENT_STREAM_ERROR_PATTERN.test(message.errorMessage)) {
|
|
13
|
+
return message;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
...message,
|
|
18
|
+
errorMessage: `${NETWORK_ERROR_PREFIX} ${message.errorMessage}`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function registerTransientNetworkErrorRetry(pi: ExtensionAPI, providerId: string): void {
|
|
23
|
+
pi.on("message_end", (event) => {
|
|
24
|
+
const message = event.message;
|
|
25
|
+
if (message.role !== "assistant" || message.provider !== providerId) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const normalized = normalizeTransientNetworkError(message);
|
|
30
|
+
if (normalized === message) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
return { message: normalized };
|
|
34
|
+
});
|
|
35
|
+
}
|
package/package.json
CHANGED