@narumitw/pi-retry 0.1.2 → 0.1.4
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/LICENSE +21 -0
- package/README.md +30 -2
- package/package.json +32 -35
- package/src/unknown-error-retry.ts +53 -0
- package/biome.json +0 -6
- package/extensions/unknown-error-retry.ts +0 -53
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 narumiruna
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -14,12 +14,40 @@ Try without installing:
|
|
|
14
14
|
pi -e npm:@narumitw/pi-retry
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
Try this
|
|
17
|
+
Try this package locally from the repository root:
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
pi -e
|
|
20
|
+
pi -e ./extensions/pi-retry
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## What it does
|
|
24
24
|
|
|
25
25
|
When an assistant message ends with `stopReason: "error"` and the error message matches `Unknown error (no error details in response)`, the extension appends pi's retryable-provider-error hint so pi's built-in retry path can continue the turn.
|
|
26
|
+
|
|
27
|
+
## Package layout
|
|
28
|
+
|
|
29
|
+
```txt
|
|
30
|
+
extensions/pi-retry/
|
|
31
|
+
├── src/
|
|
32
|
+
│ └── unknown-error-retry.ts
|
|
33
|
+
├── README.md
|
|
34
|
+
├── LICENSE
|
|
35
|
+
├── tsconfig.json
|
|
36
|
+
└── package.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The package exposes its extension through `package.json`:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"pi": {
|
|
44
|
+
"extensions": ["./src/unknown-error-retry.ts"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Install this package with Pi:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pi install npm:@narumitw/pi-retry
|
|
53
|
+
```
|
package/package.json
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"@mariozechner/pi-coding-agent": "0.73.0",
|
|
35
|
-
"typescript": "6.0.3"
|
|
36
|
-
}
|
|
2
|
+
"name": "@narumitw/pi-retry",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Public pi extension that retries empty-detail provider unknown errors.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"keywords": [
|
|
9
|
+
"pi-package",
|
|
10
|
+
"pi-extension",
|
|
11
|
+
"pi",
|
|
12
|
+
"retry"
|
|
13
|
+
],
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"pi": {
|
|
20
|
+
"extensions": [
|
|
21
|
+
"./src/unknown-error-retry.ts"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"check": "biome check . && npm run typecheck",
|
|
26
|
+
"format": "biome check --write .",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@biomejs/biome": "2.4.14",
|
|
31
|
+
"@mariozechner/pi-coding-agent": "0.73.0",
|
|
32
|
+
"typescript": "6.0.3"
|
|
33
|
+
}
|
|
37
34
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
const UNKNOWN_NO_DETAILS_RE = /Unknown error \(no error details in response\)/i;
|
|
4
|
+
const RETRYABLE_HINT = "provider returned error";
|
|
5
|
+
const EXTENSION_TAG = "[unknown-error-retry]";
|
|
6
|
+
|
|
7
|
+
export default function unknownErrorRetry(pi: ExtensionAPI) {
|
|
8
|
+
pi.on("session_start", (_event, ctx) => {
|
|
9
|
+
ctx.ui.setStatus("unknown-error-retry", "unknown-error retry: on");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
pi.on("session_shutdown", (_event, ctx) => {
|
|
13
|
+
ctx.ui.setStatus("unknown-error-retry", undefined);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
pi.on("message_end", (event, ctx) => {
|
|
17
|
+
const message = event.message as unknown as {
|
|
18
|
+
role?: string;
|
|
19
|
+
stopReason?: string;
|
|
20
|
+
errorMessage?: unknown;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
if (message.role !== "assistant") return;
|
|
25
|
+
if (message.stopReason !== "error") return;
|
|
26
|
+
if (typeof message.errorMessage !== "string") return;
|
|
27
|
+
if (!UNKNOWN_NO_DETAILS_RE.test(message.errorMessage)) return;
|
|
28
|
+
|
|
29
|
+
// Avoid appending the hint repeatedly if a resumed/replayed message already has it.
|
|
30
|
+
if (message.errorMessage.includes(EXTENSION_TAG)) return;
|
|
31
|
+
|
|
32
|
+
// pi already has agent-level auto-retry for transient provider errors, but its
|
|
33
|
+
// matcher does not classify this empty-detail "Unknown error" message as retryable.
|
|
34
|
+
// Adding this hint before the message is finalized makes pi's built-in auto-retry
|
|
35
|
+
// path pick it up, remove the failed assistant message from live agent state, and
|
|
36
|
+
// call agent.continue() with the normal retry settings/backoff.
|
|
37
|
+
const errorMessage = `${message.errorMessage}\n\n${EXTENSION_TAG} ${RETRYABLE_HINT}; treating empty-detail provider failure as retryable.`;
|
|
38
|
+
|
|
39
|
+
if (ctx.hasUI) {
|
|
40
|
+
ctx.ui.notify(
|
|
41
|
+
"Matched provider 'Unknown error (no error details in response)'; letting pi auto-retry this turn.",
|
|
42
|
+
"warning",
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
message: {
|
|
48
|
+
...message,
|
|
49
|
+
errorMessage,
|
|
50
|
+
} as typeof event.message,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
package/biome.json
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
-
|
|
3
|
-
const UNKNOWN_NO_DETAILS_RE = /Unknown error \(no error details in response\)/i;
|
|
4
|
-
const RETRYABLE_HINT = "provider returned error";
|
|
5
|
-
const EXTENSION_TAG = "[unknown-error-retry]";
|
|
6
|
-
|
|
7
|
-
export default function unknownErrorRetry(pi: ExtensionAPI) {
|
|
8
|
-
pi.on("session_start", (_event, ctx) => {
|
|
9
|
-
ctx.ui.setStatus("unknown-error-retry", "unknown-error retry: on");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
pi.on("session_shutdown", (_event, ctx) => {
|
|
13
|
-
ctx.ui.setStatus("unknown-error-retry", undefined);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
pi.on("message_end", (event, ctx) => {
|
|
17
|
-
const message = event.message as unknown as {
|
|
18
|
-
role?: string;
|
|
19
|
-
stopReason?: string;
|
|
20
|
-
errorMessage?: unknown;
|
|
21
|
-
[key: string]: unknown;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
if (message.role !== "assistant") return;
|
|
25
|
-
if (message.stopReason !== "error") return;
|
|
26
|
-
if (typeof message.errorMessage !== "string") return;
|
|
27
|
-
if (!UNKNOWN_NO_DETAILS_RE.test(message.errorMessage)) return;
|
|
28
|
-
|
|
29
|
-
// Avoid appending the hint repeatedly if a resumed/replayed message already has it.
|
|
30
|
-
if (message.errorMessage.includes(EXTENSION_TAG)) return;
|
|
31
|
-
|
|
32
|
-
// pi already has agent-level auto-retry for transient provider errors, but its
|
|
33
|
-
// matcher does not classify this empty-detail "Unknown error" message as retryable.
|
|
34
|
-
// Adding this hint before the message is finalized makes pi's built-in auto-retry
|
|
35
|
-
// path pick it up, remove the failed assistant message from live agent state, and
|
|
36
|
-
// call agent.continue() with the normal retry settings/backoff.
|
|
37
|
-
const errorMessage = `${message.errorMessage}\n\n${EXTENSION_TAG} ${RETRYABLE_HINT}; treating empty-detail provider failure as retryable.`;
|
|
38
|
-
|
|
39
|
-
if (ctx.hasUI) {
|
|
40
|
-
ctx.ui.notify(
|
|
41
|
-
"Matched provider 'Unknown error (no error details in response)'; letting pi auto-retry this turn.",
|
|
42
|
-
"warning",
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
message: {
|
|
48
|
-
...message,
|
|
49
|
-
errorMessage,
|
|
50
|
-
} as typeof event.message,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
}
|