@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,109 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { HttpError } from './errors.js';
|
|
4
|
+
import { parse } from './workspaceStore.js';
|
|
5
|
+
import { routineScheduleSchema, routineWriteSchema } from './workspaceRoutines.js';
|
|
6
|
+
const uuid = z.string().uuid();
|
|
7
|
+
const empty = z.object({}).strict();
|
|
8
|
+
const createInput = routineWriteSchema.omit({ deviceHost: true }).extend({ requestId: uuid }).strict();
|
|
9
|
+
const updateInput = z.object({
|
|
10
|
+
requestId: uuid,
|
|
11
|
+
routineId: uuid,
|
|
12
|
+
name: z.string().trim().min(1).max(100).optional(),
|
|
13
|
+
prompt: z.string().trim().min(1).max(24000).optional(),
|
|
14
|
+
enabled: z.boolean().optional(),
|
|
15
|
+
schedule: routineScheduleSchema.optional(),
|
|
16
|
+
}).strict();
|
|
17
|
+
const deleteInput = z.object({ requestId: uuid, routineId: uuid }).strict();
|
|
18
|
+
const definitions = [
|
|
19
|
+
['workspace_list_routines', '列出当前 Bot 自己的定时任务。到点后在该 Bot 的单聊中执行,不会在群聊里自动发言。', empty],
|
|
20
|
+
['workspace_create_routine', '为当前 Bot 新建定时任务。用户要求定时、提醒或周期执行时使用。name 是任务名称,prompt 是到点后要执行的内容。schedule.kind 为 once、interval、daily 或 weekly。once 需要未来的 at(毫秒时间戳);interval 需要 everyMinutes;daily 需要 time(HH:mm)和 timezone;weekly 还需要 weekdays(0 为周日,6 为周六)。requestId 使用新的 UUID,重试同一操作必须复用。不要使用 Hermes cron。', createInput],
|
|
21
|
+
['workspace_update_routine', '修改当前 Bot 已有的定时任务,可改名称、内容、是否启用或日程。暂停时设 enabled 为 false。requestId 对同一次修改保持不变。', updateInput],
|
|
22
|
+
['workspace_delete_routine', '删除当前 Bot 的一个定时任务。requestId 对同一次删除保持不变。', deleteInput],
|
|
23
|
+
];
|
|
24
|
+
export const ROUTINE_TOOL_RULES = '用户要求定时、提醒或周期执行时,使用 workspace_list_routines、workspace_create_routine、workspace_update_routine、workspace_delete_routine 管理当前 Bot 自己的定时任务。不要调用 Hermes 的 cronjob、cron 或其他 cron 工具。任务只属于当前 Bot,到点后在它的单聊中发送任务内容,不会在群聊里自动发言。新建和修改都要给出完整日程:once 用未来的 at,interval 用 everyMinutes,daily 用 timezone 和 time,weekly 再加 weekdays。requestId 使用新的 UUID,重试同一操作必须复用,不要因此创建重复任务。临时助手、已归档和远端机器人不能建立定时任务。';
|
|
25
|
+
/** The speaking Bot is taken from the server turn. The model cannot name another agent. */
|
|
26
|
+
export class WorkspaceRoutineTools {
|
|
27
|
+
routines;
|
|
28
|
+
store;
|
|
29
|
+
nodes;
|
|
30
|
+
runtime;
|
|
31
|
+
constructor(routines, store, nodes, runtime) {
|
|
32
|
+
this.routines = routines;
|
|
33
|
+
this.store = store;
|
|
34
|
+
this.nodes = nodes;
|
|
35
|
+
this.runtime = runtime;
|
|
36
|
+
}
|
|
37
|
+
handles(toolId) {
|
|
38
|
+
return definitions.some(([id]) => id === toolId);
|
|
39
|
+
}
|
|
40
|
+
turn(owner, workId) {
|
|
41
|
+
if (!this.runtime.userActive(owner))
|
|
42
|
+
throw new HttpError(403, '账号授权已失效', 'routine_tools_forbidden');
|
|
43
|
+
const work = this.store.require(owner, 'turn', workId);
|
|
44
|
+
const agent = this.store.require(owner, 'agent', work.agentId);
|
|
45
|
+
const conversation = this.store.require(owner, 'conversation', work.conversationId);
|
|
46
|
+
const root = this.store.require(owner, 'run', work.runId);
|
|
47
|
+
if (conversation.archived || !conversation.memberIds.includes(agent.id) || work.cancelRequested || root.stopRequested || !['running', 'waiting'].includes(work.status))
|
|
48
|
+
throw new HttpError(403, '当前机器人的本轮授权已失效', 'routine_tools_forbidden');
|
|
49
|
+
if (root.authorizationVersion !== undefined && root.authorizationVersion !== this.runtime.authorizationVersion(owner))
|
|
50
|
+
throw new HttpError(403, '当前机器人的本轮授权已失效', 'routine_tools_forbidden');
|
|
51
|
+
this.routines.requireSchedulable(owner, agent.id);
|
|
52
|
+
return { agent, work };
|
|
53
|
+
}
|
|
54
|
+
catalog(owner, workId) {
|
|
55
|
+
this.turn(owner, workId);
|
|
56
|
+
return definitions.map(([id, description, schema]) => ({ id, name: id, description, inputSchema: z.toJSONSchema(schema) }));
|
|
57
|
+
}
|
|
58
|
+
own(owner, agentId, routineId) {
|
|
59
|
+
const routine = this.store.require(owner, 'routine', routineId);
|
|
60
|
+
if (routine.agentId !== agentId)
|
|
61
|
+
throw new HttpError(404, '定时任务不存在', 'not_found');
|
|
62
|
+
return routine;
|
|
63
|
+
}
|
|
64
|
+
view(routine) {
|
|
65
|
+
return { id: routine.id, name: routine.name, prompt: routine.prompt, enabled: routine.enabled, schedule: routine.schedule, nextAt: routine.nextAt, lastAt: routine.lastAt };
|
|
66
|
+
}
|
|
67
|
+
call(owner, workId, toolId, input) {
|
|
68
|
+
const { agent } = this.turn(owner, workId);
|
|
69
|
+
if (toolId === 'workspace_list_routines') {
|
|
70
|
+
parse(empty, input);
|
|
71
|
+
return { delivery: '到点后在该 Bot 的单聊中执行', routines: this.store.list(owner, 'routine').filter(routine => routine.agentId === agent.id).map(routine => this.view(routine)) };
|
|
72
|
+
}
|
|
73
|
+
if (toolId === 'workspace_create_routine') {
|
|
74
|
+
const { requestId, ...body } = parse(createInput, input);
|
|
75
|
+
return this.store.command(owner, requestId, { agentId: agent.id, toolId, body }, () => {
|
|
76
|
+
this.turn(owner, workId);
|
|
77
|
+
return { routine: this.view(this.routines.save(owner, agent.id, body, randomUUID())) };
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (toolId === 'workspace_update_routine') {
|
|
81
|
+
const { requestId, routineId, ...patch } = parse(updateInput, input);
|
|
82
|
+
if (patch.name === undefined && patch.prompt === undefined && patch.enabled === undefined && patch.schedule === undefined)
|
|
83
|
+
throw new HttpError(400, '请提供要修改的内容', 'routine_patch_empty');
|
|
84
|
+
this.own(owner, agent.id, routineId);
|
|
85
|
+
return this.store.command(owner, requestId, { agentId: agent.id, toolId, routineId, patch }, () => {
|
|
86
|
+
this.turn(owner, workId);
|
|
87
|
+
const latest = this.own(owner, agent.id, routineId);
|
|
88
|
+
return { routine: this.view(this.routines.save(owner, agent.id, {
|
|
89
|
+
name: patch.name ?? latest.name,
|
|
90
|
+
prompt: patch.prompt ?? latest.prompt,
|
|
91
|
+
enabled: patch.enabled ?? latest.enabled,
|
|
92
|
+
schedule: patch.schedule ?? latest.schedule,
|
|
93
|
+
deviceHost: latest.deviceHost,
|
|
94
|
+
}, latest.id)) };
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (toolId === 'workspace_delete_routine') {
|
|
98
|
+
const { requestId, routineId } = parse(deleteInput, input);
|
|
99
|
+
this.own(owner, agent.id, routineId);
|
|
100
|
+
return this.store.command(owner, requestId, { agentId: agent.id, toolId, routineId }, () => {
|
|
101
|
+
this.turn(owner, workId);
|
|
102
|
+
const latest = this.own(owner, agent.id, routineId);
|
|
103
|
+
this.store.remove(owner, 'routine', latest.id);
|
|
104
|
+
return { ok: true, id: latest.id };
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
throw new HttpError(404, '本轮未授权此工具', 'routine_tool_not_found');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { parse } from './workspaceStore.js';
|
|
5
|
+
import { HttpError } from './errors.js';
|
|
6
|
+
const timezone = z.string().max(100).refine(value => { try {
|
|
7
|
+
new Intl.DateTimeFormat('en', { timeZone: value });
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
} }, '时区无效');
|
|
13
|
+
const clock = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/);
|
|
14
|
+
const schedule = z.discriminatedUnion('kind', [
|
|
15
|
+
z.object({ kind: z.literal('once'), timezone, at: z.number().int().positive() }).strict(),
|
|
16
|
+
z.object({ kind: z.literal('interval'), timezone, everyMinutes: z.number().int().min(1).max(525600) }).strict(),
|
|
17
|
+
z.object({ kind: z.literal('daily'), timezone, time: clock }).strict(),
|
|
18
|
+
z.object({ kind: z.literal('weekly'), timezone, time: clock, weekdays: z.array(z.number().int().min(0).max(6)).min(1).max(7) }).strict(),
|
|
19
|
+
]);
|
|
20
|
+
const input = z.object({ name: z.string().trim().min(1).max(100), prompt: z.string().trim().min(1).max(24000), enabled: z.boolean(), deviceHost: z.union([z.literal('local'), z.string().uuid()]).nullish(), schedule }).strict();
|
|
21
|
+
export const routineScheduleSchema = schedule;
|
|
22
|
+
export const routineWriteSchema = input;
|
|
23
|
+
export function nextRoutineAt(s, after) {
|
|
24
|
+
if (s.kind === 'once')
|
|
25
|
+
return s.at > after ? s.at : undefined;
|
|
26
|
+
if (s.kind === 'interval')
|
|
27
|
+
return after + s.everyMinutes * 60000;
|
|
28
|
+
const formatter = new Intl.DateTimeFormat('en-US', { timeZone: s.timezone, hourCycle: 'h23', hour: '2-digit', minute: '2-digit', weekday: 'short' });
|
|
29
|
+
for (let at = Math.floor(after / 60000) * 60000 + 60000; at <= after + 8 * 86400000; at += 60000) {
|
|
30
|
+
const parts = Object.fromEntries(formatter.formatToParts(at).map(p => [p.type, p.value]));
|
|
31
|
+
if (`${parts.hour}:${parts.minute}` === s.time && (s.kind === 'daily' || s.weekdays.includes(['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].indexOf(parts.weekday))))
|
|
32
|
+
return at;
|
|
33
|
+
}
|
|
34
|
+
throw new HttpError(400, '无法计算下次执行时间', 'routine_schedule_invalid');
|
|
35
|
+
}
|
|
36
|
+
const terminal = (status) => ['complete', 'failed', 'interrupted', 'skipped'].includes(status);
|
|
37
|
+
export class WorkspaceRoutines {
|
|
38
|
+
store;
|
|
39
|
+
auth;
|
|
40
|
+
nodes;
|
|
41
|
+
runtime;
|
|
42
|
+
paused = () => false;
|
|
43
|
+
timer;
|
|
44
|
+
ticking = false;
|
|
45
|
+
closed = false;
|
|
46
|
+
constructor(store, auth, nodes, runtime) {
|
|
47
|
+
this.store = store;
|
|
48
|
+
this.auth = auth;
|
|
49
|
+
this.nodes = nodes;
|
|
50
|
+
this.runtime = runtime;
|
|
51
|
+
}
|
|
52
|
+
agent(owner, id) { const agent = this.store.require(owner, 'agent', id); if (agent.archived || agent.temporaryGoalId || agent.remoteAgentId)
|
|
53
|
+
throw new HttpError(409, '此机器人不能建立定时任务', 'routine_agent_unavailable'); this.nodes.requireSource(owner, agent); return agent; }
|
|
54
|
+
requireSchedulable(owner, id) { return this.agent(owner, id); }
|
|
55
|
+
save(owner, agentId, body, id = randomUUID()) {
|
|
56
|
+
this.agent(owner, agentId);
|
|
57
|
+
const value = parse(input, body), old = this.store.get(owner, 'routine', id);
|
|
58
|
+
if (old && old.agentId !== agentId)
|
|
59
|
+
throw new HttpError(404, '定时任务不存在', 'not_found');
|
|
60
|
+
const now = Date.now(), unchanged = !!old && old.enabled === value.enabled && JSON.stringify(parse(schedule, old.schedule)) === JSON.stringify(value.schedule), nextAt = unchanged ? old.nextAt : value.enabled ? nextRoutineAt(value.schedule, now) : undefined;
|
|
61
|
+
if (value.enabled && !nextAt)
|
|
62
|
+
throw new HttpError(400, '请选择未来的执行时间', 'routine_time_invalid');
|
|
63
|
+
const routine = { ...value, deviceHost: value.deviceHost === undefined ? old?.deviceHost : value.deviceHost ?? undefined, id, agentId, nextAt, createdAt: old?.createdAt ?? now, updatedAt: now, lastAt: old?.lastAt };
|
|
64
|
+
this.store.put(owner, 'routine', id, routine);
|
|
65
|
+
this.store.event(owner, 'routine.changed', routine);
|
|
66
|
+
return routine;
|
|
67
|
+
}
|
|
68
|
+
runs(owner, agentId) {
|
|
69
|
+
return this.store.list(owner, 'routine-run').filter(r => r.agentId === agentId).map(r => {
|
|
70
|
+
const run = r.runId ? this.store.get(owner, 'run', r.runId) : undefined;
|
|
71
|
+
return run ? { ...r, status: run.status, error: run.error } : r;
|
|
72
|
+
}).sort((a, b) => b.startedAt - a.startedAt).slice(0, 100);
|
|
73
|
+
}
|
|
74
|
+
run(owner, routine, scheduledAt, requestId = randomUUID()) {
|
|
75
|
+
return this.store.command(owner, requestId, { operation: 'routine.run', routineId: routine.id, scheduledAt }, () => this.store.atomic(() => {
|
|
76
|
+
this.agent(owner, routine.agentId);
|
|
77
|
+
const id = randomUUID(), entry = { id, routineId: routine.id, agentId: routine.agentId, scheduledAt, startedAt: Date.now(), status: 'queued' };
|
|
78
|
+
try {
|
|
79
|
+
if (this.store.list(owner, 'routine-run').some(r => r.routineId === routine.id && !terminal((r.runId ? this.store.get(owner, 'run', r.runId)?.status : undefined) ?? r.status)))
|
|
80
|
+
throw new HttpError(409, '上次定时任务仍在执行,本次已跳过', 'routine_overlap');
|
|
81
|
+
const conversation = this.store.list(owner, 'conversation').find(c => c.kind === 'direct' && !c.archived && c.memberIds[0] === routine.agentId);
|
|
82
|
+
if (!conversation)
|
|
83
|
+
throw new HttpError(409, '机器人的聊天已归档或删除', 'routine_conversation_unavailable');
|
|
84
|
+
const run = this.runtime.send(owner, conversation.id, { requestId: id, content: routine.prompt, deviceHost: routine.deviceHost });
|
|
85
|
+
Object.assign(entry, { runId: run.id, conversationId: conversation.id });
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
entry.status = error instanceof HttpError && error.code === 'routine_overlap' ? 'skipped' : 'failed';
|
|
89
|
+
entry.error = error instanceof Error ? error.message : '定时任务未能启动';
|
|
90
|
+
}
|
|
91
|
+
this.store.put(owner, 'routine-run', id, entry);
|
|
92
|
+
const old = this.store.list(owner, 'routine-run').filter(r => r.agentId === routine.agentId).sort((a, b) => b.startedAt - a.startedAt).slice(100);
|
|
93
|
+
for (const run of old)
|
|
94
|
+
if (terminal(this.store.get(owner, 'run', run.runId ?? '')?.status ?? run.status))
|
|
95
|
+
this.store.remove(owner, 'routine-run', run.id);
|
|
96
|
+
return entry;
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
tick(now = Date.now()) {
|
|
100
|
+
if (this.closed || this.ticking || this.paused())
|
|
101
|
+
return;
|
|
102
|
+
this.ticking = true;
|
|
103
|
+
try {
|
|
104
|
+
for (const owner of this.store.owners())
|
|
105
|
+
for (const routine of this.store.list(owner, 'routine')) {
|
|
106
|
+
if (!routine.enabled || !routine.nextAt || routine.nextAt > now)
|
|
107
|
+
continue;
|
|
108
|
+
this.store.atomic(() => {
|
|
109
|
+
const due = routine.nextAt;
|
|
110
|
+
try {
|
|
111
|
+
if (!this.auth.isUserActive(owner))
|
|
112
|
+
throw new Error('账号当前不可用');
|
|
113
|
+
this.run(owner, routine, due);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const id = randomUUID();
|
|
117
|
+
routine.enabled = false;
|
|
118
|
+
this.store.put(owner, 'routine-run', id, { id, routineId: routine.id, agentId: routine.agentId, scheduledAt: due, startedAt: now, status: 'failed', error: error instanceof Error ? error.message : '定时任务未能启动' });
|
|
119
|
+
}
|
|
120
|
+
routine.lastAt = due;
|
|
121
|
+
routine.nextAt = routine.enabled ? nextRoutineAt(routine.schedule, now) : undefined;
|
|
122
|
+
if (!routine.nextAt)
|
|
123
|
+
routine.enabled = false;
|
|
124
|
+
routine.updatedAt = now;
|
|
125
|
+
this.store.put(owner, 'routine', routine.id, routine);
|
|
126
|
+
this.store.event(owner, 'routine.changed', routine);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
this.ticking = false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
start() { if (this.timer)
|
|
135
|
+
return; this.tick(); this.timer = setInterval(() => this.tick(), 10000); this.timer.unref(); }
|
|
136
|
+
close() { this.closed = true; clearInterval(this.timer); }
|
|
137
|
+
router() {
|
|
138
|
+
const router = new Router();
|
|
139
|
+
router.get('/api/app/bot-tools/automations', ctx => {
|
|
140
|
+
const owner = this.auth.require(ctx).id;
|
|
141
|
+
const agents = this.store.list(owner, 'agent').filter(a => { try {
|
|
142
|
+
this.agent(owner, a.id);
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error instanceof HttpError && [403, 404, 409].includes(error.status))
|
|
147
|
+
return false;
|
|
148
|
+
throw error;
|
|
149
|
+
} });
|
|
150
|
+
const allowed = new Set(agents.map(a => a.id));
|
|
151
|
+
const runs = this.store.list(owner, 'routine-run').filter(r => allowed.has(r.agentId)).sort((a, b) => b.startedAt - a.startedAt).slice(0, 300).map(r => { const run = r.runId ? this.store.get(owner, 'run', r.runId) : undefined; return run ? { ...r, status: run.status, error: run.error } : r; });
|
|
152
|
+
ctx.body = { agents: agents.map(({ id, name, avatar }) => ({ id, name, avatar })), routines: this.store.list(owner, 'routine').filter(r => allowed.has(r.agentId)), runs };
|
|
153
|
+
});
|
|
154
|
+
router.get('/api/app/agents/:id/routines', ctx => { const owner = this.auth.require(ctx).id; this.store.require(owner, 'agent', ctx.params.id); ctx.body = { routines: this.store.list(owner, 'routine').filter(r => r.agentId === ctx.params.id), runs: this.runs(owner, ctx.params.id) }; });
|
|
155
|
+
router.post('/api/app/agents/:id/routines', ctx => { ctx.body = { routine: this.save(this.auth.require(ctx).id, ctx.params.id, ctx.request.body) }; ctx.status = 201; });
|
|
156
|
+
router.put('/api/app/agents/:id/routines/:routineId', ctx => { const owner = this.auth.require(ctx).id; this.store.require(owner, 'routine', ctx.params.routineId); ctx.body = { routine: this.save(owner, ctx.params.id, ctx.request.body, ctx.params.routineId) }; });
|
|
157
|
+
router.delete('/api/app/agents/:id/routines/:routineId', ctx => { const owner = this.auth.require(ctx).id, r = this.store.require(owner, 'routine', ctx.params.routineId); if (r.agentId !== ctx.params.id)
|
|
158
|
+
throw new HttpError(404, '定时任务不存在', 'not_found'); this.store.remove(owner, 'routine', r.id); ctx.body = { ok: true }; });
|
|
159
|
+
router.post('/api/app/agents/:id/routines/:routineId/run', ctx => { const owner = this.auth.require(ctx).id, r = this.store.require(owner, 'routine', ctx.params.routineId); if (r.agentId !== ctx.params.id)
|
|
160
|
+
throw new HttpError(404, '定时任务不存在', 'not_found'); const body = parse(z.object({ requestId: z.string().uuid() }).strict(), ctx.request.body); ctx.body = { run: this.run(owner, r, 0, body.requestId) }; });
|
|
161
|
+
return router;
|
|
162
|
+
}
|
|
163
|
+
}
|