Merge pull request #424 from SnowLuma/dev
chore: promote dev → main (4b9921b7)
This commit is contained in:
36 files changed
+732
-56
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "snowluma-monorepo",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"description": "SnowLuma monorepo workspace (pnpm)",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/bridge",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"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).",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/common",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"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).",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/core",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"description": "SnowLuma core - NTQQ packet sniffer with Node.js native addon",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
||||
@@ -19,6 +19,10 @@ import {
|
||||
} from '@snowluma/protocol/oidb-services/contacts/fetch-robot-uin-ranges';
|
||||
import { FetchUserProfile } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile';
|
||||
import { FetchUserProfileByUid } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile-by-uid';
|
||||
import {
|
||||
fetchQidianCorpInfo as fetchQidianCorpInfoWire,
|
||||
type QidianCorpInfo,
|
||||
} from '@snowluma/protocol/services/qidian/fetch-corp-info';
|
||||
import { GetBuddyRecommendArk } from '@snowluma/protocol/oidb-services/contacts/get-buddy-recommend-ark';
|
||||
import { GetGroupRecommendArk } from '@snowluma/protocol/oidb-services/contacts/get-group-recommend-ark';
|
||||
import { SendTuwenArk, type SendTuwenArkParams } from '@snowluma/protocol/oidb-services/contacts/send-tuwen-ark';
|
||||
@@ -348,6 +352,12 @@ export class ContactsApi {
|
||||
return info;
|
||||
}
|
||||
|
||||
/** 企点企业资料卡(#404 后续 PR)。仅在判断命中的是企点账号后再调用。
|
||||
* best-effort:非企点账号或拉取失败返回 null,不影响上层资料读取。 */
|
||||
async fetchQidianCorpInfo(uin: number): Promise<QidianCorpInfo | null> {
|
||||
return fetchQidianCorpInfoWire(this.ctx, uin);
|
||||
}
|
||||
|
||||
async fetchGroupRequests(
|
||||
filtered = false,
|
||||
count = 50,
|
||||
|
||||
@@ -35,6 +35,54 @@ import { deflateSync } from 'node:zlib';
|
||||
|
||||
const FLASH_SLICE_SIZE = 1024 * 1024;
|
||||
|
||||
const FLASH_IMAGE_EXT = new Set([
|
||||
'jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'heic', 'avif', 'tiff', 'tif', 'ico', 'dib', 'heif',
|
||||
]);
|
||||
const FLASH_AUDIO_EXT = new Set(['mp3', 'wav', 'aac', 'flac']);
|
||||
const FLASH_VIDEO_EXT = new Set([
|
||||
'mp4', 'avi', 'mkv', 'mov', '3gp', 'mpeg', 'rmvb', 'rm', 'wmv', 'flv', 'asf', 'webm', 'mpg', 'vob', 'm4v', 'f4v',
|
||||
]);
|
||||
const FLASH_ARCHIVE_EXT = new Set(['zip', 'rar', 'tar', 'bz2', 'xz', 'tgz', 'gz', '7z']);
|
||||
const FLASH_MODEL_EXT = new Set(['pt', 'pth', 'onnx', 'model', 'mlmodel']);
|
||||
|
||||
/** 0x93cf f3 粗类:压缩包走 2/6,其余按媒体类 7。 */
|
||||
function flashApplyTypeCode(ext: string): number {
|
||||
if (ext === 'zip') return 6;
|
||||
if (FLASH_ARCHIVE_EXT.has(ext)) return 2;
|
||||
return 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* 0x93d0 / 0x12a9 格式码。与 QQ 客户端按扩展名判定的图标类型一致:
|
||||
* 图片 26、音频 1、视频 2、文档 3、压缩包 4、未知 11。
|
||||
*/
|
||||
function flashFormatCode(ext: string): number {
|
||||
if (FLASH_IMAGE_EXT.has(ext)) return 26;
|
||||
if (FLASH_AUDIO_EXT.has(ext)) return 1;
|
||||
if (FLASH_VIDEO_EXT.has(ext)) return 2;
|
||||
if (ext === 'doc' || ext === 'docx') return 3;
|
||||
if (FLASH_ARCHIVE_EXT.has(ext)) return 4;
|
||||
if (ext === 'apk') return 5;
|
||||
if (ext === 'xls' || ext === 'xlsx') return 6;
|
||||
if (ext === 'ppt' || ext === 'pptx') return 7;
|
||||
if (ext === 'html' || ext === 'htm') return 8;
|
||||
if (ext === 'pdf') return 9;
|
||||
if (ext === 'txt') return 10;
|
||||
if (ext === 'psd') return 12;
|
||||
if (FLASH_MODEL_EXT.has(ext)) return 15;
|
||||
if (ext === 'ttf' || ext === 'otf') return 16;
|
||||
if (ext === 'ipa') return 17;
|
||||
if (ext === 'dmg') return 23;
|
||||
if (ext === 'pkg') return 24;
|
||||
if (ext === 'key') return 18;
|
||||
if (ext === 'note') return 19;
|
||||
if (ext === 'numbers') return 20;
|
||||
if (ext === 'pages') return 21;
|
||||
if (ext === 'sketch') return 22;
|
||||
if (ext === 'exe') return 27;
|
||||
return 11;
|
||||
}
|
||||
|
||||
/** 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;
|
||||
@@ -393,21 +441,13 @@ export class FlashTransferApi {
|
||||
// ─────────────── 文件上传 ───────────────
|
||||
|
||||
/**
|
||||
* 文件扩展名 → 闪传类型码映射。typeCode 用于 0x93cf f3,formatCode 用于
|
||||
* 0x93d0 commit f7 与 0x12a9 filesetWrap.f7(两者同值)。mp4 → 2,rar/zip → 4。
|
||||
* 未知扩展名按媒体类处理(formatCode=2),服务端按文件名扩展名判定。
|
||||
* 文件扩展名 → 闪传类型码。typeCode 用于 0x93cf f3(卡片粗类:压缩包/媒体);
|
||||
* formatCode 用于 0x93d0 commit f7 与 0x12a9 filesetWrap.f7,决定对端图标
|
||||
* (png=26,mp4=2,zip=4,未知=11)。
|
||||
*/
|
||||
private static fileTypeCode(fileName: string): { typeCode: number; formatCode: number } {
|
||||
const ext = fileName.toLowerCase().match(/\.([^.]+)$/)?.[1] ?? '';
|
||||
switch (ext) {
|
||||
case 'rar': return { typeCode: 2, formatCode: 4 };
|
||||
case 'zip': return { typeCode: 6, formatCode: 4 };
|
||||
case '7z': case 'gz': case 'tar': case 'bz2': return { typeCode: 2, formatCode: 4 };
|
||||
case 'png': case 'jpg': case 'jpeg': case 'bmp': case 'gif': case 'webp':
|
||||
case 'mp4': case 'mov': case 'avi': case 'mkv':
|
||||
return { typeCode: 7, formatCode: 2 };
|
||||
default: return { typeCode: 7, formatCode: 2 };
|
||||
}
|
||||
return { typeCode: flashApplyTypeCode(ext), formatCode: flashFormatCode(ext) };
|
||||
}
|
||||
|
||||
/** 构造 sub=103 的 fileId(客户端生成的 protobuf,base64url 编码)。
|
||||
@@ -530,7 +570,8 @@ export class FlashTransferApi {
|
||||
|
||||
/**
|
||||
* 阶段1:流式哈希 + prepare(拿 rkey)+ apply(注册 fileId)。
|
||||
* 秒传(rkey=null)返回 null,调用方跳过 sliceupload。
|
||||
* 秒传时 prepare 不回 rkey,仍必须 apply,否则 fileset 会一直停在等待上传;
|
||||
* 返回 null 只表示调用方跳过 sliceupload。
|
||||
*/
|
||||
private async prepareAndApply(
|
||||
filesetUuid: string, it: StagedFlashItem,
|
||||
@@ -542,13 +583,12 @@ export class FlashTransferApi {
|
||||
filesetUuid, fileUuid: it.fileUuid, fileName: it.fileName, fileSize: it.fileSize,
|
||||
sha1: hashes.sha1Hex, fileIndex: it.fileIndex, formatCode: it.formatCode,
|
||||
});
|
||||
if (rkey === null) return null; // 秒传
|
||||
|
||||
const fileId = FlashTransferApi.buildFileId(hashes.sha1, it.fileSize);
|
||||
await ApplyUpload.invoke(this.ctx, {
|
||||
filesetUuid, fileUuid: it.fileUuid, fileId, fileName: it.fileName, fileSize: it.fileSize,
|
||||
md5: hashes.md5Hex, sha1: hashes.sha1Hex, fileIndex: it.fileIndex, formatCode: it.formatCode,
|
||||
});
|
||||
if (rkey === null) return null;
|
||||
return { rkey, sha1StateV: hashes.sha1StateV, sliceCount: hashes.sliceCount };
|
||||
}
|
||||
|
||||
@@ -638,12 +678,12 @@ export class FlashTransferApi {
|
||||
filesetUuid, fileUuid, fileName, fileSize, sha1: hashes.sha1Hex,
|
||||
fileIndex, formatCode: thumbFormatCode, thumbType, width, height,
|
||||
});
|
||||
if (rkey === null) return; // 秒传
|
||||
const fileId = FlashTransferApi.buildFileId(hashes.sha1, fileSize, appid);
|
||||
await ApplyUpload.invoke(this.ctx, {
|
||||
filesetUuid, fileUuid, fileId, fileName, fileSize,
|
||||
md5: hashes.md5Hex, sha1: hashes.sha1Hex, fileIndex, formatCode: thumbFormatCode, thumbType, width, height,
|
||||
});
|
||||
if (rkey === null) return;
|
||||
// sliceupload(缩略图小,1 片,Sha1StateV=[标准 SHA1])
|
||||
const sha1StateV = computeSha1StateV(new Uint8Array(thumbBytes), 1, fileSize);
|
||||
const body: FlashSliceUploadBody = {
|
||||
|
||||
@@ -196,10 +196,30 @@ describe('FlashTransferApi.createFlashTask — disk streaming (#359)', () => {
|
||||
|
||||
await api().createFlashTask(file);
|
||||
expect(mainSlices(slices)).toHaveLength(0);
|
||||
expect(ApplyUpload.invoke).toHaveBeenCalled(); // thumbs still apply
|
||||
expect(ApplyUpload.invoke).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
||||
fileName: 'hit.mp4',
|
||||
}));
|
||||
expect(SetFilesetStatus.invoke).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('commits a png as image format 26 rather than video format 2 (#421)', async () => {
|
||||
const file = writeSrc('shot.png', synth(48, 5));
|
||||
installSliceuploadOk();
|
||||
|
||||
await api().createFlashTask(file);
|
||||
|
||||
expect(ApplyFileset.invoke).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
||||
fileName: 'shot.png',
|
||||
typeCode: 7,
|
||||
}));
|
||||
expect(CommitFile.invoke).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
||||
entries: [expect.objectContaining({
|
||||
fileName: 'shot.png',
|
||||
formatCode: 26,
|
||||
})],
|
||||
}));
|
||||
});
|
||||
|
||||
it('sliceuploads a multi-megabyte file as 1 MiB disk chunks with flash Sha1StateV', async () => {
|
||||
const bytes = synth(SLICE + 80, 13);
|
||||
const file = writeSrc('big.mp4', bytes);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/mcp",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"description": "MCP server exposing the SnowLuma OneBot action catalog (docs + JSON Schemas) and optional execution to LLM clients.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -5314,6 +5314,18 @@
|
||||
"card_changeable": {
|
||||
"type": "boolean",
|
||||
"description": "是否可改名片(占位,恒 true)"
|
||||
},
|
||||
"qidian_master_flag": {
|
||||
"type": "integer",
|
||||
"description": "企点主号标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_crew_flag": {
|
||||
"type": "integer",
|
||||
"description": "企点员工标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_crew_flag_2": {
|
||||
"type": "integer",
|
||||
"description": "企点保留标志,0 或 1;普通账号为 0"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -5473,6 +5485,18 @@
|
||||
"card_changeable": {
|
||||
"type": "boolean",
|
||||
"description": "是否可改名片(占位,恒 true)"
|
||||
},
|
||||
"qidian_master_flag": {
|
||||
"type": "integer",
|
||||
"description": "企点主号标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_crew_flag": {
|
||||
"type": "integer",
|
||||
"description": "企点员工标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_crew_flag_2": {
|
||||
"type": "integer",
|
||||
"description": "企点保留标志,0 或 1;普通账号为 0"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -7421,7 +7445,7 @@
|
||||
"name": "get_stranger_info",
|
||||
"aliases": [],
|
||||
"summary": "获取陌生人信息",
|
||||
"returns": "用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级与企点标志。",
|
||||
"returns": "用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级、企点标志与企业名称。",
|
||||
"returnsSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -7493,6 +7517,10 @@
|
||||
"qidian_crew_flag_2": {
|
||||
"type": "integer",
|
||||
"description": "企点保留标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_enterprise_name": {
|
||||
"type": "string",
|
||||
"description": "企点企业名称;非企点账号或未获取到时为空字符串"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -5317,6 +5317,18 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"card_changeable": {
|
||||
"type": "boolean",
|
||||
"description": "是否可改名片(占位,恒 true)"
|
||||
},
|
||||
"qidian_master_flag": {
|
||||
"type": "integer",
|
||||
"description": "企点主号标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_crew_flag": {
|
||||
"type": "integer",
|
||||
"description": "企点员工标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_crew_flag_2": {
|
||||
"type": "integer",
|
||||
"description": "企点保留标志,0 或 1;普通账号为 0"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -5476,6 +5488,18 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"card_changeable": {
|
||||
"type": "boolean",
|
||||
"description": "是否可改名片(占位,恒 true)"
|
||||
},
|
||||
"qidian_master_flag": {
|
||||
"type": "integer",
|
||||
"description": "企点主号标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_crew_flag": {
|
||||
"type": "integer",
|
||||
"description": "企点员工标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_crew_flag_2": {
|
||||
"type": "integer",
|
||||
"description": "企点保留标志,0 或 1;普通账号为 0"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -7424,7 +7448,7 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"name": "get_stranger_info",
|
||||
"aliases": [],
|
||||
"summary": "获取陌生人信息",
|
||||
"returns": "用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级与企点标志。",
|
||||
"returns": "用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级、企点标志与企业名称。",
|
||||
"returnsSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -7496,6 +7520,10 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"qidian_crew_flag_2": {
|
||||
"type": "integer",
|
||||
"description": "企点保留标志,0 或 1;普通账号为 0"
|
||||
},
|
||||
"qidian_enterprise_name": {
|
||||
"type": "string",
|
||||
"description": "企点企业名称;非企点账号或未获取到时为空字符串"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/onebot",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"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.<area>.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/<x>'` collapses to `import { … } from '@snowluma/onebot/<x>'`.",
|
||||
|
||||
@@ -32,7 +32,7 @@ export const actions = [
|
||||
name: 'get_stranger_info',
|
||||
summary: '获取陌生人信息',
|
||||
readOnly: true,
|
||||
returns: '用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级与企点标志。',
|
||||
returns: '用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级、企点标志与企业名称。',
|
||||
returnsSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -53,6 +53,7 @@ export const actions = [
|
||||
qidian_master_flag: { type: 'integer', description: '企点主号标志,0 或 1;普通账号为 0' },
|
||||
qidian_crew_flag: { type: 'integer', description: '企点员工标志,0 或 1;普通账号为 0' },
|
||||
qidian_crew_flag_2: { type: 'integer', description: '企点保留标志,0 或 1;普通账号为 0' },
|
||||
qidian_enterprise_name: { type: 'string', description: '企点企业名称;非企点账号或未获取到时为空字符串' },
|
||||
},
|
||||
required: ['user_id', 'nickname', 'remark', 'sex', 'age', 'long_nick'],
|
||||
},
|
||||
|
||||
@@ -115,6 +115,9 @@ export const actions = [
|
||||
unfriendly: { type: 'boolean', description: '是否不良记录(QQ NT 不提供,恒 false)' },
|
||||
title_expire_time: { type: 'integer', description: '头衔过期时间戳(QQ NT 不提供,恒 0)' },
|
||||
card_changeable: { type: 'boolean', description: '是否可改名片(占位,恒 true)' },
|
||||
qidian_master_flag: { type: 'integer', description: '企点主号标志,0 或 1;普通账号为 0' },
|
||||
qidian_crew_flag: { type: 'integer', description: '企点员工标志,0 或 1;普通账号为 0' },
|
||||
qidian_crew_flag_2: { type: 'integer', description: '企点保留标志,0 或 1;普通账号为 0' },
|
||||
},
|
||||
required: ['group_id', 'user_id', 'nickname', 'role'],
|
||||
},
|
||||
@@ -155,6 +158,9 @@ export const actions = [
|
||||
unfriendly: { type: 'boolean', description: '是否不良记录(QQ NT 不提供,恒 false)' },
|
||||
title_expire_time: { type: 'integer', description: '头衔过期时间戳(QQ NT 不提供,恒 0)' },
|
||||
card_changeable: { type: 'boolean', description: '是否可改名片(占位,恒 true)' },
|
||||
qidian_master_flag: { type: 'integer', description: '企点主号标志,0 或 1;普通账号为 0' },
|
||||
qidian_crew_flag: { type: 'integer', description: '企点员工标志,0 或 1;普通账号为 0' },
|
||||
qidian_crew_flag_2: { type: 'integer', description: '企点保留标志,0 或 1;普通账号为 0' },
|
||||
},
|
||||
required: ['group_id', 'user_id', 'nickname', 'role'],
|
||||
},
|
||||
@@ -171,6 +177,7 @@ export const actions = [
|
||||
sex: 'unknown', age: 0, join_time: 0, last_sent_time: 0,
|
||||
shut_up_timestamp: 0,
|
||||
level: '0', role: 'member', title: '',
|
||||
qidian_master_flag: 0, qidian_crew_flag: 0, qidian_crew_flag_2: 0,
|
||||
});
|
||||
}
|
||||
return okResponse({
|
||||
|
||||
@@ -79,6 +79,44 @@ function isExplicitEmptyTextPlaceholder(segment: MessageSegment): boolean {
|
||||
&& segmentPayload(segment).text === '';
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the OneBot payload is a forward: every effective segment is
|
||||
* `node` (explicit empty-text placeholders ignored). `send_msg` routes
|
||||
* this list through the forward upload path instead of parseMessage.
|
||||
*/
|
||||
export function isExclusiveForwardNodeMessage(
|
||||
message: JsonValue,
|
||||
autoEscape: boolean,
|
||||
): boolean {
|
||||
return exclusiveForwardNodeList(message, autoEscape) !== null;
|
||||
}
|
||||
|
||||
/** Node segments from an exclusive forward payload, or null if it is not one. */
|
||||
export function exclusiveForwardNodeList(
|
||||
message: JsonValue,
|
||||
autoEscape: boolean,
|
||||
): JsonValue[] | null {
|
||||
if (autoEscape && typeof message === 'string') return null;
|
||||
if (typeof message === 'object' && message !== null && !Array.isArray(message)) {
|
||||
const type = (message as { type?: unknown }).type;
|
||||
return typeof type === 'string' && normalizeSegmentType(type) === 'node'
|
||||
? [message]
|
||||
: null;
|
||||
}
|
||||
if (!Array.isArray(message) || message.length === 0) return null;
|
||||
const nodes: JsonValue[] = [];
|
||||
for (const item of message) {
|
||||
if (typeof item !== 'object' || item === null || Array.isArray(item)) return null;
|
||||
const type = (item as { type?: unknown }).type;
|
||||
if (typeof type !== 'string' || type.trim().length === 0) return null;
|
||||
const segment = item as MessageSegment;
|
||||
if (isExplicitEmptyTextPlaceholder(segment)) continue;
|
||||
if (normalizeSegmentType(type) !== 'node') return null;
|
||||
nodes.push(item);
|
||||
}
|
||||
return nodes.length > 0 ? nodes : null;
|
||||
}
|
||||
|
||||
function outboundInputSegmentSummary(
|
||||
message: JsonValue,
|
||||
autoEscape: boolean,
|
||||
@@ -222,13 +260,13 @@ export async function segmentToElement(type: string, data: Record<string, unknow
|
||||
assertScalarSegmentData(normalizedType, data);
|
||||
}
|
||||
|
||||
// 纯 OneBot 输入词:可执行的塌缩成 json/face/poke;没有合法发送语义的 node /
|
||||
// anonymous 在这里明确拒绝。它们无收侧对应、无专属 wire 形态,故不进 codec 表。
|
||||
// 真实元素(收发同名)走下方的 ELEMENT_CODECS。
|
||||
// 纯 OneBot 输入词:可执行的塌缩成 json/face/poke。整条消息都是 node 时由
|
||||
// send 路径交给 parseForwardNodes;混进普通消息的 node、以及 anonymous,
|
||||
// 在这里明确拒绝。真实元素(收发同名)走下方的 ELEMENT_CODECS。
|
||||
switch (normalizedType) {
|
||||
case 'node': {
|
||||
// Forward-node arrays are consumed by parseForwardNodes before reaching
|
||||
// this function. A node mixed into a normal message is not sendable.
|
||||
// Exclusive node arrays never reach this function. A node mixed into a
|
||||
// normal message is not sendable.
|
||||
throw new MessageElementValidationError(
|
||||
'UNSENDABLE_TYPE',
|
||||
'message segment "node" is only valid inside a forward node list',
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { mapWithConcurrency } from '@snowluma/common/concurrency';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
|
||||
import type { IdentityService } from '@snowluma/protocol/identity-service';
|
||||
import {
|
||||
formatGroupRequestFlag,
|
||||
type GroupMemberInfo,
|
||||
type GroupRequestInfo,
|
||||
type UserProfileInfo,
|
||||
} from '@snowluma/protocol/qq-info';
|
||||
import type { QidianCorpInfo } from '@snowluma/protocol/services/qidian/fetch-corp-info';
|
||||
import type { OneBotInstanceContext } from '../instance-context';
|
||||
import type { JsonObject } from '../types';
|
||||
|
||||
@@ -211,12 +211,12 @@ export async function getGroupMemberList(
|
||||
): Promise<JsonObject[]> {
|
||||
if (noCache) {
|
||||
const members = await fetchSingleGroupMembers(bridge, groupId, true);
|
||||
return members.map(m => formatGroupMember(groupId, m));
|
||||
return members.map(m => formatGroupMember(groupId, m, cachedQidianProfile(bridge, m.uin)));
|
||||
}
|
||||
|
||||
try {
|
||||
const members = await bridge.apis.contacts.fetchGroupMemberList(groupId);
|
||||
return members.map(m => formatGroupMember(groupId, m));
|
||||
return members.map(m => formatGroupMember(groupId, m, cachedQidianProfile(bridge, m.uin)));
|
||||
} catch (err) {
|
||||
log.warn(
|
||||
'group member fetch failed, using classified cache: uin=%s group=%d err=%s',
|
||||
@@ -224,7 +224,7 @@ export async function getGroupMemberList(
|
||||
groupId,
|
||||
err instanceof Error ? (err.stack ?? err.message) : String(err),
|
||||
);
|
||||
const cached = getCachedGroupMembers(bridge.identity, groupId);
|
||||
const cached = getCachedGroupMembers(bridge, groupId);
|
||||
if (cached.length === 0) throw err;
|
||||
return cached;
|
||||
}
|
||||
@@ -242,7 +242,17 @@ export async function getGroupMemberInfo(
|
||||
}
|
||||
const m = bridge.identity.findGroupMember(groupId, userId);
|
||||
if (!m) return null;
|
||||
return formatGroupMember(groupId, m);
|
||||
// 企点标志(#404 后续 PR):优先读身份缓存,无缓存时再按需拉取一次用户资料。
|
||||
// 均为 best-effort —— 失败时回退为 0,不影响成员信息主流程。
|
||||
let profile = cachedQidianProfile(bridge, userId);
|
||||
if (!profile) {
|
||||
try {
|
||||
profile = await bridge.apis.contacts.fetchUserProfile(userId);
|
||||
} catch {
|
||||
// profile enrichment is best-effort; fall back to all-zero flags
|
||||
}
|
||||
}
|
||||
return formatGroupMember(groupId, m, profile ?? undefined);
|
||||
}
|
||||
|
||||
export async function getGroupFiles(
|
||||
@@ -280,7 +290,7 @@ export async function getGroupFiles(
|
||||
};
|
||||
}
|
||||
|
||||
function formatStrangerInfo(p: UserProfileInfo): JsonObject {
|
||||
function formatStrangerInfo(p: UserProfileInfo, corp?: QidianCorpInfo | null): JsonObject {
|
||||
return {
|
||||
user_id: p.uin,
|
||||
nickname: p.nickname,
|
||||
@@ -299,23 +309,42 @@ function formatStrangerInfo(p: UserProfileInfo): JsonObject {
|
||||
qidian_master_flag: p.qidianMasterFlag ?? 0,
|
||||
qidian_crew_flag: p.qidianCrewFlag ?? 0,
|
||||
qidian_crew_flag_2: p.qidianCrewFlag2 ?? 0,
|
||||
// #404 后续 PR:企点企业资料卡。企业资料卡不含独立的企业 ID,
|
||||
// 因此这里只透出企业名称(SsoCorpInfo.corpName)。
|
||||
qidian_enterprise_name: corp?.name ?? '',
|
||||
};
|
||||
}
|
||||
|
||||
/** 命中的是企点账号时才去拉一次企业资料卡(best-effort,失败返回 null)。 */
|
||||
async function strangerCorpInfo(
|
||||
bridge: BridgeInterface,
|
||||
p: UserProfileInfo,
|
||||
): Promise<QidianCorpInfo | null> {
|
||||
if (p.qidianMasterFlag === 0 && p.qidianCrewFlag === 0) return null;
|
||||
try {
|
||||
return await bridge.apis.contacts.fetchQidianCorpInfo(p.uin);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStrangerInfo(
|
||||
bridge: BridgeInterface,
|
||||
userId: number,
|
||||
): Promise<JsonObject | null> {
|
||||
try {
|
||||
const p = await bridge.apis.contacts.fetchUserProfile(userId);
|
||||
return formatStrangerInfo(p);
|
||||
const corp = await strangerCorpInfo(bridge, p);
|
||||
return formatStrangerInfo(p, corp);
|
||||
} catch {
|
||||
const p = bridge.identity.findUserProfile(userId);
|
||||
if (p) {
|
||||
return formatStrangerInfo({
|
||||
const profile: UserProfileInfo = {
|
||||
...p,
|
||||
remark: p.remark || bridge.identity.findFriend(userId)?.remark || '',
|
||||
});
|
||||
};
|
||||
const corp = await strangerCorpInfo(bridge, profile);
|
||||
return formatStrangerInfo(profile, corp);
|
||||
}
|
||||
|
||||
const friend = bridge.identity.findFriend(userId);
|
||||
@@ -492,12 +521,12 @@ export async function getDownloadRKeys(bridge: BridgeInterface): Promise<JsonObj
|
||||
}
|
||||
}
|
||||
|
||||
function getCachedGroupMembers(identity: IdentityService, groupId: number): JsonObject[] {
|
||||
const g = identity.findGroup(groupId);
|
||||
function getCachedGroupMembers(bridge: BridgeInterface, groupId: number): JsonObject[] {
|
||||
const g = bridge.identity.findGroup(groupId);
|
||||
if (!g) return [];
|
||||
const result: JsonObject[] = [];
|
||||
for (const [, member] of g.members) {
|
||||
result.push(formatGroupMember(groupId, member));
|
||||
result.push(formatGroupMember(groupId, member, cachedQidianProfile(bridge, member.uin)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -505,6 +534,7 @@ function getCachedGroupMembers(identity: IdentityService, groupId: number): Json
|
||||
function formatGroupMember(
|
||||
groupId: number,
|
||||
member: GroupMemberInfo,
|
||||
profile?: UserProfileInfo,
|
||||
): JsonObject {
|
||||
if (member.isRobot === undefined) {
|
||||
throw new Error(
|
||||
@@ -532,5 +562,24 @@ function formatGroupMember(
|
||||
unfriendly: false,
|
||||
title_expire_time: 0,
|
||||
card_changeable: true,
|
||||
// 企点标志(#404 后续 PR):群成员信息同样透传用户资料上的企点标志,
|
||||
// 未查到资料时全部为 0(普通账号)。
|
||||
qidian_master_flag: profile?.qidianMasterFlag ?? 0,
|
||||
qidian_crew_flag: profile?.qidianCrewFlag ?? 0,
|
||||
qidian_crew_flag_2: profile?.qidianCrewFlag2 ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
/** Best-effort read of a cached user profile's qidian flags. Triggers no
|
||||
* network call — only the identity cache (populated by fetchUserProfile /
|
||||
* fetchUserProfileByUid). */
|
||||
function cachedQidianProfile(bridge: BridgeInterface, uin: number): UserProfileInfo | undefined {
|
||||
try {
|
||||
if ('findUserProfile' in bridge.identity) {
|
||||
return bridge.identity.findUserProfile(uin) ?? undefined;
|
||||
}
|
||||
} catch {
|
||||
// profile cache lookup is best-effort; fall back to all-zero flags
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from '../message-id';
|
||||
import {
|
||||
assertOutboundMessageInput,
|
||||
exclusiveForwardNodeList,
|
||||
MessageElementValidationError,
|
||||
parseMessage,
|
||||
} from '../message-parser';
|
||||
@@ -802,6 +803,17 @@ export async function sendPrivateMessage(
|
||||
autoEscape,
|
||||
tempGroupId === undefined ? 'direct-private' : 'group-temp',
|
||||
);
|
||||
const privateForwardNodes = exclusiveForwardNodeList(message, autoEscape);
|
||||
if (privateForwardNodes) {
|
||||
if (tempGroupId !== undefined) {
|
||||
throw new MessageElementValidationError(
|
||||
'UNSENDABLE_TYPE',
|
||||
'message segment "node" cannot be sent in a temp session',
|
||||
'node',
|
||||
);
|
||||
}
|
||||
return sendPrivateForwardMessage(ref, userId, privateForwardNodes, undefined, onSelfSent);
|
||||
}
|
||||
const elements = await parseMessage(message, autoEscape, {
|
||||
resolveReplySequence: (replyMessageId) => {
|
||||
return ref.messageStore.resolveReplySequence(false, userId, replyMessageId);
|
||||
@@ -1035,6 +1047,11 @@ export async function sendGroupMessage(
|
||||
autoEscape: boolean,
|
||||
): Promise<MessageSendResult> {
|
||||
assertOutboundMessageInput(message, autoEscape, 'group');
|
||||
const groupForwardNodes = exclusiveForwardNodeList(message, autoEscape);
|
||||
if (groupForwardNodes) {
|
||||
const result = await sendGroupForwardMessage(ref, groupId, groupForwardNodes);
|
||||
return { messageId: result.messageId };
|
||||
}
|
||||
const elements = await parseMessage(message, autoEscape, {
|
||||
resolveReplySequence: (replyMessageId) => {
|
||||
return ref.messageStore.resolveReplySequence(true, groupId, replyMessageId);
|
||||
|
||||
@@ -510,6 +510,54 @@ describe('onebot/contact-actions / getGroupMemberInfo', () => {
|
||||
expect(out).toMatchObject({ user_id: 66, is_robot: true });
|
||||
});
|
||||
|
||||
it('passes through the qidian (企点) flags from the member profile', async () => {
|
||||
const member = makeMember(88, 'QidianMember', 'Q');
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupMemberList: vi.fn(async () => []),
|
||||
identity: fakeIdentity({
|
||||
findGroupMember: (gid: number, uin: number) =>
|
||||
gid === 1400 && uin === 88 ? member : null,
|
||||
}),
|
||||
fetchUserProfile: vi.fn(async () => ({
|
||||
...makeProfile(88, 'QidianMember', 'male'),
|
||||
qidianMasterFlag: 0,
|
||||
qidianCrewFlag: 1,
|
||||
qidianCrewFlag2: 0,
|
||||
})),
|
||||
});
|
||||
|
||||
const out = await getGroupMemberInfo(bridge, 1400, 88);
|
||||
|
||||
expect(out).toMatchObject({
|
||||
user_id: 88,
|
||||
qidian_master_flag: 0,
|
||||
qidian_crew_flag: 1,
|
||||
qidian_crew_flag_2: 0,
|
||||
});
|
||||
expect(bridge.apis.contacts.fetchUserProfile).toHaveBeenCalledWith(88);
|
||||
});
|
||||
|
||||
it('falls back to zero qidian flags when the profile fetch fails', async () => {
|
||||
const member = makeMember(89, 'NoProfileMember', 'N');
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupMemberList: vi.fn(async () => []),
|
||||
identity: fakeIdentity({
|
||||
findGroupMember: (gid: number, uin: number) =>
|
||||
gid === 1500 && uin === 89 ? member : null,
|
||||
}),
|
||||
fetchUserProfile: vi.fn(async () => { throw new Error('net down'); }),
|
||||
});
|
||||
|
||||
const out = await getGroupMemberInfo(bridge, 1500, 89);
|
||||
|
||||
expect(out).toMatchObject({
|
||||
user_id: 89,
|
||||
qidian_master_flag: 0,
|
||||
qidian_crew_flag: 0,
|
||||
qidian_crew_flag_2: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects when an unknown cached classification cannot be refreshed', async () => {
|
||||
const member: GroupMemberInfo = { ...makeMember(77, 'unknown'), isRobot: undefined };
|
||||
const bridge = fakeBridge({
|
||||
@@ -566,6 +614,55 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('passes through the qidian enterprise (企业) data-card when available', async () => {
|
||||
const fetchQidianCorpInfo = vi.fn(async () => ({
|
||||
name: '测试企业', intro: '测试简介', website: 'https://example.com',
|
||||
slogan: '测试签名', address: '测试地址', phone: '400-0000-0000', email: 'contact@example.com',
|
||||
}));
|
||||
const bridge = fakeBridge({
|
||||
apis: {
|
||||
contacts: {
|
||||
fetchUserProfile: vi.fn(async () => ({
|
||||
...makeProfile(55555, 'QidianWorker', 'male'),
|
||||
qidianMasterFlag: 0,
|
||||
qidianCrewFlag: 1,
|
||||
qidianCrewFlag2: 0,
|
||||
})),
|
||||
fetchQidianCorpInfo,
|
||||
},
|
||||
},
|
||||
});
|
||||
const out = await getStrangerInfo(bridge, 55555);
|
||||
expect(out).toMatchObject({
|
||||
user_id: 55555,
|
||||
qidian_master_flag: 0,
|
||||
qidian_crew_flag: 1,
|
||||
qidian_crew_flag_2: 0,
|
||||
qidian_enterprise_name: '测试企业',
|
||||
});
|
||||
expect(fetchQidianCorpInfo).toHaveBeenCalledWith(55555);
|
||||
});
|
||||
|
||||
it('leaves enterprise fields empty for non-qidian accounts and never calls the corp lookup', async () => {
|
||||
const fetchQidianCorpInfo = vi.fn(async () => ({
|
||||
name: 'x', intro: '', website: '', slogan: '', address: '', phone: '', email: '',
|
||||
}));
|
||||
const bridge = fakeBridge({
|
||||
apis: {
|
||||
contacts: {
|
||||
fetchUserProfile: vi.fn(async () => makeProfile(88888, 'Normal', 'male')),
|
||||
fetchQidianCorpInfo,
|
||||
},
|
||||
},
|
||||
});
|
||||
const out = await getStrangerInfo(bridge, 88888);
|
||||
expect(out).toMatchObject({
|
||||
user_id: 88888,
|
||||
qidian_enterprise_name: '',
|
||||
});
|
||||
expect(fetchQidianCorpInfo).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('falls back to identity.findUserProfile when fetch fails but the profile is cached', async () => {
|
||||
const bridge = fakeBridge({
|
||||
fetchUserProfile: vi.fn(async () => { throw new Error('net'); }),
|
||||
|
||||
@@ -34,6 +34,7 @@ describe('get_stranger_info action', () => {
|
||||
qidian_master_flag: { type: 'integer' },
|
||||
qidian_crew_flag: { type: 'integer' },
|
||||
qidian_crew_flag_2: { type: 'integer' },
|
||||
qidian_enterprise_name: { type: 'string' },
|
||||
},
|
||||
});
|
||||
expect(schema?.required).toContain('remark');
|
||||
|
||||
@@ -116,4 +116,15 @@ describe('group information actions', () => {
|
||||
data: { user_id: 654323, shut_up_timestamp: 0 },
|
||||
});
|
||||
});
|
||||
|
||||
it('documents qidian flags on both member-list and single-member results', () => {
|
||||
const listSchema = getGroupMemberList.describe().returnsSchema;
|
||||
const infoSchema = getGroupMemberInfo.describe().returnsSchema;
|
||||
|
||||
for (const schema of [listSchema?.items?.properties, infoSchema?.properties]) {
|
||||
expect(schema).toHaveProperty('qidian_master_flag');
|
||||
expect(schema).toHaveProperty('qidian_crew_flag');
|
||||
expect(schema).toHaveProperty('qidian_crew_flag_2');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -775,6 +775,9 @@ describe('buildApiContext contact reads', () => {
|
||||
unfriendly: false,
|
||||
title_expire_time: 0,
|
||||
card_changeable: true,
|
||||
qidian_master_flag: 0,
|
||||
qidian_crew_flag: 0,
|
||||
qidian_crew_flag_2: 0,
|
||||
}]);
|
||||
await expect(api.getGroupMemberInfo(710503, 20002)).resolves.toMatchObject({
|
||||
group_id: 710503,
|
||||
@@ -820,6 +823,7 @@ describe('buildApiContext contact reads', () => {
|
||||
qidian_master_flag: 0,
|
||||
qidian_crew_flag: 0,
|
||||
qidian_crew_flag_2: 0,
|
||||
qidian_enterprise_name: '',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1120,6 +1124,44 @@ describe('buildApiContext send and forward dispatch', () => {
|
||||
expect(dispatchEvent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('send_private_msg with an exclusive node list uploads a forward (#415)', async () => {
|
||||
const { api, dispatchEvent, ref } = makeRef();
|
||||
const nodes = [{
|
||||
type: 'node',
|
||||
data: {
|
||||
user_id: SELF_ID,
|
||||
nickname: 'SnowLuma',
|
||||
content: [{ type: 'text', data: { text: 'forwarded' } }],
|
||||
},
|
||||
}];
|
||||
|
||||
const result = await api.sendPrivateMessage(PEER_ID, nodes, false);
|
||||
|
||||
expect(result.messageId).toBe(hashMessageIdInt32(77, PEER_ID, PRIVATE_NT_MESSAGE_EVENT));
|
||||
expect(ref.bridge.apis.forward.upload).toHaveBeenCalledOnce();
|
||||
expect(ref.bridge.apis.message.sendPrivate).toHaveBeenCalledOnce();
|
||||
expect(dispatchEvent).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('send_group_msg with an exclusive node list uploads a forward (#415)', async () => {
|
||||
const { api, dispatchEvent, ref } = makeRef();
|
||||
const nodes = [{
|
||||
type: 'node',
|
||||
data: {
|
||||
user_id: SELF_ID,
|
||||
nickname: 'SnowLuma',
|
||||
content: [{ type: 'text', data: { text: 'pack' } }],
|
||||
},
|
||||
}];
|
||||
|
||||
const result = await api.sendGroupMessage(GROUP_ID, nodes, false);
|
||||
|
||||
expect(result.messageId).toBe(hashMessageIdInt32(77, GROUP_ID, GROUP_MESSAGE_EVENT));
|
||||
expect(ref.bridge.apis.forward.upload).toHaveBeenCalledOnce();
|
||||
expect(ref.bridge.apis.message.sendGroup).toHaveBeenCalledOnce();
|
||||
expect(dispatchEvent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('dispatches a private forward send', async () => {
|
||||
const { api, dispatchEvent, ref } = makeRef();
|
||||
|
||||
|
||||
@@ -3,7 +3,11 @@ import os from 'os';
|
||||
import path from 'path';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import { MessageElementValidationError, parseMessage } from '../src/message-parser';
|
||||
import {
|
||||
exclusiveForwardNodeList,
|
||||
MessageElementValidationError,
|
||||
parseMessage,
|
||||
} from '../src/message-parser';
|
||||
import { buildSendElems } from '@snowluma/protocol/element-builder';
|
||||
import type { MentionExtraSend } from '@snowluma/proto-defs/action';
|
||||
import type { MarketFacePbReserve } from '@snowluma/proto-defs/element';
|
||||
@@ -91,6 +95,20 @@ describe('parseMessage', () => {
|
||||
expect(result).toEqual([{ type: 'text', text: 'hello' }]);
|
||||
});
|
||||
|
||||
it('rejects a node mixed into a normal message', async () => {
|
||||
await expect(parseMessage(
|
||||
[
|
||||
{ type: 'text', data: { text: 'hi' } },
|
||||
{ type: 'node', data: { user_id: 1, content: [{ type: 'text', data: { text: 'x' } }] } },
|
||||
] as any,
|
||||
false,
|
||||
)).rejects.toMatchObject({
|
||||
code: 'UNSENDABLE_TYPE',
|
||||
elementType: 'node',
|
||||
message: 'message segment "node" is only valid inside a forward node list',
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores explicit empty text placeholders between sendable segments (issue #273)', async () => {
|
||||
const result = await parseMessage(
|
||||
[
|
||||
@@ -869,6 +887,34 @@ describe('parseMessage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('exclusiveForwardNodeList', () => {
|
||||
const node = {
|
||||
type: 'node',
|
||||
data: { user_id: 1, content: [{ type: 'text', data: { text: 'x' } }] },
|
||||
};
|
||||
|
||||
it('accepts a node array and a single node object', () => {
|
||||
expect(exclusiveForwardNodeList([node], false)).toEqual([node]);
|
||||
expect(exclusiveForwardNodeList(node, false)).toEqual([node]);
|
||||
});
|
||||
|
||||
it('strips explicit empty text placeholders around nodes', () => {
|
||||
expect(exclusiveForwardNodeList([
|
||||
{ type: 'text', data: { text: '' } },
|
||||
node,
|
||||
{ type: 'text', data: { text: '' } },
|
||||
], false)).toEqual([node]);
|
||||
});
|
||||
|
||||
it('rejects mixed node+text and auto-escaped strings', () => {
|
||||
expect(exclusiveForwardNodeList([
|
||||
node,
|
||||
{ type: 'text', data: { text: 'hi' } },
|
||||
], false)).toBeNull();
|
||||
expect(exclusiveForwardNodeList('hello', true)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('single segment object', () => {
|
||||
it('parses single segment object', async () => {
|
||||
const result = await parseMessage(
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { convertFriendMessage } from '../src/event-converter/to-message';
|
||||
import {
|
||||
hashMessageIdInt32,
|
||||
PRIVATE_MESSAGE_EVENT,
|
||||
PRIVATE_NT_MESSAGE_EVENT,
|
||||
PRIVATE_SENT_MESSAGE_EVENT,
|
||||
} from '../src/message-id';
|
||||
import { MessageStore } from '../src/message-store';
|
||||
import type { ConverterContext } from '../src/event-converter';
|
||||
import type { FriendMessage } from '@snowluma/protocol/events';
|
||||
|
||||
const SELF_ID = 3961840894;
|
||||
const PEER_ID = 2705892349;
|
||||
const CLIENT_SEQ = 509147526;
|
||||
const NT_SEQ = 63878;
|
||||
const SENT_AT = 1_787_409_444;
|
||||
|
||||
describe('private reply id matches send receipt (#417)', () => {
|
||||
let dir: string;
|
||||
let store: MessageStore;
|
||||
|
||||
beforeEach(() => {
|
||||
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'sl-reply-id-'));
|
||||
store = new MessageStore(path.join(dir, 'messages.db'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
store.close();
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('resolves a quote of a bot-sent private message to the send receipt id', async () => {
|
||||
const sendId = hashMessageIdInt32(NT_SEQ, PEER_ID, PRIVATE_NT_MESSAGE_EVENT);
|
||||
store.storeMeta(sendId, {
|
||||
isGroup: false,
|
||||
targetId: PEER_ID,
|
||||
sequence: NT_SEQ,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: PRIVATE_NT_MESSAGE_EVENT,
|
||||
clientSequence: CLIENT_SEQ,
|
||||
privateDirection: 'outgoing',
|
||||
random: 1,
|
||||
timestamp: SENT_AT,
|
||||
});
|
||||
|
||||
const ctx: ConverterContext = {
|
||||
selfId: SELF_ID,
|
||||
imageUrlResolver: null,
|
||||
mediaUrlResolver: null,
|
||||
mediaSegmentSink: null,
|
||||
messageIdResolver: (isGroup, sessionId, sequence, eventName, timestamp) => {
|
||||
const resolvedEventName = eventName
|
||||
|| (isGroup ? 'group_message' : PRIVATE_MESSAGE_EVENT);
|
||||
if (!isGroup
|
||||
&& timestamp !== undefined
|
||||
&& (resolvedEventName === PRIVATE_MESSAGE_EVENT
|
||||
|| resolvedEventName === PRIVATE_SENT_MESSAGE_EVENT)) {
|
||||
const storedId = store.findPrivateMessageId(
|
||||
sessionId,
|
||||
sequence,
|
||||
resolvedEventName === PRIVATE_SENT_MESSAGE_EVENT,
|
||||
timestamp,
|
||||
);
|
||||
if (storedId !== null) return storedId;
|
||||
}
|
||||
return hashMessageIdInt32(sequence, sessionId, resolvedEventName);
|
||||
},
|
||||
};
|
||||
|
||||
const event: FriendMessage = {
|
||||
kind: 'friend_message',
|
||||
time: SENT_AT + 4,
|
||||
selfUin: SELF_ID,
|
||||
senderUin: PEER_ID,
|
||||
peerUin: PEER_ID,
|
||||
senderNick: 'peer',
|
||||
msgSeq: 10151,
|
||||
ntMsgSeq: 10152,
|
||||
clientSeq: 10151,
|
||||
sequenceAuthoritative: true,
|
||||
msgId: 2,
|
||||
elements: [
|
||||
{
|
||||
type: 'reply',
|
||||
replySeq: CLIENT_SEQ,
|
||||
replySenderUin: SELF_ID,
|
||||
replyTime: SENT_AT,
|
||||
},
|
||||
{ type: 'text', text: '这是对bot的回复消息' },
|
||||
],
|
||||
};
|
||||
|
||||
const json = await convertFriendMessage(ctx, event);
|
||||
const reply = (json.message as Array<{ type: string; data: { id: string } }>)[0];
|
||||
expect(reply).toEqual({ type: 'reply', data: { id: String(sendId) } });
|
||||
expect(sendId).not.toBe(hashMessageIdInt32(CLIENT_SEQ, PEER_ID, PRIVATE_SENT_MESSAGE_EVENT));
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/proto-defs",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "SnowLuma QQ/Lagrange wire-protobuf type definitions. Pure TypeScript interfaces with proton's `pb<N, T>` 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).",
|
||||
@@ -44,6 +44,10 @@
|
||||
"types": "./src/get-c2c-msg.ts",
|
||||
"default": "./src/get-c2c-msg.ts"
|
||||
},
|
||||
"./qidian-corp": {
|
||||
"types": "./src/qidian-corp.ts",
|
||||
"default": "./src/qidian-corp.ts"
|
||||
},
|
||||
"./notify": {
|
||||
"types": "./src/notify.ts",
|
||||
"default": "./src/notify.ts"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { pb, uint_32 } from '@snowluma/proton';
|
||||
|
||||
// trpc.basic.corp.Datacard.SsoCorpInfo — 企点企业资料卡信息。
|
||||
// 请求:field1 = 目标账号 UIN(varint)。
|
||||
// 响应字段为企点企业资料卡:名称 / 简介 / 官网 / 企业签名 / 地址 / 电话 / 邮箱。
|
||||
export interface QidianCorpInfoRequest {
|
||||
uin?: pb<1, uint_32>;
|
||||
}
|
||||
|
||||
export interface QidianCorpInfoResponse {
|
||||
corpName?: pb<2, string>;
|
||||
intro?: pb<3, string>;
|
||||
website?: pb<4, string>;
|
||||
slogan?: pb<5, string>;
|
||||
address?: pb<6, string>;
|
||||
phone?: pb<7, string>;
|
||||
email?: pb<8, string>;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/protocol",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"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/<x>'` collapses to `import { … } from '@snowluma/protocol/<x>'`.",
|
||||
@@ -92,6 +92,10 @@
|
||||
"types": "./src/highway/*.ts",
|
||||
"default": "./src/highway/*.ts"
|
||||
},
|
||||
"./services/*": {
|
||||
"types": "./src/services/*.ts",
|
||||
"default": "./src/services/*.ts"
|
||||
},
|
||||
"./web/*": {
|
||||
"types": "./src/web/*.ts",
|
||||
"default": "./src/web/*.ts"
|
||||
|
||||
@@ -90,7 +90,8 @@ export namespace PrepareUpload {
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: FlashPrepareUploadResp): string | null => {
|
||||
// sub-100 resp f2={f1:rkey}(正常上传,CAES/CAIS/CAQS/CAMS)。
|
||||
// 秒传(文件已在服务端)时 f2 无 f1(rkey),返回 null,调用方跳过 sliceupload。
|
||||
// 秒传(文件已在服务端)时 f2 无 f1(rkey),返回 null,调用方仍要 apply,
|
||||
// 只跳过 sliceupload。
|
||||
return body.rkeyWrap?.rkey ?? null;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { QidianCorpInfoRequest, QidianCorpInfoResponse } from '@snowluma/proto-defs/qidian-corp';
|
||||
|
||||
// 企点企业资料卡(trpc.basic.corp.Datacard.SsoCorpInfo)。
|
||||
// 请求体为 protobuf field1 = 目标账号 UIN(varint)
|
||||
// 返回企业名称等资料卡字段(来源见 SnowLuma issue #404 讨论)。
|
||||
export const QIDIAN_CORP_INFO_CMD = 'trpc.basic.corp.Datacard.SsoCorpInfo';
|
||||
|
||||
export interface QidianCorpInfo {
|
||||
name: string;
|
||||
intro: string;
|
||||
website: string;
|
||||
slogan: string;
|
||||
address: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface RawSender {
|
||||
sendRawPacket(serviceCmd: string, body: Uint8Array, timeoutMs?: number): Promise<SendPacketResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the qidian enterprise data-card for a qidian account UIN.
|
||||
* Returns null when the account is not a qidian corp user or the server
|
||||
* returns no corp info. Best-effort by design — callers must NOT fail the
|
||||
* whole profile read if this lookup throws / returns null.
|
||||
*/
|
||||
export async function fetchQidianCorpInfo(
|
||||
sender: RawSender,
|
||||
uin: number,
|
||||
timeoutMs?: number,
|
||||
): Promise<QidianCorpInfo | null> {
|
||||
const req = protobuf_encode<QidianCorpInfoRequest>({ uin });
|
||||
const result = await sender.sendRawPacket(QIDIAN_CORP_INFO_CMD, req, timeoutMs);
|
||||
if (!result.success || !result.gotResponse || !result.responseData || result.responseData.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const decoded = protobuf_decode<QidianCorpInfoResponse>(result.responseData);
|
||||
const name = decoded?.corpName ?? '';
|
||||
if (!name) return null;
|
||||
return {
|
||||
name,
|
||||
intro: decoded?.intro ?? '',
|
||||
website: decoded?.website ?? '',
|
||||
slogan: decoded?.slogan ?? '',
|
||||
address: decoded?.address ?? '',
|
||||
phone: decoded?.phone ?? '',
|
||||
email: decoded?.email ?? '',
|
||||
};
|
||||
}
|
||||
@@ -53,7 +53,7 @@ describe('FetchUserProfileByUid namespace (UID form)', () => {
|
||||
it('decodes qidian flags from number-properties (0 when absent)', async () => {
|
||||
const qidian = makeSender({
|
||||
body: {
|
||||
uin: 3004251964, uid: 'u',
|
||||
uin: 10002, uid: 'u',
|
||||
properties: {
|
||||
bytesProperties: [],
|
||||
numberProperties: [
|
||||
|
||||
@@ -52,7 +52,7 @@ describe('FetchUserProfile namespace', () => {
|
||||
// 企点员工号:两个标志均为 1;普通账号服务器不返回这两个 key → 缺省 0
|
||||
const qidian = makeSender({
|
||||
body: {
|
||||
uin: 3004251964, uid: 'u',
|
||||
uin: 10002, uid: 'u',
|
||||
properties: {
|
||||
bytesProperties: [],
|
||||
numberProperties: [
|
||||
@@ -62,7 +62,7 @@ describe('FetchUserProfile namespace', () => {
|
||||
},
|
||||
} as any,
|
||||
});
|
||||
const out = await FetchUserProfile.invoke(qidian, { uin: 3004251964 });
|
||||
const out = await FetchUserProfile.invoke(qidian, { uin: 10002 });
|
||||
expect(out.qidianMasterFlag).toBe(1);
|
||||
expect(out.qidianCrewFlag).toBe(1);
|
||||
expect(out.qidianCrewFlag2).toBe(0);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { QidianCorpInfoResponse } from '@snowluma/proto-defs/qidian-corp';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import {
|
||||
fetchQidianCorpInfo,
|
||||
QIDIAN_CORP_INFO_CMD,
|
||||
} from '../../../src/services/qidian/fetch-corp-info';
|
||||
|
||||
function sender(body: Uint8Array, opts: Partial<SendPacketResult> = {}) {
|
||||
return {
|
||||
sendRawPacket: vi.fn(async () => ({
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
responseData: body,
|
||||
...opts,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
const CORP_BODY = protobuf_encode<QidianCorpInfoResponse>({
|
||||
corpName: '测试企业',
|
||||
intro: '测试简介',
|
||||
website: 'https://example.com',
|
||||
slogan: '测试签名',
|
||||
address: '测试地址',
|
||||
phone: '400-0000-0000',
|
||||
email: 'contact@example.com',
|
||||
});
|
||||
|
||||
describe('services/qidian / fetchQidianCorpInfo', () => {
|
||||
it('sends the corp info command with the uin as field 1', async () => {
|
||||
const s = sender(CORP_BODY);
|
||||
const out = await fetchQidianCorpInfo(s, 10001);
|
||||
expect(out?.name).toBe('测试企业');
|
||||
expect(s.sendRawPacket).toHaveBeenCalledWith(
|
||||
QIDIAN_CORP_INFO_CMD,
|
||||
expect.any(Uint8Array),
|
||||
undefined,
|
||||
);
|
||||
const body = s.sendRawPacket.mock.calls[0][1] as Uint8Array;
|
||||
expect(Buffer.from(body).toString('hex')).toBe('08914e');
|
||||
});
|
||||
|
||||
it('decodes the corp data-card fields', async () => {
|
||||
const out = await fetchQidianCorpInfo(sender(CORP_BODY), 10001);
|
||||
expect(out).toMatchObject({
|
||||
name: '测试企业',
|
||||
website: 'https://example.com',
|
||||
email: 'contact@example.com',
|
||||
});
|
||||
});
|
||||
|
||||
it('returns null for an empty / failed response', async () => {
|
||||
expect(await fetchQidianCorpInfo(sender(new Uint8Array(0)), 1)).toBeNull();
|
||||
expect(
|
||||
await fetchQidianCorpInfo(sender(new Uint8Array(0), { success: false, errorMessage: 'x' }), 1),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/proton",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"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.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/runtime",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "index.mjs",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"name": "MotricSeven",
|
||||
"email": "motricseven@gmail.com"
|
||||
},
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"description": "TypeScript SDK for SnowLuma OneBot HTTP and WebSocket transports",
|
||||
"keywords": [
|
||||
"snowluma",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"name": "MotricSeven",
|
||||
"email": "motricseven@gmail.com"
|
||||
},
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"description": "Shared SnowLuma UI primitives — Tailwind 4 theme tokens + shadcn-style atomic components",
|
||||
"keywords": [
|
||||
"snowluma",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "@snowluma/websocket",
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"name": "webui",
|
||||
"private": true,
|
||||
"version": "1.14.13",
|
||||
"version": "1.14.14",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
Reference in new issue
Block a user