@linjz/opencode-qqbot 0.3.15 → 0.3.16
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/README.md +42 -5
- package/bin/openqq.js +13 -0
- package/dist/notify-cli.js +28 -14
- package/dist/opencode-qqbot-plugin.js +934 -64
- package/dist/openqq-bot.js +3095 -677
- package/dist/openqq-cli.js +791 -0
- package/dist/openqq-watchdog.js +1063 -0
- package/package.json +8 -5
- package/src/bridge.ts +1310 -150
- package/src/cli/notify.ts +167 -158
- package/src/cli/openqq-main.ts +95 -0
- package/src/cli/service-main.ts +302 -0
- package/src/cli/watchdog-main.ts +77 -0
- package/src/commands.ts +644 -554
- package/src/config.ts +85 -0
- package/src/core/bot-control.ts +148 -0
- package/src/core/bot-launcher.ts +106 -13
- package/src/core/card-approval.ts +20 -9
- package/src/core/delivery.ts +145 -54
- package/src/core/discovery.ts +22 -4
- package/src/core/file-log.ts +35 -3
- package/src/core/form-bridge.ts +14 -5
- package/src/core/form-journal.ts +4 -4
- package/src/core/gateway-state.ts +3 -3
- package/src/core/inflight-journal.ts +214 -36
- package/src/core/instance-lock.ts +10 -2
- package/src/core/linkwatch.ts +3 -4
- package/src/core/markdown.ts +117 -0
- package/src/core/message-queue.ts +242 -91
- package/src/core/mirror.ts +222 -182
- package/src/core/notify-sink.ts +93 -96
- package/src/core/outbox.ts +10 -9
- package/src/core/permission.ts +627 -303
- package/src/core/question-form.ts +230 -0
- package/src/core/queue-view.ts +661 -0
- package/src/core/send-media.ts +32 -0
- package/src/core/storage.ts +34 -0
- package/src/core/watchdog.ts +513 -0
- package/src/core/zombie-reaper.ts +127 -0
- package/src/index.ts +140 -52
- package/src/opencode/client.ts +206 -27
- package/src/opencode/eventstream.ts +94 -12
- package/src/opencode/history.ts +4 -2
- package/src/opencode/mirror.ts +15 -2
- package/src/opencode/sessions.ts +135 -37
- package/src/plugin-entry.ts +120 -115
- package/src/qq/api.ts +165 -61
- package/src/qq/gateway.ts +79 -16
- package/src/qq/sender.ts +30 -18
- package/src/qq/types.ts +7 -0
package/src/qq/sender.ts
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
// 因此主路径直接透传 AI 的 markdown 原文,交给 QQ 渲染;仅在发送失败时回退纯文本。
|
|
8
8
|
import { sendC2CMessage, sendGroupMessage, getNextMsgSeq, type MessageResponse } from "./api.js"
|
|
9
9
|
import type { MessageContext } from "./types.js"
|
|
10
|
+
import { normalizeOutboundMarkdown, matchFence, type FenceToken } from "../core/markdown.js"
|
|
10
11
|
|
|
11
|
-
// Markdown 主路径: QQ 原生渲染标准 markdown
|
|
12
|
+
// Markdown 主路径: QQ 原生渲染标准 markdown(含表格/代码),故基本透传,仅做首尾清理
|
|
13
|
+
// 与围栏归一(补未闭合 + 去空围栏对)——两者都会在 QQ 里变成空代码卡(2026-11-10 实证)。
|
|
12
14
|
export function formatForQQMarkdown(text: string): string {
|
|
13
|
-
return text.trim()
|
|
15
|
+
return normalizeOutboundMarkdown(text.trim())
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
// 纯文本兜底: 去除所有 markdown 标记(当 markdown 发送失败时使用)
|
|
@@ -94,20 +96,20 @@ function utf8Bytes(s: string): number {
|
|
|
94
96
|
return encoder.encode(s).length
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
// —— 结构化分条(2026-10-29 固化:设计吸收自 dsh-qqbot
|
|
99
|
+
// —— 结构化分条(2026-10-29 固化:设计吸收自 dsh-qqbot 分条器 chunker,P0)——
|
|
98
100
|
// dsh 语义:GFM 表格聚成原子单元不跨片拆散 + 按行边界打包;
|
|
99
101
|
// 我方在 dsh 之上补两件事:① 字节预算(QQ 按 UTF-8 字节限长,dsh 按字符数会
|
|
100
|
-
// 踩中文 3 字节坑)②
|
|
101
|
-
//
|
|
102
|
+
// 踩中文 3 字节坑)② 围栏修补——在代码块中间切断时给前片补闭合、后片补开围栏
|
|
103
|
+
// (带语言),保证每片 markdown 独立可渲染。围栏识别与出站兜底共用 core/markdown
|
|
104
|
+
// (2026-11-10:补 ~~~ 与 4+ 标记长度,避免波浪围栏被当正文切碎)。
|
|
102
105
|
const GFM_TABLE_LINE = /^\s*\|.*\|\s*$/
|
|
103
|
-
const CODE_FENCE_OPEN = /^\s*```(\S*)/
|
|
104
106
|
|
|
105
107
|
interface LineUnit {
|
|
106
108
|
/** 行原文(含结尾 \n,全文末行除外) */
|
|
107
109
|
text: string
|
|
108
110
|
bytes: number
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
+
/** 本行是围栏行时记录标记,否则 null */
|
|
112
|
+
fence: FenceToken | null
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
function toLineUnits(text: string): LineUnit[] {
|
|
@@ -117,7 +119,7 @@ function toLineUnits(text: string): LineUnit[] {
|
|
|
117
119
|
const flushTable = (isLast: boolean): void => {
|
|
118
120
|
if (tableBuf.length === 0) return
|
|
119
121
|
const body = tableBuf.join("\n") + (isLast ? "" : "\n")
|
|
120
|
-
units.push({ text: body, bytes: utf8Bytes(body),
|
|
122
|
+
units.push({ text: body, bytes: utf8Bytes(body), fence: null })
|
|
121
123
|
tableBuf = []
|
|
122
124
|
}
|
|
123
125
|
|
|
@@ -129,9 +131,8 @@ function toLineUnits(text: string): LineUnit[] {
|
|
|
129
131
|
return
|
|
130
132
|
}
|
|
131
133
|
flushTable(isLast)
|
|
132
|
-
const fence = CODE_FENCE_OPEN.exec(line)
|
|
133
134
|
const body = line + (isLast ? "" : "\n")
|
|
134
|
-
units.push({ text: body, bytes: utf8Bytes(body),
|
|
135
|
+
units.push({ text: body, bytes: utf8Bytes(body), fence: matchFence(line) })
|
|
135
136
|
})
|
|
136
137
|
return units
|
|
137
138
|
}
|
|
@@ -187,18 +188,27 @@ export function splitMessage(text: string, maxBytes: number = MARKDOWN_MAX_BYTES
|
|
|
187
188
|
let cur = ""
|
|
188
189
|
let curBytes = 0
|
|
189
190
|
let prefix = "" // 围栏内切断时,下一片需补的开围栏(带语言)
|
|
190
|
-
let
|
|
191
|
+
let open: FenceToken | null = null // 原文全局围栏状态(跨片跟踪)
|
|
191
192
|
|
|
192
193
|
const flush = (): void => {
|
|
193
194
|
const body = cur
|
|
194
195
|
cur = ""
|
|
195
196
|
curBytes = 0
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
|
|
197
|
+
const f = open
|
|
198
|
+
const inside = f !== null
|
|
199
|
+
const closer = f ? f.ch.repeat(f.len) : ""
|
|
200
|
+
const out = prefix + body + (inside ? (body.endsWith("\n") ? `${closer}\n` : `\n${closer}\n`) : "")
|
|
201
|
+
prefix = f ? `${f.ch.repeat(f.len)}${f.info}\n` : ""
|
|
199
202
|
if (out.trim()) chunks.push(out)
|
|
200
203
|
}
|
|
201
204
|
|
|
205
|
+
const closesOpen = (u: LineUnit): boolean =>
|
|
206
|
+
open !== null &&
|
|
207
|
+
u.fence !== null &&
|
|
208
|
+
u.fence.ch === open.ch &&
|
|
209
|
+
u.fence.len >= open.len &&
|
|
210
|
+
u.fence.info === ""
|
|
211
|
+
|
|
202
212
|
for (const u of units) {
|
|
203
213
|
if (u.bytes > maxBytes) {
|
|
204
214
|
// 超大单元:先封当前片,再字节级兜底切(围栏行本身不可能超大,不参与围栏语义)
|
|
@@ -210,13 +220,15 @@ export function splitMessage(text: string, maxBytes: number = MARKDOWN_MAX_BYTES
|
|
|
210
220
|
continue
|
|
211
221
|
}
|
|
212
222
|
const prefixBytes = prefix ? utf8Bytes(prefix) : 0
|
|
213
|
-
|
|
223
|
+
// 闭栏行优先并入当前片:若在它之前切断,下一片会补出「开栏紧跟闭栏」的空代码块。
|
|
224
|
+
if (cur && !closesOpen(u) && curBytes + prefixBytes + u.bytes > maxBytes) {
|
|
214
225
|
flush()
|
|
215
226
|
}
|
|
216
227
|
cur += u.text
|
|
217
228
|
curBytes += u.bytes
|
|
218
|
-
if (u.
|
|
219
|
-
|
|
229
|
+
if (u.fence) {
|
|
230
|
+
if (!open) open = u.fence
|
|
231
|
+
else if (u.fence.ch === open.ch && u.fence.len >= open.len && u.fence.info === "") open = null
|
|
220
232
|
}
|
|
221
233
|
}
|
|
222
234
|
flush()
|
package/src/qq/types.ts
CHANGED
|
@@ -149,6 +149,13 @@ export interface MessageContext {
|
|
|
149
149
|
attachments?: MessageAttachment[]
|
|
150
150
|
/** 排队时预下载的附件(Q1:避免 drain 时 QQ 签名 URL 过期——入队即落盘) */
|
|
151
151
|
preparedAttachments?: import("./media.js").PreparedAttachments
|
|
152
|
+
/**
|
|
153
|
+
* 锚定会话(owner 2026-11-14 会话隔离裁定):入队/派发时快照的目标会话。
|
|
154
|
+
* 出站推送门据此校验「锚定=当前绑定」,绑定切走即不推(design §3.4 出站推送门)。
|
|
155
|
+
*/
|
|
156
|
+
anchorSessionId?: string
|
|
157
|
+
/** 纯表情消息标记(DEF-qqbot-20261111-P2,owner 裁定=有据提示):原始内容纯表情被规范化剥空 */
|
|
158
|
+
emojiOnly?: boolean
|
|
152
159
|
timestamp?: string
|
|
153
160
|
rawEvent?: C2CMessageEvent | GroupMessageEvent
|
|
154
161
|
}
|