@lih-x-x/kmr 1.0.14 → 1.0.15

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.
Files changed (2) hide show
  1. package/dist/index.js +68 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1030,6 +1030,65 @@ var TaskCreator = class {
1030
1030
  }
1031
1031
  };
1032
1032
 
1033
+ // src/lark/userResolver.ts
1034
+ var UserResolver = class {
1035
+ constructor(client) {
1036
+ this.client = client;
1037
+ }
1038
+ client;
1039
+ // name -> openId 映射(支持多个群的成员合并)
1040
+ nameMap = /* @__PURE__ */ new Map();
1041
+ loadedChats = /* @__PURE__ */ new Set();
1042
+ /**
1043
+ * 根据姓名解析 open_id
1044
+ * 如果缓存中没有,返回 undefined
1045
+ */
1046
+ resolve(name) {
1047
+ if (this.nameMap.has(name)) return this.nameMap.get(name);
1048
+ for (const [key, value] of this.nameMap) {
1049
+ if (key.includes(name) || name.includes(key)) return value;
1050
+ }
1051
+ return void 0;
1052
+ }
1053
+ /**
1054
+ * 加载某个群的成员列表到缓存
1055
+ */
1056
+ async loadChatMembers(chatId) {
1057
+ if (this.loadedChats.has(chatId)) return;
1058
+ console.log(`[user-resolver] \u52A0\u8F7D\u7FA4\u6210\u5458: chatId=${chatId}`);
1059
+ try {
1060
+ let pageToken;
1061
+ do {
1062
+ const response = await this.client.im.chatMembers.get({
1063
+ path: { chat_id: chatId },
1064
+ params: {
1065
+ member_id_type: "open_id",
1066
+ page_size: 100,
1067
+ ...pageToken ? { page_token: pageToken } : {}
1068
+ }
1069
+ });
1070
+ const items = response.data?.items || [];
1071
+ for (const item of items) {
1072
+ if (item.name && item.member_id) {
1073
+ this.nameMap.set(item.name, item.member_id);
1074
+ }
1075
+ }
1076
+ pageToken = response.data?.has_more ? response.data?.page_token : void 0;
1077
+ } while (pageToken);
1078
+ this.loadedChats.add(chatId);
1079
+ console.log(`[user-resolver] \u7FA4\u6210\u5458\u52A0\u8F7D\u5B8C\u6210, \u5F53\u524D\u6620\u5C04\u6570: ${this.nameMap.size}`);
1080
+ } catch (err) {
1081
+ console.error(`[user-resolver] \u52A0\u8F7D\u7FA4\u6210\u5458\u5931\u8D25:`, err.message);
1082
+ }
1083
+ }
1084
+ /**
1085
+ * 获取当前所有已缓存的映射
1086
+ */
1087
+ getAll() {
1088
+ return new Map(this.nameMap);
1089
+ }
1090
+ };
1091
+
1033
1092
  // src/index.ts
1034
1093
  async function main() {
1035
1094
  const config = loadConfig();
@@ -1041,8 +1100,9 @@ async function main() {
1041
1100
  const queryHandler = new QueryHandler(agent, config.storage.dataDir);
1042
1101
  const sessionManager = new SessionManager(KMR_DIR, config.agent.timeout);
1043
1102
  const taskCreator = new TaskCreator(client);
1103
+ const userResolver = new UserResolver(client);
1044
1104
  const pendingConfirmations = /* @__PURE__ */ new Map();
1045
- const dispatcher = createEventDispatcher(async (messageId, text, _chatId, senderId, meta) => {
1105
+ const dispatcher = createEventDispatcher(async (messageId, text, chatId, senderId, meta) => {
1046
1106
  const parsed = parseMessage(text);
1047
1107
  console.log(`[route] \u6D88\u606F\u8DEF\u7531: type=${parsed.type}, messageId=${messageId}, isGroup=${meta.isGroup}, isMentioned=${meta.isMentioned}`);
1048
1108
  if (meta.isGroup && !meta.isMentioned && parsed.type === "document_link" /* DOCUMENT_LINK */) {
@@ -1073,6 +1133,7 @@ async function main() {
1073
1133
  await messenger.replyMeetingSummary(messageId, record);
1074
1134
  console.log(`[reply] \u5DF2\u53D1\u9001\u4F1A\u8BAE\u6458\u8981\u56DE\u590D`);
1075
1135
  if (record.todos.length > 0) {
1136
+ await userResolver.loadChatMembers(chatId);
1076
1137
  const oldPending = pendingConfirmations.get(senderId);
1077
1138
  if (oldPending) clearTimeout(oldPending.timer);
1078
1139
  const timer = setTimeout(() => {
@@ -1086,6 +1147,7 @@ async function main() {
1086
1147
  meetingId: record.id,
1087
1148
  todos: record.todos,
1088
1149
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1150
+ chatId,
1089
1151
  timer
1090
1152
  });
1091
1153
  await messenger.replyTodoConfirmation(messageId, record.todos);
@@ -1149,12 +1211,16 @@ async function main() {
1149
1211
  const results = [];
1150
1212
  for (const todo of selectedTodos) {
1151
1213
  try {
1214
+ const ownerOpenId = userResolver.resolve(todo.owner) || senderId;
1215
+ if (ownerOpenId !== senderId) {
1216
+ console.log(`[task] \u8D1F\u8D23\u4EBA "${todo.owner}" -> ${ownerOpenId}`);
1217
+ }
1152
1218
  const result = await taskCreator.createTask({
1153
1219
  summary: `${todo.content}\uFF08${todo.owner}\uFF09`,
1154
1220
  due: todo.deadline,
1155
1221
  description: `\u6765\u6E90\u4F1A\u8BAE: ${pending.meetingId}
1156
1222
  \u8D1F\u8D23\u4EBA: ${todo.owner}`,
1157
- assigneeOpenId: senderId
1223
+ assigneeOpenId: ownerOpenId
1158
1224
  });
1159
1225
  results.push({ summary: todo.content, success: true, taskId: result.taskId, url: result.url });
1160
1226
  console.log(`\u2705 \u4EFB\u52A1\u521B\u5EFA\u6210\u529F: ${todo.content}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lih-x-x/kmr",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {