@linjz/opencode-qqbot 0.3.7 → 0.3.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/dist/openqq-bot.js +19 -22
- package/package.json +1 -1
- package/src/bridge.ts +1 -1
- package/src/core/inflight-journal.ts +10 -9
- package/src/opencode/client.ts +9 -4
- package/src/opencode/mirror.ts +7 -7
package/dist/openqq-bot.js
CHANGED
|
@@ -3098,7 +3098,8 @@ var TURN_TIMEOUT_MINUTES = (() => {
|
|
|
3098
3098
|
})();
|
|
3099
3099
|
var RESPONSE_TIMEOUT_MS = TURN_TIMEOUT_MINUTES * 60 * 1000;
|
|
3100
3100
|
function collectReplyText(msgs, baseline) {
|
|
3101
|
-
|
|
3101
|
+
const latest = msgs.filter((x) => x.type === "assistant" && (x.time?.created ?? 0) >= baseline).sort((a, b) => (b.time?.created ?? 0) - (a.time?.created ?? 0)).find((x) => (x.content ?? []).some((p) => p.type === "text" && p.text?.trim()));
|
|
3102
|
+
return (latest?.content ?? []).filter((p) => p.type === "text").map((p) => p.text ?? "").join(`
|
|
3102
3103
|
`).trim();
|
|
3103
3104
|
}
|
|
3104
3105
|
var client = null;
|
|
@@ -5234,18 +5235,18 @@ function buildDigest(messages) {
|
|
|
5234
5235
|
if (lastUserIdx < 0)
|
|
5235
5236
|
return null;
|
|
5236
5237
|
const userText = (ordered[lastUserIdx].text ?? "").trim();
|
|
5237
|
-
|
|
5238
|
-
for (let i =
|
|
5238
|
+
let answer = "";
|
|
5239
|
+
for (let i = ordered.length - 1;i > lastUserIdx; i--) {
|
|
5239
5240
|
const m = ordered[i];
|
|
5240
|
-
if (m.type
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5241
|
+
if (m.type !== "assistant")
|
|
5242
|
+
continue;
|
|
5243
|
+
const parts = (m.content ?? []).filter((p) => p.type === "text" && p.text?.trim()).map((p) => p.text.trim());
|
|
5244
|
+
if (parts.length > 0) {
|
|
5245
|
+
answer = parts.join(`
|
|
5246
|
+
`).trim();
|
|
5247
|
+
break;
|
|
5245
5248
|
}
|
|
5246
5249
|
}
|
|
5247
|
-
const answer = answerParts.join(`
|
|
5248
|
-
`).trim();
|
|
5249
5250
|
if (!answer)
|
|
5250
5251
|
return null;
|
|
5251
5252
|
const lines = ["\uD83D\uDCCB 桌面问答摘要"];
|
|
@@ -6678,19 +6679,16 @@ function classifyInflight(entry, messages) {
|
|
|
6678
6679
|
const completed = ordered.slice(lastUserIdx + 1).some((m) => m.type === "idle");
|
|
6679
6680
|
if (!completed)
|
|
6680
6681
|
return { kind: "running" };
|
|
6681
|
-
|
|
6682
|
-
for (let i = lastUserIdx + 1;i < ordered.length; i++) {
|
|
6682
|
+
for (let i = ordered.length - 1;i > lastUserIdx; i--) {
|
|
6683
6683
|
const m = ordered[i];
|
|
6684
|
-
if (m.type
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
answerParts.push(p.text.trim());
|
|
6688
|
-
}
|
|
6689
|
-
}
|
|
6690
|
-
}
|
|
6691
|
-
const answer = answerParts.join(`
|
|
6684
|
+
if (m.type !== "assistant")
|
|
6685
|
+
continue;
|
|
6686
|
+
const answer = (m.content ?? []).filter((p) => p.type === "text" && p.text?.trim()).map((p) => p.text.trim()).join(`
|
|
6692
6687
|
`).trim();
|
|
6693
|
-
|
|
6688
|
+
if (answer)
|
|
6689
|
+
return { kind: "answered", answer };
|
|
6690
|
+
}
|
|
6691
|
+
return { kind: "running" };
|
|
6694
6692
|
}
|
|
6695
6693
|
|
|
6696
6694
|
// src/bridge.ts
|
|
@@ -7211,7 +7209,6 @@ ${cls.answer}`);
|
|
|
7211
7209
|
console.log(`[bridge] 启动对账:已补投答案 msgId=${entry.msgId}`);
|
|
7212
7210
|
} else if (cls.kind === "running") {
|
|
7213
7211
|
mirror.beginTurn(entry.sessionId);
|
|
7214
|
-
await deliver(ctx, "\uD83D\uDD04 重启恢复:你之前的任务仍在执行,完成即回传结果");
|
|
7215
7212
|
startBackgroundWait(entry.sessionId, ctx, entry.at, entry.msgId);
|
|
7216
7213
|
console.log(`[bridge] 启动对账:在途任务已重挂后台等待 msgId=${entry.msgId}`);
|
|
7217
7214
|
} else if (ageMs <= redispatchMaxAgeMs()) {
|
package/package.json
CHANGED
package/src/bridge.ts
CHANGED
|
@@ -742,7 +742,7 @@ export function createBridge(
|
|
|
742
742
|
} else if (cls.kind === "running") {
|
|
743
743
|
// 跨重启也要保持 QQ 回合同一身份:后台直答完成时,镜像不得再投摘要。
|
|
744
744
|
mirror.beginTurn(entry.sessionId)
|
|
745
|
-
|
|
745
|
+
// 不单独发“仍在执行”通知;完成时统一回传最终答案,避免通知也占一条回复。
|
|
746
746
|
startBackgroundWait(entry.sessionId, ctx, entry.at, entry.msgId)
|
|
747
747
|
console.log(`[bridge] 启动对账:在途任务已重挂后台等待 msgId=${entry.msgId}`)
|
|
748
748
|
} else if (ageMs <= redispatchMaxAgeMs()) {
|
|
@@ -203,15 +203,16 @@ export function classifyInflight(
|
|
|
203
203
|
const completed = ordered.slice(lastUserIdx + 1).some((m) => m.type === "idle")
|
|
204
204
|
if (!completed) return { kind: "running" }
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
for (let i =
|
|
206
|
+
// 与直答一致:只补投最终 assistant 正文,不把流式进度/阶段前导语重复拼入。
|
|
207
|
+
for (let i = ordered.length - 1; i > lastUserIdx; i--) {
|
|
208
208
|
const m = ordered[i]
|
|
209
|
-
if (m.type
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
if (m.type !== "assistant") continue
|
|
210
|
+
const answer = (m.content ?? [])
|
|
211
|
+
.filter((p) => p.type === "text" && p.text?.trim())
|
|
212
|
+
.map((p) => p.text!.trim())
|
|
213
|
+
.join("\n")
|
|
214
|
+
.trim()
|
|
215
|
+
if (answer) return { kind: "answered", answer }
|
|
214
216
|
}
|
|
215
|
-
|
|
216
|
-
return answer ? { kind: "answered", answer } : { kind: "running" }
|
|
217
|
+
return { kind: "running" }
|
|
217
218
|
}
|
package/src/opencode/client.ts
CHANGED
|
@@ -128,12 +128,17 @@ const TURN_TIMEOUT_MINUTES = (() => {
|
|
|
128
128
|
})()
|
|
129
129
|
const RESPONSE_TIMEOUT_MS = TURN_TIMEOUT_MINUTES * 60 * 1000
|
|
130
130
|
|
|
131
|
-
//
|
|
132
|
-
//
|
|
131
|
+
// 取 baseline 之后最后一个有正文的 assistant 消息,丢弃 reasoning/tool 与阶段前导语。
|
|
132
|
+
// 长回合会产生多条“正在检查/进度总结”assistant 文本;全部拼接会把过程包装成多条
|
|
133
|
+
// 相近答案。promptAndWait 与后台等待都只应交付最终回答。
|
|
133
134
|
export function collectReplyText(msgs: SessionMessage[], baseline: number): string {
|
|
134
|
-
|
|
135
|
+
const latest = msgs
|
|
135
136
|
.filter((x) => x.type === "assistant" && (x.time?.created ?? 0) >= baseline)
|
|
136
|
-
.
|
|
137
|
+
.sort((a, b) => (b.time?.created ?? 0) - (a.time?.created ?? 0))
|
|
138
|
+
.find((x) => (x.content ?? []).some((p) => p.type === "text" && p.text?.trim()))
|
|
139
|
+
return (latest?.content ?? [])
|
|
140
|
+
.filter((p) => p.type === "text")
|
|
141
|
+
.map((p) => p.text ?? "")
|
|
137
142
|
.join("\n")
|
|
138
143
|
.trim()
|
|
139
144
|
}
|
package/src/opencode/mirror.ts
CHANGED
|
@@ -34,16 +34,16 @@ export function buildDigest(messages: SessionMessage[]): string | null {
|
|
|
34
34
|
|
|
35
35
|
const userText = ((ordered[lastUserIdx] as { text?: string }).text ?? "").trim()
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
for (let i =
|
|
37
|
+
let answer = ""
|
|
38
|
+
for (let i = ordered.length - 1; i > lastUserIdx; i--) {
|
|
39
39
|
const m = ordered[i]
|
|
40
|
-
if (m.type
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
if (m.type !== "assistant") continue
|
|
41
|
+
const parts = (m.content ?? []).filter((p) => p.type === "text" && p.text?.trim()).map((p) => p.text!.trim())
|
|
42
|
+
if (parts.length > 0) {
|
|
43
|
+
answer = parts.join("\n").trim()
|
|
44
|
+
break
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
const answer = answerParts.join("\n").trim()
|
|
47
47
|
if (!answer) return null
|
|
48
48
|
|
|
49
49
|
const lines = ["📋 桌面问答摘要"]
|