opencode-router 0.11.116 → 0.11.117
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/dist/bridge.js +33 -18
- package/package.json +1 -1
package/dist/bridge.js
CHANGED
|
@@ -1432,33 +1432,48 @@ export async function startBridge(config, logger, reporter, deps = {}) {
|
|
|
1432
1432
|
model: effectiveModel,
|
|
1433
1433
|
agent: messagingAgent.selectedAgent,
|
|
1434
1434
|
}, "prompt start");
|
|
1435
|
-
const
|
|
1436
|
-
sessionID,
|
|
1437
|
-
parts: [{ type: "text", text: promptText }],
|
|
1438
|
-
...(effectiveModel ? { model: effectiveModel } : {}),
|
|
1439
|
-
...(messagingAgent.selectedAgent ? { agent: messagingAgent.selectedAgent } : {}),
|
|
1440
|
-
});
|
|
1441
|
-
const parts = response.parts ?? [];
|
|
1442
|
-
const textParts = parts.filter((part) => part.type === "text" && !part.ignored);
|
|
1443
|
-
logger.debug({
|
|
1444
|
-
sessionID,
|
|
1445
|
-
partCount: parts.length,
|
|
1446
|
-
textCount: textParts.length,
|
|
1447
|
-
partTypes: parts.map((p) => p.type),
|
|
1448
|
-
ignoredCount: parts.filter((p) => p.ignored).length,
|
|
1449
|
-
}, "prompt response");
|
|
1450
|
-
const reply = parts
|
|
1435
|
+
const extractReply = (parts) => parts
|
|
1451
1436
|
.filter((part) => part.type === "text" && !part.ignored)
|
|
1452
1437
|
.map((part) => part.text ?? "")
|
|
1453
1438
|
.join("\n")
|
|
1454
1439
|
.trim();
|
|
1440
|
+
const logPromptResponse = (attempt, parts) => {
|
|
1441
|
+
const textParts = parts.filter((part) => part.type === "text" && !part.ignored);
|
|
1442
|
+
logger.debug({
|
|
1443
|
+
sessionID,
|
|
1444
|
+
attempt,
|
|
1445
|
+
partCount: parts.length,
|
|
1446
|
+
textCount: textParts.length,
|
|
1447
|
+
partTypes: parts.map((p) => p.type),
|
|
1448
|
+
ignoredCount: parts.filter((p) => p.ignored).length,
|
|
1449
|
+
}, "prompt response");
|
|
1450
|
+
};
|
|
1451
|
+
const runPrompt = async () => {
|
|
1452
|
+
const response = await getClient(boundDirectory).session.prompt({
|
|
1453
|
+
sessionID,
|
|
1454
|
+
parts: [{ type: "text", text: promptText }],
|
|
1455
|
+
...(effectiveModel ? { model: effectiveModel } : {}),
|
|
1456
|
+
...(messagingAgent.selectedAgent ? { agent: messagingAgent.selectedAgent } : {}),
|
|
1457
|
+
});
|
|
1458
|
+
return response.parts ?? [];
|
|
1459
|
+
};
|
|
1460
|
+
let parts = await runPrompt();
|
|
1461
|
+
logPromptResponse("initial", parts);
|
|
1462
|
+
let reply = extractReply(parts);
|
|
1463
|
+
if (!reply && !parts.some((part) => part.type === "tool")) {
|
|
1464
|
+
logger.warn({ sessionID }, "prompt returned no visible text; retrying once");
|
|
1465
|
+
parts = await runPrompt();
|
|
1466
|
+
logPromptResponse("retry", parts);
|
|
1467
|
+
reply = extractReply(parts);
|
|
1468
|
+
}
|
|
1455
1469
|
if (reply) {
|
|
1456
1470
|
logger.debug({ sessionID, replyLength: reply.length }, "reply built");
|
|
1457
1471
|
await sendText(inbound.channel, inbound.identityId, inbound.peerId, reply, { kind: "reply" });
|
|
1458
1472
|
}
|
|
1459
1473
|
else {
|
|
1460
|
-
logger.
|
|
1461
|
-
|
|
1474
|
+
logger.warn({ sessionID, partTypes: parts.map((part) => part.type), ignoredCount: parts.filter((part) => part.ignored).length }, "prompt returned no visible text; clearing session");
|
|
1475
|
+
store.deleteSession(inbound.channel, inbound.identityId, peerKey);
|
|
1476
|
+
await sendText(inbound.channel, inbound.identityId, inbound.peerId, "No visible response was generated. I reset this chat session in case stale state was blocking replies. Send your message again.", {
|
|
1462
1477
|
kind: "system",
|
|
1463
1478
|
});
|
|
1464
1479
|
}
|