@lsamien/yaoyao 0.4.75
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/LICENSE +202 -0
- package/NOTICE +6 -0
- package/README.md +103 -0
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/bin/desktop-service-sync.mjs +43 -0
- package/bin/hermes-yaoyao-updater.mjs +315 -0
- package/bin/hermes-yaoyao.mjs +246 -0
- package/bin/lib/data-home.d.mts +4 -0
- package/bin/lib/data-home.mjs +24 -0
- package/bin/lib/data-migration.d.mts +2 -0
- package/bin/lib/data-migration.mjs +107 -0
- package/bin/lib/desktop-activation.d.mts +4 -0
- package/bin/lib/desktop-activation.mjs +18 -0
- package/bin/lib/managed-data-migration.mjs +45 -0
- package/bin/lib/release-source.d.mts +2 -0
- package/bin/lib/release-source.mjs +23 -0
- package/bin/lib/runtime-release.mjs +78 -0
- package/bin/lib/service-data.mjs +57 -0
- package/bin/lib/service-update.mjs +372 -0
- package/bin/migrate-data-home.mjs +20 -0
- package/build-info.json +657 -0
- package/desktop/main.mjs +679 -0
- package/dist/assets/AboutDialog-BvuJp8Pe.js +2 -0
- package/dist/assets/AboutDialog-BvuJp8Pe.js.map +1 -0
- package/dist/assets/AboutDialog-DC5YWX39.css +1 -0
- package/dist/assets/BotAutomationsView-Ddgs5Hes.js +2 -0
- package/dist/assets/BotAutomationsView-Ddgs5Hes.js.map +1 -0
- package/dist/assets/BotAutomationsView-DeJ-e3y5.css +1 -0
- package/dist/assets/BotPluginsDialog-Db5dTqvg.css +1 -0
- package/dist/assets/BotPluginsDialog-xPqUSyHS.js +2 -0
- package/dist/assets/BotPluginsDialog-xPqUSyHS.js.map +1 -0
- package/dist/assets/BotSettingsDialog-BkjoAZtf.css +1 -0
- package/dist/assets/BotSettingsDialog-wLz_KGzX.js +5 -0
- package/dist/assets/BotSettingsDialog-wLz_KGzX.js.map +1 -0
- package/dist/assets/ChatView-DRPu2nKr.js +2 -0
- package/dist/assets/ChatView-DRPu2nKr.js.map +1 -0
- package/dist/assets/ChatView-Dx8YlcPr.css +1 -0
- package/dist/assets/ChevronForwardOutline-D--GIQK6.js +2 -0
- package/dist/assets/ChevronForwardOutline-D--GIQK6.js.map +1 -0
- package/dist/assets/ComputerPanel-Byr2_yKj.js +2 -0
- package/dist/assets/ComputerPanel-Byr2_yKj.js.map +1 -0
- package/dist/assets/ComputerPanel-CQOv4v8E.css +1 -0
- package/dist/assets/ComputerViewerView-BBAs4bzi.css +1 -0
- package/dist/assets/ComputerViewerView-DJ6hB-5e.js +2 -0
- package/dist/assets/ComputerViewerView-DJ6hB-5e.js.map +1 -0
- package/dist/assets/ConversationsView-C_VZl5g2.css +1 -0
- package/dist/assets/ConversationsView-cu1Yrq68.js +6 -0
- package/dist/assets/ConversationsView-cu1Yrq68.js.map +1 -0
- package/dist/assets/FilesView-DAIzo9Ps.css +1 -0
- package/dist/assets/FilesView-h9oJFmZt.js +2 -0
- package/dist/assets/FilesView-h9oJFmZt.js.map +1 -0
- package/dist/assets/FloatingResourceSearch-BF2XOLd-.css +1 -0
- package/dist/assets/FloatingResourceSearch-TofG1_DV.js +9 -0
- package/dist/assets/FloatingResourceSearch-TofG1_DV.js.map +1 -0
- package/dist/assets/HistoryView-Bh0SU969.js +2 -0
- package/dist/assets/HistoryView-Bh0SU969.js.map +1 -0
- package/dist/assets/HistoryView-DvuCAjlo.css +1 -0
- package/dist/assets/KanbanView-B-2vG4w7.css +1 -0
- package/dist/assets/KanbanView-CcqMOzB7.js +2 -0
- package/dist/assets/KanbanView-CcqMOzB7.js.map +1 -0
- package/dist/assets/LocalVmSettingsPanel-C8PIgMr3.js +2 -0
- package/dist/assets/LocalVmSettingsPanel-C8PIgMr3.js.map +1 -0
- package/dist/assets/LocalVmSettingsPanel-Dedfhqlq.css +1 -0
- package/dist/assets/RunnerSettingsPanel-CfxxQKpV.css +1 -0
- package/dist/assets/RunnerSettingsPanel-CvNnWcdH.js +4 -0
- package/dist/assets/RunnerSettingsPanel-CvNnWcdH.js.map +1 -0
- package/dist/assets/StandaloneDialog-BbNWY6IJ.js +2 -0
- package/dist/assets/StandaloneDialog-BbNWY6IJ.js.map +1 -0
- package/dist/assets/StandaloneDialog-Bg5U9bMJ.css +1 -0
- package/dist/assets/UpdateCheckDialog-C357uDSE.js +2 -0
- package/dist/assets/UpdateCheckDialog-C357uDSE.js.map +1 -0
- package/dist/assets/UpdateCheckDialog-CRlyWnE7.css +1 -0
- package/dist/assets/WorkspaceKnowledgePanel-B6xMyHdp.css +1 -0
- package/dist/assets/WorkspaceKnowledgePanel-CE7qsu2i.js +2 -0
- package/dist/assets/WorkspaceKnowledgePanel-CE7qsu2i.js.map +1 -0
- package/dist/assets/WorkspaceRoutinesPanel-CLsHmBuH.css +1 -0
- package/dist/assets/WorkspaceRoutinesPanel-DybBh6PZ.js +2 -0
- package/dist/assets/WorkspaceRoutinesPanel-DybBh6PZ.js.map +1 -0
- package/dist/assets/WorkspaceShell-7wn8iTne.css +1 -0
- package/dist/assets/WorkspaceShell-kp1ObJTk.js +44 -0
- package/dist/assets/WorkspaceShell-kp1ObJTk.js.map +1 -0
- package/dist/assets/WorkspaceView-CtNI0_AO.js +2 -0
- package/dist/assets/WorkspaceView-CtNI0_AO.js.map +1 -0
- package/dist/assets/_plugin-vue_export-helper-CscYwSBt.js +3 -0
- package/dist/assets/_plugin-vue_export-helper-CscYwSBt.js.map +1 -0
- package/dist/assets/browser-B97PQaMt.js +11 -0
- package/dist/assets/browser-B97PQaMt.js.map +1 -0
- package/dist/assets/docx-preview-YvkiVUyQ.js +22 -0
- package/dist/assets/docx-preview-YvkiVUyQ.js.map +1 -0
- package/dist/assets/index-GQxxBKs2.js +17 -0
- package/dist/assets/index-GQxxBKs2.js.map +1 -0
- package/dist/assets/index-g5POnMkp.css +1 -0
- package/dist/assets/localVm-owThjmhy.js +2 -0
- package/dist/assets/localVm-owThjmhy.js.map +1 -0
- package/dist/assets/pdf-pqGpzpl1.js +55 -0
- package/dist/assets/pdf-pqGpzpl1.js.map +1 -0
- package/dist/assets/pdf.worker.min-iDqQPrd3.mjs +31 -0
- package/dist/assets/sessionOwnership-BTz0Fyp5.css +1 -0
- package/dist/assets/sessionOwnership-bedp16q1.js +6 -0
- package/dist/assets/sessionOwnership-bedp16q1.js.map +1 -0
- package/dist/assets/viewModels-BYFb-v4u.js +38 -0
- package/dist/assets/viewModels-BYFb-v4u.js.map +1 -0
- package/dist/assets/viewModels-CkZuSvKm.css +1 -0
- package/dist/brand/AppIcon-1024.png +0 -0
- package/dist/icons/apple-touch-icon.png +0 -0
- package/dist/icons/favicon-32.png +0 -0
- package/dist/icons/icon-192.png +0 -0
- package/dist/icons/icon-512.png +0 -0
- package/dist/icons/logo-64.png +0 -0
- package/dist/index.html +19 -0
- package/dist/manifest.webmanifest +21 -0
- package/dist/setting-previews/dark.png +0 -0
- package/dist/setting-previews/light.png +0 -0
- package/dist/setting-previews/system.png +0 -0
- package/dist-server/runner/agent.js +563 -0
- package/dist-server/runner/browser/installation.js +180 -0
- package/dist-server/runner/browser/publicProxy.js +157 -0
- package/dist-server/runner/browser/runtime.js +622 -0
- package/dist-server/runner/browser/types.js +8 -0
- package/dist-server/runner/computers/commandProcess.js +127 -0
- package/dist-server/runner/computers/compose.js +139 -0
- package/dist-server/runner/computers/computer-image/Dockerfile +101 -0
- package/dist-server/runner/computers/computer-image/Dockerfile.cursor +27 -0
- package/dist-server/runner/computers/computer-image/Dockerfile.network +9 -0
- package/dist-server/runner/computers/computer-image/compose_bridge.py +329 -0
- package/dist-server/runner/computers/computer-image/cursor-browser.sh +6 -0
- package/dist-server/runner/computers/computer-image/cursor-desktop.py +86 -0
- package/dist-server/runner/computers/computer-image/network_gateway.py +197 -0
- package/dist-server/runner/computers/computer-image/prepare-firefox.sh +11 -0
- package/dist-server/runner/computers/computer-image/skill_bundle.py +111 -0
- package/dist-server/runner/computers/computerFailures.js +30 -0
- package/dist-server/runner/computers/container.js +652 -0
- package/dist-server/runner/computers/dataSnapshot.js +62 -0
- package/dist-server/runner/computers/desktopClose.js +41 -0
- package/dist-server/runner/computers/imageCli.js +42 -0
- package/dist-server/runner/computers/imageManagement.js +321 -0
- package/dist-server/runner/computers/images.js +130 -0
- package/dist-server/runner/computers/localVm.js +270 -0
- package/dist-server/runner/computers/maintenance.js +96 -0
- package/dist-server/runner/computers/maintenanceCli.js +59 -0
- package/dist-server/runner/computers/migrateUserData.js +62 -0
- package/dist-server/runner/computers/pool.js +407 -0
- package/dist-server/runner/computers/third-party/openmausbot/LICENSE +202 -0
- package/dist-server/runner/computers/third-party/openmausbot/NOTICE +4 -0
- package/dist-server/runner/computers/userData.js +128 -0
- package/dist-server/runner/computers/workspaceRecovery.js +120 -0
- package/dist-server/runner/config.js +37 -0
- package/dist-server/runner/hermes-bots-bridge/README.md +102 -0
- package/dist-server/runner/hermes-bots-bridge/__init__.py +59 -0
- package/dist-server/runner/hermes-bots-bridge/bootstrap.py +31 -0
- package/dist-server/runner/hermes-bots-bridge/bridge_runtime.py +1179 -0
- package/dist-server/runner/hermes-bots-bridge/dashboard/bridge.js +2 -0
- package/dist-server/runner/hermes-bots-bridge/dashboard/manifest.json +9 -0
- package/dist-server/runner/hermes-bots-bridge/dashboard/plugin_api.py +132 -0
- package/dist-server/runner/hermes-bots-bridge/file_transfer.py +146 -0
- package/dist-server/runner/hermes-bots-bridge/model_settings.py +136 -0
- package/dist-server/runner/hermes-bots-bridge/plugin.yaml +4 -0
- package/dist-server/runner/hermes-bots-bridge/profile_runtime_repair.py +77 -0
- package/dist-server/runner/index.js +75 -0
- package/dist-server/runner/install-hermes-bridge.py +192 -0
- package/dist-server/runner/managedBrowser.js +266 -0
- package/dist-server/runner/network/computerProxy.js +117 -0
- package/dist-server/runner/network/managedProxy.js +96 -0
- package/dist-server/runner/network/publicDestination.js +47 -0
- package/dist-server/runner/network/socketBroker.js +131 -0
- package/dist-server/runner/network/upstreamProxy.js +118 -0
- package/dist-server/runner/worker/control.js +212 -0
- package/dist-server/runner/worker/fileTransfer.js +9 -0
- package/dist-server/runner/worker/gateway.js +1009 -0
- package/dist-server/runner/worker/guest_proxy.py +116 -0
- package/dist-server/runner/worker/hermes_worker.py +310 -0
- package/dist-server/runner/worker/hostTools.js +115 -0
- package/dist-server/runner/worker/process.js +123 -0
- package/dist-server/runner/worker/profileSession.js +144 -0
- package/dist-server/runner/worker/profile_skills.py +361 -0
- package/dist-server/runner/worker/skill_bundle.py +111 -0
- package/dist-server/runner/worker/skills.js +119 -0
- package/dist-server/runner/worker/taskEnvironment.js +35 -0
- package/dist-server/server/accountPairing.js +72 -0
- package/dist-server/server/allowedHostsConfiguration.js +170 -0
- package/dist-server/server/apns.js +261 -0
- package/dist-server/server/apnsConfiguration.js +298 -0
- package/dist-server/server/app.js +639 -0
- package/dist-server/server/botModelSettings.js +60 -0
- package/dist-server/server/botPlugins/connectedApps.js +213 -0
- package/dist-server/server/botPlugins/httpMcp.js +117 -0
- package/dist-server/server/botPlugins/stdioMcp.js +263 -0
- package/dist-server/server/botPlugins/workspacePlugins.js +353 -0
- package/dist-server/server/browserFiles.js +79 -0
- package/dist-server/server/buildIdentity.js +18 -0
- package/dist-server/server/chatCache.js +1651 -0
- package/dist-server/server/chatEventProjection.js +70 -0
- package/dist-server/server/chatTranscriptApi.js +145 -0
- package/dist-server/server/chatTranscriptStore.js +1021 -0
- package/dist-server/server/chatUnread.js +34 -0
- package/dist-server/server/codexAuthorization.js +149 -0
- package/dist-server/server/composeDesktops.js +69 -0
- package/dist-server/server/computerControls.js +122 -0
- package/dist-server/server/computerNames.js +41 -0
- package/dist-server/server/config.js +176 -0
- package/dist-server/server/dashboardController.js +120 -0
- package/dist-server/server/dashboardSupervisor.js +176 -0
- package/dist-server/server/desktopActivation.js +26 -0
- package/dist-server/server/desktopEnvironments.js +600 -0
- package/dist-server/server/desktopHostProtocol.js +17 -0
- package/dist-server/server/desktopHosts.js +117 -0
- package/dist-server/server/errors.js +12 -0
- package/dist-server/server/executionSettings.js +171 -0
- package/dist-server/server/fcm.js +247 -0
- package/dist-server/server/fcmConfiguration.js +270 -0
- package/dist-server/server/fileAccess.js +103 -0
- package/dist-server/server/fileTransfer.js +98 -0
- package/dist-server/server/githubReleases.js +73 -0
- package/dist-server/server/grokAuth.js +333 -0
- package/dist-server/server/grokCloud.js +458 -0
- package/dist-server/server/hermesBotRelay.js +117 -0
- package/dist-server/server/hermesBridge.js +245 -0
- package/dist-server/server/hostToolSettings.js +60 -0
- package/dist-server/server/imageManagement.js +55 -0
- package/dist-server/server/index.js +132 -0
- package/dist-server/server/leases.js +69 -0
- package/dist-server/server/localAuth.js +737 -0
- package/dist-server/server/localVm.js +358 -0
- package/dist-server/server/loopbackAuthorization.js +58 -0
- package/dist-server/server/managedBrowserTools.js +16 -0
- package/dist-server/server/managedBrowsers.js +735 -0
- package/dist-server/server/notificationText.js +125 -0
- package/dist-server/server/openVikingConfiguration.js +222 -0
- package/dist-server/server/openVikingMemoryProvider.js +279 -0
- package/dist-server/server/openVikingService.js +177 -0
- package/dist-server/server/openVikingSessionSync.js +286 -0
- package/dist-server/server/pairing.js +342 -0
- package/dist-server/server/profileIdentities.js +103 -0
- package/dist-server/server/pushCoordinator.js +1422 -0
- package/dist-server/server/pushEventAdapter.js +31 -0
- package/dist-server/server/pushEvents.js +1218 -0
- package/dist-server/server/realtimeApi.js +330 -0
- package/dist-server/server/realtimeBroker.js +835 -0
- package/dist-server/server/realtimeProtocol.js +353 -0
- package/dist-server/server/realtimeReceipts.js +60 -0
- package/dist-server/server/releases.js +46 -0
- package/dist-server/server/routes.js +2156 -0
- package/dist-server/server/runnerHub.js +687 -0
- package/dist-server/server/security.js +196 -0
- package/dist-server/server/serverIdentity.js +31 -0
- package/dist-server/server/serviceInstance.js +178 -0
- package/dist-server/server/sessionWorkingDirectory.js +39 -0
- package/dist-server/server/sharedComputers.js +221 -0
- package/dist-server/server/subaccountAccess.js +28 -0
- package/dist-server/server/taskCoordinator.js +580 -0
- package/dist-server/server/toolOperationJournal.js +81 -0
- package/dist-server/server/updateManager.js +340 -0
- package/dist-server/server/uploads.js +265 -0
- package/dist-server/server/upstream.js +375 -0
- package/dist-server/server/upstreamReadCache.js +133 -0
- package/dist-server/server/vmComputer.js +96 -0
- package/dist-server/server/websocket.js +753 -0
- package/dist-server/server/workspaceAssets.js +192 -0
- package/dist-server/server/workspaceCollaboration.js +224 -0
- package/dist-server/server/workspaceDiscussion.js +23 -0
- package/dist-server/server/workspaceEnvironment.js +43 -0
- package/dist-server/server/workspaceGateway.js +509 -0
- package/dist-server/server/workspaceInspector.js +47 -0
- package/dist-server/server/workspaceKnowledge.js +557 -0
- package/dist-server/server/workspaceKnowledgeRoutes.js +78 -0
- package/dist-server/server/workspaceKnowledgeTools.js +105 -0
- package/dist-server/server/workspaceMemoryContext.js +34 -0
- package/dist-server/server/workspaceMemorySynthesis.js +201 -0
- package/dist-server/server/workspaceMentions.js +31 -0
- package/dist-server/server/workspacePairedNode.js +166 -0
- package/dist-server/server/workspacePrompt.js +93 -0
- package/dist-server/server/workspaceRelay.js +90 -0
- package/dist-server/server/workspaceRemoteAgents.js +191 -0
- package/dist-server/server/workspaceRoutes.js +703 -0
- package/dist-server/server/workspaceRoutineTools.js +109 -0
- package/dist-server/server/workspaceRoutines.js +163 -0
- package/dist-server/server/workspaceRuntime.js +1363 -0
- package/dist-server/server/workspaceScheduler.js +592 -0
- package/dist-server/server/workspaceStore.js +1220 -0
- package/dist-server/server/workspaceSync.js +129 -0
- package/dist-server/server/workspaceTeamTools.js +312 -0
- package/dist-server/server/workspaceToolLease.js +280 -0
- package/dist-server/shared/agentIdentity.js +90 -0
- package/dist-server/shared/agentTasks.js +1 -0
- package/dist-server/shared/botEnvironment.js +28 -0
- package/dist-server/shared/botModelSettings.js +3 -0
- package/dist-server/shared/chatTools.js +32 -0
- package/dist-server/shared/chatTranscript.js +50 -0
- package/dist-server/shared/composeDesktops.js +1 -0
- package/dist-server/shared/computerControl.js +1 -0
- package/dist-server/shared/desktopEnvironment.js +1 -0
- package/dist-server/shared/desktopHost.js +1 -0
- package/dist-server/shared/executionEnvironment.js +1 -0
- package/dist-server/shared/fileTransfer.js +5 -0
- package/dist-server/shared/fileTransferEndpoint.mjs +133 -0
- package/dist-server/shared/grokAuth.js +1 -0
- package/dist-server/shared/hermesBridge.js +1 -0
- package/dist-server/shared/hostPaths.mjs +22 -0
- package/dist-server/shared/imageManagement.js +1 -0
- package/dist-server/shared/index.js +1 -0
- package/dist-server/shared/localVm.js +9 -0
- package/dist-server/shared/managedBrowser.js +1 -0
- package/dist-server/shared/messageFiles.js +90 -0
- package/dist-server/shared/openVikingSync.js +1 -0
- package/dist-server/shared/runner.js +2 -0
- package/dist-server/shared/serverFiles.js +55 -0
- package/dist-server/shared/serverIdentity.js +1 -0
- package/dist-server/shared/sse.js +47 -0
- package/dist-server/shared/types.js +8 -0
- package/dist-server/shared/workspace.js +61 -0
- package/dist-server/shared/workspaceKnowledge.js +1 -0
- package/dist-server/shared/workspaceLifecycle.js +1 -0
- package/dist-server/shared/workspaceMessagePatch.js +63 -0
- package/dist-server/shared/workspacePanels.js +1 -0
- package/dist-server/shared/workspacePlugins.js +1 -0
- package/licenses/LaoA-GrokBot/LICENSE +21 -0
- package/licenses/OpenMausBot/LICENSE +202 -0
- package/licenses/OpenMausBot/NOTICE +6 -0
- package/package.json +122 -0
- package/release.json +6 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** List badges count completed results; transport rows and progress never count. */
|
|
2
|
+
export function isFinalChatResult(message) {
|
|
3
|
+
if (message.role !== 'assistant' || message.error || message.is_streaming || message.isStreaming)
|
|
4
|
+
return false;
|
|
5
|
+
if (message.final_result === false || message.is_interim || message.display_kind || message.displayKind)
|
|
6
|
+
return false;
|
|
7
|
+
const status = message.status ?? message.finish_reason ?? message.finishReason;
|
|
8
|
+
if (['streaming', 'pending', 'running', 'interim', 'failed', 'error', 'cancelled', 'interrupted', 'tool_calls', 'function_call'].includes(status))
|
|
9
|
+
return false;
|
|
10
|
+
// Live projections retain tool traces on the final answer. Historical tool
|
|
11
|
+
// invocation rows have no explicit completion marker and must be excluded.
|
|
12
|
+
if (message.final_result !== true) {
|
|
13
|
+
let tools = message.tool_calls ?? message.toolCalls ?? message.tools;
|
|
14
|
+
if (typeof tools === 'string') {
|
|
15
|
+
try {
|
|
16
|
+
tools = JSON.parse(tools);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if ((Array.isArray(tools) ? tools.length > 0 : !!tools) || message.function_call)
|
|
23
|
+
return false;
|
|
24
|
+
if (Array.isArray(message.content) && message.content.some(block => ['tool_use', 'tool_call', 'function_call'].includes(block?.type)))
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const content = message.content ?? message.text;
|
|
28
|
+
const visible = (value) => typeof value === 'string'
|
|
29
|
+
&& value.replace(/<(think|thinking|reasoning)\b[^>]*>[\s\S]*?(?:<\/\1>|$)/gi, '').trim().length > 0;
|
|
30
|
+
return visible(content)
|
|
31
|
+
|| (Array.isArray(content) && content.some(block => block && (['text', 'output_text'].includes(block.type) && visible(block.text)
|
|
32
|
+
|| ['image', 'image_url', 'file', 'audio', 'video'].includes(block.type))))
|
|
33
|
+
|| (Array.isArray(message.attachments) && message.attachments.length > 0);
|
|
34
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync } from 'node:fs';
|
|
3
|
+
import { homedir, tmpdir } from 'node:os';
|
|
4
|
+
import { delimiter, join } from 'node:path';
|
|
5
|
+
import { HttpError } from './errors.js';
|
|
6
|
+
const TTL = 15 * 60_000;
|
|
7
|
+
export const CODEX_DEVICE_URL = 'https://auth.openai.com/codex/device';
|
|
8
|
+
function codexBinary() {
|
|
9
|
+
if (process.env.HERMES_YAOYAO_CODEX_BIN)
|
|
10
|
+
return process.env.HERMES_YAOYAO_CODEX_BIN;
|
|
11
|
+
const command = process.platform === 'win32' ? 'codex.exe' : 'codex';
|
|
12
|
+
const candidates = (process.env.PATH ?? '').split(delimiter).filter(Boolean).map(path => join(path, command));
|
|
13
|
+
if (process.platform === 'darwin')
|
|
14
|
+
for (const base of ['/Applications', join(homedir(), 'Applications')]) {
|
|
15
|
+
candidates.push(join(base, 'ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex'), join(base, 'Codex.app/Contents/Resources/codex'));
|
|
16
|
+
}
|
|
17
|
+
return candidates.find(path => existsSync(path)) ?? command;
|
|
18
|
+
}
|
|
19
|
+
/** Each login has its own credential store; the host's Codex login is never read. */
|
|
20
|
+
export class CodexAuthorization {
|
|
21
|
+
auth;
|
|
22
|
+
launch;
|
|
23
|
+
attempts = new Map();
|
|
24
|
+
constructor(auth, launch = spawn) {
|
|
25
|
+
this.auth = auth;
|
|
26
|
+
this.launch = launch;
|
|
27
|
+
}
|
|
28
|
+
begin(owner, id) {
|
|
29
|
+
const previous = this.attempts.get(owner);
|
|
30
|
+
if (previous?.state.id === id)
|
|
31
|
+
return this.snapshot(owner, id);
|
|
32
|
+
if (previous)
|
|
33
|
+
this.stop(previous, 'cancelled');
|
|
34
|
+
if (!this.auth.isAdminActive(owner))
|
|
35
|
+
throw new HttpError(403, '需要管理员权限', 'admin_required');
|
|
36
|
+
const directory = mkdtempSync(join(tmpdir(), 'yaoyao-codex-login-'));
|
|
37
|
+
const attempt = { owner, version: this.auth.pushAuthorizationVersion(owner) ?? 0, directory, output: '',
|
|
38
|
+
state: { id, status: 'starting', expiresAt: Date.now() + TTL } };
|
|
39
|
+
this.attempts.set(owner, attempt);
|
|
40
|
+
attempt.timer = setTimeout(() => this.stop(attempt, 'expired'), TTL);
|
|
41
|
+
attempt.timer.unref();
|
|
42
|
+
const env = { ...process.env, CODEX_HOME: directory };
|
|
43
|
+
for (const key of ['OPENAI_API_KEY', 'CODEX_API_KEY', 'CODEX_ACCESS_TOKEN', 'OPENAI_FEDERATION_RULE_ID', 'OPENAI_IDENTITY_TOKEN_FILE'])
|
|
44
|
+
delete env[key];
|
|
45
|
+
try {
|
|
46
|
+
const child = this.launch(codexBinary(), ['login', '--device-auth', '-c', 'cli_auth_credentials_store="file"'], { cwd: directory, env, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
47
|
+
attempt.child = child;
|
|
48
|
+
const receive = (chunk) => {
|
|
49
|
+
if (!this.active(attempt) || !['starting', 'pending'].includes(attempt.state.status))
|
|
50
|
+
return;
|
|
51
|
+
// The CLI uses ANSI styling and can split either the URL or the code across chunks.
|
|
52
|
+
attempt.output = (attempt.output + chunk.toString()).slice(-16000);
|
|
53
|
+
const plain = attempt.output.replace(/\x1b\[[0-9;]*[A-Za-z]/g, '');
|
|
54
|
+
const code = plain.match(/^\s*([A-Z0-9]{4}-[A-Z0-9]{4,5})\s*$/m)?.[1];
|
|
55
|
+
if (plain.includes(CODEX_DEVICE_URL) && code) {
|
|
56
|
+
attempt.state = { ...attempt.state, status: 'pending', loginUrl: CODEX_DEVICE_URL, userCode: code };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
child.stdout?.on('data', receive);
|
|
60
|
+
child.stderr?.on('data', receive);
|
|
61
|
+
child.once('error', (error) => {
|
|
62
|
+
this.stop(attempt, 'failed', error.code === 'ENOENT'
|
|
63
|
+
? '服务器未找到 Codex CLI,请安装后重试,或选择导入授权文件。'
|
|
64
|
+
: '无法启动浏览器授权,请稍后重试或导入授权文件。');
|
|
65
|
+
});
|
|
66
|
+
child.once('close', code => {
|
|
67
|
+
attempt.child = undefined;
|
|
68
|
+
try {
|
|
69
|
+
if (!this.active(attempt) || !['starting', 'pending'].includes(attempt.state.status))
|
|
70
|
+
return;
|
|
71
|
+
if (code !== 0)
|
|
72
|
+
throw new Error('login failed');
|
|
73
|
+
const path = join(directory, 'auth.json');
|
|
74
|
+
if (statSync(path).size > 64000)
|
|
75
|
+
throw new Error('invalid credentials');
|
|
76
|
+
const authJson = readFileSync(path, 'utf8'), data = JSON.parse(authJson);
|
|
77
|
+
if (typeof data?.tokens?.access_token !== 'string' || !data.tokens.access_token)
|
|
78
|
+
throw new Error('missing credentials');
|
|
79
|
+
attempt.authJson = authJson;
|
|
80
|
+
attempt.output = '';
|
|
81
|
+
attempt.state = { id, status: 'authorized', expiresAt: attempt.state.expiresAt };
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
this.stop(attempt, 'failed', '浏览器授权未完成,请确认账号已开启设备码登录后重试,或导入授权文件。');
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
this.cleanup(attempt);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
this.stop(attempt, 'failed', '无法启动浏览器授权,请检查服务器上的 Codex CLI,或导入授权文件。');
|
|
93
|
+
}
|
|
94
|
+
return { ...attempt.state };
|
|
95
|
+
}
|
|
96
|
+
active(attempt) {
|
|
97
|
+
if (this.attempts.get(attempt.owner) !== attempt)
|
|
98
|
+
return false;
|
|
99
|
+
if (!this.auth.isAdminActive(attempt.owner) || this.auth.pushAuthorizationVersion(attempt.owner) !== attempt.version) {
|
|
100
|
+
this.stop(attempt, 'cancelled');
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (Date.now() >= attempt.state.expiresAt) {
|
|
104
|
+
this.stop(attempt, 'expired');
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
require(owner, id) {
|
|
110
|
+
const attempt = this.attempts.get(owner);
|
|
111
|
+
if (!attempt || attempt.state.id !== id)
|
|
112
|
+
throw new HttpError(404, '这次授权已结束,请重新登录', 'codex_auth_not_found');
|
|
113
|
+
this.active(attempt);
|
|
114
|
+
return attempt;
|
|
115
|
+
}
|
|
116
|
+
snapshot(owner, id) { return { ...this.require(owner, id).state }; }
|
|
117
|
+
credentials(owner, id) {
|
|
118
|
+
const attempt = this.require(owner, id);
|
|
119
|
+
if (attempt.state.status !== 'authorized' || !attempt.authJson)
|
|
120
|
+
throw new HttpError(409, '请先完成浏览器授权', 'codex_auth_incomplete');
|
|
121
|
+
return attempt.authJson;
|
|
122
|
+
}
|
|
123
|
+
cancel(owner, id) {
|
|
124
|
+
const attempt = this.require(owner, id);
|
|
125
|
+
this.stop(attempt, 'cancelled');
|
|
126
|
+
return { ...attempt.state };
|
|
127
|
+
}
|
|
128
|
+
cleanup(attempt) { rmSync(attempt.directory, { recursive: true, force: true }); }
|
|
129
|
+
stop(attempt, status, error) {
|
|
130
|
+
clearTimeout(attempt.timer);
|
|
131
|
+
attempt.output = '';
|
|
132
|
+
attempt.authJson = undefined;
|
|
133
|
+
attempt.state = { id: attempt.state.id, expiresAt: attempt.state.expiresAt, status, ...(error ? { error } : {}) };
|
|
134
|
+
const child = attempt.child;
|
|
135
|
+
if (child && child.exitCode === null && child.signalCode === null) {
|
|
136
|
+
child.kill();
|
|
137
|
+
const force = setTimeout(() => child.kill('SIGKILL'), 2000);
|
|
138
|
+
force.unref();
|
|
139
|
+
child.once('close', () => clearTimeout(force));
|
|
140
|
+
}
|
|
141
|
+
else
|
|
142
|
+
this.cleanup(attempt);
|
|
143
|
+
}
|
|
144
|
+
close() {
|
|
145
|
+
for (const attempt of this.attempts.values())
|
|
146
|
+
this.stop(attempt, 'cancelled');
|
|
147
|
+
this.attempts.clear();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { request } from 'node:http';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { HttpError } from './errors.js';
|
|
4
|
+
import { LOCAL_VM_IMAGE_KEYS } from '../shared/localVm.js';
|
|
5
|
+
export function parseComposeDesktops(value) {
|
|
6
|
+
if (!value?.trim())
|
|
7
|
+
return [];
|
|
8
|
+
let input;
|
|
9
|
+
try {
|
|
10
|
+
input = JSON.parse(value);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
throw new Error('HERMES_YAOYAO_COMPOSE_DESKTOPS 必须为有效 JSON');
|
|
14
|
+
}
|
|
15
|
+
const parsed = z.array(z.object({ id: z.string().uuid(), name: z.string().trim().min(1).max(100), socketPath: z.string().regex(/^\/run\/yaoyao-desktops\/[a-z0-9_-]+\/desktop\.sock$/), networkSocketPath: z.string().regex(/^\/run\/yaoyao-networks\/[a-z0-9_-]+\/gateway\.sock$/).optional(), imageKey: z.enum(LOCAL_VM_IMAGE_KEYS).optional() }).strict()).min(1).max(32).parse(input);
|
|
16
|
+
if (new Set(parsed.map(x => x.id)).size !== parsed.length || new Set(parsed.map(x => x.socketPath)).size !== parsed.length)
|
|
17
|
+
throw new Error('Compose 桌面 ID 和连接路径不能重复');
|
|
18
|
+
return parsed;
|
|
19
|
+
}
|
|
20
|
+
/** Only deployment-owned Unix sockets are addressable. No Docker daemon access. */
|
|
21
|
+
export class ComposeDesktops {
|
|
22
|
+
desktops;
|
|
23
|
+
constructor(desktops) {
|
|
24
|
+
this.desktops = desktops;
|
|
25
|
+
}
|
|
26
|
+
async call(id, operation, body = {}) {
|
|
27
|
+
const desktop = this.desktops.find(x => x.id === id);
|
|
28
|
+
if (!desktop)
|
|
29
|
+
throw new HttpError(404, '该桌面不在 Compose 配置中', 'compose_desktop_missing');
|
|
30
|
+
if (!['health', 'frame', 'acquire', 'renew', 'release', 'execute', 'cancel', 'skills-install', 'network-open', 'network-exchange', 'network-close', 'network-health'].includes(operation))
|
|
31
|
+
throw new HttpError(409, 'Compose 管理桌面数量和生命周期', 'compose_desktop_managed');
|
|
32
|
+
const socketPath = operation.startsWith('network-') ? desktop.networkSocketPath : desktop.socketPath;
|
|
33
|
+
if (!socketPath)
|
|
34
|
+
throw new HttpError(409, '请更新 Compose 配置以启用统一网络出口', 'computer_network_upgrade_required');
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const data = JSON.stringify({ ...body, desktopId: id }), req = request({ socketPath, path: `/${operation}`, method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) }, timeout: 70000 }, res => {
|
|
37
|
+
const chunks = [];
|
|
38
|
+
let size = 0;
|
|
39
|
+
res.on('data', chunk => { size += chunk.length; if (size > 40 * 1024 * 1024)
|
|
40
|
+
req.destroy(new Error('桌面回应过大'));
|
|
41
|
+
else
|
|
42
|
+
chunks.push(chunk); });
|
|
43
|
+
res.on('end', () => { try {
|
|
44
|
+
if (res.headers['x-yaoyao-desktop-id'] !== id)
|
|
45
|
+
throw new HttpError(502, 'Compose 桌面连接身份不匹配', 'compose_desktop_mismatch');
|
|
46
|
+
const value = JSON.parse(Buffer.concat(chunks).toString());
|
|
47
|
+
if (res.statusCode !== 200)
|
|
48
|
+
throw new HttpError(res.statusCode ?? 502, value.error || '桌面操作失败', value.code || 'compose_desktop_error');
|
|
49
|
+
resolve(value);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
reject(error);
|
|
53
|
+
} });
|
|
54
|
+
});
|
|
55
|
+
req.on('timeout', () => req.destroy(new Error('桌面回应超时')));
|
|
56
|
+
req.on('error', () => reject(new HttpError(503, `无法连接「${desktop.name}」,请检查对应 Compose 桌面容器`, 'compose_desktop_offline')));
|
|
57
|
+
req.end(data);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async status() { return Promise.all(this.desktops.map(async (d) => { try {
|
|
61
|
+
const state = await this.call(d.id, 'health');
|
|
62
|
+
if (state.id !== d.id || state.protocol !== 1)
|
|
63
|
+
throw new Error('身份不匹配');
|
|
64
|
+
return { id: d.id, name: d.name, imageKey: d.imageKey, online: true, ready: state.ready === true };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return { id: d.id, name: d.name, imageKey: d.imageKey, online: false, ready: false };
|
|
68
|
+
} })); }
|
|
69
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { randomBytes, randomUUID, createHash, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import Router from '@koa/router';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { readHostTools } from './hostToolSettings.js';
|
|
5
|
+
import { HttpError } from './errors.js';
|
|
6
|
+
import { parse } from './workspaceStore.js';
|
|
7
|
+
const hash = (value) => createHash('sha256').update(value).digest();
|
|
8
|
+
export class ComputerControlService {
|
|
9
|
+
store;
|
|
10
|
+
auth;
|
|
11
|
+
nodes;
|
|
12
|
+
hub;
|
|
13
|
+
constructor(store, auth, nodes, hub) {
|
|
14
|
+
this.store = store;
|
|
15
|
+
this.auth = auth;
|
|
16
|
+
this.nodes = nodes;
|
|
17
|
+
this.hub = hub;
|
|
18
|
+
}
|
|
19
|
+
agent(owner, id) {
|
|
20
|
+
const agent = this.store.require(owner, 'agent', id);
|
|
21
|
+
if (agent.archived || !readHostTools(this.store.home).vm || agent.remoteAgentId)
|
|
22
|
+
throw new HttpError(409, '该机器人没有可用的隔离电脑', 'computer_unavailable');
|
|
23
|
+
this.nodes.requireSource(owner, agent);
|
|
24
|
+
return agent;
|
|
25
|
+
}
|
|
26
|
+
allowed(id, runnerId) {
|
|
27
|
+
const grant = this.store.get('_system', 'computer-control', id);
|
|
28
|
+
if (!grant || grant.runnerId !== runnerId || grant.expiresAt <= Date.now() || this.auth.pushAuthorizationVersion(grant.owner) !== grant.authVersion)
|
|
29
|
+
return false;
|
|
30
|
+
try {
|
|
31
|
+
const agent = this.agent(grant.owner, grant.agentId);
|
|
32
|
+
return (agent.computerEnvironmentId ?? agent.id) === (grant.environmentId ?? grant.agentId);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
token(owner, agentId, body) {
|
|
39
|
+
const input = parse(z.object({ controlId: z.string().uuid(), token: z.string().min(32).max(256) }).passthrough(), body);
|
|
40
|
+
const grant = this.store.get('_system', 'computer-control', input.controlId);
|
|
41
|
+
if (!grant || grant.owner !== owner || grant.agentId !== agentId || !timingSafeEqual(Buffer.from(grant.tokenHash, 'hex'), hash(input.token)))
|
|
42
|
+
throw new HttpError(403, '需要当前电脑的控制凭据', 'computer_control_forbidden');
|
|
43
|
+
if (!this.allowed(grant.id, grant.runnerId))
|
|
44
|
+
throw new HttpError(410, '电脑控制权已过期', 'computer_control_expired');
|
|
45
|
+
return grant;
|
|
46
|
+
}
|
|
47
|
+
router() {
|
|
48
|
+
const router = new Router();
|
|
49
|
+
router.get('/api/app/computers', ctx => {
|
|
50
|
+
const actor = this.auth.require(ctx), agents = this.store.list(actor.id, 'agent').filter(agent => !agent.archived);
|
|
51
|
+
ctx.body = { canManageLocalVm: actor.role === 'admin', computers: agents.map(agent => {
|
|
52
|
+
let available = false, reason = '全局设置未开放虚拟环境';
|
|
53
|
+
if (readHostTools(this.store.home).vm)
|
|
54
|
+
try {
|
|
55
|
+
this.nodes.requireSource(actor.id, agent);
|
|
56
|
+
const record = this.hub.computerRunner(actor.id, agent), features = this.hub.summary(record).features;
|
|
57
|
+
if (features.includes('local-vm-v1') && !features.includes('image-ready-v1'))
|
|
58
|
+
throw new Error('请先在应用设置的本地虚拟机页面完成准备');
|
|
59
|
+
available = true;
|
|
60
|
+
reason = '可以打开电脑面板';
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
reason = error instanceof Error ? error.message : '电脑不可用';
|
|
64
|
+
}
|
|
65
|
+
return { agent, available, reason };
|
|
66
|
+
}) };
|
|
67
|
+
});
|
|
68
|
+
router.get('/api/app/agents/:id/computer', async (ctx, next) => {
|
|
69
|
+
if (typeof ctx.query.backend === 'string' && ctx.query.backend !== 'vm')
|
|
70
|
+
return next();
|
|
71
|
+
const owner = this.auth.require(ctx).id, agent = this.agent(owner, ctx.params.id);
|
|
72
|
+
ctx.body = await this.hub.computer(owner, agent, 'status', {}, () => { this.agent(owner, agent.id); });
|
|
73
|
+
});
|
|
74
|
+
router.get('/api/app/agents/:id/computer/frame', async (ctx, next) => {
|
|
75
|
+
if (typeof ctx.query.backend === 'string' && ctx.query.backend !== 'vm')
|
|
76
|
+
return next();
|
|
77
|
+
const owner = this.auth.require(ctx).id, agent = this.agent(owner, ctx.params.id);
|
|
78
|
+
ctx.set('Cache-Control', 'no-store');
|
|
79
|
+
ctx.body = await this.hub.computer(owner, agent, 'frame', {}, () => { this.agent(owner, agent.id); });
|
|
80
|
+
});
|
|
81
|
+
router.post('/api/app/agents/:id/computer/take', async (ctx, next) => {
|
|
82
|
+
if (typeof ctx.query.backend === 'string' && ctx.query.backend !== 'vm')
|
|
83
|
+
return next();
|
|
84
|
+
const owner = this.auth.require(ctx).id, agent = this.agent(owner, ctx.params.id), input = parse(z.object({ requestId: z.string().uuid() }).strict(), ctx.request.body);
|
|
85
|
+
const old = this.store.list('_system', 'computer-control').find(grant => grant.owner === owner && (grant.environmentId ?? grant.agentId) === (agent.computerEnvironmentId ?? agent.id) && grant.expiresAt > Date.now() && this.allowed(grant.id, grant.runnerId));
|
|
86
|
+
if (old && (old.agentId !== agent.id || old.requestId !== input.requestId))
|
|
87
|
+
throw new HttpError(409, '电脑已由另一个页面控制,关闭原页面或等待控制权到期', 'computer_control_busy');
|
|
88
|
+
const runnerId = this.hub.computerRunner(owner, agent).id;
|
|
89
|
+
const token = old ? this.nodes.open(old.sealedToken) : randomBytes(32).toString('base64url');
|
|
90
|
+
const grant = old ?? { environmentId: agent.computerEnvironmentId ?? agent.id, id: randomUUID(), requestId: input.requestId, owner, agentId: agent.id, runnerId, authVersion: this.auth.pushAuthorizationVersion(owner) ?? 0, expiresAt: Date.now() + 30000, tokenHash: hash(token).toString('hex'), sealedToken: this.nodes.seal(token) };
|
|
91
|
+
this.store.put('_system', 'computer-control', grant.id, grant);
|
|
92
|
+
const status = await this.hub.computer(owner, agent, 'take', { controlId: grant.id }, () => { if (!this.allowed(grant.id, runnerId))
|
|
93
|
+
throw new HttpError(403, '电脑控制请求已失效', 'computer_control_expired'); });
|
|
94
|
+
ctx.body = { ...status, controlId: grant.id, token, expiresAt: grant.expiresAt };
|
|
95
|
+
});
|
|
96
|
+
router.post('/api/app/agents/:id/computer/renew', (ctx, next) => {
|
|
97
|
+
if (typeof ctx.query.backend === 'string' && ctx.query.backend !== 'vm')
|
|
98
|
+
return next();
|
|
99
|
+
const owner = this.auth.require(ctx).id, grant = this.token(owner, ctx.params.id, ctx.request.body);
|
|
100
|
+
grant.expiresAt = Date.now() + 30000;
|
|
101
|
+
this.store.put('_system', 'computer-control', grant.id, grant);
|
|
102
|
+
ctx.body = { expiresAt: grant.expiresAt };
|
|
103
|
+
});
|
|
104
|
+
router.post('/api/app/agents/:id/computer/input', async (ctx, next) => {
|
|
105
|
+
if (typeof ctx.query.backend === 'string' && ctx.query.backend !== 'vm')
|
|
106
|
+
return next();
|
|
107
|
+
const owner = this.auth.require(ctx).id, agent = this.agent(owner, ctx.params.id), input = parse(z.object({ controlId: z.string().uuid(), token: z.string(), requestId: z.string().uuid(), generation: z.number().int().nonnegative(), frameId: z.string().uuid(), action: z.record(z.string(), z.unknown()) }).strict(), ctx.request.body);
|
|
108
|
+
const grant = this.token(owner, agent.id, input);
|
|
109
|
+
ctx.body = await this.hub.computer(owner, agent, 'input', { controlId: grant.id, requestId: input.requestId, generation: input.generation, frameId: input.frameId, action: input.action }, () => { this.token(owner, agent.id, input); });
|
|
110
|
+
});
|
|
111
|
+
router.post('/api/app/agents/:id/computer/giveback', async (ctx, next) => {
|
|
112
|
+
if (typeof ctx.query.backend === 'string' && ctx.query.backend !== 'vm')
|
|
113
|
+
return next();
|
|
114
|
+
const owner = this.auth.require(ctx).id, agent = this.agent(owner, ctx.params.id), input = parse(z.object({ controlId: z.string().uuid(), token: z.string(), notes: z.string().max(4000).default('') }).strict(), ctx.request.body);
|
|
115
|
+
const grant = this.token(owner, agent.id, input);
|
|
116
|
+
ctx.body = await this.hub.computer(owner, agent, 'giveback', { controlId: grant.id, notes: input.notes }, () => { this.token(owner, agent.id, input); });
|
|
117
|
+
grant.expiresAt = 0;
|
|
118
|
+
this.store.put('_system', 'computer-control', grant.id, grant);
|
|
119
|
+
});
|
|
120
|
+
return router;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { HttpError } from './errors.js';
|
|
5
|
+
const pathOf = (home) => join(home, 'computer-names.json');
|
|
6
|
+
const idOk = (id) => id === 'local' || /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(id);
|
|
7
|
+
export function readComputerNames(home) {
|
|
8
|
+
const path = pathOf(home);
|
|
9
|
+
if (!existsSync(path))
|
|
10
|
+
return {};
|
|
11
|
+
try {
|
|
12
|
+
const value = JSON.parse(readFileSync(path, 'utf8'));
|
|
13
|
+
const names = {};
|
|
14
|
+
for (const [id, name] of Object.entries(value?.names ?? {})) {
|
|
15
|
+
if (idOk(id) && typeof name === 'string' && name.trim())
|
|
16
|
+
names[id] = name.trim().slice(0, 64);
|
|
17
|
+
}
|
|
18
|
+
return names;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function saveComputerName(home, id, name) {
|
|
25
|
+
if (!idOk(id))
|
|
26
|
+
throw new HttpError(400, '这台电脑不能改名', 'computer_unknown');
|
|
27
|
+
const trimmed = name.trim();
|
|
28
|
+
if (trimmed.length > 64)
|
|
29
|
+
throw new HttpError(400, '名字最长 64 个字', 'computer_name_invalid');
|
|
30
|
+
const names = readComputerNames(home);
|
|
31
|
+
if (trimmed)
|
|
32
|
+
names[id] = trimmed;
|
|
33
|
+
else
|
|
34
|
+
delete names[id];
|
|
35
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
36
|
+
const path = pathOf(home);
|
|
37
|
+
const temporary = path + '.' + randomUUID();
|
|
38
|
+
writeFileSync(temporary, JSON.stringify({ names }, null, 2) + '\n', { mode: 0o600 });
|
|
39
|
+
renameSync(temporary, path);
|
|
40
|
+
return names;
|
|
41
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { isIP } from 'node:net';
|
|
2
|
+
import { normalizeReleaseSource } from '../../bin/lib/release-source.mjs';
|
|
3
|
+
import { resolveDataHome } from '../../bin/lib/data-home.mjs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { basename, resolve, isAbsolute } from 'node:path';
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { loadAPNsConfiguration } from './apnsConfiguration.js';
|
|
8
|
+
import { loadFCMConfiguration } from './fcmConfiguration.js';
|
|
9
|
+
import { loadAllowedHostsConfiguration, } from './allowedHostsConfiguration.js';
|
|
10
|
+
import { parseComposeDesktops } from './composeDesktops.js';
|
|
11
|
+
export { DEFAULT_APNS_TOPIC } from './apnsConfiguration.js';
|
|
12
|
+
export { DEFAULT_RELEASE_SOURCE as DEFAULT_YAOYAO_RELEASE_SOURCE } from '../../bin/lib/release-source.mjs';
|
|
13
|
+
function flag(value) {
|
|
14
|
+
return value === '1' || value?.toLowerCase() === 'true';
|
|
15
|
+
}
|
|
16
|
+
function parsePort(value) {
|
|
17
|
+
const port = Number(value ?? '15300');
|
|
18
|
+
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
|
|
19
|
+
throw new Error('HERMES_YAOYAO_PORT must be an integer between 1 and 65535');
|
|
20
|
+
}
|
|
21
|
+
return port;
|
|
22
|
+
}
|
|
23
|
+
function parseChatCacheMode(value) {
|
|
24
|
+
const mode = value?.trim() || 'prefer-local';
|
|
25
|
+
if (!['upstream-only', 'shadow', 'prefer-local'].includes(mode)) {
|
|
26
|
+
throw new Error('HERMES_YAOYAO_CHAT_CACHE_MODE must be upstream-only, shadow, or prefer-local');
|
|
27
|
+
}
|
|
28
|
+
return mode;
|
|
29
|
+
}
|
|
30
|
+
function parseUpstream(value) {
|
|
31
|
+
const upstream = new URL(value ?? 'http://127.0.0.1:9119');
|
|
32
|
+
if (!['http:', 'https:'].includes(upstream.protocol)) {
|
|
33
|
+
throw new Error('HERMES_YAOYAO_UPSTREAM must use http or https');
|
|
34
|
+
}
|
|
35
|
+
if (upstream.username || upstream.password || upstream.search || upstream.hash) {
|
|
36
|
+
throw new Error('HERMES_YAOYAO_UPSTREAM must not contain credentials, query, or fragment');
|
|
37
|
+
}
|
|
38
|
+
upstream.pathname = upstream.pathname.replace(/\/+$/, '') || '/';
|
|
39
|
+
return upstream;
|
|
40
|
+
}
|
|
41
|
+
function parseReleaseSource(value) {
|
|
42
|
+
const source = normalizeReleaseSource(value);
|
|
43
|
+
if (source.length > 2_048 || /[\u0000-\u001f\u007f]/.test(source)) {
|
|
44
|
+
throw new Error('HERMES_YAOYAO_RELEASE_SOURCE is invalid');
|
|
45
|
+
}
|
|
46
|
+
if (source.startsWith('https://') || source.startsWith('ssh://')) {
|
|
47
|
+
const url = new URL(source);
|
|
48
|
+
if ((url.protocol === 'https:' && url.username) || url.password || url.search || url.hash) {
|
|
49
|
+
throw new Error('HERMES_YAOYAO_RELEASE_SOURCE must not contain credentials, query, or fragment');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (!source.startsWith('git@') && !source.startsWith('ssh://')) {
|
|
53
|
+
throw new Error('HERMES_YAOYAO_RELEASE_SOURCE must be an HTTPS or SSH Git source');
|
|
54
|
+
}
|
|
55
|
+
return source;
|
|
56
|
+
}
|
|
57
|
+
function normalizeConfiguredHost(raw) {
|
|
58
|
+
const value = raw.trim().toLowerCase();
|
|
59
|
+
if (!value)
|
|
60
|
+
return '';
|
|
61
|
+
if (value.startsWith('[') && value.endsWith(']'))
|
|
62
|
+
return value.slice(1, -1);
|
|
63
|
+
return value.replace(/\.$/, '');
|
|
64
|
+
}
|
|
65
|
+
export function isLoopbackHost(host) {
|
|
66
|
+
const normalized = normalizeConfiguredHost(host);
|
|
67
|
+
if (normalized === 'localhost' || normalized === '::1')
|
|
68
|
+
return true;
|
|
69
|
+
if (isIP(normalized) === 4)
|
|
70
|
+
return normalized.split('.')[0] === '127';
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
export function isPrivateHost(host) {
|
|
74
|
+
const normalized = normalizeConfiguredHost(host);
|
|
75
|
+
if (isLoopbackHost(normalized))
|
|
76
|
+
return true;
|
|
77
|
+
if (isIP(normalized) === 4) {
|
|
78
|
+
const parts = normalized.split('.').map(Number);
|
|
79
|
+
return parts[0] === 10
|
|
80
|
+
|| (parts[0] === 100 && parts[1] >= 64 && parts[1] <= 127)
|
|
81
|
+
|| (parts[0] === 169 && parts[1] === 254)
|
|
82
|
+
|| (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31)
|
|
83
|
+
|| (parts[0] === 192 && parts[1] === 168);
|
|
84
|
+
}
|
|
85
|
+
if (isIP(normalized) === 6) {
|
|
86
|
+
return normalized.startsWith('fc')
|
|
87
|
+
|| normalized.startsWith('fd')
|
|
88
|
+
|| /^fe[89ab]/.test(normalized);
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
export function isLoopbackUpstream(upstream) {
|
|
93
|
+
return isLoopbackHost(upstream.hostname);
|
|
94
|
+
}
|
|
95
|
+
export function loadServerConfig(env = process.env) {
|
|
96
|
+
const host = env.HERMES_YAOYAO_HOST?.trim() || '127.0.0.1';
|
|
97
|
+
const port = parsePort(env.HERMES_YAOYAO_PORT);
|
|
98
|
+
const upstream = parseUpstream(env.HERMES_YAOYAO_UPSTREAM);
|
|
99
|
+
const home = resolveDataHome(env.YAOYAO_HOME || env.HERMES_YAOYAO_HOME, { preserveActiveUpdate: true });
|
|
100
|
+
const mediaRoot = resolve(env.HERMES_YAOYAO_MEDIA_ROOT?.trim() || `${homedir()}/Agents`);
|
|
101
|
+
const attachmentsRoot = resolve(`${homedir()}/.hermes/attachments`);
|
|
102
|
+
const imagesRoot = resolve(`${homedir()}/.hermes/images`);
|
|
103
|
+
const tlsCert = env.HERMES_YAOYAO_TLS_CERT?.trim() || undefined;
|
|
104
|
+
const tlsKey = env.HERMES_YAOYAO_TLS_KEY?.trim() || undefined;
|
|
105
|
+
if (Boolean(tlsCert) !== Boolean(tlsKey)) {
|
|
106
|
+
throw new Error('HERMES_YAOYAO_TLS_CERT and HERMES_YAOYAO_TLS_KEY must be set together');
|
|
107
|
+
}
|
|
108
|
+
const allowInsecureLan = flag(env.HERMES_YAOYAO_ALLOW_INSECURE_LAN);
|
|
109
|
+
const production = env.NODE_ENV === 'production';
|
|
110
|
+
const superviseDashboard = flag(env.HERMES_YAOYAO_SUPERVISE_DASHBOARD);
|
|
111
|
+
const localVmHost = env.HERMES_YAOYAO_LOCAL_VM_HOST?.trim() || 'server';
|
|
112
|
+
if (localVmHost !== 'server' && localVmHost !== 'runner')
|
|
113
|
+
throw new Error('HERMES_YAOYAO_LOCAL_VM_HOST must be server or runner');
|
|
114
|
+
let hermesBridgeMount;
|
|
115
|
+
if (flag(env.HERMES_YAOYAO_BRIDGE_MOUNTED)) {
|
|
116
|
+
const home = env.HERMES_YAOYAO_BRIDGE_HOME?.trim() ?? '';
|
|
117
|
+
const python = env.HERMES_YAOYAO_BRIDGE_PYTHON?.trim() || '/usr/bin/python3';
|
|
118
|
+
if (!home || !isAbsolute(home) || /[\0\r\n]/.test(home))
|
|
119
|
+
throw new Error('HERMES_YAOYAO_BRIDGE_HOME must be an absolute mounted Hermes directory');
|
|
120
|
+
if (!isAbsolute(python) || /[\0\r\n]/.test(python))
|
|
121
|
+
throw new Error('HERMES_YAOYAO_BRIDGE_PYTHON must be an absolute container Python path');
|
|
122
|
+
hermesBridgeMount = { home: resolve(home), python };
|
|
123
|
+
}
|
|
124
|
+
const chatCacheMode = parseChatCacheMode(env.HERMES_YAOYAO_CHAT_CACHE_MODE);
|
|
125
|
+
const releaseSource = parseReleaseSource(env.HERMES_YAOYAO_RELEASE_SOURCE);
|
|
126
|
+
const releaseRoot = resolve(env.HERMES_YAOYAO_RELEASE_ROOT?.trim() || `${homedir()}/.local/share/hermes-yaoyao`);
|
|
127
|
+
const allowRemoteUpdate = flag(env.HERMES_YAOYAO_ALLOW_REMOTE_UPDATE);
|
|
128
|
+
const upstreamUsername = env.HERMES_YAOYAO_UPSTREAM_USERNAME?.trim() || undefined;
|
|
129
|
+
const upstreamPasswordFile = env.HERMES_YAOYAO_UPSTREAM_PASSWORD_FILE?.trim();
|
|
130
|
+
if (env.HERMES_YAOYAO_UPSTREAM_PASSWORD && upstreamPasswordFile) {
|
|
131
|
+
throw new Error('Set only one of HERMES_YAOYAO_UPSTREAM_PASSWORD or HERMES_YAOYAO_UPSTREAM_PASSWORD_FILE');
|
|
132
|
+
}
|
|
133
|
+
const upstreamPassword = env.HERMES_YAOYAO_UPSTREAM_PASSWORD
|
|
134
|
+
|| (upstreamPasswordFile ? readFileSync(resolve(upstreamPasswordFile), 'utf8').replace(/[\r\n]+$/, '') : undefined);
|
|
135
|
+
const apnsSettings = loadAPNsConfiguration(home, env);
|
|
136
|
+
const fcmSettings = loadFCMConfiguration(home, env);
|
|
137
|
+
const insecureLan = !tlsCert && !isLoopbackHost(host);
|
|
138
|
+
if (production && insecureLan && !allowInsecureLan) {
|
|
139
|
+
throw new Error('Plain HTTP on a non-loopback host requires HERMES_YAOYAO_ALLOW_INSECURE_LAN=1');
|
|
140
|
+
}
|
|
141
|
+
const allowedHostsSettings = loadAllowedHostsConfiguration(home, env);
|
|
142
|
+
const allowedHosts = new Set(allowedHostsSettings.hosts);
|
|
143
|
+
return {
|
|
144
|
+
host,
|
|
145
|
+
port,
|
|
146
|
+
upstream,
|
|
147
|
+
allowedHosts,
|
|
148
|
+
allowedHostsSettings,
|
|
149
|
+
home,
|
|
150
|
+
mediaRoot,
|
|
151
|
+
attachmentsRoot,
|
|
152
|
+
imagesRoot,
|
|
153
|
+
mediaOwner: basename(homedir()),
|
|
154
|
+
tlsCert,
|
|
155
|
+
tlsKey,
|
|
156
|
+
allowInsecureLan,
|
|
157
|
+
insecureLan,
|
|
158
|
+
production,
|
|
159
|
+
superviseDashboard,
|
|
160
|
+
localVmHost,
|
|
161
|
+
...(hermesBridgeMount ? { hermesBridgeMount } : {}),
|
|
162
|
+
composeDesktops: parseComposeDesktops(env.HERMES_YAOYAO_COMPOSE_DESKTOPS),
|
|
163
|
+
chatCacheMode,
|
|
164
|
+
releaseSource,
|
|
165
|
+
releaseRoot,
|
|
166
|
+
allowRemoteUpdate,
|
|
167
|
+
upstreamUsername,
|
|
168
|
+
upstreamPassword,
|
|
169
|
+
...(apnsSettings.config ? { apns: apnsSettings.config } : {}),
|
|
170
|
+
...(apnsSettings.configurationError ? { apnsConfigurationError: apnsSettings.configurationError } : {}),
|
|
171
|
+
apnsSettings,
|
|
172
|
+
...(fcmSettings.config ? { fcm: fcmSettings.config } : {}),
|
|
173
|
+
...(fcmSettings.configurationError ? { fcmConfigurationError: fcmSettings.configurationError } : {}),
|
|
174
|
+
fcmSettings,
|
|
175
|
+
};
|
|
176
|
+
}
|