update: 更新light-code部分的代码模块

This commit is contained in:
2025-11-11 03:42:21 +08:00
parent dbd59e2fd9
commit 5df5a943ed
16 changed files with 761 additions and 1035 deletions

View File

@@ -3,6 +3,7 @@ import { app, assistantConfig } from '../app.ts';
import './config/index.ts';
import './shop-install/index.ts';
import './ai/index.ts';
import './light-code/index.ts';
import os from 'node:os';

View File

@@ -0,0 +1,30 @@
import { app, assistantConfig } from '../../app.ts'
import path from 'path'
import { runCode } from '../../module/light-code/run.ts'
// http://localhost:4005/api/router?path=call
app.route({
path: 'call',
// middleware: ['auth']
}).define(async (ctx) => {
const filename = ctx.query?.filename || 'root/light-code-demo/demo-router.ts'
const data = ctx.query?.data || {}
const appsConfigPath = assistantConfig.configPath?.appsDir || '';
const testA = path.join(appsConfigPath, filename)
try {
const resulst = await runCode(testA, data);
if (resulst.success) {
const callResult = resulst.data;
if (callResult.code === 200) ctx.body = callResult.data
else {
const callError = `调用程序错误: ${callResult.message}`
ctx.throw(callResult.code, callError)
}
} else {
ctx.body = `执行脚本错误: ${resulst.error}`
}
} catch (error) {
ctx.body = `执行脚本异常: ${error?.message || error}`
}
}).addTo(app)

View File

@@ -0,0 +1 @@
import './call.ts'