@linjz/opencode-qqbot 0.3.6 → 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 +24 -23
- package/package.json +1 -1
- package/src/bridge.ts +4 -2
- package/src/core/inflight-journal.ts +17 -11
- 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 桌面问答摘要"];
|
|
@@ -6675,19 +6676,19 @@ function classifyInflight(entry, messages) {
|
|
|
6675
6676
|
const matched = probe === "" || userText.includes(probe);
|
|
6676
6677
|
if (!matched)
|
|
6677
6678
|
return { kind: "lost" };
|
|
6678
|
-
const
|
|
6679
|
-
|
|
6679
|
+
const completed = ordered.slice(lastUserIdx + 1).some((m) => m.type === "idle");
|
|
6680
|
+
if (!completed)
|
|
6681
|
+
return { kind: "running" };
|
|
6682
|
+
for (let i = ordered.length - 1;i > lastUserIdx; i--) {
|
|
6680
6683
|
const m = ordered[i];
|
|
6681
|
-
if (m.type
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
answerParts.push(p.text.trim());
|
|
6685
|
-
}
|
|
6686
|
-
}
|
|
6687
|
-
}
|
|
6688
|
-
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(`
|
|
6689
6687
|
`).trim();
|
|
6690
|
-
|
|
6688
|
+
if (answer)
|
|
6689
|
+
return { kind: "answered", answer };
|
|
6690
|
+
}
|
|
6691
|
+
return { kind: "running" };
|
|
6691
6692
|
}
|
|
6692
6693
|
|
|
6693
6694
|
// src/bridge.ts
|
|
@@ -7207,8 +7208,8 @@ ${cls.answer}`);
|
|
|
7207
7208
|
settleInflight(entry.msgId);
|
|
7208
7209
|
console.log(`[bridge] 启动对账:已补投答案 msgId=${entry.msgId}`);
|
|
7209
7210
|
} else if (cls.kind === "running") {
|
|
7210
|
-
|
|
7211
|
-
startBackgroundWait(entry.sessionId, ctx,
|
|
7211
|
+
mirror.beginTurn(entry.sessionId);
|
|
7212
|
+
startBackgroundWait(entry.sessionId, ctx, entry.at, entry.msgId);
|
|
7212
7213
|
console.log(`[bridge] 启动对账:在途任务已重挂后台等待 msgId=${entry.msgId}`);
|
|
7213
7214
|
} else if (ageMs <= redispatchMaxAgeMs()) {
|
|
7214
7215
|
settleInflight(entry.msgId);
|
package/package.json
CHANGED
package/src/bridge.ts
CHANGED
|
@@ -740,8 +740,10 @@ export function createBridge(
|
|
|
740
740
|
settleInflight(entry.msgId)
|
|
741
741
|
console.log(`[bridge] 启动对账:已补投答案 msgId=${entry.msgId}`)
|
|
742
742
|
} else if (cls.kind === "running") {
|
|
743
|
-
|
|
744
|
-
|
|
743
|
+
// 跨重启也要保持 QQ 回合同一身份:后台直答完成时,镜像不得再投摘要。
|
|
744
|
+
mirror.beginTurn(entry.sessionId)
|
|
745
|
+
// 不单独发“仍在执行”通知;完成时统一回传最终答案,避免通知也占一条回复。
|
|
746
|
+
startBackgroundWait(entry.sessionId, ctx, entry.at, entry.msgId)
|
|
745
747
|
console.log(`[bridge] 启动对账:在途任务已重挂后台等待 msgId=${entry.msgId}`)
|
|
746
748
|
} else if (ageMs <= redispatchMaxAgeMs()) {
|
|
747
749
|
settleInflight(entry.msgId) // 旧账结清,重派回合走新账(合成 trackId)
|
|
@@ -173,8 +173,8 @@ export type InflightClass =
|
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
175
|
* 对账分类:台账条目 × 会话历史 → 该回合的真实状态。
|
|
176
|
-
* - answered
|
|
177
|
-
* - running
|
|
176
|
+
* - answered:找到该用户消息,且其后已有 idle + assistant 正文 → 完整答案在库里没投出,补投
|
|
177
|
+
* - running:找到该用户消息但尚未 idle(无论是否已有流式正文)→ 回合在跑,重挂后台等待
|
|
178
178
|
* - lost:历史里找不到该用户消息 → 消息从未到达 opencode(网关窗口丢失),重派/通知
|
|
179
179
|
* 匹配口径:历史 user 文本包含台账原文前 50 字(prompt 会加引用前缀/附件注记,不能全等)。
|
|
180
180
|
*/
|
|
@@ -198,15 +198,21 @@ export function classifyInflight(
|
|
|
198
198
|
const matched = probe === "" || userText.includes(probe)
|
|
199
199
|
if (!matched) return { kind: "lost" }
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
// 有 assistant 正文 ≠ 回合完成。流式/长任务在运行中也会产生多段正文;
|
|
202
|
+
// 必须看到该用户消息之后的 idle,才允许启动补投,否则会把半截答案提前发出。
|
|
203
|
+
const completed = ordered.slice(lastUserIdx + 1).some((m) => m.type === "idle")
|
|
204
|
+
if (!completed) return { kind: "running" }
|
|
205
|
+
|
|
206
|
+
// 与直答一致:只补投最终 assistant 正文,不把流式进度/阶段前导语重复拼入。
|
|
207
|
+
for (let i = ordered.length - 1; i > lastUserIdx; i--) {
|
|
203
208
|
const m = ordered[i]
|
|
204
|
-
if (m.type
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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 }
|
|
209
216
|
}
|
|
210
|
-
|
|
211
|
-
return answer ? { kind: "answered", answer } : { kind: "running" }
|
|
217
|
+
return { kind: "running" }
|
|
212
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 = ["📋 桌面问答摘要"]
|