@nick848/sf-cli 1.0.12 → 1.0.14
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/CHANGELOG.md +49 -0
- package/dist/cli/index.js +184 -51
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +156 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +156 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1985,6 +1985,7 @@ var ClaudeAdapter = class extends BaseAdapter {
|
|
|
1985
1985
|
};
|
|
1986
1986
|
|
|
1987
1987
|
// src/services/adapters/index.ts
|
|
1988
|
+
var DEEPSEEK_API_ENDPOINT = "https://api.deepseek.com/v1";
|
|
1988
1989
|
function createAdapter(provider) {
|
|
1989
1990
|
switch (provider) {
|
|
1990
1991
|
case "glm":
|
|
@@ -2003,6 +2004,8 @@ function createAdapter(provider) {
|
|
|
2003
2004
|
}
|
|
2004
2005
|
function createDeepSeekAdapter() {
|
|
2005
2006
|
const adapter = new OpenAIAdapter();
|
|
2007
|
+
let initialized = false;
|
|
2008
|
+
let config = null;
|
|
2006
2009
|
return {
|
|
2007
2010
|
get name() {
|
|
2008
2011
|
return "DeepSeek";
|
|
@@ -2013,12 +2016,38 @@ function createDeepSeekAdapter() {
|
|
|
2013
2016
|
get models() {
|
|
2014
2017
|
return adapter.models;
|
|
2015
2018
|
},
|
|
2016
|
-
initialize
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2019
|
+
async initialize(modelConfig) {
|
|
2020
|
+
config = {
|
|
2021
|
+
...modelConfig,
|
|
2022
|
+
apiEndpoint: DEEPSEEK_API_ENDPOINT
|
|
2023
|
+
};
|
|
2024
|
+
await adapter.initialize(config);
|
|
2025
|
+
initialized = true;
|
|
2026
|
+
},
|
|
2027
|
+
async sendMessage(messages, options) {
|
|
2028
|
+
return adapter.sendMessage(messages, options);
|
|
2029
|
+
},
|
|
2030
|
+
async *streamMessage(messages, options) {
|
|
2031
|
+
yield* adapter.streamMessage(messages, options);
|
|
2032
|
+
},
|
|
2033
|
+
countTokens(text) {
|
|
2034
|
+
return adapter.countTokens(text);
|
|
2035
|
+
},
|
|
2036
|
+
async validateApiKey(apiKey) {
|
|
2037
|
+
try {
|
|
2038
|
+
const response = await fetch(`${DEEPSEEK_API_ENDPOINT}/models`, {
|
|
2039
|
+
headers: {
|
|
2040
|
+
"Authorization": `Bearer ${apiKey}`
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
return response.ok;
|
|
2044
|
+
} catch {
|
|
2045
|
+
return false;
|
|
2046
|
+
}
|
|
2047
|
+
},
|
|
2048
|
+
isInitialized() {
|
|
2049
|
+
return initialized;
|
|
2050
|
+
}
|
|
2022
2051
|
};
|
|
2023
2052
|
}
|
|
2024
2053
|
var ModelService = class {
|
|
@@ -8860,7 +8889,7 @@ async function executeShell(command, ctx) {
|
|
|
8860
8889
|
init_esm_shims();
|
|
8861
8890
|
init_new();
|
|
8862
8891
|
async function handleNaturalLanguage(input, ctx) {
|
|
8863
|
-
input.trim()
|
|
8892
|
+
const trimmedInput = input.trim();
|
|
8864
8893
|
const session = getActiveSession();
|
|
8865
8894
|
if (session) {
|
|
8866
8895
|
const result = await handleWorkflowInput(input, ctx);
|
|
@@ -8871,81 +8900,163 @@ async function handleNaturalLanguage(input, ctx) {
|
|
|
8871
8900
|
};
|
|
8872
8901
|
}
|
|
8873
8902
|
}
|
|
8874
|
-
ctx.
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8903
|
+
const apiKey = ctx.configManager.get("apiKey");
|
|
8904
|
+
if (!apiKey) {
|
|
8905
|
+
return {
|
|
8906
|
+
output: chalk9.yellow("\u26A0\uFE0F \u672A\u914D\u7F6E API Key\uFF0C\u65E0\u6CD5\u4F7F\u7528 AI \u529F\u80FD") + chalk9.gray("\n\n\u8BF7\u5148\u6267\u884C /model \u914D\u7F6E\u6A21\u578B") + chalk9.gray("\n\u652F\u6301: GLM-5, GPT-4o, Claude"),
|
|
8907
|
+
contextUsed: 0
|
|
8908
|
+
};
|
|
8909
|
+
}
|
|
8910
|
+
try {
|
|
8911
|
+
const response = await ctx.modelService.sendMessage(
|
|
8912
|
+
[
|
|
8913
|
+
{
|
|
8914
|
+
role: "system",
|
|
8915
|
+
content: buildSystemPrompt(ctx)
|
|
8916
|
+
},
|
|
8917
|
+
{
|
|
8918
|
+
role: "user",
|
|
8919
|
+
content: trimmedInput
|
|
8920
|
+
}
|
|
8921
|
+
],
|
|
8922
|
+
{
|
|
8923
|
+
temperature: 0.7,
|
|
8924
|
+
maxTokens: 2e3
|
|
8925
|
+
}
|
|
8926
|
+
);
|
|
8927
|
+
ctx.contextManager.addMessage({
|
|
8928
|
+
role: "user",
|
|
8929
|
+
content: trimmedInput
|
|
8930
|
+
});
|
|
8931
|
+
ctx.contextManager.addMessage({
|
|
8932
|
+
role: "assistant",
|
|
8933
|
+
content: response.content
|
|
8934
|
+
});
|
|
8935
|
+
return {
|
|
8936
|
+
output: response.content,
|
|
8937
|
+
contextUsed: response.usage?.totalTokens || 0
|
|
8938
|
+
};
|
|
8939
|
+
} catch (error) {
|
|
8940
|
+
const errorMessage = error.message;
|
|
8941
|
+
if (errorMessage.includes("\u672A\u914D\u7F6E") || errorMessage.includes("\u672A\u521D\u59CB\u5316")) {
|
|
8942
|
+
return {
|
|
8943
|
+
output: chalk9.yellow("\u26A0\uFE0F \u6A21\u578B\u672A\u6B63\u786E\u914D\u7F6E") + chalk9.gray("\n\n\u8BF7\u6267\u884C /model \u91CD\u65B0\u914D\u7F6E"),
|
|
8944
|
+
contextUsed: 0
|
|
8945
|
+
};
|
|
8946
|
+
}
|
|
8947
|
+
if (errorMessage.includes("timeout") || errorMessage.includes("\u8D85\u65F6")) {
|
|
8948
|
+
return {
|
|
8949
|
+
output: chalk9.red("\u2717 \u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"),
|
|
8950
|
+
contextUsed: 0
|
|
8951
|
+
};
|
|
8952
|
+
}
|
|
8953
|
+
return {
|
|
8954
|
+
output: chalk9.red(`\u2717 \u5904\u7406\u5931\u8D25: ${errorMessage}`),
|
|
8955
|
+
contextUsed: 0
|
|
8956
|
+
};
|
|
8957
|
+
}
|
|
8958
|
+
}
|
|
8959
|
+
function buildSystemPrompt(ctx) {
|
|
8960
|
+
const parts = [
|
|
8961
|
+
"\u4F60\u662F sf-cli \u7684 AI \u52A9\u624B\uFF0C\u4E00\u4E2A\u4E13\u4E1A\u7684\u8F6F\u4EF6\u5F00\u53D1\u52A9\u624B\u3002",
|
|
8962
|
+
"",
|
|
8963
|
+
"\u4F60\u53EF\u4EE5\u5E2E\u52A9\u7528\u6237\uFF1A",
|
|
8964
|
+
"1. \u7406\u89E3\u548C\u5206\u6790\u9700\u6C42",
|
|
8965
|
+
"2. \u63D0\u4F9B\u4EE3\u7801\u5EFA\u8BAE\u548C\u5B9E\u73B0\u65B9\u6848",
|
|
8966
|
+
"3. \u56DE\u7B54\u6280\u672F\u95EE\u9898",
|
|
8967
|
+
"4. \u8F85\u52A9\u8FDB\u884C\u4EE3\u7801\u5BA1\u67E5",
|
|
8968
|
+
"",
|
|
8969
|
+
"\u5F53\u524D\u9879\u76EE\u4FE1\u606F\uFF1A",
|
|
8970
|
+
`- \u5DE5\u4F5C\u76EE\u5F55: ${ctx.options.workingDirectory}`,
|
|
8971
|
+
`- \u6A21\u578B: ${ctx.modelService.getCurrentModel() || "\u672A\u6307\u5B9A"}`
|
|
8972
|
+
];
|
|
8973
|
+
return parts.join("\n");
|
|
8883
8974
|
}
|
|
8884
8975
|
|
|
8885
8976
|
// src/cli/executor.ts
|
|
8886
8977
|
init_new();
|
|
8887
|
-
var
|
|
8978
|
+
var ALWAYS_ALLOWED = [
|
|
8888
8979
|
"help",
|
|
8889
8980
|
"h",
|
|
8890
8981
|
"?",
|
|
8891
|
-
"init",
|
|
8892
|
-
"i",
|
|
8893
8982
|
"model",
|
|
8894
8983
|
"m",
|
|
8895
|
-
"new",
|
|
8896
|
-
"n",
|
|
8897
8984
|
"exit",
|
|
8898
8985
|
"e",
|
|
8899
8986
|
"q",
|
|
8900
8987
|
"quit",
|
|
8901
8988
|
"clear",
|
|
8902
8989
|
"c",
|
|
8903
|
-
"update",
|
|
8904
|
-
"u",
|
|
8905
8990
|
"version",
|
|
8906
8991
|
"v"
|
|
8907
8992
|
];
|
|
8993
|
+
var REQUIRES_API_KEY = [
|
|
8994
|
+
"new",
|
|
8995
|
+
"n",
|
|
8996
|
+
"init",
|
|
8997
|
+
"i",
|
|
8998
|
+
"update",
|
|
8999
|
+
"u"
|
|
9000
|
+
];
|
|
8908
9001
|
var CommandExecutor = class {
|
|
8909
9002
|
async execute(parseResult, ctx) {
|
|
8910
9003
|
if (!parseResult.success || !parseResult.command) {
|
|
8911
9004
|
return { output: chalk9.red(`\u9519\u8BEF: ${parseResult.error}`) };
|
|
8912
9005
|
}
|
|
8913
9006
|
const { command } = parseResult;
|
|
9007
|
+
const hasApiKey = !!ctx.configManager.get("apiKey");
|
|
8914
9008
|
const hasActiveWorkflow = getActiveSession() !== null;
|
|
8915
|
-
if (
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
9009
|
+
if (command.type === "slash" /* SLASH */) {
|
|
9010
|
+
const cmd = command.command?.toLowerCase() || "";
|
|
9011
|
+
if (ALWAYS_ALLOWED.includes(cmd)) {
|
|
9012
|
+
return this.executeSlashCommand(command, ctx);
|
|
9013
|
+
}
|
|
9014
|
+
if (REQUIRES_API_KEY.includes(cmd)) {
|
|
9015
|
+
if (!hasApiKey) {
|
|
8919
9016
|
return {
|
|
8920
|
-
output: chalk9.yellow("\
|
|
9017
|
+
output: chalk9.yellow("\u26A0\uFE0F \u8BF7\u5148\u914D\u7F6E API Key") + chalk9.gray("\n\n\u6267\u884C /model \u9009\u62E9\u6A21\u578B\u5E76\u914D\u7F6E API Key")
|
|
8921
9018
|
};
|
|
8922
9019
|
}
|
|
8923
|
-
|
|
9020
|
+
return this.executeSlashCommand(command, ctx);
|
|
9021
|
+
}
|
|
9022
|
+
if (!hasActiveWorkflow) {
|
|
9023
|
+
return {
|
|
9024
|
+
output: chalk9.yellow("\u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u5DE5\u4F5C\u6D41") + chalk9.gray("\n\u8BF7\u5148\u4F7F\u7528 ") + chalk9.cyan("/new <\u9700\u6C42\u63CF\u8FF0>") + chalk9.gray(" \u542F\u52A8\u65B0\u5DE5\u4F5C\u6D41")
|
|
9025
|
+
};
|
|
9026
|
+
}
|
|
9027
|
+
return this.executeSlashCommand(command, ctx);
|
|
9028
|
+
}
|
|
9029
|
+
if (command.type === "dollar" /* DOLLAR */) {
|
|
9030
|
+
if (!hasActiveWorkflow) {
|
|
8924
9031
|
return {
|
|
8925
9032
|
output: chalk9.yellow("\u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u5DE5\u4F5C\u6D41\uFF0C\u65E0\u6CD5\u8C03\u7528 Agent") + chalk9.gray("\n\u8BF7\u5148\u4F7F\u7528 ") + chalk9.cyan("/new <\u9700\u6C42\u63CF\u8FF0>") + chalk9.gray(" \u542F\u52A8\u65B0\u5DE5\u4F5C\u6D41")
|
|
8926
9033
|
};
|
|
8927
|
-
}
|
|
9034
|
+
}
|
|
9035
|
+
if (!hasApiKey) {
|
|
9036
|
+
return {
|
|
9037
|
+
output: chalk9.yellow("\u26A0\uFE0F \u8BF7\u5148\u914D\u7F6E API Key") + chalk9.gray("\n\n\u6267\u884C /model \u914D\u7F6E\u6A21\u578B")
|
|
9038
|
+
};
|
|
9039
|
+
}
|
|
9040
|
+
return this.executeAgent(command, ctx);
|
|
9041
|
+
}
|
|
9042
|
+
if (command.type === "shell" /* SHELL */) {
|
|
9043
|
+
if (!hasActiveWorkflow) {
|
|
8928
9044
|
return {
|
|
8929
9045
|
output: chalk9.yellow("\u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u5DE5\u4F5C\u6D41\uFF0C\u65E0\u6CD5\u6267\u884C Shell \u547D\u4EE4") + chalk9.gray("\n\u8BF7\u5148\u4F7F\u7528 ") + chalk9.cyan("/new <\u9700\u6C42\u63CF\u8FF0>") + chalk9.gray(" \u542F\u52A8\u65B0\u5DE5\u4F5C\u6D41")
|
|
8930
9046
|
};
|
|
8931
9047
|
}
|
|
9048
|
+
return this.executeShell(command, ctx);
|
|
8932
9049
|
}
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
return this.executeShell(command, ctx);
|
|
8942
|
-
case "natural" /* NATURAL */:
|
|
8943
|
-
return this.executeNaturalLanguage(command, ctx);
|
|
8944
|
-
case "yolo" /* YOLO */:
|
|
8945
|
-
return this.executeYolo(ctx);
|
|
8946
|
-
default:
|
|
8947
|
-
return { output: chalk9.red("\u672A\u77E5\u7684\u547D\u4EE4\u7C7B\u578B") };
|
|
9050
|
+
if (command.type === "at" /* AT */) {
|
|
9051
|
+
return this.executeFileReference(command, ctx);
|
|
9052
|
+
}
|
|
9053
|
+
if (command.type === "natural" /* NATURAL */) {
|
|
9054
|
+
return this.executeNaturalLanguage(command, ctx);
|
|
9055
|
+
}
|
|
9056
|
+
if (command.type === "yolo" /* YOLO */) {
|
|
9057
|
+
return this.executeYolo(ctx);
|
|
8948
9058
|
}
|
|
9059
|
+
return { output: chalk9.red("\u672A\u77E5\u7684\u547D\u4EE4\u7C7B\u578B") };
|
|
8949
9060
|
}
|
|
8950
9061
|
async executeSlashCommand(command, ctx) {
|
|
8951
9062
|
const result = await runSlashCommand(
|