@juicesharp/rpiv-advisor 2.14.2 → 2.15.0

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.
@@ -31,7 +31,7 @@ import {
31
31
  errNoApiKeyDetail,
32
32
  msgConsulting,
33
33
  } from "./messages.ts";
34
- import { getRuntimeCompleteSimple, loadCompleteSimple } from "./pi-compat.ts";
34
+ import { getRuntimeCompleteSimple, loadCompleteSimple, withHostRetry } from "./pi-compat.ts";
35
35
  import { ADVISOR_SYSTEM_PROMPT } from "./prompt.ts";
36
36
  import { getAdvisorEffort, getAdvisorModel } from "./state.ts";
37
37
 
@@ -162,13 +162,18 @@ export async function executeAdvisor(
162
162
  // `requestOptions`, so the retry cannot diverge from attempt 1. `tools: []`
163
163
  // plus stripToolDeclarations keeps the "never calls tools" contract: on
164
164
  // Pi >= 1.0 the transcript's system messages declare tools of their own.
165
+ // A transient provider error is retried under Pi's retry settings first.
165
166
  const callAdvisor = (): Promise<AssistantMessage> =>
166
- completeSimple(advisor, { systemPrompt: ADVISOR_SYSTEM_PROMPT, messages, tools: [] }, requestOptions);
167
+ withHostRetry(
168
+ pi,
169
+ () => completeSimple(advisor, { systemPrompt: ADVISOR_SYSTEM_PROMPT, messages, tools: [] }, requestOptions),
170
+ signal,
171
+ );
167
172
 
168
173
  // Build the terminal envelope for an aborted/error stopReason, or return
169
174
  // undefined when the attempt produced a normal stop whose text (or lack of
170
175
  // text) the caller must still resolve. Aborted/error short-circuit and are
171
- // NEVER retried — they are not the empty-response class R6.4 targets.
176
+ // never given the empty-response retry — they are not the class R6.4 targets.
172
177
  const stopReasonEnvelope = (r: AssistantMessage): AgentToolResult<AdvisorDetails> | undefined => {
173
178
  if (r.stopReason === "aborted") {
174
179
  return buildAdvisorResult({
@@ -195,7 +200,7 @@ export async function executeAdvisor(
195
200
 
196
201
  let response = await callAdvisor();
197
202
 
198
- // Aborted/error short-circuit on the first attempt — no retry.
203
+ // Aborted/error short-circuit on the first attempt — no empty-response retry.
199
204
  const firstTerminal = stopReasonEnvelope(response);
200
205
  if (firstTerminal) return firstTerminal;
201
206
 
@@ -16,7 +16,11 @@
16
16
  * migration); when that lands, this module is the single place to migrate.
17
17
  */
18
18
 
19
+ import type { AssistantMessage } from "@earendil-works/pi-ai";
20
+ import { type ExtensionAPI, SettingsManager } from "@earendil-works/pi-coding-agent";
21
+
19
22
  type CompleteSimpleFn = typeof import("@earendil-works/pi-ai/compat").completeSimple;
23
+ type RetryAssistantCallFn = typeof import("@earendil-works/pi-ai").retryAssistantCall;
20
24
 
21
25
  /**
22
26
  * Resolve Pi's auth-aware completion facade when the host exposes one.
@@ -88,3 +92,23 @@ export async function loadCompleteSimple(): Promise<CompleteSimpleFn> {
88
92
  }
89
93
  return completeSimple;
90
94
  }
95
+
96
+ /**
97
+ * Run an advisor call under pi-ai's bounded retry for transient provider errors
98
+ * (overloaded, rate-limited, network), using the user's Pi `retry` settings —
99
+ * the policy Pi applies to its own side calls such as compaction. Hosts below
100
+ * Pi 1.0 have neither `retryAssistantCall` nor `pi.getSettings()`, so the call
101
+ * runs once.
102
+ */
103
+ export async function withHostRetry(
104
+ pi: ExtensionAPI,
105
+ call: () => Promise<AssistantMessage>,
106
+ signal: AbortSignal | undefined,
107
+ ): Promise<AssistantMessage> {
108
+ const { retryAssistantCall } = (await import("@earendil-works/pi-ai")) as {
109
+ retryAssistantCall?: RetryAssistantCallFn;
110
+ };
111
+ const settings = (pi as Partial<Pick<ExtensionAPI, "getSettings">>).getSettings?.call(pi);
112
+ if (typeof retryAssistantCall !== "function" || settings === undefined) return call();
113
+ return retryAssistantCall(call, SettingsManager.inMemory(settings).getRetrySettings(), signal);
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-advisor",
3
- "version": "2.14.2",
3
+ "version": "2.15.0",
4
4
  "description": "Pi extension. A second opinion the model can request from a stronger reviewer model before it acts.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -47,7 +47,7 @@
47
47
  ]
48
48
  },
49
49
  "dependencies": {
50
- "@juicesharp/rpiv-config": "^2.14.2"
50
+ "@juicesharp/rpiv-config": "^2.15.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@earendil-works/pi-ai": "*",