diff --git a/package.json b/package.json index 7d1c16d9..0539e210 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "license": "SEE LICENSE IN LICENSE", "name": "snowluma-monorepo", - "version": "1.14.2", + "version": "1.14.3", "description": "SnowLuma monorepo workspace (pnpm)", "private": true, "type": "module", diff --git a/packages/bridge/package.json b/packages/bridge/package.json index fd121679..1b8db3c3 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.2", + "version": "1.14.3", "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 aeff3e0b..2d2acf5c 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.2", + "version": "1.14.3", "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 8f291c95..ae67524c 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.2", + "version": "1.14.3", "description": "SnowLuma core - NTQQ packet sniffer with Node.js native addon", "private": true, "type": "module", diff --git a/packages/mcp/package.json b/packages/mcp/package.json index 07c33f0a..299e7e5b 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.2", + "version": "1.14.3", "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 5e96e773..5cf657a1 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.2", + "version": "1.14.3", "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/proto-defs/package.json b/packages/proto-defs/package.json index 38b3850e..0fb8feb8 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.2", + "version": "1.14.3", "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 935db641..6bef516e 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.2", + "version": "1.14.3", "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/protocol/src/sys-face-store.ts b/packages/protocol/src/sys-face-store.ts index a0418fed..e6934759 100644 --- a/packages/protocol/src/sys-face-store.ts +++ b/packages/protocol/src/sys-face-store.ts @@ -42,7 +42,8 @@ export interface SysFaceStoreOptions { interface IndexedCatalog { packs: SysFacePackEntry[]; byId: Map; - packNameById: Map; + entryCount: number; + overlapCount: number; } /** Pure classification once an authoritative entry is known. */ @@ -108,16 +109,25 @@ export class SysFaceStore { if (!needle || !this.catalog) return []; const matches: SysFaceEntry[] = []; - for (const [id, face] of this.catalog.byId) { - const haystacks = [ - id, - face.qDes, - face.emCode, - this.catalog.packNameById.get(id) ?? '', - ...face.emojiNameAlias, - ]; - if (haystacks.some((value) => value.toLocaleLowerCase().includes(needle))) { - matches.push(face); + const matchedIds = new Set(); + for (const pack of this.catalog.packs) { + for (const face of pack.emojis) { + if (matchedIds.has(face.qSid)) continue; + const haystacks = [ + face.qSid, + face.qDes, + face.emCode, + pack.packName, + ...face.emojiNameAlias, + ]; + if (haystacks.some((value) => value.toLocaleLowerCase().includes(needle))) { + const canonical = this.catalog.byId.get(face.qSid); + if (!canonical) { + throw new Error(`system face index is missing catalog id ${face.qSid}`); + } + matches.push(canonical); + matchedIds.add(face.qSid); + } } } return matches; @@ -179,8 +189,10 @@ export class SysFaceStore { this.refreshedInProcess = true; if (this.storage) await this.storage.save(snapshot); log.info( - 'system face catalog refreshed: faces=%d packs=%d elapsedMs=%d', + 'system face catalog refreshed: entries=%d uniqueFaces=%d overlaps=%d packs=%d elapsedMs=%d', + this.catalog.entryCount, this.catalog.byId.size, + this.catalog.overlapCount, validated.length, this.now() - startedAt, ); @@ -246,8 +258,11 @@ export class SysFaceStore { validateSnapshot(snapshot); this.catalog = indexCatalog(snapshot.packs); log.info( - 'system face catalog restored: faces=%d packs=%d fetchedAt=%d elapsedMs=%d', + 'system face catalog restored: entries=%d uniqueFaces=%d overlaps=%d packs=%d ' + + 'fetchedAt=%d elapsedMs=%d', + this.catalog.entryCount, this.catalog.byId.size, + this.catalog.overlapCount, snapshot.packs.length, snapshot.fetchedAt, this.now() - startedAt, @@ -288,7 +303,12 @@ function validateCatalog(packs: SysFacePackEntry[]): SysFacePackEntry[] { throw new Error('system face catalog is empty'); } - const seen = new Set(); + const seen = new Map; + }>(); let faceCount = 0; for (const [packIndex, pack] of packs.entries()) { if (!pack || typeof pack.packName !== 'string' || !Array.isArray(pack.emojis)) { @@ -301,9 +321,6 @@ function validateCatalog(packs: SysFacePackEntry[]): SysFacePackEntry[] { + `value=${JSON.stringify(face?.qSid)}`, ); } - if (seen.has(face.qSid)) { - throw new Error(`duplicate system face id ${face.qSid}`); - } if (!Array.isArray(face.emojiNameAlias) || face.emojiNameAlias.some((alias) => typeof alias !== 'string')) { throw new Error(`invalid aliases for system face id ${face.qSid}`); @@ -326,7 +343,31 @@ function validateCatalog(packs: SysFacePackEntry[]): SysFacePackEntry[] { if (face.url !== null && typeof face.url !== 'string') { throw new Error(`invalid url for system face id ${face.qSid}`); } - seen.add(face.qSid); + const previous = seen.get(face.qSid); + if (previous) { + const previousFaceIndex = previous.faceIndexByPack.get(packIndex); + if (previousFaceIndex !== undefined) { + throw new Error( + `duplicate system face id ${face.qSid} within pack ${packIndex}: ` + + `faces ${previousFaceIndex} and ${faceIndex}`, + ); + } + if (!hasCompatibleSendMetadata(previous.face, face)) { + throw new Error( + `conflicting system face send metadata for id ${face.qSid}: ` + + `pack ${previous.packIndex}, face ${previous.faceIndex} vs ` + + `pack ${packIndex}, face ${faceIndex}`, + ); + } + previous.faceIndexByPack.set(packIndex, faceIndex); + } else { + seen.set(face.qSid, { + face, + packIndex, + faceIndex, + faceIndexByPack: new Map([[packIndex, faceIndex]]), + }); + } faceCount += 1; } } @@ -334,16 +375,38 @@ function validateCatalog(packs: SysFacePackEntry[]): SysFacePackEntry[] { return packs; } +function hasCompatibleSendMetadata(left: SysFaceEntry, right: SysFaceEntry): boolean { + if (!isAddressableFaceId(left.qSid)) return true; + const leftIsSuper = isSuperFaceEntry(left); + const rightIsSuper = isSuperFaceEntry(right); + if (leftIsSuper !== rightIsSuper) return false; + if (!leftIsSuper) return true; + return left.aniStickerType === right.aniStickerType + && left.aniStickerPackId === right.aniStickerPackId + && left.aniStickerId === right.aniStickerId; +} + +function isAddressableFaceId(id: string): boolean { + if (!/^(?:0|[1-9]\d*)$/.test(id)) return false; + const numeric = Number(id); + return Number.isSafeInteger(numeric) && numeric >= 0; +} + function indexCatalog(packs: SysFacePackEntry[]): IndexedCatalog { const byId = new Map(); - const packNameById = new Map(); + let entryCount = 0; for (const pack of packs) { for (const emoji of pack.emojis) { - byId.set(emoji.qSid, emoji); - packNameById.set(emoji.qSid, pack.packName); + entryCount += 1; + if (!byId.has(emoji.qSid)) byId.set(emoji.qSid, emoji); } } - return { packs, byId, packNameById }; + return { + packs, + byId, + entryCount, + overlapCount: entryCount - byId.size, + }; } /** Shared, process-wide catalog (the face set is account-independent). */ diff --git a/packages/protocol/tests/sys-faces.test.ts b/packages/protocol/tests/sys-faces.test.ts index 7d3da09a..d948373d 100644 --- a/packages/protocol/tests/sys-faces.test.ts +++ b/packages/protocol/tests/sys-faces.test.ts @@ -232,7 +232,44 @@ describe('SysFaceStore — persistent catalog and query seam', () => { expect(store.lookup(128522)).toBeNull(); }); - it('still rejects empty and duplicate catalog identifiers', () => { + it('preserves one face across multiple catalog packs', async () => { + const commonFace = entry('474', 1, 4, 76, '/给你一拳'); + commonFace.emCode = '10474'; + const specialFace: SysFaceEntry = { + ...commonFace, + qDes: '/给你一拳(黄脸)', + emojiNameAlias: ['punch'], + }; + const catalog: SysFacePackEntry[] = [ + { packName: '超级表情', emojis: [commonFace] }, + { packName: 'QQ黄脸', emojis: [specialFace] }, + ]; + const storage = new MemoryCatalogStorage(); + const store = new SysFaceStore({ + storage, + now: () => 456, + fetchCatalog: async () => catalog, + }); + + await expect(store.refresh(sender)).resolves.toEqual(catalog); + + expect(storage.saved[0]?.packs).toEqual(catalog); + await expect(store.getCatalog(sender)).resolves.toEqual(catalog); + expect(store.lookup(474)).toEqual(commonFace); + expect(store.search('超级表情').map((face) => face.qSid)).toEqual(['474']); + expect(store.search('QQ黄脸').map((face) => face.qSid)).toEqual(['474']); + expect(store.search('punch').map((face) => face.qSid)).toEqual(['474']); + + const restored = new SysFaceStore({ + storage: new MemoryCatalogStorage(storage.saved[0]!), + fetchCatalog: async () => { throw new Error('network must not be used'); }, + }); + await restored.ensureReady(sender); + await expect(restored.getCatalog(sender)).resolves.toEqual(catalog); + expect(restored.search('QQ黄脸').map((face) => face.qSid)).toEqual(['474']); + }); + + it('still rejects empty identifiers and duplicates within one pack', () => { const store = new SysFaceStore(); expect(() => store.load([{ packName: 'emoji', emojis: [entry('', null, null, null)] }])) @@ -241,6 +278,32 @@ describe('SysFaceStore — persistent catalog and query seam', () => { packName: 'emoji', emojis: [entry('😊', null, null, null), entry('😊', null, null, null)], }])).toThrow(/duplicate system face id/); + expect(() => store.load([ + { packName: '超级表情', emojis: [entry('474', 1, 4, 76)] }, + { + packName: 'QQ黄脸', + emojis: [entry('474', 1, 4, 76), entry('474', 1, 4, 76)], + }, + ])).toThrow(/duplicate system face id 474 within pack 1/); + }); + + it('rejects cross-pack copies with conflicting send metadata', () => { + const store = new SysFaceStore(); + + expect(() => store.load([ + { packName: '超级表情', emojis: [entry('474', 1, 4, 76)] }, + { packName: 'QQ黄脸', emojis: [entry('474', 3, 2, 38)] }, + ])).toThrow(/conflicting system face send metadata.*pack 0.*pack 1/); + }); + + it('allows non-addressable Unicode entries to carry panel-specific metadata', () => { + const store = new SysFaceStore(); + + expect(() => store.load([ + { packName: 'emoji', emojis: [entry('😊', null, null, null, '/微笑')] }, + { packName: '最近使用', emojis: [entry('😊', 3, 2, 38, '/最近使用')] }, + ])).not.toThrow(); + expect(store.search('最近使用').map((face) => face.qSid)).toEqual(['😊']); }); it('coalesces concurrent refreshes and persists the authoritative result once', async () => { diff --git a/packages/proton/package.json b/packages/proton/package.json index 0e2dd8e5..d363c7cb 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.2", + "version": "1.14.3", "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/package.json b/packages/runtime/package.json index 390cb0f8..d20aaa10 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.2", + "version": "1.14.3", "private": true, "type": "module", "main": "index.mjs", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index a4d84af1..8ce5fcd7 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -4,7 +4,7 @@ "name": "MotricSeven", "email": "motricseven@gmail.com" }, - "version": "1.14.2", + "version": "1.14.3", "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 74b87af9..05716773 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -4,7 +4,7 @@ "name": "MotricSeven", "email": "motricseven@gmail.com" }, - "version": "1.14.2", + "version": "1.14.3", "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 733ce441..fa2a30d2 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.2", + "version": "1.14.3", "private": true, "type": "module", "main": "./src/index.ts", diff --git a/packages/webui/package.json b/packages/webui/package.json index e9769d76..a83296fb 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.2", + "version": "1.14.3", "type": "module", "scripts": { "dev": "vite",