@yorha2b-lab/autodev 5.0.0 → 5.1.0
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/bin/autodev.js +25 -23
- package/package.json +1 -1
- package/src/bootstrap/dialogs.js +10 -0
- package/src/bootstrap/index.js +13 -6
- package/src/bootstrap/infrastructure.js +4 -3
- package/src/bootstrap/yorha.js +39 -0
- package/src/commands/watch.js +11 -23
- package/src/dialogs/EN-US.js +55 -0
- package/src/dialogs/ZH-CN.js +55 -0
- package/src/handlers/api.js +92 -0
- package/src/handlers/page.js +70 -0
- package/src/handlers/part.js +59 -0
- package/src/labs/linker.js +12 -28
- package/src/labs/tower.js +8 -20
- package/src/services/llm.js +19 -18
- package/src/utils/ux.js +21 -18
- package/src/handlers/apiHandler.js +0 -111
- package/src/handlers/pageHandler.js +0 -95
- package/src/handlers/partHandler.js +0 -77
- /package/src/bootstrap/{prompt.js → prompts.js} +0 -0
package/bin/autodev.js
CHANGED
|
@@ -4,17 +4,20 @@ const path = require('path')
|
|
|
4
4
|
const chalk = require('chalk')
|
|
5
5
|
const pkg = require('../package.json')
|
|
6
6
|
const { program } = require('commander')
|
|
7
|
-
const {
|
|
7
|
+
const { local, matrixEffect, bootSequence } = require('../src/utils/ux')
|
|
8
|
+
|
|
9
|
+
const dialogs = require('../src/bootstrap/dialogs')()
|
|
10
|
+
const dialog = dialogs[local]
|
|
8
11
|
|
|
9
12
|
program
|
|
10
13
|
.version(pkg.version)
|
|
11
|
-
.description(
|
|
14
|
+
.description(dialog.bunker.desc)
|
|
12
15
|
|
|
13
|
-
program.option('-t, --template <type>',
|
|
16
|
+
program.option('-t, --template <type>', dialog.bunker.argDesc, 'react')
|
|
14
17
|
|
|
15
18
|
program
|
|
16
19
|
.command('init')
|
|
17
|
-
.description(
|
|
20
|
+
.description(dialog.bunker.initDesc)
|
|
18
21
|
.action(() => {
|
|
19
22
|
const tplConfig = path.resolve(__dirname, '../config.js')
|
|
20
23
|
const tplEnv = path.resolve(__dirname, '../.env.example')
|
|
@@ -26,50 +29,49 @@ program
|
|
|
26
29
|
fs.mkdirSync(path.join(process.cwd(), 'screenPart'), { recursive: true })
|
|
27
30
|
|
|
28
31
|
if (fs.existsSync(targetEnv)) {
|
|
29
|
-
console.log(chalk.yellow(
|
|
32
|
+
console.log(chalk.yellow(dialog.bunker.envCheck))
|
|
30
33
|
} else {
|
|
31
34
|
fs.copyFileSync(tplEnv, targetEnv)
|
|
32
|
-
console.log(chalk.green(
|
|
35
|
+
console.log(chalk.green(dialog.bunker.envCopy))
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
if (fs.existsSync(targetConfig)) {
|
|
36
|
-
console.log(chalk.yellow(
|
|
39
|
+
console.log(chalk.yellow(dialog.bunker.configCheck))
|
|
37
40
|
} else {
|
|
38
41
|
fs.copyFileSync(tplConfig, targetConfig)
|
|
39
|
-
console.log(chalk.green(
|
|
42
|
+
console.log(chalk.green(dialog.bunker.configCopy))
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
const bunkerCmd = chalk.yellow(`'bunker': 'autodev watch'`)
|
|
43
|
-
console.log(chalk.cyan(
|
|
44
|
-
`📡 Operator 6O: 呼叫 2B, 地堡部署完毕, 为了更快捷地进入战场,建议手动执行 [物理装配]: 将 ${bunkerCmd} 加入您的 package.json scripts 中`,
|
|
45
|
-
`📡 Operator 6O: Calling 2B! Bunker deployment is complete. To expedite your entry into the battlefield, I recommend a manual [Physical Assembly]: Add ${bunkerCmd} to your package.json scripts.`
|
|
46
|
-
)))
|
|
46
|
+
console.log(chalk.cyan(dialog.bunker.initComplete(bunkerCmd)))
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
program
|
|
50
50
|
.command('watch')
|
|
51
51
|
.alias('start')
|
|
52
|
-
.description(
|
|
53
|
-
.action(() => {
|
|
52
|
+
.description(dialog.bunker.watchDesc)
|
|
53
|
+
.action(async () => {
|
|
54
54
|
const bunker = require('../src/bootstrap')
|
|
55
|
-
const result = bunker.init(program.opts())
|
|
55
|
+
const result = bunker.init(program.opts(), dialogs)
|
|
56
56
|
if (!result) {
|
|
57
57
|
return
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
require('../src/commands/watch')()
|
|
59
|
+
const { commander } = result.yorha
|
|
61
60
|
const { config } = result.infrastructure
|
|
62
61
|
const { apiDoc, needMock, proxyTarget, enableAutoAlignment } = config
|
|
62
|
+
|
|
63
|
+
const bootTower = proxyTarget && !needMock && enableAutoAlignment
|
|
64
|
+
|
|
65
|
+
await bootSequence({ dialog, version: pkg.version, bootTower, commander })
|
|
66
|
+
require('../src/commands/watch')()
|
|
67
|
+
if (bootTower) {
|
|
68
|
+
require('../src/labs/tower')()
|
|
69
|
+
}
|
|
63
70
|
if (apiDoc && enableAutoAlignment) {
|
|
64
71
|
require('../src/labs/linker')()
|
|
65
72
|
}
|
|
66
|
-
if (proxyTarget && !needMock && enableAutoAlignment) {
|
|
67
|
-
require('../src/labs/tower')()
|
|
68
|
-
}
|
|
69
73
|
process.on('SIGINT', () => {
|
|
70
|
-
|
|
71
|
-
console.log(chalk.gray('--------------------------------------------------'))
|
|
72
|
-
console.log(chalk.white(' [System] ') + chalk.yellow(language('正在断开神经云链接,执行数据物理封存...', 'Disconnecting Neural Link, Executing Physical Assembly...')))
|
|
74
|
+
commander.log(dialog.bunker.systemOffline)
|
|
73
75
|
matrixEffect(500)
|
|
74
76
|
})
|
|
75
77
|
})
|
package/package.json
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = () => {
|
|
2
|
+
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
|
|
6
|
+
const dialogsPath = path.join(__dirname, `../dialogs`)
|
|
7
|
+
const dialogs = fs.readdirSync(dialogsPath).map(dialog => [path.basename(dialog, '.js'), require(path.join(dialogsPath, dialog))])
|
|
8
|
+
|
|
9
|
+
return Object.fromEntries(dialogs)
|
|
10
|
+
}
|
package/src/bootstrap/index.js
CHANGED
|
@@ -6,36 +6,43 @@ let instance = null
|
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
|
|
9
|
-
init: options => {
|
|
9
|
+
init: (options, dialogs) => {
|
|
10
10
|
|
|
11
11
|
const template = options.template
|
|
12
12
|
const ux = require('../utils/ux')
|
|
13
13
|
|
|
14
14
|
const generatorPath = path.join(__dirname, `../framework/${template}/generator`)
|
|
15
15
|
if (!fs.existsSync(generatorPath)) {
|
|
16
|
-
console.
|
|
16
|
+
console.log(chalk.red(ux.local === 'ZH-CN' ? `暂不支持 [${template}] 框架。欢迎提交 Pull Request 贡献。` : `[${template}] framework not supported. Welcome to contribute a Pull Request to help.`))
|
|
17
17
|
return
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const infrastructure = require('../utils/infrastructure')
|
|
21
21
|
|
|
22
|
+
const yorha = require('./yorha')()
|
|
22
23
|
const openAI = require('./openai')()
|
|
23
24
|
const core = require('../utils/core')
|
|
24
25
|
const handlers = require('./handlers')()
|
|
25
26
|
const config = infrastructure.getConfig()
|
|
26
27
|
const menus = infrastructure.getExistingMenus()
|
|
27
|
-
const prompts = require('./
|
|
28
|
-
require('./infrastructure')({ ux, config, options, ...infrastructure })
|
|
29
|
-
const llm = require('../services/llm')({ config, openAI, template, ...prompts })
|
|
28
|
+
const prompts = require('./prompts')({ template })
|
|
30
29
|
const handlebars = require('./handlebars')({ config, template, ...infrastructure })
|
|
31
|
-
|
|
30
|
+
|
|
31
|
+
const accessPoint = { ux, yorha, openAI, config, dialogs, options, template, ...core, ...prompts, ...handlebars, ...infrastructure }
|
|
32
|
+
|
|
33
|
+
require('./infrastructure')(accessPoint)
|
|
34
|
+
const llm = require('../services/llm')(accessPoint)
|
|
35
|
+
const generator = require(generatorPath)(accessPoint)
|
|
36
|
+
|
|
32
37
|
|
|
33
38
|
instance = {
|
|
34
39
|
ux,
|
|
35
40
|
llm,
|
|
36
41
|
core,
|
|
42
|
+
yorha,
|
|
37
43
|
openAI,
|
|
38
44
|
prompts,
|
|
45
|
+
dialogs,
|
|
39
46
|
handlers,
|
|
40
47
|
generator,
|
|
41
48
|
handlebars,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
module.exports = ({ ux, config, options, copyTemplateDir }) => {
|
|
1
|
+
module.exports = ({ ux, config, yorha, options, copyTemplateDir }) => {
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { local } = ux
|
|
4
|
+
const { commander } = yorha
|
|
4
5
|
const { hbsDir, hooksDir, utilsDir, componentsDir } = config
|
|
5
6
|
|
|
6
7
|
try {
|
|
@@ -10,6 +11,6 @@ module.exports = ({ ux, config, options, copyTemplateDir }) => {
|
|
|
10
11
|
copyTemplateDir(options, 'components', componentsDir)
|
|
11
12
|
}
|
|
12
13
|
} catch (error) {
|
|
13
|
-
|
|
14
|
+
commander.log(local === 'ZH-CN' ? `模板构筑失败: ${error}` : `Template construction failed: ${error}`, 'red')
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module.exports = () => {
|
|
2
|
+
|
|
3
|
+
const ora = require('ora')
|
|
4
|
+
const chalk = require('chalk')
|
|
5
|
+
|
|
6
|
+
const createMember = ({ name }) => ({
|
|
7
|
+
start(text) {
|
|
8
|
+
const spinner = ora({ text: chalk.cyan(`\n${name} ${text}`) }).start()
|
|
9
|
+
return spinner
|
|
10
|
+
},
|
|
11
|
+
fail(spinner, text) {
|
|
12
|
+
spinner.fail(chalk.red(`\n${name} ${text}`))
|
|
13
|
+
},
|
|
14
|
+
log(text, color = 'gray') {
|
|
15
|
+
console.log(chalk[color](`\n${name} ${text}`))
|
|
16
|
+
},
|
|
17
|
+
report(text, color = 'yellow') {
|
|
18
|
+
console.log(chalk[color](`\n${name} ${text}`))
|
|
19
|
+
},
|
|
20
|
+
update(spinner, text) {
|
|
21
|
+
spinner.text = chalk.cyan(`\n${name} ${text}`)
|
|
22
|
+
},
|
|
23
|
+
warning(spinner, text) {
|
|
24
|
+
spinner.warn(chalk.yellow(`\n${name} ${text}`))
|
|
25
|
+
},
|
|
26
|
+
success(spinner, text) {
|
|
27
|
+
spinner.succeed(chalk.green(`\n${name} ${text}`))
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
nineS: createMember({ name: '[YoRHa::9S]' }),
|
|
33
|
+
commander: createMember({ name: '[BUNKER]' }),
|
|
34
|
+
pod042: createMember({ name: '[YoRHa::Pod042]' }),
|
|
35
|
+
pod153: createMember({ name: '[YoRHa::Pod153]' }),
|
|
36
|
+
operator6O: createMember({ name: '[YoRHa::6O]' }),
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
package/src/commands/watch.js
CHANGED
|
@@ -2,30 +2,24 @@ module.exports = () => {
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs')
|
|
4
4
|
const path = require('path')
|
|
5
|
-
const chalk = require('chalk')
|
|
6
5
|
const chokidar = require('chokidar')
|
|
7
6
|
|
|
8
|
-
const { ux, core, handlers, infrastructure } = require('../bootstrap').get()
|
|
7
|
+
const { ux, core, yorha, dialogs, handlers, infrastructure } = require('../bootstrap').get()
|
|
9
8
|
|
|
10
|
-
const {
|
|
9
|
+
const { local } = ux
|
|
10
|
+
const dialog = dialogs[local]
|
|
11
11
|
const { createTaskQueue } = core
|
|
12
|
-
const {
|
|
12
|
+
const { pod042, commander, operator6O } = yorha
|
|
13
13
|
const { menus, config, contextStringify } = infrastructure
|
|
14
14
|
|
|
15
15
|
const queue = createTaskQueue(2)
|
|
16
16
|
|
|
17
17
|
queue.onIdle(() => {
|
|
18
|
-
|
|
19
|
-
'\n🤖 Pod 042: [报告] 队列已空,正在向 Bunker 同步 Menu 路由配置...',
|
|
20
|
-
'\n🤖 Pod 042: [Report] Queue empty. Syncing Menu configuration to Bunker...'
|
|
21
|
-
)))
|
|
18
|
+
pod042.report(dialog.pod042.queueEmpty)
|
|
22
19
|
const utilsDir = path.join(process.cwd(), config.utilsDir)
|
|
23
20
|
if (!fs.existsSync(utilsDir)) fs.mkdirSync(utilsDir, { recursive: true })
|
|
24
21
|
fs.writeFileSync(path.join(utilsDir, 'menus.js'), `export const menus = ${contextStringify({ context: menus, maxLength: 50 })}`)
|
|
25
|
-
|
|
26
|
-
'\n🤖 [System] 未检测到运行中的任务,系统待机中...\n',
|
|
27
|
-
'\n🤖 [System] System is STANDBY.\n'
|
|
28
|
-
)))
|
|
22
|
+
commander.log(dialog.bunker.systemStandby)
|
|
29
23
|
})
|
|
30
24
|
|
|
31
25
|
const watcher = chokidar.watch(['./screenShot', './screenPart', './response'], {
|
|
@@ -35,22 +29,16 @@ module.exports = () => {
|
|
|
35
29
|
awaitWriteFinish: { stabilityThreshold: 500, pollInterval: 100 }
|
|
36
30
|
})
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
'📡 Operator 6O: 呼叫 2B,地堡全频道联动监控已就绪!',
|
|
40
|
-
'📡 Operator 6O: Calling 2B, all-channel linked monitoring is ready!'
|
|
41
|
-
)))
|
|
32
|
+
operator6O.report(dialog.operator6O.call2B)
|
|
42
33
|
|
|
43
|
-
const routes =
|
|
44
|
-
{ match: 'response', handler: apiHandler },
|
|
45
|
-
{ match: 'screenShot', handler: pageHandler },
|
|
46
|
-
{ match: 'screenPart', handler: partHandler },
|
|
47
|
-
]
|
|
34
|
+
const routes = Object.values(handlers)
|
|
48
35
|
|
|
49
36
|
watcher.on('add', filePath => {
|
|
50
37
|
const absolutePath = path.resolve(filePath)
|
|
51
|
-
const route = routes.find(
|
|
38
|
+
const route = routes.find(route => absolutePath.includes(route.watch))
|
|
52
39
|
if (route) {
|
|
53
|
-
queue.add(() => route.
|
|
40
|
+
queue.add(() => route.handle(filePath))
|
|
54
41
|
}
|
|
55
42
|
})
|
|
43
|
+
|
|
56
44
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
nineS: {
|
|
3
|
+
dataCamouflageComplete: 'Mock data generation successful',
|
|
4
|
+
scanningField: 'Scanning field differences... Bridging semantic gaps',
|
|
5
|
+
dataCamouflage: fileName => `Piercing target firewall... Executing data camouflage [${fileName}]`,
|
|
6
|
+
},
|
|
7
|
+
pod042: {
|
|
8
|
+
queueEmpty: 'Queue empty. Syncing Menu configuration to Bunker...',
|
|
9
|
+
extractingUiMetadata: 'Extracting UI metadata from neural cloud network...',
|
|
10
|
+
simulate: 'Real-fire request intercepted. Dropping simulation package: example.json',
|
|
11
|
+
uploadVisualMetadata: 'Uploading visual metadata to Command for semantic analysis...',
|
|
12
|
+
partialConstruction: time => `Report: Partial construction achieved. Elapsed: ${time}s`,
|
|
13
|
+
constructionAborted: virus => `Construction aborted. Logic virus or timeout detected: ${virus}`,
|
|
14
|
+
visualPartCaptured: `Partial visual sample detected. Executing 'Fragment Construction Protocol'...`,
|
|
15
|
+
intercept: fileName => `Module [${fileName}] already exists. Construction skipped to prevent overwrite.`,
|
|
16
|
+
partialRecommendation: '│ Recommendation: Please manually assemble the above code block into your target file',
|
|
17
|
+
partialConstructionAborted: virus => `[Warning] Fragment construction failed. Logic interference detected: ${virus}`,
|
|
18
|
+
assemblyComplete: (fileName, time) => `Protocol complete. Physical assembly of [${fileName}] achieved. Elapsed: ${time}s`,
|
|
19
|
+
visualCaptured: fileName => `Visual sensor captured: [${fileName}]. Allocating Bunker resources for physical construction...`,
|
|
20
|
+
},
|
|
21
|
+
pod153: {
|
|
22
|
+
signalLinkFault: virus => `Signal Link Fault: ${virus}`,
|
|
23
|
+
signalSynchronized: count => `Signal Synchronized: ${count} nodes energized`,
|
|
24
|
+
formatError: 'Data format is not standard JSON, will try to align by character',
|
|
25
|
+
alignmentFailed: virus => `Alignment failed. Encountered powerful API firewall: ${virus}`,
|
|
26
|
+
autonomousAddressing: `Initiating 'Full-Channel Autonomous Addressing Protocol [Semantic Scan]'...`,
|
|
27
|
+
inactiveModule: fileName => `Inactive module: [${fileName}]. Requesting 9S for precise alignment...`,
|
|
28
|
+
reconEncryptedData: fileName => `Encrypted data source [${fileName}] detected. Initiating semantic alignment...`,
|
|
29
|
+
capturedRuntimeSignal: fileName => `Captured runtime signal [${fileName}]. Executing semantic alignment protocol...`,
|
|
30
|
+
unknownModule: fileName => `Module [${fileName}] resource not found in Bunker database. Please execute visual construction first`,
|
|
31
|
+
bridgeProtocolComplete: (count, time) => `Semantic bridge protocol complete. Corrected ${count} field deviations. Elapsed: ${time}s`,
|
|
32
|
+
},
|
|
33
|
+
bunker: {
|
|
34
|
+
envCopy: '.env storage complete',
|
|
35
|
+
envCheck: '.env already exists',
|
|
36
|
+
systemStandby: 'System is STANDBY',
|
|
37
|
+
configCheck: 'config.js already exists',
|
|
38
|
+
configCopy: 'config.js storage complete',
|
|
39
|
+
argDesc: 'Specify frontend framework template',
|
|
40
|
+
desc: 'AI-powered frontend CRUD code generator',
|
|
41
|
+
initDesc: 'Initialize Bunker construction environment',
|
|
42
|
+
towerOnline: port => `Signal Intercept Tower Online [Band: ${port}]`,
|
|
43
|
+
linkSevered: 'Link Severed: Check network status or Black Box resonance',
|
|
44
|
+
systemOffline: 'Disconnecting Neural Link, Executing Physical Assembly...',
|
|
45
|
+
accessDenied: 'YoRHa Command Center Access Denied: Invalid API Key or quota exhausted!',
|
|
46
|
+
watchDesc: 'Start full-channel linked monitoring: Coordinated Page/Part/API construction',
|
|
47
|
+
towerConnected: port => `Command: Please point your local proxy target to http://localhost:${port}`,
|
|
48
|
+
disclaimer: 'Match Result Reference Only. Not Final Decision. Each Unit should adjust based on battlefield conditions',
|
|
49
|
+
networkInstability: count => `Neural Network instability detected. Attempting to re-establish link... (Retry #${count})`,
|
|
50
|
+
initComplete: cmd => `Bunker deployment is complete. To expedite your entry into the battlefield, I recommend a manual [Physical Assembly]: Add ${cmd} to your package.json scripts.`
|
|
51
|
+
},
|
|
52
|
+
operator6O: {
|
|
53
|
+
call2B: 'Calling 2B, all-channel linked monitoring is ready!'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
nineS: {
|
|
3
|
+
dataCamouflageComplete: 'Mock 数据生成成功',
|
|
4
|
+
scanningField: '正在扫描前后端字段差异... 执行语义桥接任务',
|
|
5
|
+
dataCamouflage: fileName => `正在突破目标防火墙... 执行数据伪装程序 [${fileName}]`,
|
|
6
|
+
},
|
|
7
|
+
pod042: {
|
|
8
|
+
extractingUiMetadata: '正在从神经云网络提取 UI 元数据...',
|
|
9
|
+
simulate: '拦截到实弹请求。正在空投标准模拟包: example.json',
|
|
10
|
+
queueEmpty: '队列已空,正在向 Bunker 同步 Menu 路由配置...',
|
|
11
|
+
uploadVisualMetadata: '正在上传视觉元数据至司令部进行语义分析...',
|
|
12
|
+
visualPartCaptured: `侦测到局部视觉样本。正在执行“碎片构筑协议”...`,
|
|
13
|
+
partialConstruction: time => `报告:局部构筑达成。耗时: ${time}s`,
|
|
14
|
+
partialRecommendation: '│ 建议:请手动将上述代码块物理装配至您的目标文件中',
|
|
15
|
+
constructionAborted: virus => `构筑中断。检测到逻辑病毒或连接超时:${virus}`,
|
|
16
|
+
partialConstructionAborted: virus => `[警告] 碎片构筑失败。系统检测到逻辑干扰:${virus}`,
|
|
17
|
+
visualCaptured: fileName => `视觉传感器捕捉完成: [${fileName}]。正在调配地堡资源进行物理构筑...`,
|
|
18
|
+
intercept: fileName => `模块 [${fileName}] 已存在于地堡数据库中。为了防止数据覆盖,构筑协议已跳过`,
|
|
19
|
+
assemblyComplete: (fileName, time) => `构筑协议执行完毕。模块 [${fileName}] 物理装配达成。耗时: ${time}s`,
|
|
20
|
+
},
|
|
21
|
+
pod153: {
|
|
22
|
+
signalLinkFault: virus => `信号链路故障: ${virus}`,
|
|
23
|
+
formatError: '数据格式非标准 JSON,将尝试原始字符对齐',
|
|
24
|
+
autonomousAddressing: `启动‘全频道自动寻址协议 [语义扫描版]’...`,
|
|
25
|
+
signalSynchronized: count => `信号同步完成,${count} 个节点已通电`,
|
|
26
|
+
alignmentFailed: virus => `信号对齐失败。接口数据遭遇强力防火墙:${virus}`,
|
|
27
|
+
inactiveModule: fileName => `发现未通电模块 [${fileName}],请求 9S 执行高精度对账...`,
|
|
28
|
+
capturedRuntimeSignal: fileName => `截获运行时信号 [${fileName}]。执行自动对齐协议...`,
|
|
29
|
+
reconEncryptedData: fileName => `发现加密数据源 [${fileName}]。正在尝试执行语义对齐协议...`,
|
|
30
|
+
unknownModule: fileName => `地堡数据库中未检索到模块 [${fileName}] 的资源文件。请先执行视觉构筑`,
|
|
31
|
+
bridgeProtocolComplete: (count, time) => `语义桥接协议执行完毕。已物理修正 ${count} 处字段偏差。耗时: ${time}s`,
|
|
32
|
+
},
|
|
33
|
+
bunker: {
|
|
34
|
+
envCopy: '.env 存储完毕',
|
|
35
|
+
argDesc: '指定前端框架模板',
|
|
36
|
+
systemStandby: '系统待机中...',
|
|
37
|
+
desc: 'AI驱动的前端CRUD代码生成器',
|
|
38
|
+
configCopy: 'config.js 存储完毕',
|
|
39
|
+
initDesc: '在当前目录初始化地堡构筑环境',
|
|
40
|
+
envCheck: '终端已存在 .env 文件,跳过生成',
|
|
41
|
+
configCheck: '终端已存在 config.js 文件,跳过生成',
|
|
42
|
+
linkSevered: '连接中断:请检查网络状态或黑盒共鸣情况',
|
|
43
|
+
systemOffline: '正在断开神经云链接,执行数据物理封存...',
|
|
44
|
+
towerOnline: port => `信号拦截塔已在线 [波段: ${port}]`,
|
|
45
|
+
watchDesc: '开启全频道联动监控:支持 Page/Part/API 协同构筑',
|
|
46
|
+
accessDenied: '司令部拒绝访问:API Key 无效或额度耗尽,请检查!',
|
|
47
|
+
disclaimer: '匹配结果仅供参考,不构成最终决策,各机体需根据实际情况进行调整',
|
|
48
|
+
towerConnected: port => `指令:请将您的代理目标指向 http://localhost:${port}`,
|
|
49
|
+
networkInstability: count => `神经云网络连接不稳,正在尝试重新链接... (第 ${count} 次重试)`,
|
|
50
|
+
initComplete: cmd => `地堡部署完毕, 为了更快捷地进入战场,建议手动执行 [物理装配]: 将 ${cmd} 加入您的 package.json scripts 中`,
|
|
51
|
+
},
|
|
52
|
+
operator6O: {
|
|
53
|
+
call2B: '呼叫 2B,地堡全频道联动监控已就绪!',
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
watch: 'response',
|
|
6
|
+
async handle(filePath, liveResponse = null) {
|
|
7
|
+
|
|
8
|
+
const chalk = require('chalk')
|
|
9
|
+
const { ux, llm, core, yorha, dialogs, infrastructure } = require('../bootstrap').get()
|
|
10
|
+
|
|
11
|
+
const { local } = ux
|
|
12
|
+
const dialog = dialogs[local]
|
|
13
|
+
const { unwrapSignal } = core
|
|
14
|
+
const { nineS, pod153 } = yorha
|
|
15
|
+
const { config } = infrastructure
|
|
16
|
+
const { alignResponseFields } = llm
|
|
17
|
+
|
|
18
|
+
const { pagesDir } = config
|
|
19
|
+
const startTime = Date.now()
|
|
20
|
+
const fileName = liveResponse?.fileName ?? path.basename(filePath, path.extname(filePath))
|
|
21
|
+
const resourcePath = path.join(process.cwd(), pagesDir, fileName, 'resource.js')
|
|
22
|
+
|
|
23
|
+
const spinner = pod153.start(dialog.pod153.reconEncryptedData(fileName))
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
if (!fs.existsSync(resourcePath)) {
|
|
27
|
+
pod153.fail(spinner, dialog.pod153.unknownModule(fileName))
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let rawJson = liveResponse ? liveResponse.data : JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
|
32
|
+
let resourceStr = fs.readFileSync(resourcePath, 'utf8')
|
|
33
|
+
|
|
34
|
+
const coreArray = unwrapSignal(rawJson)
|
|
35
|
+
if (!coreArray || coreArray.length === 0) {
|
|
36
|
+
pod153.warning(spinner, dialog.pod153.formatError)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
nineS.update(spinner, dialog.nineS.scanningField)
|
|
40
|
+
|
|
41
|
+
const extractKeys = str => {
|
|
42
|
+
const keys = []
|
|
43
|
+
const regex = /(dataIndex|name)\s*:\s*['"]([^'"]+)['"]/g
|
|
44
|
+
let match
|
|
45
|
+
while ((match = regex.exec(str)) !== null) {
|
|
46
|
+
keys.push(match[2])
|
|
47
|
+
}
|
|
48
|
+
return Array.from(new Set(keys))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const sampleData = coreArray && coreArray.length > 0 ? [coreArray[0]] : rawJson
|
|
52
|
+
const result = await alignResponseFields({ responseStr: JSON.stringify(sampleData), resourceStr: extractKeys(resourceStr).join(',') })
|
|
53
|
+
let changeCount = 0
|
|
54
|
+
const resultMapping = {}
|
|
55
|
+
Object.entries(result).forEach(([oldField, newField]) => {
|
|
56
|
+
if (oldField === newField) return
|
|
57
|
+
const regex = new RegExp(`(dataIndex|name)\\s*:\\s*['"]${oldField}['"]`, 'g')
|
|
58
|
+
resourceStr = resourceStr.replace(regex, `$1: '${newField}'`)
|
|
59
|
+
changeCount++
|
|
60
|
+
resultMapping[oldField] = newField
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
fs.writeFileSync(resourcePath, resourceStr)
|
|
64
|
+
const endTime = Date.now()
|
|
65
|
+
|
|
66
|
+
pod153.success(spinner, dialog.pod153.bridgeProtocolComplete(changeCount, (endTime - startTime) / 1000))
|
|
67
|
+
|
|
68
|
+
if (changeCount > 0) {
|
|
69
|
+
console.log(chalk.magenta(`\n┌────── [ YoRHa Autonomous Backend Alignment ] ──────┐`))
|
|
70
|
+
const maxOldFieldLength = Math.max(...Object.keys(resultMapping).map(key => key.length))
|
|
71
|
+
Object.entries(resultMapping).forEach(([oldField, newField]) => {
|
|
72
|
+
const padding = ' '.repeat(Math.max(1, maxOldFieldLength + 1 - oldField.length))
|
|
73
|
+
console.log(
|
|
74
|
+
chalk.yellow(` │ `) +
|
|
75
|
+
chalk.yellow(oldField) +
|
|
76
|
+
padding +
|
|
77
|
+
chalk.cyan(` -> `) +
|
|
78
|
+
chalk.white(newField)
|
|
79
|
+
)
|
|
80
|
+
})
|
|
81
|
+
console.log(chalk.magenta(`└────────────────────────────────────────────────────┘`))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (fs.existsSync(filePath)) {
|
|
85
|
+
fs.unlinkSync(filePath)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
} catch (error) {
|
|
89
|
+
pod153.fail(spinner, dialog.pod153.alignmentFailed(error))
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
watch: 'screenShot',
|
|
6
|
+
async handle(filePath) {
|
|
7
|
+
|
|
8
|
+
const { ux, llm, yorha, dialogs, prompts, generator, infrastructure } = require('../bootstrap').get()
|
|
9
|
+
|
|
10
|
+
const { local } = ux
|
|
11
|
+
const dialog = dialogs[local]
|
|
12
|
+
const { pagePrompt } = prompts
|
|
13
|
+
const { nineS, pod042 } = yorha
|
|
14
|
+
const { index, resource } = generator
|
|
15
|
+
const { generateMock, recognizePage } = llm
|
|
16
|
+
const { menus, config, contextStringify } = infrastructure
|
|
17
|
+
|
|
18
|
+
const { useDemo, pagesDir, needMock } = config
|
|
19
|
+
|
|
20
|
+
const startTime = Date.now()
|
|
21
|
+
const fileName = path.basename(filePath, path.extname(filePath))
|
|
22
|
+
const mockDir = path.join(process.cwd(), 'mock')
|
|
23
|
+
const targetDir = path.join(process.cwd(), pagesDir, fileName)
|
|
24
|
+
|
|
25
|
+
const spinner = pod042.start(dialog.pod042.visualCaptured(fileName))
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
if (fs.existsSync(targetDir)) {
|
|
29
|
+
pod042.warning(spinner, dialog.pod042.intercept(fileName))
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!fs.existsSync(mockDir)) fs.mkdirSync(mockDir, { recursive: true })
|
|
34
|
+
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true })
|
|
35
|
+
|
|
36
|
+
let pageConfig
|
|
37
|
+
if (useDemo) {
|
|
38
|
+
pod042.report(dialog.pod042.simulate)
|
|
39
|
+
pageConfig = require('../../example/example.json')
|
|
40
|
+
} else {
|
|
41
|
+
pod042.update(spinner, dialog.pod042.uploadVisualMetadata)
|
|
42
|
+
pageConfig = await recognizePage({ prompt: pagePrompt, filePath })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fs.writeFileSync(path.join(targetDir, 'resource.js'), resource({ pageConfig }))
|
|
46
|
+
fs.writeFileSync(path.join(targetDir, 'index.js'), index({ fileName, pageConfig }))
|
|
47
|
+
|
|
48
|
+
if (!menus.find(m => m.key === fileName)) {
|
|
49
|
+
menus.push({ label: fileName, key: fileName })
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (needMock) {
|
|
53
|
+
nineS.update(spinner, dialog.nineS.dataCamouflage(fileName))
|
|
54
|
+
const rawContent = await generateMock({ columns: pageConfig.table.columns, fileName })
|
|
55
|
+
fs.writeFileSync(path.join(mockDir, `${fileName}.js`), `export default ${contextStringify({ context: rawContent })}`)
|
|
56
|
+
nineS.success(spinner, dialog.nineS.dataCamouflageComplete)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const endTime = Date.now()
|
|
60
|
+
pod042.success(spinner, dialog.pod042.assemblyComplete(fileName, (endTime - startTime) / 1000))
|
|
61
|
+
|
|
62
|
+
if (fs.existsSync(filePath)) {
|
|
63
|
+
fs.unlinkSync(filePath)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} catch (error) {
|
|
67
|
+
pod042.fail(spinner, dialog.pod042.constructionAborted(error))
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
watch: 'screenPart',
|
|
5
|
+
async handle(filePath) {
|
|
6
|
+
|
|
7
|
+
const chalk = require('chalk')
|
|
8
|
+
const { ux, llm, core, yorha, dialogs, prompts, infrastructure } = require('../bootstrap').get()
|
|
9
|
+
|
|
10
|
+
const { local } = ux
|
|
11
|
+
const { pod042 } = yorha
|
|
12
|
+
const dialog = dialogs[local]
|
|
13
|
+
const { recognizePage } = llm
|
|
14
|
+
const { partPrompt } = prompts
|
|
15
|
+
const { contextStringify } = infrastructure
|
|
16
|
+
const { cleanCode, formatFormItemAndColumns } = core
|
|
17
|
+
|
|
18
|
+
const startTime = Date.now()
|
|
19
|
+
|
|
20
|
+
const spinner = pod042.start(dialog.pod042.visualPartCaptured)
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
pod042.update(spinner, dialog.pod042.extractingUiMetadata)
|
|
24
|
+
|
|
25
|
+
const pageConfig = await recognizePage({ prompt: partPrompt, filePath, taskType: 'part' })
|
|
26
|
+
|
|
27
|
+
const { formItems, dictBlocks, processedColumns } = formatFormItemAndColumns({ pageConfig })
|
|
28
|
+
|
|
29
|
+
const result = Object.fromEntries(Object.entries({ formItems, processedColumns }).filter(([key, value]) => value?.length > 0))
|
|
30
|
+
|
|
31
|
+
let mainConfigStr = cleanCode(contextStringify({ context: result }))
|
|
32
|
+
|
|
33
|
+
let optionsCodeStr = ''
|
|
34
|
+
dictBlocks.forEach(key => {
|
|
35
|
+
const optionsArray = pageConfig.optionDict?.[key] ?? []
|
|
36
|
+
const arrayItemsStr = optionsArray.map(opt => ` { label: '${opt.label}', value: '${opt.value}' }`).join(',\n')
|
|
37
|
+
optionsCodeStr += `\nexport const ${key} = [\n${arrayItemsStr}\n]\n`
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const finalResult = `${mainConfigStr}\n${optionsCodeStr}`
|
|
41
|
+
const endTime = Date.now()
|
|
42
|
+
spinner.stop()
|
|
43
|
+
console.log(chalk.magenta(`\n┌────────────────── [ YoRHa Construction Output ] ─────────────────┐`))
|
|
44
|
+
console.log(chalk.magenta(`│ Source: ${filePath}`))
|
|
45
|
+
console.log(chalk.magenta(`│ Protocol: Partial UI Fragment | Status: SUCCESS`))
|
|
46
|
+
console.log(chalk.magenta(`├───────────────────────────────────────────────────────────────────┘`))
|
|
47
|
+
console.log(chalk.white(finalResult))
|
|
48
|
+
pod042.success(spinner, dialog.pod042.partialConstruction((endTime - startTime) / 1000))
|
|
49
|
+
pod042.success(spinner, dialog.pod042.partialRecommendation)
|
|
50
|
+
|
|
51
|
+
if (fs.existsSync(filePath)) {
|
|
52
|
+
fs.unlinkSync(filePath)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
} catch (error) {
|
|
56
|
+
pod042.fail(spinner, dialog.pod042.partialConstructionAborted(error))
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/labs/linker.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const chalk = require('chalk')
|
|
4
|
+
module.exports = async () => {
|
|
6
5
|
|
|
7
|
-
const { ux, llm, infrastructure } = require('../bootstrap').get()
|
|
6
|
+
const { ux, llm, yorha, dialogs, infrastructure } = require('../bootstrap').get()
|
|
8
7
|
|
|
9
|
-
const {
|
|
8
|
+
const { local } = ux
|
|
10
9
|
const { apiLinker } = llm
|
|
10
|
+
const dialog = dialogs[local]
|
|
11
|
+
const { pod153, commander } = yorha
|
|
11
12
|
const { config, getLocalScore, getSemanticKeywords, } = infrastructure
|
|
12
13
|
|
|
13
14
|
const { apiDoc, pagesDir } = config
|
|
14
15
|
if (!apiDoc) return
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
`\n🤖 Pod 153: 启动‘全频道自动寻址协议 [语义扫描版]’...`,
|
|
18
|
-
`\n🤖 Pod 153: Initiating 'Full-Channel Autonomous Addressing Protocol [Semantic Scan]'...`
|
|
19
|
-
)))
|
|
17
|
+
pod153.report(dialog.pod153.autonomousAddressing, 'magenta')
|
|
20
18
|
|
|
21
19
|
try {
|
|
22
20
|
// 1. 抓取情报
|
|
@@ -63,12 +61,7 @@ module.exports = async () => {
|
|
|
63
61
|
.slice(0, 20) // 💡 拓宽至前 20 名,给 AI 更多的判别空间
|
|
64
62
|
|
|
65
63
|
const finalCandidates = candidates.map(item => `${item.method} ${item.path} ${item.desc}`).join('\n')
|
|
66
|
-
|
|
67
|
-
console.log(chalk.yellow(language(
|
|
68
|
-
` 🛰️ Inactive module: [${fileName}]. Requesting 9S for precise alignment...`,
|
|
69
|
-
` 🛰️ 发现未通电模块 [${fileName}],请求 9S 执行高精度对账...`
|
|
70
|
-
)))
|
|
71
|
-
|
|
64
|
+
pod153.report(dialog.pod153.inactiveModule(fileName), 'yellow')
|
|
72
65
|
// 3. 驱动 9S 最终裁决
|
|
73
66
|
const result = await apiLinker({ bunkerAnchors, realApis: finalCandidates })
|
|
74
67
|
|
|
@@ -99,23 +92,14 @@ module.exports = async () => {
|
|
|
99
92
|
indexCode = indexCode.replaceAll(`/api/${anchor}`, `/api${cleanPath}`)
|
|
100
93
|
})
|
|
101
94
|
fs.writeFileSync(indexPath, indexCode)
|
|
102
|
-
|
|
103
|
-
`✅ 信号同步完成,${Object.keys(result).length} 个节点已通电。`,
|
|
104
|
-
`✅ Signal Synchronized: ${Object.keys(result).length} nodes energized.`
|
|
105
|
-
)))
|
|
95
|
+
pod153.report(dialog.pod153.signalSynchronized(Object.keys(result).length))
|
|
106
96
|
// 💡 战术免责补丁:采用橙黄色高亮,提醒指挥官保持警惕
|
|
107
|
-
|
|
108
|
-
`⚠️ 匹配结果仅供参考,不构成最终决策,各机体需根据实际情况进行调整。`,
|
|
109
|
-
`⚠️ Match Result Reference Only. Not Final Decision. Each Unit should adjust based on battlefield conditions.`
|
|
110
|
-
)))
|
|
97
|
+
commander.log(dialog.bunker.disclaimer, 'yellow')
|
|
111
98
|
}
|
|
112
99
|
}
|
|
113
100
|
}
|
|
114
101
|
}
|
|
115
102
|
} catch (e) {
|
|
116
|
-
|
|
117
|
-
`\n❌ Pod 153: 信号链路故障: ${e.message}\n`,
|
|
118
|
-
`\n❌ Pod 153: Signal Link Fault: ${e.message}\n`
|
|
119
|
-
)))
|
|
103
|
+
pod153.report(dialog.pod153.signalLinkFault(e.message), 'red')
|
|
120
104
|
}
|
|
121
105
|
}
|
package/src/labs/tower.js
CHANGED
|
@@ -7,13 +7,13 @@ module.exports = () => {
|
|
|
7
7
|
|
|
8
8
|
const http = require('http')
|
|
9
9
|
const zlib = require('zlib')
|
|
10
|
-
const chalk = require('chalk')
|
|
11
10
|
const httpProxy = require('http-proxy')
|
|
12
11
|
|
|
13
|
-
const { ux, core, handlers, infrastructure } = require('../bootstrap').get()
|
|
12
|
+
const { ux, core, yorha, dialogs, handlers, infrastructure } = require('../bootstrap').get()
|
|
14
13
|
|
|
15
|
-
const {
|
|
16
|
-
const {
|
|
14
|
+
const { local } = ux
|
|
15
|
+
const { pod153 } = yorha
|
|
16
|
+
const dialog = dialogs[local]
|
|
17
17
|
const { config } = infrastructure
|
|
18
18
|
const { unwrapSignal, isQuerySignal } = core
|
|
19
19
|
const { routeMap = {}, proxyTarget } = config
|
|
@@ -58,16 +58,13 @@ module.exports = () => {
|
|
|
58
58
|
return
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
`\n📡 Pod 153: 截获运行时信号 [${fileName}]。执行自动对齐协议...`,
|
|
63
|
-
`\n📡 Pod 153: Captured runtime signal [${fileName}]. Executing semantic alignment protocol...`
|
|
64
|
-
)))
|
|
61
|
+
pod153.report(dialog.pod153.capturedRuntimeSignal(fileName))
|
|
65
62
|
// 💡 直接调用 api-handler 物理更新 resource.js
|
|
66
|
-
await
|
|
63
|
+
await handlers.api.handle(null, { fileName, data: json })
|
|
67
64
|
hackedRegistry.set(fileName, fingerprint)
|
|
68
65
|
} catch (e) {
|
|
69
|
-
console.log(e)
|
|
70
66
|
// 非 JSON 信号,保持静默
|
|
67
|
+
console.log(e)
|
|
71
68
|
}
|
|
72
69
|
})
|
|
73
70
|
})
|
|
@@ -81,14 +78,5 @@ module.exports = () => {
|
|
|
81
78
|
proxy.web(req, res, { target: proxyTarget, changeOrigin: true })
|
|
82
79
|
})
|
|
83
80
|
|
|
84
|
-
server.listen(TOWER_PORT, () => {
|
|
85
|
-
console.log(chalk.magenta(language(
|
|
86
|
-
`✨ YoRHa 联合基站:信号拦截塔已在线 [波段: ${TOWER_PORT}]`,
|
|
87
|
-
`✨ YoRHa Joint Station: Signal Intercept Tower Online [Band: ${TOWER_PORT}]`
|
|
88
|
-
)))
|
|
89
|
-
console.log(chalk.gray(language(
|
|
90
|
-
`💡 指令:请将您的代理目标指向 http://localhost:${TOWER_PORT}`,
|
|
91
|
-
`💡 Command: Please point your local proxy target to http://localhost:${TOWER_PORT}`
|
|
92
|
-
)))
|
|
93
|
-
})
|
|
81
|
+
server.listen(TOWER_PORT, () => {})
|
|
94
82
|
}
|
package/src/services/llm.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
const
|
|
3
|
-
const { language } = require('../utils/ux')
|
|
4
|
-
|
|
5
|
-
const askAI = async ({ model, openAI, messages, response_format = { type: 'json_object' }, retryCount = 0 }) => {
|
|
2
|
+
const askAI = async ({ model, yorha, dialog, openAI, messages, response_format = { type: 'json_object' }, retryCount = 0 }) => {
|
|
6
3
|
|
|
7
4
|
if (retryCount > 3) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'YoRHa Command Link Severed: Check network status or Black Box resonance.'
|
|
11
|
-
))
|
|
5
|
+
yorha.commander.log(dialog.bunker.linkSevered, 'red')
|
|
6
|
+
throw new Error()
|
|
12
7
|
}
|
|
13
8
|
|
|
14
9
|
try {
|
|
@@ -28,32 +23,32 @@ const askAI = async ({ model, openAI, messages, response_format = { type: 'json_
|
|
|
28
23
|
const statusCode = err.status || err.response?.status
|
|
29
24
|
const isAuthError = err.message.includes('401') || err.message.includes('402') || [401, 402].includes(statusCode)
|
|
30
25
|
if (isAuthError) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
'[SYSTEM ALERT] YoRHa Command Center Access Denied: Invalid API Key or quota exhausted!'
|
|
34
|
-
))
|
|
26
|
+
yorha.commander.log(dialog.bunker.accessDenied, 'red')
|
|
27
|
+
throw new Error()
|
|
35
28
|
}
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
`[系统警告] 神经云网络连接不稳,正在尝试重新链接... (第 ${retryCount + 1} 次重试)`,
|
|
39
|
-
`[SYSTEM ALERT] Neural Network instability detected. Attempting to re-establish link... (Retry #${retryCount + 1})`
|
|
40
|
-
)), err.message)
|
|
30
|
+
yorha.commander.log(dialog.bunker.networkInstability(retryCount + 1))
|
|
41
31
|
|
|
42
|
-
return askAI({ model, messages, response_format, retryCount: retryCount + 1 })
|
|
32
|
+
return askAI({ model, yorha, dialog, openAI, messages, response_format, retryCount: retryCount + 1 })
|
|
43
33
|
}
|
|
44
34
|
}
|
|
45
35
|
|
|
46
|
-
module.exports = ({
|
|
36
|
+
module.exports = ({ ux, config, yorha, openAI, dialogs, template, ...prompts }) => {
|
|
47
37
|
|
|
48
38
|
const sharp = require('sharp')
|
|
49
39
|
|
|
40
|
+
const { local } = ux
|
|
41
|
+
const dialog = dialogs[local]
|
|
50
42
|
const { textModel, visionModel } = config
|
|
43
|
+
const { systemPrompt, apiPrompt, mockPrompt, linkerPrompt } = prompts
|
|
51
44
|
const { UI_DESIGNER, API_DESIGNER, MOCK_DESIGNER } = systemPrompt
|
|
52
45
|
|
|
53
46
|
return {
|
|
54
47
|
generateMock: async ({ columns, fileName }) => {
|
|
55
48
|
return askAI({
|
|
49
|
+
yorha,
|
|
56
50
|
openAI,
|
|
51
|
+
dialog,
|
|
57
52
|
model: textModel,
|
|
58
53
|
messages: [
|
|
59
54
|
{ role: 'system', content: MOCK_DESIGNER },
|
|
@@ -63,7 +58,9 @@ module.exports = ({ config, openAI, template, systemPrompt, apiPrompt, mockPromp
|
|
|
63
58
|
},
|
|
64
59
|
apiLinker: async ({ bunkerAnchors, realApis }) => {
|
|
65
60
|
return askAI({
|
|
61
|
+
yorha,
|
|
66
62
|
openAI,
|
|
63
|
+
dialog,
|
|
67
64
|
model: textModel,
|
|
68
65
|
messages: [
|
|
69
66
|
{ role: 'system', content: API_DESIGNER },
|
|
@@ -73,7 +70,9 @@ module.exports = ({ config, openAI, template, systemPrompt, apiPrompt, mockPromp
|
|
|
73
70
|
},
|
|
74
71
|
alignResponseFields: async ({ responseStr, resourceStr }) => {
|
|
75
72
|
return askAI({
|
|
73
|
+
yorha,
|
|
76
74
|
openAI,
|
|
75
|
+
dialog,
|
|
77
76
|
model: textModel,
|
|
78
77
|
messages: [
|
|
79
78
|
{ role: 'system', content: API_DESIGNER },
|
|
@@ -89,7 +88,9 @@ module.exports = ({ config, openAI, template, systemPrompt, apiPrompt, mockPromp
|
|
|
89
88
|
const base64Image = compressedBuffer.toString('base64')
|
|
90
89
|
|
|
91
90
|
return askAI({
|
|
91
|
+
yorha,
|
|
92
92
|
openAI,
|
|
93
|
+
dialog,
|
|
93
94
|
model: visionModel,
|
|
94
95
|
messages: [
|
|
95
96
|
{ role: 'system', content: UI_DESIGNER },
|
package/src/utils/ux.js
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
const chalk = require('chalk')
|
|
7
7
|
const figlet = require('figlet')
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const language = (zh, en) => (isCN ? zh : en)
|
|
9
|
+
const local = Intl.DateTimeFormat().resolvedOptions().locale.includes('zh') ? 'ZH-CN' : 'EN-US'
|
|
11
10
|
|
|
12
11
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
13
12
|
|
|
@@ -16,22 +15,26 @@ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
|
16
15
|
* 模拟系统引导过程中的动画效果
|
|
17
16
|
* @returns {void}
|
|
18
17
|
*/
|
|
19
|
-
const bootSequence = async version => {
|
|
18
|
+
const bootSequence = async ({ dialog, version, bootTower, commander }) => {
|
|
20
19
|
const lines = [
|
|
21
20
|
chalk.cyan(figlet.textSync('AutoDev', { horizontalLayout: 'full' })),
|
|
22
|
-
chalk.gray('Booting System...'),
|
|
23
|
-
chalk.white('
|
|
24
|
-
chalk.white('
|
|
25
|
-
chalk.white('
|
|
26
|
-
chalk.white('
|
|
27
|
-
chalk.white('
|
|
28
|
-
chalk.white('
|
|
29
|
-
chalk.gray('
|
|
21
|
+
chalk.gray('[BUNKER] Booting System...'),
|
|
22
|
+
chalk.white('[BUNKER] ') + chalk.green('Locale Detection: ') + chalk.cyan(local),
|
|
23
|
+
chalk.white('[BUNKER] ') + chalk.green('YoRHa No.2 Type B Unit: ') + chalk.cyan('Online'),
|
|
24
|
+
chalk.white('[BUNKER] ') + chalk.green('Scanner Type 9S Unit: ') + chalk.cyan('Standby'),
|
|
25
|
+
chalk.white('[BUNKER] ') + chalk.green('Full-Channel Link: ') + chalk.cyan('Established'),
|
|
26
|
+
chalk.white('[BUNKER] ') + chalk.yellow('Construction Protocol: ') + chalk.cyan('v' + version),
|
|
27
|
+
chalk.white('[BUNKER] ') + chalk.magenta('Glory to mankind. (人类荣光永存)'),
|
|
28
|
+
chalk.gray('--------------------------------------------------')
|
|
30
29
|
]
|
|
31
30
|
for (const line of lines) {
|
|
32
31
|
console.log(line)
|
|
33
32
|
await sleep(line.includes('AutoDev') ? 300 : 80)
|
|
34
33
|
}
|
|
34
|
+
if (bootTower) {
|
|
35
|
+
commander.log(dialog.bunker.towerOnline('42153'), 'magenta')
|
|
36
|
+
commander.log(dialog.bunker.towerConnected('42153'), 'magenta')
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -83,17 +86,17 @@ const matrixEffect = async (duration = 1500) => {
|
|
|
83
86
|
const interval = setInterval(() => {
|
|
84
87
|
if (Date.now() > endTime) {
|
|
85
88
|
clearInterval(interval)
|
|
86
|
-
console.log(
|
|
89
|
+
console.log(local ? '所有构筑数据已同步至 Bunker 存储节点。' : 'All data synced to Bunker storage nodes.')
|
|
87
90
|
if (currentTotal !== 0) {
|
|
88
91
|
if (isLegendary) {
|
|
89
|
-
console.log(chalk.yellow.bold(
|
|
90
|
-
console.log(chalk.yellow(
|
|
92
|
+
console.log(chalk.yellow.bold(local ? `物理克隆总数已超越 ${threshold} 战略阈值!当前战力:${currentTotal}` : `Physical clone count has exceeded ${threshold} strategic threshold! Current power: ${currentTotal}`))
|
|
93
|
+
console.log(chalk.yellow(local ? '恭喜您指挥官,您的构筑协议已成为人类荣光的一部分。' : 'Congratulations, your construction protocol is now part of humanity.'))
|
|
91
94
|
} else {
|
|
92
|
-
console.log(chalk.cyan(
|
|
95
|
+
console.log(chalk.cyan(local ? `当前构筑总数:${currentTotal}。距离 ${threshold} 勋章还剩 ${threshold - currentTotal} 次。` : `Current clones: ${currentTotal}. ${threshold - currentTotal} to Achievement.`))
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
console.log(chalk.cyan(
|
|
96
|
-
console.log(chalk.cyan('
|
|
98
|
+
console.log(chalk.cyan(local ? '如果它能帮您节省时间,请在 GitHub 上给它点个赞 ⭐。' : 'If it saves you time, feel free to give it a ⭐ on GitHub.'))
|
|
99
|
+
console.log(chalk.cyan(local ? '系统信号已丢失。' : 'Signal Lost'))
|
|
97
100
|
process.exit(0)
|
|
98
101
|
return
|
|
99
102
|
}
|
|
@@ -112,4 +115,4 @@ const matrixEffect = async (duration = 1500) => {
|
|
|
112
115
|
}, 40)
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
module.exports = {
|
|
118
|
+
module.exports = { local, matrixEffect, bootSequence }
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
module.exports = async (filePath, liveResponse = null) => {
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const ora = require('ora')
|
|
5
|
-
const path = require('path')
|
|
6
|
-
const chalk = require('chalk')
|
|
7
|
-
|
|
8
|
-
const { ux, llm, core, infrastructure } = require('../bootstrap').get()
|
|
9
|
-
|
|
10
|
-
const { language } = ux
|
|
11
|
-
const { unwrapSignal } = core
|
|
12
|
-
const { config } = infrastructure
|
|
13
|
-
const { alignResponseFields } = llm
|
|
14
|
-
|
|
15
|
-
const { pagesDir } = config
|
|
16
|
-
const startTime = Date.now()
|
|
17
|
-
const fileName = liveResponse?.fileName ?? path.basename(filePath, path.extname(filePath))
|
|
18
|
-
const resourcePath = path.join(process.cwd(), pagesDir, fileName, 'resource.js')
|
|
19
|
-
|
|
20
|
-
const spinner = ora({
|
|
21
|
-
text: chalk.yellow(language(
|
|
22
|
-
`🤖 Pod 153: [侦察] 发现加密数据源 [${fileName}]。正在尝试执行语义对齐协议...\n`,
|
|
23
|
-
`🤖 Pod 153: [Recon] Encrypted data source [${fileName}] detected. Initiating semantic alignment...\n`
|
|
24
|
-
)),
|
|
25
|
-
color: 'yellow'
|
|
26
|
-
}).start()
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
if (!fs.existsSync(resourcePath)) {
|
|
30
|
-
throw new Error(language(
|
|
31
|
-
`🤖 Pod 153: [警告] 地堡数据库中未检索到模块 [${fileName}] 的资源文件。请先执行视觉构筑。`,
|
|
32
|
-
`🤖 Pod 153: [Warning] Module [${fileName}] resource not found in Bunker database. Please execute visual construction first.`
|
|
33
|
-
))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let rawJson = liveResponse ? liveResponse.data : JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
|
37
|
-
let resourceStr = fs.readFileSync(resourcePath, 'utf8')
|
|
38
|
-
|
|
39
|
-
const coreArray = unwrapSignal(rawJson)
|
|
40
|
-
|
|
41
|
-
if (!coreArray || coreArray.length === 0) {
|
|
42
|
-
console.log(chalk.gray(language(
|
|
43
|
-
` [System] 数据格式非标准 JSON,将尝试原始字符对齐。`,
|
|
44
|
-
` [System] Data format is not standard JSON, will try to align by character.`)
|
|
45
|
-
))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const sampleData = coreArray && coreArray.length > 0 ? [coreArray[0]] : rawJson
|
|
49
|
-
|
|
50
|
-
spinner.text = chalk.yellow(language(
|
|
51
|
-
`🧑💻 9S: 正在扫描前后端字段差异... 执行语义桥接任务。`,
|
|
52
|
-
`🧑💻 9S: Scanning field differences... Bridging semantic gaps.`
|
|
53
|
-
))
|
|
54
|
-
|
|
55
|
-
const extractKeys = str => {
|
|
56
|
-
const keys = []
|
|
57
|
-
const regex = /(dataIndex|name)\s*:\s*['"]([^'"]+)['"]/g
|
|
58
|
-
let match
|
|
59
|
-
while ((match = regex.exec(str)) !== null) {
|
|
60
|
-
keys.push(match[2])
|
|
61
|
-
}
|
|
62
|
-
return Array.from(new Set(keys))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const result = await alignResponseFields({ responseStr: JSON.stringify(sampleData), resourceStr: extractKeys(resourceStr).join(',') })
|
|
66
|
-
let changeCount = 0
|
|
67
|
-
const resultMapping = {}
|
|
68
|
-
Object.entries(result).forEach(([oldField, newField]) => {
|
|
69
|
-
if (oldField === newField) return
|
|
70
|
-
const regex = new RegExp(`(dataIndex|name)\\s*:\\s*['"]${oldField}['"]`, 'g')
|
|
71
|
-
resourceStr = resourceStr.replace(regex, `$1: '${newField}'`)
|
|
72
|
-
changeCount++
|
|
73
|
-
resultMapping[oldField] = newField
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
fs.writeFileSync(resourcePath, resourceStr)
|
|
77
|
-
const endTime = Date.now()
|
|
78
|
-
|
|
79
|
-
spinner.succeed(chalk.green(language(
|
|
80
|
-
`🤖 Pod 153: [肯定] 语义桥接协议执行完毕。已物理修正 ${changeCount} 处字段偏差。耗时: ${(endTime - startTime) / 1000}s`,
|
|
81
|
-
`🤖 Pod 153: [Affirmative] Semantic bridge protocol complete. Corrected ${changeCount} field deviations. Elapsed: ${(endTime - startTime) / 1000}s`
|
|
82
|
-
)))
|
|
83
|
-
|
|
84
|
-
if (changeCount > 0) {
|
|
85
|
-
console.log(chalk.magenta(`\n┌────── [ YoRHa Autonomous Backend Alignment ] ──────┐`))
|
|
86
|
-
Object.entries(resultMapping).forEach(([oldField, newField]) => {
|
|
87
|
-
// 💡 物理校准:计算空格数量,让箭头对齐在第 15 个字符位
|
|
88
|
-
// 中文字符长度 * 2 是为了抵消它在终端占的双倍宽度
|
|
89
|
-
const padding = ' '.repeat(Math.max(1, 15 - oldField.length * 2))
|
|
90
|
-
console.log(
|
|
91
|
-
chalk.gray(` │ `) +
|
|
92
|
-
chalk.yellow(oldField) +
|
|
93
|
-
padding +
|
|
94
|
-
chalk.cyan(` -> `) +
|
|
95
|
-
chalk.white(newField)
|
|
96
|
-
)
|
|
97
|
-
})
|
|
98
|
-
console.log(chalk.magenta(`└───────────────────────────────────────────────────────┘\n`))
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (fs.existsSync(filePath)) {
|
|
102
|
-
fs.unlinkSync(filePath)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
} catch (error) {
|
|
106
|
-
spinner.fail(chalk.red(language(
|
|
107
|
-
`🤖 Pod 153: [严重警告] 信号对齐失败。接口数据遭遇强力防火墙:${error}`,
|
|
108
|
-
`🤖 Pod 153: [CRITICAL] Alignment failed. Encountered powerful API firewall: ${error}`
|
|
109
|
-
)))
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
module.exports = async filePath => {
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const ora = require('ora')
|
|
5
|
-
const path = require('path')
|
|
6
|
-
const chalk = require('chalk')
|
|
7
|
-
|
|
8
|
-
const { ux, llm, prompts, generator, infrastructure } = require('../bootstrap').get()
|
|
9
|
-
|
|
10
|
-
const { language } = ux
|
|
11
|
-
const { pagePrompt } = prompts
|
|
12
|
-
const { index, resource } = generator
|
|
13
|
-
const { generateMock, recognizePage } = llm
|
|
14
|
-
const { menus, config, contextStringify } = infrastructure
|
|
15
|
-
|
|
16
|
-
const { useDemo, pagesDir, needMock } = config
|
|
17
|
-
|
|
18
|
-
const startTime = Date.now()
|
|
19
|
-
const fileName = path.basename(filePath, path.extname(filePath))
|
|
20
|
-
const mockDir = path.join(process.cwd(), 'mock')
|
|
21
|
-
const targetDir = path.join(process.cwd(), pagesDir, fileName)
|
|
22
|
-
|
|
23
|
-
const spinner = ora({
|
|
24
|
-
text: chalk.cyan(language(
|
|
25
|
-
`[System] 视觉传感器捕捉完成: [${fileName}]。正在调配地堡资源进行物理构筑...\n`,
|
|
26
|
-
`[System] Visual sensor captured: [${fileName}]. Allocating Bunker resources for physical construction...\n`
|
|
27
|
-
)),
|
|
28
|
-
color: 'cyan'
|
|
29
|
-
}).start()
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
|
|
33
|
-
if (fs.existsSync(targetDir)) {
|
|
34
|
-
spinner.warn(chalk.yellow(language(
|
|
35
|
-
`🤖 Pod 042: [拦截] 模块 [${fileName}] 已存在于地堡数据库中。为了防止数据覆盖,构筑协议已跳过。`,
|
|
36
|
-
`🤖 Pod 042: [Intercept] Module [${fileName}] already exists. Construction skipped to prevent overwrite.`
|
|
37
|
-
)))
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!fs.existsSync(mockDir)) fs.mkdirSync(mockDir, { recursive: true })
|
|
42
|
-
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true })
|
|
43
|
-
|
|
44
|
-
let pageConfig
|
|
45
|
-
if (useDemo) {
|
|
46
|
-
console.log(chalk.yellow(language(
|
|
47
|
-
`\n🤖 Pod 042: [报告] 拦截到实弹请求。正在空投标准模拟包: example.json\n`,
|
|
48
|
-
`\n🤖 Pod 042: [Report] Real-fire request intercepted. Dropping simulation package: example.json\n`
|
|
49
|
-
)))
|
|
50
|
-
pageConfig = require('../../example/example.json')
|
|
51
|
-
} else {
|
|
52
|
-
spinner.text = chalk.cyan(language(
|
|
53
|
-
`🤖 Pod 042: 正在上传视觉元数据至司令部进行语义分析...\n`,
|
|
54
|
-
`🤖 Pod 042: Uploading visual metadata to Command for semantic analysis...\n`
|
|
55
|
-
))
|
|
56
|
-
pageConfig = await recognizePage({ prompt: pagePrompt, filePath })
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
fs.writeFileSync(path.join(targetDir, 'resource.js'), resource({ pageConfig }))
|
|
60
|
-
fs.writeFileSync(path.join(targetDir, 'index.js'), index({ fileName, pageConfig }))
|
|
61
|
-
|
|
62
|
-
if (!menus.find(m => m.key === fileName)) {
|
|
63
|
-
menus.push({ label: fileName, key: fileName })
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (needMock) {
|
|
67
|
-
spinner.text = chalk.yellow(language(
|
|
68
|
-
`🧑💻 9S: 正在突破目标防火墙... 执行数据伪装程序 [${fileName}]`,
|
|
69
|
-
`🧑💻 9S: Piercing target firewall... Executing data camouflage [${fileName}]`
|
|
70
|
-
))
|
|
71
|
-
const rawContent = await generateMock({ columns: pageConfig.table.columns, fileName })
|
|
72
|
-
fs.writeFileSync(path.join(mockDir, `${fileName}.js`), `export default ${contextStringify({ context: rawContent })}`)
|
|
73
|
-
console.log(chalk.green(language(
|
|
74
|
-
`\n[Success] 9S 报告: Mock 数据生成成功`,
|
|
75
|
-
`\n[Success] 9S Report: Mock data generation successful.`
|
|
76
|
-
)))
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const endTime = Date.now()
|
|
80
|
-
spinner.succeed(chalk.green(language(
|
|
81
|
-
`🤖 Pod 042: [报告] 构筑协议执行完毕。模块 [${fileName}] 物理装配达成。耗时: ${(endTime - startTime) / 1000}s`,
|
|
82
|
-
`🤖 Pod 042: [Report] Protocol complete. Physical assembly of [${fileName}] achieved. Elapsed: ${(endTime - startTime) / 1000}s`
|
|
83
|
-
)))
|
|
84
|
-
|
|
85
|
-
if (fs.existsSync(filePath)) {
|
|
86
|
-
fs.unlinkSync(filePath)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
} catch (error) {
|
|
90
|
-
spinner.fail(chalk.red(language(
|
|
91
|
-
`🤖 Pod 042: [警告] 构筑中断。检测到逻辑病毒或连接超时:${error}`,
|
|
92
|
-
`🤖 Pod 042: [Warning] Construction aborted. Logic virus or timeout detected: ${error}`
|
|
93
|
-
)))
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
module.exports = async filePath => {
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const ora = require('ora')
|
|
5
|
-
const chalk = require('chalk')
|
|
6
|
-
|
|
7
|
-
const { ux, llm, core, prompts, infrastructure } = require('../bootstrap').get()
|
|
8
|
-
|
|
9
|
-
const { language } = ux
|
|
10
|
-
const { partPrompt } = prompts
|
|
11
|
-
const { recognizePage } = llm
|
|
12
|
-
const { contextStringify } = infrastructure
|
|
13
|
-
const { cleanCode, formatFormItemAndColumns } = core
|
|
14
|
-
|
|
15
|
-
const startTime = Date.now()
|
|
16
|
-
|
|
17
|
-
const spinner = ora({
|
|
18
|
-
text: chalk.cyan(language(
|
|
19
|
-
`[System] 侦测到局部视觉样本。正在执行“碎片构筑协议”...`,
|
|
20
|
-
`[System] Partial visual sample detected. Executing 'Fragment Construction Protocol'...`
|
|
21
|
-
)),
|
|
22
|
-
color: 'cyan'
|
|
23
|
-
}).start()
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
spinner.text = chalk.cyan(language(
|
|
27
|
-
`🤖 Pod 042: 正在从神经云网络提取 UI 元数据...\n`,
|
|
28
|
-
`🤖 Pod 042: Extracting UI metadata from neural cloud network...\n`
|
|
29
|
-
))
|
|
30
|
-
|
|
31
|
-
const pageConfig = await recognizePage({ prompt: partPrompt, filePath, taskType: 'part' })
|
|
32
|
-
|
|
33
|
-
const { formItems, dictBlocks, processedColumns } = formatFormItemAndColumns({ pageConfig })
|
|
34
|
-
|
|
35
|
-
const result = Object.fromEntries(Object.entries({ formItems, processedColumns }).filter(([key, value]) => value?.length > 0))
|
|
36
|
-
|
|
37
|
-
let mainConfigStr = cleanCode(contextStringify({ context: result }))
|
|
38
|
-
|
|
39
|
-
let optionsCodeStr = ''
|
|
40
|
-
dictBlocks.forEach(key => {
|
|
41
|
-
const optionsArray = pageConfig.optionDict?.[key] ?? []
|
|
42
|
-
const arrayItemsStr = optionsArray.map(opt => ` { label: '${opt.label}', value: '${opt.value}' }`).join(',\n')
|
|
43
|
-
optionsCodeStr += `\nexport const ${key} = [\n${arrayItemsStr}\n]\n`
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const finalResult = `${mainConfigStr}\n${optionsCodeStr}`
|
|
47
|
-
const endTime = Date.now()
|
|
48
|
-
|
|
49
|
-
spinner.stop()
|
|
50
|
-
|
|
51
|
-
console.log(chalk.magenta(`\n┌────────────────── [ YoRHa Construction Output ] ──────────────────┐`))
|
|
52
|
-
console.log(chalk.gray(`│ Source: ${filePath}`))
|
|
53
|
-
console.log(chalk.gray(`│ Protocol: Partial UI Fragment | Status: SUCCESS`))
|
|
54
|
-
console.log(chalk.magenta(`├────────────────────────────────────────────────────────────────────┘`))
|
|
55
|
-
console.log(chalk.white(finalResult))
|
|
56
|
-
console.log(chalk.magenta(`┌────────────────────────────────────────────────────────────────────┐`))
|
|
57
|
-
console.log(chalk.green(language(
|
|
58
|
-
`│ 🤖 Pod 042 报告:局部构筑达成。耗时: ${(endTime - startTime) / 1000}s`,
|
|
59
|
-
`│ 🤖 Pod 042 Report: Partial construction achieved. Elapsed: ${(endTime - startTime) / 1000}s`
|
|
60
|
-
)))
|
|
61
|
-
console.log(chalk.green(language(
|
|
62
|
-
`│ 命令:请手动将上述代码块物理装配至您的目标文件中。`,
|
|
63
|
-
`│ Command: Please manually assemble the above code block into your target file.`
|
|
64
|
-
)))
|
|
65
|
-
console.log(chalk.magenta(`└───────────────────────────────────────────────────────────────────┘\n`))
|
|
66
|
-
|
|
67
|
-
if (fs.existsSync(filePath)) {
|
|
68
|
-
fs.unlinkSync(filePath)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
} catch (error) {
|
|
72
|
-
spinner.fail(chalk.red(language(
|
|
73
|
-
`🤖 Pod 042: [警告] 碎片构筑失败。系统检测到逻辑干扰:${error}`,
|
|
74
|
-
`🤖 Pod 042: [Warning] Fragment construction failed. Logic interference detected: ${error}`
|
|
75
|
-
)))
|
|
76
|
-
}
|
|
77
|
-
}
|
|
File without changes
|