@yorha2b-lab/autodev 5.2.0 → 5.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "description": "基于视觉大模型的前端(react+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -42,12 +42,21 @@ module.exports = {
42
42
  return instance
43
43
  },
44
44
 
45
- get: () => instance,
45
+ get: () => {
46
+ return new Proxy({}, {
47
+ get(target, prop) {
48
+ if (!instance) {
49
+ throw new Error()
50
+ }
51
+ return instance[prop]
52
+ }
53
+ })
54
+ },
46
55
 
47
56
  reboot() {
48
57
  const { template, dialog } = instance
49
58
  delete require.cache[require.resolve(path.join(process.cwd(), 'config.js'))]
50
- instance.labs?.shutdown?.()
59
+ instance.labs?.tower?.close()
51
60
  instance = null
52
61
  return this.init({ template }, dialog)
53
62
  }
@@ -1,21 +1,16 @@
1
- let tower
2
-
3
1
  module.exports = accessPoint => {
4
2
 
3
+ const labs = {}
4
+
5
5
  const { apiDoc, needMock, proxyTarget, enableAutoAlignment } = accessPoint.config
6
6
 
7
7
  if (!needMock && proxyTarget && enableAutoAlignment) {
8
- tower = require('../labs/tower')(accessPoint)
8
+ labs.tower = require('../labs/tower')(accessPoint)
9
9
  }
10
10
 
11
11
  if (apiDoc && enableAutoAlignment) {
12
- require('../labs/linker')(accessPoint)
12
+ labs.council = require('../labs/council')(accessPoint)
13
13
  }
14
14
 
15
- return {
16
- shutdown() {
17
- tower?.close()
18
- }
19
-
20
- }
15
+ return labs
21
16
  }
@@ -5,20 +5,16 @@ module.exports = () => {
5
5
  const chokidar = require('chokidar')
6
6
 
7
7
  const bootstrap = require('../bootstrap')
8
- const { core, menus, yorha, config, dialog, handlers, foundation } = bootstrap.get()
8
+ const ctx = bootstrap.get()
9
9
 
10
- const { createTaskQueue } = core
11
- const { contextStringify } = foundation
12
- const { pod042, commander, operator6O } = yorha
13
-
14
- const queue = createTaskQueue(2)
10
+ const queue = ctx.core.createTaskQueue(2)
15
11
 
16
12
  queue.onIdle(() => {
17
- pod042.report(dialog.pod042.queueEmpty)
18
- const utilsDir = path.join(process.cwd(), config.utilsDir)
13
+ ctx.yorha.pod042.report(ctx.dialog.pod042.queueEmpty)
14
+ const utilsDir = path.join(process.cwd(), ctx.config.utilsDir)
19
15
  if (!fs.existsSync(utilsDir)) fs.mkdirSync(utilsDir, { recursive: true })
20
- fs.writeFileSync(path.join(utilsDir, 'menus.js'), `export const menus = ${contextStringify({ context: menus, maxLength: 50 })}`)
21
- commander.report(dialog.bunker.systemStandby, 'gray')
16
+ fs.writeFileSync(path.join(utilsDir, 'menus.js'), `export const menus = ${ctx.foundation.contextStringify({ context: ctx.menus, maxLength: 50 })}`)
17
+ ctx.yorha.commander.report(ctx.dialog.bunker.systemStandby, 'gray')
22
18
  })
23
19
 
24
20
  const options = {
@@ -31,9 +27,9 @@ module.exports = () => {
31
27
  const fileWatcher = chokidar.watch(['./config.js'], options)
32
28
  const dirWatcher = chokidar.watch(['./screenShot', './screenPart', './response'], options)
33
29
 
34
- operator6O.report(dialog.operator6O.call2B)
30
+ ctx.yorha.operator6O.report(ctx.dialog.operator6O.call2B)
35
31
 
36
- const routes = Object.values(handlers)
32
+ const routes = Object.values(ctx.handlers)
37
33
 
38
34
  dirWatcher.on('add', filePath => {
39
35
  const absolutePath = path.resolve(filePath)
@@ -48,6 +48,7 @@ module.exports = {
48
48
  systemOffline: 'Disconnecting Neural Link, Executing Physical Assembly...',
49
49
  accessDenied: 'YoRHa Command Center Access Denied: Invalid API Key or quota exhausted!',
50
50
  watchDesc: 'Start full-channel linked monitoring: Coordinated Page/Part/API construction',
51
+ copyEnum: `│ Backend Enums detected \n│ Weld the code below into the module's resource center`,
51
52
  towerConnected: port => `Command: Please point your local proxy target to http://localhost:${port}`,
52
53
  disclaimer: 'Match Result Reference Only. Not Final Decision. Each Unit should adjust based on battlefield conditions',
53
54
  frameworkNotSupported: template => `[${template}] framework not supported. Welcome to contribute a Pull Request to help`,
@@ -50,6 +50,7 @@ module.exports = {
50
50
  accessDenied: '司令部拒绝访问:API Key 无效或额度耗尽,请检查!',
51
51
  disclaimer: '匹配结果仅供参考,不构成最终决策,各机体需根据实际情况进行调整',
52
52
  towerConnected: port => `指令:请将您的代理目标指向 http://localhost:${port}`,
53
+ copyEnum: '│ 侦察到后端原始基因(Enum) \n│ 建议:将下方代码片段物理焊接到该模块的资源中心',
53
54
  networkInstability: count => `神经云网络连接不稳,正在尝试重新链接... (第 ${count} 次重试)`,
54
55
  frameworkNotSupported: template => `暂不支持 [${template}] 框架。欢迎提交 Pull Request 贡献`,
55
56
  strategicThreshold: (target, current) => `物理克隆总数已超越 ${target} 战略阈值!当前战力:${current}`,
@@ -12,7 +12,7 @@ ${realApis}
12
12
  - 识别后缀(如 edit, delete, add)。
13
13
  - 结合 UI 语义,在 API 库中寻找对应路径。
14
14
  - **输出格式**:请只输出一个 JSON 映射表。
15
- - **例如**:{"BUNKER_API_ANCHOR_editByRecord": "[method] /api/v1/update-user"}
15
+ - **例如**:{"BUNKER_API_ANCHOR_editByRecord": "[method] /v1/update-user"}
16
16
 
17
17
  ⚠️ 严禁解释,严禁输出 JSON 之外的内容。
18
18
  `.trim()
@@ -6,16 +6,17 @@ module.exports = {
6
6
  async handle(filePath, liveResponse = null) {
7
7
 
8
8
  const chalk = require('chalk')
9
- const { llm, core, yorha, dialog, config } = require('../bootstrap').get()
9
+ const { llm, core, labs, yorha, dialog, config } = require('../bootstrap').get()
10
10
 
11
11
  const { pagesDir } = config
12
- const { unwrapSignal } = core
13
12
  const { nineS, pod153 } = yorha
14
13
  const { alignResponseFields } = llm
14
+ const { cleanCode, unwrapSignal } = core
15
15
 
16
16
  const startTime = Date.now()
17
17
  const fileName = liveResponse?.fileName ?? path.basename(filePath, path.extname(filePath))
18
18
  const resourcePath = path.join(process.cwd(), pagesDir, fileName, 'resource.js')
19
+ const enumParams = (await labs?.council)?.[fileName] ?? ''
19
20
 
20
21
  const spinner = pod153.start(dialog.pod153.reconEncryptedData(fileName))
21
22
 
@@ -42,7 +43,7 @@ module.exports = {
42
43
  while ((match = regex.exec(str)) !== null) {
43
44
  keys.push(match[2])
44
45
  }
45
- return Array.from(new Set(keys))
46
+ return Array.from(new Set(keys.filter(key => key !== 'index')))
46
47
  }
47
48
 
48
49
  const sampleData = coreArray && coreArray.length > 0 ? [coreArray[0]] : rawJson
@@ -78,6 +79,13 @@ module.exports = {
78
79
  console.log(chalk.magenta(`└────────────────────────────────────────────────────┘`))
79
80
  }
80
81
 
82
+ if (enumParams) {
83
+ console.log(chalk.magenta(`\n┌──────── [ YoRHa Physical Assembly: Enum Genomes ] ────────┐`))
84
+ console.log(chalk.gray(dialog.bunker.copyEnum))
85
+ console.log(chalk.white(cleanCode(enumParams)))
86
+ console.log(chalk.magenta(`├───────────────────────────────────────────────────────────┘`))
87
+ }
88
+
81
89
  if (fs.existsSync(filePath)) {
82
90
  fs.unlinkSync(filePath)
83
91
  }
@@ -1,11 +1,12 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
3
 
4
- module.exports = async ({ llm, core, yorha, dialog, config }) => {
4
+ module.exports = async ({ llm, core, yorha, dialog, config, foundation }) => {
5
5
 
6
- const { apiLinker } = llm
6
+ const { apiParser } = llm
7
7
  const { pod153, commander } = yorha
8
8
  const { apiDoc, pagesDir } = config
9
+ const { contextStringify } = foundation
9
10
  const { getLocalScore, getSemanticKeywords } = core
10
11
 
11
12
  if (!apiDoc) return
@@ -27,6 +28,7 @@ module.exports = async ({ llm, core, yorha, dialog, config }) => {
27
28
  // 2. 战场侦察
28
29
  const pages = path.join(process.cwd(), pagesDir)
29
30
  const files = fs.readdirSync(pages)
31
+ const enumParamsMap = {}
30
32
 
31
33
  for (const fileName of files) {
32
34
  const indexPath = path.join(pages, fileName, 'index.js')
@@ -34,6 +36,7 @@ module.exports = async ({ llm, core, yorha, dialog, config }) => {
34
36
 
35
37
  if (fs.existsSync(indexPath) && fs.existsSync(resourcePath)) {
36
38
  let indexCode = fs.readFileSync(indexPath, 'utf-8')
39
+ let resourceCode = fs.readFileSync(resourcePath, 'utf-8')
37
40
 
38
41
  // 💡 锁定待通电锚点
39
42
  if (indexCode.includes('BUNKER_API_ANCHOR')) {
@@ -59,15 +62,13 @@ module.exports = async ({ llm, core, yorha, dialog, config }) => {
59
62
  const finalCandidates = candidates.map(item => `${item.method} ${item.path} ${item.desc}`).join('\n')
60
63
  pod153.report(dialog.pod153.inactiveModule(fileName), 'yellow')
61
64
  // 3. 驱动 9S 最终裁决
62
- const result = await apiLinker({ bunkerAnchors, realApis: finalCandidates })
65
+ const result = await apiParser({ bunkerAnchors, realApis: finalCandidates })
63
66
 
64
67
  if (result) {
65
68
  // 💡 执行物理更替
66
69
  Object.entries(result).forEach(([anchor, fullSignal]) => {
67
70
  // 💡 1. 信号解压
68
- const parts = fullSignal.split(' ')
69
- const realMethod = parts[0].toUpperCase()
70
- const realPath = parts[1]
71
+ const [realMethod, realPath] = fullSignal.split(' ')
71
72
 
72
73
  // 💡 2. 路径清洗:确保路径拼接时不产生双斜杠 //
73
74
  // 逻辑:如果 realPath 以 / 开头,咱们拼接时就得小心
@@ -82,11 +83,21 @@ module.exports = async ({ llm, core, yorha, dialog, config }) => {
82
83
 
83
84
  // 💡 4. 执行“全频道通电”
84
85
  // $1 现在包含了 request('/api 这一串
85
- indexCode = indexCode.replace(requestRegex, `$1${cleanPath}$2${realMethod}$4`)
86
+ indexCode = indexCode.replace(requestRegex, `$1${cleanPath}$2${realMethod.toUpperCase()}$4`)
86
87
  // 💡 5. 兜底替换(针对没有 method 配置的简易请求)
87
88
  // 同样保留 /api/ 前缀
88
89
  indexCode = indexCode.replaceAll(`/api/${anchor}`, `/api${cleanPath}`)
89
90
  })
91
+
92
+ const [pagesMethod, pagesApi] = result?.['BUNKER_API_ANCHOR_pages']?.split(' ')
93
+ const definitions = (apiData.paths[pagesApi]?.[pagesMethod] ?? apiData.paths[pagesApi]?.[pagesMethod.toLowerCase()])?.parameters?.flatMap(item => Object.values(item.schema)?.flatMap(def => def.split('/').at(-1))) || []
94
+ const parameters = apiData.definitions?.[definitions[0]]?.properties ?? {}
95
+ const enumParams = Object.entries(parameters)?.filter(([_, value]) => value.hasOwnProperty('enum')) || []
96
+ enumParamsMap[fileName] = contextStringify({
97
+ maxLength: 100,
98
+ context: Object.fromEntries(enumParams.map(([key, value]) => [`${key}Options`, value.enum?.map(opt => ({ label: opt, value: opt }))])),
99
+ })
100
+
90
101
  fs.writeFileSync(indexPath, indexCode)
91
102
  pod153.report(dialog.pod153.signalSynchronized(Object.keys(result).length))
92
103
  // 💡 战术免责补丁:采用橙黄色高亮,提醒指挥官保持警惕
@@ -95,6 +106,8 @@ module.exports = async ({ llm, core, yorha, dialog, config }) => {
95
106
  }
96
107
  }
97
108
  }
109
+
110
+ return enumParamsMap
98
111
  } catch (e) {
99
112
  pod153.report(dialog.pod153.signalLinkFault(e.message), 'red')
100
113
  }
package/src/labs/tower.js CHANGED
@@ -74,8 +74,8 @@ module.exports = ({ core, yorha, dialog, config, handlers }) => {
74
74
  })
75
75
 
76
76
  server.listen(TOWER_PORT, () => {
77
- commander.report(dialog.bunker.towerOnline('42153'), 'magenta')
78
- commander.report(dialog.bunker.towerConnected('42153'), 'magenta')
77
+ commander.report(dialog.bunker.towerOnline(TOWER_PORT), 'magenta')
78
+ commander.report(dialog.bunker.towerConnected(TOWER_PORT), 'magenta')
79
79
  })
80
80
 
81
81
  return server
@@ -37,7 +37,7 @@ module.exports = ({ config, yorha, openAI, dialog, prompts, template }) => {
37
37
  const sharp = require('sharp')
38
38
 
39
39
  const { textModel, visionModel } = config
40
- const { api, mock, system, linker } = prompts
40
+ const { api, mock, system, council } = prompts
41
41
  const { UI_DESIGNER, API_DESIGNER, MOCK_DESIGNER } = system
42
42
 
43
43
  return {
@@ -53,7 +53,7 @@ module.exports = ({ config, yorha, openAI, dialog, prompts, template }) => {
53
53
  ]
54
54
  })
55
55
  },
56
- apiLinker: async ({ bunkerAnchors, realApis }) => {
56
+ apiParser: async ({ bunkerAnchors, realApis }) => {
57
57
  return askAI({
58
58
  yorha,
59
59
  openAI,
@@ -61,7 +61,7 @@ module.exports = ({ config, yorha, openAI, dialog, prompts, template }) => {
61
61
  model: textModel,
62
62
  messages: [
63
63
  { role: 'system', content: API_DESIGNER },
64
- { role: 'user', content: linker({ bunkerAnchors, realApis }) }
64
+ { role: 'user', content: council({ bunkerAnchors, realApis }) }
65
65
  ]
66
66
  })
67
67
  },