@linjz/opencode-qqbot 0.3.10 → 0.3.11

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.
@@ -6732,24 +6732,36 @@ function pendingInflight() {
6732
6732
  }
6733
6733
  function classifyInflight(entry, messages) {
6734
6734
  const ordered = [...messages].reverse();
6735
- let lastUserIdx = -1;
6736
- for (let i = ordered.length - 1;i >= 0; i--) {
6735
+ const probe = entry.text.trim().slice(0, 50);
6736
+ let userIdx = -1;
6737
+ if (probe === "") {
6738
+ for (let i = ordered.length - 1;i >= 0; i--) {
6739
+ if (ordered[i].type === "user") {
6740
+ userIdx = i;
6741
+ break;
6742
+ }
6743
+ }
6744
+ } else {
6745
+ for (let i = ordered.length - 1;i >= 0; i--) {
6746
+ if (ordered[i].type === "user" && (ordered[i].text ?? "").includes(probe)) {
6747
+ userIdx = i;
6748
+ break;
6749
+ }
6750
+ }
6751
+ }
6752
+ if (userIdx < 0)
6753
+ return { kind: "lost" };
6754
+ let turnEnd = ordered.length;
6755
+ for (let i = userIdx + 1;i < ordered.length; i++) {
6737
6756
  if (ordered[i].type === "user") {
6738
- lastUserIdx = i;
6757
+ turnEnd = i;
6739
6758
  break;
6740
6759
  }
6741
6760
  }
6742
- if (lastUserIdx < 0)
6743
- return { kind: "lost" };
6744
- const userText = (ordered[lastUserIdx].text ?? "").trim();
6745
- const probe = entry.text.trim().slice(0, 50);
6746
- const matched = probe === "" || userText.includes(probe);
6747
- if (!matched)
6748
- return { kind: "lost" };
6749
- const completed = ordered.slice(lastUserIdx + 1).some((m) => m.type === "idle");
6761
+ const completed = ordered.slice(userIdx + 1, turnEnd).some((m) => m.type === "idle");
6750
6762
  if (!completed)
6751
6763
  return { kind: "running" };
6752
- for (let i = ordered.length - 1;i > lastUserIdx; i--) {
6764
+ for (let i = turnEnd - 1;i > userIdx; i--) {
6753
6765
  const m = ordered[i];
6754
6766
  if (m.type !== "assistant")
6755
6767
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linjz/opencode-qqbot",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "type": "module",
5
5
  "description": "QQ Bot for OpenCode AI - chat with AI coding assistant via QQ",
6
6
  "exports": {
@@ -183,28 +183,44 @@ export function classifyInflight(
183
183
  messages: HistoryMessage[],
184
184
  ): InflightClass {
185
185
  const ordered = [...messages].reverse()
186
- let lastUserIdx = -1
187
- for (let i = ordered.length - 1; i >= 0; i--) {
186
+ const probe = entry.text.trim().slice(0, 50)
187
+ let userIdx = -1
188
+ if (probe === "") {
189
+ // 纯附件没有文本锚,只能沿用最新用户消息,由 idle/答案状态兜底。
190
+ for (let i = ordered.length - 1; i >= 0; i--) {
191
+ if (ordered[i].type === "user") {
192
+ userIdx = i
193
+ break
194
+ }
195
+ }
196
+ } else {
197
+ // 长任务期间可能出现更新用户消息;必须按原文找回原回合,不能只查最后一条,
198
+ // 否则会把已到达的旧消息误判为 lost 并再次派发给 LLM。
199
+ for (let i = ordered.length - 1; i >= 0; i--) {
200
+ if (ordered[i].type === "user" && (ordered[i].text ?? "").includes(probe)) {
201
+ userIdx = i
202
+ break
203
+ }
204
+ }
205
+ }
206
+ if (userIdx < 0) return { kind: "lost" }
207
+
208
+ // 回合边界 = 原用户消息之后、下一条用户消息之前。后续新回合的 idle/答案
209
+ // 不能拿来给原回合销账。
210
+ let turnEnd = ordered.length
211
+ for (let i = userIdx + 1; i < ordered.length; i++) {
188
212
  if (ordered[i].type === "user") {
189
- lastUserIdx = i
213
+ turnEnd = i
190
214
  break
191
215
  }
192
216
  }
193
- if (lastUserIdx < 0) return { kind: "lost" }
194
-
195
- const userText = (ordered[lastUserIdx].text ?? "").trim()
196
- const probe = entry.text.trim().slice(0, 50)
197
- // 纯附件消息(无文字)无法文本匹配——探针为空视为匹配(由 answered 判定兜底)
198
- const matched = probe === "" || userText.includes(probe)
199
- if (!matched) return { kind: "lost" }
200
217
 
201
- // 有 assistant 正文 ≠ 回合完成。流式/长任务在运行中也会产生多段正文;
202
- // 必须看到该用户消息之后的 idle,才允许启动补投,否则会把半截答案提前发出。
203
- const completed = ordered.slice(lastUserIdx + 1).some((m) => m.type === "idle")
218
+ // 有 assistant 正文 ≠ 回合完成。必须在该回合边界内看到 idle,才允许补投。
219
+ const completed = ordered.slice(userIdx + 1, turnEnd).some((m) => m.type === "idle")
204
220
  if (!completed) return { kind: "running" }
205
221
 
206
- // 与直答一致:只补投最终 assistant 正文,不把流式进度/阶段前导语重复拼入。
207
- for (let i = ordered.length - 1; i > lastUserIdx; i--) {
222
+ // 与直答一致:只补投该回合最终 assistant 正文,不拼接阶段前导语。
223
+ for (let i = turnEnd - 1; i > userIdx; i--) {
208
224
  const m = ordered[i]
209
225
  if (m.type !== "assistant") continue
210
226
  const answer = (m.content ?? [])