@juicesharp/rpiv-advisor 1.0.16 → 1.0.18
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/advisor.ts +15 -21
- package/package.json +1 -1
package/advisor.ts
CHANGED
|
@@ -61,11 +61,7 @@ const CHECKMARK = " ✓";
|
|
|
61
61
|
// Messages (static)
|
|
62
62
|
const MSG_ADVISOR_DISABLED = "Advisor disabled";
|
|
63
63
|
const MSG_REQUIRES_INTERACTIVE = "/advisor requires interactive mode";
|
|
64
|
-
|
|
65
|
-
// User-tail nudge — appended when stripping leaves an assistant tail (some
|
|
66
|
-
// providers, e.g. recent Anthropic models, reject payloads not ending with
|
|
67
|
-
// a user message: "This model does not support assistant message prefill.").
|
|
68
|
-
const ADVISOR_NUDGE_TEXT = "Please advise on the executor's situation above.";
|
|
64
|
+
const MSG_ADVISOR_NUDGE = "Please advise on the executor's situation above.";
|
|
69
65
|
|
|
70
66
|
// Errors (static)
|
|
71
67
|
const ERR_NO_MODEL = "No advisor model is configured. The user can enable one with the /advisor command.";
|
|
@@ -211,23 +207,21 @@ export function stripInflightAdvisorCall(messages: Message[]): Message[] {
|
|
|
211
207
|
return [...messages.slice(0, -1), { ...last, content: filtered }];
|
|
212
208
|
}
|
|
213
209
|
|
|
214
|
-
// Some providers (recent Anthropic Claude models) reject payloads
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
// (e.g. the executor wrote thinking text before
|
|
218
|
-
// minimal user-role nudge
|
|
219
|
-
export function
|
|
210
|
+
// Some providers (recent Anthropic Claude models) reject payloads ending on an
|
|
211
|
+
// assistant turn ("This model does not support assistant message prefill. The
|
|
212
|
+
// conversation must end with a user message."). After stripInflightAdvisorCall
|
|
213
|
+
// the tail can be assistant (e.g. the executor wrote thinking text before
|
|
214
|
+
// calling advisor). Append a minimal user-role nudge to guarantee user-tail.
|
|
215
|
+
export function ensureUserTailForAdvisor(messages: Message[]): Message[] {
|
|
220
216
|
if (messages.length === 0) return messages;
|
|
221
217
|
const last = messages[messages.length - 1];
|
|
222
|
-
if (last.role
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
{
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
},
|
|
230
|
-
];
|
|
218
|
+
if (last.role !== "assistant") return messages;
|
|
219
|
+
const nudge: Message = {
|
|
220
|
+
role: "user",
|
|
221
|
+
content: [{ type: "text", text: MSG_ADVISOR_NUDGE }],
|
|
222
|
+
timestamp: Date.now(),
|
|
223
|
+
};
|
|
224
|
+
return [...messages, nudge];
|
|
231
225
|
}
|
|
232
226
|
|
|
233
227
|
// Returns `undefined` when the registry is empty (no extensions loaded) so
|
|
@@ -361,7 +355,7 @@ async function executeAdvisor(
|
|
|
361
355
|
const agentMessages = branch
|
|
362
356
|
.filter((e): e is SessionEntry & { type: "message" } => e.type === "message")
|
|
363
357
|
.map((e) => e.message);
|
|
364
|
-
const branchMessages =
|
|
358
|
+
const branchMessages = ensureUserTailForAdvisor(stripInflightAdvisorCall(convertToLlm(agentMessages)));
|
|
365
359
|
const inventoryMessage = getInventoryMessage(pi.getAllTools());
|
|
366
360
|
const messages: Message[] = inventoryMessage ? [inventoryMessage, ...branchMessages] : branchMessages;
|
|
367
361
|
|