nikou-cli 0.1.3 → 0.1.4
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.js +365 -411
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1173,6 +1173,24 @@ function safeJsonStringify(payload) {
|
|
|
1173
1173
|
return `{"error":"JSON.stringify failed","reason":"${msg}"}`;
|
|
1174
1174
|
}
|
|
1175
1175
|
}
|
|
1176
|
+
function countReplacementChars(text) {
|
|
1177
|
+
return (text.match(/\uFFFD/g) || []).length;
|
|
1178
|
+
}
|
|
1179
|
+
function decodeProcessOutputChunk(chunk) {
|
|
1180
|
+
if (typeof chunk === "string") {
|
|
1181
|
+
return chunk;
|
|
1182
|
+
}
|
|
1183
|
+
const utf8 = chunk.toString("utf8");
|
|
1184
|
+
if (process2.platform !== "win32" || !utf8.includes("\uFFFD")) {
|
|
1185
|
+
return utf8;
|
|
1186
|
+
}
|
|
1187
|
+
try {
|
|
1188
|
+
const decoded = new TextDecoder("gb18030").decode(chunk);
|
|
1189
|
+
return countReplacementChars(decoded) < countReplacementChars(utf8) ? decoded : utf8;
|
|
1190
|
+
} catch {
|
|
1191
|
+
return utf8;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1176
1194
|
function toSingleLineLog(text, maxLength = 600) {
|
|
1177
1195
|
const normalized = String(text || "").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
1178
1196
|
if (normalized.length <= maxLength) return normalized;
|
|
@@ -6309,6 +6327,14 @@ var CodexRunner = class {
|
|
|
6309
6327
|
resolveCodexExecution(args, env = process7.env) {
|
|
6310
6328
|
return resolveCliExecution("codex", args, env);
|
|
6311
6329
|
}
|
|
6330
|
+
buildFailureMessage(stderr, stdout, code, dirPath, displayCommand) {
|
|
6331
|
+
const reason = stderr.trim() || stdout.trim() || `codex \u9000\u51FA\u7801 ${code}`;
|
|
6332
|
+
return [
|
|
6333
|
+
reason,
|
|
6334
|
+
`cwd=${dirPath || "-"}`,
|
|
6335
|
+
`command=${displayCommand || "codex"}`
|
|
6336
|
+
].join("\n");
|
|
6337
|
+
}
|
|
6312
6338
|
writePromptToChildStdin(child, prompt, traceMessage = "") {
|
|
6313
6339
|
if (!this.shouldUseStdinPrompt(prompt) || !child?.stdin) {
|
|
6314
6340
|
return;
|
|
@@ -6425,15 +6451,17 @@ var CodexRunner = class {
|
|
|
6425
6451
|
const timer = this.createTimeout(child, resolveTraceId(threadKey, resolvedSessionId, dirPath), reject, "Codex \u6267\u884C\u8D85\u65F6", CODEX_EXEC_TIMEOUT_MS);
|
|
6426
6452
|
child.stdout?.on("data", (chunk) => {
|
|
6427
6453
|
clearTimeout(startupTimer);
|
|
6428
|
-
stdout +=
|
|
6454
|
+
stdout += decodeProcessOutputChunk(chunk);
|
|
6429
6455
|
});
|
|
6430
6456
|
child.stderr?.on("data", (chunk) => {
|
|
6431
|
-
stderr +=
|
|
6457
|
+
stderr += decodeProcessOutputChunk(chunk);
|
|
6432
6458
|
});
|
|
6433
6459
|
child.on("error", (error) => {
|
|
6434
6460
|
clearTimeout(startupTimer);
|
|
6435
6461
|
clearTimeout(timer);
|
|
6436
|
-
reject(error
|
|
6462
|
+
reject(new Error(`${error.message}
|
|
6463
|
+
cwd=${dirPath || "-"}
|
|
6464
|
+
command=${execConfig.displayCommand}`));
|
|
6437
6465
|
});
|
|
6438
6466
|
child.on("close", (code) => {
|
|
6439
6467
|
clearTimeout(startupTimer);
|
|
@@ -6451,8 +6479,7 @@ var CodexRunner = class {
|
|
|
6451
6479
|
this.stateManager.markCodexRun(dirPath);
|
|
6452
6480
|
}
|
|
6453
6481
|
if (code !== 0) {
|
|
6454
|
-
|
|
6455
|
-
reject(new Error(err));
|
|
6482
|
+
reject(new Error(this.buildFailureMessage(stderr, stdout, code, dirPath, execConfig.displayCommand)));
|
|
6456
6483
|
return;
|
|
6457
6484
|
}
|
|
6458
6485
|
resolve3({
|
|
@@ -6558,13 +6585,13 @@ var CodexRunner = class {
|
|
|
6558
6585
|
};
|
|
6559
6586
|
child.stdout?.on("data", (chunk) => {
|
|
6560
6587
|
clearTimeout(startupTimer);
|
|
6561
|
-
const text =
|
|
6588
|
+
const text = decodeProcessOutputChunk(chunk);
|
|
6562
6589
|
stdout += text;
|
|
6563
6590
|
pending += text;
|
|
6564
6591
|
consumeLines();
|
|
6565
6592
|
});
|
|
6566
6593
|
child.stderr?.on("data", (chunk) => {
|
|
6567
|
-
const text =
|
|
6594
|
+
const text = decodeProcessOutputChunk(chunk);
|
|
6568
6595
|
stderr += text;
|
|
6569
6596
|
text.split(/\r?\n/).forEach((line) => {
|
|
6570
6597
|
if (line.trim() && !shouldIgnoreStderrLine(line)) {
|
|
@@ -6578,7 +6605,9 @@ var CodexRunner = class {
|
|
|
6578
6605
|
if (taskKey) {
|
|
6579
6606
|
this.activeChildrenByTaskId.delete(taskKey);
|
|
6580
6607
|
}
|
|
6581
|
-
reject(error
|
|
6608
|
+
reject(new Error(`${error.message}
|
|
6609
|
+
cwd=${dirPath || "-"}
|
|
6610
|
+
command=${execConfig.displayCommand}`));
|
|
6582
6611
|
});
|
|
6583
6612
|
child.on("close", (code) => {
|
|
6584
6613
|
clearTimeout(startupTimer);
|
|
@@ -6631,8 +6660,7 @@ var CodexRunner = class {
|
|
|
6631
6660
|
this.stateManager.markCodexRun(dirPath);
|
|
6632
6661
|
}
|
|
6633
6662
|
if (code !== 0) {
|
|
6634
|
-
|
|
6635
|
-
reject(new Error(err));
|
|
6663
|
+
reject(new Error(this.buildFailureMessage(stderr, stdout, code, dirPath, execConfig.displayCommand)));
|
|
6636
6664
|
return;
|
|
6637
6665
|
}
|
|
6638
6666
|
resolve3({
|
|
@@ -6649,10 +6677,10 @@ var CodexRunner = class {
|
|
|
6649
6677
|
import fs12 from "fs";
|
|
6650
6678
|
import os5 from "os";
|
|
6651
6679
|
import path11 from "path";
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
function
|
|
6655
|
-
if (value
|
|
6680
|
+
|
|
6681
|
+
// src/hook/display-name.ts
|
|
6682
|
+
function normalizeText(value) {
|
|
6683
|
+
if (value === null || value === void 0) {
|
|
6656
6684
|
return "";
|
|
6657
6685
|
}
|
|
6658
6686
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
@@ -6660,24 +6688,15 @@ function normalize6(value) {
|
|
|
6660
6688
|
}
|
|
6661
6689
|
return "";
|
|
6662
6690
|
}
|
|
6663
|
-
function lower(value) {
|
|
6664
|
-
return normalize6(value).toLowerCase();
|
|
6665
|
-
}
|
|
6666
|
-
function extractUserFromEmail(email) {
|
|
6667
|
-
const normalizedEmail = lower(email);
|
|
6668
|
-
if (!normalizedEmail.includes("@")) {
|
|
6669
|
-
return "";
|
|
6670
|
-
}
|
|
6671
|
-
return normalizedEmail.split("@")[0] || "";
|
|
6672
|
-
}
|
|
6673
6691
|
function resolveDisplayName(value) {
|
|
6674
|
-
const direct =
|
|
6692
|
+
const direct = normalizeText(value);
|
|
6675
6693
|
if (direct) {
|
|
6676
6694
|
return direct;
|
|
6677
6695
|
}
|
|
6678
6696
|
if (!value || typeof value !== "object") {
|
|
6679
6697
|
return "";
|
|
6680
6698
|
}
|
|
6699
|
+
const record = value;
|
|
6681
6700
|
const candidateKeys = [
|
|
6682
6701
|
"zh_cn",
|
|
6683
6702
|
"zh-CN",
|
|
@@ -6689,15 +6708,30 @@ function resolveDisplayName(value) {
|
|
|
6689
6708
|
"name",
|
|
6690
6709
|
"display_name",
|
|
6691
6710
|
"full_name",
|
|
6692
|
-
"value"
|
|
6711
|
+
"value",
|
|
6712
|
+
"default_value"
|
|
6693
6713
|
];
|
|
6694
6714
|
for (const key of candidateKeys) {
|
|
6695
|
-
const text =
|
|
6715
|
+
const text = normalizeText(record[key]);
|
|
6696
6716
|
if (text) {
|
|
6697
6717
|
return text;
|
|
6698
6718
|
}
|
|
6699
6719
|
}
|
|
6700
|
-
return
|
|
6720
|
+
return resolveDisplayName(record.i18n_value) || resolveDisplayName(record.i18nValue) || resolveDisplayName(record.text);
|
|
6721
|
+
}
|
|
6722
|
+
|
|
6723
|
+
// src/hook/context/identity-resolver.ts
|
|
6724
|
+
var VOPS_USER_CACHE_PATH2 = path11.join(os5.homedir(), "ops", "vops_user.json");
|
|
6725
|
+
var CHAT_CACHE_TYPE = "__chat_cache__";
|
|
6726
|
+
function lower(value) {
|
|
6727
|
+
return normalizeText(value).toLowerCase();
|
|
6728
|
+
}
|
|
6729
|
+
function extractUserFromEmail(email) {
|
|
6730
|
+
const normalizedEmail = lower(email);
|
|
6731
|
+
if (!normalizedEmail.includes("@")) {
|
|
6732
|
+
return "";
|
|
6733
|
+
}
|
|
6734
|
+
return normalizedEmail.split("@")[0] || "";
|
|
6701
6735
|
}
|
|
6702
6736
|
function pickUserData(response) {
|
|
6703
6737
|
const data = response?.data || {};
|
|
@@ -6721,7 +6755,7 @@ function hasUserProfileData(entry) {
|
|
|
6721
6755
|
if (!entry || typeof entry !== "object") {
|
|
6722
6756
|
return false;
|
|
6723
6757
|
}
|
|
6724
|
-
return Boolean(
|
|
6758
|
+
return Boolean(normalizeText(entry.name) || normalizeText(entry.user) || normalizeText(entry.email));
|
|
6725
6759
|
}
|
|
6726
6760
|
var IdentityResolver = class {
|
|
6727
6761
|
logger;
|
|
@@ -6735,36 +6769,36 @@ var IdentityResolver = class {
|
|
|
6735
6769
|
this.cachePath = VOPS_USER_CACHE_PATH2;
|
|
6736
6770
|
}
|
|
6737
6771
|
setTraceId(traceId = "") {
|
|
6738
|
-
this.currentTraceId =
|
|
6772
|
+
this.currentTraceId = normalizeText(traceId) || "-";
|
|
6739
6773
|
}
|
|
6740
6774
|
trace(message) {
|
|
6741
6775
|
return formatTraceLog(this.currentTraceId, message);
|
|
6742
6776
|
}
|
|
6743
6777
|
scoreUserRecord(record) {
|
|
6744
6778
|
let score = 0;
|
|
6745
|
-
if (
|
|
6746
|
-
if (
|
|
6747
|
-
if (
|
|
6748
|
-
if (
|
|
6749
|
-
if (
|
|
6750
|
-
if (
|
|
6779
|
+
if (normalizeText(record?.user || "")) score += 100;
|
|
6780
|
+
if (normalizeText(record?.email || "")) score += 40;
|
|
6781
|
+
if (normalizeText(record?.feishuUserId || "")) score += 30;
|
|
6782
|
+
if (normalizeText(record?.feishuOpenId || "")) score += 20;
|
|
6783
|
+
if (normalizeText(record?.name || "")) score += 10;
|
|
6784
|
+
if (normalizeText(record?.uId || "")) score += 5;
|
|
6751
6785
|
return score;
|
|
6752
6786
|
}
|
|
6753
6787
|
mergeUserRecord(base, extra) {
|
|
6754
6788
|
const merged = { ...base };
|
|
6755
6789
|
const fields = ["uId", "name", "feishuUserId", "feishuOpenId", "feishuProjectUser", "user", "email"];
|
|
6756
6790
|
for (const field of fields) {
|
|
6757
|
-
const baseValue =
|
|
6758
|
-
const extraValue =
|
|
6791
|
+
const baseValue = normalizeText(merged[field]);
|
|
6792
|
+
const extraValue = normalizeText(extra?.[field]);
|
|
6759
6793
|
if (!baseValue && extraValue) {
|
|
6760
6794
|
merged[field] = extraValue;
|
|
6761
6795
|
}
|
|
6762
6796
|
}
|
|
6763
|
-
const baseUpdated =
|
|
6764
|
-
const extraUpdated =
|
|
6797
|
+
const baseUpdated = normalizeText(base?.updatedAt);
|
|
6798
|
+
const extraUpdated = normalizeText(extra?.updatedAt);
|
|
6765
6799
|
merged.updatedAt = baseUpdated && extraUpdated ? baseUpdated >= extraUpdated ? baseUpdated : extraUpdated : baseUpdated || extraUpdated || (/* @__PURE__ */ new Date()).toISOString();
|
|
6766
6800
|
const emailUser = extractUserFromEmail(merged.email);
|
|
6767
|
-
if (!
|
|
6801
|
+
if (!normalizeText(merged.user) && emailUser) {
|
|
6768
6802
|
merged.user = emailUser;
|
|
6769
6803
|
}
|
|
6770
6804
|
return merged;
|
|
@@ -6782,8 +6816,8 @@ var IdentityResolver = class {
|
|
|
6782
6816
|
chatEntries.push(row);
|
|
6783
6817
|
continue;
|
|
6784
6818
|
}
|
|
6785
|
-
const normalizedEmail =
|
|
6786
|
-
const normalizedUser =
|
|
6819
|
+
const normalizedEmail = normalizeText(row.email);
|
|
6820
|
+
const normalizedUser = normalizeText(row.user) || extractUserFromEmail(normalizedEmail);
|
|
6787
6821
|
row.email = normalizedEmail;
|
|
6788
6822
|
row.user = lower(normalizedUser);
|
|
6789
6823
|
userEntries.push(row);
|
|
@@ -6808,28 +6842,28 @@ var IdentityResolver = class {
|
|
|
6808
6842
|
const userRecords = Array.from(byUser.values());
|
|
6809
6843
|
const userNameCount = /* @__PURE__ */ new Map();
|
|
6810
6844
|
userRecords.forEach((item) => {
|
|
6811
|
-
const nameKey =
|
|
6845
|
+
const nameKey = normalizeText(item.name);
|
|
6812
6846
|
if (nameKey) {
|
|
6813
6847
|
userNameCount.set(nameKey, (userNameCount.get(nameKey) || 0) + 1);
|
|
6814
6848
|
}
|
|
6815
6849
|
});
|
|
6816
6850
|
const uniqueNameToUser = /* @__PURE__ */ new Map();
|
|
6817
6851
|
userRecords.forEach((item) => {
|
|
6818
|
-
const nameKey =
|
|
6852
|
+
const nameKey = normalizeText(item.name);
|
|
6819
6853
|
if (nameKey && userNameCount.get(nameKey) === 1) {
|
|
6820
6854
|
uniqueNameToUser.set(nameKey, item);
|
|
6821
6855
|
}
|
|
6822
6856
|
});
|
|
6823
6857
|
const byNoUserKey = /* @__PURE__ */ new Map();
|
|
6824
6858
|
for (const record of noUser) {
|
|
6825
|
-
const nameKey =
|
|
6859
|
+
const nameKey = normalizeText(record.name);
|
|
6826
6860
|
const uniqueNameTarget = uniqueNameToUser.get(nameKey);
|
|
6827
6861
|
if (uniqueNameTarget) {
|
|
6828
6862
|
const merged = this.mergeUserRecord(uniqueNameTarget, record);
|
|
6829
6863
|
byUser.set(lower(merged.user || uniqueNameTarget.user || ""), merged);
|
|
6830
6864
|
continue;
|
|
6831
6865
|
}
|
|
6832
|
-
const idKey =
|
|
6866
|
+
const idKey = normalizeText(record.feishuUserId) || normalizeText(record.feishuOpenId) || normalizeText(record.uId) || `${nameKey}#${normalizeText(record.updatedAt)}`;
|
|
6833
6867
|
const existed = byNoUserKey.get(idKey);
|
|
6834
6868
|
if (!existed) {
|
|
6835
6869
|
byNoUserKey.set(idKey, record);
|
|
@@ -6874,25 +6908,25 @@ var IdentityResolver = class {
|
|
|
6874
6908
|
}
|
|
6875
6909
|
}
|
|
6876
6910
|
findUserEntries(cache, { userId, openId }) {
|
|
6877
|
-
const uid =
|
|
6878
|
-
const oid =
|
|
6911
|
+
const uid = normalizeText(userId);
|
|
6912
|
+
const oid = normalizeText(openId);
|
|
6879
6913
|
return (cache || []).filter((item) => {
|
|
6880
6914
|
if (!item || typeof item !== "object" || item.__cacheType === CHAT_CACHE_TYPE) {
|
|
6881
6915
|
return false;
|
|
6882
6916
|
}
|
|
6883
|
-
return uid &&
|
|
6917
|
+
return uid && normalizeText(item.feishuUserId) === uid || oid && normalizeText(item.feishuOpenId) === oid;
|
|
6884
6918
|
});
|
|
6885
6919
|
}
|
|
6886
6920
|
findChatCache(cache, chatId) {
|
|
6887
|
-
const cid =
|
|
6921
|
+
const cid = normalizeText(chatId);
|
|
6888
6922
|
if (!cid) {
|
|
6889
6923
|
return null;
|
|
6890
6924
|
}
|
|
6891
|
-
return cache.find((item) => item.__cacheType === CHAT_CACHE_TYPE &&
|
|
6925
|
+
return cache.find((item) => item.__cacheType === CHAT_CACHE_TYPE && normalizeText(item.chatId) === cid) || null;
|
|
6892
6926
|
}
|
|
6893
6927
|
patchRequesterOpenId(cache, { userId = "", openId = "" } = {}) {
|
|
6894
|
-
const uid =
|
|
6895
|
-
const oid =
|
|
6928
|
+
const uid = normalizeText(userId);
|
|
6929
|
+
const oid = normalizeText(openId);
|
|
6896
6930
|
if (!uid || !oid) {
|
|
6897
6931
|
return false;
|
|
6898
6932
|
}
|
|
@@ -6901,7 +6935,7 @@ var IdentityResolver = class {
|
|
|
6901
6935
|
if (!item || typeof item !== "object" || item.__cacheType === CHAT_CACHE_TYPE) {
|
|
6902
6936
|
return;
|
|
6903
6937
|
}
|
|
6904
|
-
if (
|
|
6938
|
+
if (normalizeText(item.feishuUserId) === uid && !normalizeText(item.feishuOpenId)) {
|
|
6905
6939
|
item.feishuOpenId = oid;
|
|
6906
6940
|
item.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6907
6941
|
changed = true;
|
|
@@ -6910,8 +6944,8 @@ var IdentityResolver = class {
|
|
|
6910
6944
|
return changed;
|
|
6911
6945
|
}
|
|
6912
6946
|
async fetchUserFromLark(userId, openId) {
|
|
6913
|
-
const targetUserId =
|
|
6914
|
-
const targetOpenId =
|
|
6947
|
+
const targetUserId = normalizeText(userId);
|
|
6948
|
+
const targetOpenId = normalizeText(openId);
|
|
6915
6949
|
const userApi = this.larkClient?.contact?.v3?.user?.get;
|
|
6916
6950
|
if (typeof userApi !== "function") {
|
|
6917
6951
|
return null;
|
|
@@ -6940,7 +6974,7 @@ var IdentityResolver = class {
|
|
|
6940
6974
|
return null;
|
|
6941
6975
|
}
|
|
6942
6976
|
async fetchEmployeeFromDirectory(openId) {
|
|
6943
|
-
const oid =
|
|
6977
|
+
const oid = normalizeText(openId);
|
|
6944
6978
|
const request = this.larkClient?.request;
|
|
6945
6979
|
if (!oid || typeof request !== "function") {
|
|
6946
6980
|
return null;
|
|
@@ -6966,10 +7000,10 @@ var IdentityResolver = class {
|
|
|
6966
7000
|
if (!larkUser || typeof larkUser !== "object") {
|
|
6967
7001
|
return;
|
|
6968
7002
|
}
|
|
6969
|
-
const userId =
|
|
6970
|
-
const openId =
|
|
7003
|
+
const userId = normalizeText(larkUser.user_id || larkUser.userId || fallbackUserId);
|
|
7004
|
+
const openId = normalizeText(larkUser.open_id || larkUser.openId || fallbackOpenId);
|
|
6971
7005
|
const name = resolveDisplayName(larkUser.name) || resolveDisplayName(larkUser.display_name) || resolveDisplayName(larkUser.en_name) || resolveDisplayName(larkUser.full_name);
|
|
6972
|
-
const email =
|
|
7006
|
+
const email = normalizeText(larkUser.email);
|
|
6973
7007
|
const emailUser = extractUserFromEmail(email);
|
|
6974
7008
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
6975
7009
|
if (!userId && !openId && !name) {
|
|
@@ -6983,7 +7017,7 @@ var IdentityResolver = class {
|
|
|
6983
7017
|
existing = cache.find((item) => item.__cacheType !== CHAT_CACHE_TYPE && (lower(item.user) === lower(emailUser) || lower(item.email) === lower(email))) || null;
|
|
6984
7018
|
}
|
|
6985
7019
|
if (!existing && name) {
|
|
6986
|
-
existing = cache.find((item) => item.__cacheType !== CHAT_CACHE_TYPE &&
|
|
7020
|
+
existing = cache.find((item) => item.__cacheType !== CHAT_CACHE_TYPE && normalizeText(item.name) === name && normalizeText(item.user)) || null;
|
|
6987
7021
|
}
|
|
6988
7022
|
if (existing) {
|
|
6989
7023
|
existing.name = name || existing.name || "";
|
|
@@ -7010,7 +7044,7 @@ var IdentityResolver = class {
|
|
|
7010
7044
|
});
|
|
7011
7045
|
}
|
|
7012
7046
|
async fetchChatNameFromLark(chatId) {
|
|
7013
|
-
const cid =
|
|
7047
|
+
const cid = normalizeText(chatId);
|
|
7014
7048
|
const chatApi = this.larkClient?.im?.v1?.chat?.get;
|
|
7015
7049
|
if (!cid || typeof chatApi !== "function") {
|
|
7016
7050
|
return "";
|
|
@@ -7033,7 +7067,7 @@ var IdentityResolver = class {
|
|
|
7033
7067
|
return "";
|
|
7034
7068
|
}
|
|
7035
7069
|
async fetchChatMembersFromLark(chatId) {
|
|
7036
|
-
const cid =
|
|
7070
|
+
const cid = normalizeText(chatId);
|
|
7037
7071
|
const api = this.larkClient?.im?.v1?.chatMembers?.get;
|
|
7038
7072
|
if (!cid || typeof api !== "function") {
|
|
7039
7073
|
return [];
|
|
@@ -7058,8 +7092,8 @@ var IdentityResolver = class {
|
|
|
7058
7092
|
}
|
|
7059
7093
|
let changed = false;
|
|
7060
7094
|
for (const member of members) {
|
|
7061
|
-
const userId =
|
|
7062
|
-
const openId =
|
|
7095
|
+
const userId = normalizeText(member.member_id || member.user_id || member.userId);
|
|
7096
|
+
const openId = normalizeText(member.open_id || member.openId);
|
|
7063
7097
|
const name = resolveDisplayName(member.name) || resolveDisplayName(member.display_name) || resolveDisplayName(member.en_name);
|
|
7064
7098
|
if (!userId && !openId && !name) {
|
|
7065
7099
|
continue;
|
|
@@ -7074,8 +7108,8 @@ var IdentityResolver = class {
|
|
|
7074
7108
|
return changed;
|
|
7075
7109
|
}
|
|
7076
7110
|
upsertChatCache(cache, chatId, chatName) {
|
|
7077
|
-
const cid =
|
|
7078
|
-
const cname =
|
|
7111
|
+
const cid = normalizeText(chatId);
|
|
7112
|
+
const cname = normalizeText(chatName);
|
|
7079
7113
|
if (!cid) {
|
|
7080
7114
|
return;
|
|
7081
7115
|
}
|
|
@@ -7094,7 +7128,7 @@ var IdentityResolver = class {
|
|
|
7094
7128
|
}
|
|
7095
7129
|
async resolveRequester({ userId = "", openId = "", chatId = "" } = {}) {
|
|
7096
7130
|
const cache = this.loadCache();
|
|
7097
|
-
this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u5F00\u59CB: user_id=${
|
|
7131
|
+
this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u5F00\u59CB: user_id=${normalizeText(userId) || "-"}, open_id=${normalizeText(openId) || "-"}, chat_id=${normalizeText(chatId) || "-"}`));
|
|
7098
7132
|
if (this.patchRequesterOpenId(cache, { userId, openId })) {
|
|
7099
7133
|
this.saveCache();
|
|
7100
7134
|
}
|
|
@@ -7102,12 +7136,12 @@ var IdentityResolver = class {
|
|
|
7102
7136
|
if (matchedEntries.length > 0) {
|
|
7103
7137
|
const first = matchedEntries[0] || {};
|
|
7104
7138
|
if (hasUserProfileData(first)) {
|
|
7105
|
-
this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u547D\u4E2D\u7F13\u5B58: matched=${matchedEntries.length}, name=${resolveDisplayName(first.name) || "-"}, user=${
|
|
7139
|
+
this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u547D\u4E2D\u7F13\u5B58: matched=${matchedEntries.length}, name=${resolveDisplayName(first.name) || "-"}, user=${normalizeText(first.user) || "-"}, email=${normalizeText(first.email) || "-"}`));
|
|
7106
7140
|
return {
|
|
7107
|
-
userId:
|
|
7108
|
-
openId:
|
|
7109
|
-
name: resolveDisplayName(first.name) ||
|
|
7110
|
-
email:
|
|
7141
|
+
userId: normalizeText(userId) || normalizeText(first.feishuUserId),
|
|
7142
|
+
openId: normalizeText(openId) || normalizeText(first.feishuOpenId),
|
|
7143
|
+
name: resolveDisplayName(first.name) || normalizeText(first.user) || normalizeText(userId),
|
|
7144
|
+
email: normalizeText(first.email),
|
|
7111
7145
|
matchedEntries,
|
|
7112
7146
|
from: "cache"
|
|
7113
7147
|
};
|
|
@@ -7117,14 +7151,14 @@ var IdentityResolver = class {
|
|
|
7117
7151
|
if (directoryEmployee) {
|
|
7118
7152
|
const base = directoryEmployee.base_info || directoryEmployee.baseInfo || {};
|
|
7119
7153
|
const dirName = resolveDisplayName(base.name) || resolveDisplayName(directoryEmployee.name);
|
|
7120
|
-
const dirEmail =
|
|
7154
|
+
const dirEmail = normalizeText(base.email || directoryEmployee.email);
|
|
7121
7155
|
if (dirName || dirEmail) {
|
|
7122
|
-
this.updateUserCache(cache, { user_id:
|
|
7156
|
+
this.updateUserCache(cache, { user_id: normalizeText(userId), open_id: normalizeText(openId), name: dirName, email: dirEmail }, userId, openId);
|
|
7123
7157
|
this.saveCache();
|
|
7124
7158
|
return {
|
|
7125
|
-
userId:
|
|
7126
|
-
openId:
|
|
7127
|
-
name: dirName ||
|
|
7159
|
+
userId: normalizeText(userId),
|
|
7160
|
+
openId: normalizeText(openId),
|
|
7161
|
+
name: dirName || normalizeText(userId) || "-",
|
|
7128
7162
|
email: dirEmail,
|
|
7129
7163
|
matchedEntries: this.findUserEntries(cache, { userId, openId }),
|
|
7130
7164
|
from: "directory"
|
|
@@ -7136,21 +7170,21 @@ var IdentityResolver = class {
|
|
|
7136
7170
|
this.updateUserCache(cache, larkUser, userId, openId);
|
|
7137
7171
|
this.saveCache();
|
|
7138
7172
|
const refreshedMatches = this.findUserEntries(cache, {
|
|
7139
|
-
userId:
|
|
7140
|
-
openId:
|
|
7173
|
+
userId: normalizeText(larkUser.user_id || userId),
|
|
7174
|
+
openId: normalizeText(larkUser.open_id || openId)
|
|
7141
7175
|
});
|
|
7142
7176
|
return {
|
|
7143
|
-
userId:
|
|
7144
|
-
openId:
|
|
7145
|
-
name: resolveDisplayName(larkUser.name) ||
|
|
7146
|
-
email:
|
|
7177
|
+
userId: normalizeText(larkUser.user_id || userId),
|
|
7178
|
+
openId: normalizeText(larkUser.open_id || openId),
|
|
7179
|
+
name: resolveDisplayName(larkUser.name) || normalizeText(userId),
|
|
7180
|
+
email: normalizeText(larkUser.email),
|
|
7147
7181
|
matchedEntries: refreshedMatches,
|
|
7148
7182
|
from: "lark"
|
|
7149
7183
|
};
|
|
7150
7184
|
}
|
|
7151
7185
|
const members = await this.fetchChatMembersFromLark(chatId);
|
|
7152
7186
|
if (members.length > 0) {
|
|
7153
|
-
this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u7FA4\u6210\u5458\u515C\u5E95: chat_id=${
|
|
7187
|
+
this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u7FA4\u6210\u5458\u515C\u5E95: chat_id=${normalizeText(chatId) || "-"}, members=${members.length}`));
|
|
7154
7188
|
this.syncChatMembersToCache(cache, members);
|
|
7155
7189
|
this.patchRequesterOpenId(cache, { userId, openId });
|
|
7156
7190
|
this.saveCache();
|
|
@@ -7158,19 +7192,19 @@ var IdentityResolver = class {
|
|
|
7158
7192
|
if (memberMatches.length > 0) {
|
|
7159
7193
|
const first = memberMatches[0] || {};
|
|
7160
7194
|
return {
|
|
7161
|
-
userId:
|
|
7162
|
-
openId:
|
|
7163
|
-
name: resolveDisplayName(first.name) ||
|
|
7164
|
-
email:
|
|
7195
|
+
userId: normalizeText(userId) || normalizeText(first.feishuUserId),
|
|
7196
|
+
openId: normalizeText(openId) || normalizeText(first.feishuOpenId),
|
|
7197
|
+
name: resolveDisplayName(first.name) || normalizeText(first.user) || normalizeText(userId),
|
|
7198
|
+
email: normalizeText(first.email),
|
|
7165
7199
|
matchedEntries: memberMatches,
|
|
7166
7200
|
from: "chat_members"
|
|
7167
7201
|
};
|
|
7168
7202
|
}
|
|
7169
7203
|
}
|
|
7170
7204
|
return {
|
|
7171
|
-
userId:
|
|
7172
|
-
openId:
|
|
7173
|
-
name:
|
|
7205
|
+
userId: normalizeText(userId),
|
|
7206
|
+
openId: normalizeText(openId),
|
|
7207
|
+
name: normalizeText(userId) || "-",
|
|
7174
7208
|
email: "",
|
|
7175
7209
|
matchedEntries: [],
|
|
7176
7210
|
from: "id"
|
|
@@ -7179,16 +7213,16 @@ var IdentityResolver = class {
|
|
|
7179
7213
|
async resolveChat({ chatId = "" } = {}) {
|
|
7180
7214
|
const cache = this.loadCache();
|
|
7181
7215
|
const cached = this.findChatCache(cache, chatId);
|
|
7182
|
-
if (
|
|
7183
|
-
return { chatId:
|
|
7216
|
+
if (normalizeText(cached?.chatName)) {
|
|
7217
|
+
return { chatId: normalizeText(chatId), chatName: normalizeText(cached?.chatName), from: "cache" };
|
|
7184
7218
|
}
|
|
7185
7219
|
const chatName = await this.fetchChatNameFromLark(chatId);
|
|
7186
7220
|
if (chatName) {
|
|
7187
7221
|
this.upsertChatCache(cache, chatId, chatName);
|
|
7188
7222
|
this.saveCache();
|
|
7189
|
-
return { chatId:
|
|
7223
|
+
return { chatId: normalizeText(chatId), chatName, from: "lark" };
|
|
7190
7224
|
}
|
|
7191
|
-
return { chatId:
|
|
7225
|
+
return { chatId: normalizeText(chatId), chatName: normalizeText(chatId) || "-", from: "id" };
|
|
7192
7226
|
}
|
|
7193
7227
|
async resolveConversationIdentity({ senderUserId = "", senderOpenId = "", chatId = "" } = {}) {
|
|
7194
7228
|
const requester = await this.resolveRequester({ userId: senderUserId, openId: senderOpenId, chatId });
|
|
@@ -7251,7 +7285,7 @@ var REQUESTER_PERSONA_RULES = Object.freeze({
|
|
|
7251
7285
|
var OPS_DIR = path12.join(os6.homedir(), "ops");
|
|
7252
7286
|
var NIKOU_PROMPTS_DIR = path12.join(OPS_DIR, "nikou-prompts");
|
|
7253
7287
|
var NIKOU_ROLE_PROMPTS_DIR = path12.join(NIKOU_PROMPTS_DIR, "roles");
|
|
7254
|
-
function
|
|
7288
|
+
function normalizeText2(value) {
|
|
7255
7289
|
return String(value || "").trim();
|
|
7256
7290
|
}
|
|
7257
7291
|
function ensureDir(dirPath) {
|
|
@@ -7319,12 +7353,12 @@ function buildPromptDefinitions() {
|
|
|
7319
7353
|
const roleDefinitions = Object.entries(REQUESTER_PERSONA_RULES.roles).map(([roleKey, roleConfig]) => ({
|
|
7320
7354
|
id: roleKey,
|
|
7321
7355
|
kind: "role",
|
|
7322
|
-
title: `${
|
|
7356
|
+
title: `${normalizeText2(roleConfig.label) || roleKey}\u89D2\u8272\u63D0\u793A\u8BCD`,
|
|
7323
7357
|
path: path12.join(NIKOU_ROLE_PROMPTS_DIR, `${roleKey}.md`),
|
|
7324
7358
|
legacyPaths: [],
|
|
7325
7359
|
defaultContent: Array.isArray(roleConfig.promptLines) ? roleConfig.promptLines.join("\n") : "",
|
|
7326
7360
|
roleKey,
|
|
7327
|
-
roleLabel:
|
|
7361
|
+
roleLabel: normalizeText2(roleConfig.label) || roleKey
|
|
7328
7362
|
}));
|
|
7329
7363
|
return [
|
|
7330
7364
|
{
|
|
@@ -7459,7 +7493,7 @@ var NikouPromptStore = class {
|
|
|
7459
7493
|
});
|
|
7460
7494
|
}
|
|
7461
7495
|
readRolePrompt(roleKey) {
|
|
7462
|
-
const normalizedRoleKey =
|
|
7496
|
+
const normalizedRoleKey = normalizeText2(roleKey);
|
|
7463
7497
|
if (!normalizedRoleKey || !this.definitions.has(normalizedRoleKey)) {
|
|
7464
7498
|
return "";
|
|
7465
7499
|
}
|
|
@@ -7590,9 +7624,9 @@ var MessageReceiveStrategy = class {
|
|
|
7590
7624
|
const message = event?.message || {};
|
|
7591
7625
|
const senderId = this.resolveSenderUserId(eventPayload);
|
|
7592
7626
|
const senderOpenId = this.resolveSenderOpenId(eventPayload);
|
|
7593
|
-
const chatId =
|
|
7594
|
-
const chatType =
|
|
7595
|
-
const messageId =
|
|
7627
|
+
const chatId = normalizeText(message?.chat_id || message?.chatId);
|
|
7628
|
+
const chatType = normalizeText(message?.chat_type || message?.chatType);
|
|
7629
|
+
const messageId = normalizeText(message?.message_id || message?.messageId);
|
|
7596
7630
|
if (!chatId || !messageId) {
|
|
7597
7631
|
return null;
|
|
7598
7632
|
}
|
|
@@ -7602,12 +7636,12 @@ var MessageReceiveStrategy = class {
|
|
|
7602
7636
|
messageId,
|
|
7603
7637
|
senderId,
|
|
7604
7638
|
senderOpenId,
|
|
7605
|
-
messageType:
|
|
7606
|
-
content:
|
|
7607
|
-
rootId:
|
|
7608
|
-
parentId:
|
|
7609
|
-
threadId:
|
|
7610
|
-
createTime: Number.parseInt(
|
|
7639
|
+
messageType: normalizeText(message?.message_type || message?.messageType || "text"),
|
|
7640
|
+
content: normalizeText(message?.content),
|
|
7641
|
+
rootId: normalizeText(message?.root_id || message?.rootId),
|
|
7642
|
+
parentId: normalizeText(message?.parent_id || message?.parentId),
|
|
7643
|
+
threadId: normalizeText(message?.thread_id || message?.threadId),
|
|
7644
|
+
createTime: Number.parseInt(normalizeText(message?.create_time || message?.createTime || 0), 10) || 0,
|
|
7611
7645
|
mentions: Array.isArray(message?.mentions) ? message.mentions : []
|
|
7612
7646
|
};
|
|
7613
7647
|
}
|
|
@@ -7677,7 +7711,8 @@ var MessageReceiveStrategy = class {
|
|
|
7677
7711
|
lines.push(`\u6267\u884C\u8EAB\u4EFD: ${resolveOpsUserName()}`);
|
|
7678
7712
|
}
|
|
7679
7713
|
if (includeRequester && identity?.requester) {
|
|
7680
|
-
|
|
7714
|
+
const requesterName = resolveDisplayName(identity.requester.name) || normalizeText(identity.requester.user) || "-";
|
|
7715
|
+
lines.push(`\u63D0\u95EE\u8005: ${requesterName}(${normalizeText(identity.requester.userId) || "-"})`);
|
|
7681
7716
|
if (includeRequesterEmail && identity.requester.email) {
|
|
7682
7717
|
lines.push(`\u63D0\u95EE\u8005\u90AE\u7BB1: ${identity.requester.email}`);
|
|
7683
7718
|
}
|
|
@@ -7686,7 +7721,7 @@ var MessageReceiveStrategy = class {
|
|
|
7686
7721
|
}
|
|
7687
7722
|
}
|
|
7688
7723
|
if (includeChat && identity?.chat) {
|
|
7689
|
-
lines.push(`\u63D0\u95EE\u7FA4\u804A: ${identity.chat.chatName || "-"}(${identity.chat.chatId || "-"})`);
|
|
7724
|
+
lines.push(`\u63D0\u95EE\u7FA4\u804A: ${resolveDisplayName(identity.chat.chatName) || "-"}(${normalizeText(identity.chat.chatId) || "-"})`);
|
|
7690
7725
|
}
|
|
7691
7726
|
return lines;
|
|
7692
7727
|
}
|
|
@@ -11087,7 +11122,7 @@ var LocalBrowserWsServer = class {
|
|
|
11087
11122
|
import fs17 from "fs";
|
|
11088
11123
|
import os10 from "os";
|
|
11089
11124
|
import path16 from "path";
|
|
11090
|
-
function
|
|
11125
|
+
function normalize6(value) {
|
|
11091
11126
|
if (value === null || value === void 0) {
|
|
11092
11127
|
return "";
|
|
11093
11128
|
}
|
|
@@ -11100,8 +11135,8 @@ var HostProfileService = class {
|
|
|
11100
11135
|
cachePath;
|
|
11101
11136
|
constructor(options) {
|
|
11102
11137
|
this.logger = options.logger;
|
|
11103
|
-
this.ownerUserId =
|
|
11104
|
-
this.opsUserName =
|
|
11138
|
+
this.ownerUserId = normalize6(options.ownerUserId);
|
|
11139
|
+
this.opsUserName = normalize6(options.opsUserName);
|
|
11105
11140
|
this.cachePath = path16.join(os10.homedir(), "ops", "vops_user.json");
|
|
11106
11141
|
}
|
|
11107
11142
|
/**
|
|
@@ -11111,12 +11146,12 @@ var HostProfileService = class {
|
|
|
11111
11146
|
getProfile() {
|
|
11112
11147
|
const cacheEntry = this.findCacheEntry();
|
|
11113
11148
|
return {
|
|
11114
|
-
name:
|
|
11115
|
-
feishuUserId: this.ownerUserId ||
|
|
11116
|
-
feishuOpenId:
|
|
11117
|
-
employeeNo:
|
|
11118
|
-
email:
|
|
11119
|
-
user:
|
|
11149
|
+
name: normalize6(cacheEntry?.name),
|
|
11150
|
+
feishuUserId: this.ownerUserId || normalize6(cacheEntry?.feishuUserId),
|
|
11151
|
+
feishuOpenId: normalize6(cacheEntry?.feishuOpenId),
|
|
11152
|
+
employeeNo: normalize6(cacheEntry?.user || cacheEntry?.uId),
|
|
11153
|
+
email: normalize6(cacheEntry?.email),
|
|
11154
|
+
user: normalize6(cacheEntry?.user),
|
|
11120
11155
|
opsUserName: this.opsUserName,
|
|
11121
11156
|
source: cacheEntry ? "cache" : "fallback"
|
|
11122
11157
|
};
|
|
@@ -11128,11 +11163,11 @@ var HostProfileService = class {
|
|
|
11128
11163
|
try {
|
|
11129
11164
|
const parsed = JSON.parse(fs17.readFileSync(this.cachePath, "utf-8"));
|
|
11130
11165
|
const list = Array.isArray(parsed) ? parsed : [];
|
|
11131
|
-
const byUserId = list.find((item) =>
|
|
11166
|
+
const byUserId = list.find((item) => normalize6(item.feishuUserId) === this.ownerUserId);
|
|
11132
11167
|
if (byUserId) {
|
|
11133
11168
|
return byUserId;
|
|
11134
11169
|
}
|
|
11135
|
-
const byOpsUser = list.find((item) =>
|
|
11170
|
+
const byOpsUser = list.find((item) => normalize6(item.user) === this.opsUserName);
|
|
11136
11171
|
if (byOpsUser) {
|
|
11137
11172
|
return byOpsUser;
|
|
11138
11173
|
}
|
|
@@ -11151,7 +11186,7 @@ import os11 from "os";
|
|
|
11151
11186
|
import path17 from "path";
|
|
11152
11187
|
|
|
11153
11188
|
// src/hook/profile/codex-account-utils.ts
|
|
11154
|
-
function
|
|
11189
|
+
function normalize7(value) {
|
|
11155
11190
|
if (value === null || value === void 0) {
|
|
11156
11191
|
return "";
|
|
11157
11192
|
}
|
|
@@ -11164,7 +11199,7 @@ function compactLine(line) {
|
|
|
11164
11199
|
return stripAnsi2(line).replace(/[│╭╮╰╯]/g, " ").replace(/\s+/g, " ").trim();
|
|
11165
11200
|
}
|
|
11166
11201
|
function pickLine(lines, prefix) {
|
|
11167
|
-
const lowerPrefix =
|
|
11202
|
+
const lowerPrefix = normalize7(prefix).toLowerCase();
|
|
11168
11203
|
return lines.find((item) => compactLine(item).toLowerCase().startsWith(lowerPrefix)) || "";
|
|
11169
11204
|
}
|
|
11170
11205
|
function extractValue(line) {
|
|
@@ -11262,7 +11297,7 @@ function normalizeMonth(monthText) {
|
|
|
11262
11297
|
return monthMap[String(monthText || "").trim().toLowerCase()] || "";
|
|
11263
11298
|
}
|
|
11264
11299
|
function normalizeResetText(raw) {
|
|
11265
|
-
const text =
|
|
11300
|
+
const text = normalize7(raw);
|
|
11266
11301
|
if (!text) {
|
|
11267
11302
|
return "";
|
|
11268
11303
|
}
|
|
@@ -11309,7 +11344,7 @@ function normalizeUsageText(rawText) {
|
|
|
11309
11344
|
return text;
|
|
11310
11345
|
}
|
|
11311
11346
|
function normalizePlan(plan) {
|
|
11312
|
-
const raw =
|
|
11347
|
+
const raw = normalize7(plan).toLowerCase();
|
|
11313
11348
|
if (!raw) {
|
|
11314
11349
|
return "";
|
|
11315
11350
|
}
|
|
@@ -11329,10 +11364,10 @@ function extractAuthState(auth) {
|
|
|
11329
11364
|
}
|
|
11330
11365
|
const tokens = auth.tokens || {};
|
|
11331
11366
|
return {
|
|
11332
|
-
accessToken:
|
|
11333
|
-
idToken:
|
|
11334
|
-
accountId:
|
|
11335
|
-
authMode:
|
|
11367
|
+
accessToken: normalize7(tokens.access_token),
|
|
11368
|
+
idToken: normalize7(tokens.id_token),
|
|
11369
|
+
accountId: normalize7(tokens.account_id || auth.account_id),
|
|
11370
|
+
authMode: normalize7(auth.auth_mode)
|
|
11336
11371
|
};
|
|
11337
11372
|
}
|
|
11338
11373
|
function extractAccountInfo(auth) {
|
|
@@ -11340,10 +11375,10 @@ function extractAccountInfo(auth) {
|
|
|
11340
11375
|
const payload = decodeJwtPayload(authState.accessToken || authState.idToken || "");
|
|
11341
11376
|
const profileInfo = payload["https://api.openai.com/profile"] || {};
|
|
11342
11377
|
const authInfo = payload["https://api.openai.com/auth"] || {};
|
|
11343
|
-
const email =
|
|
11344
|
-
const planType =
|
|
11345
|
-
const accountId =
|
|
11346
|
-
const userId =
|
|
11378
|
+
const email = normalize7(profileInfo.email || payload.email);
|
|
11379
|
+
const planType = normalize7(authInfo.chatgpt_plan_type);
|
|
11380
|
+
const accountId = normalize7(authInfo.chatgpt_account_id || authState.accountId);
|
|
11381
|
+
const userId = normalize7(authInfo.chatgpt_user_id || authInfo.user_id);
|
|
11347
11382
|
const planLabel = normalizePlan(planType);
|
|
11348
11383
|
return {
|
|
11349
11384
|
email,
|
|
@@ -11361,8 +11396,8 @@ function pickRealtimeLimits(payload) {
|
|
|
11361
11396
|
const secondary = rateLimit.secondary_window || null;
|
|
11362
11397
|
const additional = Array.isArray(payload.additional_rate_limits) ? payload.additional_rate_limits : [];
|
|
11363
11398
|
const weeklyCandidate = additional.find((item) => {
|
|
11364
|
-
const feature =
|
|
11365
|
-
const name =
|
|
11399
|
+
const feature = normalize7(item.metered_feature).toLowerCase();
|
|
11400
|
+
const name = normalize7(item.limit_name).toLowerCase();
|
|
11366
11401
|
return feature.includes("weekly") || name.includes("weekly");
|
|
11367
11402
|
}) || additional[0] || null;
|
|
11368
11403
|
const weeklyRateLimit = weeklyCandidate ? (weeklyCandidate.rate_limit || {}).primary_window : secondary;
|
|
@@ -11504,7 +11539,7 @@ var CodexStatusService = class {
|
|
|
11504
11539
|
import fs19 from "fs";
|
|
11505
11540
|
import os12 from "os";
|
|
11506
11541
|
import path18 from "path";
|
|
11507
|
-
function
|
|
11542
|
+
function normalize8(value) {
|
|
11508
11543
|
return String(value || "").trim();
|
|
11509
11544
|
}
|
|
11510
11545
|
function ensureStoreShape(store) {
|
|
@@ -11554,7 +11589,7 @@ function compareProfiles(left, right) {
|
|
|
11554
11589
|
return String(left.alias || "").localeCompare(String(right.alias || ""), "zh-Hans-CN");
|
|
11555
11590
|
}
|
|
11556
11591
|
function isSameAccount(profile, targetAccount, targetState) {
|
|
11557
|
-
const profileAccountId =
|
|
11592
|
+
const profileAccountId = normalize8(profile.account?.accountId);
|
|
11558
11593
|
if (profileAccountId && targetAccount.accountId && profileAccountId === targetAccount.accountId) {
|
|
11559
11594
|
return true;
|
|
11560
11595
|
}
|
|
@@ -11742,11 +11777,11 @@ var CodexAccountService = class {
|
|
|
11742
11777
|
const profiles = refreshedProfiles.sort(compareProfiles).map((profile) => ({
|
|
11743
11778
|
alias: profile.alias,
|
|
11744
11779
|
current: profile.alias === store.current,
|
|
11745
|
-
account:
|
|
11746
|
-
planLabel:
|
|
11747
|
-
fiveHourLimit:
|
|
11748
|
-
weeklyLimit:
|
|
11749
|
-
updatedAt:
|
|
11780
|
+
account: normalize8(profile.account?.displayText || profile.account?.email),
|
|
11781
|
+
planLabel: normalize8(profile.account?.planLabel),
|
|
11782
|
+
fiveHourLimit: normalize8(profile.usage?.fiveHourLimit),
|
|
11783
|
+
weeklyLimit: normalize8(profile.usage?.weeklyLimit),
|
|
11784
|
+
updatedAt: normalize8(profile.usage?.updatedAt || profile.updatedAt),
|
|
11750
11785
|
fetchOk: Boolean(profile.usage?.fiveHourLimit || profile.usage?.weeklyLimit)
|
|
11751
11786
|
}));
|
|
11752
11787
|
return {
|
|
@@ -11758,7 +11793,7 @@ var CodexAccountService = class {
|
|
|
11758
11793
|
* 按别名切换当前 ~/.codex/auth.json。
|
|
11759
11794
|
*/
|
|
11760
11795
|
async switchAlias(alias) {
|
|
11761
|
-
const normalizedAlias =
|
|
11796
|
+
const normalizedAlias = normalize8(alias);
|
|
11762
11797
|
const store = await this.ensureCurrentAuthProfile(this.loadStore());
|
|
11763
11798
|
const target = normalizedAlias ? store.profiles[normalizedAlias] : void 0;
|
|
11764
11799
|
if (!target) {
|
|
@@ -11781,10 +11816,10 @@ var CodexAccountService = class {
|
|
|
11781
11816
|
return {
|
|
11782
11817
|
ok: true,
|
|
11783
11818
|
alias: normalizedAlias,
|
|
11784
|
-
account:
|
|
11785
|
-
planLabel:
|
|
11786
|
-
fiveHourLimit:
|
|
11787
|
-
weeklyLimit:
|
|
11819
|
+
account: normalize8(refreshed.account?.displayText || refreshed.account?.email),
|
|
11820
|
+
planLabel: normalize8(refreshed.account?.planLabel),
|
|
11821
|
+
fiveHourLimit: normalize8(refreshed.usage?.fiveHourLimit),
|
|
11822
|
+
weeklyLimit: normalize8(refreshed.usage?.weeklyLimit),
|
|
11788
11823
|
message: ""
|
|
11789
11824
|
};
|
|
11790
11825
|
}
|
|
@@ -11793,7 +11828,7 @@ var CodexAccountService = class {
|
|
|
11793
11828
|
// src/hook/bind/bind-chat-profile-service.ts
|
|
11794
11829
|
import os13 from "os";
|
|
11795
11830
|
import path19 from "path";
|
|
11796
|
-
function
|
|
11831
|
+
function normalize9(value) {
|
|
11797
11832
|
if (value === null || value === void 0) {
|
|
11798
11833
|
return "";
|
|
11799
11834
|
}
|
|
@@ -11817,7 +11852,7 @@ var BindChatProfileService = class {
|
|
|
11817
11852
|
path: { chat_id: chatId }
|
|
11818
11853
|
});
|
|
11819
11854
|
const data = response?.data || response || {};
|
|
11820
|
-
return
|
|
11855
|
+
return normalize9(data.name || data.chat_name || data.chat?.name);
|
|
11821
11856
|
} catch (error) {
|
|
11822
11857
|
const message = error instanceof Error ? error.message : String(error);
|
|
11823
11858
|
this.logger.warn(`\u7FA4\u804A\u540D\u79F0\u89E3\u6790\u5931\u8D25: chat_id=${chatId}, error=${message}`);
|
|
@@ -11833,21 +11868,21 @@ var BindChatProfileService = class {
|
|
|
11833
11868
|
const items = [];
|
|
11834
11869
|
for (const [dirPath, binding] of Object.entries(bindings)) {
|
|
11835
11870
|
const chatIds = Array.isArray(binding?.chat_ids) ? binding.chat_ids.filter(Boolean) : [];
|
|
11836
|
-
const dirName = path19.basename(dirPath || "") ||
|
|
11871
|
+
const dirName = path19.basename(dirPath || "") || normalize9(dirPath);
|
|
11837
11872
|
for (const chatId of chatIds) {
|
|
11838
11873
|
const chatName = await this.resolveChatName(chatId);
|
|
11839
11874
|
items.push({
|
|
11840
|
-
chatId:
|
|
11841
|
-
chatName: chatName ||
|
|
11875
|
+
chatId: normalize9(chatId),
|
|
11876
|
+
chatName: chatName || normalize9(chatId),
|
|
11842
11877
|
dirName,
|
|
11843
|
-
dirPath:
|
|
11844
|
-
bindAt:
|
|
11878
|
+
dirPath: normalize9(dirPath),
|
|
11879
|
+
bindAt: normalize9(binding?.bindAt)
|
|
11845
11880
|
});
|
|
11846
11881
|
}
|
|
11847
11882
|
}
|
|
11848
11883
|
items.sort((left, right) => right.bindAt.localeCompare(left.bindAt));
|
|
11849
11884
|
return {
|
|
11850
|
-
hostName:
|
|
11885
|
+
hostName: normalize9(os13.hostname()),
|
|
11851
11886
|
count: items.length,
|
|
11852
11887
|
items
|
|
11853
11888
|
};
|
|
@@ -11859,7 +11894,7 @@ import fs20 from "fs";
|
|
|
11859
11894
|
import os14 from "os";
|
|
11860
11895
|
import path20 from "path";
|
|
11861
11896
|
var LATEST_SESSION_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
11862
|
-
function
|
|
11897
|
+
function normalize10(value) {
|
|
11863
11898
|
return String(value || "").trim();
|
|
11864
11899
|
}
|
|
11865
11900
|
function isSameLocalDate(leftDate, rightDate) {
|
|
@@ -11936,10 +11971,10 @@ var P2PSessionService = class {
|
|
|
11936
11971
|
}
|
|
11937
11972
|
buildSessionKey(input) {
|
|
11938
11973
|
return [
|
|
11939
|
-
|
|
11940
|
-
|
|
11941
|
-
|
|
11942
|
-
|
|
11974
|
+
normalize10(input.ownerUserId),
|
|
11975
|
+
normalize10(input.requesterUserId),
|
|
11976
|
+
normalize10(input.chatId),
|
|
11977
|
+
normalize10(input.anchorMessageId)
|
|
11943
11978
|
].join("::");
|
|
11944
11979
|
}
|
|
11945
11980
|
parseNewConversationCommand(text = "") {
|
|
@@ -11976,9 +12011,9 @@ var P2PSessionService = class {
|
|
|
11976
12011
|
* 解析当前单聊应该复用哪个会话。
|
|
11977
12012
|
*/
|
|
11978
12013
|
resolveSessionContext(input) {
|
|
11979
|
-
const ownerUserId =
|
|
12014
|
+
const ownerUserId = normalize10(this.stateManager.getState()?.ownerUserId || "");
|
|
11980
12015
|
if (!input.forceNew) {
|
|
11981
|
-
const candidates = Array.from(new Set([
|
|
12016
|
+
const candidates = Array.from(new Set([normalize10(input.rootId), normalize10(input.parentId)].filter(Boolean)));
|
|
11982
12017
|
for (const referencedId of candidates) {
|
|
11983
12018
|
const matched = this.stateManager.getP2PSessionByMessageId(referencedId);
|
|
11984
12019
|
if (!matched) {
|
|
@@ -11986,13 +12021,13 @@ var P2PSessionService = class {
|
|
|
11986
12021
|
}
|
|
11987
12022
|
return {
|
|
11988
12023
|
ownerUserId,
|
|
11989
|
-
requesterUserId:
|
|
11990
|
-
chatId:
|
|
11991
|
-
dirPath:
|
|
11992
|
-
anchorMessageId:
|
|
11993
|
-
existingSessionId:
|
|
11994
|
-
sessionKey:
|
|
11995
|
-
messageIds: Array.isArray(matched.messageIds) ? matched.messageIds.map((item) =>
|
|
12024
|
+
requesterUserId: normalize10(input.requesterUserId),
|
|
12025
|
+
chatId: normalize10(input.chatId),
|
|
12026
|
+
dirPath: normalize10(input.dirPath),
|
|
12027
|
+
anchorMessageId: normalize10(matched.anchorMessageId || referencedId || input.messageId),
|
|
12028
|
+
existingSessionId: normalize10(matched.sessionId),
|
|
12029
|
+
sessionKey: normalize10(matched.sessionKey),
|
|
12030
|
+
messageIds: Array.isArray(matched.messageIds) ? matched.messageIds.map((item) => normalize10(item)).filter(Boolean) : [],
|
|
11996
12031
|
matchedBy: "reference"
|
|
11997
12032
|
};
|
|
11998
12033
|
}
|
|
@@ -12001,26 +12036,26 @@ var P2PSessionService = class {
|
|
|
12001
12036
|
requesterUserId: input.requesterUserId,
|
|
12002
12037
|
chatId: input.chatId
|
|
12003
12038
|
});
|
|
12004
|
-
if (latest &&
|
|
12039
|
+
if (latest && normalize10(latest.sessionId)) {
|
|
12005
12040
|
return {
|
|
12006
12041
|
ownerUserId,
|
|
12007
|
-
requesterUserId:
|
|
12008
|
-
chatId:
|
|
12009
|
-
dirPath:
|
|
12010
|
-
anchorMessageId:
|
|
12011
|
-
existingSessionId:
|
|
12012
|
-
sessionKey:
|
|
12013
|
-
messageIds: Array.isArray(latest.messageIds) ? latest.messageIds.map((item) =>
|
|
12042
|
+
requesterUserId: normalize10(input.requesterUserId),
|
|
12043
|
+
chatId: normalize10(input.chatId),
|
|
12044
|
+
dirPath: normalize10(input.dirPath || latest.dirPath),
|
|
12045
|
+
anchorMessageId: normalize10(latest.anchorMessageId),
|
|
12046
|
+
existingSessionId: normalize10(latest.sessionId),
|
|
12047
|
+
sessionKey: normalize10(latest.sessionKey),
|
|
12048
|
+
messageIds: Array.isArray(latest.messageIds) ? latest.messageIds.map((item) => normalize10(item)).filter(Boolean) : [],
|
|
12014
12049
|
matchedBy: "latest"
|
|
12015
12050
|
};
|
|
12016
12051
|
}
|
|
12017
12052
|
}
|
|
12018
|
-
const anchorMessageId =
|
|
12053
|
+
const anchorMessageId = normalize10(input.rootId || input.parentId || input.messageId);
|
|
12019
12054
|
return {
|
|
12020
12055
|
ownerUserId,
|
|
12021
|
-
requesterUserId:
|
|
12022
|
-
chatId:
|
|
12023
|
-
dirPath:
|
|
12056
|
+
requesterUserId: normalize10(input.requesterUserId),
|
|
12057
|
+
chatId: normalize10(input.chatId),
|
|
12058
|
+
dirPath: normalize10(input.dirPath),
|
|
12024
12059
|
anchorMessageId,
|
|
12025
12060
|
existingSessionId: "",
|
|
12026
12061
|
sessionKey: this.buildSessionKey({
|
|
@@ -12039,12 +12074,12 @@ var P2PSessionService = class {
|
|
|
12039
12074
|
}
|
|
12040
12075
|
this.stateManager.upsertP2PSession({
|
|
12041
12076
|
sessionKey: input.sessionKey,
|
|
12042
|
-
ownerUserId:
|
|
12043
|
-
requesterUserId:
|
|
12044
|
-
chatId:
|
|
12045
|
-
anchorMessageId:
|
|
12046
|
-
dirPath:
|
|
12047
|
-
sessionId:
|
|
12077
|
+
ownerUserId: normalize10(input.ownerUserId),
|
|
12078
|
+
requesterUserId: normalize10(input.requesterUserId),
|
|
12079
|
+
chatId: normalize10(input.chatId),
|
|
12080
|
+
anchorMessageId: normalize10(input.anchorMessageId),
|
|
12081
|
+
dirPath: normalize10(input.dirPath),
|
|
12082
|
+
sessionId: normalize10(input.sessionId)
|
|
12048
12083
|
}, input.messageIds);
|
|
12049
12084
|
}
|
|
12050
12085
|
};
|
|
@@ -12052,11 +12087,11 @@ var P2PSessionService = class {
|
|
|
12052
12087
|
// src/hook/memory/memory-bucket-resolver.ts
|
|
12053
12088
|
import fs21 from "fs";
|
|
12054
12089
|
import path21 from "path";
|
|
12055
|
-
function
|
|
12090
|
+
function normalize11(value) {
|
|
12056
12091
|
return String(value || "").trim();
|
|
12057
12092
|
}
|
|
12058
12093
|
function buildSafeSegment(value, fallback = "unknown") {
|
|
12059
|
-
const normalized =
|
|
12094
|
+
const normalized = normalize11(value).replace(/[<>:"/\\|?*\u0000-\u001F]/g, "_");
|
|
12060
12095
|
return normalized || fallback;
|
|
12061
12096
|
}
|
|
12062
12097
|
function buildTodayString(offsetDays = 0) {
|
|
@@ -12082,8 +12117,8 @@ var MemoryBucketResolver = class {
|
|
|
12082
12117
|
const requester = buildSafeSegment(requesterUserId, "requester");
|
|
12083
12118
|
const baseDir = path21.join(this.getRootDir(), "p2p", owner, requester);
|
|
12084
12119
|
return this.buildBucket({
|
|
12085
|
-
bucketKey: `p2p::${
|
|
12086
|
-
bucketLabel: `\u5355\u804A(${
|
|
12120
|
+
bucketKey: `p2p::${normalize11(ownerUserId)}::${normalize11(requesterUserId)}`,
|
|
12121
|
+
bucketLabel: `\u5355\u804A(${normalize11(requesterUserId) || requester})`,
|
|
12087
12122
|
bucketType: "p2p",
|
|
12088
12123
|
baseDir,
|
|
12089
12124
|
chatId
|
|
@@ -12093,8 +12128,8 @@ var MemoryBucketResolver = class {
|
|
|
12093
12128
|
const chat = buildSafeSegment(chatId, "chat");
|
|
12094
12129
|
const baseDir = path21.join(this.getRootDir(), "group", chat);
|
|
12095
12130
|
return this.buildBucket({
|
|
12096
|
-
bucketKey: `group::${
|
|
12097
|
-
bucketLabel: `\u7FA4\u804A(${
|
|
12131
|
+
bucketKey: `group::${normalize11(chatId)}`,
|
|
12132
|
+
bucketLabel: `\u7FA4\u804A(${normalize11(chatId) || chat})`,
|
|
12098
12133
|
bucketType: "group",
|
|
12099
12134
|
baseDir,
|
|
12100
12135
|
chatId
|
|
@@ -12108,7 +12143,7 @@ var MemoryBucketResolver = class {
|
|
|
12108
12143
|
bucketKey,
|
|
12109
12144
|
bucketLabel,
|
|
12110
12145
|
bucketType,
|
|
12111
|
-
chatId:
|
|
12146
|
+
chatId: normalize11(chatId),
|
|
12112
12147
|
baseDir,
|
|
12113
12148
|
memoryDir,
|
|
12114
12149
|
longTermPath: path21.join(baseDir, "MEMORY.md"),
|
|
@@ -12138,11 +12173,11 @@ var MemoryBucketResolver = class {
|
|
|
12138
12173
|
};
|
|
12139
12174
|
|
|
12140
12175
|
// src/hook/memory/memory-extract-service.ts
|
|
12141
|
-
function
|
|
12176
|
+
function normalize12(value) {
|
|
12142
12177
|
return String(value || "").replace(/\s+/g, " ").trim();
|
|
12143
12178
|
}
|
|
12144
12179
|
function extractSummary(text = "") {
|
|
12145
|
-
const normalized =
|
|
12180
|
+
const normalized = normalize12(text).replace(/^\/new\s*/i, "").replace(/^(记住|记一下|写入记忆|更新记忆|记到长期记忆)\s*/i, "").trim();
|
|
12146
12181
|
if (!normalized) {
|
|
12147
12182
|
return "";
|
|
12148
12183
|
}
|
|
@@ -12150,7 +12185,7 @@ function extractSummary(text = "") {
|
|
|
12150
12185
|
}
|
|
12151
12186
|
var MemoryExtractService = class {
|
|
12152
12187
|
extractExplicit(text = "") {
|
|
12153
|
-
const normalized =
|
|
12188
|
+
const normalized = normalize12(text);
|
|
12154
12189
|
if (!normalized) {
|
|
12155
12190
|
return { matched: false, target: "DAILY", summary: "" };
|
|
12156
12191
|
}
|
|
@@ -12166,8 +12201,8 @@ var MemoryExtractService = class {
|
|
|
12166
12201
|
if (String(chatType || "").trim() !== "p2p") {
|
|
12167
12202
|
return { shouldWrite: false, target: "DAILY", summary: "" };
|
|
12168
12203
|
}
|
|
12169
|
-
const normalized =
|
|
12170
|
-
if (!normalized || !
|
|
12204
|
+
const normalized = normalize12(questionText);
|
|
12205
|
+
if (!normalized || !normalize12(resultText)) {
|
|
12171
12206
|
return { shouldWrite: false, target: "DAILY", summary: "" };
|
|
12172
12207
|
}
|
|
12173
12208
|
const likelyMemory = /(以后|默认|偏好|习惯|优先|总是|不要|回答时|称呼我|风格|长期|固定规则)/i.test(normalized);
|
|
@@ -12184,7 +12219,7 @@ var MemoryExtractService = class {
|
|
|
12184
12219
|
};
|
|
12185
12220
|
|
|
12186
12221
|
// src/hook/memory/memory-index-service.ts
|
|
12187
|
-
function
|
|
12222
|
+
function normalize13(value) {
|
|
12188
12223
|
return String(value || "").trim();
|
|
12189
12224
|
}
|
|
12190
12225
|
function toSnippet(text = "", maxLength = 220) {
|
|
@@ -12207,7 +12242,7 @@ var MemoryIndexService = class {
|
|
|
12207
12242
|
this.docsByBucket.set(String(bucket.bucketKey || ""), docs);
|
|
12208
12243
|
}
|
|
12209
12244
|
async search(bucket, query, limit = 5) {
|
|
12210
|
-
const text =
|
|
12245
|
+
const text = normalize13(query);
|
|
12211
12246
|
if (!text) {
|
|
12212
12247
|
return [];
|
|
12213
12248
|
}
|
|
@@ -12243,7 +12278,7 @@ ${content}`.toLowerCase();
|
|
|
12243
12278
|
// src/hook/memory/memory-service.ts
|
|
12244
12279
|
import fs22 from "fs";
|
|
12245
12280
|
import path22 from "path";
|
|
12246
|
-
function
|
|
12281
|
+
function normalize14(value) {
|
|
12247
12282
|
return String(value || "").trim();
|
|
12248
12283
|
}
|
|
12249
12284
|
function nowIso() {
|
|
@@ -12369,7 +12404,7 @@ ${nextLine}`;
|
|
|
12369
12404
|
return { longTermText, dailyText, searchResults };
|
|
12370
12405
|
}
|
|
12371
12406
|
resolveCommand(text = "") {
|
|
12372
|
-
const normalized =
|
|
12407
|
+
const normalized = normalize14(text);
|
|
12373
12408
|
if (!normalized) {
|
|
12374
12409
|
return { matched: false };
|
|
12375
12410
|
}
|
|
@@ -12380,7 +12415,7 @@ ${nextLine}`;
|
|
|
12380
12415
|
if (/^确认重置长期记忆$/i.test(normalized)) return { matched: true, type: "confirm_reset_memory" };
|
|
12381
12416
|
const searchMatch = normalized.match(/^搜索记忆\s+([\s\S]+)$/i);
|
|
12382
12417
|
if (searchMatch) {
|
|
12383
|
-
return { matched: true, type: "search_memory", query:
|
|
12418
|
+
return { matched: true, type: "search_memory", query: normalize14(searchMatch[1]) };
|
|
12384
12419
|
}
|
|
12385
12420
|
const explicit = this.extractService.extractExplicit(normalized);
|
|
12386
12421
|
if (explicit.matched) {
|
|
@@ -12432,7 +12467,7 @@ ${item.snippet}`);
|
|
|
12432
12467
|
${lines.join("\n\n")}` };
|
|
12433
12468
|
}
|
|
12434
12469
|
case "write_memory": {
|
|
12435
|
-
const summary =
|
|
12470
|
+
const summary = normalize14(command.summary);
|
|
12436
12471
|
if (!summary) {
|
|
12437
12472
|
return { handled: true, text: "\u8BB0\u5FC6\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u5DF2\u5FFD\u7565" };
|
|
12438
12473
|
}
|
|
@@ -12465,7 +12500,7 @@ ${lines.join("\n\n")}` };
|
|
|
12465
12500
|
};
|
|
12466
12501
|
|
|
12467
12502
|
// src/hook/reminder/reminder-action-classifier.ts
|
|
12468
|
-
function
|
|
12503
|
+
function normalize15(value) {
|
|
12469
12504
|
return String(value || "").replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
|
|
12470
12505
|
}
|
|
12471
12506
|
var NOTIFY_PATTERNS = [
|
|
@@ -12500,7 +12535,7 @@ var AGENT_PATTERNS = [
|
|
|
12500
12535
|
];
|
|
12501
12536
|
var ReminderActionClassifier = class {
|
|
12502
12537
|
classify(rawText = "") {
|
|
12503
|
-
const text =
|
|
12538
|
+
const text = normalize15(rawText);
|
|
12504
12539
|
if (!text) {
|
|
12505
12540
|
return { ok: false, reason: "empty_action" };
|
|
12506
12541
|
}
|
|
@@ -12517,7 +12552,7 @@ var ReminderActionClassifier = class {
|
|
|
12517
12552
|
|
|
12518
12553
|
// src/hook/reminder/reminder-agent-executor.ts
|
|
12519
12554
|
import fs23 from "fs";
|
|
12520
|
-
function
|
|
12555
|
+
function normalize16(value) {
|
|
12521
12556
|
return String(value || "").trim();
|
|
12522
12557
|
}
|
|
12523
12558
|
var ReminderAgentExecutor = class {
|
|
@@ -12540,16 +12575,16 @@ var ReminderAgentExecutor = class {
|
|
|
12540
12575
|
this.isExecutionBusy = typeof isExecutionBusy === "function" ? isExecutionBusy : () => false;
|
|
12541
12576
|
}
|
|
12542
12577
|
resolveSessionKey(job) {
|
|
12543
|
-
const ownerUserId =
|
|
12544
|
-
const chatType =
|
|
12545
|
-
const chatId =
|
|
12546
|
-
const rootId =
|
|
12578
|
+
const ownerUserId = normalize16(job?.ownerUserId);
|
|
12579
|
+
const chatType = normalize16(job?.delivery?.chatType || job?.chatType);
|
|
12580
|
+
const chatId = normalize16(job?.delivery?.chatId || job?.chatId);
|
|
12581
|
+
const rootId = normalize16(job?.rootId || job?.delivery?.rootId);
|
|
12547
12582
|
if (chatType === "p2p") return `p2p::${ownerUserId || "unknown"}`;
|
|
12548
12583
|
if (chatType === "group") return rootId ? `group::${chatId || "unknown"}::${rootId}` : `group::${chatId || "unknown"}`;
|
|
12549
12584
|
return "";
|
|
12550
12585
|
}
|
|
12551
12586
|
loadAiHookPrompt(requesterUserId = "") {
|
|
12552
|
-
const promptPath = requesterUserId ? requesterUserId ===
|
|
12587
|
+
const promptPath = requesterUserId ? requesterUserId === normalize16(process.env.AGENT_BLOCK_OWNER_USER_ID) ? resolveAiHookPath() : resolveAiHookGuestPath() : resolveAiHookGuestPath();
|
|
12553
12588
|
if (!fs23.existsSync(promptPath)) {
|
|
12554
12589
|
return "";
|
|
12555
12590
|
}
|
|
@@ -12569,8 +12604,8 @@ var ReminderAgentExecutor = class {
|
|
|
12569
12604
|
if (!dirResolved.ok || !dirResolved.dirPath) {
|
|
12570
12605
|
return { ok: false, retryLater: false, error: dirResolved.error || "\u9ED8\u8BA4\u76EE\u5F55\u672A\u521D\u59CB\u5316" };
|
|
12571
12606
|
}
|
|
12572
|
-
const requesterUserId =
|
|
12573
|
-
const actionPrompt =
|
|
12607
|
+
const requesterUserId = normalize16(job?.requesterUserId || job?.delivery?.requesterUserId);
|
|
12608
|
+
const actionPrompt = normalize16(job?.action?.prompt || job?.action?.text);
|
|
12574
12609
|
if (!actionPrompt) {
|
|
12575
12610
|
return { ok: false, retryLater: false, error: "\u7F3A\u5C11\u5B9A\u65F6\u6267\u884C\u5185\u5BB9" };
|
|
12576
12611
|
}
|
|
@@ -12580,9 +12615,9 @@ var ReminderAgentExecutor = class {
|
|
|
12580
12615
|
${actionPrompt}` : actionPrompt;
|
|
12581
12616
|
const memoryBucket = this.memoryService?.resolveBucket({
|
|
12582
12617
|
chatType: "p2p",
|
|
12583
|
-
ownerUserId:
|
|
12618
|
+
ownerUserId: normalize16(job?.ownerUserId),
|
|
12584
12619
|
requesterUserId,
|
|
12585
|
-
chatId:
|
|
12620
|
+
chatId: normalize16(job?.delivery?.chatId)
|
|
12586
12621
|
}) || null;
|
|
12587
12622
|
this.logger.info(formatTraceLog(traceId, `\u5B9A\u65F6\u4EFB\u52A1\u5F00\u59CB\u6267\u884C: job_id=${job?.id || "-"}, dir=${dirResolved.dirPath}, action=agent_turn, session_key=${sessionKey || "-"}`));
|
|
12588
12623
|
const result = await this.codexRunner.run(prompt, dirResolved.dirPath, {
|
|
@@ -12710,7 +12745,7 @@ var ReminderMessageBuilder = class {
|
|
|
12710
12745
|
};
|
|
12711
12746
|
|
|
12712
12747
|
// src/hook/reminder/reminder-parser.ts
|
|
12713
|
-
function
|
|
12748
|
+
function normalize17(value) {
|
|
12714
12749
|
return String(value || "").replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
|
|
12715
12750
|
}
|
|
12716
12751
|
function pad23(value) {
|
|
@@ -12724,7 +12759,7 @@ function buildTodayOrTomorrow(baseDate, daysOffset, hour, minute) {
|
|
|
12724
12759
|
return next;
|
|
12725
12760
|
}
|
|
12726
12761
|
function toMinutes(amount, unit) {
|
|
12727
|
-
const normalized =
|
|
12762
|
+
const normalized = normalize17(unit).toLowerCase();
|
|
12728
12763
|
if (["\u5206\u949F", "\u5206", "m", "min", "mins", "minute", "minutes"].includes(normalized)) {
|
|
12729
12764
|
return amount;
|
|
12730
12765
|
}
|
|
@@ -12736,7 +12771,7 @@ var ReminderParser = class {
|
|
|
12736
12771
|
this.actionClassifier = actionClassifier;
|
|
12737
12772
|
}
|
|
12738
12773
|
parse(rawText, now = /* @__PURE__ */ new Date(), context = {}) {
|
|
12739
|
-
const text =
|
|
12774
|
+
const text = normalize17(rawText);
|
|
12740
12775
|
if (!text) {
|
|
12741
12776
|
return { matched: false };
|
|
12742
12777
|
}
|
|
@@ -12751,7 +12786,7 @@ var ReminderParser = class {
|
|
|
12751
12786
|
if (/^清空提醒$/i.test(text)) return { matched: true, type: "clear_jobs" };
|
|
12752
12787
|
const cancelMatch = text.match(/^取消提醒\s+([A-Za-z0-9_-]+)$/i);
|
|
12753
12788
|
if (cancelMatch) {
|
|
12754
|
-
return { matched: true, type: "cancel_job", jobId:
|
|
12789
|
+
return { matched: true, type: "cancel_job", jobId: normalize17(cancelMatch[1]) };
|
|
12755
12790
|
}
|
|
12756
12791
|
return { matched: false };
|
|
12757
12792
|
}
|
|
@@ -12765,12 +12800,12 @@ var ReminderParser = class {
|
|
|
12765
12800
|
parseSlashRemind(text, now) {
|
|
12766
12801
|
const match = text.match(/^\/remind\s+(\d+)\s*(分钟|分|min|mins|minute|minutes|m|小时|时|hour|hours|h)\s+(.+)$/i);
|
|
12767
12802
|
if (!match) return { matched: false };
|
|
12768
|
-
return this.buildCreateResult(Number.parseInt(match[1] || "0", 10),
|
|
12803
|
+
return this.buildCreateResult(Number.parseInt(match[1] || "0", 10), normalize17(match[2]).toLowerCase(), normalize17(match[3]), now, { forceKind: "notify" });
|
|
12769
12804
|
}
|
|
12770
12805
|
parseRelativeReminder(text, now, context) {
|
|
12771
12806
|
const match = text.match(/^(\d+)\s*(分钟|分|min|mins|minute|minutes|m|小时|时|hour|hours|h)\s*后\s*(.+)$/i);
|
|
12772
12807
|
if (!match) return { matched: false };
|
|
12773
|
-
return this.buildCreateResult(Number.parseInt(match[1] || "0", 10),
|
|
12808
|
+
return this.buildCreateResult(Number.parseInt(match[1] || "0", 10), normalize17(match[2]).toLowerCase(), normalize17(match[3]), now, context);
|
|
12774
12809
|
}
|
|
12775
12810
|
buildCreateResult(amount, unit, content, now, context = {}) {
|
|
12776
12811
|
if (!Number.isFinite(amount) || amount <= 0) {
|
|
@@ -12797,10 +12832,10 @@ var ReminderParser = class {
|
|
|
12797
12832
|
parseFixedReminder(text, now, context) {
|
|
12798
12833
|
const match = text.match(/^(今天|明天)\s*(\d{1,2})[::](\d{2})\s*(.+)$/i);
|
|
12799
12834
|
if (!match) return { matched: false };
|
|
12800
|
-
const dayToken =
|
|
12835
|
+
const dayToken = normalize17(match[1]);
|
|
12801
12836
|
const hour = Number.parseInt(match[2] || "0", 10);
|
|
12802
12837
|
const minute = Number.parseInt(match[3] || "0", 10);
|
|
12803
|
-
const content =
|
|
12838
|
+
const content = normalize17(match[4]);
|
|
12804
12839
|
if (!Number.isFinite(hour) || hour < 0 || hour > 23 || !Number.isFinite(minute) || minute < 0 || minute > 59) {
|
|
12805
12840
|
return { matched: true, type: "invalid", error: "\u63D0\u9192\u65F6\u95F4\u683C\u5F0F\u4E0D\u6B63\u786E\uFF0C\u8BF7\u4F7F\u7528 HH:mm" };
|
|
12806
12841
|
}
|
|
@@ -12826,7 +12861,7 @@ var ReminderParser = class {
|
|
|
12826
12861
|
};
|
|
12827
12862
|
}
|
|
12828
12863
|
resolveAction(content, context = {}, forceKind = "") {
|
|
12829
|
-
const normalizedContent =
|
|
12864
|
+
const normalizedContent = normalize17(content);
|
|
12830
12865
|
if (!normalizedContent) {
|
|
12831
12866
|
return { ok: false, reason: "empty_action" };
|
|
12832
12867
|
}
|
|
@@ -12891,16 +12926,16 @@ var ReminderStore = class {
|
|
|
12891
12926
|
};
|
|
12892
12927
|
|
|
12893
12928
|
// src/hook/reminder/reminder-service.ts
|
|
12894
|
-
function
|
|
12929
|
+
function normalize18(value) {
|
|
12895
12930
|
return String(value || "").trim();
|
|
12896
12931
|
}
|
|
12897
12932
|
function normalizeTargets2(items = []) {
|
|
12898
12933
|
const seen = /* @__PURE__ */ new Set();
|
|
12899
12934
|
const targets = [];
|
|
12900
12935
|
(Array.isArray(items) ? items : []).forEach((item) => {
|
|
12901
|
-
const userId =
|
|
12902
|
-
const openId =
|
|
12903
|
-
const name =
|
|
12936
|
+
const userId = normalize18(item?.userId || item?.user_id);
|
|
12937
|
+
const openId = normalize18(item?.openId || item?.open_id);
|
|
12938
|
+
const name = normalize18(item?.name);
|
|
12904
12939
|
if (!userId && !openId) {
|
|
12905
12940
|
return;
|
|
12906
12941
|
}
|
|
@@ -13026,27 +13061,27 @@ var ReminderService = class {
|
|
|
13026
13061
|
const nowMs = Date.now();
|
|
13027
13062
|
return {
|
|
13028
13063
|
id: createJobId(),
|
|
13029
|
-
ownerUserId:
|
|
13030
|
-
requesterUserId:
|
|
13031
|
-
requesterOpenId:
|
|
13032
|
-
chatType:
|
|
13033
|
-
messageId:
|
|
13034
|
-
rootId:
|
|
13035
|
-
parentId:
|
|
13036
|
-
traceId:
|
|
13064
|
+
ownerUserId: normalize18(context.ownerUserId),
|
|
13065
|
+
requesterUserId: normalize18(context.requesterUserId),
|
|
13066
|
+
requesterOpenId: normalize18(context.requesterOpenId),
|
|
13067
|
+
chatType: normalize18(context.chatType),
|
|
13068
|
+
messageId: normalize18(context.messageId),
|
|
13069
|
+
rootId: normalize18(context.rootId),
|
|
13070
|
+
parentId: normalize18(context.parentId),
|
|
13071
|
+
traceId: normalize18(context.traceId),
|
|
13037
13072
|
schedule: { kind: "at", runAtMs: Number(command?.schedule?.runAtMs || 0) },
|
|
13038
13073
|
action: {
|
|
13039
|
-
kind:
|
|
13040
|
-
text:
|
|
13041
|
-
prompt:
|
|
13074
|
+
kind: normalize18(command?.action?.kind || "notify"),
|
|
13075
|
+
text: normalize18(command?.action?.content || command?.action?.text || command?.sourceText),
|
|
13076
|
+
prompt: normalize18(command?.action?.content || command?.action?.prompt || command?.sourceText)
|
|
13042
13077
|
},
|
|
13043
13078
|
delivery: {
|
|
13044
13079
|
mode: "feishu_message",
|
|
13045
13080
|
target: "origin_chat",
|
|
13046
|
-
chatType:
|
|
13047
|
-
chatId:
|
|
13048
|
-
requesterUserId:
|
|
13049
|
-
requesterOpenId:
|
|
13081
|
+
chatType: normalize18(context.chatType),
|
|
13082
|
+
chatId: normalize18(context.chatId),
|
|
13083
|
+
requesterUserId: normalize18(context.requesterUserId),
|
|
13084
|
+
requesterOpenId: normalize18(context.requesterOpenId),
|
|
13050
13085
|
notifyTargets: normalizeTargets2(context.reminderTargets)
|
|
13051
13086
|
},
|
|
13052
13087
|
state: {
|
|
@@ -13062,20 +13097,20 @@ var ReminderService = class {
|
|
|
13062
13097
|
return this.store.readAll().filter((job) => this.isVisibleForContext(job, context) && job?.state?.status === "pending");
|
|
13063
13098
|
}
|
|
13064
13099
|
findPendingJobForContext(context, jobId = "") {
|
|
13065
|
-
const normalized =
|
|
13100
|
+
const normalized = normalize18(jobId);
|
|
13066
13101
|
if (!normalized) {
|
|
13067
13102
|
return null;
|
|
13068
13103
|
}
|
|
13069
|
-
return this.listPendingJobs(context).find((job) =>
|
|
13104
|
+
return this.listPendingJobs(context).find((job) => normalize18(job?.id) === normalized) || null;
|
|
13070
13105
|
}
|
|
13071
13106
|
isVisibleForContext(job, context) {
|
|
13072
|
-
const requesterUserId =
|
|
13073
|
-
const chatId =
|
|
13074
|
-
const chatType =
|
|
13107
|
+
const requesterUserId = normalize18(context.requesterUserId);
|
|
13108
|
+
const chatId = normalize18(context.chatId);
|
|
13109
|
+
const chatType = normalize18(context.chatType).toLowerCase();
|
|
13075
13110
|
if (chatType === "p2p") {
|
|
13076
|
-
return
|
|
13111
|
+
return normalize18(job?.requesterUserId) === requesterUserId && normalize18(job?.delivery?.chatId) === chatId;
|
|
13077
13112
|
}
|
|
13078
|
-
return
|
|
13113
|
+
return normalize18(job?.requesterUserId) === requesterUserId && normalize18(job?.delivery?.chatId) === chatId;
|
|
13079
13114
|
}
|
|
13080
13115
|
scheduleNext() {
|
|
13081
13116
|
if (!this.running) {
|
|
@@ -13111,9 +13146,9 @@ var ReminderService = class {
|
|
|
13111
13146
|
this.scheduleNext();
|
|
13112
13147
|
}
|
|
13113
13148
|
async executeJob(job) {
|
|
13114
|
-
const traceId =
|
|
13149
|
+
const traceId = normalize18(job?.traceId || job?.messageId || job?.id);
|
|
13115
13150
|
try {
|
|
13116
|
-
const actionKind =
|
|
13151
|
+
const actionKind = normalize18(job?.action?.kind);
|
|
13117
13152
|
if (actionKind === "notify") {
|
|
13118
13153
|
await this.sendNotify(job);
|
|
13119
13154
|
} else if (actionKind === "agent_turn") {
|
|
@@ -13137,7 +13172,7 @@ var ReminderService = class {
|
|
|
13137
13172
|
this.logger.info(formatTraceLog(traceId, `\u63D0\u9192\u5DF2\u89E6\u53D1: job_id=${job.id}, chat_id=${job?.delivery?.chatId || "-"}, chat_type=${job?.delivery?.chatType || "-"}`));
|
|
13138
13173
|
} catch (error) {
|
|
13139
13174
|
const message = error instanceof Error ? error.message : String(error);
|
|
13140
|
-
if (
|
|
13175
|
+
if (normalize18(job?.action?.kind) === "agent_turn") {
|
|
13141
13176
|
try {
|
|
13142
13177
|
await this.sendAgentTurnFailure(job, message);
|
|
13143
13178
|
} catch (notifyError) {
|
|
@@ -13161,7 +13196,7 @@ var ReminderService = class {
|
|
|
13161
13196
|
});
|
|
13162
13197
|
}
|
|
13163
13198
|
async sendNotify(job) {
|
|
13164
|
-
const chatId =
|
|
13199
|
+
const chatId = normalize18(job?.delivery?.chatId);
|
|
13165
13200
|
if (!chatId) {
|
|
13166
13201
|
throw new Error("\u63D0\u9192\u7F3A\u5C11 chat_id");
|
|
13167
13202
|
}
|
|
@@ -13175,7 +13210,7 @@ var ReminderService = class {
|
|
|
13175
13210
|
});
|
|
13176
13211
|
}
|
|
13177
13212
|
async sendAgentTurnResult(job, resultText = "") {
|
|
13178
|
-
const chatId =
|
|
13213
|
+
const chatId = normalize18(job?.delivery?.chatId);
|
|
13179
13214
|
if (!chatId) {
|
|
13180
13215
|
throw new Error("\u5B9A\u65F6\u4EFB\u52A1\u7F3A\u5C11 chat_id");
|
|
13181
13216
|
}
|
|
@@ -13189,7 +13224,7 @@ var ReminderService = class {
|
|
|
13189
13224
|
});
|
|
13190
13225
|
}
|
|
13191
13226
|
async sendAgentTurnFailure(job, error = "") {
|
|
13192
|
-
const chatId =
|
|
13227
|
+
const chatId = normalize18(job?.delivery?.chatId);
|
|
13193
13228
|
if (!chatId) {
|
|
13194
13229
|
throw new Error("\u5B9A\u65F6\u4EFB\u52A1\u7F3A\u5C11 chat_id");
|
|
13195
13230
|
}
|
|
@@ -13207,32 +13242,6 @@ var ReminderService = class {
|
|
|
13207
13242
|
// src/hook/persona/requester-persona-service.ts
|
|
13208
13243
|
import fs25 from "fs";
|
|
13209
13244
|
import path24 from "path";
|
|
13210
|
-
function normalize20(value) {
|
|
13211
|
-
if (value === null || value === void 0) {
|
|
13212
|
-
return "";
|
|
13213
|
-
}
|
|
13214
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
13215
|
-
return String(value).trim();
|
|
13216
|
-
}
|
|
13217
|
-
return "";
|
|
13218
|
-
}
|
|
13219
|
-
function resolveDisplayName2(value) {
|
|
13220
|
-
const direct = normalize20(value);
|
|
13221
|
-
if (direct) {
|
|
13222
|
-
return direct;
|
|
13223
|
-
}
|
|
13224
|
-
if (!value || typeof value !== "object") {
|
|
13225
|
-
return "";
|
|
13226
|
-
}
|
|
13227
|
-
const candidateKeys = ["zh_cn", "zh-CN", "zh_hans", "zh", "en_us", "en-US", "en", "name", "value"];
|
|
13228
|
-
for (const key of candidateKeys) {
|
|
13229
|
-
const text = normalize20(value?.[key]);
|
|
13230
|
-
if (text) {
|
|
13231
|
-
return text;
|
|
13232
|
-
}
|
|
13233
|
-
}
|
|
13234
|
-
return "";
|
|
13235
|
-
}
|
|
13236
13245
|
function pickUserData2(response) {
|
|
13237
13246
|
const data = response?.data || {};
|
|
13238
13247
|
const user = data?.user || data?.data?.user || data?.items?.[0] || data?.item || {};
|
|
@@ -13310,8 +13319,8 @@ var RequesterPersonaService = class {
|
|
|
13310
13319
|
}
|
|
13311
13320
|
}
|
|
13312
13321
|
buildCacheKey(userId = "", openId = "") {
|
|
13313
|
-
const normalizedUserId =
|
|
13314
|
-
const normalizedOpenId =
|
|
13322
|
+
const normalizedUserId = normalizeText(userId);
|
|
13323
|
+
const normalizedOpenId = normalizeText(openId);
|
|
13315
13324
|
if (normalizedUserId) {
|
|
13316
13325
|
return `user_id:${normalizedUserId}`;
|
|
13317
13326
|
}
|
|
@@ -13350,8 +13359,8 @@ var RequesterPersonaService = class {
|
|
|
13350
13359
|
return null;
|
|
13351
13360
|
}
|
|
13352
13361
|
const attempts = [];
|
|
13353
|
-
const normalizedUserId =
|
|
13354
|
-
const normalizedOpenId =
|
|
13362
|
+
const normalizedUserId = normalizeText(userId);
|
|
13363
|
+
const normalizedOpenId = normalizeText(openId);
|
|
13355
13364
|
if (normalizedUserId) {
|
|
13356
13365
|
attempts.push({
|
|
13357
13366
|
path: { user_id: normalizedUserId },
|
|
@@ -13387,7 +13396,7 @@ var RequesterPersonaService = class {
|
|
|
13387
13396
|
return null;
|
|
13388
13397
|
}
|
|
13389
13398
|
async tryFetchJobLevelName(jobLevelId = "") {
|
|
13390
|
-
const normalizedJobLevelId =
|
|
13399
|
+
const normalizedJobLevelId = normalizeText(jobLevelId);
|
|
13391
13400
|
if (!normalizedJobLevelId || !this.jobLevelNameLookupEnabled) {
|
|
13392
13401
|
return "";
|
|
13393
13402
|
}
|
|
@@ -13403,7 +13412,7 @@ var RequesterPersonaService = class {
|
|
|
13403
13412
|
return "";
|
|
13404
13413
|
}
|
|
13405
13414
|
const jobLevel = pickJobLevelData(response);
|
|
13406
|
-
return
|
|
13415
|
+
return resolveDisplayName(jobLevel.name) || resolveDisplayName(jobLevel.i18n_name) || normalizeText(jobLevel.code || "");
|
|
13407
13416
|
} catch (error) {
|
|
13408
13417
|
const errorCode = error?.response?.data?.code || error?.code || "";
|
|
13409
13418
|
if ((String(errorCode) === "99991672" || String(error?.message || "").includes("Access denied")) && !this.jobLevelPermissionDeniedLogged) {
|
|
@@ -13415,14 +13424,14 @@ var RequesterPersonaService = class {
|
|
|
13415
13424
|
}
|
|
13416
13425
|
}
|
|
13417
13426
|
resolveRoleConfig(jobLevelId = "") {
|
|
13418
|
-
const normalizedJobLevelId =
|
|
13427
|
+
const normalizedJobLevelId = normalizeText(jobLevelId);
|
|
13419
13428
|
if (!normalizedJobLevelId) {
|
|
13420
13429
|
return { roleKey: "", roleConfig: null };
|
|
13421
13430
|
}
|
|
13422
13431
|
const roles = this.rules?.roles || {};
|
|
13423
13432
|
for (const [roleKey, roleConfig] of Object.entries(roles)) {
|
|
13424
13433
|
const ids = Array.isArray(roleConfig?.jobLevelIds) ? roleConfig.jobLevelIds : [];
|
|
13425
|
-
if (ids.map((item) =>
|
|
13434
|
+
if (ids.map((item) => normalizeText(item)).includes(normalizedJobLevelId)) {
|
|
13426
13435
|
return { roleKey, roleConfig };
|
|
13427
13436
|
}
|
|
13428
13437
|
}
|
|
@@ -13438,12 +13447,12 @@ var RequesterPersonaService = class {
|
|
|
13438
13447
|
return "";
|
|
13439
13448
|
}
|
|
13440
13449
|
const lines = [
|
|
13441
|
-
`- \u63D0\u95EE\u8005\u89D2\u8272: ${
|
|
13442
|
-
`- \u63D0\u95EE\u8005 user_id: ${
|
|
13443
|
-
`- \u63D0\u95EE\u8005\u59D3\u540D: ${
|
|
13444
|
-
`- \u63D0\u95EE\u8005\u804C\u7EA7ID: ${
|
|
13450
|
+
`- \u63D0\u95EE\u8005\u89D2\u8272: ${normalizeText(roleConfig.label) || roleKey}`,
|
|
13451
|
+
`- \u63D0\u95EE\u8005 user_id: ${normalizeText(record.userId) || "-"}`,
|
|
13452
|
+
`- \u63D0\u95EE\u8005\u59D3\u540D: ${normalizeText(record.name) || "-"}`,
|
|
13453
|
+
`- \u63D0\u95EE\u8005\u804C\u7EA7ID: ${normalizeText(record.jobLevelId) || "-"}`
|
|
13445
13454
|
];
|
|
13446
|
-
const jobLevelName =
|
|
13455
|
+
const jobLevelName = normalizeText(record.jobLevelName);
|
|
13447
13456
|
if (jobLevelName) {
|
|
13448
13457
|
lines.push(`- \u63D0\u95EE\u8005\u804C\u7EA7\u540D\u79F0: ${jobLevelName}`);
|
|
13449
13458
|
}
|
|
@@ -13457,12 +13466,12 @@ var RequesterPersonaService = class {
|
|
|
13457
13466
|
}
|
|
13458
13467
|
buildRecord({ cached = null, user = null, identity = null, jobLevelName = "" } = {}) {
|
|
13459
13468
|
const requester = identity?.requester || {};
|
|
13460
|
-
const userId =
|
|
13461
|
-
const openId =
|
|
13462
|
-
const name =
|
|
13463
|
-
const email =
|
|
13464
|
-
const jobLevelId =
|
|
13465
|
-
const nextJobLevelName =
|
|
13469
|
+
const userId = normalizeText(user?.user_id || cached?.userId || requester?.userId || "");
|
|
13470
|
+
const openId = normalizeText(user?.open_id || cached?.openId || requester?.openId || "");
|
|
13471
|
+
const name = resolveDisplayName(user?.name) || resolveDisplayName(user?.en_name) || normalizeText(cached?.name || requester?.name || "");
|
|
13472
|
+
const email = normalizeText(user?.email || cached?.email || requester?.email || "");
|
|
13473
|
+
const jobLevelId = normalizeText(user?.job_level_id || cached?.jobLevelId || "");
|
|
13474
|
+
const nextJobLevelName = normalizeText(jobLevelName || cached?.jobLevelName || "");
|
|
13466
13475
|
const { roleKey, roleConfig } = this.resolveRoleConfig(jobLevelId);
|
|
13467
13476
|
const now = Date.now();
|
|
13468
13477
|
return {
|
|
@@ -13473,18 +13482,18 @@ var RequesterPersonaService = class {
|
|
|
13473
13482
|
jobLevelId,
|
|
13474
13483
|
jobLevelName: nextJobLevelName,
|
|
13475
13484
|
personaRole: roleKey,
|
|
13476
|
-
personaLabel:
|
|
13485
|
+
personaLabel: normalizeText(roleConfig?.label || ""),
|
|
13477
13486
|
updatedAt: now,
|
|
13478
13487
|
expiresAt: now + this.cacheTtlMs
|
|
13479
13488
|
};
|
|
13480
13489
|
}
|
|
13481
13490
|
logUnmatchedJobLevel(jobLevelId = "", userId = "") {
|
|
13482
|
-
const normalizedJobLevelId =
|
|
13491
|
+
const normalizedJobLevelId = normalizeText(jobLevelId);
|
|
13483
13492
|
if (!normalizedJobLevelId || this.loggedUnknownJobLevelIds.has(normalizedJobLevelId)) {
|
|
13484
13493
|
return;
|
|
13485
13494
|
}
|
|
13486
13495
|
this.loggedUnknownJobLevelIds.add(normalizedJobLevelId);
|
|
13487
|
-
this.logger.info(`\u63D0\u95EE\u8005\u753B\u50CF\u672A\u547D\u4E2D\u6620\u5C04: user_id=${
|
|
13496
|
+
this.logger.info(`\u63D0\u95EE\u8005\u753B\u50CF\u672A\u547D\u4E2D\u6620\u5C04: user_id=${normalizeText(userId) || "-"}, job_level_id=${normalizedJobLevelId}`);
|
|
13488
13497
|
}
|
|
13489
13498
|
async resolveRequesterPersona({
|
|
13490
13499
|
chatType = "",
|
|
@@ -13492,11 +13501,11 @@ var RequesterPersonaService = class {
|
|
|
13492
13501
|
senderOpenId = "",
|
|
13493
13502
|
identity = null
|
|
13494
13503
|
} = {}) {
|
|
13495
|
-
if (
|
|
13504
|
+
if (normalizeText(chatType).toLowerCase() !== "group") {
|
|
13496
13505
|
return null;
|
|
13497
13506
|
}
|
|
13498
|
-
const normalizedUserId =
|
|
13499
|
-
const normalizedOpenId =
|
|
13507
|
+
const normalizedUserId = normalizeText(senderUserId);
|
|
13508
|
+
const normalizedOpenId = normalizeText(senderOpenId);
|
|
13500
13509
|
if (!normalizedUserId && !normalizedOpenId) {
|
|
13501
13510
|
return null;
|
|
13502
13511
|
}
|
|
@@ -13522,7 +13531,7 @@ var RequesterPersonaService = class {
|
|
|
13522
13531
|
if (!user) {
|
|
13523
13532
|
return null;
|
|
13524
13533
|
}
|
|
13525
|
-
const jobLevelId =
|
|
13534
|
+
const jobLevelId = normalizeText(user?.job_level_id || "");
|
|
13526
13535
|
let jobLevelName = "";
|
|
13527
13536
|
if (jobLevelId) {
|
|
13528
13537
|
jobLevelName = await this.tryFetchJobLevelName(jobLevelId);
|
|
@@ -13687,17 +13696,8 @@ function buildWorkerState(options) {
|
|
|
13687
13696
|
}
|
|
13688
13697
|
|
|
13689
13698
|
// src/hook/worker/worker-owner-resolver.ts
|
|
13690
|
-
function normalize21(value) {
|
|
13691
|
-
if (value === null || value === void 0) {
|
|
13692
|
-
return "";
|
|
13693
|
-
}
|
|
13694
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
13695
|
-
return String(value).trim();
|
|
13696
|
-
}
|
|
13697
|
-
return "";
|
|
13698
|
-
}
|
|
13699
13699
|
function lower2(value) {
|
|
13700
|
-
return
|
|
13700
|
+
return normalizeText(value).toLowerCase();
|
|
13701
13701
|
}
|
|
13702
13702
|
function buildEmailFromUser(user = "") {
|
|
13703
13703
|
const normalizedUser = lower2(user);
|
|
@@ -13706,42 +13706,13 @@ function buildEmailFromUser(user = "") {
|
|
|
13706
13706
|
}
|
|
13707
13707
|
return normalizedUser.includes("@") ? normalizedUser : `${normalizedUser}@hstong.com`;
|
|
13708
13708
|
}
|
|
13709
|
-
function resolveDisplayName3(value) {
|
|
13710
|
-
const direct = normalize21(value);
|
|
13711
|
-
if (direct) {
|
|
13712
|
-
return direct;
|
|
13713
|
-
}
|
|
13714
|
-
if (!value || typeof value !== "object") {
|
|
13715
|
-
return "";
|
|
13716
|
-
}
|
|
13717
|
-
const candidateKeys = [
|
|
13718
|
-
"zh_cn",
|
|
13719
|
-
"zh-CN",
|
|
13720
|
-
"zh_hans",
|
|
13721
|
-
"zh",
|
|
13722
|
-
"en_us",
|
|
13723
|
-
"en-US",
|
|
13724
|
-
"en",
|
|
13725
|
-
"name",
|
|
13726
|
-
"display_name",
|
|
13727
|
-
"full_name",
|
|
13728
|
-
"value"
|
|
13729
|
-
];
|
|
13730
|
-
for (const key of candidateKeys) {
|
|
13731
|
-
const text = normalize21(value[key]);
|
|
13732
|
-
if (text) {
|
|
13733
|
-
return text;
|
|
13734
|
-
}
|
|
13735
|
-
}
|
|
13736
|
-
return "";
|
|
13737
|
-
}
|
|
13738
13709
|
function scoreEntry(entry) {
|
|
13739
13710
|
let score = 0;
|
|
13740
|
-
if (
|
|
13741
|
-
if (
|
|
13742
|
-
if (
|
|
13743
|
-
if (
|
|
13744
|
-
if (
|
|
13711
|
+
if (normalizeText(entry.feishuUserId)) score += 100;
|
|
13712
|
+
if (normalizeText(entry.feishuOpenId)) score += 30;
|
|
13713
|
+
if (normalizeText(entry.email)) score += 20;
|
|
13714
|
+
if (normalizeText(entry.user)) score += 10;
|
|
13715
|
+
if (normalizeText(entry.name)) score += 5;
|
|
13745
13716
|
return score;
|
|
13746
13717
|
}
|
|
13747
13718
|
var WorkerOwnerResolver = class {
|
|
@@ -13750,7 +13721,7 @@ var WorkerOwnerResolver = class {
|
|
|
13750
13721
|
identityResolver;
|
|
13751
13722
|
constructor({ logger: logger3, larkClient, opsUserName = "" }) {
|
|
13752
13723
|
this.logger = logger3;
|
|
13753
|
-
this.opsUserName =
|
|
13724
|
+
this.opsUserName = normalizeText(opsUserName);
|
|
13754
13725
|
this.identityResolver = new IdentityResolver({ logger: logger3, larkClient });
|
|
13755
13726
|
}
|
|
13756
13727
|
pickBestEntry(entries = []) {
|
|
@@ -13768,7 +13739,7 @@ var WorkerOwnerResolver = class {
|
|
|
13768
13739
|
if (!item || typeof item !== "object" || item.__cacheType) {
|
|
13769
13740
|
return false;
|
|
13770
13741
|
}
|
|
13771
|
-
return lower2(item.user) === ownerKey ||
|
|
13742
|
+
return lower2(item.user) === ownerKey || normalizeText(item.name) === this.opsUserName;
|
|
13772
13743
|
});
|
|
13773
13744
|
return this.pickBestEntry(candidates);
|
|
13774
13745
|
}
|
|
@@ -13796,10 +13767,10 @@ var WorkerOwnerResolver = class {
|
|
|
13796
13767
|
return null;
|
|
13797
13768
|
}
|
|
13798
13769
|
return {
|
|
13799
|
-
user_id:
|
|
13800
|
-
open_id:
|
|
13801
|
-
name:
|
|
13802
|
-
email:
|
|
13770
|
+
user_id: normalizeText(user.user_id),
|
|
13771
|
+
open_id: normalizeText(user.open_id),
|
|
13772
|
+
name: normalizeText(user.name),
|
|
13773
|
+
email: normalizeText(user.email || normalizedEmail)
|
|
13803
13774
|
};
|
|
13804
13775
|
} catch (error) {
|
|
13805
13776
|
const detail = error?.response?.data ? JSON.stringify(error.response.data) : error instanceof Error ? error.message : String(error);
|
|
@@ -13808,8 +13779,8 @@ var WorkerOwnerResolver = class {
|
|
|
13808
13779
|
}
|
|
13809
13780
|
}
|
|
13810
13781
|
async enrichEntryFromEmail(cache, entry) {
|
|
13811
|
-
const baseUser =
|
|
13812
|
-
const candidateEmail =
|
|
13782
|
+
const baseUser = normalizeText(entry?.user) || this.opsUserName;
|
|
13783
|
+
const candidateEmail = normalizeText(entry?.email) || buildEmailFromUser(baseUser);
|
|
13813
13784
|
if (!candidateEmail) {
|
|
13814
13785
|
return null;
|
|
13815
13786
|
}
|
|
@@ -13818,19 +13789,19 @@ var WorkerOwnerResolver = class {
|
|
|
13818
13789
|
return null;
|
|
13819
13790
|
}
|
|
13820
13791
|
let detailedUser = null;
|
|
13821
|
-
if (!
|
|
13792
|
+
if (!normalizeText(larkUser.open_id)) {
|
|
13822
13793
|
detailedUser = await this.identityResolver.fetchUserFromLark(larkUser.user_id, "");
|
|
13823
13794
|
}
|
|
13824
13795
|
this.identityResolver.updateUserCache(cache, {
|
|
13825
|
-
user_id:
|
|
13826
|
-
open_id:
|
|
13827
|
-
name:
|
|
13828
|
-
email:
|
|
13829
|
-
},
|
|
13796
|
+
user_id: normalizeText(detailedUser?.user_id || larkUser.user_id),
|
|
13797
|
+
open_id: normalizeText(detailedUser?.open_id || larkUser.open_id),
|
|
13798
|
+
name: normalizeText(detailedUser?.name || larkUser.name || entry?.name),
|
|
13799
|
+
email: normalizeText(detailedUser?.email || larkUser.email || candidateEmail)
|
|
13800
|
+
}, normalizeText(detailedUser?.user_id || larkUser.user_id), normalizeText(detailedUser?.open_id || larkUser.open_id));
|
|
13830
13801
|
this.identityResolver.saveCache();
|
|
13831
13802
|
const refreshed = this.findOwnerEntry(cache);
|
|
13832
13803
|
if (refreshed) {
|
|
13833
|
-
this.logger.info(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u5DF2\u6309\u90AE\u7BB1\u8865\u9F50: ops_user=${this.opsUserName}, email=${candidateEmail}, owner_user_id=${
|
|
13804
|
+
this.logger.info(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u5DF2\u6309\u90AE\u7BB1\u8865\u9F50: ops_user=${this.opsUserName}, email=${candidateEmail}, owner_user_id=${normalizeText(refreshed.feishuUserId) || "-"}`);
|
|
13834
13805
|
}
|
|
13835
13806
|
return refreshed;
|
|
13836
13807
|
}
|
|
@@ -13841,30 +13812,30 @@ var WorkerOwnerResolver = class {
|
|
|
13841
13812
|
}
|
|
13842
13813
|
const cache = this.identityResolver.loadCache();
|
|
13843
13814
|
let entry = this.findOwnerEntry(cache);
|
|
13844
|
-
if (!
|
|
13815
|
+
if (!normalizeText(entry?.feishuUserId) || !normalizeText(entry?.feishuOpenId)) {
|
|
13845
13816
|
entry = await this.enrichEntryFromEmail(cache, entry);
|
|
13846
13817
|
}
|
|
13847
|
-
const ownerUserId =
|
|
13818
|
+
const ownerUserId = normalizeText(entry?.feishuUserId);
|
|
13848
13819
|
if (!ownerUserId) {
|
|
13849
13820
|
this.logger.warn(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u89E3\u6790\u5931\u8D25: ops_user=${this.opsUserName}, reason=missing_feishu_user_id`);
|
|
13850
13821
|
return {
|
|
13851
13822
|
...this.emptyProfile(entry ? "cache_incomplete" : "cache_miss"),
|
|
13852
|
-
ownerDisplayName:
|
|
13853
|
-
ownerOpenId:
|
|
13854
|
-
employeeNo:
|
|
13855
|
-
email:
|
|
13856
|
-
user:
|
|
13823
|
+
ownerDisplayName: resolveDisplayName(entry?.name),
|
|
13824
|
+
ownerOpenId: normalizeText(entry?.feishuOpenId),
|
|
13825
|
+
employeeNo: normalizeText(entry?.uId),
|
|
13826
|
+
email: normalizeText(entry?.email),
|
|
13827
|
+
user: normalizeText(entry?.user)
|
|
13857
13828
|
};
|
|
13858
13829
|
}
|
|
13859
|
-
const ownerDisplayName =
|
|
13830
|
+
const ownerDisplayName = resolveDisplayName(entry?.name) || normalizeText(entry?.user) || this.opsUserName;
|
|
13860
13831
|
this.logger.info(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u89E3\u6790\u6210\u529F: ops_user=${this.opsUserName}, owner_user_id=${ownerUserId}, owner_name=${ownerDisplayName}`);
|
|
13861
13832
|
return {
|
|
13862
13833
|
ownerUserId,
|
|
13863
13834
|
ownerDisplayName,
|
|
13864
|
-
ownerOpenId:
|
|
13865
|
-
employeeNo:
|
|
13866
|
-
email:
|
|
13867
|
-
user:
|
|
13835
|
+
ownerOpenId: normalizeText(entry?.feishuOpenId),
|
|
13836
|
+
employeeNo: normalizeText(entry?.uId),
|
|
13837
|
+
email: normalizeText(entry?.email),
|
|
13838
|
+
user: normalizeText(entry?.user),
|
|
13868
13839
|
opsUserName: this.opsUserName,
|
|
13869
13840
|
source: "cache"
|
|
13870
13841
|
};
|
|
@@ -13890,28 +13861,11 @@ var PERSPECTIVE_RULES = [
|
|
|
13890
13861
|
{ key: "product", label: "\u4EA7\u54C1\u89C6\u89D2", pattern: /产品经理|产品/i },
|
|
13891
13862
|
{ key: "backend", label: "\u540E\u7AEF\u7814\u53D1\u89C6\u89D2", pattern: /java/i }
|
|
13892
13863
|
];
|
|
13893
|
-
function normalize22(value) {
|
|
13894
|
-
if (value === null || value === void 0) {
|
|
13895
|
-
return "";
|
|
13896
|
-
}
|
|
13897
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
13898
|
-
return String(value).trim();
|
|
13899
|
-
}
|
|
13900
|
-
return "";
|
|
13901
|
-
}
|
|
13902
13864
|
function resolveLocalizedText(value) {
|
|
13903
|
-
|
|
13904
|
-
if (direct) {
|
|
13905
|
-
return direct;
|
|
13906
|
-
}
|
|
13907
|
-
if (!value || typeof value !== "object") {
|
|
13908
|
-
return "";
|
|
13909
|
-
}
|
|
13910
|
-
const record = value;
|
|
13911
|
-
return normalize22(record.default_value) || normalize22(record.i18n_value?.zh_cn) || normalize22(record.i18n_value?.en_us);
|
|
13865
|
+
return resolveDisplayName(value);
|
|
13912
13866
|
}
|
|
13913
13867
|
function resolvePerspectiveByJobTitle(jobTitle = "") {
|
|
13914
|
-
const matched = PERSPECTIVE_RULES.find((rule) => rule.pattern.test(
|
|
13868
|
+
const matched = PERSPECTIVE_RULES.find((rule) => rule.pattern.test(normalizeText(jobTitle)));
|
|
13915
13869
|
return matched ? { perspectiveKey: matched.key, perspectiveLabel: matched.label } : { perspectiveKey: "general", perspectiveLabel: "\u901A\u7528\u89C6\u89D2" };
|
|
13916
13870
|
}
|
|
13917
13871
|
var WorkerPerspectiveResolver = class {
|
|
@@ -13922,7 +13876,7 @@ var WorkerPerspectiveResolver = class {
|
|
|
13922
13876
|
this.larkClient = larkClient;
|
|
13923
13877
|
}
|
|
13924
13878
|
async resolve(ownerProfile) {
|
|
13925
|
-
const ownerOpenId =
|
|
13879
|
+
const ownerOpenId = normalizeText(ownerProfile.ownerOpenId);
|
|
13926
13880
|
if (!ownerOpenId || typeof this.larkClient?.request !== "function") {
|
|
13927
13881
|
return this.buildResult();
|
|
13928
13882
|
}
|
|
@@ -13946,9 +13900,9 @@ var WorkerPerspectiveResolver = class {
|
|
|
13946
13900
|
const jobTitle = employee?.work_info?.job_title || {};
|
|
13947
13901
|
const result = this.buildResult(
|
|
13948
13902
|
resolveLocalizedText(jobTitle.job_title_name),
|
|
13949
|
-
|
|
13903
|
+
normalizeText(jobTitle.job_title_id)
|
|
13950
13904
|
);
|
|
13951
|
-
this.logger.info(`\u5BBF\u4E3B\u804C\u52A1\u89E3\u6790\u5B8C\u6210: owner=${
|
|
13905
|
+
this.logger.info(`\u5BBF\u4E3B\u804C\u52A1\u89E3\u6790\u5B8C\u6210: owner=${normalizeText(ownerProfile.ownerDisplayName) || "-"}, job_title=${result.jobTitle || "-"}, perspective=${result.perspectiveLabel}`);
|
|
13952
13906
|
return result;
|
|
13953
13907
|
} catch (error) {
|
|
13954
13908
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -13958,15 +13912,15 @@ var WorkerPerspectiveResolver = class {
|
|
|
13958
13912
|
}
|
|
13959
13913
|
buildResult(jobTitle = "", jobTitleId = "") {
|
|
13960
13914
|
return {
|
|
13961
|
-
jobTitle:
|
|
13962
|
-
jobTitleId:
|
|
13915
|
+
jobTitle: normalizeText(jobTitle),
|
|
13916
|
+
jobTitleId: normalizeText(jobTitleId),
|
|
13963
13917
|
...resolvePerspectiveByJobTitle(jobTitle)
|
|
13964
13918
|
};
|
|
13965
13919
|
}
|
|
13966
13920
|
};
|
|
13967
13921
|
|
|
13968
13922
|
// src/hook/worker/owner-notify-service.ts
|
|
13969
|
-
function
|
|
13923
|
+
function normalize19(value) {
|
|
13970
13924
|
return String(value || "").trim();
|
|
13971
13925
|
}
|
|
13972
13926
|
var OwnerNotifyService = class {
|
|
@@ -13980,12 +13934,12 @@ var OwnerNotifyService = class {
|
|
|
13980
13934
|
this.ownerProfile = ownerProfile;
|
|
13981
13935
|
}
|
|
13982
13936
|
hasTarget() {
|
|
13983
|
-
return Boolean(
|
|
13937
|
+
return Boolean(normalize19(this.ownerProfile.ownerUserId) || normalize19(this.ownerProfile.ownerOpenId));
|
|
13984
13938
|
}
|
|
13985
13939
|
async sendText(text) {
|
|
13986
13940
|
const content = JSON.stringify({ text: String(text || "").trim() });
|
|
13987
|
-
const userId =
|
|
13988
|
-
const openId =
|
|
13941
|
+
const userId = normalize19(this.ownerProfile.ownerUserId);
|
|
13942
|
+
const openId = normalize19(this.ownerProfile.ownerOpenId);
|
|
13989
13943
|
if (userId) {
|
|
13990
13944
|
return await this.larkClient.im.v1.message.create({
|
|
13991
13945
|
params: { receive_id_type: "user_id" },
|