diff --git a/package.json b/package.json index 36b271a8..9f0a71bd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "snowluma-monorepo", - "version": "1.14.8", + "version": "1.14.9", "description": "SnowLuma monorepo workspace (pnpm)", "private": true, "type": "module", diff --git a/packages/bridge/package.json b/packages/bridge/package.json index 47bb61b5..a5daa29b 100644 --- a/packages/bridge/package.json +++ b/packages/bridge/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/bridge", - "version": "1.14.8", + "version": "1.14.9", "private": true, "type": "module", "description": "SnowLuma bridge — QQ NT desktop client lifecycle: hook injection (via native addon), per-PID HookSession orchestration, pipe-watcher for process discovery, and the BridgeManagerSink interface that lets the hook layer call back into a UIN-keyed session router without depending on @snowluma/core. Consumed by the top-level app entry (which constructs the BridgeManager from @snowluma/core and injects it as the sink) and by the WebUI server (read-only HookProcessInfo views).", diff --git a/packages/common/package.json b/packages/common/package.json index 0433fe8e..399e8baa 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/common", - "version": "1.14.8", + "version": "1.14.9", "private": true, "type": "module", "description": "SnowLuma shared infrastructure — leaf-package utilities with zero business dependencies. Logger / hex codec / log file transport / log line summariser / packet sender wire-protocol types / runtime config loader. Consumed by @snowluma/protocol, @snowluma/core, and @snowluma/onebot. Per-file subpath exports keep import sites unambiguous and let the bundler tree-shake aggressively (importing `@snowluma/common/hex` doesn't pull in `node:fs` from the logger transport).", diff --git a/packages/core/package.json b/packages/core/package.json index 44e42cfc..1312c990 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/core", - "version": "1.14.8", + "version": "1.14.9", "description": "SnowLuma core - NTQQ packet sniffer with Node.js native addon", "private": true, "type": "module", diff --git a/packages/core/src/bridge/apis/flash-transfer.ts b/packages/core/src/bridge/apis/flash-transfer.ts index c60fec64..220b2fd6 100644 --- a/packages/core/src/bridge/apis/flash-transfer.ts +++ b/packages/core/src/bridge/apis/flash-transfer.ts @@ -35,6 +35,10 @@ import { deflateSync } from 'node:zlib'; const FLASH_SLICE_SIZE = 1024 * 1024; +/** After create returns, 0x93d4 can still omit the main-file fileId for a + * few seconds (#364). Re-query on this schedule (first lookup is immediate). */ +const FLASH_FILE_ID_RETRY_DELAYS_MS = [1000, 2000, 4000, 4000] as const; + /** Fail cleanly if the staged file changed since the streaming hash pass. */ async function assertUnchanged(filePath: string, baseline: { size: number; mtimeMs: number }): Promise { const now = await fsp.stat(filePath); @@ -267,21 +271,30 @@ export class FlashTransferApi { * 多文件时每条 f6=序号、f14=主文件 fileId),按 fileIndex 选中后走 0x12a9 sub=200 * 拿主文件直链。0x93d3/0x93d4 的 downloadUrl 字段是缩略图(appid=14903/14902), * 主文件必须走 0x12a9 sub=200。 + * + * create 刚返回时 f14 可能还是空的(#364)。fileId 空则按 + * FLASH_FILE_ID_RETRY_DELAYS_MS 再问 0x93d4;已经有 fileId 后 0x12a9 只打一枪。 */ private async getFileDownload( filesetUuid: string, fileIndex: number = 1, ): Promise<{ url: string; fileName: string; fileSize: number } | null> { - const metas = await GetDownloadUrl.invoke(this.ctx, { filesetUuid }); - const meta = metas.find((m) => m.fileIndex === fileIndex); - if (!meta || !meta.fileId) return null; - const url = await GetFlashDownload.invoke(this.ctx, { - filesetUuid: meta.filesetUuid, - fileUuid: meta.fileUuid, - fileId: meta.fileId, - fileName: meta.fileName, - }); - if (!url) return null; - return { url, fileName: meta.fileName, fileSize: meta.fileSize }; + for (let attempt = 0; ; attempt++) { + const metas = await GetDownloadUrl.invoke(this.ctx, { filesetUuid }); + const meta = metas.find((m) => m.fileIndex === fileIndex); + if (meta?.fileId) { + const url = await GetFlashDownload.invoke(this.ctx, { + filesetUuid: meta.filesetUuid, + fileUuid: meta.fileUuid, + fileId: meta.fileId, + fileName: meta.fileName, + }); + if (!url) return null; + return { url, fileName: meta.fileName, fileSize: meta.fileSize }; + } + const delay = FLASH_FILE_ID_RETRY_DELAYS_MS[attempt]; + if (delay === undefined) return null; + await new Promise((resolve) => setTimeout(resolve, delay)); + } } /** diff --git a/packages/core/tests/flash-transfer-download.test.ts b/packages/core/tests/flash-transfer-download.test.ts new file mode 100644 index 00000000..7dfe4ef0 --- /dev/null +++ b/packages/core/tests/flash-transfer-download.test.ts @@ -0,0 +1,99 @@ +// Regression for #364: create_flash_task can return before 0x93d4 fills +// the main-file fileId. get_flash_file_url / download_fileset poll 0x93d4 +// while that field is empty, then take the normal 0x12a9 sub=200 path. + +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { GetDownloadUrl } from '@snowluma/protocol/oidb-services/flash-transfer/get-download-url'; +import { GetFlashDownload } from '@snowluma/protocol/oidb-services/flash-transfer/get-flash-download'; +import { FlashTransferApi } from '../src/bridge/apis/flash-transfer'; + +const FILESET = '8982c4b5-195c-49e2-a3ab-478b32af234c'; +const FILE_ID = 'main-file-id'; +const URL = 'https://multimedia.qfile.qq.com/download?appid=14901&fileid=main-file-id'; + +function meta(fileId: string, fileIndex = 1): GetDownloadUrl.FileMeta { + return { + fileIndex, + fileId, + filesetUuid: FILESET, + fileUuid: 'file-uuid', + fileName: 'sl364-hitpass.txt', + fileSize: 41, + }; +} + +function api(): FlashTransferApi { + return new FlashTransferApi({} as never); +} + +describe('FlashTransferApi.getFlashFileUrl — empty fileId poll (#364)', () => { + beforeEach(() => { + vi.useFakeTimers(); + }); + + afterEach(() => { + vi.useRealTimers(); + vi.restoreAllMocks(); + }); + + it('does not wait when 0x93d4 already has the main-file fileId', async () => { + const lookup = vi.spyOn(GetDownloadUrl, 'invoke').mockResolvedValue([meta(FILE_ID)]); + const download = vi.spyOn(GetFlashDownload, 'invoke').mockResolvedValue(URL); + + await expect(api().getFlashFileUrl(FILESET)).resolves.toBe(URL); + expect(lookup).toHaveBeenCalledOnce(); + expect(download).toHaveBeenCalledOnce(); + expect(download.mock.calls[0]![1]).toMatchObject({ fileId: FILE_ID, filesetUuid: FILESET }); + }); + + it('re-queries 0x93d4 after an empty fileId and then takes the download path', async () => { + const lookup = vi.spyOn(GetDownloadUrl, 'invoke') + .mockResolvedValueOnce([meta('')]) + .mockResolvedValueOnce([meta(FILE_ID)]); + const download = vi.spyOn(GetFlashDownload, 'invoke').mockResolvedValue(URL); + + const pending = api().getFlashFileUrl(FILESET); + await vi.advanceTimersByTimeAsync(1000); + await expect(pending).resolves.toBe(URL); + + expect(lookup).toHaveBeenCalledTimes(2); + expect(download).toHaveBeenCalledOnce(); + expect(download.mock.calls[0]![1]).toMatchObject({ fileId: FILE_ID }); + }); + + it('shares the same poll for download_fileset', async () => { + vi.spyOn(GetDownloadUrl, 'invoke') + .mockResolvedValueOnce([meta('')]) + .mockResolvedValueOnce([meta(FILE_ID)]); + vi.spyOn(GetFlashDownload, 'invoke').mockResolvedValue(URL); + + const pending = api().downloadFileset(FILESET); + await vi.advanceTimersByTimeAsync(1000); + await expect(pending).resolves.toEqual({ + url: URL, + fileName: 'sl364-hitpass.txt', + fileSize: 41, + }); + }); + + it('keeps the original error when fileId stays empty through the budget', async () => { + const lookup = vi.spyOn(GetDownloadUrl, 'invoke').mockResolvedValue([meta('')]); + const download = vi.spyOn(GetFlashDownload, 'invoke').mockResolvedValue(URL); + + const pending = api().getFlashFileUrl(FILESET); + const expectFailed = expect(pending).rejects.toThrow('get_flash_file_url: no download url available'); + await vi.advanceTimersByTimeAsync(20_000); + await expectFailed; + + expect(lookup.mock.calls.length).toBeGreaterThan(1); + expect(download).not.toHaveBeenCalled(); + }); + + it('does not re-query 0x93d4 when fileId is present but 0x12a9 returns no url', async () => { + const lookup = vi.spyOn(GetDownloadUrl, 'invoke').mockResolvedValue([meta(FILE_ID)]); + vi.spyOn(GetFlashDownload, 'invoke').mockResolvedValue(null); + + await expect(api().getFlashFileUrl(FILESET)).rejects.toThrow('get_flash_file_url: no download url available'); + expect(lookup).toHaveBeenCalledOnce(); + }); +}); diff --git a/packages/mcp/package.json b/packages/mcp/package.json index 08de5994..b6eb0a8a 100644 --- a/packages/mcp/package.json +++ b/packages/mcp/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/mcp", - "version": "1.14.8", + "version": "1.14.9", "description": "MCP server exposing the SnowLuma OneBot action catalog (docs + JSON Schemas) and optional execution to LLM clients.", "repository": { "type": "git", diff --git a/packages/onebot/package.json b/packages/onebot/package.json index f9f60175..913867cb 100644 --- a/packages/onebot/package.json +++ b/packages/onebot/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/onebot", - "version": "1.14.8", + "version": "1.14.9", "private": true, "type": "module", "description": "SnowLuma OneBot v11 adapter — the protocol translation layer that maps the public OneBot vocabulary (HTTP / WebSocket actions, message segments, post events) onto @snowluma/core's typed Api hub (`bridge.apis..method()`). Owns network adapters (HTTP server / HTTP client / WS server / WS client), the registered action handlers, the receive-side event→OneBot converter, message-id hashing, message store (SQLite-backed event history), media store, and the OneBot instance + manager that ties one OneBotConfig to one Bridge. Per-file subpath exports mirror the legacy `core/src/onebot/*` layout 1:1 so the previous `import { … } from '../onebot/'` collapses to `import { … } from '@snowluma/onebot/'`.", diff --git a/packages/onebot/src/event-converter/element-codecs.ts b/packages/onebot/src/event-converter/element-codecs.ts index 5b72728d..f30a1f9f 100644 --- a/packages/onebot/src/event-converter/element-codecs.ts +++ b/packages/onebot/src/event-converter/element-codecs.ts @@ -211,7 +211,8 @@ export const ELEMENT_CODECS = { log.warn('could not quote the target message'); return null; } - if (id <= 0) { + // message_id is a signed int32 hash; only 0 is invalid (#371). + if (id === 0) { log.warn('could not quote the target message'); return null; } @@ -246,7 +247,10 @@ export const ELEMENT_CODECS = { } // Backward-compatible path: allow direct seq reply IDs. - return id > 0 ? { type: 'reply', replySeq: id } : null; + // A negative OneBot id is never a QQ sequence. + if (id > 0) return { type: 'reply', replySeq: id }; + log.warn('could not quote the target message'); + return null; }, }, diff --git a/packages/onebot/src/modules/message-actions.ts b/packages/onebot/src/modules/message-actions.ts index f1674602..afd70211 100644 --- a/packages/onebot/src/modules/message-actions.ts +++ b/packages/onebot/src/modules/message-actions.ts @@ -1679,7 +1679,7 @@ async function parseForwardNodes( const eventSender = asJsonObject(event.sender) ?? {}; const senderCard = eventSender.card !== undefined ? String(eventSender.card) : undefined; - const nickname = String(eventSender.card ?? eventSender.nickname ?? nodeData.nickname ?? nodeData.name ?? ''); + const nickname = String(eventSender.card || eventSender.nickname || nodeData.nickname || nodeData.name || ''); const userUin = toPositiveInt(event.user_id); if (userUin <= 0) { throw new MessageElementValidationError( diff --git a/packages/onebot/tests/forward-nested.test.ts b/packages/onebot/tests/forward-nested.test.ts index a82b9bfa..a9bbf823 100644 --- a/packages/onebot/tests/forward-nested.test.ts +++ b/packages/onebot/tests/forward-nested.test.ts @@ -375,6 +375,50 @@ describe('forward — nested {type:"node"} content', () => { }); }); + it('[#372] empty group card does not replace a cached sender nickname with the QQ number', async () => { + // Group events always store sender.card as "" when the member has no + // card. `??` treats that empty string as present and then + // `nickname || String(userUin)` collapses the display name to the QQ + // number — the get_forward_msg symptom in #372. + const uploadForwardNodes = vi.fn(async () => 'RES'); + const sendGroupMessage = vi.fn(async () => ({ + messageId: 1, sequence: 1, clientSequence: 0, random: 1, timestamp: 1, + })); + const findEvent = vi.fn((id: number) => id === 7 ? ({ + user_id: 22222, + message_id: 7, + message_seq: 42, + message_type: 'group', + group_id: 12345, + time: 1700000000, + message: [{ type: 'text', data: { text: 'cached' } }], + sender: { user_id: 22222, nickname: 'alice', card: '' }, + }) : id === 8 ? ({ + user_id: 33333, + message_id: 8, + message_seq: 43, + message_type: 'group', + group_id: 12345, + time: 1700000000, + message: [{ type: 'text', data: { text: 'nameless' } }], + sender: { user_id: 33333, nickname: '', card: '' }, + }) : null); + const bridge = fakeBridge({ + apis: { message: { sendGroup: sendGroupMessage }, forward: { upload: uploadForwardNodes } }, + } as any); + const ctx = makeCtx(bridge); + (ctx as any).messageStore = { findEvent }; + + await sendGroupForwardMessage(ctx, 12345, [ + { type: 'node', data: { id: 7, nickname: 'node-override' } }, + { type: 'node', data: { id: 8, nickname: 'node-fallback' } }, + ] as any); + + const [nodes] = uploadForwardNodes.mock.calls[0]!; + expect((nodes as any[])[0]).toMatchObject({ userUin: 22222, nickname: 'alice' }); + expect((nodes as any[])[1]).toMatchObject({ userUin: 33333, nickname: 'node-fallback' }); + }); + it('reports a missing cached message_id as caller-invalid before upload', async () => { const uploadForwardNodes = vi.fn(async () => 'RES'); const sendGroupMessage = vi.fn(); diff --git a/packages/onebot/tests/message-parser.test.ts b/packages/onebot/tests/message-parser.test.ts index 8fa6e781..a3cd4710 100644 --- a/packages/onebot/tests/message-parser.test.ts +++ b/packages/onebot/tests/message-parser.test.ts @@ -666,6 +666,33 @@ describe('parseMessage', () => { expect(result[0].replySeq).toBe(100); }); + it('resolves a signed-int32 message_id to the stored reply sequence (#371)', async () => { + const result = await parseMessage( + [ + { type: 'reply', data: { id: -188861750 } }, + { type: 'text', data: { text: '测试成功' } }, + ] as any, + false, + { resolveReplySequence: (id) => id === -188861750 ? 4242 : null }, + ); + expect(result).toEqual([ + { type: 'reply', replySeq: 4242, replyMessageId: -188861750 }, + { type: 'text', text: '测试成功' }, + ]); + }); + + it('does not treat an unresolved negative message_id as a QQ sequence (#371)', async () => { + const result = await parseMessage( + [ + { type: 'reply', data: { id: -188861750 } }, + { type: 'text', data: { text: '测试成功' } }, + ] as any, + false, + { resolveReplySequence: () => null }, + ); + expect(result).toEqual([{ type: 'text', text: '测试成功' }]); + }); + it('parses share as json card', async () => { const result = await parseMessage( [{ type: 'share', data: { url: 'https://example.com', title: 'Test' } }] as any, diff --git a/packages/proto-defs/package.json b/packages/proto-defs/package.json index ee8e89b3..20257b54 100644 --- a/packages/proto-defs/package.json +++ b/packages/proto-defs/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/proto-defs", - "version": "1.14.8", + "version": "1.14.9", "private": true, "type": "module", "description": "SnowLuma QQ/Lagrange wire-protobuf type definitions. Pure TypeScript interfaces with proton's `pb` marker types — `@snowluma/proton`'s vite plugin compiles them into zero-runtime encoder/decoder functions at the call sites in `@snowluma/core` (and any downstream consumer). Exposed as per-file subpaths (`@snowluma/proto-defs/oidb`, `@snowluma/proto-defs/message`, …) so the import-site shape mirrors the legacy `bridge/proto/proton/*` layout and avoids name collisions across files (notably `highway.ts` and `oidb-actions/media.ts` share NTV2-prefixed names).", diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 1a79c9dc..9a7b675b 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/protocol", - "version": "1.14.8", + "version": "1.14.9", "private": true, "type": "module", "description": "SnowLuma protocol — the protocol-layer between QQ wire bytes and typed events. Owns: identity service (uid↔uin cache with SQLite persistence), event bus, packet pipeline (incoming SSO packet → QQEventVariant), msg-push decoders, element-builder (MessageElement → wire elems[]), highway upload protocol (file/image/video/ptt), OIDB envelope helper, and the event/notice/request type vocabulary. Consumers (@snowluma/core, @snowluma/onebot) talk to this package through `BridgeContext` for runtime calls and the standalone classes (IdentityService, BridgeEventBus, IncomingPacketPipeline) for composition. Per-file subpath exports mirror the legacy `core/src/bridge/*` layout 1:1 so the previous `import { …} from '../bridge/'` collapses to `import { … } from '@snowluma/protocol/'`.", diff --git a/packages/proton/package.json b/packages/proton/package.json index 27c12bfe..f21dbe8c 100644 --- a/packages/proton/package.json +++ b/packages/proton/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/proton", - "version": "1.14.8", + "version": "1.14.9", "private": true, "type": "module", "description": "Compile-time protobuf encoder/decoder generator for SnowLuma. TypeScript interfaces → fully-inlined, zero-runtime protobuf codec functions. Vendored from SnowLuma/protobuf-dsl (reference copy under dev/protobuf-dsl/) with edge-case fixes applied.", diff --git a/packages/runtime/native/snowluma-linux-arm64.node b/packages/runtime/native/snowluma-linux-arm64.node index b24be4f9..4c419dcf 100644 Binary files a/packages/runtime/native/snowluma-linux-arm64.node and b/packages/runtime/native/snowluma-linux-arm64.node differ diff --git a/packages/runtime/native/snowluma-linux-arm64.so b/packages/runtime/native/snowluma-linux-arm64.so index f569a7af..20736176 100644 Binary files a/packages/runtime/native/snowluma-linux-arm64.so and b/packages/runtime/native/snowluma-linux-arm64.so differ diff --git a/packages/runtime/native/snowluma-linux-x64.node b/packages/runtime/native/snowluma-linux-x64.node index aa3815dd..8075ffb1 100644 Binary files a/packages/runtime/native/snowluma-linux-x64.node and b/packages/runtime/native/snowluma-linux-x64.node differ diff --git a/packages/runtime/native/snowluma-linux-x64.so b/packages/runtime/native/snowluma-linux-x64.so index f40f077e..be1058c5 100644 Binary files a/packages/runtime/native/snowluma-linux-x64.so and b/packages/runtime/native/snowluma-linux-x64.so differ diff --git a/packages/runtime/native/snowluma-win32-x64.dll b/packages/runtime/native/snowluma-win32-x64.dll index 92589917..2dd1244f 100644 Binary files a/packages/runtime/native/snowluma-win32-x64.dll and b/packages/runtime/native/snowluma-win32-x64.dll differ diff --git a/packages/runtime/native/snowluma-win32-x64.node b/packages/runtime/native/snowluma-win32-x64.node index d9294a1e..4f2764a0 100644 Binary files a/packages/runtime/native/snowluma-win32-x64.node and b/packages/runtime/native/snowluma-win32-x64.node differ diff --git a/packages/runtime/package.json b/packages/runtime/package.json index e4b9d077..cba11818 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/runtime", - "version": "1.14.8", + "version": "1.14.9", "private": true, "type": "module", "main": "index.mjs", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index cd1a23cc..d5131ace 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -4,7 +4,7 @@ "name": "MotricSeven", "email": "motricseven@gmail.com" }, - "version": "1.14.8", + "version": "1.14.9", "description": "TypeScript SDK for SnowLuma OneBot HTTP and WebSocket transports", "keywords": [ "snowluma", diff --git a/packages/ui/package.json b/packages/ui/package.json index d46ee238..79baec0f 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -4,7 +4,7 @@ "name": "MotricSeven", "email": "motricseven@gmail.com" }, - "version": "1.14.8", + "version": "1.14.9", "description": "Shared SnowLuma UI primitives — Tailwind 4 theme tokens + shadcn-style atomic components", "keywords": [ "snowluma", diff --git a/packages/websocket/package.json b/packages/websocket/package.json index e5715175..4247556f 100644 --- a/packages/websocket/package.json +++ b/packages/websocket/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "@snowluma/websocket", - "version": "1.14.8", + "version": "1.14.9", "private": true, "type": "module", "main": "./src/index.ts", diff --git a/packages/webui/package.json b/packages/webui/package.json index 671c6e64..335424b9 100644 --- a/packages/webui/package.json +++ b/packages/webui/package.json @@ -2,7 +2,7 @@ "license": "SEE LICENSE IN LICENSE", "name": "webui", "private": true, - "version": "1.14.8", + "version": "1.14.9", "type": "module", "scripts": { "dev": "vite",