nikou-cli 0.1.1 → 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/README.md +2 -2
- package/dist/ai-hook.d.ts +1 -0
- package/dist/ai-hook.js +12 -0
- package/dist/chunk-F3EPGM5N.js +25 -0
- package/dist/index.js +415 -447
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
normalizeCliArgs
|
|
4
|
+
} from "./chunk-F3EPGM5N.js";
|
|
2
5
|
|
|
3
6
|
// src/index.ts
|
|
4
7
|
import { Command } from "commander";
|
|
@@ -460,17 +463,17 @@ var TOOL_CONFIG = {
|
|
|
460
463
|
gemini: { filePath: join6(homedir(), ".gemini", "settings.json"), format: "json", jsonPath: ["mcpServers"] },
|
|
461
464
|
opencode: { filePath: join6(homedir(), ".config", "opencode", "opencode.json"), format: "json", jsonPath: ["mcp"] }
|
|
462
465
|
};
|
|
463
|
-
function readJsonFile(
|
|
464
|
-
if (!existsSync5(
|
|
466
|
+
function readJsonFile(path29) {
|
|
467
|
+
if (!existsSync5(path29)) return {};
|
|
465
468
|
try {
|
|
466
|
-
return JSON.parse(readFileSync4(
|
|
469
|
+
return JSON.parse(readFileSync4(path29, "utf-8"));
|
|
467
470
|
} catch {
|
|
468
471
|
return {};
|
|
469
472
|
}
|
|
470
473
|
}
|
|
471
|
-
function writeJsonFile(
|
|
472
|
-
mkdirSync4(dirname2(
|
|
473
|
-
writeFileSync3(
|
|
474
|
+
function writeJsonFile(path29, data) {
|
|
475
|
+
mkdirSync4(dirname2(path29), { recursive: true });
|
|
476
|
+
writeFileSync3(path29, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
474
477
|
}
|
|
475
478
|
function getNestedObj(root, keys) {
|
|
476
479
|
let cur = root;
|
|
@@ -497,10 +500,10 @@ function extractServerFromContent(content, jsonPath) {
|
|
|
497
500
|
return null;
|
|
498
501
|
}
|
|
499
502
|
}
|
|
500
|
-
function readTomlFile(
|
|
501
|
-
if (!existsSync5(
|
|
503
|
+
function readTomlFile(path29) {
|
|
504
|
+
if (!existsSync5(path29)) return "";
|
|
502
505
|
try {
|
|
503
|
-
return readFileSync4(
|
|
506
|
+
return readFileSync4(path29, "utf-8");
|
|
504
507
|
} catch {
|
|
505
508
|
return "";
|
|
506
509
|
}
|
|
@@ -546,9 +549,9 @@ function tomlListServers(toml) {
|
|
|
546
549
|
}
|
|
547
550
|
return results;
|
|
548
551
|
}
|
|
549
|
-
function backupFile(
|
|
550
|
-
if (existsSync5(
|
|
551
|
-
copyFileSync(
|
|
552
|
+
function backupFile(path29) {
|
|
553
|
+
if (existsSync5(path29)) {
|
|
554
|
+
copyFileSync(path29, path29 + ".bak");
|
|
552
555
|
}
|
|
553
556
|
}
|
|
554
557
|
function writeMcpToTool(toolId, serverName, variantContent, force) {
|
|
@@ -1170,6 +1173,24 @@ function safeJsonStringify(payload) {
|
|
|
1170
1173
|
return `{"error":"JSON.stringify failed","reason":"${msg}"}`;
|
|
1171
1174
|
}
|
|
1172
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
|
+
}
|
|
1173
1194
|
function toSingleLineLog(text, maxLength = 600) {
|
|
1174
1195
|
const normalized = String(text || "").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
1175
1196
|
if (normalized.length <= maxLength) return normalized;
|
|
@@ -6306,6 +6327,14 @@ var CodexRunner = class {
|
|
|
6306
6327
|
resolveCodexExecution(args, env = process7.env) {
|
|
6307
6328
|
return resolveCliExecution("codex", args, env);
|
|
6308
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
|
+
}
|
|
6309
6338
|
writePromptToChildStdin(child, prompt, traceMessage = "") {
|
|
6310
6339
|
if (!this.shouldUseStdinPrompt(prompt) || !child?.stdin) {
|
|
6311
6340
|
return;
|
|
@@ -6422,15 +6451,17 @@ var CodexRunner = class {
|
|
|
6422
6451
|
const timer = this.createTimeout(child, resolveTraceId(threadKey, resolvedSessionId, dirPath), reject, "Codex \u6267\u884C\u8D85\u65F6", CODEX_EXEC_TIMEOUT_MS);
|
|
6423
6452
|
child.stdout?.on("data", (chunk) => {
|
|
6424
6453
|
clearTimeout(startupTimer);
|
|
6425
|
-
stdout +=
|
|
6454
|
+
stdout += decodeProcessOutputChunk(chunk);
|
|
6426
6455
|
});
|
|
6427
6456
|
child.stderr?.on("data", (chunk) => {
|
|
6428
|
-
stderr +=
|
|
6457
|
+
stderr += decodeProcessOutputChunk(chunk);
|
|
6429
6458
|
});
|
|
6430
6459
|
child.on("error", (error) => {
|
|
6431
6460
|
clearTimeout(startupTimer);
|
|
6432
6461
|
clearTimeout(timer);
|
|
6433
|
-
reject(error
|
|
6462
|
+
reject(new Error(`${error.message}
|
|
6463
|
+
cwd=${dirPath || "-"}
|
|
6464
|
+
command=${execConfig.displayCommand}`));
|
|
6434
6465
|
});
|
|
6435
6466
|
child.on("close", (code) => {
|
|
6436
6467
|
clearTimeout(startupTimer);
|
|
@@ -6448,8 +6479,7 @@ var CodexRunner = class {
|
|
|
6448
6479
|
this.stateManager.markCodexRun(dirPath);
|
|
6449
6480
|
}
|
|
6450
6481
|
if (code !== 0) {
|
|
6451
|
-
|
|
6452
|
-
reject(new Error(err));
|
|
6482
|
+
reject(new Error(this.buildFailureMessage(stderr, stdout, code, dirPath, execConfig.displayCommand)));
|
|
6453
6483
|
return;
|
|
6454
6484
|
}
|
|
6455
6485
|
resolve3({
|
|
@@ -6555,13 +6585,13 @@ var CodexRunner = class {
|
|
|
6555
6585
|
};
|
|
6556
6586
|
child.stdout?.on("data", (chunk) => {
|
|
6557
6587
|
clearTimeout(startupTimer);
|
|
6558
|
-
const text =
|
|
6588
|
+
const text = decodeProcessOutputChunk(chunk);
|
|
6559
6589
|
stdout += text;
|
|
6560
6590
|
pending += text;
|
|
6561
6591
|
consumeLines();
|
|
6562
6592
|
});
|
|
6563
6593
|
child.stderr?.on("data", (chunk) => {
|
|
6564
|
-
const text =
|
|
6594
|
+
const text = decodeProcessOutputChunk(chunk);
|
|
6565
6595
|
stderr += text;
|
|
6566
6596
|
text.split(/\r?\n/).forEach((line) => {
|
|
6567
6597
|
if (line.trim() && !shouldIgnoreStderrLine(line)) {
|
|
@@ -6575,7 +6605,9 @@ var CodexRunner = class {
|
|
|
6575
6605
|
if (taskKey) {
|
|
6576
6606
|
this.activeChildrenByTaskId.delete(taskKey);
|
|
6577
6607
|
}
|
|
6578
|
-
reject(error
|
|
6608
|
+
reject(new Error(`${error.message}
|
|
6609
|
+
cwd=${dirPath || "-"}
|
|
6610
|
+
command=${execConfig.displayCommand}`));
|
|
6579
6611
|
});
|
|
6580
6612
|
child.on("close", (code) => {
|
|
6581
6613
|
clearTimeout(startupTimer);
|
|
@@ -6628,8 +6660,7 @@ var CodexRunner = class {
|
|
|
6628
6660
|
this.stateManager.markCodexRun(dirPath);
|
|
6629
6661
|
}
|
|
6630
6662
|
if (code !== 0) {
|
|
6631
|
-
|
|
6632
|
-
reject(new Error(err));
|
|
6663
|
+
reject(new Error(this.buildFailureMessage(stderr, stdout, code, dirPath, execConfig.displayCommand)));
|
|
6633
6664
|
return;
|
|
6634
6665
|
}
|
|
6635
6666
|
resolve3({
|
|
@@ -6646,10 +6677,10 @@ var CodexRunner = class {
|
|
|
6646
6677
|
import fs12 from "fs";
|
|
6647
6678
|
import os5 from "os";
|
|
6648
6679
|
import path11 from "path";
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
function
|
|
6652
|
-
if (value
|
|
6680
|
+
|
|
6681
|
+
// src/hook/display-name.ts
|
|
6682
|
+
function normalizeText(value) {
|
|
6683
|
+
if (value === null || value === void 0) {
|
|
6653
6684
|
return "";
|
|
6654
6685
|
}
|
|
6655
6686
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
@@ -6657,24 +6688,15 @@ function normalize6(value) {
|
|
|
6657
6688
|
}
|
|
6658
6689
|
return "";
|
|
6659
6690
|
}
|
|
6660
|
-
function lower(value) {
|
|
6661
|
-
return normalize6(value).toLowerCase();
|
|
6662
|
-
}
|
|
6663
|
-
function extractUserFromEmail(email) {
|
|
6664
|
-
const normalizedEmail = lower(email);
|
|
6665
|
-
if (!normalizedEmail.includes("@")) {
|
|
6666
|
-
return "";
|
|
6667
|
-
}
|
|
6668
|
-
return normalizedEmail.split("@")[0] || "";
|
|
6669
|
-
}
|
|
6670
6691
|
function resolveDisplayName(value) {
|
|
6671
|
-
const direct =
|
|
6692
|
+
const direct = normalizeText(value);
|
|
6672
6693
|
if (direct) {
|
|
6673
6694
|
return direct;
|
|
6674
6695
|
}
|
|
6675
6696
|
if (!value || typeof value !== "object") {
|
|
6676
6697
|
return "";
|
|
6677
6698
|
}
|
|
6699
|
+
const record = value;
|
|
6678
6700
|
const candidateKeys = [
|
|
6679
6701
|
"zh_cn",
|
|
6680
6702
|
"zh-CN",
|
|
@@ -6686,15 +6708,30 @@ function resolveDisplayName(value) {
|
|
|
6686
6708
|
"name",
|
|
6687
6709
|
"display_name",
|
|
6688
6710
|
"full_name",
|
|
6689
|
-
"value"
|
|
6711
|
+
"value",
|
|
6712
|
+
"default_value"
|
|
6690
6713
|
];
|
|
6691
6714
|
for (const key of candidateKeys) {
|
|
6692
|
-
const text =
|
|
6715
|
+
const text = normalizeText(record[key]);
|
|
6693
6716
|
if (text) {
|
|
6694
6717
|
return text;
|
|
6695
6718
|
}
|
|
6696
6719
|
}
|
|
6697
|
-
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] || "";
|
|
6698
6735
|
}
|
|
6699
6736
|
function pickUserData(response) {
|
|
6700
6737
|
const data = response?.data || {};
|
|
@@ -6718,7 +6755,7 @@ function hasUserProfileData(entry) {
|
|
|
6718
6755
|
if (!entry || typeof entry !== "object") {
|
|
6719
6756
|
return false;
|
|
6720
6757
|
}
|
|
6721
|
-
return Boolean(
|
|
6758
|
+
return Boolean(normalizeText(entry.name) || normalizeText(entry.user) || normalizeText(entry.email));
|
|
6722
6759
|
}
|
|
6723
6760
|
var IdentityResolver = class {
|
|
6724
6761
|
logger;
|
|
@@ -6732,36 +6769,36 @@ var IdentityResolver = class {
|
|
|
6732
6769
|
this.cachePath = VOPS_USER_CACHE_PATH2;
|
|
6733
6770
|
}
|
|
6734
6771
|
setTraceId(traceId = "") {
|
|
6735
|
-
this.currentTraceId =
|
|
6772
|
+
this.currentTraceId = normalizeText(traceId) || "-";
|
|
6736
6773
|
}
|
|
6737
6774
|
trace(message) {
|
|
6738
6775
|
return formatTraceLog(this.currentTraceId, message);
|
|
6739
6776
|
}
|
|
6740
6777
|
scoreUserRecord(record) {
|
|
6741
6778
|
let score = 0;
|
|
6742
|
-
if (
|
|
6743
|
-
if (
|
|
6744
|
-
if (
|
|
6745
|
-
if (
|
|
6746
|
-
if (
|
|
6747
|
-
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;
|
|
6748
6785
|
return score;
|
|
6749
6786
|
}
|
|
6750
6787
|
mergeUserRecord(base, extra) {
|
|
6751
6788
|
const merged = { ...base };
|
|
6752
6789
|
const fields = ["uId", "name", "feishuUserId", "feishuOpenId", "feishuProjectUser", "user", "email"];
|
|
6753
6790
|
for (const field of fields) {
|
|
6754
|
-
const baseValue =
|
|
6755
|
-
const extraValue =
|
|
6791
|
+
const baseValue = normalizeText(merged[field]);
|
|
6792
|
+
const extraValue = normalizeText(extra?.[field]);
|
|
6756
6793
|
if (!baseValue && extraValue) {
|
|
6757
6794
|
merged[field] = extraValue;
|
|
6758
6795
|
}
|
|
6759
6796
|
}
|
|
6760
|
-
const baseUpdated =
|
|
6761
|
-
const extraUpdated =
|
|
6797
|
+
const baseUpdated = normalizeText(base?.updatedAt);
|
|
6798
|
+
const extraUpdated = normalizeText(extra?.updatedAt);
|
|
6762
6799
|
merged.updatedAt = baseUpdated && extraUpdated ? baseUpdated >= extraUpdated ? baseUpdated : extraUpdated : baseUpdated || extraUpdated || (/* @__PURE__ */ new Date()).toISOString();
|
|
6763
6800
|
const emailUser = extractUserFromEmail(merged.email);
|
|
6764
|
-
if (!
|
|
6801
|
+
if (!normalizeText(merged.user) && emailUser) {
|
|
6765
6802
|
merged.user = emailUser;
|
|
6766
6803
|
}
|
|
6767
6804
|
return merged;
|
|
@@ -6779,8 +6816,8 @@ var IdentityResolver = class {
|
|
|
6779
6816
|
chatEntries.push(row);
|
|
6780
6817
|
continue;
|
|
6781
6818
|
}
|
|
6782
|
-
const normalizedEmail =
|
|
6783
|
-
const normalizedUser =
|
|
6819
|
+
const normalizedEmail = normalizeText(row.email);
|
|
6820
|
+
const normalizedUser = normalizeText(row.user) || extractUserFromEmail(normalizedEmail);
|
|
6784
6821
|
row.email = normalizedEmail;
|
|
6785
6822
|
row.user = lower(normalizedUser);
|
|
6786
6823
|
userEntries.push(row);
|
|
@@ -6805,28 +6842,28 @@ var IdentityResolver = class {
|
|
|
6805
6842
|
const userRecords = Array.from(byUser.values());
|
|
6806
6843
|
const userNameCount = /* @__PURE__ */ new Map();
|
|
6807
6844
|
userRecords.forEach((item) => {
|
|
6808
|
-
const nameKey =
|
|
6845
|
+
const nameKey = normalizeText(item.name);
|
|
6809
6846
|
if (nameKey) {
|
|
6810
6847
|
userNameCount.set(nameKey, (userNameCount.get(nameKey) || 0) + 1);
|
|
6811
6848
|
}
|
|
6812
6849
|
});
|
|
6813
6850
|
const uniqueNameToUser = /* @__PURE__ */ new Map();
|
|
6814
6851
|
userRecords.forEach((item) => {
|
|
6815
|
-
const nameKey =
|
|
6852
|
+
const nameKey = normalizeText(item.name);
|
|
6816
6853
|
if (nameKey && userNameCount.get(nameKey) === 1) {
|
|
6817
6854
|
uniqueNameToUser.set(nameKey, item);
|
|
6818
6855
|
}
|
|
6819
6856
|
});
|
|
6820
6857
|
const byNoUserKey = /* @__PURE__ */ new Map();
|
|
6821
6858
|
for (const record of noUser) {
|
|
6822
|
-
const nameKey =
|
|
6859
|
+
const nameKey = normalizeText(record.name);
|
|
6823
6860
|
const uniqueNameTarget = uniqueNameToUser.get(nameKey);
|
|
6824
6861
|
if (uniqueNameTarget) {
|
|
6825
6862
|
const merged = this.mergeUserRecord(uniqueNameTarget, record);
|
|
6826
6863
|
byUser.set(lower(merged.user || uniqueNameTarget.user || ""), merged);
|
|
6827
6864
|
continue;
|
|
6828
6865
|
}
|
|
6829
|
-
const idKey =
|
|
6866
|
+
const idKey = normalizeText(record.feishuUserId) || normalizeText(record.feishuOpenId) || normalizeText(record.uId) || `${nameKey}#${normalizeText(record.updatedAt)}`;
|
|
6830
6867
|
const existed = byNoUserKey.get(idKey);
|
|
6831
6868
|
if (!existed) {
|
|
6832
6869
|
byNoUserKey.set(idKey, record);
|
|
@@ -6871,25 +6908,25 @@ var IdentityResolver = class {
|
|
|
6871
6908
|
}
|
|
6872
6909
|
}
|
|
6873
6910
|
findUserEntries(cache, { userId, openId }) {
|
|
6874
|
-
const uid =
|
|
6875
|
-
const oid =
|
|
6911
|
+
const uid = normalizeText(userId);
|
|
6912
|
+
const oid = normalizeText(openId);
|
|
6876
6913
|
return (cache || []).filter((item) => {
|
|
6877
6914
|
if (!item || typeof item !== "object" || item.__cacheType === CHAT_CACHE_TYPE) {
|
|
6878
6915
|
return false;
|
|
6879
6916
|
}
|
|
6880
|
-
return uid &&
|
|
6917
|
+
return uid && normalizeText(item.feishuUserId) === uid || oid && normalizeText(item.feishuOpenId) === oid;
|
|
6881
6918
|
});
|
|
6882
6919
|
}
|
|
6883
6920
|
findChatCache(cache, chatId) {
|
|
6884
|
-
const cid =
|
|
6921
|
+
const cid = normalizeText(chatId);
|
|
6885
6922
|
if (!cid) {
|
|
6886
6923
|
return null;
|
|
6887
6924
|
}
|
|
6888
|
-
return cache.find((item) => item.__cacheType === CHAT_CACHE_TYPE &&
|
|
6925
|
+
return cache.find((item) => item.__cacheType === CHAT_CACHE_TYPE && normalizeText(item.chatId) === cid) || null;
|
|
6889
6926
|
}
|
|
6890
6927
|
patchRequesterOpenId(cache, { userId = "", openId = "" } = {}) {
|
|
6891
|
-
const uid =
|
|
6892
|
-
const oid =
|
|
6928
|
+
const uid = normalizeText(userId);
|
|
6929
|
+
const oid = normalizeText(openId);
|
|
6893
6930
|
if (!uid || !oid) {
|
|
6894
6931
|
return false;
|
|
6895
6932
|
}
|
|
@@ -6898,7 +6935,7 @@ var IdentityResolver = class {
|
|
|
6898
6935
|
if (!item || typeof item !== "object" || item.__cacheType === CHAT_CACHE_TYPE) {
|
|
6899
6936
|
return;
|
|
6900
6937
|
}
|
|
6901
|
-
if (
|
|
6938
|
+
if (normalizeText(item.feishuUserId) === uid && !normalizeText(item.feishuOpenId)) {
|
|
6902
6939
|
item.feishuOpenId = oid;
|
|
6903
6940
|
item.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6904
6941
|
changed = true;
|
|
@@ -6907,8 +6944,8 @@ var IdentityResolver = class {
|
|
|
6907
6944
|
return changed;
|
|
6908
6945
|
}
|
|
6909
6946
|
async fetchUserFromLark(userId, openId) {
|
|
6910
|
-
const targetUserId =
|
|
6911
|
-
const targetOpenId =
|
|
6947
|
+
const targetUserId = normalizeText(userId);
|
|
6948
|
+
const targetOpenId = normalizeText(openId);
|
|
6912
6949
|
const userApi = this.larkClient?.contact?.v3?.user?.get;
|
|
6913
6950
|
if (typeof userApi !== "function") {
|
|
6914
6951
|
return null;
|
|
@@ -6937,7 +6974,7 @@ var IdentityResolver = class {
|
|
|
6937
6974
|
return null;
|
|
6938
6975
|
}
|
|
6939
6976
|
async fetchEmployeeFromDirectory(openId) {
|
|
6940
|
-
const oid =
|
|
6977
|
+
const oid = normalizeText(openId);
|
|
6941
6978
|
const request = this.larkClient?.request;
|
|
6942
6979
|
if (!oid || typeof request !== "function") {
|
|
6943
6980
|
return null;
|
|
@@ -6963,10 +7000,10 @@ var IdentityResolver = class {
|
|
|
6963
7000
|
if (!larkUser || typeof larkUser !== "object") {
|
|
6964
7001
|
return;
|
|
6965
7002
|
}
|
|
6966
|
-
const userId =
|
|
6967
|
-
const openId =
|
|
7003
|
+
const userId = normalizeText(larkUser.user_id || larkUser.userId || fallbackUserId);
|
|
7004
|
+
const openId = normalizeText(larkUser.open_id || larkUser.openId || fallbackOpenId);
|
|
6968
7005
|
const name = resolveDisplayName(larkUser.name) || resolveDisplayName(larkUser.display_name) || resolveDisplayName(larkUser.en_name) || resolveDisplayName(larkUser.full_name);
|
|
6969
|
-
const email =
|
|
7006
|
+
const email = normalizeText(larkUser.email);
|
|
6970
7007
|
const emailUser = extractUserFromEmail(email);
|
|
6971
7008
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
6972
7009
|
if (!userId && !openId && !name) {
|
|
@@ -6980,7 +7017,7 @@ var IdentityResolver = class {
|
|
|
6980
7017
|
existing = cache.find((item) => item.__cacheType !== CHAT_CACHE_TYPE && (lower(item.user) === lower(emailUser) || lower(item.email) === lower(email))) || null;
|
|
6981
7018
|
}
|
|
6982
7019
|
if (!existing && name) {
|
|
6983
|
-
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;
|
|
6984
7021
|
}
|
|
6985
7022
|
if (existing) {
|
|
6986
7023
|
existing.name = name || existing.name || "";
|
|
@@ -7007,7 +7044,7 @@ var IdentityResolver = class {
|
|
|
7007
7044
|
});
|
|
7008
7045
|
}
|
|
7009
7046
|
async fetchChatNameFromLark(chatId) {
|
|
7010
|
-
const cid =
|
|
7047
|
+
const cid = normalizeText(chatId);
|
|
7011
7048
|
const chatApi = this.larkClient?.im?.v1?.chat?.get;
|
|
7012
7049
|
if (!cid || typeof chatApi !== "function") {
|
|
7013
7050
|
return "";
|
|
@@ -7030,7 +7067,7 @@ var IdentityResolver = class {
|
|
|
7030
7067
|
return "";
|
|
7031
7068
|
}
|
|
7032
7069
|
async fetchChatMembersFromLark(chatId) {
|
|
7033
|
-
const cid =
|
|
7070
|
+
const cid = normalizeText(chatId);
|
|
7034
7071
|
const api = this.larkClient?.im?.v1?.chatMembers?.get;
|
|
7035
7072
|
if (!cid || typeof api !== "function") {
|
|
7036
7073
|
return [];
|
|
@@ -7055,8 +7092,8 @@ var IdentityResolver = class {
|
|
|
7055
7092
|
}
|
|
7056
7093
|
let changed = false;
|
|
7057
7094
|
for (const member of members) {
|
|
7058
|
-
const userId =
|
|
7059
|
-
const openId =
|
|
7095
|
+
const userId = normalizeText(member.member_id || member.user_id || member.userId);
|
|
7096
|
+
const openId = normalizeText(member.open_id || member.openId);
|
|
7060
7097
|
const name = resolveDisplayName(member.name) || resolveDisplayName(member.display_name) || resolveDisplayName(member.en_name);
|
|
7061
7098
|
if (!userId && !openId && !name) {
|
|
7062
7099
|
continue;
|
|
@@ -7071,8 +7108,8 @@ var IdentityResolver = class {
|
|
|
7071
7108
|
return changed;
|
|
7072
7109
|
}
|
|
7073
7110
|
upsertChatCache(cache, chatId, chatName) {
|
|
7074
|
-
const cid =
|
|
7075
|
-
const cname =
|
|
7111
|
+
const cid = normalizeText(chatId);
|
|
7112
|
+
const cname = normalizeText(chatName);
|
|
7076
7113
|
if (!cid) {
|
|
7077
7114
|
return;
|
|
7078
7115
|
}
|
|
@@ -7091,7 +7128,7 @@ var IdentityResolver = class {
|
|
|
7091
7128
|
}
|
|
7092
7129
|
async resolveRequester({ userId = "", openId = "", chatId = "" } = {}) {
|
|
7093
7130
|
const cache = this.loadCache();
|
|
7094
|
-
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) || "-"}`));
|
|
7095
7132
|
if (this.patchRequesterOpenId(cache, { userId, openId })) {
|
|
7096
7133
|
this.saveCache();
|
|
7097
7134
|
}
|
|
@@ -7099,12 +7136,12 @@ var IdentityResolver = class {
|
|
|
7099
7136
|
if (matchedEntries.length > 0) {
|
|
7100
7137
|
const first = matchedEntries[0] || {};
|
|
7101
7138
|
if (hasUserProfileData(first)) {
|
|
7102
|
-
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) || "-"}`));
|
|
7103
7140
|
return {
|
|
7104
|
-
userId:
|
|
7105
|
-
openId:
|
|
7106
|
-
name: resolveDisplayName(first.name) ||
|
|
7107
|
-
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),
|
|
7108
7145
|
matchedEntries,
|
|
7109
7146
|
from: "cache"
|
|
7110
7147
|
};
|
|
@@ -7114,14 +7151,14 @@ var IdentityResolver = class {
|
|
|
7114
7151
|
if (directoryEmployee) {
|
|
7115
7152
|
const base = directoryEmployee.base_info || directoryEmployee.baseInfo || {};
|
|
7116
7153
|
const dirName = resolveDisplayName(base.name) || resolveDisplayName(directoryEmployee.name);
|
|
7117
|
-
const dirEmail =
|
|
7154
|
+
const dirEmail = normalizeText(base.email || directoryEmployee.email);
|
|
7118
7155
|
if (dirName || dirEmail) {
|
|
7119
|
-
this.updateUserCache(cache, { user_id:
|
|
7156
|
+
this.updateUserCache(cache, { user_id: normalizeText(userId), open_id: normalizeText(openId), name: dirName, email: dirEmail }, userId, openId);
|
|
7120
7157
|
this.saveCache();
|
|
7121
7158
|
return {
|
|
7122
|
-
userId:
|
|
7123
|
-
openId:
|
|
7124
|
-
name: dirName ||
|
|
7159
|
+
userId: normalizeText(userId),
|
|
7160
|
+
openId: normalizeText(openId),
|
|
7161
|
+
name: dirName || normalizeText(userId) || "-",
|
|
7125
7162
|
email: dirEmail,
|
|
7126
7163
|
matchedEntries: this.findUserEntries(cache, { userId, openId }),
|
|
7127
7164
|
from: "directory"
|
|
@@ -7133,21 +7170,21 @@ var IdentityResolver = class {
|
|
|
7133
7170
|
this.updateUserCache(cache, larkUser, userId, openId);
|
|
7134
7171
|
this.saveCache();
|
|
7135
7172
|
const refreshedMatches = this.findUserEntries(cache, {
|
|
7136
|
-
userId:
|
|
7137
|
-
openId:
|
|
7173
|
+
userId: normalizeText(larkUser.user_id || userId),
|
|
7174
|
+
openId: normalizeText(larkUser.open_id || openId)
|
|
7138
7175
|
});
|
|
7139
7176
|
return {
|
|
7140
|
-
userId:
|
|
7141
|
-
openId:
|
|
7142
|
-
name: resolveDisplayName(larkUser.name) ||
|
|
7143
|
-
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),
|
|
7144
7181
|
matchedEntries: refreshedMatches,
|
|
7145
7182
|
from: "lark"
|
|
7146
7183
|
};
|
|
7147
7184
|
}
|
|
7148
7185
|
const members = await this.fetchChatMembersFromLark(chatId);
|
|
7149
7186
|
if (members.length > 0) {
|
|
7150
|
-
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}`));
|
|
7151
7188
|
this.syncChatMembersToCache(cache, members);
|
|
7152
7189
|
this.patchRequesterOpenId(cache, { userId, openId });
|
|
7153
7190
|
this.saveCache();
|
|
@@ -7155,19 +7192,19 @@ var IdentityResolver = class {
|
|
|
7155
7192
|
if (memberMatches.length > 0) {
|
|
7156
7193
|
const first = memberMatches[0] || {};
|
|
7157
7194
|
return {
|
|
7158
|
-
userId:
|
|
7159
|
-
openId:
|
|
7160
|
-
name: resolveDisplayName(first.name) ||
|
|
7161
|
-
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),
|
|
7162
7199
|
matchedEntries: memberMatches,
|
|
7163
7200
|
from: "chat_members"
|
|
7164
7201
|
};
|
|
7165
7202
|
}
|
|
7166
7203
|
}
|
|
7167
7204
|
return {
|
|
7168
|
-
userId:
|
|
7169
|
-
openId:
|
|
7170
|
-
name:
|
|
7205
|
+
userId: normalizeText(userId),
|
|
7206
|
+
openId: normalizeText(openId),
|
|
7207
|
+
name: normalizeText(userId) || "-",
|
|
7171
7208
|
email: "",
|
|
7172
7209
|
matchedEntries: [],
|
|
7173
7210
|
from: "id"
|
|
@@ -7176,16 +7213,16 @@ var IdentityResolver = class {
|
|
|
7176
7213
|
async resolveChat({ chatId = "" } = {}) {
|
|
7177
7214
|
const cache = this.loadCache();
|
|
7178
7215
|
const cached = this.findChatCache(cache, chatId);
|
|
7179
|
-
if (
|
|
7180
|
-
return { chatId:
|
|
7216
|
+
if (normalizeText(cached?.chatName)) {
|
|
7217
|
+
return { chatId: normalizeText(chatId), chatName: normalizeText(cached?.chatName), from: "cache" };
|
|
7181
7218
|
}
|
|
7182
7219
|
const chatName = await this.fetchChatNameFromLark(chatId);
|
|
7183
7220
|
if (chatName) {
|
|
7184
7221
|
this.upsertChatCache(cache, chatId, chatName);
|
|
7185
7222
|
this.saveCache();
|
|
7186
|
-
return { chatId:
|
|
7223
|
+
return { chatId: normalizeText(chatId), chatName, from: "lark" };
|
|
7187
7224
|
}
|
|
7188
|
-
return { chatId:
|
|
7225
|
+
return { chatId: normalizeText(chatId), chatName: normalizeText(chatId) || "-", from: "id" };
|
|
7189
7226
|
}
|
|
7190
7227
|
async resolveConversationIdentity({ senderUserId = "", senderOpenId = "", chatId = "" } = {}) {
|
|
7191
7228
|
const requester = await this.resolveRequester({ userId: senderUserId, openId: senderOpenId, chatId });
|
|
@@ -7248,7 +7285,7 @@ var REQUESTER_PERSONA_RULES = Object.freeze({
|
|
|
7248
7285
|
var OPS_DIR = path12.join(os6.homedir(), "ops");
|
|
7249
7286
|
var NIKOU_PROMPTS_DIR = path12.join(OPS_DIR, "nikou-prompts");
|
|
7250
7287
|
var NIKOU_ROLE_PROMPTS_DIR = path12.join(NIKOU_PROMPTS_DIR, "roles");
|
|
7251
|
-
function
|
|
7288
|
+
function normalizeText2(value) {
|
|
7252
7289
|
return String(value || "").trim();
|
|
7253
7290
|
}
|
|
7254
7291
|
function ensureDir(dirPath) {
|
|
@@ -7316,12 +7353,12 @@ function buildPromptDefinitions() {
|
|
|
7316
7353
|
const roleDefinitions = Object.entries(REQUESTER_PERSONA_RULES.roles).map(([roleKey, roleConfig]) => ({
|
|
7317
7354
|
id: roleKey,
|
|
7318
7355
|
kind: "role",
|
|
7319
|
-
title: `${
|
|
7356
|
+
title: `${normalizeText2(roleConfig.label) || roleKey}\u89D2\u8272\u63D0\u793A\u8BCD`,
|
|
7320
7357
|
path: path12.join(NIKOU_ROLE_PROMPTS_DIR, `${roleKey}.md`),
|
|
7321
7358
|
legacyPaths: [],
|
|
7322
7359
|
defaultContent: Array.isArray(roleConfig.promptLines) ? roleConfig.promptLines.join("\n") : "",
|
|
7323
7360
|
roleKey,
|
|
7324
|
-
roleLabel:
|
|
7361
|
+
roleLabel: normalizeText2(roleConfig.label) || roleKey
|
|
7325
7362
|
}));
|
|
7326
7363
|
return [
|
|
7327
7364
|
{
|
|
@@ -7456,7 +7493,7 @@ var NikouPromptStore = class {
|
|
|
7456
7493
|
});
|
|
7457
7494
|
}
|
|
7458
7495
|
readRolePrompt(roleKey) {
|
|
7459
|
-
const normalizedRoleKey =
|
|
7496
|
+
const normalizedRoleKey = normalizeText2(roleKey);
|
|
7460
7497
|
if (!normalizedRoleKey || !this.definitions.has(normalizedRoleKey)) {
|
|
7461
7498
|
return "";
|
|
7462
7499
|
}
|
|
@@ -7587,9 +7624,9 @@ var MessageReceiveStrategy = class {
|
|
|
7587
7624
|
const message = event?.message || {};
|
|
7588
7625
|
const senderId = this.resolveSenderUserId(eventPayload);
|
|
7589
7626
|
const senderOpenId = this.resolveSenderOpenId(eventPayload);
|
|
7590
|
-
const chatId =
|
|
7591
|
-
const chatType =
|
|
7592
|
-
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);
|
|
7593
7630
|
if (!chatId || !messageId) {
|
|
7594
7631
|
return null;
|
|
7595
7632
|
}
|
|
@@ -7599,12 +7636,12 @@ var MessageReceiveStrategy = class {
|
|
|
7599
7636
|
messageId,
|
|
7600
7637
|
senderId,
|
|
7601
7638
|
senderOpenId,
|
|
7602
|
-
messageType:
|
|
7603
|
-
content:
|
|
7604
|
-
rootId:
|
|
7605
|
-
parentId:
|
|
7606
|
-
threadId:
|
|
7607
|
-
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,
|
|
7608
7645
|
mentions: Array.isArray(message?.mentions) ? message.mentions : []
|
|
7609
7646
|
};
|
|
7610
7647
|
}
|
|
@@ -7674,7 +7711,8 @@ var MessageReceiveStrategy = class {
|
|
|
7674
7711
|
lines.push(`\u6267\u884C\u8EAB\u4EFD: ${resolveOpsUserName()}`);
|
|
7675
7712
|
}
|
|
7676
7713
|
if (includeRequester && identity?.requester) {
|
|
7677
|
-
|
|
7714
|
+
const requesterName = resolveDisplayName(identity.requester.name) || normalizeText(identity.requester.user) || "-";
|
|
7715
|
+
lines.push(`\u63D0\u95EE\u8005: ${requesterName}(${normalizeText(identity.requester.userId) || "-"})`);
|
|
7678
7716
|
if (includeRequesterEmail && identity.requester.email) {
|
|
7679
7717
|
lines.push(`\u63D0\u95EE\u8005\u90AE\u7BB1: ${identity.requester.email}`);
|
|
7680
7718
|
}
|
|
@@ -7683,7 +7721,7 @@ var MessageReceiveStrategy = class {
|
|
|
7683
7721
|
}
|
|
7684
7722
|
}
|
|
7685
7723
|
if (includeChat && identity?.chat) {
|
|
7686
|
-
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) || "-"})`);
|
|
7687
7725
|
}
|
|
7688
7726
|
return lines;
|
|
7689
7727
|
}
|
|
@@ -11084,7 +11122,7 @@ var LocalBrowserWsServer = class {
|
|
|
11084
11122
|
import fs17 from "fs";
|
|
11085
11123
|
import os10 from "os";
|
|
11086
11124
|
import path16 from "path";
|
|
11087
|
-
function
|
|
11125
|
+
function normalize6(value) {
|
|
11088
11126
|
if (value === null || value === void 0) {
|
|
11089
11127
|
return "";
|
|
11090
11128
|
}
|
|
@@ -11097,8 +11135,8 @@ var HostProfileService = class {
|
|
|
11097
11135
|
cachePath;
|
|
11098
11136
|
constructor(options) {
|
|
11099
11137
|
this.logger = options.logger;
|
|
11100
|
-
this.ownerUserId =
|
|
11101
|
-
this.opsUserName =
|
|
11138
|
+
this.ownerUserId = normalize6(options.ownerUserId);
|
|
11139
|
+
this.opsUserName = normalize6(options.opsUserName);
|
|
11102
11140
|
this.cachePath = path16.join(os10.homedir(), "ops", "vops_user.json");
|
|
11103
11141
|
}
|
|
11104
11142
|
/**
|
|
@@ -11108,12 +11146,12 @@ var HostProfileService = class {
|
|
|
11108
11146
|
getProfile() {
|
|
11109
11147
|
const cacheEntry = this.findCacheEntry();
|
|
11110
11148
|
return {
|
|
11111
|
-
name:
|
|
11112
|
-
feishuUserId: this.ownerUserId ||
|
|
11113
|
-
feishuOpenId:
|
|
11114
|
-
employeeNo:
|
|
11115
|
-
email:
|
|
11116
|
-
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),
|
|
11117
11155
|
opsUserName: this.opsUserName,
|
|
11118
11156
|
source: cacheEntry ? "cache" : "fallback"
|
|
11119
11157
|
};
|
|
@@ -11125,11 +11163,11 @@ var HostProfileService = class {
|
|
|
11125
11163
|
try {
|
|
11126
11164
|
const parsed = JSON.parse(fs17.readFileSync(this.cachePath, "utf-8"));
|
|
11127
11165
|
const list = Array.isArray(parsed) ? parsed : [];
|
|
11128
|
-
const byUserId = list.find((item) =>
|
|
11166
|
+
const byUserId = list.find((item) => normalize6(item.feishuUserId) === this.ownerUserId);
|
|
11129
11167
|
if (byUserId) {
|
|
11130
11168
|
return byUserId;
|
|
11131
11169
|
}
|
|
11132
|
-
const byOpsUser = list.find((item) =>
|
|
11170
|
+
const byOpsUser = list.find((item) => normalize6(item.user) === this.opsUserName);
|
|
11133
11171
|
if (byOpsUser) {
|
|
11134
11172
|
return byOpsUser;
|
|
11135
11173
|
}
|
|
@@ -11148,7 +11186,7 @@ import os11 from "os";
|
|
|
11148
11186
|
import path17 from "path";
|
|
11149
11187
|
|
|
11150
11188
|
// src/hook/profile/codex-account-utils.ts
|
|
11151
|
-
function
|
|
11189
|
+
function normalize7(value) {
|
|
11152
11190
|
if (value === null || value === void 0) {
|
|
11153
11191
|
return "";
|
|
11154
11192
|
}
|
|
@@ -11161,7 +11199,7 @@ function compactLine(line) {
|
|
|
11161
11199
|
return stripAnsi2(line).replace(/[│╭╮╰╯]/g, " ").replace(/\s+/g, " ").trim();
|
|
11162
11200
|
}
|
|
11163
11201
|
function pickLine(lines, prefix) {
|
|
11164
|
-
const lowerPrefix =
|
|
11202
|
+
const lowerPrefix = normalize7(prefix).toLowerCase();
|
|
11165
11203
|
return lines.find((item) => compactLine(item).toLowerCase().startsWith(lowerPrefix)) || "";
|
|
11166
11204
|
}
|
|
11167
11205
|
function extractValue(line) {
|
|
@@ -11259,7 +11297,7 @@ function normalizeMonth(monthText) {
|
|
|
11259
11297
|
return monthMap[String(monthText || "").trim().toLowerCase()] || "";
|
|
11260
11298
|
}
|
|
11261
11299
|
function normalizeResetText(raw) {
|
|
11262
|
-
const text =
|
|
11300
|
+
const text = normalize7(raw);
|
|
11263
11301
|
if (!text) {
|
|
11264
11302
|
return "";
|
|
11265
11303
|
}
|
|
@@ -11306,7 +11344,7 @@ function normalizeUsageText(rawText) {
|
|
|
11306
11344
|
return text;
|
|
11307
11345
|
}
|
|
11308
11346
|
function normalizePlan(plan) {
|
|
11309
|
-
const raw =
|
|
11347
|
+
const raw = normalize7(plan).toLowerCase();
|
|
11310
11348
|
if (!raw) {
|
|
11311
11349
|
return "";
|
|
11312
11350
|
}
|
|
@@ -11326,10 +11364,10 @@ function extractAuthState(auth) {
|
|
|
11326
11364
|
}
|
|
11327
11365
|
const tokens = auth.tokens || {};
|
|
11328
11366
|
return {
|
|
11329
|
-
accessToken:
|
|
11330
|
-
idToken:
|
|
11331
|
-
accountId:
|
|
11332
|
-
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)
|
|
11333
11371
|
};
|
|
11334
11372
|
}
|
|
11335
11373
|
function extractAccountInfo(auth) {
|
|
@@ -11337,10 +11375,10 @@ function extractAccountInfo(auth) {
|
|
|
11337
11375
|
const payload = decodeJwtPayload(authState.accessToken || authState.idToken || "");
|
|
11338
11376
|
const profileInfo = payload["https://api.openai.com/profile"] || {};
|
|
11339
11377
|
const authInfo = payload["https://api.openai.com/auth"] || {};
|
|
11340
|
-
const email =
|
|
11341
|
-
const planType =
|
|
11342
|
-
const accountId =
|
|
11343
|
-
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);
|
|
11344
11382
|
const planLabel = normalizePlan(planType);
|
|
11345
11383
|
return {
|
|
11346
11384
|
email,
|
|
@@ -11358,8 +11396,8 @@ function pickRealtimeLimits(payload) {
|
|
|
11358
11396
|
const secondary = rateLimit.secondary_window || null;
|
|
11359
11397
|
const additional = Array.isArray(payload.additional_rate_limits) ? payload.additional_rate_limits : [];
|
|
11360
11398
|
const weeklyCandidate = additional.find((item) => {
|
|
11361
|
-
const feature =
|
|
11362
|
-
const name =
|
|
11399
|
+
const feature = normalize7(item.metered_feature).toLowerCase();
|
|
11400
|
+
const name = normalize7(item.limit_name).toLowerCase();
|
|
11363
11401
|
return feature.includes("weekly") || name.includes("weekly");
|
|
11364
11402
|
}) || additional[0] || null;
|
|
11365
11403
|
const weeklyRateLimit = weeklyCandidate ? (weeklyCandidate.rate_limit || {}).primary_window : secondary;
|
|
@@ -11501,7 +11539,7 @@ var CodexStatusService = class {
|
|
|
11501
11539
|
import fs19 from "fs";
|
|
11502
11540
|
import os12 from "os";
|
|
11503
11541
|
import path18 from "path";
|
|
11504
|
-
function
|
|
11542
|
+
function normalize8(value) {
|
|
11505
11543
|
return String(value || "").trim();
|
|
11506
11544
|
}
|
|
11507
11545
|
function ensureStoreShape(store) {
|
|
@@ -11551,7 +11589,7 @@ function compareProfiles(left, right) {
|
|
|
11551
11589
|
return String(left.alias || "").localeCompare(String(right.alias || ""), "zh-Hans-CN");
|
|
11552
11590
|
}
|
|
11553
11591
|
function isSameAccount(profile, targetAccount, targetState) {
|
|
11554
|
-
const profileAccountId =
|
|
11592
|
+
const profileAccountId = normalize8(profile.account?.accountId);
|
|
11555
11593
|
if (profileAccountId && targetAccount.accountId && profileAccountId === targetAccount.accountId) {
|
|
11556
11594
|
return true;
|
|
11557
11595
|
}
|
|
@@ -11739,11 +11777,11 @@ var CodexAccountService = class {
|
|
|
11739
11777
|
const profiles = refreshedProfiles.sort(compareProfiles).map((profile) => ({
|
|
11740
11778
|
alias: profile.alias,
|
|
11741
11779
|
current: profile.alias === store.current,
|
|
11742
|
-
account:
|
|
11743
|
-
planLabel:
|
|
11744
|
-
fiveHourLimit:
|
|
11745
|
-
weeklyLimit:
|
|
11746
|
-
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),
|
|
11747
11785
|
fetchOk: Boolean(profile.usage?.fiveHourLimit || profile.usage?.weeklyLimit)
|
|
11748
11786
|
}));
|
|
11749
11787
|
return {
|
|
@@ -11755,7 +11793,7 @@ var CodexAccountService = class {
|
|
|
11755
11793
|
* 按别名切换当前 ~/.codex/auth.json。
|
|
11756
11794
|
*/
|
|
11757
11795
|
async switchAlias(alias) {
|
|
11758
|
-
const normalizedAlias =
|
|
11796
|
+
const normalizedAlias = normalize8(alias);
|
|
11759
11797
|
const store = await this.ensureCurrentAuthProfile(this.loadStore());
|
|
11760
11798
|
const target = normalizedAlias ? store.profiles[normalizedAlias] : void 0;
|
|
11761
11799
|
if (!target) {
|
|
@@ -11778,10 +11816,10 @@ var CodexAccountService = class {
|
|
|
11778
11816
|
return {
|
|
11779
11817
|
ok: true,
|
|
11780
11818
|
alias: normalizedAlias,
|
|
11781
|
-
account:
|
|
11782
|
-
planLabel:
|
|
11783
|
-
fiveHourLimit:
|
|
11784
|
-
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),
|
|
11785
11823
|
message: ""
|
|
11786
11824
|
};
|
|
11787
11825
|
}
|
|
@@ -11790,7 +11828,7 @@ var CodexAccountService = class {
|
|
|
11790
11828
|
// src/hook/bind/bind-chat-profile-service.ts
|
|
11791
11829
|
import os13 from "os";
|
|
11792
11830
|
import path19 from "path";
|
|
11793
|
-
function
|
|
11831
|
+
function normalize9(value) {
|
|
11794
11832
|
if (value === null || value === void 0) {
|
|
11795
11833
|
return "";
|
|
11796
11834
|
}
|
|
@@ -11814,7 +11852,7 @@ var BindChatProfileService = class {
|
|
|
11814
11852
|
path: { chat_id: chatId }
|
|
11815
11853
|
});
|
|
11816
11854
|
const data = response?.data || response || {};
|
|
11817
|
-
return
|
|
11855
|
+
return normalize9(data.name || data.chat_name || data.chat?.name);
|
|
11818
11856
|
} catch (error) {
|
|
11819
11857
|
const message = error instanceof Error ? error.message : String(error);
|
|
11820
11858
|
this.logger.warn(`\u7FA4\u804A\u540D\u79F0\u89E3\u6790\u5931\u8D25: chat_id=${chatId}, error=${message}`);
|
|
@@ -11830,21 +11868,21 @@ var BindChatProfileService = class {
|
|
|
11830
11868
|
const items = [];
|
|
11831
11869
|
for (const [dirPath, binding] of Object.entries(bindings)) {
|
|
11832
11870
|
const chatIds = Array.isArray(binding?.chat_ids) ? binding.chat_ids.filter(Boolean) : [];
|
|
11833
|
-
const dirName = path19.basename(dirPath || "") ||
|
|
11871
|
+
const dirName = path19.basename(dirPath || "") || normalize9(dirPath);
|
|
11834
11872
|
for (const chatId of chatIds) {
|
|
11835
11873
|
const chatName = await this.resolveChatName(chatId);
|
|
11836
11874
|
items.push({
|
|
11837
|
-
chatId:
|
|
11838
|
-
chatName: chatName ||
|
|
11875
|
+
chatId: normalize9(chatId),
|
|
11876
|
+
chatName: chatName || normalize9(chatId),
|
|
11839
11877
|
dirName,
|
|
11840
|
-
dirPath:
|
|
11841
|
-
bindAt:
|
|
11878
|
+
dirPath: normalize9(dirPath),
|
|
11879
|
+
bindAt: normalize9(binding?.bindAt)
|
|
11842
11880
|
});
|
|
11843
11881
|
}
|
|
11844
11882
|
}
|
|
11845
11883
|
items.sort((left, right) => right.bindAt.localeCompare(left.bindAt));
|
|
11846
11884
|
return {
|
|
11847
|
-
hostName:
|
|
11885
|
+
hostName: normalize9(os13.hostname()),
|
|
11848
11886
|
count: items.length,
|
|
11849
11887
|
items
|
|
11850
11888
|
};
|
|
@@ -11856,7 +11894,7 @@ import fs20 from "fs";
|
|
|
11856
11894
|
import os14 from "os";
|
|
11857
11895
|
import path20 from "path";
|
|
11858
11896
|
var LATEST_SESSION_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
11859
|
-
function
|
|
11897
|
+
function normalize10(value) {
|
|
11860
11898
|
return String(value || "").trim();
|
|
11861
11899
|
}
|
|
11862
11900
|
function isSameLocalDate(leftDate, rightDate) {
|
|
@@ -11933,10 +11971,10 @@ var P2PSessionService = class {
|
|
|
11933
11971
|
}
|
|
11934
11972
|
buildSessionKey(input) {
|
|
11935
11973
|
return [
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
11974
|
+
normalize10(input.ownerUserId),
|
|
11975
|
+
normalize10(input.requesterUserId),
|
|
11976
|
+
normalize10(input.chatId),
|
|
11977
|
+
normalize10(input.anchorMessageId)
|
|
11940
11978
|
].join("::");
|
|
11941
11979
|
}
|
|
11942
11980
|
parseNewConversationCommand(text = "") {
|
|
@@ -11973,9 +12011,9 @@ var P2PSessionService = class {
|
|
|
11973
12011
|
* 解析当前单聊应该复用哪个会话。
|
|
11974
12012
|
*/
|
|
11975
12013
|
resolveSessionContext(input) {
|
|
11976
|
-
const ownerUserId =
|
|
12014
|
+
const ownerUserId = normalize10(this.stateManager.getState()?.ownerUserId || "");
|
|
11977
12015
|
if (!input.forceNew) {
|
|
11978
|
-
const candidates = Array.from(new Set([
|
|
12016
|
+
const candidates = Array.from(new Set([normalize10(input.rootId), normalize10(input.parentId)].filter(Boolean)));
|
|
11979
12017
|
for (const referencedId of candidates) {
|
|
11980
12018
|
const matched = this.stateManager.getP2PSessionByMessageId(referencedId);
|
|
11981
12019
|
if (!matched) {
|
|
@@ -11983,13 +12021,13 @@ var P2PSessionService = class {
|
|
|
11983
12021
|
}
|
|
11984
12022
|
return {
|
|
11985
12023
|
ownerUserId,
|
|
11986
|
-
requesterUserId:
|
|
11987
|
-
chatId:
|
|
11988
|
-
dirPath:
|
|
11989
|
-
anchorMessageId:
|
|
11990
|
-
existingSessionId:
|
|
11991
|
-
sessionKey:
|
|
11992
|
-
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) : [],
|
|
11993
12031
|
matchedBy: "reference"
|
|
11994
12032
|
};
|
|
11995
12033
|
}
|
|
@@ -11998,26 +12036,26 @@ var P2PSessionService = class {
|
|
|
11998
12036
|
requesterUserId: input.requesterUserId,
|
|
11999
12037
|
chatId: input.chatId
|
|
12000
12038
|
});
|
|
12001
|
-
if (latest &&
|
|
12039
|
+
if (latest && normalize10(latest.sessionId)) {
|
|
12002
12040
|
return {
|
|
12003
12041
|
ownerUserId,
|
|
12004
|
-
requesterUserId:
|
|
12005
|
-
chatId:
|
|
12006
|
-
dirPath:
|
|
12007
|
-
anchorMessageId:
|
|
12008
|
-
existingSessionId:
|
|
12009
|
-
sessionKey:
|
|
12010
|
-
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) : [],
|
|
12011
12049
|
matchedBy: "latest"
|
|
12012
12050
|
};
|
|
12013
12051
|
}
|
|
12014
12052
|
}
|
|
12015
|
-
const anchorMessageId =
|
|
12053
|
+
const anchorMessageId = normalize10(input.rootId || input.parentId || input.messageId);
|
|
12016
12054
|
return {
|
|
12017
12055
|
ownerUserId,
|
|
12018
|
-
requesterUserId:
|
|
12019
|
-
chatId:
|
|
12020
|
-
dirPath:
|
|
12056
|
+
requesterUserId: normalize10(input.requesterUserId),
|
|
12057
|
+
chatId: normalize10(input.chatId),
|
|
12058
|
+
dirPath: normalize10(input.dirPath),
|
|
12021
12059
|
anchorMessageId,
|
|
12022
12060
|
existingSessionId: "",
|
|
12023
12061
|
sessionKey: this.buildSessionKey({
|
|
@@ -12036,12 +12074,12 @@ var P2PSessionService = class {
|
|
|
12036
12074
|
}
|
|
12037
12075
|
this.stateManager.upsertP2PSession({
|
|
12038
12076
|
sessionKey: input.sessionKey,
|
|
12039
|
-
ownerUserId:
|
|
12040
|
-
requesterUserId:
|
|
12041
|
-
chatId:
|
|
12042
|
-
anchorMessageId:
|
|
12043
|
-
dirPath:
|
|
12044
|
-
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)
|
|
12045
12083
|
}, input.messageIds);
|
|
12046
12084
|
}
|
|
12047
12085
|
};
|
|
@@ -12049,11 +12087,11 @@ var P2PSessionService = class {
|
|
|
12049
12087
|
// src/hook/memory/memory-bucket-resolver.ts
|
|
12050
12088
|
import fs21 from "fs";
|
|
12051
12089
|
import path21 from "path";
|
|
12052
|
-
function
|
|
12090
|
+
function normalize11(value) {
|
|
12053
12091
|
return String(value || "").trim();
|
|
12054
12092
|
}
|
|
12055
12093
|
function buildSafeSegment(value, fallback = "unknown") {
|
|
12056
|
-
const normalized =
|
|
12094
|
+
const normalized = normalize11(value).replace(/[<>:"/\\|?*\u0000-\u001F]/g, "_");
|
|
12057
12095
|
return normalized || fallback;
|
|
12058
12096
|
}
|
|
12059
12097
|
function buildTodayString(offsetDays = 0) {
|
|
@@ -12079,8 +12117,8 @@ var MemoryBucketResolver = class {
|
|
|
12079
12117
|
const requester = buildSafeSegment(requesterUserId, "requester");
|
|
12080
12118
|
const baseDir = path21.join(this.getRootDir(), "p2p", owner, requester);
|
|
12081
12119
|
return this.buildBucket({
|
|
12082
|
-
bucketKey: `p2p::${
|
|
12083
|
-
bucketLabel: `\u5355\u804A(${
|
|
12120
|
+
bucketKey: `p2p::${normalize11(ownerUserId)}::${normalize11(requesterUserId)}`,
|
|
12121
|
+
bucketLabel: `\u5355\u804A(${normalize11(requesterUserId) || requester})`,
|
|
12084
12122
|
bucketType: "p2p",
|
|
12085
12123
|
baseDir,
|
|
12086
12124
|
chatId
|
|
@@ -12090,8 +12128,8 @@ var MemoryBucketResolver = class {
|
|
|
12090
12128
|
const chat = buildSafeSegment(chatId, "chat");
|
|
12091
12129
|
const baseDir = path21.join(this.getRootDir(), "group", chat);
|
|
12092
12130
|
return this.buildBucket({
|
|
12093
|
-
bucketKey: `group::${
|
|
12094
|
-
bucketLabel: `\u7FA4\u804A(${
|
|
12131
|
+
bucketKey: `group::${normalize11(chatId)}`,
|
|
12132
|
+
bucketLabel: `\u7FA4\u804A(${normalize11(chatId) || chat})`,
|
|
12095
12133
|
bucketType: "group",
|
|
12096
12134
|
baseDir,
|
|
12097
12135
|
chatId
|
|
@@ -12105,7 +12143,7 @@ var MemoryBucketResolver = class {
|
|
|
12105
12143
|
bucketKey,
|
|
12106
12144
|
bucketLabel,
|
|
12107
12145
|
bucketType,
|
|
12108
|
-
chatId:
|
|
12146
|
+
chatId: normalize11(chatId),
|
|
12109
12147
|
baseDir,
|
|
12110
12148
|
memoryDir,
|
|
12111
12149
|
longTermPath: path21.join(baseDir, "MEMORY.md"),
|
|
@@ -12135,11 +12173,11 @@ var MemoryBucketResolver = class {
|
|
|
12135
12173
|
};
|
|
12136
12174
|
|
|
12137
12175
|
// src/hook/memory/memory-extract-service.ts
|
|
12138
|
-
function
|
|
12176
|
+
function normalize12(value) {
|
|
12139
12177
|
return String(value || "").replace(/\s+/g, " ").trim();
|
|
12140
12178
|
}
|
|
12141
12179
|
function extractSummary(text = "") {
|
|
12142
|
-
const normalized =
|
|
12180
|
+
const normalized = normalize12(text).replace(/^\/new\s*/i, "").replace(/^(记住|记一下|写入记忆|更新记忆|记到长期记忆)\s*/i, "").trim();
|
|
12143
12181
|
if (!normalized) {
|
|
12144
12182
|
return "";
|
|
12145
12183
|
}
|
|
@@ -12147,7 +12185,7 @@ function extractSummary(text = "") {
|
|
|
12147
12185
|
}
|
|
12148
12186
|
var MemoryExtractService = class {
|
|
12149
12187
|
extractExplicit(text = "") {
|
|
12150
|
-
const normalized =
|
|
12188
|
+
const normalized = normalize12(text);
|
|
12151
12189
|
if (!normalized) {
|
|
12152
12190
|
return { matched: false, target: "DAILY", summary: "" };
|
|
12153
12191
|
}
|
|
@@ -12163,8 +12201,8 @@ var MemoryExtractService = class {
|
|
|
12163
12201
|
if (String(chatType || "").trim() !== "p2p") {
|
|
12164
12202
|
return { shouldWrite: false, target: "DAILY", summary: "" };
|
|
12165
12203
|
}
|
|
12166
|
-
const normalized =
|
|
12167
|
-
if (!normalized || !
|
|
12204
|
+
const normalized = normalize12(questionText);
|
|
12205
|
+
if (!normalized || !normalize12(resultText)) {
|
|
12168
12206
|
return { shouldWrite: false, target: "DAILY", summary: "" };
|
|
12169
12207
|
}
|
|
12170
12208
|
const likelyMemory = /(以后|默认|偏好|习惯|优先|总是|不要|回答时|称呼我|风格|长期|固定规则)/i.test(normalized);
|
|
@@ -12181,7 +12219,7 @@ var MemoryExtractService = class {
|
|
|
12181
12219
|
};
|
|
12182
12220
|
|
|
12183
12221
|
// src/hook/memory/memory-index-service.ts
|
|
12184
|
-
function
|
|
12222
|
+
function normalize13(value) {
|
|
12185
12223
|
return String(value || "").trim();
|
|
12186
12224
|
}
|
|
12187
12225
|
function toSnippet(text = "", maxLength = 220) {
|
|
@@ -12204,7 +12242,7 @@ var MemoryIndexService = class {
|
|
|
12204
12242
|
this.docsByBucket.set(String(bucket.bucketKey || ""), docs);
|
|
12205
12243
|
}
|
|
12206
12244
|
async search(bucket, query, limit = 5) {
|
|
12207
|
-
const text =
|
|
12245
|
+
const text = normalize13(query);
|
|
12208
12246
|
if (!text) {
|
|
12209
12247
|
return [];
|
|
12210
12248
|
}
|
|
@@ -12240,7 +12278,7 @@ ${content}`.toLowerCase();
|
|
|
12240
12278
|
// src/hook/memory/memory-service.ts
|
|
12241
12279
|
import fs22 from "fs";
|
|
12242
12280
|
import path22 from "path";
|
|
12243
|
-
function
|
|
12281
|
+
function normalize14(value) {
|
|
12244
12282
|
return String(value || "").trim();
|
|
12245
12283
|
}
|
|
12246
12284
|
function nowIso() {
|
|
@@ -12366,7 +12404,7 @@ ${nextLine}`;
|
|
|
12366
12404
|
return { longTermText, dailyText, searchResults };
|
|
12367
12405
|
}
|
|
12368
12406
|
resolveCommand(text = "") {
|
|
12369
|
-
const normalized =
|
|
12407
|
+
const normalized = normalize14(text);
|
|
12370
12408
|
if (!normalized) {
|
|
12371
12409
|
return { matched: false };
|
|
12372
12410
|
}
|
|
@@ -12377,7 +12415,7 @@ ${nextLine}`;
|
|
|
12377
12415
|
if (/^确认重置长期记忆$/i.test(normalized)) return { matched: true, type: "confirm_reset_memory" };
|
|
12378
12416
|
const searchMatch = normalized.match(/^搜索记忆\s+([\s\S]+)$/i);
|
|
12379
12417
|
if (searchMatch) {
|
|
12380
|
-
return { matched: true, type: "search_memory", query:
|
|
12418
|
+
return { matched: true, type: "search_memory", query: normalize14(searchMatch[1]) };
|
|
12381
12419
|
}
|
|
12382
12420
|
const explicit = this.extractService.extractExplicit(normalized);
|
|
12383
12421
|
if (explicit.matched) {
|
|
@@ -12429,7 +12467,7 @@ ${item.snippet}`);
|
|
|
12429
12467
|
${lines.join("\n\n")}` };
|
|
12430
12468
|
}
|
|
12431
12469
|
case "write_memory": {
|
|
12432
|
-
const summary =
|
|
12470
|
+
const summary = normalize14(command.summary);
|
|
12433
12471
|
if (!summary) {
|
|
12434
12472
|
return { handled: true, text: "\u8BB0\u5FC6\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u5DF2\u5FFD\u7565" };
|
|
12435
12473
|
}
|
|
@@ -12462,7 +12500,7 @@ ${lines.join("\n\n")}` };
|
|
|
12462
12500
|
};
|
|
12463
12501
|
|
|
12464
12502
|
// src/hook/reminder/reminder-action-classifier.ts
|
|
12465
|
-
function
|
|
12503
|
+
function normalize15(value) {
|
|
12466
12504
|
return String(value || "").replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
|
|
12467
12505
|
}
|
|
12468
12506
|
var NOTIFY_PATTERNS = [
|
|
@@ -12497,7 +12535,7 @@ var AGENT_PATTERNS = [
|
|
|
12497
12535
|
];
|
|
12498
12536
|
var ReminderActionClassifier = class {
|
|
12499
12537
|
classify(rawText = "") {
|
|
12500
|
-
const text =
|
|
12538
|
+
const text = normalize15(rawText);
|
|
12501
12539
|
if (!text) {
|
|
12502
12540
|
return { ok: false, reason: "empty_action" };
|
|
12503
12541
|
}
|
|
@@ -12514,7 +12552,7 @@ var ReminderActionClassifier = class {
|
|
|
12514
12552
|
|
|
12515
12553
|
// src/hook/reminder/reminder-agent-executor.ts
|
|
12516
12554
|
import fs23 from "fs";
|
|
12517
|
-
function
|
|
12555
|
+
function normalize16(value) {
|
|
12518
12556
|
return String(value || "").trim();
|
|
12519
12557
|
}
|
|
12520
12558
|
var ReminderAgentExecutor = class {
|
|
@@ -12537,16 +12575,16 @@ var ReminderAgentExecutor = class {
|
|
|
12537
12575
|
this.isExecutionBusy = typeof isExecutionBusy === "function" ? isExecutionBusy : () => false;
|
|
12538
12576
|
}
|
|
12539
12577
|
resolveSessionKey(job) {
|
|
12540
|
-
const ownerUserId =
|
|
12541
|
-
const chatType =
|
|
12542
|
-
const chatId =
|
|
12543
|
-
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);
|
|
12544
12582
|
if (chatType === "p2p") return `p2p::${ownerUserId || "unknown"}`;
|
|
12545
12583
|
if (chatType === "group") return rootId ? `group::${chatId || "unknown"}::${rootId}` : `group::${chatId || "unknown"}`;
|
|
12546
12584
|
return "";
|
|
12547
12585
|
}
|
|
12548
12586
|
loadAiHookPrompt(requesterUserId = "") {
|
|
12549
|
-
const promptPath = requesterUserId ? requesterUserId ===
|
|
12587
|
+
const promptPath = requesterUserId ? requesterUserId === normalize16(process.env.AGENT_BLOCK_OWNER_USER_ID) ? resolveAiHookPath() : resolveAiHookGuestPath() : resolveAiHookGuestPath();
|
|
12550
12588
|
if (!fs23.existsSync(promptPath)) {
|
|
12551
12589
|
return "";
|
|
12552
12590
|
}
|
|
@@ -12566,8 +12604,8 @@ var ReminderAgentExecutor = class {
|
|
|
12566
12604
|
if (!dirResolved.ok || !dirResolved.dirPath) {
|
|
12567
12605
|
return { ok: false, retryLater: false, error: dirResolved.error || "\u9ED8\u8BA4\u76EE\u5F55\u672A\u521D\u59CB\u5316" };
|
|
12568
12606
|
}
|
|
12569
|
-
const requesterUserId =
|
|
12570
|
-
const actionPrompt =
|
|
12607
|
+
const requesterUserId = normalize16(job?.requesterUserId || job?.delivery?.requesterUserId);
|
|
12608
|
+
const actionPrompt = normalize16(job?.action?.prompt || job?.action?.text);
|
|
12571
12609
|
if (!actionPrompt) {
|
|
12572
12610
|
return { ok: false, retryLater: false, error: "\u7F3A\u5C11\u5B9A\u65F6\u6267\u884C\u5185\u5BB9" };
|
|
12573
12611
|
}
|
|
@@ -12577,9 +12615,9 @@ var ReminderAgentExecutor = class {
|
|
|
12577
12615
|
${actionPrompt}` : actionPrompt;
|
|
12578
12616
|
const memoryBucket = this.memoryService?.resolveBucket({
|
|
12579
12617
|
chatType: "p2p",
|
|
12580
|
-
ownerUserId:
|
|
12618
|
+
ownerUserId: normalize16(job?.ownerUserId),
|
|
12581
12619
|
requesterUserId,
|
|
12582
|
-
chatId:
|
|
12620
|
+
chatId: normalize16(job?.delivery?.chatId)
|
|
12583
12621
|
}) || null;
|
|
12584
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 || "-"}`));
|
|
12585
12623
|
const result = await this.codexRunner.run(prompt, dirResolved.dirPath, {
|
|
@@ -12707,7 +12745,7 @@ var ReminderMessageBuilder = class {
|
|
|
12707
12745
|
};
|
|
12708
12746
|
|
|
12709
12747
|
// src/hook/reminder/reminder-parser.ts
|
|
12710
|
-
function
|
|
12748
|
+
function normalize17(value) {
|
|
12711
12749
|
return String(value || "").replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
|
|
12712
12750
|
}
|
|
12713
12751
|
function pad23(value) {
|
|
@@ -12721,7 +12759,7 @@ function buildTodayOrTomorrow(baseDate, daysOffset, hour, minute) {
|
|
|
12721
12759
|
return next;
|
|
12722
12760
|
}
|
|
12723
12761
|
function toMinutes(amount, unit) {
|
|
12724
|
-
const normalized =
|
|
12762
|
+
const normalized = normalize17(unit).toLowerCase();
|
|
12725
12763
|
if (["\u5206\u949F", "\u5206", "m", "min", "mins", "minute", "minutes"].includes(normalized)) {
|
|
12726
12764
|
return amount;
|
|
12727
12765
|
}
|
|
@@ -12733,7 +12771,7 @@ var ReminderParser = class {
|
|
|
12733
12771
|
this.actionClassifier = actionClassifier;
|
|
12734
12772
|
}
|
|
12735
12773
|
parse(rawText, now = /* @__PURE__ */ new Date(), context = {}) {
|
|
12736
|
-
const text =
|
|
12774
|
+
const text = normalize17(rawText);
|
|
12737
12775
|
if (!text) {
|
|
12738
12776
|
return { matched: false };
|
|
12739
12777
|
}
|
|
@@ -12748,7 +12786,7 @@ var ReminderParser = class {
|
|
|
12748
12786
|
if (/^清空提醒$/i.test(text)) return { matched: true, type: "clear_jobs" };
|
|
12749
12787
|
const cancelMatch = text.match(/^取消提醒\s+([A-Za-z0-9_-]+)$/i);
|
|
12750
12788
|
if (cancelMatch) {
|
|
12751
|
-
return { matched: true, type: "cancel_job", jobId:
|
|
12789
|
+
return { matched: true, type: "cancel_job", jobId: normalize17(cancelMatch[1]) };
|
|
12752
12790
|
}
|
|
12753
12791
|
return { matched: false };
|
|
12754
12792
|
}
|
|
@@ -12762,12 +12800,12 @@ var ReminderParser = class {
|
|
|
12762
12800
|
parseSlashRemind(text, now) {
|
|
12763
12801
|
const match = text.match(/^\/remind\s+(\d+)\s*(分钟|分|min|mins|minute|minutes|m|小时|时|hour|hours|h)\s+(.+)$/i);
|
|
12764
12802
|
if (!match) return { matched: false };
|
|
12765
|
-
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" });
|
|
12766
12804
|
}
|
|
12767
12805
|
parseRelativeReminder(text, now, context) {
|
|
12768
12806
|
const match = text.match(/^(\d+)\s*(分钟|分|min|mins|minute|minutes|m|小时|时|hour|hours|h)\s*后\s*(.+)$/i);
|
|
12769
12807
|
if (!match) return { matched: false };
|
|
12770
|
-
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);
|
|
12771
12809
|
}
|
|
12772
12810
|
buildCreateResult(amount, unit, content, now, context = {}) {
|
|
12773
12811
|
if (!Number.isFinite(amount) || amount <= 0) {
|
|
@@ -12794,10 +12832,10 @@ var ReminderParser = class {
|
|
|
12794
12832
|
parseFixedReminder(text, now, context) {
|
|
12795
12833
|
const match = text.match(/^(今天|明天)\s*(\d{1,2})[::](\d{2})\s*(.+)$/i);
|
|
12796
12834
|
if (!match) return { matched: false };
|
|
12797
|
-
const dayToken =
|
|
12835
|
+
const dayToken = normalize17(match[1]);
|
|
12798
12836
|
const hour = Number.parseInt(match[2] || "0", 10);
|
|
12799
12837
|
const minute = Number.parseInt(match[3] || "0", 10);
|
|
12800
|
-
const content =
|
|
12838
|
+
const content = normalize17(match[4]);
|
|
12801
12839
|
if (!Number.isFinite(hour) || hour < 0 || hour > 23 || !Number.isFinite(minute) || minute < 0 || minute > 59) {
|
|
12802
12840
|
return { matched: true, type: "invalid", error: "\u63D0\u9192\u65F6\u95F4\u683C\u5F0F\u4E0D\u6B63\u786E\uFF0C\u8BF7\u4F7F\u7528 HH:mm" };
|
|
12803
12841
|
}
|
|
@@ -12823,7 +12861,7 @@ var ReminderParser = class {
|
|
|
12823
12861
|
};
|
|
12824
12862
|
}
|
|
12825
12863
|
resolveAction(content, context = {}, forceKind = "") {
|
|
12826
|
-
const normalizedContent =
|
|
12864
|
+
const normalizedContent = normalize17(content);
|
|
12827
12865
|
if (!normalizedContent) {
|
|
12828
12866
|
return { ok: false, reason: "empty_action" };
|
|
12829
12867
|
}
|
|
@@ -12888,16 +12926,16 @@ var ReminderStore = class {
|
|
|
12888
12926
|
};
|
|
12889
12927
|
|
|
12890
12928
|
// src/hook/reminder/reminder-service.ts
|
|
12891
|
-
function
|
|
12929
|
+
function normalize18(value) {
|
|
12892
12930
|
return String(value || "").trim();
|
|
12893
12931
|
}
|
|
12894
12932
|
function normalizeTargets2(items = []) {
|
|
12895
12933
|
const seen = /* @__PURE__ */ new Set();
|
|
12896
12934
|
const targets = [];
|
|
12897
12935
|
(Array.isArray(items) ? items : []).forEach((item) => {
|
|
12898
|
-
const userId =
|
|
12899
|
-
const openId =
|
|
12900
|
-
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);
|
|
12901
12939
|
if (!userId && !openId) {
|
|
12902
12940
|
return;
|
|
12903
12941
|
}
|
|
@@ -13023,27 +13061,27 @@ var ReminderService = class {
|
|
|
13023
13061
|
const nowMs = Date.now();
|
|
13024
13062
|
return {
|
|
13025
13063
|
id: createJobId(),
|
|
13026
|
-
ownerUserId:
|
|
13027
|
-
requesterUserId:
|
|
13028
|
-
requesterOpenId:
|
|
13029
|
-
chatType:
|
|
13030
|
-
messageId:
|
|
13031
|
-
rootId:
|
|
13032
|
-
parentId:
|
|
13033
|
-
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),
|
|
13034
13072
|
schedule: { kind: "at", runAtMs: Number(command?.schedule?.runAtMs || 0) },
|
|
13035
13073
|
action: {
|
|
13036
|
-
kind:
|
|
13037
|
-
text:
|
|
13038
|
-
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)
|
|
13039
13077
|
},
|
|
13040
13078
|
delivery: {
|
|
13041
13079
|
mode: "feishu_message",
|
|
13042
13080
|
target: "origin_chat",
|
|
13043
|
-
chatType:
|
|
13044
|
-
chatId:
|
|
13045
|
-
requesterUserId:
|
|
13046
|
-
requesterOpenId:
|
|
13081
|
+
chatType: normalize18(context.chatType),
|
|
13082
|
+
chatId: normalize18(context.chatId),
|
|
13083
|
+
requesterUserId: normalize18(context.requesterUserId),
|
|
13084
|
+
requesterOpenId: normalize18(context.requesterOpenId),
|
|
13047
13085
|
notifyTargets: normalizeTargets2(context.reminderTargets)
|
|
13048
13086
|
},
|
|
13049
13087
|
state: {
|
|
@@ -13059,20 +13097,20 @@ var ReminderService = class {
|
|
|
13059
13097
|
return this.store.readAll().filter((job) => this.isVisibleForContext(job, context) && job?.state?.status === "pending");
|
|
13060
13098
|
}
|
|
13061
13099
|
findPendingJobForContext(context, jobId = "") {
|
|
13062
|
-
const normalized =
|
|
13100
|
+
const normalized = normalize18(jobId);
|
|
13063
13101
|
if (!normalized) {
|
|
13064
13102
|
return null;
|
|
13065
13103
|
}
|
|
13066
|
-
return this.listPendingJobs(context).find((job) =>
|
|
13104
|
+
return this.listPendingJobs(context).find((job) => normalize18(job?.id) === normalized) || null;
|
|
13067
13105
|
}
|
|
13068
13106
|
isVisibleForContext(job, context) {
|
|
13069
|
-
const requesterUserId =
|
|
13070
|
-
const chatId =
|
|
13071
|
-
const chatType =
|
|
13107
|
+
const requesterUserId = normalize18(context.requesterUserId);
|
|
13108
|
+
const chatId = normalize18(context.chatId);
|
|
13109
|
+
const chatType = normalize18(context.chatType).toLowerCase();
|
|
13072
13110
|
if (chatType === "p2p") {
|
|
13073
|
-
return
|
|
13111
|
+
return normalize18(job?.requesterUserId) === requesterUserId && normalize18(job?.delivery?.chatId) === chatId;
|
|
13074
13112
|
}
|
|
13075
|
-
return
|
|
13113
|
+
return normalize18(job?.requesterUserId) === requesterUserId && normalize18(job?.delivery?.chatId) === chatId;
|
|
13076
13114
|
}
|
|
13077
13115
|
scheduleNext() {
|
|
13078
13116
|
if (!this.running) {
|
|
@@ -13108,9 +13146,9 @@ var ReminderService = class {
|
|
|
13108
13146
|
this.scheduleNext();
|
|
13109
13147
|
}
|
|
13110
13148
|
async executeJob(job) {
|
|
13111
|
-
const traceId =
|
|
13149
|
+
const traceId = normalize18(job?.traceId || job?.messageId || job?.id);
|
|
13112
13150
|
try {
|
|
13113
|
-
const actionKind =
|
|
13151
|
+
const actionKind = normalize18(job?.action?.kind);
|
|
13114
13152
|
if (actionKind === "notify") {
|
|
13115
13153
|
await this.sendNotify(job);
|
|
13116
13154
|
} else if (actionKind === "agent_turn") {
|
|
@@ -13134,7 +13172,7 @@ var ReminderService = class {
|
|
|
13134
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 || "-"}`));
|
|
13135
13173
|
} catch (error) {
|
|
13136
13174
|
const message = error instanceof Error ? error.message : String(error);
|
|
13137
|
-
if (
|
|
13175
|
+
if (normalize18(job?.action?.kind) === "agent_turn") {
|
|
13138
13176
|
try {
|
|
13139
13177
|
await this.sendAgentTurnFailure(job, message);
|
|
13140
13178
|
} catch (notifyError) {
|
|
@@ -13158,7 +13196,7 @@ var ReminderService = class {
|
|
|
13158
13196
|
});
|
|
13159
13197
|
}
|
|
13160
13198
|
async sendNotify(job) {
|
|
13161
|
-
const chatId =
|
|
13199
|
+
const chatId = normalize18(job?.delivery?.chatId);
|
|
13162
13200
|
if (!chatId) {
|
|
13163
13201
|
throw new Error("\u63D0\u9192\u7F3A\u5C11 chat_id");
|
|
13164
13202
|
}
|
|
@@ -13172,7 +13210,7 @@ var ReminderService = class {
|
|
|
13172
13210
|
});
|
|
13173
13211
|
}
|
|
13174
13212
|
async sendAgentTurnResult(job, resultText = "") {
|
|
13175
|
-
const chatId =
|
|
13213
|
+
const chatId = normalize18(job?.delivery?.chatId);
|
|
13176
13214
|
if (!chatId) {
|
|
13177
13215
|
throw new Error("\u5B9A\u65F6\u4EFB\u52A1\u7F3A\u5C11 chat_id");
|
|
13178
13216
|
}
|
|
@@ -13186,7 +13224,7 @@ var ReminderService = class {
|
|
|
13186
13224
|
});
|
|
13187
13225
|
}
|
|
13188
13226
|
async sendAgentTurnFailure(job, error = "") {
|
|
13189
|
-
const chatId =
|
|
13227
|
+
const chatId = normalize18(job?.delivery?.chatId);
|
|
13190
13228
|
if (!chatId) {
|
|
13191
13229
|
throw new Error("\u5B9A\u65F6\u4EFB\u52A1\u7F3A\u5C11 chat_id");
|
|
13192
13230
|
}
|
|
@@ -13204,32 +13242,6 @@ var ReminderService = class {
|
|
|
13204
13242
|
// src/hook/persona/requester-persona-service.ts
|
|
13205
13243
|
import fs25 from "fs";
|
|
13206
13244
|
import path24 from "path";
|
|
13207
|
-
function normalize20(value) {
|
|
13208
|
-
if (value === null || value === void 0) {
|
|
13209
|
-
return "";
|
|
13210
|
-
}
|
|
13211
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
13212
|
-
return String(value).trim();
|
|
13213
|
-
}
|
|
13214
|
-
return "";
|
|
13215
|
-
}
|
|
13216
|
-
function resolveDisplayName2(value) {
|
|
13217
|
-
const direct = normalize20(value);
|
|
13218
|
-
if (direct) {
|
|
13219
|
-
return direct;
|
|
13220
|
-
}
|
|
13221
|
-
if (!value || typeof value !== "object") {
|
|
13222
|
-
return "";
|
|
13223
|
-
}
|
|
13224
|
-
const candidateKeys = ["zh_cn", "zh-CN", "zh_hans", "zh", "en_us", "en-US", "en", "name", "value"];
|
|
13225
|
-
for (const key of candidateKeys) {
|
|
13226
|
-
const text = normalize20(value?.[key]);
|
|
13227
|
-
if (text) {
|
|
13228
|
-
return text;
|
|
13229
|
-
}
|
|
13230
|
-
}
|
|
13231
|
-
return "";
|
|
13232
|
-
}
|
|
13233
13245
|
function pickUserData2(response) {
|
|
13234
13246
|
const data = response?.data || {};
|
|
13235
13247
|
const user = data?.user || data?.data?.user || data?.items?.[0] || data?.item || {};
|
|
@@ -13307,8 +13319,8 @@ var RequesterPersonaService = class {
|
|
|
13307
13319
|
}
|
|
13308
13320
|
}
|
|
13309
13321
|
buildCacheKey(userId = "", openId = "") {
|
|
13310
|
-
const normalizedUserId =
|
|
13311
|
-
const normalizedOpenId =
|
|
13322
|
+
const normalizedUserId = normalizeText(userId);
|
|
13323
|
+
const normalizedOpenId = normalizeText(openId);
|
|
13312
13324
|
if (normalizedUserId) {
|
|
13313
13325
|
return `user_id:${normalizedUserId}`;
|
|
13314
13326
|
}
|
|
@@ -13347,8 +13359,8 @@ var RequesterPersonaService = class {
|
|
|
13347
13359
|
return null;
|
|
13348
13360
|
}
|
|
13349
13361
|
const attempts = [];
|
|
13350
|
-
const normalizedUserId =
|
|
13351
|
-
const normalizedOpenId =
|
|
13362
|
+
const normalizedUserId = normalizeText(userId);
|
|
13363
|
+
const normalizedOpenId = normalizeText(openId);
|
|
13352
13364
|
if (normalizedUserId) {
|
|
13353
13365
|
attempts.push({
|
|
13354
13366
|
path: { user_id: normalizedUserId },
|
|
@@ -13384,7 +13396,7 @@ var RequesterPersonaService = class {
|
|
|
13384
13396
|
return null;
|
|
13385
13397
|
}
|
|
13386
13398
|
async tryFetchJobLevelName(jobLevelId = "") {
|
|
13387
|
-
const normalizedJobLevelId =
|
|
13399
|
+
const normalizedJobLevelId = normalizeText(jobLevelId);
|
|
13388
13400
|
if (!normalizedJobLevelId || !this.jobLevelNameLookupEnabled) {
|
|
13389
13401
|
return "";
|
|
13390
13402
|
}
|
|
@@ -13400,7 +13412,7 @@ var RequesterPersonaService = class {
|
|
|
13400
13412
|
return "";
|
|
13401
13413
|
}
|
|
13402
13414
|
const jobLevel = pickJobLevelData(response);
|
|
13403
|
-
return
|
|
13415
|
+
return resolveDisplayName(jobLevel.name) || resolveDisplayName(jobLevel.i18n_name) || normalizeText(jobLevel.code || "");
|
|
13404
13416
|
} catch (error) {
|
|
13405
13417
|
const errorCode = error?.response?.data?.code || error?.code || "";
|
|
13406
13418
|
if ((String(errorCode) === "99991672" || String(error?.message || "").includes("Access denied")) && !this.jobLevelPermissionDeniedLogged) {
|
|
@@ -13412,14 +13424,14 @@ var RequesterPersonaService = class {
|
|
|
13412
13424
|
}
|
|
13413
13425
|
}
|
|
13414
13426
|
resolveRoleConfig(jobLevelId = "") {
|
|
13415
|
-
const normalizedJobLevelId =
|
|
13427
|
+
const normalizedJobLevelId = normalizeText(jobLevelId);
|
|
13416
13428
|
if (!normalizedJobLevelId) {
|
|
13417
13429
|
return { roleKey: "", roleConfig: null };
|
|
13418
13430
|
}
|
|
13419
13431
|
const roles = this.rules?.roles || {};
|
|
13420
13432
|
for (const [roleKey, roleConfig] of Object.entries(roles)) {
|
|
13421
13433
|
const ids = Array.isArray(roleConfig?.jobLevelIds) ? roleConfig.jobLevelIds : [];
|
|
13422
|
-
if (ids.map((item) =>
|
|
13434
|
+
if (ids.map((item) => normalizeText(item)).includes(normalizedJobLevelId)) {
|
|
13423
13435
|
return { roleKey, roleConfig };
|
|
13424
13436
|
}
|
|
13425
13437
|
}
|
|
@@ -13435,12 +13447,12 @@ var RequesterPersonaService = class {
|
|
|
13435
13447
|
return "";
|
|
13436
13448
|
}
|
|
13437
13449
|
const lines = [
|
|
13438
|
-
`- \u63D0\u95EE\u8005\u89D2\u8272: ${
|
|
13439
|
-
`- \u63D0\u95EE\u8005 user_id: ${
|
|
13440
|
-
`- \u63D0\u95EE\u8005\u59D3\u540D: ${
|
|
13441
|
-
`- \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) || "-"}`
|
|
13442
13454
|
];
|
|
13443
|
-
const jobLevelName =
|
|
13455
|
+
const jobLevelName = normalizeText(record.jobLevelName);
|
|
13444
13456
|
if (jobLevelName) {
|
|
13445
13457
|
lines.push(`- \u63D0\u95EE\u8005\u804C\u7EA7\u540D\u79F0: ${jobLevelName}`);
|
|
13446
13458
|
}
|
|
@@ -13454,12 +13466,12 @@ var RequesterPersonaService = class {
|
|
|
13454
13466
|
}
|
|
13455
13467
|
buildRecord({ cached = null, user = null, identity = null, jobLevelName = "" } = {}) {
|
|
13456
13468
|
const requester = identity?.requester || {};
|
|
13457
|
-
const userId =
|
|
13458
|
-
const openId =
|
|
13459
|
-
const name =
|
|
13460
|
-
const email =
|
|
13461
|
-
const jobLevelId =
|
|
13462
|
-
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 || "");
|
|
13463
13475
|
const { roleKey, roleConfig } = this.resolveRoleConfig(jobLevelId);
|
|
13464
13476
|
const now = Date.now();
|
|
13465
13477
|
return {
|
|
@@ -13470,18 +13482,18 @@ var RequesterPersonaService = class {
|
|
|
13470
13482
|
jobLevelId,
|
|
13471
13483
|
jobLevelName: nextJobLevelName,
|
|
13472
13484
|
personaRole: roleKey,
|
|
13473
|
-
personaLabel:
|
|
13485
|
+
personaLabel: normalizeText(roleConfig?.label || ""),
|
|
13474
13486
|
updatedAt: now,
|
|
13475
13487
|
expiresAt: now + this.cacheTtlMs
|
|
13476
13488
|
};
|
|
13477
13489
|
}
|
|
13478
13490
|
logUnmatchedJobLevel(jobLevelId = "", userId = "") {
|
|
13479
|
-
const normalizedJobLevelId =
|
|
13491
|
+
const normalizedJobLevelId = normalizeText(jobLevelId);
|
|
13480
13492
|
if (!normalizedJobLevelId || this.loggedUnknownJobLevelIds.has(normalizedJobLevelId)) {
|
|
13481
13493
|
return;
|
|
13482
13494
|
}
|
|
13483
13495
|
this.loggedUnknownJobLevelIds.add(normalizedJobLevelId);
|
|
13484
|
-
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}`);
|
|
13485
13497
|
}
|
|
13486
13498
|
async resolveRequesterPersona({
|
|
13487
13499
|
chatType = "",
|
|
@@ -13489,11 +13501,11 @@ var RequesterPersonaService = class {
|
|
|
13489
13501
|
senderOpenId = "",
|
|
13490
13502
|
identity = null
|
|
13491
13503
|
} = {}) {
|
|
13492
|
-
if (
|
|
13504
|
+
if (normalizeText(chatType).toLowerCase() !== "group") {
|
|
13493
13505
|
return null;
|
|
13494
13506
|
}
|
|
13495
|
-
const normalizedUserId =
|
|
13496
|
-
const normalizedOpenId =
|
|
13507
|
+
const normalizedUserId = normalizeText(senderUserId);
|
|
13508
|
+
const normalizedOpenId = normalizeText(senderOpenId);
|
|
13497
13509
|
if (!normalizedUserId && !normalizedOpenId) {
|
|
13498
13510
|
return null;
|
|
13499
13511
|
}
|
|
@@ -13519,7 +13531,7 @@ var RequesterPersonaService = class {
|
|
|
13519
13531
|
if (!user) {
|
|
13520
13532
|
return null;
|
|
13521
13533
|
}
|
|
13522
|
-
const jobLevelId =
|
|
13534
|
+
const jobLevelId = normalizeText(user?.job_level_id || "");
|
|
13523
13535
|
let jobLevelName = "";
|
|
13524
13536
|
if (jobLevelId) {
|
|
13525
13537
|
jobLevelName = await this.tryFetchJobLevelName(jobLevelId);
|
|
@@ -13684,17 +13696,8 @@ function buildWorkerState(options) {
|
|
|
13684
13696
|
}
|
|
13685
13697
|
|
|
13686
13698
|
// src/hook/worker/worker-owner-resolver.ts
|
|
13687
|
-
function normalize21(value) {
|
|
13688
|
-
if (value === null || value === void 0) {
|
|
13689
|
-
return "";
|
|
13690
|
-
}
|
|
13691
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
13692
|
-
return String(value).trim();
|
|
13693
|
-
}
|
|
13694
|
-
return "";
|
|
13695
|
-
}
|
|
13696
13699
|
function lower2(value) {
|
|
13697
|
-
return
|
|
13700
|
+
return normalizeText(value).toLowerCase();
|
|
13698
13701
|
}
|
|
13699
13702
|
function buildEmailFromUser(user = "") {
|
|
13700
13703
|
const normalizedUser = lower2(user);
|
|
@@ -13703,42 +13706,13 @@ function buildEmailFromUser(user = "") {
|
|
|
13703
13706
|
}
|
|
13704
13707
|
return normalizedUser.includes("@") ? normalizedUser : `${normalizedUser}@hstong.com`;
|
|
13705
13708
|
}
|
|
13706
|
-
function resolveDisplayName3(value) {
|
|
13707
|
-
const direct = normalize21(value);
|
|
13708
|
-
if (direct) {
|
|
13709
|
-
return direct;
|
|
13710
|
-
}
|
|
13711
|
-
if (!value || typeof value !== "object") {
|
|
13712
|
-
return "";
|
|
13713
|
-
}
|
|
13714
|
-
const candidateKeys = [
|
|
13715
|
-
"zh_cn",
|
|
13716
|
-
"zh-CN",
|
|
13717
|
-
"zh_hans",
|
|
13718
|
-
"zh",
|
|
13719
|
-
"en_us",
|
|
13720
|
-
"en-US",
|
|
13721
|
-
"en",
|
|
13722
|
-
"name",
|
|
13723
|
-
"display_name",
|
|
13724
|
-
"full_name",
|
|
13725
|
-
"value"
|
|
13726
|
-
];
|
|
13727
|
-
for (const key of candidateKeys) {
|
|
13728
|
-
const text = normalize21(value[key]);
|
|
13729
|
-
if (text) {
|
|
13730
|
-
return text;
|
|
13731
|
-
}
|
|
13732
|
-
}
|
|
13733
|
-
return "";
|
|
13734
|
-
}
|
|
13735
13709
|
function scoreEntry(entry) {
|
|
13736
13710
|
let score = 0;
|
|
13737
|
-
if (
|
|
13738
|
-
if (
|
|
13739
|
-
if (
|
|
13740
|
-
if (
|
|
13741
|
-
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;
|
|
13742
13716
|
return score;
|
|
13743
13717
|
}
|
|
13744
13718
|
var WorkerOwnerResolver = class {
|
|
@@ -13747,7 +13721,7 @@ var WorkerOwnerResolver = class {
|
|
|
13747
13721
|
identityResolver;
|
|
13748
13722
|
constructor({ logger: logger3, larkClient, opsUserName = "" }) {
|
|
13749
13723
|
this.logger = logger3;
|
|
13750
|
-
this.opsUserName =
|
|
13724
|
+
this.opsUserName = normalizeText(opsUserName);
|
|
13751
13725
|
this.identityResolver = new IdentityResolver({ logger: logger3, larkClient });
|
|
13752
13726
|
}
|
|
13753
13727
|
pickBestEntry(entries = []) {
|
|
@@ -13765,7 +13739,7 @@ var WorkerOwnerResolver = class {
|
|
|
13765
13739
|
if (!item || typeof item !== "object" || item.__cacheType) {
|
|
13766
13740
|
return false;
|
|
13767
13741
|
}
|
|
13768
|
-
return lower2(item.user) === ownerKey ||
|
|
13742
|
+
return lower2(item.user) === ownerKey || normalizeText(item.name) === this.opsUserName;
|
|
13769
13743
|
});
|
|
13770
13744
|
return this.pickBestEntry(candidates);
|
|
13771
13745
|
}
|
|
@@ -13793,10 +13767,10 @@ var WorkerOwnerResolver = class {
|
|
|
13793
13767
|
return null;
|
|
13794
13768
|
}
|
|
13795
13769
|
return {
|
|
13796
|
-
user_id:
|
|
13797
|
-
open_id:
|
|
13798
|
-
name:
|
|
13799
|
-
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)
|
|
13800
13774
|
};
|
|
13801
13775
|
} catch (error) {
|
|
13802
13776
|
const detail = error?.response?.data ? JSON.stringify(error.response.data) : error instanceof Error ? error.message : String(error);
|
|
@@ -13805,8 +13779,8 @@ var WorkerOwnerResolver = class {
|
|
|
13805
13779
|
}
|
|
13806
13780
|
}
|
|
13807
13781
|
async enrichEntryFromEmail(cache, entry) {
|
|
13808
|
-
const baseUser =
|
|
13809
|
-
const candidateEmail =
|
|
13782
|
+
const baseUser = normalizeText(entry?.user) || this.opsUserName;
|
|
13783
|
+
const candidateEmail = normalizeText(entry?.email) || buildEmailFromUser(baseUser);
|
|
13810
13784
|
if (!candidateEmail) {
|
|
13811
13785
|
return null;
|
|
13812
13786
|
}
|
|
@@ -13815,19 +13789,19 @@ var WorkerOwnerResolver = class {
|
|
|
13815
13789
|
return null;
|
|
13816
13790
|
}
|
|
13817
13791
|
let detailedUser = null;
|
|
13818
|
-
if (!
|
|
13792
|
+
if (!normalizeText(larkUser.open_id)) {
|
|
13819
13793
|
detailedUser = await this.identityResolver.fetchUserFromLark(larkUser.user_id, "");
|
|
13820
13794
|
}
|
|
13821
13795
|
this.identityResolver.updateUserCache(cache, {
|
|
13822
|
-
user_id:
|
|
13823
|
-
open_id:
|
|
13824
|
-
name:
|
|
13825
|
-
email:
|
|
13826
|
-
},
|
|
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));
|
|
13827
13801
|
this.identityResolver.saveCache();
|
|
13828
13802
|
const refreshed = this.findOwnerEntry(cache);
|
|
13829
13803
|
if (refreshed) {
|
|
13830
|
-
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) || "-"}`);
|
|
13831
13805
|
}
|
|
13832
13806
|
return refreshed;
|
|
13833
13807
|
}
|
|
@@ -13838,30 +13812,30 @@ var WorkerOwnerResolver = class {
|
|
|
13838
13812
|
}
|
|
13839
13813
|
const cache = this.identityResolver.loadCache();
|
|
13840
13814
|
let entry = this.findOwnerEntry(cache);
|
|
13841
|
-
if (!
|
|
13815
|
+
if (!normalizeText(entry?.feishuUserId) || !normalizeText(entry?.feishuOpenId)) {
|
|
13842
13816
|
entry = await this.enrichEntryFromEmail(cache, entry);
|
|
13843
13817
|
}
|
|
13844
|
-
const ownerUserId =
|
|
13818
|
+
const ownerUserId = normalizeText(entry?.feishuUserId);
|
|
13845
13819
|
if (!ownerUserId) {
|
|
13846
13820
|
this.logger.warn(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u89E3\u6790\u5931\u8D25: ops_user=${this.opsUserName}, reason=missing_feishu_user_id`);
|
|
13847
13821
|
return {
|
|
13848
13822
|
...this.emptyProfile(entry ? "cache_incomplete" : "cache_miss"),
|
|
13849
|
-
ownerDisplayName:
|
|
13850
|
-
ownerOpenId:
|
|
13851
|
-
employeeNo:
|
|
13852
|
-
email:
|
|
13853
|
-
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)
|
|
13854
13828
|
};
|
|
13855
13829
|
}
|
|
13856
|
-
const ownerDisplayName =
|
|
13830
|
+
const ownerDisplayName = resolveDisplayName(entry?.name) || normalizeText(entry?.user) || this.opsUserName;
|
|
13857
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}`);
|
|
13858
13832
|
return {
|
|
13859
13833
|
ownerUserId,
|
|
13860
13834
|
ownerDisplayName,
|
|
13861
|
-
ownerOpenId:
|
|
13862
|
-
employeeNo:
|
|
13863
|
-
email:
|
|
13864
|
-
user:
|
|
13835
|
+
ownerOpenId: normalizeText(entry?.feishuOpenId),
|
|
13836
|
+
employeeNo: normalizeText(entry?.uId),
|
|
13837
|
+
email: normalizeText(entry?.email),
|
|
13838
|
+
user: normalizeText(entry?.user),
|
|
13865
13839
|
opsUserName: this.opsUserName,
|
|
13866
13840
|
source: "cache"
|
|
13867
13841
|
};
|
|
@@ -13887,28 +13861,11 @@ var PERSPECTIVE_RULES = [
|
|
|
13887
13861
|
{ key: "product", label: "\u4EA7\u54C1\u89C6\u89D2", pattern: /产品经理|产品/i },
|
|
13888
13862
|
{ key: "backend", label: "\u540E\u7AEF\u7814\u53D1\u89C6\u89D2", pattern: /java/i }
|
|
13889
13863
|
];
|
|
13890
|
-
function normalize22(value) {
|
|
13891
|
-
if (value === null || value === void 0) {
|
|
13892
|
-
return "";
|
|
13893
|
-
}
|
|
13894
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
13895
|
-
return String(value).trim();
|
|
13896
|
-
}
|
|
13897
|
-
return "";
|
|
13898
|
-
}
|
|
13899
13864
|
function resolveLocalizedText(value) {
|
|
13900
|
-
|
|
13901
|
-
if (direct) {
|
|
13902
|
-
return direct;
|
|
13903
|
-
}
|
|
13904
|
-
if (!value || typeof value !== "object") {
|
|
13905
|
-
return "";
|
|
13906
|
-
}
|
|
13907
|
-
const record = value;
|
|
13908
|
-
return normalize22(record.default_value) || normalize22(record.i18n_value?.zh_cn) || normalize22(record.i18n_value?.en_us);
|
|
13865
|
+
return resolveDisplayName(value);
|
|
13909
13866
|
}
|
|
13910
13867
|
function resolvePerspectiveByJobTitle(jobTitle = "") {
|
|
13911
|
-
const matched = PERSPECTIVE_RULES.find((rule) => rule.pattern.test(
|
|
13868
|
+
const matched = PERSPECTIVE_RULES.find((rule) => rule.pattern.test(normalizeText(jobTitle)));
|
|
13912
13869
|
return matched ? { perspectiveKey: matched.key, perspectiveLabel: matched.label } : { perspectiveKey: "general", perspectiveLabel: "\u901A\u7528\u89C6\u89D2" };
|
|
13913
13870
|
}
|
|
13914
13871
|
var WorkerPerspectiveResolver = class {
|
|
@@ -13919,7 +13876,7 @@ var WorkerPerspectiveResolver = class {
|
|
|
13919
13876
|
this.larkClient = larkClient;
|
|
13920
13877
|
}
|
|
13921
13878
|
async resolve(ownerProfile) {
|
|
13922
|
-
const ownerOpenId =
|
|
13879
|
+
const ownerOpenId = normalizeText(ownerProfile.ownerOpenId);
|
|
13923
13880
|
if (!ownerOpenId || typeof this.larkClient?.request !== "function") {
|
|
13924
13881
|
return this.buildResult();
|
|
13925
13882
|
}
|
|
@@ -13943,9 +13900,9 @@ var WorkerPerspectiveResolver = class {
|
|
|
13943
13900
|
const jobTitle = employee?.work_info?.job_title || {};
|
|
13944
13901
|
const result = this.buildResult(
|
|
13945
13902
|
resolveLocalizedText(jobTitle.job_title_name),
|
|
13946
|
-
|
|
13903
|
+
normalizeText(jobTitle.job_title_id)
|
|
13947
13904
|
);
|
|
13948
|
-
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}`);
|
|
13949
13906
|
return result;
|
|
13950
13907
|
} catch (error) {
|
|
13951
13908
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -13955,15 +13912,15 @@ var WorkerPerspectiveResolver = class {
|
|
|
13955
13912
|
}
|
|
13956
13913
|
buildResult(jobTitle = "", jobTitleId = "") {
|
|
13957
13914
|
return {
|
|
13958
|
-
jobTitle:
|
|
13959
|
-
jobTitleId:
|
|
13915
|
+
jobTitle: normalizeText(jobTitle),
|
|
13916
|
+
jobTitleId: normalizeText(jobTitleId),
|
|
13960
13917
|
...resolvePerspectiveByJobTitle(jobTitle)
|
|
13961
13918
|
};
|
|
13962
13919
|
}
|
|
13963
13920
|
};
|
|
13964
13921
|
|
|
13965
13922
|
// src/hook/worker/owner-notify-service.ts
|
|
13966
|
-
function
|
|
13923
|
+
function normalize19(value) {
|
|
13967
13924
|
return String(value || "").trim();
|
|
13968
13925
|
}
|
|
13969
13926
|
var OwnerNotifyService = class {
|
|
@@ -13977,12 +13934,12 @@ var OwnerNotifyService = class {
|
|
|
13977
13934
|
this.ownerProfile = ownerProfile;
|
|
13978
13935
|
}
|
|
13979
13936
|
hasTarget() {
|
|
13980
|
-
return Boolean(
|
|
13937
|
+
return Boolean(normalize19(this.ownerProfile.ownerUserId) || normalize19(this.ownerProfile.ownerOpenId));
|
|
13981
13938
|
}
|
|
13982
13939
|
async sendText(text) {
|
|
13983
13940
|
const content = JSON.stringify({ text: String(text || "").trim() });
|
|
13984
|
-
const userId =
|
|
13985
|
-
const openId =
|
|
13941
|
+
const userId = normalize19(this.ownerProfile.ownerUserId);
|
|
13942
|
+
const openId = normalize19(this.ownerProfile.ownerOpenId);
|
|
13986
13943
|
if (userId) {
|
|
13987
13944
|
return await this.larkClient.im.v1.message.create({
|
|
13988
13945
|
params: { receive_id_type: "user_id" },
|
|
@@ -14366,6 +14323,23 @@ var DEFAULT_MASTER_HOST_ENV = "NIKOU_HOOK_MASTER_HOST";
|
|
|
14366
14323
|
function resolveHookSection2(config) {
|
|
14367
14324
|
return config.hook ?? config.ai_hook ?? config.aiHook ?? {};
|
|
14368
14325
|
}
|
|
14326
|
+
function resolveConfiguredMasterHost(config) {
|
|
14327
|
+
const hook2 = resolveHookSection2(config);
|
|
14328
|
+
return String(hook2.master_host || hook2.masterHost || "").trim();
|
|
14329
|
+
}
|
|
14330
|
+
function mergeHookInitMasterHost(config, masterHost) {
|
|
14331
|
+
const host = String(masterHost || "").trim();
|
|
14332
|
+
if (!host) {
|
|
14333
|
+
return config;
|
|
14334
|
+
}
|
|
14335
|
+
return {
|
|
14336
|
+
...config,
|
|
14337
|
+
hook: {
|
|
14338
|
+
...config.hook ?? config.ai_hook ?? config.aiHook ?? {},
|
|
14339
|
+
master_host: host
|
|
14340
|
+
}
|
|
14341
|
+
};
|
|
14342
|
+
}
|
|
14369
14343
|
function resolveContextConfigFromHook(hook2) {
|
|
14370
14344
|
return {
|
|
14371
14345
|
enabled: parseBoolean(
|
|
@@ -14411,7 +14385,7 @@ function normalizeHookInitConfig(config, defaults = {}) {
|
|
|
14411
14385
|
const appSecret = String(
|
|
14412
14386
|
config.feishu?.app_secret || config.feishu?.appSecret || config.feishu?.appsecret || ""
|
|
14413
14387
|
).trim();
|
|
14414
|
-
const masterHost =
|
|
14388
|
+
const masterHost = resolveConfiguredMasterHost(config) || String(defaults.defaultMasterHost || "").trim();
|
|
14415
14389
|
const masterPort = parsePositiveInt(hook2.master_port ?? hook2.masterPort, DEFAULT_MASTER_PORT);
|
|
14416
14390
|
const sharedSecret = String(hook2.shared_secret || hook2.sharedSecret || appSecret || "").trim();
|
|
14417
14391
|
const bindAllowedUserIds = parseUserIdList(hook2.bind_allowed_user_ids ?? hook2.bindAllowedUserIds);
|
|
@@ -14456,7 +14430,6 @@ var HookInitCommand = class {
|
|
|
14456
14430
|
async run() {
|
|
14457
14431
|
this.ensureInteractiveTerminal();
|
|
14458
14432
|
const source = this.resolveSourceConfig();
|
|
14459
|
-
const normalized = this.normalizeSourceConfig(source.config);
|
|
14460
14433
|
const migration = loadLegacyMigrationResult(this.logger);
|
|
14461
14434
|
const existingAggregateConfig = this.readJson(DEFAULT_CONFIG_PATH);
|
|
14462
14435
|
const existingMasterConfig = this.readJson(MASTER_CONFIG_PATH);
|
|
@@ -14468,6 +14441,10 @@ var HookInitCommand = class {
|
|
|
14468
14441
|
this.printEnvironmentSummary(source.path, { existingAggregateConfig, existingMasterConfig, existingWorkerConfig }, migration.summary);
|
|
14469
14442
|
const botName = await this.askChoice(rl, "\u7B2C\u4E00\u6B65\uFF1A\u9009\u62E9\u98DE\u4E66\u673A\u5668\u4EBA", BOT_OPTIONS, 0);
|
|
14470
14443
|
await this.askChoice(rl, "\u7B2C\u4E8C\u6B65\uFF1A\u9009\u62E9\u90E8\u7F72\u65B9\u5F0F", DEPLOYMENT_OPTIONS, 0);
|
|
14444
|
+
const masterHost = await this.askMasterHost(rl, source.config);
|
|
14445
|
+
const normalized = this.normalizeSourceConfig(
|
|
14446
|
+
mergeHookInitMasterHost(source.config, masterHost)
|
|
14447
|
+
);
|
|
14471
14448
|
const nextMasterConfig = this.buildMasterConfigPayload(normalized, botName);
|
|
14472
14449
|
const nextWorkerConfig = this.buildWorkerConfigPayload(normalized, botName);
|
|
14473
14450
|
const nextWorkerState = this.buildSeedWorkerState({
|
|
@@ -14584,6 +14561,19 @@ var HookInitCommand = class {
|
|
|
14584
14561
|
console.log(chalk9.yellow("\u8BF7\u8F93\u5165 y \u6216 n\u3002\n"));
|
|
14585
14562
|
}
|
|
14586
14563
|
}
|
|
14564
|
+
async askMasterHost(rl, config) {
|
|
14565
|
+
const defaultHost = resolveConfiguredMasterHost(config) || resolveDefaultMasterHost();
|
|
14566
|
+
while (true) {
|
|
14567
|
+
const label = defaultHost ? `\u7B2C\u4E09\u6B65\uFF1A\u4E3B\u8282\u70B9\u5730\u5740 [\u9ED8\u8BA4 ${defaultHost}]: ` : "\u7B2C\u4E09\u6B65\uFF1A\u4E3B\u8282\u70B9\u5730\u5740: ";
|
|
14568
|
+
const answer = (await rl.question(chalk9.dim(label))).trim();
|
|
14569
|
+
const resolved = answer || defaultHost;
|
|
14570
|
+
if (resolved) {
|
|
14571
|
+
console.log("");
|
|
14572
|
+
return resolved;
|
|
14573
|
+
}
|
|
14574
|
+
console.log(chalk9.yellow("\u4E3B\u8282\u70B9\u5730\u5740\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u8BF7\u8F93\u5165 IP \u6216\u57DF\u540D\u3002\n"));
|
|
14575
|
+
}
|
|
14576
|
+
}
|
|
14587
14577
|
buildMasterConfigPayload(normalized, botName) {
|
|
14588
14578
|
return {
|
|
14589
14579
|
feishu: {
|
|
@@ -15089,28 +15079,6 @@ async function hookLogAction(query = "", options = {}) {
|
|
|
15089
15079
|
}
|
|
15090
15080
|
}
|
|
15091
15081
|
|
|
15092
|
-
// src/cli-entry.ts
|
|
15093
|
-
import path29 from "path";
|
|
15094
|
-
var AI_HOOK_COMMAND_NAMES = /* @__PURE__ */ new Set(["ai-hook", "ai-hook.cmd", "ai-hook.exe"]);
|
|
15095
|
-
var HOOK_SUBCOMMANDS = /* @__PURE__ */ new Set(["master", "init", "worker", "log", "help"]);
|
|
15096
|
-
function normalizeCliArgs(commandPath, args) {
|
|
15097
|
-
const commandName = path29.basename(commandPath || "");
|
|
15098
|
-
if (!AI_HOOK_COMMAND_NAMES.has(commandName)) {
|
|
15099
|
-
return args;
|
|
15100
|
-
}
|
|
15101
|
-
const [firstArg = "", ...restArgs] = args;
|
|
15102
|
-
if (firstArg === "hook") {
|
|
15103
|
-
return args;
|
|
15104
|
-
}
|
|
15105
|
-
if (HOOK_SUBCOMMANDS.has(firstArg)) {
|
|
15106
|
-
return ["hook", ...args];
|
|
15107
|
-
}
|
|
15108
|
-
if (!firstArg || firstArg.startsWith("-")) {
|
|
15109
|
-
return ["hook", "worker", "codex", ...args];
|
|
15110
|
-
}
|
|
15111
|
-
return ["hook", "worker", firstArg, ...restArgs];
|
|
15112
|
-
}
|
|
15113
|
-
|
|
15114
15082
|
// src/index.ts
|
|
15115
15083
|
var DEFAULT_DEST = ".agents/skills";
|
|
15116
15084
|
var WORKER_BOOLEAN_OPTIONS = /* @__PURE__ */ new Set([
|