@lsamien/yaoyao 0.5.0 → 0.5.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 +12 -8
- package/bin/hermes-yaoyao.mjs +10 -1
- package/build-info.json +15 -3
- package/desktop/main.mjs +21 -55
- package/dist/admin/admin.html +18 -0
- package/dist/admin/assets/AccountPage-BM-5BzEC.js +2 -0
- package/dist/admin/assets/AccountPage-BM-5BzEC.js.map +1 -0
- package/dist/admin/assets/AccountPage-DuED6n3Z.css +1 -0
- package/dist/admin/assets/AppIcon-Ci5jJQ_z.css +1 -0
- package/dist/admin/assets/AppIcon-DT0aZXKp.js +2 -0
- package/dist/admin/assets/AppIcon-DT0aZXKp.js.map +1 -0
- package/dist/admin/assets/AuditPage-BYC3Sj8A.js +2 -0
- package/dist/admin/assets/AuditPage-BYC3Sj8A.js.map +1 -0
- package/dist/admin/assets/AuditPage-CCU02Ssr.css +1 -0
- package/dist/admin/assets/DesktopHostSettingsPanel-0ExrDTcn.css +1 -0
- package/dist/admin/assets/DesktopHostSettingsPanel-va4JiNPy.js +3 -0
- package/dist/admin/assets/DesktopHostSettingsPanel-va4JiNPy.js.map +1 -0
- package/dist/admin/assets/DevicesPage-D7-OiBsf.js +2 -0
- package/dist/admin/assets/DevicesPage-D7-OiBsf.js.map +1 -0
- package/dist/admin/assets/DevicesPage-vlD4SH1G.css +1 -0
- package/dist/admin/assets/ExecutionPage-C7dAaW56.css +1 -0
- package/dist/admin/assets/ExecutionPage-yK_unxZe.js +4 -0
- package/dist/admin/assets/ExecutionPage-yK_unxZe.js.map +1 -0
- package/dist/admin/assets/HermesModelSettingsPanel-CjdtWrj3.css +1 -0
- package/dist/admin/assets/HermesModelSettingsPanel-DbvAMOaL.js +4 -0
- package/dist/admin/assets/HermesModelSettingsPanel-DbvAMOaL.js.map +1 -0
- package/dist/admin/assets/LocalVmSettingsPanel-Mts0IE2D.js +2 -0
- package/dist/admin/assets/LocalVmSettingsPanel-Mts0IE2D.js.map +1 -0
- package/dist/admin/assets/MemoryPage-BbN5Cy7z.js +2 -0
- package/dist/admin/assets/MemoryPage-BbN5Cy7z.js.map +1 -0
- package/dist/admin/assets/NetworkPage-CFr7H5d3.css +1 -0
- package/dist/admin/assets/NetworkPage-DJpVHDkh.js +2 -0
- package/dist/admin/assets/NetworkPage-DJpVHDkh.js.map +1 -0
- package/dist/admin/assets/OverviewPage-C6p0VjPP.css +1 -0
- package/dist/admin/assets/OverviewPage-COSbych-.js +2 -0
- package/dist/admin/assets/OverviewPage-COSbych-.js.map +1 -0
- package/dist/admin/assets/PushPage-DPIZOOyb.js +2 -0
- package/dist/admin/assets/PushPage-DPIZOOyb.js.map +1 -0
- package/dist/admin/assets/RunnerSettingsPanel-CcDBl75r.css +1 -0
- package/dist/admin/assets/RunnerSettingsPanel-DVkI577k.js +4 -0
- package/dist/admin/assets/RunnerSettingsPanel-DVkI577k.js.map +1 -0
- package/dist/admin/assets/SystemManagementPanel-CPqP2Jjj.js +6 -0
- package/dist/admin/assets/SystemManagementPanel-CPqP2Jjj.js.map +1 -0
- package/dist/admin/assets/SystemManagementPanel-bwpHvkQn.css +1 -0
- package/dist/admin/assets/UpdatePage-pSh40naO.js +2 -0
- package/dist/admin/assets/UpdatePage-pSh40naO.js.map +1 -0
- package/dist/admin/assets/UpdatePage-sEtLezMA.css +1 -0
- package/dist/admin/assets/UsersPage-BArUB_g5.js +2 -0
- package/dist/admin/assets/UsersPage-BArUB_g5.js.map +1 -0
- package/dist/admin/assets/VoicePage-Bt778ia-.js +2 -0
- package/dist/admin/assets/VoicePage-Bt778ia-.js.map +1 -0
- package/dist/admin/assets/VoicePage-CVMwNSdM.css +1 -0
- package/dist/admin/assets/_plugin-vue_export-helper-B5sAOsbt.js +2 -0
- package/dist/admin/assets/_plugin-vue_export-helper-B5sAOsbt.js.map +1 -0
- package/dist/admin/assets/admin-BuMvp0yU.css +1 -0
- package/dist/admin/assets/admin-C-rH6P63.js +4 -0
- package/dist/admin/assets/admin-C-rH6P63.js.map +1 -0
- package/dist/admin/assets/agentManagement-BJKdxRR4.js +2 -0
- package/dist/admin/assets/agentManagement-BJKdxRR4.js.map +1 -0
- package/dist/admin/assets/id-JJk5w4N8.js +2 -0
- package/dist/admin/assets/id-JJk5w4N8.js.map +1 -0
- package/dist/admin/assets/webOrigin-B8RkRJQC.js +2 -0
- package/dist/admin/assets/webOrigin-B8RkRJQC.js.map +1 -0
- package/dist/admin/brand/AppIcon-1024.png +0 -0
- package/dist/admin/icons/apple-touch-icon.png +0 -0
- package/dist/admin/icons/favicon-32.png +0 -0
- package/dist/admin/icons/icon-192.png +0 -0
- package/dist/admin/icons/icon-512.png +0 -0
- package/dist/admin/icons/logo-64.png +0 -0
- package/dist/admin/manifest.webmanifest +21 -0
- package/dist/admin/provider-logos/airtable.svg +13 -0
- package/dist/admin/provider-logos/discord.svg +15 -0
- package/dist/admin/provider-logos/github.svg +10 -0
- package/dist/admin/provider-logos/gmail.svg +1 -0
- package/dist/admin/provider-logos/googlecalendar.svg +148 -0
- package/dist/admin/provider-logos/googledrive.svg +25 -0
- package/dist/admin/provider-logos/linear.svg +5 -0
- package/dist/admin/provider-logos/notion.svg +11 -0
- package/dist/admin/provider-logos/outlook.svg +76 -0
- package/dist/admin/provider-logos/slack.svg +22 -0
- package/dist/admin/provider-logos/trello.svg +19 -0
- package/dist/admin/provider-logos/twitter.svg +128 -0
- package/dist/admin/setting-previews/dark.png +0 -0
- package/dist/admin/setting-previews/light.png +0 -0
- package/dist/admin/setting-previews/system.png +0 -0
- package/dist/assets/AboutDialog-CuQClWtI.js +2 -0
- package/dist/assets/AboutDialog-CuQClWtI.js.map +1 -0
- package/dist/assets/{AgentAvatar-C37KUyoW.js → AgentAvatar-DGAfESjC.js} +3 -3
- package/dist/assets/AgentAvatar-DGAfESjC.js.map +1 -0
- package/dist/assets/{AppIcon-BPvEfb2q.js → AppIcon-BSQW3rNo.js} +2 -2
- package/dist/assets/{AppIcon-BPvEfb2q.js.map → AppIcon-BSQW3rNo.js.map} +1 -1
- package/dist/assets/BotAutomationsView-F2DUYiMz.js +2 -0
- package/dist/assets/{BotAutomationsView-gKt3Ynba.js.map → BotAutomationsView-F2DUYiMz.js.map} +1 -1
- package/dist/assets/BotPluginsDialog-GWss_AWD.js +2 -0
- package/dist/assets/{BotPluginsDialog-BDb-ov2N.js.map → BotPluginsDialog-GWss_AWD.js.map} +1 -1
- package/dist/assets/BotSettingsDialog-CJbJ-etj.css +1 -0
- package/dist/assets/BotSettingsDialog-DeAfjy5V.js +2 -0
- package/dist/assets/BotSettingsDialog-DeAfjy5V.js.map +1 -0
- package/dist/assets/BrandMark-y7NnuoOH.js +2 -0
- package/dist/assets/BrandMark-y7NnuoOH.js.map +1 -0
- package/dist/assets/ComputerPanel-BttazrS8.js +2 -0
- package/dist/assets/{ComputerPanel-CzE73VoT.js.map → ComputerPanel-BttazrS8.js.map} +1 -1
- package/dist/assets/ComputerViewerView-cIjIUTqR.js +2 -0
- package/dist/assets/{ComputerViewerView-Lc3DX3Qp.js.map → ComputerViewerView-cIjIUTqR.js.map} +1 -1
- package/dist/assets/ConversationsView-BLo8VLvG.js +81 -0
- package/dist/assets/ConversationsView-BLo8VLvG.js.map +1 -0
- package/dist/assets/{ConversationsView-Cbj8h0ms.css → ConversationsView-Y7Npknvu.css} +1 -1
- package/dist/assets/StandaloneDialog-Dakzt5_X.js +2 -0
- package/dist/assets/{StandaloneDialog-DibKSM6U.js.map → StandaloneDialog-Dakzt5_X.js.map} +1 -1
- package/dist/assets/TeamAvatar-C5dodifX.js +2 -0
- package/dist/assets/TeamAvatar-C5dodifX.js.map +1 -0
- package/dist/assets/WorkspaceKnowledgePanel-B6xMyHdp.css +1 -0
- package/dist/assets/WorkspaceKnowledgePanel-ChnX-SdQ.js +2 -0
- package/dist/assets/WorkspaceKnowledgePanel-ChnX-SdQ.js.map +1 -0
- package/dist/assets/WorkspaceRoutinesPanel-Dfi6aiNd.js +2 -0
- package/dist/assets/{WorkspaceRoutinesPanel-CIJJtGi1.js.map → WorkspaceRoutinesPanel-Dfi6aiNd.js.map} +1 -1
- package/dist/assets/{_plugin-vue_export-helper-CW5Ldrk2.js → _plugin-vue_export-helper-CscYwSBt.js} +2 -2
- package/dist/assets/_plugin-vue_export-helper-CscYwSBt.js.map +1 -0
- package/dist/assets/browser-B97PQaMt.js.map +1 -1
- package/dist/assets/client-DlFcPeeo.js +2 -0
- package/dist/assets/{client-BQtZaYs8.js.map → client-DlFcPeeo.js.map} +1 -1
- package/dist/assets/docx-preview-DZusoPTe.js.map +1 -1
- package/dist/assets/{index-BRikiCOi.css → index-CXNB3OJV.css} +1 -1
- package/dist/assets/index-q-PRe7O6.js +3 -0
- package/dist/assets/index-q-PRe7O6.js.map +1 -0
- package/dist/assets/pdf-tIZzkLfe.js.map +1 -1
- package/dist/assets/vue-router-BhrrTMUg.js +2 -0
- package/dist/assets/vue-router-BhrrTMUg.js.map +1 -0
- package/dist/index.html +9 -9
- package/dist-server/server/admin/app.js +291 -0
- package/dist-server/server/admin/audit.js +106 -0
- package/dist-server/server/admin/routes.js +68 -0
- package/dist-server/server/admin/sessions.js +121 -0
- package/dist-server/server/admin/throttle.js +51 -0
- package/dist-server/server/app.js +94 -22
- package/dist-server/server/computerControls.js +1 -1
- package/dist-server/server/config.js +26 -0
- package/dist-server/server/desktopHosts.js +57 -0
- package/dist-server/server/index.js +46 -0
- package/dist-server/server/localAuth.js +59 -8
- package/dist-server/server/routes.js +4 -4
- package/dist-server/server/security.js +5 -3
- package/dist-server/server/workspaceRoutes.js +4 -4
- package/package.json +2 -2
- package/release.json +3 -3
- package/dist/assets/AboutDialog-nXDYG57h.js +0 -2
- package/dist/assets/AboutDialog-nXDYG57h.js.map +0 -1
- package/dist/assets/AgentAvatar-C37KUyoW.js.map +0 -1
- package/dist/assets/BotAutomationsView-gKt3Ynba.js +0 -2
- package/dist/assets/BotPluginsDialog-BDb-ov2N.js +0 -2
- package/dist/assets/BotSettingsDialog-DqA2zJZK.js +0 -5
- package/dist/assets/BotSettingsDialog-DqA2zJZK.js.map +0 -1
- package/dist/assets/BotSettingsDialog-yxqKMuZ-.css +0 -1
- package/dist/assets/BrandMark-DHKCL6jN.js +0 -2
- package/dist/assets/BrandMark-DHKCL6jN.js.map +0 -1
- package/dist/assets/ComputerPanel-CzE73VoT.js +0 -2
- package/dist/assets/ComputerViewerView-Lc3DX3Qp.js +0 -2
- package/dist/assets/ConversationsView-CTqxBOQ9.js +0 -83
- package/dist/assets/ConversationsView-CTqxBOQ9.js.map +0 -1
- package/dist/assets/LocalVmSettingsPanel-D2kMqDFb.js +0 -2
- package/dist/assets/LocalVmSettingsPanel-D2kMqDFb.js.map +0 -1
- package/dist/assets/RunnerSettingsPanel-C85I5Md_.css +0 -1
- package/dist/assets/RunnerSettingsPanel-Hw8OyWFI.js +0 -4
- package/dist/assets/RunnerSettingsPanel-Hw8OyWFI.js.map +0 -1
- package/dist/assets/StandaloneDialog-DibKSM6U.js +0 -2
- package/dist/assets/SystemManagementPanel-5uMrQ0km.css +0 -1
- package/dist/assets/SystemManagementPanel-_N_phucL.js +0 -7
- package/dist/assets/SystemManagementPanel-_N_phucL.js.map +0 -1
- package/dist/assets/TeamAvatar-C9jl8KF_.js +0 -2
- package/dist/assets/TeamAvatar-C9jl8KF_.js.map +0 -1
- package/dist/assets/UpdateCheckDialog-CPKcCSFt.js +0 -2
- package/dist/assets/UpdateCheckDialog-CPKcCSFt.js.map +0 -1
- package/dist/assets/UpdateCheckDialog-CRlyWnE7.css +0 -1
- package/dist/assets/WorkspaceRoutinesPanel-CIJJtGi1.js +0 -2
- package/dist/assets/_plugin-vue_export-helper-CW5Ldrk2.js.map +0 -1
- package/dist/assets/client-BQtZaYs8.js +0 -2
- package/dist/assets/index-B9T7NLfA.js +0 -3
- package/dist/assets/index-B9T7NLfA.js.map +0 -1
- package/dist/assets/localVm-owThjmhy.js +0 -2
- package/dist/assets/localVm-owThjmhy.js.map +0 -1
- package/dist/assets/systemUpdate-CXMCaKgI.js +0 -2
- package/dist/assets/systemUpdate-CXMCaKgI.js.map +0 -1
- package/dist/assets/vue-router-DYhC9cWJ.js +0 -2
- package/dist/assets/vue-router-DYhC9cWJ.js.map +0 -1
- /package/dist/{assets → admin/assets}/LocalVmSettingsPanel-Dedfhqlq.css +0 -0
|
@@ -49,13 +49,19 @@ import { LocalVmService } from './localVm.js';
|
|
|
49
49
|
import { SharedComputers } from './sharedComputers.js';
|
|
50
50
|
import { ComputerControlService } from './computerControls.js';
|
|
51
51
|
import { RunnerHub } from './runnerHub.js';
|
|
52
|
+
import { AdminAudit } from './admin/audit.js';
|
|
53
|
+
import { CONSOLE_CSRF_COOKIE, createConsoleApp } from './admin/app.js';
|
|
54
|
+
import { isManagementRoute } from './admin/routes.js';
|
|
55
|
+
import { AdminSessionStore } from './admin/sessions.js';
|
|
56
|
+
import { kernelPaths, requireKernel } from './hermes/paths.js';
|
|
57
|
+
import { readReleaseManifest } from './releases.js';
|
|
52
58
|
function isMutation(method) {
|
|
53
59
|
return !['GET', 'HEAD', 'OPTIONS'].includes(method);
|
|
54
60
|
}
|
|
55
|
-
function persistentCsrfSecret(home, override) {
|
|
61
|
+
function persistentCsrfSecret(home, override, file = 'csrf-secret.bin') {
|
|
56
62
|
if (override)
|
|
57
63
|
return override;
|
|
58
|
-
const path = join(home,
|
|
64
|
+
const path = join(home, file);
|
|
59
65
|
try {
|
|
60
66
|
const secret = readFileSync(path);
|
|
61
67
|
if (secret.byteLength === 32)
|
|
@@ -82,6 +88,8 @@ function persistentCsrfSecret(home, override) {
|
|
|
82
88
|
}
|
|
83
89
|
export function createApplication(options = {}) {
|
|
84
90
|
const config = options.config ?? loadServerConfig();
|
|
91
|
+
// Test configs predate the console; they get the default local listener.
|
|
92
|
+
config.admin ??= { enabled: true, host: '127.0.0.1', port: config.port === 15301 ? 15302 : 15301, allowIps: [], insecureHttp: false, external: false };
|
|
85
93
|
const runtimeAllowedHosts = new Set(config.allowedHosts);
|
|
86
94
|
config.allowedHosts = runtimeAllowedHosts;
|
|
87
95
|
const app = new Koa();
|
|
@@ -277,6 +285,12 @@ export function createApplication(options = {}) {
|
|
|
277
285
|
}
|
|
278
286
|
await next();
|
|
279
287
|
});
|
|
288
|
+
// Management moved to the admin console; the Web keeps no management routes.
|
|
289
|
+
app.use(async (ctx, next) => {
|
|
290
|
+
if (isManagementRoute(ctx.method, ctx.path))
|
|
291
|
+
throw new HttpError(410, '该设置已移到管理后台,请在服务器本机打开管理后台操作。', 'moved_to_admin_console');
|
|
292
|
+
await next();
|
|
293
|
+
});
|
|
280
294
|
app.use(async (ctx, next) => {
|
|
281
295
|
if (ctx.path.startsWith('/api/app/') && isMutation(ctx.method)) {
|
|
282
296
|
const secure = ctx.secure || Boolean(config.tlsCert);
|
|
@@ -299,7 +313,7 @@ export function createApplication(options = {}) {
|
|
|
299
313
|
const publicPath = ['/api/status', '/api/auth/providers', '/api/auth/me', '/api/profiles', '/api/app/bootstrap', '/api/app/login', '/api/app/logout'].includes(path);
|
|
300
314
|
const accountPath = ['/api/account/credentials', '/api/app/account/credentials', '/api/app/account/avatar'].includes(path);
|
|
301
315
|
const workspacePath = /^\/api\/app\/(?:capabilities|agents|conversations|runs|interactions|events|uploads|files|message-files|computers|bot-tools)(?:\/|$)/.test(path)
|
|
302
|
-
&&
|
|
316
|
+
&& !/^\/api\/app\/agents\/remote\/?$/i.test(path);
|
|
303
317
|
const pushPath = /^\/api\/(?:app\/)?push\/v1\//.test(path);
|
|
304
318
|
const identityRead = path === '/api/app/server-identity' && ['GET', 'HEAD'].includes(ctx.method);
|
|
305
319
|
if (!publicPath && !accountPath && !workspacePath && !isWorkspaceAccountPath(ctx.method, path) && !pushPath && !identityRead)
|
|
@@ -372,24 +386,16 @@ export function createApplication(options = {}) {
|
|
|
372
386
|
await credentialVault.logout(user.id, cookie);
|
|
373
387
|
await next();
|
|
374
388
|
});
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const localVmRouter = localVm.router();
|
|
383
|
-
app.use(localVmRouter.routes());
|
|
384
|
-
app.use(localVmRouter.allowedMethods());
|
|
385
|
-
const computerRouter = computerControls.router();
|
|
386
|
-
app.use(computerRouter.routes());
|
|
387
|
-
app.use(computerRouter.allowedMethods());
|
|
389
|
+
// Route handlers are shared by the Web and the admin console; each listener gates which ones it exposes.
|
|
390
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
391
|
+
const routes = [];
|
|
392
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
393
|
+
const mount = (router, options) => { routes.push(router.routes(), router.allowedMethods(options)); };
|
|
394
|
+
for (const router of [credentialVault.router(), executionSettings.router(), managedBrowsers.router(), desktopEnvironments.router(), grokCloud.authorization.router(), grokCloud.router(), workspaceInspector.router(), workspaceRoutines.router(), workspacePlugins.router(), sharedComputers.router(), localVm.router(), computerControls.router()])
|
|
395
|
+
mount(router);
|
|
388
396
|
const applicationRouter = workspaceRouter(workspace, workspaceRuntime, workspaceNodes, workspaceAssets, uploads, auth, push, csrf);
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
app.use(applicationRouter.routes());
|
|
392
|
-
app.use(async (ctx, next) => {
|
|
397
|
+
routes.push(runners.adminRouter().routes(), desktopHosts.adminRouter().routes(), applicationRouter.routes());
|
|
398
|
+
routes.push(async (ctx, next) => {
|
|
393
399
|
if (ctx.path.includes('/plugins/yaoyao') || ctx.path.startsWith('/api/app/groups'))
|
|
394
400
|
throw new HttpError(410, '请使用新版聊天接口', 'retired_plugin_api');
|
|
395
401
|
await next();
|
|
@@ -419,8 +425,9 @@ export function createApplication(options = {}) {
|
|
|
419
425
|
openVikingSessionSync,
|
|
420
426
|
allowedHostsConfiguration,
|
|
421
427
|
});
|
|
422
|
-
|
|
423
|
-
|
|
428
|
+
mount(router, { throw: false });
|
|
429
|
+
for (const middleware of routes)
|
|
430
|
+
app.use(middleware);
|
|
424
431
|
app.use(async (ctx, next) => {
|
|
425
432
|
if (ctx.path === '/api' || ctx.path.startsWith('/api/') || ctx.path.startsWith('/ws/')) {
|
|
426
433
|
ctx.status = 404;
|
|
@@ -430,7 +437,60 @@ export function createApplication(options = {}) {
|
|
|
430
437
|
}
|
|
431
438
|
await next();
|
|
432
439
|
});
|
|
440
|
+
const adminSessions = options.adminSessions ?? new AdminSessionStore(config.home, auth, Boolean(config.tlsCert));
|
|
441
|
+
const adminAudit = new AdminAudit(config.home);
|
|
442
|
+
const adminCsrf = new CsrfProtection(persistentCsrfSecret(config.home, options.adminCsrfSecret, 'admin-csrf-secret.bin'), Boolean(config.tlsCert), CONSOLE_CSRF_COOKIE);
|
|
443
|
+
let version = 'unknown';
|
|
444
|
+
try {
|
|
445
|
+
version = readReleaseManifest(join(process.cwd(), 'release.json')).releaseVersion;
|
|
446
|
+
}
|
|
447
|
+
catch { /* Source checkouts without a manifest. */ }
|
|
448
|
+
const adminApp = createConsoleApp({
|
|
449
|
+
config, auth, sessions: adminSessions, audit: adminAudit, csrf: adminCsrf, routes, version,
|
|
450
|
+
readScope: (user, next) => upstream.withReadScope(`user:${user.id}:${auth.pushAuthorizationVersion(user.id)}`, false, next),
|
|
451
|
+
profiles: async () => {
|
|
452
|
+
const response = await upstreamSession.request('/api/profiles');
|
|
453
|
+
const parsed = JSON.parse(response.body.toString('utf8') || '{}');
|
|
454
|
+
const rows = Array.isArray(parsed) ? parsed : parsed.profiles ?? [];
|
|
455
|
+
return rows.flatMap(row => typeof row.name === 'string' && row.name ? [{ name: row.name, label: typeof row.display_name === 'string' && row.display_name || row.name, isDefault: row.name === 'default' || row.is_default === true }] : []);
|
|
456
|
+
},
|
|
457
|
+
overview: async (admin) => {
|
|
458
|
+
let kernel = { ready: true };
|
|
459
|
+
try {
|
|
460
|
+
const paths = kernelPaths();
|
|
461
|
+
requireKernel(paths, paths.worker);
|
|
462
|
+
}
|
|
463
|
+
catch (cause) {
|
|
464
|
+
kernel = { ready: false, error: cause instanceof Error ? cause.message : '内置 Hermes 内核不可用' };
|
|
465
|
+
}
|
|
466
|
+
const users = auth.list(admin);
|
|
467
|
+
const runnerRows = runners.records().map(record => runners.summary(record));
|
|
468
|
+
const hostRows = desktopHosts.records().filter(record => record.enabled).map(record => desktopHosts.summary(record));
|
|
469
|
+
const pushStatus = push.status();
|
|
470
|
+
let update;
|
|
471
|
+
try {
|
|
472
|
+
const status = updates.status();
|
|
473
|
+
update = { current: status.current.releaseVersion, updateAvailable: status.updateAvailable, ...(status.latest ? { latest: status.latest.releaseVersion } : {}) };
|
|
474
|
+
}
|
|
475
|
+
catch { /* Update status is optional. */ }
|
|
476
|
+
return {
|
|
477
|
+
version,
|
|
478
|
+
kernel: { ...kernel, version: '0.23.0' },
|
|
479
|
+
users: { total: users.length, admins: users.filter(user => user.role === 'admin').length, pending: users.filter(user => user.registrationStatus === 'pending').map(user => ({ id: user.id, username: user.username, createdAt: user.createdAt })), disabled: users.filter(user => !user.enabled).length },
|
|
480
|
+
runners: { total: runnerRows.filter(row => row.enabled).length, online: runnerRows.filter(row => row.enabled && row.online).length },
|
|
481
|
+
desktopHosts: { total: hostRows.length, online: hostRows.filter(row => row.online).length, offline: hostRows.filter(row => !row.online).map(row => ({ id: row.id, name: row.displayName || row.name, lastSeen: row.lastSeen })) },
|
|
482
|
+
push: { configured: pushStatus.configured, healthy: pushStatus.healthy, registrations: pushStatus.registrationCount },
|
|
483
|
+
...(update ? { update } : {}),
|
|
484
|
+
web: { host: config.host, port: config.port },
|
|
485
|
+
console: { host: config.admin.host, port: config.admin.port, external: config.admin.external },
|
|
486
|
+
};
|
|
487
|
+
},
|
|
488
|
+
});
|
|
433
489
|
return {
|
|
490
|
+
adminApp,
|
|
491
|
+
adminSessions,
|
|
492
|
+
adminAudit,
|
|
493
|
+
adminCsrf,
|
|
434
494
|
credentialVault,
|
|
435
495
|
runners,
|
|
436
496
|
localVm,
|
|
@@ -462,6 +522,7 @@ export function createApplication(options = {}) {
|
|
|
462
522
|
allowedHostsConfiguration,
|
|
463
523
|
startBackground,
|
|
464
524
|
close: () => {
|
|
525
|
+
adminAudit.close();
|
|
465
526
|
credentialVault.close();
|
|
466
527
|
closed = true;
|
|
467
528
|
openVikingSessionSync.close();
|
|
@@ -494,6 +555,9 @@ export function createNodeServer(runtime, options = {}) {
|
|
|
494
555
|
key: readFileSync(config.tlsKey),
|
|
495
556
|
}, runtime.app.callback())
|
|
496
557
|
: createHttpServer(runtime.app.callback());
|
|
558
|
+
const adminServer = !config.admin.enabled ? undefined : config.tlsCert && config.tlsKey
|
|
559
|
+
? createHttpsServer({ cert: readFileSync(config.tlsCert), key: readFileSync(config.tlsKey) }, runtime.adminApp.callback())
|
|
560
|
+
: createHttpServer(runtime.adminApp.callback());
|
|
497
561
|
let backgroundStarted = false, localVmStarted = false, closed = false;
|
|
498
562
|
const startLocalVm = () => {
|
|
499
563
|
if (!backgroundStarted || localVmStarted || closed)
|
|
@@ -519,13 +583,21 @@ export function createNodeServer(runtime, options = {}) {
|
|
|
519
583
|
if (!options.deferBackground)
|
|
520
584
|
startBackground();
|
|
521
585
|
const removeWebSockets = rejectWebSocketUpgrades(server, config.production);
|
|
586
|
+
const removeAdminWebSockets = adminServer ? rejectWebSocketUpgrades(adminServer, config.production) : () => undefined;
|
|
522
587
|
return {
|
|
523
588
|
server,
|
|
589
|
+
...(adminServer ? { adminServer } : {}),
|
|
524
590
|
startBackground,
|
|
525
591
|
close: async (closeConnections = false) => {
|
|
526
592
|
closed = true;
|
|
527
593
|
await runtime.localVm.close();
|
|
528
594
|
removeWebSockets();
|
|
595
|
+
removeAdminWebSockets();
|
|
596
|
+
if (adminServer?.listening) {
|
|
597
|
+
if (closeConnections)
|
|
598
|
+
adminServer.closeAllConnections();
|
|
599
|
+
await new Promise(resolve => adminServer.close(() => resolve()));
|
|
600
|
+
}
|
|
529
601
|
if (closeConnections)
|
|
530
602
|
server.closeAllConnections();
|
|
531
603
|
await new Promise((resolve, reject) => {
|
|
@@ -48,7 +48,7 @@ export class ComputerControlService {
|
|
|
48
48
|
const router = new Router();
|
|
49
49
|
router.get('/api/app/computers', ctx => {
|
|
50
50
|
const actor = this.auth.require(ctx), agents = this.store.list(actor.id, 'agent').filter(agent => !agent.archived);
|
|
51
|
-
ctx.body = {
|
|
51
|
+
ctx.body = { computers: agents.map(agent => {
|
|
52
52
|
let available = false, reason = '全局设置未开放虚拟环境';
|
|
53
53
|
if (readHostTools(this.store.home).vm)
|
|
54
54
|
try {
|
|
@@ -20,6 +20,31 @@ function parsePort(value) {
|
|
|
20
20
|
}
|
|
21
21
|
return port;
|
|
22
22
|
}
|
|
23
|
+
const CIDR = /^(?:(?:\d{1,3}\.){3}\d{1,3}|[0-9a-f:]+)(?:\/\d{1,3})?$/i;
|
|
24
|
+
/** Admin console listener. A non-loopback listener must name its clients and use TLS (or opt out explicitly). */
|
|
25
|
+
export function loadAdminConsoleConfig(env, mainPort, tls) {
|
|
26
|
+
const rawPort = env.YAOYAO_ADMIN_PORT?.trim();
|
|
27
|
+
const enabled = rawPort?.toLowerCase() !== 'off';
|
|
28
|
+
const port = enabled ? Number(rawPort || '15301') : 0;
|
|
29
|
+
if (enabled && (!Number.isInteger(port) || port < 1 || port > 65_535))
|
|
30
|
+
throw new Error('YAOYAO_ADMIN_PORT must be an integer between 1 and 65535, or off');
|
|
31
|
+
if (enabled && port === mainPort)
|
|
32
|
+
throw new Error('YAOYAO_ADMIN_PORT must differ from the Web port');
|
|
33
|
+
const host = env.YAOYAO_ADMIN_HOST?.trim() || '127.0.0.1';
|
|
34
|
+
const allowIps = (env.YAOYAO_ADMIN_ALLOW_IPS ?? '').split(',').map(item => item.trim()).filter(Boolean);
|
|
35
|
+
for (const item of allowIps)
|
|
36
|
+
if (!CIDR.test(item))
|
|
37
|
+
throw new Error(`YAOYAO_ADMIN_ALLOW_IPS has an invalid entry: ${item}`);
|
|
38
|
+
const insecureHttp = flag(env.YAOYAO_ADMIN_INSECURE_HTTP);
|
|
39
|
+
const external = enabled && !isLoopbackHost(host);
|
|
40
|
+
if (external) {
|
|
41
|
+
if (!allowIps.length)
|
|
42
|
+
throw new Error('A non-loopback YAOYAO_ADMIN_HOST requires YAOYAO_ADMIN_ALLOW_IPS');
|
|
43
|
+
if (!tls && !insecureHttp)
|
|
44
|
+
throw new Error('A non-loopback YAOYAO_ADMIN_HOST requires HERMES_YAOYAO_TLS_CERT/KEY, or YAOYAO_ADMIN_INSECURE_HTTP=1 when the port is only published on the host loopback');
|
|
45
|
+
}
|
|
46
|
+
return { enabled, host, port, allowIps, insecureHttp, external };
|
|
47
|
+
}
|
|
23
48
|
function parseUpstream(value) {
|
|
24
49
|
const upstream = new URL(value ?? 'http://127.0.0.1:9119');
|
|
25
50
|
if (!['http:', 'https:'].includes(upstream.protocol)) {
|
|
@@ -125,6 +150,7 @@ export function loadServerConfig(env = process.env) {
|
|
|
125
150
|
const allowedHostsSettings = loadAllowedHostsConfiguration(home, env);
|
|
126
151
|
const allowedHosts = new Set(allowedHostsSettings.hosts);
|
|
127
152
|
return {
|
|
153
|
+
admin: loadAdminConsoleConfig(env, port, Boolean(tlsCert)),
|
|
128
154
|
host,
|
|
129
155
|
port,
|
|
130
156
|
upstream,
|
|
@@ -23,6 +23,9 @@ export class DesktopHostHub {
|
|
|
23
23
|
/** Bound to DesktopEnvironments.dropHost so revocation fences live commands. */
|
|
24
24
|
drop = () => { };
|
|
25
25
|
online = new Map();
|
|
26
|
+
/** One-time codes from the admin console; a computer redeems one instead of an admin login. */
|
|
27
|
+
pairingCodes = new Map();
|
|
28
|
+
pairingFailures = new Map();
|
|
26
29
|
constructor(store, auth) {
|
|
27
30
|
this.store = store;
|
|
28
31
|
this.auth = auth;
|
|
@@ -75,12 +78,66 @@ export class DesktopHostHub {
|
|
|
75
78
|
router.get('/api/app/admin/desktop-hosts', ctx => { this.auth.requireAdmin(ctx); ctx.set('Cache-Control', 'no-store'); const names = readComputerNames(this.store.home); ctx.body = { protocol: DESKTOP_HOST_PROTOCOL, localName: names.local || '', hosts: this.records().map(record => this.summary(record)) }; });
|
|
76
79
|
router.put('/api/app/admin/desktop-hosts/:id/name', ctx => { this.auth.requireAdmin(ctx); const id = ctx.params.id; if (id !== 'local' && !this.records().some(record => record.id === id && record.enabled))
|
|
77
80
|
throw new HttpError(404, '这台电脑不存在', 'desktop_host_unknown'); const name = typeof ctx.request.body?.name === 'string' ? ctx.request.body.name : ''; ctx.body = { id, name: saveComputerName(this.store.home, id, name)[id] || '' }; });
|
|
81
|
+
router.post('/api/app/admin/desktop-hosts/pairing-codes', ctx => { this.auth.requireAdmin(ctx); ctx.status = 201; ctx.body = this.createPairingCode(); });
|
|
78
82
|
router.post('/api/app/admin/desktop-hosts', ctx => { this.auth.requireAdmin(ctx); ctx.body = this.enroll(ctx.request.body); ctx.status = 201; });
|
|
79
83
|
router.delete('/api/app/admin/desktop-hosts/:id', ctx => { this.auth.requireAdmin(ctx); this.remove(ctx.params.id); ctx.body = { ok: true }; });
|
|
80
84
|
return router;
|
|
81
85
|
}
|
|
86
|
+
/** 8 characters without look-alikes (0/O, 1/I/L), shown as XXXX-XXXX, valid 10 minutes, single use. */
|
|
87
|
+
createPairingCode(now = Date.now()) {
|
|
88
|
+
for (const [code, expiresAt] of this.pairingCodes)
|
|
89
|
+
if (expiresAt <= now)
|
|
90
|
+
this.pairingCodes.delete(code);
|
|
91
|
+
const alphabet = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
|
|
92
|
+
const bytes = randomBytes(8);
|
|
93
|
+
const raw = [...bytes].map(byte => alphabet[byte % alphabet.length]).join('');
|
|
94
|
+
const expiresAt = now + 10 * 60_000;
|
|
95
|
+
this.pairingCodes.set(raw, expiresAt);
|
|
96
|
+
return { code: `${raw.slice(0, 4)}-${raw.slice(4)}`, expiresAt };
|
|
97
|
+
}
|
|
98
|
+
/** Redeems a console pairing code for a computer token. Ten failures per address per ten minutes. */
|
|
99
|
+
enrollWithCode(ip, value, now = Date.now()) {
|
|
100
|
+
const recent = (this.pairingFailures.get(ip) ?? []).filter(at => now - at < 10 * 60_000);
|
|
101
|
+
if (recent.length >= 10)
|
|
102
|
+
throw new HttpError(429, '配对码尝试次数过多,请 10 分钟后再试。', 'desktop_pairing_locked');
|
|
103
|
+
const input = parse(enrollInput.extend({ code: z.string().trim().min(8).max(20) }).strict(), value);
|
|
104
|
+
const code = input.code.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
|
105
|
+
const expiresAt = this.pairingCodes.get(code);
|
|
106
|
+
if (!expiresAt || expiresAt <= now) {
|
|
107
|
+
this.pairingFailures.set(ip, [...recent, now]);
|
|
108
|
+
throw new HttpError(403, '配对码无效或已过期,请在管理后台重新生成。', 'desktop_pairing_invalid');
|
|
109
|
+
}
|
|
110
|
+
this.pairingCodes.delete(code);
|
|
111
|
+
const { code: _code, ...enrollment } = input;
|
|
112
|
+
return this.enroll(enrollment);
|
|
113
|
+
}
|
|
82
114
|
middleware() {
|
|
83
115
|
return async (ctx, next) => {
|
|
116
|
+
if (ctx.path === '/api/desktop-host/v1/enroll') {
|
|
117
|
+
if (ctx.get('origin'))
|
|
118
|
+
throw new HttpError(403, '电脑授权无效', 'desktop_host_unauthorized');
|
|
119
|
+
if (ctx.method !== 'POST')
|
|
120
|
+
throw new HttpError(405, '仅允许 POST', 'method_not_allowed');
|
|
121
|
+
let bytes = 0;
|
|
122
|
+
const chunks = [];
|
|
123
|
+
for await (const chunk of ctx.req) {
|
|
124
|
+
bytes += chunk.length;
|
|
125
|
+
if (bytes > 16 * 1024)
|
|
126
|
+
throw new HttpError(413, '请求过大', 'desktop_limit');
|
|
127
|
+
chunks.push(Buffer.from(chunk));
|
|
128
|
+
}
|
|
129
|
+
let json;
|
|
130
|
+
try {
|
|
131
|
+
json = JSON.parse(Buffer.concat(chunks).toString() || '{}');
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
throw new HttpError(400, '请求格式无效', 'desktop_invalid');
|
|
135
|
+
}
|
|
136
|
+
ctx.set('Cache-Control', 'no-store');
|
|
137
|
+
ctx.status = 201;
|
|
138
|
+
ctx.body = this.enrollWithCode(ctx.ip, json);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
84
141
|
const match = /^\/api\/desktop-host\/v1\/([0-9a-f-]{36})\/exchange$/.exec(ctx.path);
|
|
85
142
|
if (!match)
|
|
86
143
|
return next();
|
|
@@ -3,6 +3,7 @@ import { resolve } from 'node:path';
|
|
|
3
3
|
import send from 'koa-send';
|
|
4
4
|
import serve from 'koa-static';
|
|
5
5
|
import { createApplication, createNodeServer } from './app.js';
|
|
6
|
+
import { serveConsoleStatic } from './admin/app.js';
|
|
6
7
|
import { loadServerConfig } from './config.js';
|
|
7
8
|
import { acquireServiceInstance } from './serviceInstance.js';
|
|
8
9
|
import { readReleaseManifest } from './releases.js';
|
|
@@ -56,8 +57,17 @@ runtime.app.middleware.unshift(instance.middleware(shutdown, () => runtime.runne
|
|
|
56
57
|
const user = runtime.auth.localDesktopSession(ctx);
|
|
57
58
|
ctx.body = { user, setCookies: ctx.response.get('set-cookie') };
|
|
58
59
|
}));
|
|
60
|
+
// The console bundle lives in dist/admin but is served only on the admin port.
|
|
61
|
+
runtime.app.use(async (ctx, next) => {
|
|
62
|
+
if (ctx.path === '/admin' || ctx.path.startsWith('/admin/') || ctx.path === '/admin.html') {
|
|
63
|
+
ctx.status = 404;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
await next();
|
|
67
|
+
});
|
|
59
68
|
if (runtime.config.production) {
|
|
60
69
|
const dist = resolve(process.env.HERMES_YAOYAO_STATIC_DIR || resolve(process.cwd(), 'dist'));
|
|
70
|
+
serveConsoleStatic(runtime.adminApp, resolve(dist, 'admin'));
|
|
61
71
|
runtime.app.use(serve(dist, { index: 'index.html' }));
|
|
62
72
|
runtime.app.use(async (ctx) => {
|
|
63
73
|
if (ctx.method !== 'GET' || !ctx.accepts('html') || !existsSync(resolve(dist, 'index.html'))) {
|
|
@@ -77,6 +87,28 @@ else {
|
|
|
77
87
|
appType: 'spa',
|
|
78
88
|
});
|
|
79
89
|
closeFrontend = () => vite.close();
|
|
90
|
+
// Development: the same Vite server renders the console entry (admin.html) on the admin port.
|
|
91
|
+
runtime.adminApp.use(async (ctx) => {
|
|
92
|
+
if (ctx.method === 'GET' && !/\.[a-z0-9]+$/i.test(ctx.path) && !ctx.path.startsWith('/@') && !ctx.path.startsWith('/src/') && !ctx.path.startsWith('/node_modules/'))
|
|
93
|
+
ctx.req.url = '/admin.html';
|
|
94
|
+
const handled = await new Promise((resolvePromise, reject) => {
|
|
95
|
+
const finish = () => { ctx.res.off('finish', finish); ctx.res.off('close', finish); resolvePromise(true); };
|
|
96
|
+
ctx.res.once('finish', finish);
|
|
97
|
+
ctx.res.once('close', finish);
|
|
98
|
+
vite.middlewares(ctx.req, ctx.res, (error) => {
|
|
99
|
+
ctx.res.off('finish', finish);
|
|
100
|
+
ctx.res.off('close', finish);
|
|
101
|
+
if (error)
|
|
102
|
+
reject(error);
|
|
103
|
+
else
|
|
104
|
+
resolvePromise(false);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
if (handled)
|
|
108
|
+
ctx.respond = false;
|
|
109
|
+
else
|
|
110
|
+
ctx.status = 404;
|
|
111
|
+
});
|
|
80
112
|
runtime.app.use(async (ctx) => {
|
|
81
113
|
const handled = await new Promise((resolvePromise, reject) => {
|
|
82
114
|
const finish = () => {
|
|
@@ -121,6 +153,20 @@ nodeRuntime.server.listen(runtime.config.port, runtime.config.host, () => {
|
|
|
121
153
|
}
|
|
122
154
|
desktopActivation.start();
|
|
123
155
|
});
|
|
156
|
+
const adminServer = nodeRuntime.adminServer;
|
|
157
|
+
if (adminServer) {
|
|
158
|
+
const { host, port, external } = runtime.config.admin;
|
|
159
|
+
adminServer.once('error', (error) => {
|
|
160
|
+
// The Web keeps running; the console is reported as unavailable.
|
|
161
|
+
console.error(error.code === 'EADDRINUSE'
|
|
162
|
+
? `管理后台无法启动:${host}:${port} 已被占用。可用 YAOYAO_ADMIN_PORT 指定其他端口。`
|
|
163
|
+
: `管理后台无法启动:${error.message}`);
|
|
164
|
+
});
|
|
165
|
+
adminServer.listen(port, host, () => {
|
|
166
|
+
const protocol = runtime.config.tlsCert ? 'https' : 'http';
|
|
167
|
+
console.log(`夭夭管理后台 listening on ${protocol}://${host}:${port}${external ? '(允许远程访问,已启用访问白名单)' : '(仅本机)'}`);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
124
170
|
let closing = false;
|
|
125
171
|
async function shutdown() {
|
|
126
172
|
if (closing)
|
|
@@ -91,6 +91,59 @@ export class LocalAuthStore {
|
|
|
91
91
|
throw new HttpError(401, '用户名或密码错误', 'login_failed');
|
|
92
92
|
return this.#issueSession(ctx, user, desktop);
|
|
93
93
|
}
|
|
94
|
+
/** Admin console login: checks credentials without issuing a Web session. */
|
|
95
|
+
verifyCredentials(usernameValue, password) {
|
|
96
|
+
const normalized = usernameValue.trim().toLocaleLowerCase('en-US');
|
|
97
|
+
const user = this.#users.find(candidate => candidate.normalizedUsername === normalized);
|
|
98
|
+
if (!user || !this.#passwordMatches(user, password) || !user.enabled) {
|
|
99
|
+
throw new HttpError(401, '用户名或密码错误', 'login_failed');
|
|
100
|
+
}
|
|
101
|
+
if (user.registrationStatus === 'pending')
|
|
102
|
+
throw new HttpError(403, '账号尚未开通', 'account_pending_approval');
|
|
103
|
+
return { user: publicUser(user), authVersion: user.authVersion };
|
|
104
|
+
}
|
|
105
|
+
/** The admin behind a console session, or undefined once disabled, demoted or its password changed. */
|
|
106
|
+
consoleAdmin(userID, authVersion) {
|
|
107
|
+
const user = this.#users.find(candidate => candidate.id === userID);
|
|
108
|
+
if (!user || !user.enabled || user.role !== 'admin' || user.authVersion !== authVersion)
|
|
109
|
+
return undefined;
|
|
110
|
+
return publicUser(user);
|
|
111
|
+
}
|
|
112
|
+
verifyPassword(userID, password) {
|
|
113
|
+
const user = this.#users.find(candidate => candidate.id === userID);
|
|
114
|
+
return Boolean(user && this.#passwordMatches(user, password));
|
|
115
|
+
}
|
|
116
|
+
/** Console password change; signs the admin out of every Web and console session. */
|
|
117
|
+
changePassword(userID, currentPassword, newPassword) {
|
|
118
|
+
const user = this.#users.find(candidate => candidate.id === userID);
|
|
119
|
+
if (!user)
|
|
120
|
+
throw new HttpError(401, '请重新登录', 'authentication_required');
|
|
121
|
+
if (!this.#passwordMatches(user, currentPassword))
|
|
122
|
+
throw new HttpError(401, '当前密码错误', 'invalid_current_password');
|
|
123
|
+
this.#setPassword(user, validatePassword(newPassword), false);
|
|
124
|
+
user.updatedAt = Date.now();
|
|
125
|
+
this.#saveUsers();
|
|
126
|
+
this.#revokeUser(user.id);
|
|
127
|
+
return { user: publicUser(user), authVersion: user.authVersion };
|
|
128
|
+
}
|
|
129
|
+
/** Console username change for the signed-in admin; existing sessions stay valid. */
|
|
130
|
+
rename(userID, currentPassword, newUsername) {
|
|
131
|
+
const user = this.#users.find(candidate => candidate.id === userID);
|
|
132
|
+
if (!user)
|
|
133
|
+
throw new HttpError(401, '请重新登录', 'authentication_required');
|
|
134
|
+
if (!this.#passwordMatches(user, currentPassword))
|
|
135
|
+
throw new HttpError(401, '当前密码错误', 'invalid_current_password');
|
|
136
|
+
const username = canonicalUsername(newUsername);
|
|
137
|
+
const normalized = username.toLocaleLowerCase('en-US');
|
|
138
|
+
if (this.#users.some(candidate => candidate.id !== user.id && candidate.normalizedUsername === normalized)) {
|
|
139
|
+
throw new HttpError(409, '用户名已存在', 'username_exists');
|
|
140
|
+
}
|
|
141
|
+
user.username = username;
|
|
142
|
+
user.normalizedUsername = normalized;
|
|
143
|
+
user.updatedAt = Date.now();
|
|
144
|
+
this.#saveUsers();
|
|
145
|
+
return publicUser(user);
|
|
146
|
+
}
|
|
94
147
|
/** Called only behind the native service capability, never from public auth routes. */
|
|
95
148
|
localDesktopSession(ctx) {
|
|
96
149
|
let admin = this.#users.find(user => user.role === 'admin' && user.enabled);
|
|
@@ -152,6 +205,10 @@ export class LocalAuthStore {
|
|
|
152
205
|
const injected = ctx.state.localUser;
|
|
153
206
|
if (injected)
|
|
154
207
|
return injected;
|
|
208
|
+
// The admin console re-resolves its own session; Web cookies never reach it.
|
|
209
|
+
const resolve = ctx.state.resolveLocalUser;
|
|
210
|
+
if (resolve)
|
|
211
|
+
return resolve();
|
|
155
212
|
return this.currentFromCookieHeader(ctx.get('cookie'));
|
|
156
213
|
}
|
|
157
214
|
/** Opaque vault binding; callers must separately validate the session. */
|
|
@@ -301,19 +358,13 @@ export class LocalAuthStore {
|
|
|
301
358
|
this.#saveUsers();
|
|
302
359
|
this.#revokeUser(userID);
|
|
303
360
|
}
|
|
304
|
-
changeCredentials(ctx, currentPassword, newPassword
|
|
361
|
+
changeCredentials(ctx, currentPassword, newPassword) {
|
|
305
362
|
const current = this.require(ctx, true);
|
|
306
363
|
const user = this.#users.find(candidate => candidate.id === current.id);
|
|
307
364
|
if (!current.localDesktop && !this.#passwordMatches(user, currentPassword)) {
|
|
308
365
|
throw new HttpError(401, '当前密码错误', 'invalid_current_password');
|
|
309
366
|
}
|
|
310
|
-
const username =
|
|
311
|
-
const normalized = username.toLocaleLowerCase('en-US');
|
|
312
|
-
if (this.#users.some(candidate => candidate.id !== user.id && candidate.normalizedUsername === normalized)) {
|
|
313
|
-
throw new HttpError(409, '用户名已存在', 'username_exists');
|
|
314
|
-
}
|
|
315
|
-
user.username = username;
|
|
316
|
-
user.normalizedUsername = normalized;
|
|
367
|
+
const username = user.username;
|
|
317
368
|
this.#setPassword(user, validatePassword(newPassword), false);
|
|
318
369
|
user.mustChangePassword = false;
|
|
319
370
|
user.updatedAt = Date.now();
|
|
@@ -648,8 +648,8 @@ export function createApiRouter(dependencies) {
|
|
|
648
648
|
const request = body(ctx);
|
|
649
649
|
const currentPassword = typeof request.currentPassword === 'string' ? request.currentPassword : '';
|
|
650
650
|
const newPassword = typeof request.newPassword === 'string' ? request.newPassword : '';
|
|
651
|
-
|
|
652
|
-
const user = dependencies.auth.changeCredentials(ctx, currentPassword, newPassword
|
|
651
|
+
// Usernames are not changed from the Web; administrators rename themselves in the admin console.
|
|
652
|
+
const user = dependencies.auth.changeCredentials(ctx, currentPassword, newPassword);
|
|
653
653
|
json(ctx, 200, { user, must_change_password: false, server_kind: 'yaoyao-web' });
|
|
654
654
|
});
|
|
655
655
|
router.post('/api/app/account-pairings', (ctx) => {
|
|
@@ -813,8 +813,8 @@ export function createApiRouter(dependencies) {
|
|
|
813
813
|
const request = body(ctx);
|
|
814
814
|
const currentPassword = typeof request.currentPassword === 'string' ? request.currentPassword : '';
|
|
815
815
|
const newPassword = typeof request.newPassword === 'string' ? request.newPassword : '';
|
|
816
|
-
|
|
817
|
-
const user = dependencies.auth.changeCredentials(ctx, currentPassword, newPassword
|
|
816
|
+
// Usernames are not changed from the Web; administrators rename themselves in the admin console.
|
|
817
|
+
const user = dependencies.auth.changeCredentials(ctx, currentPassword, newPassword);
|
|
818
818
|
json(ctx, 200, { user, mustChangePassword: false, csrfToken: dependencies.csrf.issue(ctx, true) });
|
|
819
819
|
});
|
|
820
820
|
router.put('/api/app/account/avatar', (ctx) => {
|
|
@@ -90,9 +90,11 @@ export function appendSetCookies(ctx, values) {
|
|
|
90
90
|
export class CsrfProtection {
|
|
91
91
|
#secret;
|
|
92
92
|
#secure;
|
|
93
|
-
|
|
93
|
+
#cookie;
|
|
94
|
+
constructor(secret = randomBytes(32), secure = false, cookieName = CSRF_COOKIE) {
|
|
94
95
|
this.#secret = secret;
|
|
95
96
|
this.#secure = secure;
|
|
97
|
+
this.#cookie = cookieName;
|
|
96
98
|
}
|
|
97
99
|
issue(ctx, rotate = false) {
|
|
98
100
|
const currentCookie = typeof ctx.get === 'function' ? ctx.get('cookie') : undefined;
|
|
@@ -103,7 +105,7 @@ export class CsrfProtection {
|
|
|
103
105
|
}
|
|
104
106
|
const token = randomBytes(24).toString('base64url');
|
|
105
107
|
const signed = `${token}.${this.#sign(token)}`;
|
|
106
|
-
appendSetCookies(ctx, [serialize(
|
|
108
|
+
appendSetCookies(ctx, [serialize(this.#cookie, signed, {
|
|
107
109
|
httpOnly: true,
|
|
108
110
|
secure: this.#secure,
|
|
109
111
|
sameSite: 'strict',
|
|
@@ -123,7 +125,7 @@ export class CsrfProtection {
|
|
|
123
125
|
#read(cookieHeader) {
|
|
124
126
|
if (!cookieHeader)
|
|
125
127
|
return undefined;
|
|
126
|
-
const signed = parse(cookieHeader)[
|
|
128
|
+
const signed = parse(cookieHeader)[this.#cookie];
|
|
127
129
|
if (!signed)
|
|
128
130
|
return undefined;
|
|
129
131
|
const separator = signed.lastIndexOf('.');
|
|
@@ -58,11 +58,11 @@ export function workspaceRouter(store, runtime, nodes, assets, uploads, auth, pu
|
|
|
58
58
|
'agentTeamManagement',
|
|
59
59
|
'computerControl', 'sharedComputers', 'computerManagement',
|
|
60
60
|
'files',
|
|
61
|
-
...(auth.require(ctx).role === 'admin' ? ['voice', 'context'] : []),
|
|
62
|
-
...(auth.require(ctx).role === 'admin' ? ['nodes', 'pairedNodes', 'editableNodeAddress'] : []),
|
|
63
61
|
'events', 'workspace-stream-v1',
|
|
64
62
|
// Ordinary chat, history and the realtime relay were removed; mobile hides its chat mode.
|
|
65
63
|
'bot-only-v1',
|
|
64
|
+
// Management and system settings live on the separate admin console listener.
|
|
65
|
+
'admin-console-v1',
|
|
66
66
|
...(store.messagePatchesEnabled ? [WORKSPACE_PATCH_CAPABILITY] : []),
|
|
67
67
|
],
|
|
68
68
|
};
|
|
@@ -75,11 +75,11 @@ export function workspaceRouter(store, runtime, nodes, assets, uploads, auth, pu
|
|
|
75
75
|
ctx.body = { agents: agents.map(agent => store.agentSummary(agent)) };
|
|
76
76
|
});
|
|
77
77
|
router.get('/api/app/nodes/:id/agents', async (ctx) => {
|
|
78
|
-
auth.
|
|
78
|
+
auth.require(ctx);
|
|
79
79
|
throw new HttpError(410, '远程机器人已停用', 'remote_agent_removed');
|
|
80
80
|
});
|
|
81
81
|
router.post('/api/app/agents/remote', async (ctx) => {
|
|
82
|
-
auth.
|
|
82
|
+
auth.require(ctx);
|
|
83
83
|
throw new HttpError(410, '远程机器人已停用', 'remote_agent_removed');
|
|
84
84
|
});
|
|
85
85
|
router.post('/api/app/agents', async (ctx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lsamien/yaoyao",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "夭夭 AI:聊天、多 Agent 团队、文件库与电脑工作空间",
|
|
6
6
|
"type": "module",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"dev": "cross-env NODE_ENV=development tsx watch src/server/index.ts",
|
|
16
|
-
"build": "npm run brand:verify && npm run release:verify && vue-tsc -b tsconfig.client.build.json && vite build && tsc -p tsconfig.server.json && node scripts/copy-worker.mjs && node scripts/write-build-info.mjs",
|
|
16
|
+
"build": "npm run brand:verify && npm run release:verify && vue-tsc -b tsconfig.client.build.json && vite build && vite build --config vite.admin.config.ts && tsc -p tsconfig.server.json && node scripts/copy-worker.mjs && node scripts/write-build-info.mjs",
|
|
17
17
|
"start": "cross-env NODE_ENV=production node dist-server/server/index.js",
|
|
18
18
|
"typecheck": "vue-tsc -b && tsc --noEmit -p tsconfig.server.json",
|
|
19
19
|
"test": "vitest run",
|
package/release.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{G as e,I as t,S as n,b as r,g as i,h as a,lt as o,ot as s,t as c,y as l}from"./_plugin-vue_export-helper-CW5Ldrk2.js";import{t as u}from"./BrandMark-DHKCL6jN.js";import{t as d}from"./StandaloneDialog-DibKSM6U.js";var f=`0.5.0`,p={class:`about-content`},m={class:`about-version`},h=c(n({__name:`AboutDialog`,emits:[`close`],setup(n,{emit:c}){let h=c;return(n,c)=>(t(),i(d,{title:`关于夭夭 AI`,compact:``,onClose:c[0]||=e=>h(`close`)},{default:e(()=>[a(`section`,p,[r(u,{size:56,label:!1,compact:``,bare:``}),c[1]||=a(`h3`,null,`夭夭 AI`,-1),a(`p`,m,`版本 `+o(s(f)),1),c[2]||=a(`p`,null,[l(`与 AI 聊天,让 Bot 协作完成任务。`),a(`br`),l(`基于 Apache-2.0 许可证开放源代码。`)],-1),c[3]||=a(`nav`,{"aria-label":`关于链接`},[a(`a`,{href:`https://github.com/Lsamien/yaoyao`,target:`_blank`,rel:`noopener noreferrer`},`GitHub`),a(`a`,{href:`https://yaoyao.samien.cn`,target:`_blank`,rel:`noopener noreferrer`},`帮助中心`),a(`a`,{href:`https://github.com/Lsamien/yaoyao/releases`,target:`_blank`,rel:`noopener noreferrer`},`版本发布`)],-1)])]),_:1}))}}),[[`__scopeId`,`data-v-c1a0f944`]]);export{h as default};
|
|
2
|
-
//# sourceMappingURL=AboutDialog-nXDYG57h.js.map
|