opencode-lore 0.2.7 → 0.2.8
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/package.json +1 -1
- package/src/index.ts +16 -13
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -395,28 +395,31 @@ export const LorePlugin: Plugin = async (ctx) => {
|
|
|
395
395
|
// so the append-only sequence stays intact for prompt caching.
|
|
396
396
|
if (result.layer > 0) {
|
|
397
397
|
// The API requires the conversation to end with a user message.
|
|
398
|
-
// Drop trailing
|
|
399
|
-
//
|
|
400
|
-
//
|
|
401
|
-
//
|
|
398
|
+
// Drop trailing pure-text assistant messages (no tool parts), which would
|
|
399
|
+
// cause an Anthropic "does not support assistant message prefill" error.
|
|
400
|
+
//
|
|
401
|
+
// Crucially, assistant messages that contain tool parts (completed OR pending)
|
|
402
|
+
// must NOT be dropped:
|
|
403
|
+
// - Completed tool parts: OpenCode's SDK converts these into tool_result blocks
|
|
404
|
+
// sent as user-role messages at the API level. The conversation already ends
|
|
405
|
+
// with a user message — dropping would strip the entire current agentic turn
|
|
406
|
+
// and cause an infinite tool-call loop (the model restarts from scratch).
|
|
407
|
+
// - Pending tool parts: the tool call hasn't returned yet; dropping would make
|
|
408
|
+
// the model re-issue the same tool call on the next turn.
|
|
402
409
|
while (
|
|
403
410
|
result.messages.length > 0 &&
|
|
404
411
|
result.messages.at(-1)!.info.role !== "user"
|
|
405
412
|
) {
|
|
406
413
|
const last = result.messages.at(-1)!;
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
console.error(
|
|
412
|
-
"[lore] WARN: cannot drop trailing assistant message with pending tool call — may cause prefill error. id:",
|
|
413
|
-
last.info.id,
|
|
414
|
-
);
|
|
414
|
+
const hasToolParts = last.parts.some((p) => p.type === "tool");
|
|
415
|
+
if (hasToolParts) {
|
|
416
|
+
// Tool parts → tool_result (user-role) at the API level → no prefill error.
|
|
417
|
+
// Stop dropping; the conversation ends correctly as-is.
|
|
415
418
|
break;
|
|
416
419
|
}
|
|
417
420
|
const dropped = result.messages.pop()!;
|
|
418
421
|
console.error(
|
|
419
|
-
"[lore] WARN: dropping trailing",
|
|
422
|
+
"[lore] WARN: dropping trailing pure-text",
|
|
420
423
|
dropped.info.role,
|
|
421
424
|
"message to prevent prefill error. id:",
|
|
422
425
|
dropped.info.id,
|