deepfish-ai 1.0.28 → 2.0.2
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 +126 -368
- package/dist/index.js +23320 -0
- package/dist/serve/client/assets/index-DUHYC91l.js +1 -0
- package/dist/serve/client/assets/index-zcrdNLZs.css +1 -0
- package/dist/serve/client/index.html +14 -0
- package/dist/serve/pm2-server.js +21015 -0
- package/dist/serve/server/entry-server.mjs +224 -0
- package/package.json +50 -70
- package/LICENSE +0 -21
- package/README_CN.md +0 -460
- package/src/AgentRobot/AgentRobotFactory/MainAgentRobot.js +0 -88
- package/src/AgentRobot/AgentRobotFactory/SubAgentRobot.js +0 -45
- package/src/AgentRobot/AgentRobotFactory/SubSkillAgentRobot.js +0 -45
- package/src/AgentRobot/AgentRobotFactory/index.js +0 -48
- package/src/AgentRobot/BaseAgentRobot/Brain.js +0 -210
- package/src/AgentRobot/BaseAgentRobot/BrainEvent.js +0 -17
- package/src/AgentRobot/BaseAgentRobot/Hand.js +0 -119
- package/src/AgentRobot/BaseAgentRobot/Heart.js +0 -0
- package/src/AgentRobot/BaseAgentRobot/Logger.js +0 -114
- package/src/AgentRobot/BaseAgentRobot/ScreenPrinter.js +0 -49
- package/src/AgentRobot/BaseAgentRobot/index.js +0 -266
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/AliBailian.js +0 -997
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/doc-transform.js +0 -204
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/docx.js +0 -1286
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/img.js +0 -765
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/pdf.js +0 -736
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/pptx.js +0 -567
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/video.js +0 -36
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/xlsx.js +0 -611
- package/src/AgentRobot/BaseAgentRobot/tools/BaseTools.js +0 -13
- package/src/AgentRobot/BaseAgentRobot/tools/CreateAgentTools.js +0 -158
- package/src/AgentRobot/BaseAgentRobot/tools/FileTools.js +0 -768
- package/src/AgentRobot/BaseAgentRobot/tools/GenerateTools.js +0 -441
- package/src/AgentRobot/BaseAgentRobot/tools/InquirerTools.js +0 -244
- package/src/AgentRobot/BaseAgentRobot/tools/SystemTools.js +0 -263
- package/src/AgentRobot/BaseAgentRobot/tools/TaskTools.js +0 -211
- package/src/AgentRobot/BaseAgentRobot/tools/TestTools.js +0 -100
- package/src/AgentRobot/BaseAgentRobot/tools/UserTool.js +0 -87
- package/src/AgentRobot/BaseAgentRobot/tools/WebTools.js +0 -257
- package/src/AgentRobot/BaseAgentRobot/utils/AIRequest.js +0 -297
- package/src/AgentRobot/BaseAgentRobot/utils/AIToolManager.js +0 -131
- package/src/AgentRobot/BaseAgentRobot/utils/AgentTree.js +0 -66
- package/src/AgentRobot/BaseAgentRobot/utils/AttachmentToolScanner.js +0 -235
- package/src/AgentRobot/BaseAgentRobot/utils/MessageCompresser.js +0 -236
- package/src/AgentRobot/BaseAgentRobot/utils/aiConsole.js +0 -74
- package/src/AgentRobot/BaseAgentRobot/utils/aiInquirer.js +0 -78
- package/src/AgentRobot/BaseAgentRobot/utils/analyzeReturn.test.js +0 -104
- package/src/AgentRobot/BaseAgentRobot/utils/copilot.js +0 -117
- package/src/AgentRobot/BaseAgentRobot/utils/node-root.js +0 -138
- package/src/AgentRobot/BaseAgentRobot/utils/normal.js +0 -399
- package/src/cli/ConfigManager.js +0 -283
- package/src/cli/DefaultConfig.js +0 -98
- package/src/cli/GlobalVariable.js +0 -8
- package/src/cli/MemoryManager.js +0 -53
- package/src/cli/SkillConfigManager.js +0 -343
- package/src/cli/SkillParser.js +0 -58
- package/src/cli/ai-auth.js +0 -231
- package/src/cli/ai-config.js +0 -225
- package/src/cli/ai-memory.js +0 -22
- package/src/cli/ai-skill.js +0 -65
- package/src/cli/index.js +0 -77
- package/src/index.js +0 -54
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const assert = require('assert')
|
|
2
|
-
const { analyzeReturn } = require('./normal')
|
|
3
|
-
|
|
4
|
-
function runCase(name, code, expected) {
|
|
5
|
-
const actual = analyzeReturn(code)
|
|
6
|
-
assert.deepStrictEqual(
|
|
7
|
-
actual,
|
|
8
|
-
expected,
|
|
9
|
-
`${name} failed\nexpected: ${JSON.stringify(expected)}\nactual: ${JSON.stringify(actual)}\ncode:\n${code}`,
|
|
10
|
-
)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function run() {
|
|
14
|
-
const cases = [
|
|
15
|
-
{
|
|
16
|
-
name: 'empty input',
|
|
17
|
-
code: '',
|
|
18
|
-
expected: { hasReturn: false, hasReturnValue: false },
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
name: 'non-string input',
|
|
22
|
-
code: null,
|
|
23
|
-
expected: { hasReturn: false, hasReturnValue: false },
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: 'top-level return with number',
|
|
27
|
-
code: 'const x = 1\nreturn x + 1',
|
|
28
|
-
expected: { hasReturn: true, hasReturnValue: true },
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: 'top-level bare return',
|
|
32
|
-
code: 'if (ok) {\n return\n}\nreturn;',
|
|
33
|
-
expected: { hasReturn: true, hasReturnValue: false },
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: 'ASI after return newline',
|
|
37
|
-
code: "return\n'hello'",
|
|
38
|
-
expected: { hasReturn: true, hasReturnValue: false },
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'return with inline comment and value',
|
|
42
|
-
code: 'return /* explain */ 42',
|
|
43
|
-
expected: { hasReturn: true, hasReturnValue: true },
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'return with line comment then newline',
|
|
47
|
-
code: 'return // explain\n42',
|
|
48
|
-
expected: { hasReturn: true, hasReturnValue: false },
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: 'return object literal',
|
|
52
|
-
code: 'return { ok: true }',
|
|
53
|
-
expected: { hasReturn: true, hasReturnValue: true },
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'return template literal',
|
|
57
|
-
code: 'return `done:${1}`',
|
|
58
|
-
expected: { hasReturn: true, hasReturnValue: true },
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: 'ignore return in string/comment',
|
|
62
|
-
code: "const s = 'return 1'\n// return 2\n/* return 3 */\nconst n = 4",
|
|
63
|
-
expected: { hasReturn: false, hasReturnValue: false },
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: 'ignore return in nested function declaration',
|
|
67
|
-
code: 'function inner() { return 1 }\nconst n = 1',
|
|
68
|
-
expected: { hasReturn: false, hasReturnValue: false },
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: 'ignore return in nested arrow block',
|
|
72
|
-
code: 'const fn = () => { return 1 }\nconst n = 1',
|
|
73
|
-
expected: { hasReturn: false, hasReturnValue: false },
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: 'ignore return in class method',
|
|
77
|
-
code: 'class A { m() { return 1 } }\nconst n = 1',
|
|
78
|
-
expected: { hasReturn: false, hasReturnValue: false },
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: 'ignore return in object method',
|
|
82
|
-
code: 'const obj = { m() { return 1 } }\nconst n = 1',
|
|
83
|
-
expected: { hasReturn: false, hasReturnValue: false },
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
name: 'top-level return exists even with nested returns',
|
|
87
|
-
code: 'const fn = () => { return 1 }\nif (ok) { return 2 }',
|
|
88
|
-
expected: { hasReturn: true, hasReturnValue: true },
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: 'real-world code snippet from code.txt shape',
|
|
92
|
-
code: "const fs = require('fs')\nconst content = 'x'\nreturn 'File updated successfully.'",
|
|
93
|
-
expected: { hasReturn: true, hasReturnValue: true },
|
|
94
|
-
},
|
|
95
|
-
]
|
|
96
|
-
|
|
97
|
-
for (const testCase of cases) {
|
|
98
|
-
runCase(testCase.name, testCase.code, testCase.expected)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
console.log(`analyzeReturn tests passed: ${cases.length} cases`)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
run()
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
const axios = require('axios')
|
|
2
|
-
const { GlobalVariable } = require('../../../cli/GlobalVariable.js')
|
|
3
|
-
|
|
4
|
-
function isExpiring(isoTime, thresholdSec = 120) {
|
|
5
|
-
if (!isoTime) {
|
|
6
|
-
return false
|
|
7
|
-
}
|
|
8
|
-
const target = new Date(isoTime).getTime()
|
|
9
|
-
if (!Number.isFinite(target)) {
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
return target - Date.now() <= thresholdSec * 1000
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function secondsToISO(seconds) {
|
|
16
|
-
if (!seconds || Number(seconds) <= 0) {
|
|
17
|
-
return ''
|
|
18
|
-
}
|
|
19
|
-
return new Date(Date.now() + Number(seconds) * 1000).toISOString()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function refreshGithubModelsTokenIfNeeded(aiConfig = {}) {
|
|
23
|
-
if (aiConfig.type !== 'github-models' && aiConfig.type !== 'copilot') {
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
const githubAuth = aiConfig.githubAuth || {}
|
|
27
|
-
if (!isExpiring(githubAuth.accessTokenExpiresAt)) {
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
if (!githubAuth.refreshToken) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
'GitHub access token expired and no refresh token is available. Please run "ai auth github-login" again.',
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
if (!githubAuth.clientId || !githubAuth.clientSecret) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
'GitHub token refresh requires clientId and clientSecret. Please run "ai auth github-login" and provide both values.',
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
if (isExpiring(githubAuth.refreshTokenExpiresAt, 0)) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
'GitHub refresh token expired. Please run "ai auth github-login" again.',
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const form = new URLSearchParams()
|
|
47
|
-
form.set('client_id', githubAuth.clientId)
|
|
48
|
-
form.set('client_secret', githubAuth.clientSecret)
|
|
49
|
-
form.set('grant_type', 'refresh_token')
|
|
50
|
-
form.set('refresh_token', githubAuth.refreshToken)
|
|
51
|
-
|
|
52
|
-
const response = await axios.post(
|
|
53
|
-
'https://github.com/login/oauth/access_token',
|
|
54
|
-
form.toString(),
|
|
55
|
-
{
|
|
56
|
-
headers: {
|
|
57
|
-
Accept: 'application/json',
|
|
58
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
59
|
-
},
|
|
60
|
-
timeout: 20000,
|
|
61
|
-
},
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
const tokenData = response.data || {}
|
|
65
|
-
if (!tokenData.access_token) {
|
|
66
|
-
const errMessage = tokenData.error_description || tokenData.error || 'Unknown token refresh error'
|
|
67
|
-
throw new Error(`GitHub token refresh failed: ${errMessage}`)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const newAuth = {
|
|
71
|
-
...githubAuth,
|
|
72
|
-
tokenType: tokenData.token_type || githubAuth.tokenType || 'bearer',
|
|
73
|
-
accessTokenExpiresAt: secondsToISO(tokenData.expires_in),
|
|
74
|
-
refreshToken: tokenData.refresh_token || githubAuth.refreshToken,
|
|
75
|
-
refreshTokenExpiresAt: tokenData.refresh_token_expires_in
|
|
76
|
-
? secondsToISO(tokenData.refresh_token_expires_in)
|
|
77
|
-
: githubAuth.refreshTokenExpiresAt,
|
|
78
|
-
lastUpdatedAt: new Date().toISOString(),
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
aiConfig.apiKey = tokenData.access_token
|
|
82
|
-
aiConfig.githubAuth = newAuth
|
|
83
|
-
|
|
84
|
-
const configManager = GlobalVariable.configManager
|
|
85
|
-
if (configManager && aiConfig.name && configManager.updateAiConfigByName) {
|
|
86
|
-
configManager.updateAiConfigByName(aiConfig.name, (current) => {
|
|
87
|
-
return {
|
|
88
|
-
...current,
|
|
89
|
-
apiKey: tokenData.access_token,
|
|
90
|
-
githubAuth: {
|
|
91
|
-
...(current.githubAuth || {}),
|
|
92
|
-
...newAuth,
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function buildDefaultHeaders(aiConfig = {}) {
|
|
100
|
-
if (aiConfig.type === 'github-models') {
|
|
101
|
-
return {
|
|
102
|
-
Accept: 'application/vnd.github+json',
|
|
103
|
-
'X-GitHub-Api-Version': '2026-03-10',
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (aiConfig.type === 'copilot') {
|
|
107
|
-
return {
|
|
108
|
-
'Openai-Intent': 'conversation-edits',
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return undefined
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
module.exports = {
|
|
115
|
-
refreshGithubModelsTokenIfNeeded,
|
|
116
|
-
buildDefaultHeaders,
|
|
117
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
const { execSync } = require('child_process')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 辅助函数:安全执行 shell 命令(避免执行失败导致程序崩溃)
|
|
7
|
-
* @param {string} cmd 要执行的命令
|
|
8
|
-
* @returns {string|null} 命令输出结果(失败返回 null)
|
|
9
|
-
*/
|
|
10
|
-
function safeExec(cmd) {
|
|
11
|
-
try {
|
|
12
|
-
return execSync(cmd, { encoding: 'utf8', stdio: 'pipe' }).trim()
|
|
13
|
-
} catch (err) {
|
|
14
|
-
return null
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 辅助函数:解析路径(处理软链/快捷方式,验证路径存在性)
|
|
20
|
-
* @param {string} targetPath 待解析的路径
|
|
21
|
-
* @returns {string|null} 真实存在的路径(失败返回 null)
|
|
22
|
-
*/
|
|
23
|
-
function resolveValidPath(targetPath) {
|
|
24
|
-
if (!targetPath) return null
|
|
25
|
-
try {
|
|
26
|
-
// 解析软链/快捷方式的真实物理路径
|
|
27
|
-
const realPath = fs.realpathSync(targetPath)
|
|
28
|
-
// 验证路径是否存在
|
|
29
|
-
return fs.existsSync(realPath) ? realPath : null
|
|
30
|
-
} catch (err) {
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 从 NVM 环境中获取全局 node_modules 路径
|
|
37
|
-
* @returns {string|null} NVM 环境下的真实路径
|
|
38
|
-
*/
|
|
39
|
-
function getNvmGlobalPath() {
|
|
40
|
-
// 1. 获取 NVM 根目录(优先读环境变量)
|
|
41
|
-
const nvmDir = process.env.NVM_DIR || (
|
|
42
|
-
process.platform === 'win32'
|
|
43
|
-
? path.join(process.env.USERPROFILE, '.nvm')
|
|
44
|
-
: path.join(process.env.HOME, '.nvm')
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
// 2. 获取当前激活的 Node 版本
|
|
48
|
-
const nodeVersion = safeExec('nvm current')
|
|
49
|
-
if (!nodeVersion || nodeVersion.includes('N/A')) return null
|
|
50
|
-
|
|
51
|
-
// 3. 拼接 NVM 下的全局 node_modules 路径
|
|
52
|
-
const nvmGlobalPath = path.join(
|
|
53
|
-
nvmDir,
|
|
54
|
-
'versions',
|
|
55
|
-
'node',
|
|
56
|
-
nodeVersion,
|
|
57
|
-
'lib',
|
|
58
|
-
'node_modules'
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
// 4. 解析并验证路径有效性
|
|
62
|
-
return resolveValidPath(nvmGlobalPath)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 从 NPM 命令获取全局 node_modules 路径
|
|
67
|
-
* @returns {string|null} NPM 返回的真实路径
|
|
68
|
-
*/
|
|
69
|
-
function getNpmGlobalPath() {
|
|
70
|
-
// 1. 执行 npm root -g 获取路径
|
|
71
|
-
const npmPath = safeExec('npm root -g')
|
|
72
|
-
// 2. 解析并验证路径有效性
|
|
73
|
-
return resolveValidPath(npmPath)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 兜底方案:通过 Node 内置变量计算全局路径
|
|
78
|
-
* @returns {string|null} 计算出的路径(仅作为最后兜底)
|
|
79
|
-
*/
|
|
80
|
-
function getFallbackGlobalPath() {
|
|
81
|
-
try {
|
|
82
|
-
const nodeExecPath = process.execPath
|
|
83
|
-
let globalPrefix;
|
|
84
|
-
|
|
85
|
-
if (process.platform === 'win32') {
|
|
86
|
-
// Windows:node.exe 所在目录的上一级
|
|
87
|
-
globalPrefix = path.dirname(path.dirname(nodeExecPath))
|
|
88
|
-
} else {
|
|
89
|
-
// Mac/Linux:node 所在目录的上两级
|
|
90
|
-
globalPrefix = path.dirname(path.dirname(path.dirname(nodeExecPath)))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const fallbackPath = path.join(globalPrefix, 'lib', 'node_modules')
|
|
94
|
-
return resolveValidPath(fallbackPath)
|
|
95
|
-
} catch (err) {
|
|
96
|
-
return null
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 主函数:获取最正确的全局 node_modules 路径(自动适配所有场景)
|
|
102
|
-
* 优先级:NVM 路径 → NPM 命令路径 → 兜底计算路径
|
|
103
|
-
* @returns {string|null} 最准确的全局 node_modules 路径
|
|
104
|
-
*/
|
|
105
|
-
function getGlobalNodeModulesPath() {
|
|
106
|
-
// 优先级 1:优先获取 NVM 环境下的路径(适配 NVM 场景)
|
|
107
|
-
const nvmPath = getNvmGlobalPath()
|
|
108
|
-
if (nvmPath) {
|
|
109
|
-
return nvmPath
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// 优先级 2:通过 npm 命令获取(普通环境最准确)
|
|
113
|
-
const npmPath = getNpmGlobalPath()
|
|
114
|
-
if (npmPath) {
|
|
115
|
-
return npmPath
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 优先级 3:兜底计算(仅当以上都失败时使用)
|
|
119
|
-
const fallbackPath = getFallbackGlobalPath()
|
|
120
|
-
if (fallbackPath) {
|
|
121
|
-
return fallbackPath
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 所有方案都失败
|
|
125
|
-
console.error('无法获取全局 node_modules 路径')
|
|
126
|
-
return null
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
module.exports = {
|
|
130
|
-
safeExec,
|
|
131
|
-
resolveValidPath,
|
|
132
|
-
getNvmGlobalPath,
|
|
133
|
-
getNpmGlobalPath,
|
|
134
|
-
getFallbackGlobalPath,
|
|
135
|
-
getGlobalNodeModulesPath // 主函数
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
module.exports.default = getGlobalNodeModulesPath
|