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