engine7 7.1.53 → 7.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +237 -108
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1831,39 +1831,118 @@ async function ask(rl, question, defaultValue) {
|
|
|
1831
1831
|
});
|
|
1832
1832
|
});
|
|
1833
1833
|
}
|
|
1834
|
-
async function askChoice(rl, question, choices, defaultIdx = 0) {
|
|
1834
|
+
async function askChoice(rl, question, choices, defaultIdx = 0, current) {
|
|
1835
|
+
let currentIdx = -1;
|
|
1836
|
+
if (current) {
|
|
1837
|
+
currentIdx = choices.findIndex((c) => c === current || c.split(" ")[0] === current || current.startsWith(c.split(" ")[0]));
|
|
1838
|
+
}
|
|
1839
|
+
if (currentIdx >= 0) defaultIdx = currentIdx;
|
|
1835
1840
|
console.log(question);
|
|
1836
|
-
choices.forEach((c, i) => console.log(` ${i + 1}. ${c}`));
|
|
1841
|
+
choices.forEach((c, i) => console.log(` ${i + 1}. ${c}${i === currentIdx ? " \u2190\uFF08\u4E0A\u6B21\u5DF2\u9009\uFF09" : ""}`));
|
|
1837
1842
|
const answer = await ask(rl, `\u9009\u62E9 (1-${choices.length})`, String(defaultIdx + 1));
|
|
1838
1843
|
const idx = parseInt(answer, 10) - 1;
|
|
1839
1844
|
return choices[idx >= 0 && idx < choices.length ? idx : defaultIdx];
|
|
1840
1845
|
}
|
|
1841
1846
|
function getDefaultValues(stateDir) {
|
|
1847
|
+
const existing = loadExistingValues(stateDir);
|
|
1842
1848
|
return {
|
|
1843
1849
|
stateDir,
|
|
1844
|
-
agentName: "Agent",
|
|
1845
|
-
primaryProvider: "dashscope",
|
|
1846
|
-
zhipuPlan: "",
|
|
1847
|
-
primaryApiKey: "",
|
|
1848
|
-
primaryModel: "dashscope/qwen3.7-max",
|
|
1849
|
-
visionModel: "dashscope/qwen3.7-max",
|
|
1850
|
-
discordEnabled: false,
|
|
1851
|
-
discordToken: "",
|
|
1852
|
-
discordUserId: "",
|
|
1853
|
-
feishuEnabled: false,
|
|
1854
|
-
feishuAppId: "",
|
|
1855
|
-
feishuAppSecret: "",
|
|
1856
|
-
feishuOpenId: "",
|
|
1857
|
-
wechatEnabled: false,
|
|
1858
|
-
wechatToken: "",
|
|
1859
|
-
wechatAccountId: "",
|
|
1860
|
-
customBaseUrl: "",
|
|
1861
|
-
customModelId: "",
|
|
1862
|
-
customApi: "anthropic",
|
|
1863
|
-
tavilyKey: "",
|
|
1864
|
-
apiPort: 16990
|
|
1850
|
+
agentName: existing.agentName || "Agent",
|
|
1851
|
+
primaryProvider: existing.primaryProvider || "dashscope",
|
|
1852
|
+
zhipuPlan: existing.zhipuPlan || "",
|
|
1853
|
+
primaryApiKey: existing.primaryApiKey || "",
|
|
1854
|
+
primaryModel: existing.primaryModel || "dashscope/qwen3.7-max",
|
|
1855
|
+
visionModel: existing.visionModel || "dashscope/qwen3.7-max",
|
|
1856
|
+
discordEnabled: existing.discordEnabled ?? false,
|
|
1857
|
+
discordToken: existing.discordToken || "",
|
|
1858
|
+
discordUserId: existing.discordUserId || "",
|
|
1859
|
+
feishuEnabled: existing.feishuEnabled ?? false,
|
|
1860
|
+
feishuAppId: existing.feishuAppId || "",
|
|
1861
|
+
feishuAppSecret: existing.feishuAppSecret || "",
|
|
1862
|
+
feishuOpenId: existing.feishuOpenId || "",
|
|
1863
|
+
wechatEnabled: existing.wechatEnabled ?? false,
|
|
1864
|
+
wechatToken: existing.wechatToken || "",
|
|
1865
|
+
wechatAccountId: existing.wechatAccountId || "",
|
|
1866
|
+
customBaseUrl: existing.customBaseUrl || "",
|
|
1867
|
+
customModelId: existing.customModelId || "",
|
|
1868
|
+
customApi: existing.customApi || "anthropic",
|
|
1869
|
+
tavilyKey: existing.tavilyKey || "",
|
|
1870
|
+
apiPort: existing.apiPort || 16990
|
|
1865
1871
|
};
|
|
1866
1872
|
}
|
|
1873
|
+
function loadExistingValues(stateDir) {
|
|
1874
|
+
const configPath = path3.join(stateDir, "configs", "main7.json");
|
|
1875
|
+
try {
|
|
1876
|
+
if (!fs3.existsSync(configPath)) return {};
|
|
1877
|
+
const j = JSON.parse(fs3.readFileSync(configPath, "utf8"));
|
|
1878
|
+
const out = {};
|
|
1879
|
+
if (j.agents?.defaults?.name) out.agentName = j.agents.defaults.name;
|
|
1880
|
+
const providers = j.models?.providers || {};
|
|
1881
|
+
const firstId = Object.keys(providers)[0];
|
|
1882
|
+
if (firstId) {
|
|
1883
|
+
out.primaryProvider = firstId;
|
|
1884
|
+
const p = providers[firstId];
|
|
1885
|
+
const keyRef = typeof p?.apiKey === "string" ? p.apiKey : "";
|
|
1886
|
+
if (keyRef.startsWith("env:")) {
|
|
1887
|
+
const envName = keyRef.slice(4);
|
|
1888
|
+
out.primaryApiKey = readSecretsValue(stateDir, envName) || "";
|
|
1889
|
+
} else if (keyRef && !keyRef.startsWith("env:")) {
|
|
1890
|
+
out.primaryApiKey = keyRef;
|
|
1891
|
+
}
|
|
1892
|
+
if (p?.baseUrl && !["dashscope", "minimax", "zhipu", "deepseek"].includes(firstId)) {
|
|
1893
|
+
out.customBaseUrl = p.baseUrl;
|
|
1894
|
+
out.customApi = p.api || "anthropic";
|
|
1895
|
+
}
|
|
1896
|
+
const firstModel = p?.models?.[0]?.id;
|
|
1897
|
+
if (firstModel) {
|
|
1898
|
+
out.primaryModel = `${firstId}/${firstModel}`;
|
|
1899
|
+
out.customModelId = ["dashscope", "minimax", "zhipu", "deepseek"].includes(firstId) ? "" : firstModel;
|
|
1900
|
+
}
|
|
1901
|
+
if (j.agents?.defaults?.model?.vision) out.visionModel = j.agents.defaults.model.vision;
|
|
1902
|
+
}
|
|
1903
|
+
if (j.channels?.discord) {
|
|
1904
|
+
out.discordEnabled = !!j.channels.discord.enabled;
|
|
1905
|
+
out.discordToken = j.channels.discord.accounts?.default?.token || "";
|
|
1906
|
+
}
|
|
1907
|
+
if (j.channels?.feishu) {
|
|
1908
|
+
out.feishuEnabled = !!j.channels.feishu.enabled;
|
|
1909
|
+
out.feishuAppId = j.channels.feishu.appId || "";
|
|
1910
|
+
out.feishuAppSecret = j.channels.feishu.appSecret || "";
|
|
1911
|
+
}
|
|
1912
|
+
if (j.channels?.wechat) {
|
|
1913
|
+
out.wechatEnabled = !!j.channels.wechat.enabled;
|
|
1914
|
+
out.wechatToken = j.channels.wechat.token || "";
|
|
1915
|
+
out.wechatAccountId = j.channels.wechat.accountId || "";
|
|
1916
|
+
}
|
|
1917
|
+
if (j.tools?.tavily?.apiKey) out.tavilyKey = j.tools.tavily.apiKey;
|
|
1918
|
+
if (j.api?.port) out.apiPort = j.api.port;
|
|
1919
|
+
return out;
|
|
1920
|
+
} catch {
|
|
1921
|
+
return {};
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
function readSecretsValue(stateDir, envName) {
|
|
1925
|
+
try {
|
|
1926
|
+
const secretsDir = path3.join(process.env.HOME || process.env.USERPROFILE || ".", ".engine7-secrets");
|
|
1927
|
+
const cfgBase = path3.basename(stateDir) === ".engine7" ? "main7" : path3.basename(stateDir);
|
|
1928
|
+
const candidates = [
|
|
1929
|
+
path3.join(secretsDir, `${cfgBase}.env`),
|
|
1930
|
+
path3.join(stateDir, "configs", `.env.${cfgBase}`)
|
|
1931
|
+
];
|
|
1932
|
+
for (const p of candidates) {
|
|
1933
|
+
if (fs3.existsSync(p)) {
|
|
1934
|
+
for (const line of fs3.readFileSync(p, "utf8").split("\n")) {
|
|
1935
|
+
const eq = line.indexOf("=");
|
|
1936
|
+
if (eq > 0 && line.slice(0, eq).trim() === envName) {
|
|
1937
|
+
return line.slice(eq + 1).trim();
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
} catch {
|
|
1943
|
+
}
|
|
1944
|
+
return "";
|
|
1945
|
+
}
|
|
1867
1946
|
async function interactiveConfig(rl, defaults) {
|
|
1868
1947
|
const v = { ...defaults };
|
|
1869
1948
|
console.log("\n=== \u7B2C\u4E00\u6B65\uFF1A\u5FC5\u586B\u914D\u7F6E ===\n");
|
|
@@ -1876,25 +1955,35 @@ async function interactiveConfig(rl, defaults) {
|
|
|
1876
1955
|
"deepseek (DeepSeek)": "deepseek",
|
|
1877
1956
|
"custom (\u81EA\u5B9A\u4E49/\u5176\u4ED6 Anthropic \u517C\u5BB9\u7AEF\u70B9)": "custom"
|
|
1878
1957
|
};
|
|
1879
|
-
const chosenProvider = await askChoice(rl, "\u4E3B\u6A21\u578B Provider:", providers, 0);
|
|
1958
|
+
const chosenProvider = await askChoice(rl, "\u4E3B\u6A21\u578B Provider:", providers, 0, defaults.primaryProvider);
|
|
1880
1959
|
v.primaryProvider = providerMap[chosenProvider] || "dashscope";
|
|
1881
1960
|
v.zhipuPlan = "";
|
|
1882
1961
|
if (v.primaryProvider === "zhipu") {
|
|
1883
1962
|
const planOptions = ["coding-plan (GLM Coding \u8BA2\u9605\uFF0C\u5305\u6708)", "api-pay (API \u6309\u91CF\u4ED8\u8D39)"];
|
|
1884
|
-
const chosenPlan = await askChoice(rl, "\u667A\u8C31\u8BA2\u9605\u7C7B\u578B:", planOptions, 0);
|
|
1963
|
+
const chosenPlan = await askChoice(rl, "\u667A\u8C31\u8BA2\u9605\u7C7B\u578B:", planOptions, 0, defaults.zhipuPlan === "token" ? "api-pay" : defaults.zhipuPlan === "coding" ? "coding-plan" : void 0);
|
|
1885
1964
|
v.zhipuPlan = chosenPlan.startsWith("coding") ? "coding" : "token";
|
|
1886
1965
|
}
|
|
1887
1966
|
v.customBaseUrl = "";
|
|
1888
1967
|
v.customModelId = "";
|
|
1889
1968
|
v.customApi = "anthropic";
|
|
1890
1969
|
if (v.primaryProvider === "custom") {
|
|
1891
|
-
|
|
1970
|
+
const isKnownCustom = defaults.primaryProvider !== "dashscope" && defaults.primaryProvider !== "minimax" && defaults.primaryProvider !== "zhipu" && defaults.primaryProvider !== "deepseek";
|
|
1971
|
+
v.primaryProvider = await ask(rl, "Provider ID\uFF08\u5C0F\u5199\u5B57\u6BCD\uFF0C\u5982 kimi / moonshot / openrouter / zai\uFF09", isKnownCustom ? defaults.primaryProvider : "custom");
|
|
1892
1972
|
const apiOptions = ["anthropic (Anthropic \u517C\u5BB9\uFF0C\u63A8\u8350)", "openai-completions (OpenAI \u517C\u5BB9 /v1/chat/completions)"];
|
|
1893
|
-
const chosenApi = await askChoice(rl, "API \u7C7B\u578B:", apiOptions, 0);
|
|
1973
|
+
const chosenApi = await askChoice(rl, "API \u7C7B\u578B:", apiOptions, 0, defaults.customApi || void 0);
|
|
1894
1974
|
v.customApi = chosenApi.startsWith("anthropic") ? "anthropic" : "openai-completions";
|
|
1895
1975
|
const baseUrlExample = v.customApi === "anthropic" ? "\uFF08\u5982 https://api.moonshot.cn/anthropic\uFF09" : "\uFF08\u5982 https://api.deepinfra.com/v1/openai\uFF09";
|
|
1896
|
-
v.customBaseUrl = await ask(rl,
|
|
1897
|
-
v.
|
|
1976
|
+
v.customBaseUrl = await ask(rl, `baseUrl ${baseUrlExample}`, defaults.customBaseUrl || "");
|
|
1977
|
+
while (v.customBaseUrl) {
|
|
1978
|
+
try {
|
|
1979
|
+
new URL(v.customBaseUrl);
|
|
1980
|
+
break;
|
|
1981
|
+
} catch {
|
|
1982
|
+
console.log(`\u26A0\uFE0F \u65E0\u6548 URL\uFF1A\u300C${v.customBaseUrl}\u300D\u2014\u2014\u68C0\u67E5\u62FC\u5199\u3001\u534F\u8BAE\u5934\uFF08https://\uFF09\u3001\u6709\u6CA1\u6709\u591A\u4F59\u7A7A\u683C\u6216\u659C\u6760`);
|
|
1983
|
+
v.customBaseUrl = await ask(rl, `baseUrl ${baseUrlExample}`, "");
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
v.customModelId = await ask(rl, "\u6A21\u578B ID\uFF08\u5982 kimi-k2-turbo-preview\uFF09", defaults.customModelId || "");
|
|
1898
1987
|
}
|
|
1899
1988
|
const keyMap = {
|
|
1900
1989
|
dashscope: "DashScope API Key",
|
|
@@ -1902,7 +1991,9 @@ async function interactiveConfig(rl, defaults) {
|
|
|
1902
1991
|
zhipu: "\u667A\u8C31 API Key",
|
|
1903
1992
|
deepseek: "DeepSeek API Key"
|
|
1904
1993
|
};
|
|
1905
|
-
|
|
1994
|
+
const existingKeyHint = defaults.primaryApiKey ? `(\u5F53\u524D: ${defaults.primaryApiKey.slice(0, 8)}...${defaults.primaryApiKey.slice(-4)}\uFF0C\u56DE\u8F66\u4FDD\u7559)` : "";
|
|
1995
|
+
const keyAns = await ask(rl, `${keyMap[v.primaryProvider] || v.primaryProvider + " API Key"} ${existingKeyHint}`, defaults.primaryApiKey || "");
|
|
1996
|
+
v.primaryApiKey = keyAns || defaults.primaryApiKey || "";
|
|
1906
1997
|
const modelMap = {
|
|
1907
1998
|
dashscope: ["dashscope/qwen3.7-max", "dashscope/qwen3.7-plus"],
|
|
1908
1999
|
minimax: ["minimax/MiniMax-M3", "minimax/MiniMax-M2.7"],
|
|
@@ -1913,7 +2004,7 @@ async function interactiveConfig(rl, defaults) {
|
|
|
1913
2004
|
v.primaryModel = v.primaryProvider + "/" + v.customModelId;
|
|
1914
2005
|
} else if (modelMap[v.primaryProvider]) {
|
|
1915
2006
|
const models = modelMap[v.primaryProvider];
|
|
1916
|
-
v.primaryModel = await askChoice(rl, "\u4E3B\u6A21\u578B:", models, 0);
|
|
2007
|
+
v.primaryModel = await askChoice(rl, "\u4E3B\u6A21\u578B:", models, 0, defaults.primaryModel || void 0);
|
|
1917
2008
|
} else {
|
|
1918
2009
|
console.log("\u26A0\uFE0F \u8FD8\u7F3A\u6A21\u578B ID\uFF0C\u8865\u4E00\u4E0B\uFF1A");
|
|
1919
2010
|
v.customModelId = await ask(rl, "\u6A21\u578B ID\uFF08\u5982 glm-5.3 / kimi-k2-turbo-preview\uFF09");
|
|
@@ -1939,101 +2030,132 @@ async function interactiveConfig(rl, defaults) {
|
|
|
1939
2030
|
console.log(` \u6CE8\u610F\uFF1AVision \u6A21\u578B\u7528\u4E86\u4E0D\u540C provider\uFF0C\u9700\u8981\u5728 config \u91CC\u8865\u5145\u5BF9\u5E94\u7684 API key`);
|
|
1940
2031
|
}
|
|
1941
2032
|
}
|
|
1942
|
-
console.log("\n=== \u7B2C\u4E8C\u6B65\uFF1A\u53EF\u9009\u914D\u7F6E\uFF08\u56DE\u8F66\u8DF3\u8FC7\uFF09===\n");
|
|
1943
|
-
const discordAns = await ask(rl, "\u542F\u7528 Discord? (y/n)", "n");
|
|
2033
|
+
console.log("\n=== \u7B2C\u4E8C\u6B65\uFF1A\u53EF\u9009\u914D\u7F6E\uFF08\u56DE\u8F66\u8DF3\u8FC7\uFF0C\u5DF2\u542F\u7528\u7684\u56DE\u8F66\u4FDD\u7559\uFF09===\n");
|
|
2034
|
+
const discordAns = await ask(rl, "\u542F\u7528 Discord? (y/n)", defaults.discordEnabled ? "y" : "n");
|
|
1944
2035
|
v.discordEnabled = discordAns.toLowerCase() === "y";
|
|
1945
2036
|
if (v.discordEnabled) {
|
|
1946
|
-
v.discordToken = await ask(rl,
|
|
1947
|
-
v.discordUserId = await ask(rl, "\u4F60\u7684 Discord User ID");
|
|
2037
|
+
v.discordToken = await ask(rl, `Discord Bot Token${defaults.discordToken ? ` (\u5F53\u524D: ${defaults.discordToken.slice(0, 12)}...\uFF0C\u56DE\u8F66\u4FDD\u7559)` : ""}`, defaults.discordToken || "");
|
|
2038
|
+
v.discordUserId = await ask(rl, "\u4F60\u7684 Discord User ID", defaults.discordUserId || "");
|
|
1948
2039
|
}
|
|
1949
|
-
const feishuAns = await ask(rl, "\u542F\u7528\u98DE\u4E66? (y/n)", "n");
|
|
2040
|
+
const feishuAns = await ask(rl, "\u542F\u7528\u98DE\u4E66? (y/n)", defaults.feishuEnabled ? "y" : "n");
|
|
1950
2041
|
v.feishuEnabled = feishuAns.toLowerCase() === "y";
|
|
1951
2042
|
if (v.feishuEnabled) {
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
2043
|
+
if (defaults.feishuAppId && defaults.feishuAppSecret) {
|
|
2044
|
+
console.log(`
|
|
2045
|
+
\u5F53\u524D\u5DF2\u914D\u7F6E\u98DE\u4E66: App ID ${defaults.feishuAppId}`);
|
|
2046
|
+
const keep = await ask(rl, "\u4FDD\u7559\u73B0\u6709\u98DE\u4E66\u914D\u7F6E? (y=\u4FDD\u7559\u56DE\u8F66\u9ED8\u8BA4/n=\u91CD\u65B0\u626B\u7801)", "y");
|
|
2047
|
+
if (keep.toLowerCase() !== "n") {
|
|
2048
|
+
v.feishuAppId = defaults.feishuAppId;
|
|
2049
|
+
v.feishuAppSecret = defaults.feishuAppSecret;
|
|
2050
|
+
v.feishuOpenId = defaults.feishuOpenId || "";
|
|
2051
|
+
console.log(" \u2705 \u4FDD\u7559\u73B0\u6709\u98DE\u4E66\u914D\u7F6E");
|
|
2052
|
+
} else {
|
|
2053
|
+
await configureFeishu(rl, v);
|
|
2054
|
+
}
|
|
2055
|
+
} else {
|
|
2056
|
+
await configureFeishu(rl, v);
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
const wechatAns = await ask(rl, "\u542F\u7528\u5FAE\u4FE1? (y/n)", defaults.wechatEnabled ? "y" : "n");
|
|
2060
|
+
v.wechatEnabled = wechatAns.toLowerCase() === "y";
|
|
2061
|
+
if (v.wechatEnabled) {
|
|
2062
|
+
if (defaults.wechatToken && defaults.wechatAccountId) {
|
|
2063
|
+
console.log(`
|
|
2064
|
+
\u5F53\u524D\u5DF2\u914D\u7F6E\u5FAE\u4FE1: ${defaults.wechatAccountId}`);
|
|
2065
|
+
const keep = await ask(rl, "\u4FDD\u7559\u73B0\u6709\u5FAE\u4FE1\u914D\u7F6E? (y=\u4FDD\u7559/n=\u91CD\u65B0\u626B\u7801)", "y");
|
|
2066
|
+
if (keep.toLowerCase() !== "n") {
|
|
2067
|
+
v.wechatToken = defaults.wechatToken;
|
|
2068
|
+
v.wechatAccountId = defaults.wechatAccountId;
|
|
2069
|
+
console.log(" \u2705 \u4FDD\u7559\u73B0\u6709\u5FAE\u4FE1\u914D\u7F6E");
|
|
2070
|
+
} else {
|
|
2071
|
+
await configureWechat(rl, v);
|
|
2072
|
+
}
|
|
2073
|
+
} else {
|
|
2074
|
+
await configureWechat(rl, v);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
const tavilyKey = await ask(rl, `Tavily API Key\uFF08\u8054\u7F51\u641C\u7D22${defaults.tavilyKey ? `\uFF0C\u5F53\u524D: ${defaults.tavilyKey.slice(0, 8)}...\uFF0C\u56DE\u8F66\u4FDD\u7559` : "\uFF0C\u56DE\u8F66\u8DF3\u8FC7"}\uFF09`, defaults.tavilyKey || "");
|
|
2078
|
+
v.tavilyKey = tavilyKey;
|
|
2079
|
+
const portAns = await ask(rl, "API \u7AEF\u53E3", String(defaults.apiPort));
|
|
2080
|
+
v.apiPort = parseInt(portAns, 10) || defaults.apiPort;
|
|
2081
|
+
return v;
|
|
2082
|
+
}
|
|
2083
|
+
async function configureFeishu(rl, v) {
|
|
2084
|
+
console.log("\n \u98DE\u4E66\u914D\u7F6E\u65B9\u5F0F\uFF1A");
|
|
2085
|
+
console.log(" 1. \u626B\u7801\u81EA\u52A8\u521B\u5EFA\uFF08\u63A8\u8350\uFF0C30\u79D2\u641E\u5B9A\uFF09");
|
|
2086
|
+
console.log(" 2. \u624B\u52A8\u8F93\u5165 App ID / App Secret");
|
|
2087
|
+
const feishuMode = await ask(rl, "\u9009\u62E9 (1/2)", "1");
|
|
2088
|
+
if (feishuMode === "1") {
|
|
2089
|
+
console.log("\n\u{1F4DD} \u6B63\u5728\u751F\u6210\u98DE\u4E66\u4E8C\u7EF4\u7801...\n");
|
|
2090
|
+
const result = await registerFeishuApp({
|
|
2091
|
+
onLog: (msg) => console.log(` ${msg}`),
|
|
2092
|
+
onQrCode: async (url) => {
|
|
2093
|
+
try {
|
|
2094
|
+
const qr = await renderQrTerminal(url, { small: true });
|
|
2095
|
+
console.log(qr);
|
|
2096
|
+
} catch {
|
|
2097
|
+
console.log(`
|
|
1966
2098
|
\u8BF7\u5728\u624B\u673A\u6D4F\u89C8\u5668\u6253\u5F00\u6B64\u94FE\u63A5\u626B\u7801\uFF1A
|
|
1967
2099
|
${url}
|
|
1968
2100
|
`);
|
|
1969
|
-
}
|
|
1970
2101
|
}
|
|
1971
|
-
});
|
|
1972
|
-
if (result) {
|
|
1973
|
-
v.feishuAppId = result.appId;
|
|
1974
|
-
v.feishuAppSecret = result.appSecret;
|
|
1975
|
-
v.feishuOpenId = result.openId || "";
|
|
1976
|
-
console.log(`
|
|
1977
|
-
\u2705 App ID: ${result.appId}`);
|
|
1978
|
-
console.log(` \u2705 App Secret: ${result.appSecret.slice(0, 6)}...`);
|
|
1979
|
-
if (result.openId) {
|
|
1980
|
-
console.log(` \u2705 Open ID: ${result.openId}`);
|
|
1981
|
-
}
|
|
1982
|
-
} else {
|
|
1983
|
-
console.log("\n \u26A0\uFE0F \u626B\u7801\u8D85\u65F6\u6216\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u8F93\u5165");
|
|
1984
|
-
v.feishuAppId = await ask(rl, "\u98DE\u4E66 App ID");
|
|
1985
|
-
v.feishuAppSecret = await ask(rl, "\u98DE\u4E66 App Secret");
|
|
1986
|
-
v.feishuOpenId = await ask(rl, "\u4F60\u7684\u98DE\u4E66 open_id\uFF08\u56DE\u8F66\u8DF3\u8FC7\uFF09", "");
|
|
1987
2102
|
}
|
|
2103
|
+
});
|
|
2104
|
+
if (result) {
|
|
2105
|
+
v.feishuAppId = result.appId;
|
|
2106
|
+
v.feishuAppSecret = result.appSecret;
|
|
2107
|
+
v.feishuOpenId = result.openId || "";
|
|
2108
|
+
console.log(`
|
|
2109
|
+
\u2705 App ID: ${result.appId}`);
|
|
2110
|
+
console.log(` \u2705 App Secret: ${result.appSecret.slice(0, 6)}...`);
|
|
2111
|
+
if (result.openId) console.log(` \u2705 Open ID: ${result.openId}`);
|
|
1988
2112
|
} else {
|
|
2113
|
+
console.log("\n \u26A0\uFE0F \u626B\u7801\u8D85\u65F6\u6216\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u8F93\u5165");
|
|
1989
2114
|
v.feishuAppId = await ask(rl, "\u98DE\u4E66 App ID");
|
|
1990
2115
|
v.feishuAppSecret = await ask(rl, "\u98DE\u4E66 App Secret");
|
|
1991
2116
|
v.feishuOpenId = await ask(rl, "\u4F60\u7684\u98DE\u4E66 open_id\uFF08\u56DE\u8F66\u8DF3\u8FC7\uFF09", "");
|
|
1992
2117
|
}
|
|
1993
|
-
}
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2118
|
+
} else {
|
|
2119
|
+
v.feishuAppId = await ask(rl, "\u98DE\u4E66 App ID");
|
|
2120
|
+
v.feishuAppSecret = await ask(rl, "\u98DE\u4E66 App Secret");
|
|
2121
|
+
v.feishuOpenId = await ask(rl, "\u4F60\u7684\u98DE\u4E66 open_id\uFF08\u56DE\u8F66\u8DF3\u8FC7\uFF09", "");
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
async function configureWechat(rl, v) {
|
|
2125
|
+
console.log("\n \u5FAE\u4FE1\u63A5\u5165\u65B9\u5F0F\uFF1A");
|
|
2126
|
+
console.log(" 1. \u626B\u7801\u7ED1\u5B9A\uFF08\u63A8\u8350\uFF0C\u7528\u4F60\u81EA\u5DF1\u7684\u5FAE\u4FE1\u626B\u4E00\u4E0B\u5C31\u884C\uFF09");
|
|
2127
|
+
console.log(" 2. \u624B\u52A8\u8F93\u5165 token\uFF08\u5DF2\u6709\u51ED\u8BC1\u65F6\uFF09");
|
|
2128
|
+
const wechatMode = await ask(rl, "\u9009\u62E9 (1/2)", "1");
|
|
2129
|
+
if (wechatMode === "1") {
|
|
2130
|
+
console.log("\n\u{1F4DD} \u6B63\u5728\u751F\u6210\u5FAE\u4FE1\u4E8C\u7EF4\u7801...\n");
|
|
2131
|
+
console.log(" \u63D0\u793A\uFF1A\u4E00\u4E2A\u5FAE\u4FE1\u53F7\u53EA\u80FD\u7ED1\u4E00\u4E2A bot\uFF1Bbot \u4E0D\u8FDB\u7FA4\uFF08\u817E\u8BAF\u9650\u5236\uFF09\uFF0C\u79C1\u804A 1v1");
|
|
2132
|
+
const cred = await wechatQrLogin({ timeoutSeconds: 300, stateDir: v.stateDir });
|
|
2133
|
+
if (cred) {
|
|
2134
|
+
v.wechatToken = cred.token;
|
|
2135
|
+
v.wechatAccountId = cred.accountId;
|
|
2136
|
+
console.log(`
|
|
2009
2137
|
\u2705 accountId: ${cred.accountId}`);
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
} else {
|
|
2020
|
-
console.log("\n \u26A0\uFE0F \u518D\u6B21\u5931\u8D25\uFF0C\u8DF3\u8FC7\u5FAE\u4FE1\uFF08\u4E4B\u540E\u53EF\u624B\u52A8\u914D\u7F6E\uFF09");
|
|
2021
|
-
v.wechatEnabled = false;
|
|
2022
|
-
}
|
|
2138
|
+
console.log(` \u2705 \u51ED\u8BC1\u5DF2\u81EA\u52A8\u4FDD\u5B58\uFF0Cconfig \u5C06\u81EA\u52A8\u5199\u5165`);
|
|
2139
|
+
} else {
|
|
2140
|
+
console.log("\n \u26A0\uFE0F \u626B\u7801\u8D85\u65F6\u6216\u5931\u8D25");
|
|
2141
|
+
const retry = await ask(rl, "\u91CD\u8BD5\u626B\u7801? (y/n)", "y");
|
|
2142
|
+
if (retry.toLowerCase() === "y") {
|
|
2143
|
+
const cred2 = await wechatQrLogin({ timeoutSeconds: 300, stateDir: v.stateDir });
|
|
2144
|
+
if (cred2) {
|
|
2145
|
+
v.wechatToken = cred2.token;
|
|
2146
|
+
v.wechatAccountId = cred2.accountId;
|
|
2023
2147
|
} else {
|
|
2148
|
+
console.log("\n \u26A0\uFE0F \u518D\u6B21\u5931\u8D25\uFF0C\u8DF3\u8FC7\u5FAE\u4FE1\uFF08\u4E4B\u540E\u53EF\u624B\u52A8\u914D\u7F6E\uFF09");
|
|
2024
2149
|
v.wechatEnabled = false;
|
|
2025
2150
|
}
|
|
2151
|
+
} else {
|
|
2152
|
+
v.wechatEnabled = false;
|
|
2026
2153
|
}
|
|
2027
|
-
} else {
|
|
2028
|
-
v.wechatToken = await ask(rl, "\u5FAE\u4FE1 token");
|
|
2029
|
-
v.wechatAccountId = await ask(rl, "\u5FAE\u4FE1 accountId");
|
|
2030
2154
|
}
|
|
2155
|
+
} else {
|
|
2156
|
+
v.wechatToken = await ask(rl, "\u5FAE\u4FE1 token");
|
|
2157
|
+
v.wechatAccountId = await ask(rl, "\u5FAE\u4FE1 accountId");
|
|
2031
2158
|
}
|
|
2032
|
-
const tavilyKey = await ask(rl, "Tavily API Key\uFF08\u8054\u7F51\u641C\u7D22\uFF0C\u56DE\u8F66\u8DF3\u8FC7\uFF09", "");
|
|
2033
|
-
v.tavilyKey = tavilyKey;
|
|
2034
|
-
const portAns = await ask(rl, "API \u7AEF\u53E3", String(defaults.apiPort));
|
|
2035
|
-
v.apiPort = parseInt(portAns, 10) || defaults.apiPort;
|
|
2036
|
-
return v;
|
|
2037
2159
|
}
|
|
2038
2160
|
function generateConfig(v) {
|
|
2039
2161
|
const workspace = path3.join(v.stateDir, "workspace").replace(/\\/g, "/");
|
|
@@ -3097,11 +3219,18 @@ WantedBy=default.target`;
|
|
|
3097
3219
|
\u26A0\uFE0F --force: \u6E05\u7A7A\u5DF2\u6709\u76EE\u5F55 ${opts.stateDir}`);
|
|
3098
3220
|
fs3.rmSync(opts.stateDir, { recursive: true, force: true });
|
|
3099
3221
|
} else {
|
|
3100
|
-
|
|
3222
|
+
const existingConfig = path3.join(opts.stateDir, "configs", "main7.json");
|
|
3223
|
+
if (fs3.existsSync(existingConfig)) {
|
|
3224
|
+
console.log(`
|
|
3225
|
+
\u267B\uFE0F \u68C0\u6D4B\u5230\u5DF2\u6709\u914D\u7F6E: ${existingConfig}`);
|
|
3226
|
+
console.log(` \u2192 \u590D\u8DD1\u6A21\u5F0F\uFF1A\u663E\u793A\u73B0\u6709\u914D\u7F6E\uFF0C\u56DE\u8F66\u4FDD\u7559\uFF0C\u6539\u4E86\u624D\u751F\u6548\uFF08\u4E0D\u4F1A\u6E05\u7A7A\u76EE\u5F55\uFF09`);
|
|
3227
|
+
} else {
|
|
3228
|
+
console.error(`
|
|
3101
3229
|
\u274C \u76EE\u5F55\u5DF2\u5B58\u5728\u4E14\u975E\u7A7A: ${opts.stateDir}`);
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3230
|
+
console.error(` \u8BF7\u9009\u62E9\u7A7A\u76EE\u5F55\uFF0C\u6216\u7528 --force \u6E05\u7A7A\u540E\u91CD\u65B0\u914D\u7F6E`);
|
|
3231
|
+
console.error(` \u4F8B: engine7 init --force`);
|
|
3232
|
+
process.exit(1);
|
|
3233
|
+
}
|
|
3105
3234
|
}
|
|
3106
3235
|
}
|
|
3107
3236
|
}
|