@promptbook/cli 0.114.0-13 → 0.114.0-18
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/apps/agents-server/next.config.ts +6 -0
- package/apps/agents-server/src/app/admin/_components/AdminFilterFields.tsx +84 -0
- package/apps/agents-server/src/app/admin/_components/AdminMetricCard.tsx +36 -0
- package/apps/agents-server/src/app/admin/_components/AdminTaskManagerTabs.tsx +97 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerClient.tsx +103 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerEditDialog.tsx +232 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerFiltersCard.tsx +195 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerRow.tsx +189 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerSummaryMetrics.tsx +60 -0
- package/apps/agents-server/src/app/admin/planned-messages/PlannedMessageManagerTableCard.tsx +147 -0
- package/apps/agents-server/src/app/admin/planned-messages/page.tsx +17 -0
- package/apps/agents-server/src/app/admin/planned-messages/plannedMessageEditForm.ts +186 -0
- package/apps/agents-server/src/app/admin/planned-messages/plannedMessageManagerDialogs.ts +46 -0
- package/apps/agents-server/src/app/admin/planned-messages/plannedMessageManagerPresentation.tsx +188 -0
- package/apps/agents-server/src/app/admin/planned-messages/resolvePlannedMessageSortValue.ts +115 -0
- package/apps/agents-server/src/app/admin/planned-messages/usePlannedMessageManagerData.ts +116 -0
- package/apps/agents-server/src/app/admin/planned-messages/usePlannedMessageManagerState.ts +289 -0
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerClient.tsx +7 -2
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerFiltersCard.tsx +7 -73
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerSummaryMetrics.tsx +5 -30
- package/apps/agents-server/src/app/admin/task-manager/[taskId]/TaskManagerTaskDetailClient.tsx +1 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/book/reference-diagnostics/route.ts +30 -7
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +1 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/test.http +3 -3
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorMissingReferences.tsx +106 -12
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +3 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorDiagnostics.ts +12 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorWrapper.tsx +2 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatPlannedMessages.tsx +46 -3
- package/apps/agents-server/src/app/api/admin/default-agents/reinstate/route.ts +5 -1
- package/apps/agents-server/src/app/api/admin/planned-messages/[timeoutId]/route.ts +80 -0
- package/apps/agents-server/src/app/api/admin/planned-messages/route.ts +19 -0
- package/apps/agents-server/src/app/api/internal/agent-goal-chat-planned-messages/route.ts +30 -2
- package/apps/agents-server/src/components/DefaultAgents/ReinstateBundledAgentsButton.tsx +7 -0
- package/apps/agents-server/src/components/DefaultAgents/coreAgentsAdminRoute.ts +6 -0
- package/apps/agents-server/src/components/Header/buildHeaderSystemMenuItems.ts +7 -0
- package/apps/agents-server/src/components/Homepage/DefaultAgentsStatusNotice.tsx +1 -7
- package/apps/agents-server/src/database/migrations/2026-08-1800-user-chat-timeout-schedule.sql +11 -0
- package/apps/agents-server/src/instrumentation-node.ts +18 -0
- package/apps/agents-server/src/languages/ServerTranslationKeys.ts +4 -0
- package/apps/agents-server/src/languages/translations/czech.yaml +4 -0
- package/apps/agents-server/src/languages/translations/english.yaml +4 -0
- package/apps/agents-server/src/tools/agentGoalChatTimeoutToolFunctions.ts +62 -15
- package/apps/agents-server/src/tools/agentGoalChatTimeoutTools.ts +63 -9
- package/apps/agents-server/src/utils/adminEntityLookups/loadAgentNamesByPermanentId.ts +45 -0
- package/apps/agents-server/src/utils/adminEntityLookups/loadUsernamesByUserId.ts +36 -0
- package/apps/agents-server/src/utils/adminEntityLookups.ts +2 -0
- package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatPlannedMessageActions.ts +299 -52
- package/apps/agents-server/src/utils/agentGoalChat/createAgentGoalChatNoteContent.ts +45 -17
- package/apps/agents-server/src/utils/agentGoalChat.ts +1 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectIdentity.ts +46 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeAutostartScheduler.ts +162 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeDesiredState.ts +252 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeDisplay.ts +6 -3
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeDomains.ts +2 -44
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimePaths.ts +25 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimePm2.ts +4 -3
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimeRegistry.ts +77 -24
- package/apps/agents-server/src/utils/agentProjects/agentProjectStateMutationQueue.ts +58 -0
- package/apps/agents-server/src/utils/agentProjects/listAllLocalAgentProjectIdentities.ts +48 -0
- package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectRuntimeEnvironmentFlag.ts +23 -0
- package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectRuntimeStatus.ts +73 -0
- package/apps/agents-server/src/utils/agentProjects/startDefaultAgentProjectRuntimes.ts +110 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/MissingCoreAgentRecovery.ts +19 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/bookScopedAgentReferences.ts +7 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/createAgentInheritanceDiagnostics.ts +457 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/createUnresolvedAgentReferenceDiagnostics.ts +27 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/resolveCoreAgentAwareMissingReferences.ts +156 -0
- package/apps/agents-server/src/utils/chatMessageChips/createAnsweredMessageChipToolCalls.ts +15 -3
- package/apps/agents-server/src/utils/chatMessageChips/createPlannedMessageChipToolCalls.ts +8 -3
- package/apps/agents-server/src/utils/chatMessageChips/createTouchedExternalSourceChipToolCalls.ts +39 -0
- package/apps/agents-server/src/utils/chatMessageChips/createTouchedProjectChipResult.ts +45 -0
- package/apps/agents-server/src/utils/chatMessageChips/createTouchedProjectChipToolCalls.ts +58 -24
- package/apps/agents-server/src/utils/cronExpression/CronExpression.ts +63 -0
- package/apps/agents-server/src/utils/cronExpression/normalizeCronExpression.ts +34 -0
- package/apps/agents-server/src/utils/cronExpression/normalizeCronExpressionWhitespace.ts +11 -0
- package/apps/agents-server/src/utils/cronExpression/parseCronExpression.ts +41 -0
- package/apps/agents-server/src/utils/cronExpression/parseCronExpressionField.ts +140 -0
- package/apps/agents-server/src/utils/cronExpression/resolveNextCronRun.ts +100 -0
- package/apps/agents-server/src/utils/cronExpression/throwInvalidCronExpressionField.ts +20 -0
- package/apps/agents-server/src/utils/cronExpression.ts +10 -0
- package/apps/agents-server/src/utils/explicitFromCommitment.ts +130 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/loadAdminChatTaskFallbackData.ts +3 -77
- package/apps/agents-server/src/utils/localChatRunner/applyLocalAgentPlannedMessageCommands.ts +53 -4
- package/apps/agents-server/src/utils/localChatRunner/prepareLocalAgentPlannedMessagesSidecar.ts +15 -7
- package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +8 -0
- package/apps/agents-server/src/utils/manGoOnboarding/manGoOnboardingAgentBooks.ts +5 -11
- package/apps/agents-server/src/utils/manGoOnboarding/manGoOnboardingAgentRuntime.ts +2 -2
- package/apps/agents-server/src/utils/managementApi/managementApiSchemas.ts +2 -2
- package/apps/agents-server/src/utils/plannedMessageManager/cancelManagedPlannedMessage.ts +35 -0
- package/apps/agents-server/src/utils/plannedMessageManager/collectPlannedMessageAgentOptions.ts +56 -0
- package/apps/agents-server/src/utils/plannedMessageManager/createPlannedMessageManagerCounters.ts +104 -0
- package/apps/agents-server/src/utils/plannedMessageManager/filterPlannedMessages.ts +191 -0
- package/apps/agents-server/src/utils/plannedMessageManager/getPlannedMessageManagerResponse.ts +55 -0
- package/apps/agents-server/src/utils/plannedMessageManager/isPlannedMessageStillPlanned.ts +18 -0
- package/apps/agents-server/src/utils/plannedMessageManager/loadPlannedMessageManagerRecord.ts +32 -0
- package/apps/agents-server/src/utils/plannedMessageManager/mapPlannedMessageManagerRecord.ts +73 -0
- package/apps/agents-server/src/utils/plannedMessageManager/parsePlannedMessageManagerUpdateRequest.ts +76 -0
- package/apps/agents-server/src/utils/plannedMessageManager/resolvePlannedMessageEndReason.ts +59 -0
- package/apps/agents-server/src/utils/plannedMessageManager/resolvePlannedMessageLifecycle.ts +99 -0
- package/apps/agents-server/src/utils/plannedMessageManager/resolvePlannedMessageRecurrenceKind.ts +40 -0
- package/apps/agents-server/src/utils/plannedMessageManager/updateManagedPlannedMessage.ts +121 -0
- package/apps/agents-server/src/utils/plannedMessagesAdmin.ts +200 -0
- package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +114 -95
- package/apps/agents-server/src/utils/userChatClient.ts +4 -0
- package/apps/agents-server/src/utils/userChatTimeout/UserChatTimeoutRecord.ts +37 -1
- package/apps/agents-server/src/utils/userChatTimeout/agentScopedTimeoutBulkActions.ts +11 -17
- package/apps/agents-server/src/utils/userChatTimeout/createTimeoutWakeUpMessage.ts +37 -13
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/PlannedMessageSchedule.ts +52 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/hasPlannedMessageRecurrence.ts +13 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/isPlannedMessageScheduleFinished.ts +30 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/normalizePlannedMessageScheduleValues.ts +62 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/parsePlannedMessageSchedule.ts +202 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule/resolvePlannedMessageDueAt.ts +121 -0
- package/apps/agents-server/src/utils/userChatTimeout/plannedMessageSchedule.ts +12 -0
- package/apps/agents-server/src/utils/userChatTimeout/setAgentScopedUserChatTimeoutPausedState.ts +66 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/createUserChatTimeout.ts +76 -5
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/listAllUserChatTimeouts.ts +37 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/mapUserChatTimeoutRow.ts +9 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/repeatFiredUserChatTimeout.ts +19 -9
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/updateAgentScopedUserChatTimeout.ts +39 -6
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore.ts +1 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +110 -11
- package/apps/agents-server/src/utils/userChatTimeout.ts +16 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateCron.ts +23 -316
- package/apps/agents-server/tests/e2e/support/AgentManagementApi.ts +3 -3
- package/esm/index.es.js +951 -102
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-messages/git/commitAgentProjectChanges.d.ts +15 -0
- package/esm/scripts/run-agent-messages/git/commitAnsweredMessageProjectChanges.d.ts +24 -0
- package/esm/scripts/run-agent-messages/git/ensureAgentProjectGitRepository.d.ts +20 -0
- package/esm/scripts/run-agent-messages/git/readAgentProjectCommitChange.d.ts +11 -0
- package/esm/scripts/run-agent-messages/git/runAgentProjectGitCommand.d.ts +29 -0
- package/esm/scripts/run-agent-messages/messages/buildAgentGoalChatPromptSection.d.ts +3 -3
- package/esm/scripts/run-agent-messages/messages/listAgentProjectDirectoryNames.d.ts +7 -0
- package/esm/scripts/run-agent-messages/messages/resolveAnsweredMessageTouches.d.ts +29 -0
- package/esm/scripts/run-codex-prompts/ping/pingCoderHarnessPeriodically.d.ts +22 -0
- package/esm/src/book-3.0/AgentMessageRunReport.d.ts +18 -0
- package/esm/src/book-3.0/AgentPlannedMessagesSidecar.d.ts +38 -5
- package/esm/src/book-3.0/describeAgentPlannedMessageSchedule.d.ts +31 -0
- package/esm/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +1 -9
- package/esm/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.d.ts +28 -0
- package/esm/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.test.d.ts +1 -0
- package/esm/src/book-components/Chat/Chat/renderAgentProjectDiff.d.ts +13 -0
- package/esm/src/book-components/Chat/Chat/renderAgentProjectToolCallDetails.d.ts +16 -0
- package/esm/src/book-components/Chat/utils/agentProjectToolCall.d.ts +39 -0
- package/esm/src/book-components/Chat/utils/agentProjectToolCall.test.d.ts +1 -0
- package/esm/src/book-components/Chat/utils/externalSourceToolCall.d.ts +38 -0
- package/esm/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +6 -0
- package/esm/src/cli/cli-commands/coder/waitOptions.d.ts +12 -0
- package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +15 -0
- package/esm/src/utils/agent-message-runtime/AgentMessageProjectChange.d.ts +76 -0
- package/esm/src/utils/agent-message-runtime/AgentMessageTouchedExternalSource.d.ts +45 -0
- package/esm/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.d.ts +3 -0
- package/esm/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.d.ts +18 -0
- package/esm/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.test.d.ts +1 -0
- package/esm/src/utils/random/$generateBookBoilerplate.test.d.ts +1 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/book-2.0/agent-source/string_book.ts +1 -1
- package/src/book-2.0/book-language-documentation/czechBookLanguageManualDictionary.ts +6 -1
- package/src/book-2.0/book-language-documentation/englishBookLanguageManualDictionary.ts +6 -1
- package/src/book-3.0/AgentMessageRunReport.ts +59 -0
- package/src/book-3.0/AgentPlannedMessagesSidecar.ts +64 -9
- package/src/book-3.0/describeAgentPlannedMessageSchedule.ts +94 -0
- package/src/book-components/BookEditor/BookEditorMonaco.tsx +2 -0
- package/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.ts +3 -11
- package/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.ts +71 -0
- package/src/book-components/Chat/Chat/Chat.module.css +165 -18
- package/src/book-components/Chat/Chat/ChatMessageMap.tsx +0 -1
- package/src/book-components/Chat/Chat/renderAgentProjectDiff.tsx +85 -0
- package/src/book-components/Chat/Chat/renderAgentProjectToolCallDetails.tsx +206 -0
- package/src/book-components/Chat/Chat/renderToolCallDetails.tsx +8 -0
- package/src/book-components/Chat/MarkdownContent/MarkdownContent.tsx +2 -3
- package/src/book-components/Chat/utils/agentProjectToolCall.ts +82 -5
- package/src/book-components/Chat/utils/externalSourceToolCall.ts +65 -0
- package/src/book-components/Chat/utils/getToolCallChipletInfo.ts +36 -0
- package/src/book-components/Chat/utils/renderMarkdown.ts +3 -10
- package/src/book-components/Chat/utils/timeoutToolCallPresentation.ts +12 -1
- package/src/cli/cli-commands/coder/ping.ts +35 -9
- package/src/cli/cli-commands/coder/waitOptions.ts +33 -0
- package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +3 -1
- package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +3 -1
- package/src/cli/cli-commands/common/harnessUpdateCliOptions.ts +1 -4
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.ts +47 -3
- package/src/commands/FORMAT/formatCommandParser.ts +4 -2
- package/src/commitments/FROM/FROM.ts +13 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +819 -751
- package/src/utils/agent-message-runtime/AgentMessageProjectChange.ts +183 -0
- package/src/utils/agent-message-runtime/AgentMessageTouchedExternalSource.ts +80 -0
- package/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.ts +3 -0
- package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +2 -4
- package/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.ts +341 -0
- package/src/utils/random/$generateBookBoilerplate.ts +1 -1
- package/src/version.ts +2 -2
- package/src/versions.txt +5 -0
- package/umd/index.umd.js +950 -101
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-messages/git/commitAgentProjectChanges.d.ts +15 -0
- package/umd/scripts/run-agent-messages/git/commitAnsweredMessageProjectChanges.d.ts +24 -0
- package/umd/scripts/run-agent-messages/git/ensureAgentProjectGitRepository.d.ts +20 -0
- package/umd/scripts/run-agent-messages/git/readAgentProjectCommitChange.d.ts +11 -0
- package/umd/scripts/run-agent-messages/git/runAgentProjectGitCommand.d.ts +29 -0
- package/umd/scripts/run-agent-messages/messages/buildAgentGoalChatPromptSection.d.ts +3 -3
- package/umd/scripts/run-agent-messages/messages/listAgentProjectDirectoryNames.d.ts +7 -0
- package/umd/scripts/run-agent-messages/messages/resolveAnsweredMessageTouches.d.ts +29 -0
- package/umd/scripts/run-codex-prompts/ping/pingCoderHarnessPeriodically.d.ts +22 -0
- package/umd/src/book-3.0/AgentMessageRunReport.d.ts +18 -0
- package/umd/src/book-3.0/AgentPlannedMessagesSidecar.d.ts +38 -5
- package/umd/src/book-3.0/describeAgentPlannedMessageSchedule.d.ts +31 -0
- package/umd/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +1 -9
- package/umd/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.d.ts +28 -0
- package/umd/src/book-components/BookEditor/createDuplicateFromCommitmentDiagnostics.test.d.ts +1 -0
- package/umd/src/book-components/Chat/Chat/renderAgentProjectDiff.d.ts +13 -0
- package/umd/src/book-components/Chat/Chat/renderAgentProjectToolCallDetails.d.ts +16 -0
- package/umd/src/book-components/Chat/utils/agentProjectToolCall.d.ts +39 -0
- package/umd/src/book-components/Chat/utils/agentProjectToolCall.test.d.ts +1 -0
- package/umd/src/book-components/Chat/utils/externalSourceToolCall.d.ts +38 -0
- package/umd/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +6 -0
- package/umd/src/cli/cli-commands/coder/waitOptions.d.ts +12 -0
- package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +15 -0
- package/umd/src/utils/agent-message-runtime/AgentMessageProjectChange.d.ts +76 -0
- package/umd/src/utils/agent-message-runtime/AgentMessageTouchedExternalSource.d.ts +45 -0
- package/umd/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.d.ts +3 -0
- package/umd/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.d.ts +18 -0
- package/umd/src/utils/agent-message-runtime/resolveAgentMessageTouchedExternalSources.test.d.ts +1 -0
- package/umd/src/utils/random/$generateBookBoilerplate.test.d.ts +1 -0
- package/umd/src/version.d.ts +1 -1
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerScopeTabs.tsx +0 -74
- package/esm/scripts/run-agent-messages/messages/resolveTouchedAgentProjects.d.ts +0 -15
- package/umd/scripts/run-agent-messages/messages/resolveTouchedAgentProjects.d.ts +0 -15
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { UserChatTimeoutStatus } from '../userChatTimeout/UserChatTimeoutRecord';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stage one planned message is in, as shown by the planned-message manager.
|
|
5
|
+
*
|
|
6
|
+
* The stored `UserChatTimeoutStatus` alone cannot answer this: a queued planned message may be
|
|
7
|
+
* waiting for its own starting date, may be paused, or may already have a cancellation on its way,
|
|
8
|
+
* and all three look like `QUEUED` in the database.
|
|
9
|
+
*
|
|
10
|
+
* @private internal admin utility of Agents Server
|
|
11
|
+
*/
|
|
12
|
+
export type PlannedMessageLifecycle =
|
|
13
|
+
| 'ONGOING'
|
|
14
|
+
| 'SCHEDULED'
|
|
15
|
+
| 'NOT_STARTED'
|
|
16
|
+
| 'PAUSED'
|
|
17
|
+
| 'CANCELLED'
|
|
18
|
+
| 'ENDED'
|
|
19
|
+
| 'FAILED';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Stored fields needed to tell which stage one planned message is in.
|
|
23
|
+
*
|
|
24
|
+
* Both a durable timeout row and one manager row satisfy this shape, so the very same rule decides
|
|
25
|
+
* the stage on the server and in the browser.
|
|
26
|
+
*
|
|
27
|
+
* @private internal admin utility of Agents Server
|
|
28
|
+
*/
|
|
29
|
+
export type PlannedMessageLifecycleInput = {
|
|
30
|
+
readonly status: UserChatTimeoutStatus;
|
|
31
|
+
readonly pausedAt: string | null;
|
|
32
|
+
readonly cancelRequestedAt: string | null;
|
|
33
|
+
readonly startsAt: string | null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Resolves the stage one planned message is in.
|
|
38
|
+
*
|
|
39
|
+
* @param plannedMessage - Stored planned message.
|
|
40
|
+
* @param atDate - Moment the stage is judged at.
|
|
41
|
+
* @returns Stage of the planned message.
|
|
42
|
+
*
|
|
43
|
+
* @private internal admin utility of Agents Server
|
|
44
|
+
*/
|
|
45
|
+
export function resolvePlannedMessageLifecycle(
|
|
46
|
+
plannedMessage: PlannedMessageLifecycleInput,
|
|
47
|
+
atDate: Date,
|
|
48
|
+
): PlannedMessageLifecycle {
|
|
49
|
+
if (plannedMessage.status === 'RUNNING') {
|
|
50
|
+
return 'ONGOING';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (plannedMessage.status === 'FAILED') {
|
|
54
|
+
return 'FAILED';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (plannedMessage.status === 'CANCELLED') {
|
|
58
|
+
return 'CANCELLED';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (plannedMessage.status === 'COMPLETED') {
|
|
62
|
+
return 'ENDED';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Note: A cancellation is requested on the row first and only turned into `CANCELLED` by the
|
|
66
|
+
// worker, so a queued row carrying that request is already on its way out
|
|
67
|
+
if (plannedMessage.cancelRequestedAt !== null) {
|
|
68
|
+
return 'CANCELLED';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (plannedMessage.pausedAt !== null) {
|
|
72
|
+
return 'PAUSED';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (isPlannedMessageWaitingForStartingDate(plannedMessage.startsAt, atDate)) {
|
|
76
|
+
return 'NOT_STARTED';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return 'SCHEDULED';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Determines whether one planned message may not wake its agent yet because its window has not opened.
|
|
84
|
+
*
|
|
85
|
+
* @param startsAt - Moment before which the planned message never wakes the agent.
|
|
86
|
+
* @param atDate - Moment the stage is judged at.
|
|
87
|
+
* @returns `true` while the starting date is still ahead.
|
|
88
|
+
*
|
|
89
|
+
* @private function of `resolvePlannedMessageLifecycle`
|
|
90
|
+
*/
|
|
91
|
+
function isPlannedMessageWaitingForStartingDate(startsAt: string | null, atDate: Date): boolean {
|
|
92
|
+
if (startsAt === null) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const startsAtTime = Date.parse(startsAt);
|
|
97
|
+
|
|
98
|
+
return Number.isFinite(startsAtTime) && startsAtTime > atDate.getTime();
|
|
99
|
+
}
|
package/apps/agents-server/src/utils/plannedMessageManager/resolvePlannedMessageRecurrenceKind.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How often one planned message wakes its agent.
|
|
3
|
+
*
|
|
4
|
+
* A planned message follows exactly one recurrence rule, so these three kinds are exhaustive.
|
|
5
|
+
*
|
|
6
|
+
* @private internal admin utility of Agents Server
|
|
7
|
+
*/
|
|
8
|
+
export type PlannedMessageRecurrenceKind = 'ONCE' | 'INTERVAL' | 'CRON';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Stored fields deciding how often one planned message repeats.
|
|
12
|
+
*
|
|
13
|
+
* @private internal admin utility of Agents Server
|
|
14
|
+
*/
|
|
15
|
+
export type PlannedMessageRecurrenceInput = {
|
|
16
|
+
readonly recurrenceIntervalMs: number | null;
|
|
17
|
+
readonly cronExpression: string | null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Resolves how often one planned message wakes its agent.
|
|
22
|
+
*
|
|
23
|
+
* @param plannedMessage - Stored planned message.
|
|
24
|
+
* @returns Recurrence kind of the planned message.
|
|
25
|
+
*
|
|
26
|
+
* @private internal admin utility of Agents Server
|
|
27
|
+
*/
|
|
28
|
+
export function resolvePlannedMessageRecurrenceKind(
|
|
29
|
+
plannedMessage: PlannedMessageRecurrenceInput,
|
|
30
|
+
): PlannedMessageRecurrenceKind {
|
|
31
|
+
if (plannedMessage.cronExpression) {
|
|
32
|
+
return 'CRON';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (plannedMessage.recurrenceIntervalMs) {
|
|
36
|
+
return 'INTERVAL';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return 'ONCE';
|
|
40
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { AGENT_GOAL_CHAT_PLANNED_MESSAGE_ACTIONS } from '../agentGoalChat/agentGoalChatPlannedMessageActions';
|
|
2
|
+
import type { PlannedMessageManagerRecord } from '../plannedMessagesAdmin';
|
|
3
|
+
import { getUserChatTimeoutById, setAgentScopedUserChatTimeoutPausedState } from '../userChatTimeout';
|
|
4
|
+
import { loadPlannedMessageManagerRecord } from './loadPlannedMessageManagerRecord';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Change requested for one planned message, as it arrives from an administrator.
|
|
8
|
+
*
|
|
9
|
+
* Every schedule field is untrusted and validated by the shared planned-message service, exactly the
|
|
10
|
+
* same way a schedule requested by an agent is. Only `isPaused` is checked before it gets here,
|
|
11
|
+
* because no later step would check it.
|
|
12
|
+
*
|
|
13
|
+
* @private internal admin utility of Agents Server
|
|
14
|
+
*/
|
|
15
|
+
export type UpdateManagedPlannedMessageRequest = {
|
|
16
|
+
readonly message?: unknown;
|
|
17
|
+
readonly milliseconds?: unknown;
|
|
18
|
+
readonly cronExpression?: unknown;
|
|
19
|
+
readonly startsAt?: unknown;
|
|
20
|
+
readonly endsAt?: unknown;
|
|
21
|
+
readonly maxRunCount?: unknown;
|
|
22
|
+
readonly isPaused?: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Outcome of one administrator change to a planned message.
|
|
27
|
+
*
|
|
28
|
+
* `busy` means the planned message is firing right now, so its schedule is being consumed by that
|
|
29
|
+
* very firing and cannot be rewritten underneath it.
|
|
30
|
+
*
|
|
31
|
+
* @private internal admin utility of Agents Server
|
|
32
|
+
*/
|
|
33
|
+
export type UpdateManagedPlannedMessageResult =
|
|
34
|
+
| { readonly status: 'updated'; readonly plannedMessage: PlannedMessageManagerRecord }
|
|
35
|
+
| { readonly status: 'not_found' }
|
|
36
|
+
| { readonly status: 'busy' };
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Applies one administrator change to a planned message of any agent.
|
|
40
|
+
*
|
|
41
|
+
* The change goes through the very same planned-message service an agent re-plans itself with, so an
|
|
42
|
+
* administrator can never write a schedule the agent itself could not have written.
|
|
43
|
+
*
|
|
44
|
+
* @param timeoutId - Id of the planned message being changed.
|
|
45
|
+
* @param payload - Requested change, where an absent field keeps its stored value.
|
|
46
|
+
* @returns Changed planned message, or why it could not be changed.
|
|
47
|
+
*
|
|
48
|
+
* @private internal admin utility of Agents Server
|
|
49
|
+
*/
|
|
50
|
+
export async function updateManagedPlannedMessage(
|
|
51
|
+
timeoutId: string,
|
|
52
|
+
payload: UpdateManagedPlannedMessageRequest,
|
|
53
|
+
): Promise<UpdateManagedPlannedMessageResult> {
|
|
54
|
+
const existingPlannedMessage = await getUserChatTimeoutById(timeoutId);
|
|
55
|
+
|
|
56
|
+
if (!existingPlannedMessage) {
|
|
57
|
+
return { status: 'not_found' };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const { agentPermanentId } = existingPlannedMessage;
|
|
61
|
+
|
|
62
|
+
if (isPlannedMessageScheduleChangeRequested(payload)) {
|
|
63
|
+
const updateResult = await AGENT_GOAL_CHAT_PLANNED_MESSAGE_ACTIONS.update({
|
|
64
|
+
agentPermanentId,
|
|
65
|
+
timeoutId,
|
|
66
|
+
...(payload.message === undefined ? {} : { message: payload.message }),
|
|
67
|
+
...(payload.milliseconds === undefined ? {} : { milliseconds: payload.milliseconds }),
|
|
68
|
+
...(payload.cronExpression === undefined ? {} : { cronExpression: payload.cronExpression }),
|
|
69
|
+
...(payload.startsAt === undefined ? {} : { startsAt: payload.startsAt }),
|
|
70
|
+
...(payload.endsAt === undefined ? {} : { endsAt: payload.endsAt }),
|
|
71
|
+
...(payload.maxRunCount === undefined ? {} : { maxRunCount: payload.maxRunCount }),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (updateResult.status === 'not_found') {
|
|
75
|
+
return { status: 'not_found' };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (updateResult.status === 'busy') {
|
|
79
|
+
return { status: 'busy' };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (payload.isPaused !== undefined) {
|
|
84
|
+
const pauseResult = await setAgentScopedUserChatTimeoutPausedState({
|
|
85
|
+
agentPermanentId,
|
|
86
|
+
timeoutId,
|
|
87
|
+
isPaused: payload.isPaused,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (!pauseResult.isApplied) {
|
|
91
|
+
return pauseResult.plannedMessage === null ? { status: 'not_found' } : { status: 'busy' };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const changedPlannedMessage = await loadPlannedMessageManagerRecord(timeoutId);
|
|
96
|
+
|
|
97
|
+
if (!changedPlannedMessage) {
|
|
98
|
+
return { status: 'not_found' };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return { status: 'updated', plannedMessage: changedPlannedMessage };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Determines whether one requested change touches the schedule or the text of a planned message.
|
|
106
|
+
*
|
|
107
|
+
* @param payload - Requested change.
|
|
108
|
+
* @returns `true` when anything but the paused state was requested.
|
|
109
|
+
*
|
|
110
|
+
* @private function of `updateManagedPlannedMessage`
|
|
111
|
+
*/
|
|
112
|
+
function isPlannedMessageScheduleChangeRequested(payload: UpdateManagedPlannedMessageRequest): boolean {
|
|
113
|
+
return (
|
|
114
|
+
payload.message !== undefined ||
|
|
115
|
+
payload.milliseconds !== undefined ||
|
|
116
|
+
payload.cronExpression !== undefined ||
|
|
117
|
+
payload.startsAt !== undefined ||
|
|
118
|
+
payload.endsAt !== undefined ||
|
|
119
|
+
payload.maxRunCount !== undefined
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { PlannedMessageEndReason } from './plannedMessageManager/resolvePlannedMessageEndReason';
|
|
2
|
+
import type { PlannedMessageLifecycle } from './plannedMessageManager/resolvePlannedMessageLifecycle';
|
|
3
|
+
import type { PlannedMessageRecurrenceKind } from './plannedMessageManager/resolvePlannedMessageRecurrenceKind';
|
|
4
|
+
import type { UserChatTimeoutStatus } from './userChatTimeout/UserChatTimeoutRecord';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One planned message (durable chat timeout) as shown in the admin planned-message manager.
|
|
8
|
+
*
|
|
9
|
+
* This is the whole planned message, not the queue view of it the task manager shows: it carries the
|
|
10
|
+
* schedule the agent planned, where that plan stands now, and who it belongs to.
|
|
11
|
+
*
|
|
12
|
+
* @private internal admin utility of Agents Server
|
|
13
|
+
*/
|
|
14
|
+
export type PlannedMessageManagerRecord = {
|
|
15
|
+
timeoutId: string;
|
|
16
|
+
status: UserChatTimeoutStatus;
|
|
17
|
+
lifecycle: PlannedMessageLifecycle;
|
|
18
|
+
recurrenceKind: PlannedMessageRecurrenceKind;
|
|
19
|
+
endReason: PlannedMessageEndReason;
|
|
20
|
+
message: string | null;
|
|
21
|
+
|
|
22
|
+
createdAt: string;
|
|
23
|
+
updatedAt: string;
|
|
24
|
+
dueAt: string;
|
|
25
|
+
startsAt: string | null;
|
|
26
|
+
endsAt: string | null;
|
|
27
|
+
lastFiredAt: string | null;
|
|
28
|
+
completedAt: string | null;
|
|
29
|
+
cancelRequestedAt: string | null;
|
|
30
|
+
pausedAt: string | null;
|
|
31
|
+
|
|
32
|
+
recurrenceIntervalMs: number | null;
|
|
33
|
+
cronExpression: string | null;
|
|
34
|
+
maxRunCount: number | null;
|
|
35
|
+
runCount: number;
|
|
36
|
+
attemptCount: number;
|
|
37
|
+
failureReason: string | null;
|
|
38
|
+
|
|
39
|
+
userId: number;
|
|
40
|
+
username: string | null;
|
|
41
|
+
agentPermanentId: string;
|
|
42
|
+
agentName: string | null;
|
|
43
|
+
chatId: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* True when the planned message lives in the agent's own goal chat, which is where an agent plans
|
|
47
|
+
* its own work.
|
|
48
|
+
*/
|
|
49
|
+
isAgentGoalChat: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Full payload returned by the admin planned-message listing endpoint.
|
|
54
|
+
*
|
|
55
|
+
* The whole bounded set is returned at once, so filtering, sorting, and counting all see the same
|
|
56
|
+
* rows and can never disagree with each other.
|
|
57
|
+
*
|
|
58
|
+
* @private internal admin utility of Agents Server
|
|
59
|
+
*/
|
|
60
|
+
export type PlannedMessageManagerListResponse = {
|
|
61
|
+
items: Array<PlannedMessageManagerRecord>;
|
|
62
|
+
generatedAt: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* True when more planned messages exist than the endpoint is willing to return at once.
|
|
66
|
+
*/
|
|
67
|
+
hasMore: boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Stage filter offered by the planned-message manager.
|
|
72
|
+
*
|
|
73
|
+
* @private internal admin utility of Agents Server
|
|
74
|
+
*/
|
|
75
|
+
export type PlannedMessageManagerView =
|
|
76
|
+
| 'active'
|
|
77
|
+
| 'scheduled'
|
|
78
|
+
| 'not-started'
|
|
79
|
+
| 'ongoing'
|
|
80
|
+
| 'paused'
|
|
81
|
+
| 'finished'
|
|
82
|
+
| 'all';
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Recurrence (frequency) filter offered by the planned-message manager.
|
|
86
|
+
*
|
|
87
|
+
* @private internal admin utility of Agents Server
|
|
88
|
+
*/
|
|
89
|
+
export type PlannedMessageManagerRecurrenceFilter = 'all' | PlannedMessageRecurrenceKind;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Last-run filter offered by the planned-message manager.
|
|
93
|
+
*
|
|
94
|
+
* @private internal admin utility of Agents Server
|
|
95
|
+
*/
|
|
96
|
+
export type PlannedMessageManagerLastRunFilter = 'all' | 'never' | 'hour' | 'day' | 'week' | 'older';
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Sortable planned-message manager columns.
|
|
100
|
+
*
|
|
101
|
+
* @private internal admin utility of Agents Server
|
|
102
|
+
*/
|
|
103
|
+
export type PlannedMessageManagerSortField =
|
|
104
|
+
| 'plannedMessage'
|
|
105
|
+
| 'agent'
|
|
106
|
+
| 'frequency'
|
|
107
|
+
| 'nextRun'
|
|
108
|
+
| 'lastRun'
|
|
109
|
+
| 'runs'
|
|
110
|
+
| 'state';
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Change requested for one planned message by an administrator.
|
|
114
|
+
*
|
|
115
|
+
* Leaving a field out keeps it as it is and passing `null` removes the bound, exactly like the
|
|
116
|
+
* re-planning an agent can do itself.
|
|
117
|
+
*
|
|
118
|
+
* @private internal admin utility of Agents Server
|
|
119
|
+
*/
|
|
120
|
+
export type PlannedMessageManagerUpdatePayload = {
|
|
121
|
+
message?: string;
|
|
122
|
+
milliseconds?: number | null;
|
|
123
|
+
cronExpression?: string | null;
|
|
124
|
+
startsAt?: string | null;
|
|
125
|
+
endsAt?: string | null;
|
|
126
|
+
maxRunCount?: number | null;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Whether the planned message should be held back from waking its agent.
|
|
130
|
+
*/
|
|
131
|
+
isPaused?: boolean;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Route of the admin planned-message manager API.
|
|
136
|
+
*
|
|
137
|
+
* @private internal admin utility of Agents Server
|
|
138
|
+
*/
|
|
139
|
+
const ADMIN_PLANNED_MESSAGES_API_PATH = '/api/admin/planned-messages';
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Fetches every planned message of this server for the admin manager.
|
|
143
|
+
*
|
|
144
|
+
* @private internal admin utility of Agents Server
|
|
145
|
+
*/
|
|
146
|
+
export async function $fetchAdminPlannedMessages(): Promise<PlannedMessageManagerListResponse> {
|
|
147
|
+
const response = await fetch(ADMIN_PLANNED_MESSAGES_API_PATH, { method: 'GET' });
|
|
148
|
+
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
const payload = await response.json().catch(() => ({}));
|
|
151
|
+
throw new Error(payload.error || 'Failed to load planned messages.');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return (await response.json()) as PlannedMessageManagerListResponse;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Applies one administrator change to a planned message.
|
|
159
|
+
*
|
|
160
|
+
* @private internal admin utility of Agents Server
|
|
161
|
+
*/
|
|
162
|
+
export async function $updateAdminPlannedMessage(
|
|
163
|
+
timeoutId: string,
|
|
164
|
+
payload: PlannedMessageManagerUpdatePayload,
|
|
165
|
+
): Promise<PlannedMessageManagerRecord> {
|
|
166
|
+
const response = await fetch(`${ADMIN_PLANNED_MESSAGES_API_PATH}/${encodeURIComponent(timeoutId)}`, {
|
|
167
|
+
method: 'PATCH',
|
|
168
|
+
headers: {
|
|
169
|
+
'Content-Type': 'application/json',
|
|
170
|
+
},
|
|
171
|
+
body: JSON.stringify(payload),
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const data = (await response.json().catch(() => ({}))) as {
|
|
175
|
+
plannedMessage?: PlannedMessageManagerRecord;
|
|
176
|
+
error?: string;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
if (!response.ok || !data.plannedMessage) {
|
|
180
|
+
throw new Error(data.error || 'Failed to update the planned message.');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return data.plannedMessage;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Cancels one planned message so it never wakes its agent again.
|
|
188
|
+
*
|
|
189
|
+
* @private internal admin utility of Agents Server
|
|
190
|
+
*/
|
|
191
|
+
export async function $cancelAdminPlannedMessage(timeoutId: string): Promise<void> {
|
|
192
|
+
const response = await fetch(`${ADMIN_PLANNED_MESSAGES_API_PATH}/${encodeURIComponent(timeoutId)}`, {
|
|
193
|
+
method: 'DELETE',
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
if (!response.ok) {
|
|
197
|
+
const payload = await response.json().catch(() => ({}));
|
|
198
|
+
throw new Error(payload.error || 'Failed to cancel the planned message.');
|
|
199
|
+
}
|
|
200
|
+
}
|