feat: restructure command for Claude models and add new remote routes

- Deleted the old cc.ts command and created a new cc.ts under src/command/claude for better organization.
- Added support for a new model 'bailian' in the command.
- Implemented remote app connection status and connection routes in assistant/src/routes/remote/index.ts.
- Updated index.ts to reflect the new path for the cc command.
- Added a placeholder for future management of plugin operations in src/command/opencode/plugin.ts.
This commit is contained in:
2026-01-21 23:22:58 +08:00
parent a911334459
commit 028a6ac726
15 changed files with 469 additions and 276 deletions

View File

@@ -1,7 +1,7 @@
import { createApiProxy, ProxyInfo, proxy } from '@/module/assistant/index.ts';
import { createApiProxy, ProxyInfo, proxy } from '@/module/assistant/index.ts';
import http from 'node:http';
import { LocalProxy } from './local-proxy.ts';
import { assistantConfig, app, simpleRouter } from '@/app.ts';
import { assistantConfig, simpleRouter } from '@/app.ts';
import { log, logger } from '@/module/logger.ts';
import { getToken } from '@/module/http-token.ts';
import { getTokenUserCache } from '@/routes/index.ts';
@@ -12,7 +12,7 @@ const localProxy = new LocalProxy({});
localProxy.initFromAssistantConfig(assistantConfig);
const isOpenPath = (pathname: string): boolean => {
const openPaths = ['/root/home', '/root/cli'];
const openPaths = ['/root/home', '/root/cli', '/root/login'];
for (const openPath of openPaths) {
if (pathname.startsWith(openPath)) {
return true;
@@ -31,7 +31,7 @@ const authFilter = async (req: http.IncomingMessage, res: http.ServerResponse) =
const auth = _assistantConfig?.auth || {};
const share = auth.share || 'protected';
const noAdmin = !auth.username;
if (noAdmin) return { code: 500, message: '没有管理员' };
if (noAdmin) return { code: 200, message: '没有管理员, 直接放过, 让管理登录和自己设置' };
const admin = auth.username;
const admins = auth.admin || [];
if (admin) {
@@ -160,7 +160,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
return;
}
const isOpen = isOpenPath(pathname)
log.debug('proxyRoute', { _user, _app, pathname, noAdmin, isOpen });
logger.debug('proxyRoute', { _user, _app, pathname, noAdmin, isOpen });
if (noAdmin && !isOpen) {
return toSetting();
}
@@ -172,19 +172,20 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
const proxyApiList = _assistantConfig?.proxy || [];
const proxyApi = proxyApiList.find((item) => pathname.startsWith(item.path));
if (proxyApi) {
log.debug('proxyPage', { proxyApi, pathname });
logger.debug('proxyPage', { proxyApi, pathname });
return proxyFn(req, res, proxyApi);
}
const filter = await authFilter(req, res);
if (filter.code !== 200) {
console.log('auth filter deny', filter);
logger.debug('auth filter deny', filter);
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
// TODO: 这里可以做成可配置的登录页面
return res.end(renderNoAuthAndLogin('Not Authorized Proxy'));
}
const localProxyProxyList = localProxy.getLocalProxyList();
const localProxyProxy = localProxyProxyList.find((item) => pathname.startsWith(item.path));
if (localProxyProxy) {
log.log('localProxyProxy', { localProxyProxy, url: req.url });
logger.debug('localProxyProxy', { localProxyProxy, url: req.url });
return proxyFn(req, res, {
path: localProxyProxy.path,
"type": 'file',
@@ -203,7 +204,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
type: 'http',
});
}
log.debug('handle by router 404', req.url);
logger.debug('handle by router 404', req.url);
res.statusCode = 404;
res.end('Not Found Proxy');