@promptbook/cli 0.114.0-5 → 0.114.0-7
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/agents/default/developer.book +1 -0
- package/apps/agents-server/next.config.ts +22 -0
- package/apps/agents-server/package.json +6 -6
- package/apps/agents-server/scripts/build-agents-server.js +43 -7
- package/apps/agents-server/scripts/build-e2e.js +12 -2
- package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +30 -16
- package/apps/agents-server/scripts/kill-port.js +163 -0
- package/apps/agents-server/scripts/run-e2e-tests.js +21 -8
- package/apps/agents-server/scripts/run-npm.js +81 -5
- package/apps/agents-server/src/app/actions.ts +3 -0
- package/apps/agents-server/src/app/admin/email-server/page.tsx +17 -18
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +2 -0
- package/apps/agents-server/src/app/admin/task-manager/[taskId]/TaskManagerTaskDetailClient.tsx +2 -0
- package/apps/agents-server/src/app/admin/task-manager/taskManagerTaskPresentation.tsx +23 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +7 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/[timeoutId]/route.ts +10 -153
- package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/route.ts +9 -4
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/route.ts +3 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +2 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/resolveUserChatScope.ts +8 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/route.ts +15 -7
- package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorSaving.ts +18 -28
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistoryClient.tsx +19 -1
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatSidebarDefault.tsx +17 -5
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatNotice.tsx +23 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatPlannedMessages.tsx +153 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatPanel.tsx +6 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +13 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/ExternalUserChatAdminActions.tsx +51 -3
- package/apps/agents-server/src/app/agents/[agentName]/chat/TeamMemberFrozenChatPrimaryAgentLink.tsx +31 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatSidebarState.ts +26 -2
- package/apps/agents-server/src/app/agents/[agentName]/goal/page.tsx +35 -0
- package/apps/agents-server/src/app/agents/[agentName]/projects/[projectName]/page.tsx +2 -2
- package/apps/agents-server/src/app/api/admin/dns-records/cloudflare/route.ts +26 -16
- package/apps/agents-server/src/app/api/emails/incoming/stalwart/route.ts +9 -2
- package/apps/agents-server/src/app/superadmin/servers/ServersRegistryTable.tsx +31 -39
- package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +10 -3
- package/apps/agents-server/src/components/AgentProjects/AgentProjectIcon.tsx +137 -0
- package/apps/agents-server/src/components/AgentProjects/AgentProjectItem.tsx +26 -10
- package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsApiTokenImportStep.tsx +5 -6
- package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsCheckStep.tsx +6 -5
- package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsManualStep.tsx +10 -14
- package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsWizard.tsx +11 -20
- package/apps/agents-server/src/components/CloudflareDnsWizard/useCloudflareDnsRecordImport.ts +5 -6
- package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsInstructions.tsx +91 -57
- package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsSectionPanel.tsx +63 -0
- package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsSectionVariantTabs.tsx +67 -0
- package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsTable.tsx +40 -0
- package/apps/agents-server/src/components/Header/buildActiveAgentViewItems.ts +5 -4
- package/apps/agents-server/src/components/Header/createAgentViewLabel.tsx +4 -4
- package/apps/agents-server/src/components/Header/resolveActiveAgentNavigation.ts +2 -2
- package/apps/agents-server/src/components/Homepage/useAgentsListImportExportState.ts +22 -10
- package/apps/agents-server/src/components/_utils/generateMetaTxt.ts +1 -1
- package/apps/agents-server/src/database/migratePrefix.ts +13 -12
- package/apps/agents-server/src/database/migrations/2026-08-0100-agent-goal-chat-source.sql +10 -0
- package/apps/agents-server/src/generated/reservedPaths.ts +42 -42
- package/apps/agents-server/src/languages/ServerTranslationKeys.ts +9 -1
- package/apps/agents-server/src/languages/translations/czech.yaml +9 -1
- package/apps/agents-server/src/languages/translations/english.yaml +9 -1
- package/apps/agents-server/src/message-providers/email/stalwart/parseInboundStalwartEmail.ts +17 -2
- package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatConstants.ts +9 -0
- package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatIdentity.ts +28 -0
- package/apps/agents-server/src/utils/agentGoalChat/appendAgentGoalChatNote.ts +43 -0
- package/apps/agents-server/src/utils/agentGoalChat/canAccessAgentGoalChat.ts +14 -0
- package/apps/agents-server/src/utils/agentGoalChat/createAgentGoalChatNoteContent.ts +69 -0
- package/apps/agents-server/src/utils/agentGoalChat/ensureAgentGoalChat.ts +66 -0
- package/apps/agents-server/src/utils/agentGoalChat/prependAgentGoalChatSummarySeed.ts +40 -0
- package/apps/agents-server/src/utils/agentGoalChat/recordAgentGoalChatLifecycleNote.ts +36 -0
- package/apps/agents-server/src/utils/agentGoalChat/resolveAgentGoalChatOwnerUserId.ts +104 -0
- package/apps/agents-server/src/utils/agentGoalChat/scheduleAgentGoalChatModifiedNote.ts +82 -0
- package/apps/agents-server/src/utils/agentGoalChat.ts +19 -0
- package/apps/agents-server/src/utils/agentProjects/AgentProjectInfo.ts +10 -1
- package/apps/agents-server/src/utils/agentProjects/AgentProjectReferenceInfo.ts +5 -2
- package/apps/agents-server/src/utils/agentProjects/agentProjectFileNames.ts +21 -0
- package/apps/agents-server/src/utils/agentProjects/agentProjectHrefs.ts +20 -11
- package/apps/agents-server/src/utils/agentProjects/agentProjectsPaths.ts +15 -5
- package/apps/agents-server/src/utils/agentProjects/createAgentProjectInitials.ts +36 -0
- package/apps/agents-server/src/utils/agentProjects/createAgentProjectMarkdownReferences.ts +11 -9
- package/apps/agents-server/src/utils/agentProjects/createAgentProjectsDnsRecordsSection.ts +113 -0
- package/apps/agents-server/src/utils/agentProjects/createStaticAgentProjectServer.ts +2 -6
- package/apps/agents-server/src/utils/agentProjects/humanizeAgentProjectName.ts +25 -0
- package/apps/agents-server/src/utils/agentProjects/listAgentProjectChatReferences.ts +10 -3
- package/apps/agents-server/src/utils/agentProjects/parseAgentProjectIndexHtml.ts +167 -0
- package/apps/agents-server/src/utils/agentProjects/readAgentProjectIndexHtmlProfile.ts +24 -0
- package/apps/agents-server/src/utils/agentProjects/readAgentProjectReadme.ts +3 -53
- package/apps/agents-server/src/utils/agentProjects/readAgentProjectRootTextFile.ts +73 -0
- package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectFaviconRelativePath.ts +108 -0
- package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectInfo.ts +12 -3
- package/apps/agents-server/src/utils/agentProjects/{resolveAgentProjectReadmeProfile.ts → resolveAgentProjectProfile.ts} +33 -33
- package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectPublicUrls.ts +34 -0
- package/apps/agents-server/src/utils/bookLanguageDocumentation/createBookLanguageDocumentationPdfResponse.ts +19 -17
- package/apps/agents-server/src/utils/chatTasksAdmin.ts +9 -0
- package/apps/agents-server/src/utils/dnsRecords/DnsRecordInstruction.ts +20 -0
- package/apps/agents-server/src/utils/dnsRecords/DnsRecordsSection.ts +77 -0
- package/apps/agents-server/src/utils/dnsRecords/createServerDnsRecordsSections.ts +58 -0
- package/apps/agents-server/src/utils/dnsRecords/createServerDomainDnsRecordsSection.ts +48 -0
- package/apps/agents-server/src/utils/dnsRecords/dnsRecordGroups.ts +52 -0
- package/apps/agents-server/src/utils/dnsRecords/resolveDnsRecordBatchPlan.ts +47 -1
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/adminChatTaskSqlQuery.ts +41 -36
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskFallbackRows.ts +3 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskSqlRows.ts +2 -0
- package/apps/agents-server/src/utils/localChatRunner/parseLocalTeamConversations.ts +281 -0
- package/apps/agents-server/src/utils/localChatRunner/persistLocalTeamConversations.ts +71 -0
- package/apps/agents-server/src/utils/localChatRunner/prepareLocalTeamConversationWorkspace.ts +233 -0
- package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +37 -6
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/insertManagedServerRegistryRow.ts +2 -2
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerCoreAgents.ts +7 -6
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +5 -4
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerMetadata.ts +3 -2
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerUsers.ts +3 -2
- package/apps/agents-server/src/utils/serverManagement/deleteManagedServer.ts +2 -2
- package/apps/agents-server/src/utils/stalwart/createEmailDnsRecordsSection.ts +53 -0
- package/apps/agents-server/src/utils/userChat/UserChatRecord.ts +13 -0
- package/apps/agents-server/src/utils/userChat/UserChatSource.ts +14 -0
- package/apps/agents-server/src/utils/userChat/createUserChatSummary.ts +10 -2
- package/apps/agents-server/src/utils/userChat/finalizeUserChatJob.ts +3 -2
- package/apps/agents-server/src/utils/userChat/getUserChat.ts +16 -1
- package/apps/agents-server/src/utils/userChat/getUserChatForJobRunner.ts +31 -0
- package/apps/agents-server/src/utils/userChat/listUserChats.ts +113 -110
- package/apps/agents-server/src/utils/userChat/persistFrozenUserChat.ts +21 -6
- package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +2 -6
- package/apps/agents-server/src/utils/userChat/runUserChatJob.ts +2 -6
- package/apps/agents-server/src/utils/userChat/teamMemberUserChatContext.ts +63 -0
- package/apps/agents-server/src/utils/userChat.ts +5 -1
- package/apps/agents-server/src/utils/userChatClient/cancelAgentUserTimeout.ts +2 -2
- package/apps/agents-server/src/utils/userChatClient/fetchAgentUserTimeouts.ts +2 -2
- package/apps/agents-server/src/utils/userChatClient.ts +9 -31
- package/apps/agents-server/src/utils/userChatTimeout/UserChatTimeoutRecord.ts +10 -2
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/claimNextDueUserChatTimeout.ts +28 -25
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/getAgentScopedUserChatTimeout.ts +8 -4
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/listAgentUserChatTimeouts.ts +4 -1
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/recoverExpiredRunningUserChatTimeouts.ts +3 -2
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +53 -0
- package/esm/index.es.js +1534 -401
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +7 -1
- package/esm/scripts/run-agent-messages/messages/buildAgentTeamPromptSection.d.ts +12 -0
- package/esm/scripts/run-agent-messages/messages/finalizeAgentTeamConversationWorkspace.d.ts +16 -0
- package/esm/scripts/run-agent-messages/messages/loadAgentTeamConversationWorkspace.d.ts +6 -0
- package/esm/scripts/run-codex-prompts/common/normalizeLineEndingsInChangedFiles.d.ts +2 -3
- package/esm/scripts/run-codex-prompts/git/coderCommitScope.d.ts +31 -0
- package/esm/scripts/run-codex-prompts/git/coderGitSync.d.ts +15 -2
- package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +9 -3
- package/esm/scripts/run-codex-prompts/git/workingTreeChanges.d.ts +40 -0
- package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +1 -1
- package/esm/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +5 -5
- package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiTerminalFrameUpdate.d.ts +27 -0
- package/esm/src/avatars/renderAvatarVisualTerminalText.d.ts +80 -0
- package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +54 -0
- package/esm/src/book-3.0/AgentTeamConversationWorkspace.d.ts +85 -0
- package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +3 -2
- package/esm/src/book-components/Chat/utils/renderMarkdown.d.ts +12 -3
- package/esm/src/cli/cli-commands/coder/boilerplateCount.d.ts +1 -1
- package/esm/src/cli/cli-commands/coder/generate-boilerplates.d.ts +1 -1
- package/esm/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.d.ts → npm/$askForNpmPackageInstallationApproval.d.ts} +2 -2
- package/{umd/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.d.ts → esm/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.d.ts} +2 -3
- package/esm/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.d.ts +12 -0
- package/esm/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.d.ts +9 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +9 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +14 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +12 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +10 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.d.ts +39 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.d.ts +26 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.d.ts +7 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.d.ts +7 -0
- package/esm/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.d.ts +3 -3
- package/esm/src/utils/agents/terminalAgentAvatarVisual.d.ts +5 -2
- package/esm/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +6 -0
- package/esm/src/utils/ascii-art/createAnsiColorCode.d.ts +46 -0
- package/esm/src/utils/misc/debounce.d.ts +4 -2
- package/esm/src/utils/misc/debounce.test.d.ts +1 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/avatars/renderAvatarVisualTerminalText.ts +249 -0
- package/src/avatars/types/AvatarVisualDefinition.ts +60 -0
- package/src/avatars/visuals/asciiOctopusAvatarVisual.ts +144 -22
- package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +4 -4
- package/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.ts +1 -4
- package/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.ts +4 -17
- package/src/book-3.0/AgentTeamConversationWorkspace.ts +172 -0
- package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +56 -55
- package/src/book-components/Chat/Chat/Chat.module.css +1 -8
- package/src/book-components/Chat/Chat/ChatMessageMap.tsx +8 -4
- package/src/book-components/Chat/Chat/ChatProps.tsx +3 -2
- package/src/book-components/Chat/MarkdownContent/MarkdownContent.module.css +14 -14
- package/src/book-components/Chat/save/react/exports/chat-preview-2025-10-13 (1).jsx +95 -5
- package/src/book-components/Chat/utils/renderMarkdown.ts +535 -89
- package/src/cli/cli-commands/coder/add.ts +3 -3
- package/src/cli/cli-commands/coder/boilerplateCount.ts +1 -1
- package/src/cli/cli-commands/coder/generate-boilerplates.ts +27 -27
- package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +5 -4
- package/src/cli/cli-commands/coder/init.ts +3 -3
- package/src/cli/cli-commands/coder/run.ts +10 -2
- package/src/cli/cli-commands/common/coderGitSyncCliOptions.ts +6 -2
- package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +2 -2
- package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +4 -4
- package/src/cli/cli-commands/common/harness/$resolveInstalledHarnessVersion.ts +2 -2
- package/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.ts → npm/$askForNpmPackageInstallationApproval.ts} +3 -3
- package/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.ts +49 -0
- package/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.ts +25 -0
- package/src/cli/cli-commands/common/{harness/isHarnessVersionOutdated.ts → npm/isNpmPackageVersionOutdated.ts} +6 -4
- package/src/cli/cli-commands/common/projectInitialization.ts +10 -1
- package/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.ts +73 -0
- package/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.ts +94 -0
- package/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.ts +223 -0
- package/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.ts +53 -0
- package/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.ts +46 -0
- package/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.ts +32 -0
- package/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.ts +22 -0
- package/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.ts +47 -0
- package/src/commands/FORMAT/formatCommandParser.ts +2 -2
- package/src/llm-providers/openai/utils/buildToolInvocationScript.ts +21 -18
- package/src/other/templates/getTemplatesPipelineCollection.ts +976 -668
- package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +80 -27
- package/src/utils/agents/terminalAgentAvatarVisual.ts +31 -3
- package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +9 -109
- package/src/utils/ascii-art/createAnsiColorCode.ts +132 -0
- package/src/utils/misc/debounce.ts +26 -5
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -0
- package/umd/index.umd.js +1533 -400
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +7 -1
- package/umd/scripts/run-agent-messages/messages/buildAgentTeamPromptSection.d.ts +12 -0
- package/umd/scripts/run-agent-messages/messages/finalizeAgentTeamConversationWorkspace.d.ts +16 -0
- package/umd/scripts/run-agent-messages/messages/loadAgentTeamConversationWorkspace.d.ts +6 -0
- package/umd/scripts/run-codex-prompts/common/normalizeLineEndingsInChangedFiles.d.ts +2 -3
- package/umd/scripts/run-codex-prompts/git/coderCommitScope.d.ts +31 -0
- package/umd/scripts/run-codex-prompts/git/coderGitSync.d.ts +15 -2
- package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +9 -3
- package/umd/scripts/run-codex-prompts/git/workingTreeChanges.d.ts +40 -0
- package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +1 -1
- package/umd/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +5 -5
- package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiTerminalFrameUpdate.d.ts +27 -0
- package/umd/src/avatars/renderAvatarVisualTerminalText.d.ts +80 -0
- package/umd/src/avatars/renderAvatarVisualTerminalText.test.d.ts +1 -0
- package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +54 -0
- package/umd/src/book-3.0/AgentTeamConversationWorkspace.d.ts +85 -0
- package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +3 -2
- package/umd/src/book-components/Chat/utils/renderMarkdown.d.ts +12 -3
- package/umd/src/cli/cli-commands/coder/boilerplateCount.d.ts +1 -1
- package/umd/src/cli/cli-commands/coder/generate-boilerplates.d.ts +1 -1
- package/umd/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.d.ts → npm/$askForNpmPackageInstallationApproval.d.ts} +2 -2
- package/{esm/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.d.ts → umd/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.d.ts} +2 -3
- package/umd/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.d.ts +12 -0
- package/umd/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.d.ts +9 -0
- package/umd/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +9 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +14 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +12 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +10 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.d.ts +39 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.d.ts +26 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.d.ts +7 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.d.ts +7 -0
- package/umd/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.d.ts +3 -3
- package/umd/src/utils/agents/terminalAgentAvatarVisual.d.ts +5 -2
- package/umd/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +6 -0
- package/umd/src/utils/ascii-art/createAnsiColorCode.d.ts +46 -0
- package/umd/src/utils/misc/debounce.d.ts +4 -2
- package/umd/src/utils/misc/debounce.test.d.ts +1 -0
- package/umd/src/version.d.ts +1 -1
- package/apps/agents-server/scripts/ignore-kill-eperm.js +0 -31
- package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/actions/route.ts +0 -103
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsClient.tsx +0 -43
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsEditDialog.tsx +0 -98
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsFiltersCard.tsx +0 -75
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsHeader.tsx +0 -53
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsSummaryMetrics.tsx +0 -70
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableCard.tsx +0 -58
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableRow.tsx +0 -242
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/loading.tsx +0 -15
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/page.tsx +0 -28
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/useAgentTimeoutsClientState.ts +0 -769
- package/apps/agents-server/src/components/AgentProjectDnsInstructions/AgentProjectDnsInstructions.tsx +0 -182
- package/apps/agents-server/src/utils/userChatClient/runAgentUserTimeoutBulkAction.ts +0 -24
- package/apps/agents-server/src/utils/userChatClient/updateAgentUserTimeout.ts +0 -25
- package/esm/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.d.ts +0 -11
- package/esm/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.d.ts +0 -9
- package/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.ts +0 -34
- package/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.ts +0 -28
- package/umd/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.d.ts +0 -11
- package/umd/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.d.ts +0 -9
- /package/esm/src/{cli/cli-commands/common/harness/extractHarnessVersionFromOutput.test.d.ts → avatars/renderAvatarVisualTerminalText.test.d.ts} +0 -0
- /package/esm/src/cli/cli-commands/common/{harness/isHarnessVersionOutdated.test.d.ts → npm/$resolveLatestNpmPackageVersion.test.d.ts} +0 -0
- /package/{umd/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.test.d.ts → esm/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.test.d.ts} +0 -0
- /package/{umd/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.test.d.ts → esm/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.test.d.ts} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spaceTrim } from 'spacetrim';
|
|
1
2
|
import type { Client } from 'pg';
|
|
2
3
|
import { importRuntimeModule } from './importRuntimeModule';
|
|
3
4
|
import type { DatabaseMigrationAppliedBy, DatabaseMigrationLogger } from './runDatabaseMigrations';
|
|
@@ -219,42 +220,42 @@ export async function migratePrefix(options: MigratePrefixOptions): Promise<numb
|
|
|
219
220
|
* @private function of runDatabaseMigrations
|
|
220
221
|
*/
|
|
221
222
|
async function ensureMigrationsTableSchema(options: EnsureMigrationsTableSchemaOptions): Promise<void> {
|
|
222
|
-
await options.client.query(`
|
|
223
|
+
await options.client.query(spaceTrim(`
|
|
223
224
|
CREATE TABLE IF NOT EXISTS ${options.migrationsTableIdentifier} (
|
|
224
225
|
"filename" TEXT PRIMARY KEY,
|
|
225
226
|
"appliedAt" TIMESTAMP WITH TIME ZONE DEFAULT now(),
|
|
226
227
|
"appliedBy" TEXT NOT NULL DEFAULT '${options.manualAppliedByDefault}'
|
|
227
228
|
);
|
|
228
|
-
`);
|
|
229
|
+
`));
|
|
229
230
|
|
|
230
|
-
await options.client.query(`
|
|
231
|
+
await options.client.query(spaceTrim(`
|
|
231
232
|
ALTER TABLE ${options.migrationsTableIdentifier}
|
|
232
233
|
ADD COLUMN IF NOT EXISTS "appliedBy" TEXT;
|
|
233
|
-
`);
|
|
234
|
+
`));
|
|
234
235
|
|
|
235
236
|
await options.client.query(
|
|
236
|
-
`
|
|
237
|
+
spaceTrim(`
|
|
237
238
|
UPDATE ${options.migrationsTableIdentifier}
|
|
238
239
|
SET "appliedBy" = $1
|
|
239
240
|
WHERE "appliedBy" IS NULL;
|
|
240
|
-
|
|
241
|
+
`),
|
|
241
242
|
[options.manualAppliedByDefault],
|
|
242
243
|
);
|
|
243
244
|
|
|
244
|
-
await options.client.query(`
|
|
245
|
+
await options.client.query(spaceTrim(`
|
|
245
246
|
ALTER TABLE ${options.migrationsTableIdentifier}
|
|
246
247
|
ALTER COLUMN "appliedBy" SET DEFAULT '${options.manualAppliedByDefault}';
|
|
247
|
-
`);
|
|
248
|
+
`));
|
|
248
249
|
|
|
249
|
-
await options.client.query(`
|
|
250
|
+
await options.client.query(spaceTrim(`
|
|
250
251
|
ALTER TABLE ${options.migrationsTableIdentifier}
|
|
251
252
|
ALTER COLUMN "appliedBy" SET NOT NULL;
|
|
252
|
-
`);
|
|
253
|
+
`));
|
|
253
254
|
|
|
254
|
-
await options.client.query(`
|
|
255
|
+
await options.client.query(spaceTrim(`
|
|
255
256
|
ALTER TABLE ${options.migrationsTableIdentifier}
|
|
256
257
|
ENABLE ROW LEVEL SECURITY;
|
|
257
|
-
`);
|
|
258
|
+
`));
|
|
258
259
|
}
|
|
259
260
|
|
|
260
261
|
/**
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
ALTER TABLE "prefix_UserChat"
|
|
2
|
+
DROP CONSTRAINT IF EXISTS "prefix_UserChat_source_check";
|
|
3
|
+
|
|
4
|
+
ALTER TABLE "prefix_UserChat"
|
|
5
|
+
ADD CONSTRAINT "prefix_UserChat_source_check"
|
|
6
|
+
CHECK ("source" IN ('WEB_UI', 'OPENAI_API', 'TEAM_MEMBER', 'EMAIL', 'AGENT_GOAL'));
|
|
7
|
+
|
|
8
|
+
CREATE INDEX IF NOT EXISTS "prefix_UserChat_agentPermanentId_goalSource_idx"
|
|
9
|
+
ON "prefix_UserChat" ("agentPermanentId")
|
|
10
|
+
WHERE "source" = 'AGENT_GOAL';
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export const RESERVED_PATHS: readonly string[] = [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
] as const;
|
|
2
|
+
* Reserved paths that should not be treated as agent names.
|
|
3
|
+
* This file is auto-generated by scripts/generate-reserved-paths.js
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
6
|
+
*
|
|
7
|
+
* @see /apps/agents-server/src/app - source directory for routes
|
|
8
|
+
* @see /apps/agents-server/public - source directory for static files
|
|
9
|
+
* @see /apps/agents-server/src/middleware.ts - where this is used
|
|
10
|
+
*/
|
|
11
|
+
export const RESERVED_PATHS: readonly string[] = [
|
|
12
|
+
"_data",
|
|
13
|
+
"_next",
|
|
14
|
+
"admin",
|
|
15
|
+
"agents",
|
|
16
|
+
"api",
|
|
17
|
+
"dashboard",
|
|
18
|
+
"docs",
|
|
19
|
+
"embed",
|
|
20
|
+
"experiments",
|
|
21
|
+
"favicon.ico",
|
|
22
|
+
"fonts",
|
|
23
|
+
"humans.txt",
|
|
24
|
+
"logo-blue-white-256.png",
|
|
25
|
+
"manifest.webmanifest",
|
|
26
|
+
"openapi.json",
|
|
27
|
+
"promptbook-logo-blue.png",
|
|
28
|
+
"promptbook-logo-white.png",
|
|
29
|
+
"recycle-bin",
|
|
30
|
+
"restricted",
|
|
31
|
+
"robots.txt",
|
|
32
|
+
"s3",
|
|
33
|
+
"search",
|
|
34
|
+
"security.txt",
|
|
35
|
+
"sitemap.xml",
|
|
36
|
+
"sounds",
|
|
37
|
+
"story",
|
|
38
|
+
"superadmin",
|
|
39
|
+
"sw.js",
|
|
40
|
+
"swagger",
|
|
41
|
+
"system",
|
|
42
|
+
"test"
|
|
43
|
+
] as const;
|
|
@@ -14,7 +14,15 @@ export const SERVER_TRANSLATION_KEYS = [
|
|
|
14
14
|
'common.chat',
|
|
15
15
|
'chat.answerDurationLabel',
|
|
16
16
|
'common.book',
|
|
17
|
-
'common.
|
|
17
|
+
'common.goalChat',
|
|
18
|
+
'goalChat.noticeTitle',
|
|
19
|
+
'goalChat.noticeDescription',
|
|
20
|
+
'goalChat.plannedMessagesTitle',
|
|
21
|
+
'goalChat.plannedMessagesEmptyLabel',
|
|
22
|
+
'goalChat.plannedMessagesLoadErrorLabel',
|
|
23
|
+
'goalChat.plannedMessageDefaultLabel',
|
|
24
|
+
'goalChat.plannedMessageCancelLabel',
|
|
25
|
+
'goalChat.plannedMessageCancellingLabel',
|
|
18
26
|
'common.projects',
|
|
19
27
|
'common.more',
|
|
20
28
|
'chatEnterBehavior.sectionEyebrow',
|
|
@@ -8,7 +8,15 @@ common.profile: Profil
|
|
|
8
8
|
common.chat: Chat
|
|
9
9
|
chat.answerDurationLabel: 'Odpověď za {duration}'
|
|
10
10
|
common.book: Book
|
|
11
|
-
common.
|
|
11
|
+
common.goalChat: Cíl
|
|
12
|
+
goalChat.noticeTitle: Toto je cílový chat agenta
|
|
13
|
+
goalChat.noticeDescription: Agent si sem píše sám a plánuje práci ke svému cíli, proto je toto vlákno pro lidi jen ke čtení.
|
|
14
|
+
goalChat.plannedMessagesTitle: Naplánované zprávy
|
|
15
|
+
goalChat.plannedMessagesEmptyLabel: Žádné naplánované zprávy. Agent se probudí, až mu někdo napíše.
|
|
16
|
+
goalChat.plannedMessagesLoadErrorLabel: Naplánované zprávy se nepodařilo načíst.
|
|
17
|
+
goalChat.plannedMessageDefaultLabel: Naplánované probuzení
|
|
18
|
+
goalChat.plannedMessageCancelLabel: Zrušit
|
|
19
|
+
goalChat.plannedMessageCancellingLabel: Ruším
|
|
12
20
|
common.projects: Projekty
|
|
13
21
|
common.more: Více
|
|
14
22
|
chatEnterBehavior.sectionEyebrow: Klávesové zkratky
|
|
@@ -8,7 +8,15 @@ common.profile: Profile
|
|
|
8
8
|
common.chat: Chat
|
|
9
9
|
chat.answerDurationLabel: '{duration} to answer'
|
|
10
10
|
common.book: Book
|
|
11
|
-
common.
|
|
11
|
+
common.goalChat: Goal
|
|
12
|
+
goalChat.noticeTitle: This is the agent's goal chat
|
|
13
|
+
goalChat.noticeDescription: The agent writes here on its own to plan work towards its goal, so this thread is read-only for people.
|
|
14
|
+
goalChat.plannedMessagesTitle: Planned messages
|
|
15
|
+
goalChat.plannedMessagesEmptyLabel: No planned messages. The agent will wake up only when someone writes to it.
|
|
16
|
+
goalChat.plannedMessagesLoadErrorLabel: Failed to load planned messages.
|
|
17
|
+
goalChat.plannedMessageDefaultLabel: Planned wake-up
|
|
18
|
+
goalChat.plannedMessageCancelLabel: Cancel
|
|
19
|
+
goalChat.plannedMessageCancellingLabel: Cancelling
|
|
12
20
|
common.projects: Projects
|
|
13
21
|
common.more: More
|
|
14
22
|
chatEnterBehavior.sectionEyebrow: Keybindings
|
package/apps/agents-server/src/message-providers/email/stalwart/parseInboundStalwartEmail.ts
CHANGED
|
@@ -14,6 +14,21 @@ export type ParsedInboundStalwartEmail = {
|
|
|
14
14
|
readonly queueId: string | null;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Rebuilds one RFC 5322 header line from a Stalwart header tuple.
|
|
19
|
+
*
|
|
20
|
+
* Stalwart reports every header exactly as it stood on the wire, so its value already carries the
|
|
21
|
+
* space after the colon and its own terminating line break, while folded values keep their inner
|
|
22
|
+
* line breaks. Emitting such a value verbatim would write `Name: value` with a doubled space and,
|
|
23
|
+
* once the tuples are joined with another line break, an empty line after every header - which ends
|
|
24
|
+
* the header block right after the first one and turns all remaining headers into message body.
|
|
25
|
+
*/
|
|
26
|
+
function createInboundStalwartHeaderLine([name, value]: readonly [string, string]): string {
|
|
27
|
+
const headerValue = value.replace(/[\r\n]+$/, '');
|
|
28
|
+
const separator = /^[ \t]/.test(headerValue) ? '' : ' ';
|
|
29
|
+
return `${name}:${separator}${headerValue}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
/**
|
|
18
33
|
* Reconstructs an RFC 5322 message from Stalwart's DATA-stage MTA hook payload.
|
|
19
34
|
*/
|
|
@@ -38,7 +53,7 @@ export async function parseInboundStalwartEmail(
|
|
|
38
53
|
.map((recipient) => recipient.address.trim())
|
|
39
54
|
.filter(Boolean);
|
|
40
55
|
|
|
41
|
-
if (!headers || typeof contents !== 'string' || envelopeRecipients.length === 0) {
|
|
56
|
+
if (!headers?.length || typeof contents !== 'string' || envelopeRecipients.length === 0) {
|
|
42
57
|
throw new ParseError(
|
|
43
58
|
spaceTrim(`
|
|
44
59
|
Stalwart sent an incomplete DATA-stage MTA hook payload.
|
|
@@ -49,7 +64,7 @@ export async function parseInboundStalwartEmail(
|
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
const rawEmail = `${[...(payload.message?.serverHeaders || []), ...headers]
|
|
52
|
-
.map(
|
|
67
|
+
.map(createInboundStalwartHeaderLine)
|
|
53
68
|
.join('\r\n')}\r\n\r\n${contents}`;
|
|
54
69
|
|
|
55
70
|
let email: InboundEmail;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefix of every goal-chat id.
|
|
3
|
+
*
|
|
4
|
+
* Goal-chat ids are derived deterministically from the agent permanent id so that exactly one
|
|
5
|
+
* goal chat can ever exist per agent, and so that any layer holding only a `chatId`
|
|
6
|
+
* (SQL task queries, admin task rows, UI rows) can recognize a goal chat without extra lookups.
|
|
7
|
+
*/
|
|
8
|
+
export const AGENT_GOAL_CHAT_ID_PREFIX = 'goal-';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Builds the deterministic singleton goal-chat id of one agent.
|
|
12
|
+
*
|
|
13
|
+
* @param agentPermanentId - Permanent id of the agent owning the goal chat.
|
|
14
|
+
* @returns Stable goal-chat id.
|
|
15
|
+
*/
|
|
16
|
+
export function buildAgentGoalChatId(agentPermanentId: string): string {
|
|
17
|
+
return `${AGENT_GOAL_CHAT_ID_PREFIX}${agentPermanentId}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Returns `true` when one chat id belongs to an agent goal chat.
|
|
22
|
+
*
|
|
23
|
+
* @param chatId - Chat id to inspect.
|
|
24
|
+
* @returns `true` for goal chats.
|
|
25
|
+
*/
|
|
26
|
+
export function isAgentGoalChatId(chatId: string | null | undefined): boolean {
|
|
27
|
+
return typeof chatId === 'string' && chatId.startsWith(AGENT_GOAL_CHAT_ID_PREFIX);
|
|
28
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ChatMessage } from '@promptbook-local/types';
|
|
2
|
+
import { $randomBase58 } from '../../../../../src/utils/random/$randomBase58';
|
|
3
|
+
import type { UserChatRecord } from '../userChat/UserChatRecord';
|
|
4
|
+
import { mutateUserChat } from '../userChat/mutateUserChat';
|
|
5
|
+
import { AGENT_GOAL_CHAT_MESSAGE_ID_LENGTH } from './agentGoalChatConstants';
|
|
6
|
+
import { ensureAgentGoalChat } from './ensureAgentGoalChat';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Appends one agent-authored note to the singleton goal chat of an agent.
|
|
10
|
+
*
|
|
11
|
+
* Goal chats are written only by the agent and by the server acting on its behalf, so every note is
|
|
12
|
+
* stored as a completed `AGENT` message.
|
|
13
|
+
*
|
|
14
|
+
* @param options - Target agent and note content.
|
|
15
|
+
* @returns Updated goal-chat record.
|
|
16
|
+
*/
|
|
17
|
+
export async function appendAgentGoalChatNote(options: {
|
|
18
|
+
readonly agentPermanentId: string;
|
|
19
|
+
readonly content: string;
|
|
20
|
+
}): Promise<UserChatRecord> {
|
|
21
|
+
const goalChat = await ensureAgentGoalChat(options.agentPermanentId);
|
|
22
|
+
const nowIso = new Date().toISOString() as NonNullable<ChatMessage['createdAt']>;
|
|
23
|
+
|
|
24
|
+
return mutateUserChat({
|
|
25
|
+
userId: goalChat.userId,
|
|
26
|
+
agentPermanentId: goalChat.agentPermanentId,
|
|
27
|
+
chatId: goalChat.id,
|
|
28
|
+
mutate: (currentChat) => ({
|
|
29
|
+
messages: [
|
|
30
|
+
...currentChat.messages,
|
|
31
|
+
{
|
|
32
|
+
id: $randomBase58(AGENT_GOAL_CHAT_MESSAGE_ID_LENGTH),
|
|
33
|
+
sender: 'AGENT',
|
|
34
|
+
content: options.content,
|
|
35
|
+
createdAt: nowIso,
|
|
36
|
+
isComplete: true,
|
|
37
|
+
lifecycleState: 'completed',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
lastMessageAt: nowIso,
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getCurrentUser } from '../getCurrentUser';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolves whether the current request may read the goal chat of an agent.
|
|
5
|
+
*
|
|
6
|
+
* Goal chats expose the agent's own planning, so they follow exactly the same rule as the agent
|
|
7
|
+
* source book page (`/agents/<agentName>/book`): a signed-in user is required. Keeping the rule in
|
|
8
|
+
* one place makes the two surfaces impossible to drift apart.
|
|
9
|
+
*
|
|
10
|
+
* @returns `true` when the current identity may read agent goal chats.
|
|
11
|
+
*/
|
|
12
|
+
export async function canAccessAgentGoalChat(): Promise<boolean> {
|
|
13
|
+
return Boolean(await getCurrentUser());
|
|
14
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { spaceTrim } from 'spacetrim';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lifecycle events of an agent that are recorded in its goal chat.
|
|
5
|
+
*/
|
|
6
|
+
export type AgentGoalChatLifecycleEvent = 'CREATED' | 'MODIFIED';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds the goal-chat note left when an agent is created or its book is modified.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Lifecycle event and the agent name shown in the note.
|
|
12
|
+
* @returns Note content stored as one agent message.
|
|
13
|
+
*/
|
|
14
|
+
export function createAgentGoalChatLifecycleNoteContent(options: {
|
|
15
|
+
readonly event: AgentGoalChatLifecycleEvent;
|
|
16
|
+
readonly agentName: string;
|
|
17
|
+
}): string {
|
|
18
|
+
if (options.event === 'CREATED') {
|
|
19
|
+
return spaceTrim(`
|
|
20
|
+
🌱 I was created as \`${options.agentName}\`.
|
|
21
|
+
|
|
22
|
+
From now on I keep my own plans towards my goal in this thread.
|
|
23
|
+
`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return spaceTrim(`
|
|
27
|
+
📝 My book was updated, so \`${options.agentName}\` may work differently from now on.
|
|
28
|
+
|
|
29
|
+
I should re-check my plans towards my goal against the new book.
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Builds the goal-chat note left when a planned message is scheduled.
|
|
35
|
+
*
|
|
36
|
+
* @param options - Planned-message identity, due time, and optional payload message.
|
|
37
|
+
* @returns Note content stored as one agent message.
|
|
38
|
+
*/
|
|
39
|
+
export function createAgentGoalChatPlannedMessageNoteContent(options: {
|
|
40
|
+
readonly timeoutId: string;
|
|
41
|
+
readonly dueAt: string;
|
|
42
|
+
readonly message?: string | null;
|
|
43
|
+
}): string {
|
|
44
|
+
const plannedMessage = options.message?.trim() || '';
|
|
45
|
+
|
|
46
|
+
return spaceTrim(
|
|
47
|
+
(block) => `
|
|
48
|
+
⏳ I planned a message that will wake me up at ${options.dueAt}.
|
|
49
|
+
|
|
50
|
+
${plannedMessage ? block(plannedMessage) : ''}
|
|
51
|
+
|
|
52
|
+
timeoutId: ${options.timeoutId}
|
|
53
|
+
`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Builds the goal-chat note left when a planned message is cancelled.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Planned-message identity.
|
|
61
|
+
* @returns Note content stored as one agent message.
|
|
62
|
+
*/
|
|
63
|
+
export function createAgentGoalChatCancelledPlannedMessageNoteContent(options: {
|
|
64
|
+
readonly timeoutId: string;
|
|
65
|
+
}): string {
|
|
66
|
+
return spaceTrim(`
|
|
67
|
+
🚫 I cancelled the planned message \`${options.timeoutId}\`, so it will not wake me up anymore.
|
|
68
|
+
`);
|
|
69
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { UserChatRecord } from '../userChat/UserChatRecord';
|
|
2
|
+
import { USER_CHAT_SOURCES } from '../userChat/UserChatSource';
|
|
3
|
+
import { createUserChat } from '../userChat/createUserChat';
|
|
4
|
+
import { getUserChat } from '../userChat/getUserChat';
|
|
5
|
+
import { AGENT_GOAL_CHAT_TITLE } from './agentGoalChatConstants';
|
|
6
|
+
import { buildAgentGoalChatId } from './agentGoalChatIdentity';
|
|
7
|
+
import { resolveAgentGoalChatOwnerUserId } from './resolveAgentGoalChatOwnerUserId';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Loads the singleton goal chat of one agent, creating it on first use.
|
|
11
|
+
*
|
|
12
|
+
* The chat id is derived from the agent permanent id, so concurrent callers converge on the very
|
|
13
|
+
* same row and an agent can never end up with two goal chats.
|
|
14
|
+
*
|
|
15
|
+
* @param agentPermanentId - Permanent id of the agent owning the goal chat.
|
|
16
|
+
* @returns Persisted goal-chat record.
|
|
17
|
+
*/
|
|
18
|
+
export async function ensureAgentGoalChat(agentPermanentId: string): Promise<UserChatRecord> {
|
|
19
|
+
const chatId = buildAgentGoalChatId(agentPermanentId);
|
|
20
|
+
const existingGoalChat = await loadAgentGoalChat(agentPermanentId, chatId);
|
|
21
|
+
|
|
22
|
+
if (existingGoalChat) {
|
|
23
|
+
return existingGoalChat;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
return await createUserChat({
|
|
28
|
+
chatId,
|
|
29
|
+
userId: await resolveAgentGoalChatOwnerUserId(agentPermanentId),
|
|
30
|
+
agentPermanentId,
|
|
31
|
+
source: USER_CHAT_SOURCES.AGENT_GOAL,
|
|
32
|
+
title: AGENT_GOAL_CHAT_TITLE,
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
// Note: Another request may have created the very same singleton row in the meantime
|
|
36
|
+
const racedGoalChat = await loadAgentGoalChat(agentPermanentId, chatId);
|
|
37
|
+
|
|
38
|
+
if (racedGoalChat) {
|
|
39
|
+
return racedGoalChat;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Loads the stored goal chat of one agent by its deterministic id.
|
|
48
|
+
*
|
|
49
|
+
* The stored owner is deliberately not part of the lookup: agent ownership can change after the
|
|
50
|
+
* goal chat was created, while the goal chat itself must stay the very same singleton row.
|
|
51
|
+
*
|
|
52
|
+
* @param agentPermanentId - Permanent id of the agent owning the goal chat.
|
|
53
|
+
* @param chatId - Deterministic goal-chat id.
|
|
54
|
+
* @returns Stored goal chat, or `null` when it does not exist yet.
|
|
55
|
+
*
|
|
56
|
+
* @private function of `ensureAgentGoalChat`
|
|
57
|
+
*/
|
|
58
|
+
async function loadAgentGoalChat(agentPermanentId: string, chatId: string): Promise<UserChatRecord | null> {
|
|
59
|
+
return getUserChat({
|
|
60
|
+
// Note: The access decision belongs to the callers of `ensureAgentGoalChat`
|
|
61
|
+
userId: 0,
|
|
62
|
+
viewerCanAccessAgentGoalChat: true,
|
|
63
|
+
agentPermanentId,
|
|
64
|
+
chatId,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { serializeError } from '@promptbook-local/utils';
|
|
2
|
+
import type { UserChatSummarySeed } from '../userChat/createUserChatSummary';
|
|
3
|
+
import { createUserChatSummarySeedFromChatRecord } from '../userChat/listUserChats';
|
|
4
|
+
import { ensureAgentGoalChat } from './ensureAgentGoalChat';
|
|
5
|
+
import { isAgentGoalChatId } from './agentGoalChatIdentity';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Puts the singleton goal chat of one agent on top of the chat-history list.
|
|
9
|
+
*
|
|
10
|
+
* The goal chat is not owned by the viewer and is therefore not part of the normal chat listing
|
|
11
|
+
* query, so it is resolved separately and pinned in front of every other chat.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Loaded chat seeds together with the agent and the viewer's access decision.
|
|
14
|
+
* @returns Chat seeds, with the goal chat first whenever the viewer may read it.
|
|
15
|
+
*/
|
|
16
|
+
export async function prependAgentGoalChatSummarySeed(options: {
|
|
17
|
+
readonly chatSummarySeeds: ReadonlyArray<UserChatSummarySeed>;
|
|
18
|
+
readonly agentPermanentId: string;
|
|
19
|
+
readonly isAgentGoalChatVisible: boolean;
|
|
20
|
+
}): Promise<Array<UserChatSummarySeed>> {
|
|
21
|
+
const otherChatSummarySeeds = options.chatSummarySeeds.filter(
|
|
22
|
+
(chatSummarySeed) => !isAgentGoalChatId(chatSummarySeed.id),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (!options.isAgentGoalChatVisible) {
|
|
26
|
+
return otherChatSummarySeeds;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const goalChat = await ensureAgentGoalChat(options.agentPermanentId);
|
|
31
|
+
return [createUserChatSummarySeedFromChatRecord(goalChat), ...otherChatSummarySeeds];
|
|
32
|
+
} catch (error) {
|
|
33
|
+
// Note: A missing goal chat must never break the chat list of the agent
|
|
34
|
+
console.error('[agent-goal-chat]', 'list_seed_failed', {
|
|
35
|
+
agentPermanentId: options.agentPermanentId,
|
|
36
|
+
error: serializeError(error as Error),
|
|
37
|
+
});
|
|
38
|
+
return otherChatSummarySeeds;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { serializeError } from '@promptbook-local/utils';
|
|
2
|
+
import { appendAgentGoalChatNote } from './appendAgentGoalChatNote';
|
|
3
|
+
import {
|
|
4
|
+
createAgentGoalChatLifecycleNoteContent,
|
|
5
|
+
type AgentGoalChatLifecycleEvent,
|
|
6
|
+
} from './createAgentGoalChatNoteContent';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Leaves the goal-chat note that records one agent lifecycle event.
|
|
10
|
+
*
|
|
11
|
+
* Writing the note is best-effort on purpose: creating or saving an agent must never fail because
|
|
12
|
+
* its goal chat could not be updated.
|
|
13
|
+
*
|
|
14
|
+
* @param options - Lifecycle event together with the affected agent.
|
|
15
|
+
*/
|
|
16
|
+
export async function recordAgentGoalChatLifecycleNote(options: {
|
|
17
|
+
readonly event: AgentGoalChatLifecycleEvent;
|
|
18
|
+
readonly agentPermanentId: string;
|
|
19
|
+
readonly agentName: string;
|
|
20
|
+
}): Promise<void> {
|
|
21
|
+
try {
|
|
22
|
+
await appendAgentGoalChatNote({
|
|
23
|
+
agentPermanentId: options.agentPermanentId,
|
|
24
|
+
content: createAgentGoalChatLifecycleNoteContent({
|
|
25
|
+
event: options.event,
|
|
26
|
+
agentName: options.agentName,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('[agent-goal-chat]', 'lifecycle_note_failed', {
|
|
31
|
+
event: options.event,
|
|
32
|
+
agentPermanentId: options.agentPermanentId,
|
|
33
|
+
error: serializeError(error as Error),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { spaceTrim } from 'spacetrim';
|
|
2
|
+
import { DatabaseError } from '../../../../../src/errors/DatabaseError';
|
|
3
|
+
import { $getTableName } from '../../database/$getTableName';
|
|
4
|
+
import { $provideSupabaseForServer } from '../../database/$provideSupabaseForServer';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the database user the singleton goal chat of one agent is stored under.
|
|
8
|
+
*
|
|
9
|
+
* The goal chat conceptually belongs to the agent, not to any human, but `UserChat.userId` is a
|
|
10
|
+
* non-null foreign key. The agent owner is therefore used, with the same fallback ordering the
|
|
11
|
+
* ownership migration uses when an agent has no owner assigned yet.
|
|
12
|
+
*
|
|
13
|
+
* @param agentPermanentId - Permanent id of the agent owning the goal chat.
|
|
14
|
+
* @returns Database user id used as the goal-chat owner.
|
|
15
|
+
*/
|
|
16
|
+
export async function resolveAgentGoalChatOwnerUserId(agentPermanentId: string): Promise<number> {
|
|
17
|
+
const agentOwnerUserId = await loadAgentOwnerUserId(agentPermanentId);
|
|
18
|
+
|
|
19
|
+
if (typeof agentOwnerUserId === 'number') {
|
|
20
|
+
return agentOwnerUserId;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return loadFallbackOwnerUserId(agentPermanentId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Loads the owner of one agent row.
|
|
28
|
+
*
|
|
29
|
+
* @param agentPermanentId - Permanent id of the agent.
|
|
30
|
+
* @returns Owning user id, or `null` when the agent has no owner assigned.
|
|
31
|
+
*
|
|
32
|
+
* @private function of `resolveAgentGoalChatOwnerUserId`
|
|
33
|
+
*/
|
|
34
|
+
async function loadAgentOwnerUserId(agentPermanentId: string): Promise<number | null> {
|
|
35
|
+
const supabase = $provideSupabaseForServer();
|
|
36
|
+
const agentTableName = await $getTableName('Agent');
|
|
37
|
+
const { data, error } = await supabase
|
|
38
|
+
.from(agentTableName)
|
|
39
|
+
.select('userId')
|
|
40
|
+
.eq('permanentId', agentPermanentId)
|
|
41
|
+
.maybeSingle();
|
|
42
|
+
|
|
43
|
+
if (error) {
|
|
44
|
+
throw new DatabaseError(
|
|
45
|
+
spaceTrim(`
|
|
46
|
+
Failed to load the owner of agent \`${agentPermanentId}\` for its goal chat.
|
|
47
|
+
|
|
48
|
+
**Cause:** \`${error.message}\`
|
|
49
|
+
`),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const userId = (data as { userId?: unknown } | null)?.userId;
|
|
54
|
+
return typeof userId === 'number' ? userId : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Loads the fallback goal-chat owner used when an agent has no owner assigned.
|
|
59
|
+
*
|
|
60
|
+
* Mirrors the `fallbackUser` ordering of the ownership migration so unowned agents keep a stable,
|
|
61
|
+
* predictable goal-chat owner.
|
|
62
|
+
*
|
|
63
|
+
* @param agentPermanentId - Permanent id of the agent, used only for error reporting.
|
|
64
|
+
* @returns Database user id of the fallback owner.
|
|
65
|
+
*
|
|
66
|
+
* @private function of `resolveAgentGoalChatOwnerUserId`
|
|
67
|
+
*/
|
|
68
|
+
async function loadFallbackOwnerUserId(agentPermanentId: string): Promise<number> {
|
|
69
|
+
const supabase = $provideSupabaseForServer();
|
|
70
|
+
const userTableName = await $getTableName('User');
|
|
71
|
+
const { data, error } = await supabase
|
|
72
|
+
.from(userTableName)
|
|
73
|
+
.select('id')
|
|
74
|
+
.order('isAdmin', { ascending: false })
|
|
75
|
+
.order('createdAt', { ascending: true })
|
|
76
|
+
.order('id', { ascending: true })
|
|
77
|
+
.limit(1)
|
|
78
|
+
.maybeSingle();
|
|
79
|
+
|
|
80
|
+
if (error) {
|
|
81
|
+
throw new DatabaseError(
|
|
82
|
+
spaceTrim(`
|
|
83
|
+
Failed to resolve the fallback goal-chat owner for agent \`${agentPermanentId}\`.
|
|
84
|
+
|
|
85
|
+
**Cause:** \`${error.message}\`
|
|
86
|
+
`),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const fallbackUserId = (data as { id?: unknown } | null)?.id;
|
|
91
|
+
|
|
92
|
+
if (typeof fallbackUserId !== 'number') {
|
|
93
|
+
throw new DatabaseError(
|
|
94
|
+
spaceTrim(`
|
|
95
|
+
Agent \`${agentPermanentId}\` has no owner and this server has no user to fall back to,
|
|
96
|
+
so its goal chat cannot be stored.
|
|
97
|
+
|
|
98
|
+
**Note:** Every goal chat is persisted as one \`UserChat\` row, which requires a \`userId\`.
|
|
99
|
+
`),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return fallbackUserId;
|
|
104
|
+
}
|