@napuketto/kernel 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1310,6 +1310,8 @@ type CanonicalElement = {
1310
1310
  } | {
1311
1311
  type: "reply";
1312
1312
  messageId: string;
1313
+ senderUid?: string;
1314
+ senderUin?: string;
1313
1315
  } | {
1314
1316
  type: "forward";
1315
1317
  messageIds: string[];
@@ -1640,7 +1642,8 @@ export declare class FlashTransferApi {
1640
1642
  /** 好友条目(uid + 昵称/备注,昵称由 buddy service 缓存补全)。 */
1641
1643
  interface Friend {
1642
1644
  uid: string;
1643
- uin: string;
1645
+ /** QQ 号。无法解析时为空,uid 始终单独保留。 */
1646
+ uin: string | null;
1644
1647
  nickname: string;
1645
1648
  remark: string;
1646
1649
  }
@@ -1672,7 +1675,7 @@ interface DoubtFriendRequestInfo {
1672
1675
  }
1673
1676
  /** FriendApi 构造选项。 */
1674
1677
  interface FriendApiOptions {
1675
- /** uid→uin 转换器(通常注入 GroupApi.uidToUin);缺省 uin 退化为 uid。 */
1678
+ /** uid→uin 转换器(通常注入 GroupApi.uidToUin);只补缺少 UIN 的项。 */
1676
1679
  uidToUin?: ((uids: string[]) => Promise<Map<string, string>>) | undefined;
1677
1680
  }
1678
1681
  /** 好友 API:从 session 拿 buddy service,包装成语义化方法。 */
@@ -1682,6 +1685,7 @@ export declare class FriendApi {
1682
1685
  constructor(session: NodeIQQNTWrapperSession, opts?: FriendApiOptions);
1683
1686
  /** 好友列表(分类拍平为 Friend[];昵称/备注从 service 缓存读取)。 */
1684
1687
  getFriendList(): Promise<Friend[]>;
1688
+ private friendsFromCategories;
1685
1689
  /** 带分类的好友列表(get_friends_with_category,分类保留)。 */
1686
1690
  getFriendCategories(): Promise<FriendCategory[]>;
1687
1691
  /** 原始分类(getBuddyListV2 / 缓存)。 */
@@ -1698,8 +1702,6 @@ export declare class FriendApi {
1698
1702
  deleteFriend(uid: string, tempBlock?: boolean, tempBothDel?: boolean): Promise<void>;
1699
1703
  /** 可疑好友申请列表(get_doubt_friends_add_request;uin 经 uidToUin 转换)。 */
1700
1704
  getDoubtFriendRequest(count: number): Promise<DoubtFriendRequestInfo[]>;
1701
- /** 单项转换:DoubtBuddyReq → OB11 结构(可选字段条件赋值,exactOptionalPropertyTypes)。 */
1702
- private toDoubtFriendRequestInfo;
1703
1705
  /** 处理可疑好友申请(set_doubt_friends_add_request;uid=flag)。 */
1704
1706
  handleDoubtFriendRequest(uid: string): void;
1705
1707
  }
@@ -1792,16 +1794,51 @@ export declare class GroupApi {
1792
1794
  remainAtAllCountForGroup: number;
1793
1795
  }>;
1794
1796
  }
1797
+ declare const requestTypes: {
1798
+ readonly invitation: 1;
1799
+ readonly invited_join_request: 5;
1800
+ readonly join_request: 7;
1801
+ };
1802
+ type GroupRequestKind = keyof typeof requestTypes;
1803
+ interface GroupRequestRef {
1804
+ seq: string;
1805
+ groupCode: string;
1806
+ kind: GroupRequestKind;
1807
+ doubt: boolean;
1808
+ }
1809
+ interface PendingGroupRequest {
1810
+ request: GroupRequestRef;
1811
+ initiatorUid?: string;
1812
+ targetUid?: string;
1813
+ comment?: string;
1814
+ }
1815
+ /** 仅接受有完整审批标识的未处理群通知。 */
1816
+ export declare function toPendingGroupRequest(notify: GroupNotify, doubt: boolean): PendingGroupRequest | undefined;
1817
+ /** 兼容按序号审批的协议。指定队列时只读取该队列。 */
1818
+ export declare function findPendingGroupRequest(api: Pick<GroupNotifyApi, "getSingleScreenNotifies">, filter: {
1819
+ seq: string;
1820
+ doubt?: boolean | undefined;
1821
+ groupCode?: string;
1822
+ kind?: GroupRequestKind | readonly GroupRequestKind[] | undefined;
1823
+ }, count: number): Promise<{
1824
+ request: GroupRequestRef;
1825
+ notify: GroupNotify;
1826
+ }>;
1795
1827
  /** 群通知 API:从 session 拿 group service,包装成语义化方法。 */
1796
1828
  export declare class GroupNotifyApi {
1797
1829
  private readonly service;
1798
1830
  constructor(session: NodeIQQNTWrapperSession);
1799
1831
  /** 单屏通知列表(get_group_system_msg / set_group_add_request 共用)。 */
1800
1832
  getSingleScreenNotifies(doubt: boolean, count: number): Promise<GroupNotify[]>;
1833
+ /** 从实时通知提取可供 IPC 消费的请求。 */
1834
+ getPendingGroupRequests(doubt: boolean, notifies: unknown): PendingGroupRequest[];
1835
+ /** 处理同一登录会话发出的请求引用。QQ 负责权限与请求有效性判定。 */
1836
+ respondToRequest(request: GroupRequestRef, approve: boolean, reason?: string): Promise<void>;
1801
1837
  /** 禁言成员列表(get_group_shut_list)。 */
1802
1838
  getGroupShutUpMemberList(groupCode: string): Promise<GroupMember[]>;
1803
1839
  /** 处理群请求(set_group_add_request 应答;approve=true 同意 / false 拒绝)。 */
1804
1840
  handleGroupRequest(doubt: boolean, notify: GroupNotify, operateType: NTGroupRequestOperateTypes, reason: string): Promise<void>;
1841
+ private operateRequest;
1805
1842
  }
1806
1843
  /** Listener 接口形状(宽约束;精确签名由实例化时的具体接口保证)。 */
1807
1844
  type ListenerShape = Record<string, unknown>;
@@ -3610,4 +3647,4 @@ interface QqVersionInfo {
3610
3647
  }
3611
3648
  /** @deprecated 使用 `QqVersionInfo`(缩写大小写统一为 `Qq`)。 */
3612
3649
  type QQVersionInfo = QqVersionInfo;
3613
- export { type BootEnv, type BuddyCacheEventChannel, type BuddyCacheListener, type BuddyCacheOptions, type BuddyCategory, type BuddyCoreInfo, type BuddyEventChannel, type BuddyListEntry, type BuddyListener, type BuddyProfileLikeResult, type BuddyReq, type CanonicalElement, type ConfigFormat, type ConfigOptions, type ConfigPathOptions, type ConfigSchema, type ConsoleFormatStreamOptions, type CoreContext, type CoreContextOptions, type CoreLoginOptions, type DesktopPathConfig, type DeviceInfo, type DoubtBuddyReq, type DoubtFriendRequestInfo, type EnginInitDesktopConfig, type EssenceAddedItem, type EssenceCacheEntry, type EssenceDiffResult, type EssenceListSyncDeps, type EssenceMsgItem, type FaceElement, type FileElement, type FlashTransferFileSet, type FlashTransferFileStatus, type FlashTransferPermission, type FlashTransferTarget, type FlashTransferTaskInfo, type FlashTransferUploadListener, type FlashTransferUploadOptions, type FlashTransferUploadResult, type ForceFetchClientKeyRetType, type Friend, type FriendApiOptions, type FriendCategory, type GeneralCallResult, type GetFileListParam, type GrayTipElement, type GrayTipRevokeElement, type Group, type GroupBulletin, type GroupCacheOptions, type GroupDetailInfo, type GroupEventChannel, type GroupFileItemInfo, type GroupFileListItem, type GroupFileSystemInfo, type GroupFolderInfo, type GroupHonorWebInfo, type GroupListener, type GroupMember, type GroupMemberListChange, type GroupNotify, type GroupRemainAtTimes, type GroupSpaceInfo, type HonorListItem, type IKernelLoginListener, type KernelErrorCode, type KernelLoginListener, type KernelRuntime, type KernelRuntimeOptions, type KickMemberInfo, type KickMemberV2Req, type ListenerEvents, type ListenerRecordEvent, type ListenerRecordingResult, type LogConfig, type LogEnvSource, type LogFileConfig, type LogFormat, type LogLevel, type LogModuleName, type LoggerOptions, type LoginAccountInfo, type LoginEventChannel, type LoginListItem, type LoginListener, type LoginProgress, type LoginResult, type LoginState, type MsgEventChannel, type MsgListener, type MsgReadReportItem, type MsgReceipt, type NapukettoCoreOptions, type NodeIDependsAdapter, type NodeIDispatcherAdapter, type NodeIGlobalAdapter, type NodeIKernelBuddyService, type NodeIKernelGroupService, type NodeIKernelLoginService, type NodeIKernelMsgService, type NodeIKernelProfileLikeService, type NodeIKernelProfileService, type NodeIKernelRecentContactService, type NodeIKernelRichMediaService, type NodeIKernelSessionListener, type NodeIKernelTicketService, type NodeIQQNTStartupSessionWrapper, type NodeIQQNTWrapperEngine, type NodeIQQNTWrapperSession, type NodeQQNTWrapperUtil, type NudgeParam, type PathOptions, type Peer, type PicElement, type PinnedContact, type PlatformType, type PttElement, type QQVersionContext, type QQVersionInfo, type QqDataRootOptions, type QqVersionContext, type QqVersionInfo, type QrCodeData, type QuickLoginOptions, type RDeliveryConfig, type RawElement, type RawMessage, type RecentContact, type RecentContactEventChannel, type RecentContactFetchParam, type RecentContactListChanged, type RecentContactListener, type ReplyElement, type SelfInfo, type SendMessageElement, type SessionConfigOptions, type SessionListenerOptions, type ShutUpGroupMember, type StartNapukettoOptions, type StrangerInfo, type TextElement, type TimestampMode, type TipAioOpGrayTipElement, type TipGroupElement, type UserDetailInfoByUin, type VendorType, type VideoElement, type WrapperContext, type WrapperNodeApi, type WrapperSessionInitConfig, createSessionListener as createLifecycleSessionListener };
3650
+ export { type BootEnv, type BuddyCacheEventChannel, type BuddyCacheListener, type BuddyCacheOptions, type BuddyCategory, type BuddyCoreInfo, type BuddyEventChannel, type BuddyListEntry, type BuddyListener, type BuddyProfileLikeResult, type BuddyReq, type CanonicalElement, type ConfigFormat, type ConfigOptions, type ConfigPathOptions, type ConfigSchema, type ConsoleFormatStreamOptions, type CoreContext, type CoreContextOptions, type CoreLoginOptions, type DesktopPathConfig, type DeviceInfo, type DoubtBuddyReq, type DoubtFriendRequestInfo, type EnginInitDesktopConfig, type EssenceAddedItem, type EssenceCacheEntry, type EssenceDiffResult, type EssenceListSyncDeps, type EssenceMsgItem, type FaceElement, type FileElement, type FlashTransferFileSet, type FlashTransferFileStatus, type FlashTransferPermission, type FlashTransferTarget, type FlashTransferTaskInfo, type FlashTransferUploadListener, type FlashTransferUploadOptions, type FlashTransferUploadResult, type ForceFetchClientKeyRetType, type Friend, type FriendApiOptions, type FriendCategory, type GeneralCallResult, type GetFileListParam, type GrayTipElement, type GrayTipRevokeElement, type Group, type GroupBulletin, type GroupCacheOptions, type GroupDetailInfo, type GroupEventChannel, type GroupFileItemInfo, type GroupFileListItem, type GroupFileSystemInfo, type GroupFolderInfo, type GroupHonorWebInfo, type GroupListener, type GroupMember, type GroupMemberListChange, type GroupNotify, type GroupRemainAtTimes, type GroupRequestKind, type GroupRequestRef, type GroupSpaceInfo, type HonorListItem, type IKernelLoginListener, type KernelErrorCode, type KernelLoginListener, type KernelRuntime, type KernelRuntimeOptions, type KickMemberInfo, type KickMemberV2Req, type ListenerEvents, type ListenerRecordEvent, type ListenerRecordingResult, type LogConfig, type LogEnvSource, type LogFileConfig, type LogFormat, type LogLevel, type LogModuleName, type LoggerOptions, type LoginAccountInfo, type LoginEventChannel, type LoginListItem, type LoginListener, type LoginProgress, type LoginResult, type LoginState, type MsgEventChannel, type MsgListener, type MsgReadReportItem, type MsgReceipt, type NapukettoCoreOptions, type NodeIDependsAdapter, type NodeIDispatcherAdapter, type NodeIGlobalAdapter, type NodeIKernelBuddyService, type NodeIKernelGroupService, type NodeIKernelLoginService, type NodeIKernelMsgService, type NodeIKernelProfileLikeService, type NodeIKernelProfileService, type NodeIKernelRecentContactService, type NodeIKernelRichMediaService, type NodeIKernelSessionListener, type NodeIKernelTicketService, type NodeIQQNTStartupSessionWrapper, type NodeIQQNTWrapperEngine, type NodeIQQNTWrapperSession, type NodeQQNTWrapperUtil, type NudgeParam, type PathOptions, type Peer, type PendingGroupRequest, type PicElement, type PinnedContact, type PlatformType, type PttElement, type QQVersionContext, type QQVersionInfo, type QqDataRootOptions, type QqVersionContext, type QqVersionInfo, type QrCodeData, type QuickLoginOptions, type RDeliveryConfig, type RawElement, type RawMessage, type RecentContact, type RecentContactEventChannel, type RecentContactFetchParam, type RecentContactListChanged, type RecentContactListener, type ReplyElement, type SelfInfo, type SendMessageElement, type SessionConfigOptions, type SessionListenerOptions, type ShutUpGroupMember, type StartNapukettoOptions, type StrangerInfo, type TextElement, type TimestampMode, type TipAioOpGrayTipElement, type TipGroupElement, type UserDetailInfoByUin, type VendorType, type VideoElement, type WrapperContext, type WrapperNodeApi, type WrapperSessionInitConfig, createSessionListener as createLifecycleSessionListener };
package/dist/index.mjs CHANGED
@@ -1295,6 +1295,7 @@ function clearTimer(timer) {
1295
1295
  * (getBuddyReq / approvalFriendRequest / setBuddyRemark / delBuddy /
1296
1296
  * getDoubtBuddyReq / approvalDoubtBuddyReq)。
1297
1297
  */
1298
+ const QQ_NUMBER = /^[1-9]\d*$/;
1298
1299
  /** 好友 API:从 session 拿 buddy service,包装成语义化方法。 */
1299
1300
  var FriendApi = class {
1300
1301
  service;
@@ -1305,34 +1306,30 @@ var FriendApi = class {
1305
1306
  }
1306
1307
  /** 好友列表(分类拍平为 Friend[];昵称/备注从 service 缓存读取)。 */
1307
1308
  async getFriendList() {
1308
- let categories;
1309
- try {
1310
- categories = await this.service.getBuddyListFromCache(0);
1311
- } catch {
1312
- const raw = await this.service.getBuddyListV2("cli", true, 0);
1313
- if (raw.result !== 0) throw kernelError(`getBuddyListV2 失败: ${raw.errMsg}`, "UNKNOWN");
1314
- categories = raw.data;
1315
- }
1316
- const uids = categories.flatMap((cat) => cat.buddyList?.map((b) => b.uid) ?? cat.buddyUids ?? []);
1317
- let uinMap = /* @__PURE__ */ new Map();
1318
- if (this.uidToUin !== void 0) uinMap = await this.uidToUin(uids);
1319
- const out = [];
1320
- for (const uid of uids) out.push({
1321
- uid,
1322
- uin: uinMap.get(uid) ?? uid,
1323
- nickname: this.service.getBuddyNick(uid),
1324
- remark: this.service.getBuddyRemark(uid)
1309
+ return this.friendsFromCategories(await this.getBuddyCategories());
1310
+ }
1311
+ async friendsFromCategories(categories) {
1312
+ const entries = categories.flatMap(buddyEntries);
1313
+ const unresolved = new Set(entries.filter((entry) => buddyUin(entry) === null).map(({ uid }) => uid));
1314
+ const uinMap = unresolved.size > 0 ? await this.uidToUin?.([...unresolved]) : void 0;
1315
+ return entries.map((entry) => {
1316
+ const { uid, coreInfo } = entry;
1317
+ return {
1318
+ uid,
1319
+ uin: buddyUin(entry) ?? validUin(uinMap?.get(uid)),
1320
+ nickname: coreInfo?.nick ?? this.service.getBuddyNick(uid),
1321
+ remark: coreInfo?.remark ?? this.service.getBuddyRemark(uid)
1322
+ };
1325
1323
  });
1326
- return out;
1327
1324
  }
1328
1325
  /** 带分类的好友列表(get_friends_with_category,分类保留)。 */
1329
1326
  async getFriendCategories() {
1330
1327
  const categories = await this.getBuddyCategories();
1331
1328
  const friendMap = /* @__PURE__ */ new Map();
1332
- for (const friend of await this.getFriendList()) friendMap.set(friend.uid, friend);
1329
+ for (const friend of await this.friendsFromCategories(categories)) friendMap.set(friend.uid, friend);
1333
1330
  return categories.map((cat) => {
1334
1331
  const buddies = [];
1335
- for (const uid of cat.buddyList?.map((b) => b.uid) ?? cat.buddyUids ?? []) {
1332
+ for (const { uid } of buddyEntries(cat)) {
1336
1333
  const friend = friendMap.get(uid);
1337
1334
  if (friend !== void 0) buddies.push(friend);
1338
1335
  }
@@ -1397,19 +1394,22 @@ var FriendApi = class {
1397
1394
  const list = raw.doubtList ?? [];
1398
1395
  let uinMap = /* @__PURE__ */ new Map();
1399
1396
  if (this.uidToUin !== void 0 && list.length > 0) uinMap = await this.uidToUin(list.map((item) => item.uid));
1400
- const out = [];
1401
- for (const item of list) out.push(this.toDoubtFriendRequestInfo(item, uinMap));
1402
- return out;
1403
- }
1404
- /** 单项转换:DoubtBuddyReq → OB11 结构(可选字段条件赋值,exactOptionalPropertyTypes)。 */
1405
- toDoubtFriendRequestInfo(item, uinMap) {
1406
- return toDoubtFriendRequestInfo(item, uinMap);
1397
+ return list.map((item) => toDoubtFriendRequestInfo(item, uinMap));
1407
1398
  }
1408
1399
  /** 处理可疑好友申请(set_doubt_friends_add_request;uid=flag)。 */
1409
1400
  handleDoubtFriendRequest(uid) {
1410
1401
  this.service.approvalDoubtBuddyReq(uid, "", "");
1411
1402
  }
1412
1403
  };
1404
+ function buddyEntries(category) {
1405
+ return category.buddyList ?? category.buddyUids?.map((uid) => ({ uid })) ?? [];
1406
+ }
1407
+ function buddyUin(entry) {
1408
+ return validUin(entry.uin) ?? validUin(entry.coreInfo?.uin);
1409
+ }
1410
+ function validUin(value) {
1411
+ return typeof value === "string" && QQ_NUMBER.test(value) ? value : null;
1412
+ }
1413
1413
  /** 可选字段条件赋值(undefined 跳过,兼容 exactOptionalPropertyTypes)。 */
1414
1414
  function assignOptional(info, key, value) {
1415
1415
  if (value !== void 0) info[key] = value;
@@ -1421,7 +1421,7 @@ function assignOptional(info, key, value) {
1421
1421
  * 经 JSON.stringify 变 null。这里只接受正安全整数(QQ 号),其余交给调用方省略字段。
1422
1422
  */
1423
1423
  function resolveDoubtUin(uid, uinMap) {
1424
- const value = Number(uinMap.get(uid) ?? uid);
1424
+ const value = Number(validUin(uinMap.get(uid)));
1425
1425
  return Number.isSafeInteger(value) && value > 0 ? value : void 0;
1426
1426
  }
1427
1427
  /** 单项转换:DoubtBuddyReq → OB11 结构(导出供单测,friend.test.ts)。 */
@@ -1602,10 +1602,10 @@ function textToCanonical(textEl) {
1602
1602
  type: "at",
1603
1603
  target: "all"
1604
1604
  };
1605
- if (atType === AtType.ONE || atType === AtType.ME) {
1605
+ if ((atType === AtType.ONE || atType === AtType.ME) && atUid != null && atUid.trim() !== "") {
1606
1606
  const base = {
1607
1607
  type: "at",
1608
- target: atUid ?? content
1608
+ target: atUid
1609
1609
  };
1610
1610
  const display = content.startsWith("@") ? content.slice(1) : content;
1611
1611
  if (display === "") return base;
@@ -1745,9 +1745,13 @@ function replyToCanonical(reply) {
1745
1745
  type: "reply",
1746
1746
  messageId: ""
1747
1747
  };
1748
+ const senderUid = emptyToUndefined(reply.senderUid);
1749
+ const senderUin = emptyToUndefined(reply.senderUin);
1748
1750
  return {
1749
1751
  type: "reply",
1750
- messageId: reply.replayMsgId ?? ""
1752
+ messageId: reply.replayMsgId ?? "",
1753
+ ...senderUid !== void 0 ? { senderUid } : {},
1754
+ ...senderUin !== void 0 ? { senderUin } : {}
1751
1755
  };
1752
1756
  }
1753
1757
  /**
@@ -2023,6 +2027,7 @@ var GroupApi = class {
2023
2027
  */
2024
2028
  async setMemberShutUp(groupCode, members) {
2025
2029
  if (members.length === 0) throw kernelError("setMemberShutUp 需要至少一个成员", "INVALID_PARAM");
2030
+ if (members.some(({ duration }) => !Number.isSafeInteger(duration) || duration < 0)) throw kernelError("禁言时长必须是非负整数秒,0 表示解除", "INVALID_PARAM");
2026
2031
  const raw = await this.service.setMemberShutUp(groupCode, members.map((m) => ({
2027
2032
  uid: m.uid,
2028
2033
  timeStamp: m.duration
@@ -2252,6 +2257,66 @@ function extractGroupDetail(result, raw) {
2252
2257
  return isGroupDetailInfo(candidate) ? candidate : null;
2253
2258
  }
2254
2259
  // src/apis/group-notify.ts
2260
+ /**
2261
+ * GroupNotifyApi:群通知/禁言列表语义化 API(ADR-009 统一错误语义,P2-13)
2262
+ *
2263
+ * get_group_system_msg / set_group_add_request / get_group_shut_list 共用。
2264
+ * getSingleScreenNotifies / getGroupShutUpMemberList 的列表可能走 listener 回调,
2265
+ * 直接调用返回形状待探测校准:兼容 result 数组 / 字段 / Map。
2266
+ *
2267
+ * 列表提取一律走元素级类型守卫(`isGroupNotify` / `isGroupMember`):
2268
+ * 原生返回数组里混入 null / 字符串 / 残缺对象时逐项丢弃,而不是整数组强转。
2269
+ */
2270
+ const requestTypes = {
2271
+ invitation: GroupNotifyMsgType.INVITED_BY_MEMBER,
2272
+ invited_join_request: GroupNotifyMsgType.INVITED_NEED_ADMINI_STRATOR_PASS,
2273
+ join_request: GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS
2274
+ };
2275
+ const GROUP_CODE = /^[1-9]\d*$/;
2276
+ /** 仅接受有完整审批标识的未处理群通知。 */
2277
+ function toPendingGroupRequest(notify, doubt) {
2278
+ const { status, type, seq, group, user1, user2, postscript } = notify;
2279
+ const groupCode = group?.groupCode;
2280
+ if (status !== GroupNotifyMsgStatus.KUNHANDLE || typeof seq !== "string" || seq.trim() === "" || typeof groupCode !== "string" || !GROUP_CODE.test(groupCode)) return;
2281
+ const kind = requestKinds.find((key) => requestTypes[key] === type);
2282
+ if (kind === void 0) return;
2283
+ return {
2284
+ request: {
2285
+ seq,
2286
+ groupCode,
2287
+ kind,
2288
+ doubt
2289
+ },
2290
+ ...typeof user1?.uid === "string" && user1.uid !== "" ? { initiatorUid: user1.uid } : {},
2291
+ ...typeof user2?.uid === "string" && user2.uid !== "" ? { targetUid: user2.uid } : {},
2292
+ ...typeof postscript === "string" ? { comment: postscript } : {}
2293
+ };
2294
+ }
2295
+ const requestKinds = [
2296
+ "invitation",
2297
+ "invited_join_request",
2298
+ "join_request"
2299
+ ];
2300
+ /** 兼容按序号审批的协议。指定队列时只读取该队列。 */
2301
+ async function findPendingGroupRequest(api, filter, count) {
2302
+ const queues = filter.doubt === void 0 ? [false, true] : [filter.doubt];
2303
+ const kinds = typeof filter.kind === "string" ? [filter.kind] : filter.kind;
2304
+ const matches = /* @__PURE__ */ new Map();
2305
+ for (const doubt of queues) {
2306
+ const notifies = await api.getSingleScreenNotifies(doubt, count);
2307
+ for (const notify of notifies.filter(({ seq }) => seq === filter.seq)) {
2308
+ const request = toPendingGroupRequest(notify, doubt)?.request;
2309
+ if (request !== void 0 && request.groupCode === (filter.groupCode ?? request.groupCode) && kinds?.includes(request.kind) !== false) matches.set(JSON.stringify(request), {
2310
+ request,
2311
+ notify
2312
+ });
2313
+ }
2314
+ }
2315
+ if (matches.size > 1) throw kernelError("群请求标识有多个匹配,请指定队列、群号和类型", "INVALID_PARAM");
2316
+ const match = matches.values().next().value;
2317
+ if (match === void 0) throw kernelError("未找到待处理群请求", "NOT_FOUND");
2318
+ return match;
2319
+ }
2255
2320
  /** 群通知 API:从 session 拿 group service,包装成语义化方法。 */
2256
2321
  var GroupNotifyApi = class {
2257
2322
  service;
@@ -2261,7 +2326,27 @@ var GroupNotifyApi = class {
2261
2326
  /** 单屏通知列表(get_group_system_msg / set_group_add_request 共用)。 */
2262
2327
  async getSingleScreenNotifies(doubt, count) {
2263
2328
  const raw = await this.service.getSingleScreenNotifies(doubt, "", count);
2264
- return extractNotifyList(isRecord(raw) ? raw["result"] : void 0);
2329
+ checkLooseResult("getSingleScreenNotifies", raw);
2330
+ const result = isRecord(raw) ? raw["result"] : void 0;
2331
+ return extractNotifyList(result !== null && typeof result === "object" ? result : raw);
2332
+ }
2333
+ /** 从实时通知提取可供 IPC 消费的请求。 */
2334
+ getPendingGroupRequests(doubt, notifies) {
2335
+ return extractNotifyList(notifies).flatMap((notify) => {
2336
+ const pending = toPendingGroupRequest(notify, doubt);
2337
+ return pending === void 0 ? [] : [pending];
2338
+ });
2339
+ }
2340
+ /** 处理同一登录会话发出的请求引用。QQ 负责权限与请求有效性判定。 */
2341
+ async respondToRequest(request, approve, reason = "") {
2342
+ const { seq, groupCode, kind, doubt } = request;
2343
+ if (!requestKinds.includes(kind) || seq.trim() === "" || !GROUP_CODE.test(groupCode)) throw kernelError("群请求引用无效", "INVALID_PARAM");
2344
+ await this.operateRequest(doubt, {
2345
+ seq,
2346
+ type: requestTypes[kind],
2347
+ groupCode,
2348
+ postscript: reason || " "
2349
+ }, approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE);
2265
2350
  }
2266
2351
  /** 禁言成员列表(get_group_shut_list)。 */
2267
2352
  async getGroupShutUpMemberList(groupCode) {
@@ -2277,15 +2362,18 @@ var GroupNotifyApi = class {
2277
2362
  if (group !== void 0) ({groupCode} = group);
2278
2363
  let postscript = reason;
2279
2364
  if (postscript === "") postscript = " ";
2280
- await this.service.operateSysNotify(doubt, {
2365
+ await this.operateRequest(doubt, {
2366
+ seq,
2367
+ type,
2368
+ groupCode,
2369
+ postscript
2370
+ }, operateType);
2371
+ }
2372
+ async operateRequest(doubt, targetMsg, operateType) {
2373
+ checkLooseResult("operateSysNotify", await this.service.operateSysNotify(doubt, {
2281
2374
  operateType,
2282
- targetMsg: {
2283
- seq,
2284
- type,
2285
- groupCode,
2286
- postscript
2287
- }
2288
- });
2375
+ targetMsg
2376
+ }));
2289
2377
  }
2290
2378
  };
2291
2379
  /** 群通知项形状判定(seq 字符串 + type 数字是 GroupNotify 的必备标识)。 */
@@ -7067,4 +7155,4 @@ function listQQVersions(installDir) {
7067
7155
  return statSync(full).isDirectory() && existsSync(join(full, "resources", "app", "wrapper.node"));
7068
7156
  }).sort().reverse();
7069
7157
  }
7070
- export { BuddyCache, CONFIG_FILE_MODE, ChatType, ConfigBase, ConfigError, DEFAULT_DATA_ROOT_NAME, DependsAdapter, DispatcherAdapter, EXIT_CONFIG_INVALID, ElementType, EssenceListSync, FlashTransferApi, FriendApi, FriendBridge, GlobalAdapter, GrayTipSubType, GroupApi, GroupBridge, GroupCache, GroupListUpdateType, GroupMemberDataSource, GroupNotifyApi, GroupNotifyMsgStatus, GroupNotifyMsgType, KERNEL_ERROR_CODES, KernelError, LoginBridge, MAIN_CONFIG_FILE, MsgApi, MsgBridge, NTEventChannel, NTGroupMemberRole, NTGroupRequestOperateTypes, NapukettoCore, PathWrapper, ProfileApi, ProfileLikeApi, QrLoginSession, RecentContactApi, RecentContactBridge, RichMediaApi, TicketApi, TipGroupElementType, VIDEO_THUMB_KEY, WebApi, WebHonorType, activateO3MiscService, buildEngineConfig, buildLoginConfig, buildSessionConfig, configError, createConsoleFormatStream, createCoreContext, createKernelRuntime, createSessionListener as createLifecycleSessionListener, createSessionListener, createLogger, createLoginListener, createRecordingListener, createSession, createWrapper, diffEssenceList, dlopenWrapper, electronProcessType, errorMessage, getErrorCode, getErrorMessage, getExistingSession, getMainSession, getOwnProp, hasBooleanProp, hasCallableProp, hasFunctionProp, hasMethodSurface, hasNumberProp, hasStaticCreator, hasStaticGetter, hasStringProp, initAndStartSession, initEngine, initSession, isCallable, isKernelError, isPromiseLike, isRecord, kernelError, listLoginAccounts, listQQVersions, narrowBuddyCategories, narrowEssenceGroupArg, parseAppidFromMajor, parseJsonWithGuard, parseLogConfig, parseToml, probeRuntime, quickLogin, readMachineGuid, requireKernelService, resolveAppidQua, resolveConfigPath, resolveDataRoot, resolveQQVersion, resolveQqGlobalPath, resolveQqUserDataRoot, resolveSandboxWritePath, resolveWrapperPath, sleep, startListenerRecording, startNapuketto, startSession, stringifyToml, toCanonicalElements, toSendElements, waitFor, waitForNetworkConnection, waitSessionReady };
7158
+ export { BuddyCache, CONFIG_FILE_MODE, ChatType, ConfigBase, ConfigError, DEFAULT_DATA_ROOT_NAME, DependsAdapter, DispatcherAdapter, EXIT_CONFIG_INVALID, ElementType, EssenceListSync, FlashTransferApi, FriendApi, FriendBridge, GlobalAdapter, GrayTipSubType, GroupApi, GroupBridge, GroupCache, GroupListUpdateType, GroupMemberDataSource, GroupNotifyApi, GroupNotifyMsgStatus, GroupNotifyMsgType, KERNEL_ERROR_CODES, KernelError, LoginBridge, MAIN_CONFIG_FILE, MsgApi, MsgBridge, NTEventChannel, NTGroupMemberRole, NTGroupRequestOperateTypes, NapukettoCore, PathWrapper, ProfileApi, ProfileLikeApi, QrLoginSession, RecentContactApi, RecentContactBridge, RichMediaApi, TicketApi, TipGroupElementType, VIDEO_THUMB_KEY, WebApi, WebHonorType, activateO3MiscService, buildEngineConfig, buildLoginConfig, buildSessionConfig, configError, createConsoleFormatStream, createCoreContext, createKernelRuntime, createSessionListener as createLifecycleSessionListener, createSessionListener, createLogger, createLoginListener, createRecordingListener, createSession, createWrapper, diffEssenceList, dlopenWrapper, electronProcessType, errorMessage, findPendingGroupRequest, getErrorCode, getErrorMessage, getExistingSession, getMainSession, getOwnProp, hasBooleanProp, hasCallableProp, hasFunctionProp, hasMethodSurface, hasNumberProp, hasStaticCreator, hasStaticGetter, hasStringProp, initAndStartSession, initEngine, initSession, isCallable, isKernelError, isPromiseLike, isRecord, kernelError, listLoginAccounts, listQQVersions, narrowBuddyCategories, narrowEssenceGroupArg, parseAppidFromMajor, parseJsonWithGuard, parseLogConfig, parseToml, probeRuntime, quickLogin, readMachineGuid, requireKernelService, resolveAppidQua, resolveConfigPath, resolveDataRoot, resolveQQVersion, resolveQqGlobalPath, resolveQqUserDataRoot, resolveSandboxWritePath, resolveWrapperPath, sleep, startListenerRecording, startNapuketto, startSession, stringifyToml, toCanonicalElements, toPendingGroupRequest, toSendElements, waitFor, waitForNetworkConnection, waitSessionReady };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@napuketto/kernel",
4
- "version": "0.17.0",
4
+ "version": "0.18.0",
5
5
  "type": "module",
6
6
  "description": "Core runtime kernel of NapukettoQQ",
7
7
  "keywords": [