@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.
Files changed (296) hide show
  1. package/agents/default/developer.book +1 -0
  2. package/apps/agents-server/next.config.ts +22 -0
  3. package/apps/agents-server/package.json +6 -6
  4. package/apps/agents-server/scripts/build-agents-server.js +43 -7
  5. package/apps/agents-server/scripts/build-e2e.js +12 -2
  6. package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +30 -16
  7. package/apps/agents-server/scripts/kill-port.js +163 -0
  8. package/apps/agents-server/scripts/run-e2e-tests.js +21 -8
  9. package/apps/agents-server/scripts/run-npm.js +81 -5
  10. package/apps/agents-server/src/app/actions.ts +3 -0
  11. package/apps/agents-server/src/app/admin/email-server/page.tsx +17 -18
  12. package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +2 -0
  13. package/apps/agents-server/src/app/admin/task-manager/[taskId]/TaskManagerTaskDetailClient.tsx +2 -0
  14. package/apps/agents-server/src/app/admin/task-manager/taskManagerTaskPresentation.tsx +23 -0
  15. package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +7 -0
  16. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/[timeoutId]/route.ts +10 -153
  17. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/route.ts +9 -4
  18. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/route.ts +3 -0
  19. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +2 -0
  20. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/resolveUserChatScope.ts +8 -1
  21. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/route.ts +15 -7
  22. package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorSaving.ts +18 -28
  23. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistoryClient.tsx +19 -1
  24. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatSidebarDefault.tsx +17 -5
  25. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatNotice.tsx +23 -0
  26. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatPlannedMessages.tsx +153 -0
  27. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatPanel.tsx +6 -0
  28. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +13 -0
  29. package/apps/agents-server/src/app/agents/[agentName]/chat/ExternalUserChatAdminActions.tsx +51 -3
  30. package/apps/agents-server/src/app/agents/[agentName]/chat/TeamMemberFrozenChatPrimaryAgentLink.tsx +31 -0
  31. package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatSidebarState.ts +26 -2
  32. package/apps/agents-server/src/app/agents/[agentName]/goal/page.tsx +35 -0
  33. package/apps/agents-server/src/app/agents/[agentName]/projects/[projectName]/page.tsx +2 -2
  34. package/apps/agents-server/src/app/api/admin/dns-records/cloudflare/route.ts +26 -16
  35. package/apps/agents-server/src/app/api/emails/incoming/stalwart/route.ts +9 -2
  36. package/apps/agents-server/src/app/superadmin/servers/ServersRegistryTable.tsx +31 -39
  37. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +10 -3
  38. package/apps/agents-server/src/components/AgentProjects/AgentProjectIcon.tsx +137 -0
  39. package/apps/agents-server/src/components/AgentProjects/AgentProjectItem.tsx +26 -10
  40. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsApiTokenImportStep.tsx +5 -6
  41. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsCheckStep.tsx +6 -5
  42. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsManualStep.tsx +10 -14
  43. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsWizard.tsx +11 -20
  44. package/apps/agents-server/src/components/CloudflareDnsWizard/useCloudflareDnsRecordImport.ts +5 -6
  45. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsInstructions.tsx +91 -57
  46. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsSectionPanel.tsx +63 -0
  47. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsSectionVariantTabs.tsx +67 -0
  48. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsTable.tsx +40 -0
  49. package/apps/agents-server/src/components/Header/buildActiveAgentViewItems.ts +5 -4
  50. package/apps/agents-server/src/components/Header/createAgentViewLabel.tsx +4 -4
  51. package/apps/agents-server/src/components/Header/resolveActiveAgentNavigation.ts +2 -2
  52. package/apps/agents-server/src/components/Homepage/useAgentsListImportExportState.ts +22 -10
  53. package/apps/agents-server/src/components/_utils/generateMetaTxt.ts +1 -1
  54. package/apps/agents-server/src/database/migratePrefix.ts +13 -12
  55. package/apps/agents-server/src/database/migrations/2026-08-0100-agent-goal-chat-source.sql +10 -0
  56. package/apps/agents-server/src/generated/reservedPaths.ts +42 -42
  57. package/apps/agents-server/src/languages/ServerTranslationKeys.ts +9 -1
  58. package/apps/agents-server/src/languages/translations/czech.yaml +9 -1
  59. package/apps/agents-server/src/languages/translations/english.yaml +9 -1
  60. package/apps/agents-server/src/message-providers/email/stalwart/parseInboundStalwartEmail.ts +17 -2
  61. package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatConstants.ts +9 -0
  62. package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatIdentity.ts +28 -0
  63. package/apps/agents-server/src/utils/agentGoalChat/appendAgentGoalChatNote.ts +43 -0
  64. package/apps/agents-server/src/utils/agentGoalChat/canAccessAgentGoalChat.ts +14 -0
  65. package/apps/agents-server/src/utils/agentGoalChat/createAgentGoalChatNoteContent.ts +69 -0
  66. package/apps/agents-server/src/utils/agentGoalChat/ensureAgentGoalChat.ts +66 -0
  67. package/apps/agents-server/src/utils/agentGoalChat/prependAgentGoalChatSummarySeed.ts +40 -0
  68. package/apps/agents-server/src/utils/agentGoalChat/recordAgentGoalChatLifecycleNote.ts +36 -0
  69. package/apps/agents-server/src/utils/agentGoalChat/resolveAgentGoalChatOwnerUserId.ts +104 -0
  70. package/apps/agents-server/src/utils/agentGoalChat/scheduleAgentGoalChatModifiedNote.ts +82 -0
  71. package/apps/agents-server/src/utils/agentGoalChat.ts +19 -0
  72. package/apps/agents-server/src/utils/agentProjects/AgentProjectInfo.ts +10 -1
  73. package/apps/agents-server/src/utils/agentProjects/AgentProjectReferenceInfo.ts +5 -2
  74. package/apps/agents-server/src/utils/agentProjects/agentProjectFileNames.ts +21 -0
  75. package/apps/agents-server/src/utils/agentProjects/agentProjectHrefs.ts +20 -11
  76. package/apps/agents-server/src/utils/agentProjects/agentProjectsPaths.ts +15 -5
  77. package/apps/agents-server/src/utils/agentProjects/createAgentProjectInitials.ts +36 -0
  78. package/apps/agents-server/src/utils/agentProjects/createAgentProjectMarkdownReferences.ts +11 -9
  79. package/apps/agents-server/src/utils/agentProjects/createAgentProjectsDnsRecordsSection.ts +113 -0
  80. package/apps/agents-server/src/utils/agentProjects/createStaticAgentProjectServer.ts +2 -6
  81. package/apps/agents-server/src/utils/agentProjects/humanizeAgentProjectName.ts +25 -0
  82. package/apps/agents-server/src/utils/agentProjects/listAgentProjectChatReferences.ts +10 -3
  83. package/apps/agents-server/src/utils/agentProjects/parseAgentProjectIndexHtml.ts +167 -0
  84. package/apps/agents-server/src/utils/agentProjects/readAgentProjectIndexHtmlProfile.ts +24 -0
  85. package/apps/agents-server/src/utils/agentProjects/readAgentProjectReadme.ts +3 -53
  86. package/apps/agents-server/src/utils/agentProjects/readAgentProjectRootTextFile.ts +73 -0
  87. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectFaviconRelativePath.ts +108 -0
  88. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectInfo.ts +12 -3
  89. package/apps/agents-server/src/utils/agentProjects/{resolveAgentProjectReadmeProfile.ts → resolveAgentProjectProfile.ts} +33 -33
  90. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectPublicUrls.ts +34 -0
  91. package/apps/agents-server/src/utils/bookLanguageDocumentation/createBookLanguageDocumentationPdfResponse.ts +19 -17
  92. package/apps/agents-server/src/utils/chatTasksAdmin.ts +9 -0
  93. package/apps/agents-server/src/utils/dnsRecords/DnsRecordInstruction.ts +20 -0
  94. package/apps/agents-server/src/utils/dnsRecords/DnsRecordsSection.ts +77 -0
  95. package/apps/agents-server/src/utils/dnsRecords/createServerDnsRecordsSections.ts +58 -0
  96. package/apps/agents-server/src/utils/dnsRecords/createServerDomainDnsRecordsSection.ts +48 -0
  97. package/apps/agents-server/src/utils/dnsRecords/dnsRecordGroups.ts +52 -0
  98. package/apps/agents-server/src/utils/dnsRecords/resolveDnsRecordBatchPlan.ts +47 -1
  99. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/adminChatTaskSqlQuery.ts +41 -36
  100. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskFallbackRows.ts +3 -0
  101. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskSqlRows.ts +2 -0
  102. package/apps/agents-server/src/utils/localChatRunner/parseLocalTeamConversations.ts +281 -0
  103. package/apps/agents-server/src/utils/localChatRunner/persistLocalTeamConversations.ts +71 -0
  104. package/apps/agents-server/src/utils/localChatRunner/prepareLocalTeamConversationWorkspace.ts +233 -0
  105. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +37 -6
  106. package/apps/agents-server/src/utils/serverManagement/createManagedServer/insertManagedServerRegistryRow.ts +2 -2
  107. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerCoreAgents.ts +7 -6
  108. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +5 -4
  109. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerMetadata.ts +3 -2
  110. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerUsers.ts +3 -2
  111. package/apps/agents-server/src/utils/serverManagement/deleteManagedServer.ts +2 -2
  112. package/apps/agents-server/src/utils/stalwart/createEmailDnsRecordsSection.ts +53 -0
  113. package/apps/agents-server/src/utils/userChat/UserChatRecord.ts +13 -0
  114. package/apps/agents-server/src/utils/userChat/UserChatSource.ts +14 -0
  115. package/apps/agents-server/src/utils/userChat/createUserChatSummary.ts +10 -2
  116. package/apps/agents-server/src/utils/userChat/finalizeUserChatJob.ts +3 -2
  117. package/apps/agents-server/src/utils/userChat/getUserChat.ts +16 -1
  118. package/apps/agents-server/src/utils/userChat/getUserChatForJobRunner.ts +31 -0
  119. package/apps/agents-server/src/utils/userChat/listUserChats.ts +113 -110
  120. package/apps/agents-server/src/utils/userChat/persistFrozenUserChat.ts +21 -6
  121. package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +2 -6
  122. package/apps/agents-server/src/utils/userChat/runUserChatJob.ts +2 -6
  123. package/apps/agents-server/src/utils/userChat/teamMemberUserChatContext.ts +63 -0
  124. package/apps/agents-server/src/utils/userChat.ts +5 -1
  125. package/apps/agents-server/src/utils/userChatClient/cancelAgentUserTimeout.ts +2 -2
  126. package/apps/agents-server/src/utils/userChatClient/fetchAgentUserTimeouts.ts +2 -2
  127. package/apps/agents-server/src/utils/userChatClient.ts +9 -31
  128. package/apps/agents-server/src/utils/userChatTimeout/UserChatTimeoutRecord.ts +10 -2
  129. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/claimNextDueUserChatTimeout.ts +28 -25
  130. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/getAgentScopedUserChatTimeout.ts +8 -4
  131. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/listAgentUserChatTimeouts.ts +4 -1
  132. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/recoverExpiredRunningUserChatTimeouts.ts +3 -2
  133. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +53 -0
  134. package/esm/index.es.js +1534 -401
  135. package/esm/index.es.js.map +1 -1
  136. package/esm/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +7 -1
  137. package/esm/scripts/run-agent-messages/messages/buildAgentTeamPromptSection.d.ts +12 -0
  138. package/esm/scripts/run-agent-messages/messages/finalizeAgentTeamConversationWorkspace.d.ts +16 -0
  139. package/esm/scripts/run-agent-messages/messages/loadAgentTeamConversationWorkspace.d.ts +6 -0
  140. package/esm/scripts/run-codex-prompts/common/normalizeLineEndingsInChangedFiles.d.ts +2 -3
  141. package/esm/scripts/run-codex-prompts/git/coderCommitScope.d.ts +31 -0
  142. package/esm/scripts/run-codex-prompts/git/coderGitSync.d.ts +15 -2
  143. package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +9 -3
  144. package/esm/scripts/run-codex-prompts/git/workingTreeChanges.d.ts +40 -0
  145. package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +1 -1
  146. package/esm/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +5 -5
  147. package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiTerminalFrameUpdate.d.ts +27 -0
  148. package/esm/src/avatars/renderAvatarVisualTerminalText.d.ts +80 -0
  149. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +54 -0
  150. package/esm/src/book-3.0/AgentTeamConversationWorkspace.d.ts +85 -0
  151. package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +3 -2
  152. package/esm/src/book-components/Chat/utils/renderMarkdown.d.ts +12 -3
  153. package/esm/src/cli/cli-commands/coder/boilerplateCount.d.ts +1 -1
  154. package/esm/src/cli/cli-commands/coder/generate-boilerplates.d.ts +1 -1
  155. package/esm/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.d.ts → npm/$askForNpmPackageInstallationApproval.d.ts} +2 -2
  156. package/{umd/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.d.ts → esm/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.d.ts} +2 -3
  157. package/esm/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.d.ts +12 -0
  158. package/esm/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.d.ts +9 -0
  159. package/esm/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +9 -0
  160. package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +14 -0
  161. package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.test.d.ts +1 -0
  162. package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +12 -0
  163. package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.test.d.ts +1 -0
  164. package/esm/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +10 -0
  165. package/esm/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.d.ts +39 -0
  166. package/esm/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.d.ts +26 -0
  167. package/esm/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.d.ts +7 -0
  168. package/esm/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.test.d.ts +1 -0
  169. package/esm/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.d.ts +7 -0
  170. package/esm/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.d.ts +3 -3
  171. package/esm/src/utils/agents/terminalAgentAvatarVisual.d.ts +5 -2
  172. package/esm/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +6 -0
  173. package/esm/src/utils/ascii-art/createAnsiColorCode.d.ts +46 -0
  174. package/esm/src/utils/misc/debounce.d.ts +4 -2
  175. package/esm/src/utils/misc/debounce.test.d.ts +1 -0
  176. package/esm/src/version.d.ts +1 -1
  177. package/package.json +1 -1
  178. package/src/avatars/renderAvatarVisualTerminalText.ts +249 -0
  179. package/src/avatars/types/AvatarVisualDefinition.ts +60 -0
  180. package/src/avatars/visuals/asciiOctopusAvatarVisual.ts +144 -22
  181. package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +4 -4
  182. package/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.ts +1 -4
  183. package/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.ts +4 -17
  184. package/src/book-3.0/AgentTeamConversationWorkspace.ts +172 -0
  185. package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +56 -55
  186. package/src/book-components/Chat/Chat/Chat.module.css +1 -8
  187. package/src/book-components/Chat/Chat/ChatMessageMap.tsx +8 -4
  188. package/src/book-components/Chat/Chat/ChatProps.tsx +3 -2
  189. package/src/book-components/Chat/MarkdownContent/MarkdownContent.module.css +14 -14
  190. package/src/book-components/Chat/save/react/exports/chat-preview-2025-10-13 (1).jsx +95 -5
  191. package/src/book-components/Chat/utils/renderMarkdown.ts +535 -89
  192. package/src/cli/cli-commands/coder/add.ts +3 -3
  193. package/src/cli/cli-commands/coder/boilerplateCount.ts +1 -1
  194. package/src/cli/cli-commands/coder/generate-boilerplates.ts +27 -27
  195. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +5 -4
  196. package/src/cli/cli-commands/coder/init.ts +3 -3
  197. package/src/cli/cli-commands/coder/run.ts +10 -2
  198. package/src/cli/cli-commands/common/coderGitSyncCliOptions.ts +6 -2
  199. package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +2 -2
  200. package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +4 -4
  201. package/src/cli/cli-commands/common/harness/$resolveInstalledHarnessVersion.ts +2 -2
  202. package/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.ts → npm/$askForNpmPackageInstallationApproval.ts} +3 -3
  203. package/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.ts +49 -0
  204. package/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.ts +25 -0
  205. package/src/cli/cli-commands/common/{harness/isHarnessVersionOutdated.ts → npm/isNpmPackageVersionOutdated.ts} +6 -4
  206. package/src/cli/cli-commands/common/projectInitialization.ts +10 -1
  207. package/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.ts +73 -0
  208. package/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.ts +94 -0
  209. package/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.ts +223 -0
  210. package/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.ts +53 -0
  211. package/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.ts +46 -0
  212. package/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.ts +32 -0
  213. package/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.ts +22 -0
  214. package/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.ts +47 -0
  215. package/src/commands/FORMAT/formatCommandParser.ts +2 -2
  216. package/src/llm-providers/openai/utils/buildToolInvocationScript.ts +21 -18
  217. package/src/other/templates/getTemplatesPipelineCollection.ts +976 -668
  218. package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +80 -27
  219. package/src/utils/agents/terminalAgentAvatarVisual.ts +31 -3
  220. package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +9 -109
  221. package/src/utils/ascii-art/createAnsiColorCode.ts +132 -0
  222. package/src/utils/misc/debounce.ts +26 -5
  223. package/src/version.ts +2 -2
  224. package/src/versions.txt +2 -0
  225. package/umd/index.umd.js +1533 -400
  226. package/umd/index.umd.js.map +1 -1
  227. package/umd/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +7 -1
  228. package/umd/scripts/run-agent-messages/messages/buildAgentTeamPromptSection.d.ts +12 -0
  229. package/umd/scripts/run-agent-messages/messages/finalizeAgentTeamConversationWorkspace.d.ts +16 -0
  230. package/umd/scripts/run-agent-messages/messages/loadAgentTeamConversationWorkspace.d.ts +6 -0
  231. package/umd/scripts/run-codex-prompts/common/normalizeLineEndingsInChangedFiles.d.ts +2 -3
  232. package/umd/scripts/run-codex-prompts/git/coderCommitScope.d.ts +31 -0
  233. package/umd/scripts/run-codex-prompts/git/coderGitSync.d.ts +15 -2
  234. package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +9 -3
  235. package/umd/scripts/run-codex-prompts/git/workingTreeChanges.d.ts +40 -0
  236. package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +1 -1
  237. package/umd/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +5 -5
  238. package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiTerminalFrameUpdate.d.ts +27 -0
  239. package/umd/src/avatars/renderAvatarVisualTerminalText.d.ts +80 -0
  240. package/umd/src/avatars/renderAvatarVisualTerminalText.test.d.ts +1 -0
  241. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +54 -0
  242. package/umd/src/book-3.0/AgentTeamConversationWorkspace.d.ts +85 -0
  243. package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +3 -2
  244. package/umd/src/book-components/Chat/utils/renderMarkdown.d.ts +12 -3
  245. package/umd/src/cli/cli-commands/coder/boilerplateCount.d.ts +1 -1
  246. package/umd/src/cli/cli-commands/coder/generate-boilerplates.d.ts +1 -1
  247. package/umd/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.d.ts → npm/$askForNpmPackageInstallationApproval.d.ts} +2 -2
  248. package/{esm/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.d.ts → umd/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.d.ts} +2 -3
  249. package/umd/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.test.d.ts +1 -0
  250. package/umd/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.d.ts +12 -0
  251. package/umd/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.test.d.ts +1 -0
  252. package/umd/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.d.ts +9 -0
  253. package/umd/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.test.d.ts +1 -0
  254. package/umd/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +9 -0
  255. package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +14 -0
  256. package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.test.d.ts +1 -0
  257. package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +12 -0
  258. package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.test.d.ts +1 -0
  259. package/umd/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +10 -0
  260. package/umd/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.d.ts +39 -0
  261. package/umd/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.d.ts +26 -0
  262. package/umd/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.d.ts +7 -0
  263. package/umd/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.test.d.ts +1 -0
  264. package/umd/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.d.ts +7 -0
  265. package/umd/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.d.ts +3 -3
  266. package/umd/src/utils/agents/terminalAgentAvatarVisual.d.ts +5 -2
  267. package/umd/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +6 -0
  268. package/umd/src/utils/ascii-art/createAnsiColorCode.d.ts +46 -0
  269. package/umd/src/utils/misc/debounce.d.ts +4 -2
  270. package/umd/src/utils/misc/debounce.test.d.ts +1 -0
  271. package/umd/src/version.d.ts +1 -1
  272. package/apps/agents-server/scripts/ignore-kill-eperm.js +0 -31
  273. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/actions/route.ts +0 -103
  274. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsClient.tsx +0 -43
  275. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsEditDialog.tsx +0 -98
  276. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsFiltersCard.tsx +0 -75
  277. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsHeader.tsx +0 -53
  278. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsSummaryMetrics.tsx +0 -70
  279. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableCard.tsx +0 -58
  280. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableRow.tsx +0 -242
  281. package/apps/agents-server/src/app/agents/[agentName]/timeouts/loading.tsx +0 -15
  282. package/apps/agents-server/src/app/agents/[agentName]/timeouts/page.tsx +0 -28
  283. package/apps/agents-server/src/app/agents/[agentName]/timeouts/useAgentTimeoutsClientState.ts +0 -769
  284. package/apps/agents-server/src/components/AgentProjectDnsInstructions/AgentProjectDnsInstructions.tsx +0 -182
  285. package/apps/agents-server/src/utils/userChatClient/runAgentUserTimeoutBulkAction.ts +0 -24
  286. package/apps/agents-server/src/utils/userChatClient/updateAgentUserTimeout.ts +0 -25
  287. package/esm/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.d.ts +0 -11
  288. package/esm/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.d.ts +0 -9
  289. package/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.ts +0 -34
  290. package/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.ts +0 -28
  291. package/umd/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.d.ts +0 -11
  292. package/umd/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.d.ts +0 -9
  293. /package/esm/src/{cli/cli-commands/common/harness/extractHarnessVersionFromOutput.test.d.ts → avatars/renderAvatarVisualTerminalText.test.d.ts} +0 -0
  294. /package/esm/src/cli/cli-commands/common/{harness/isHarnessVersionOutdated.test.d.ts → npm/$resolveLatestNpmPackageVersion.test.d.ts} +0 -0
  295. /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
  296. /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,769 +0,0 @@
1
- 'use client';
2
-
3
- import { showAlert, showConfirm, showPrompt } from '@/src/components/AsyncDialogs/asyncDialogs';
4
- import { useDirtyModalGuard } from '@/src/components/utils/useDirtyModalGuard';
5
- import { useCallback, useEffect, useMemo, useState } from 'react';
6
- import {
7
- cancelAgentUserTimeout,
8
- fetchAgentUserTimeouts,
9
- runAgentUserTimeoutBulkAction,
10
- updateAgentUserTimeout,
11
- type AgentUserTimeoutBulkAction,
12
- type AgentUserTimeoutCounters,
13
- type AgentUserTimeoutUpdatePayload,
14
- type UserChatTimeout,
15
- } from '@/src/utils/userChatClient';
16
-
17
- /**
18
- * Filter tabs available in the timeout manager.
19
- *
20
- * @private function of AgentTimeoutsClient
21
- */
22
- type TimeoutManagerFilter = 'active' | 'paused' | 'history' | 'all';
23
-
24
- /**
25
- * Supported timeout actions shown as busy states in the manager.
26
- *
27
- * @private function of AgentTimeoutsClient
28
- */
29
- type TimeoutManagerActionKind = 'save' | 'cancel' | 'pause' | 'resume' | 'extend';
30
-
31
- /**
32
- * Local edit form state for the timeout dialog.
33
- *
34
- * @private function of AgentTimeoutsClient
35
- */
36
- type TimeoutEditDraft = {
37
- dueAtLocalValue: string;
38
- recurrenceMinutesValue: string;
39
- messageValue: string;
40
- parametersValue: string;
41
- };
42
-
43
- /**
44
- * Props accepted by `useAgentTimeoutsClientState`.
45
- *
46
- * @private function of AgentTimeoutsClient
47
- */
48
- type UseAgentTimeoutsClientStateProps = {
49
- agentName: string;
50
- };
51
-
52
- /**
53
- * Button metadata for one timeout-manager bulk action.
54
- *
55
- * @private function of AgentTimeoutsClient
56
- */
57
- type TimeoutManagerBulkActionView = {
58
- action: AgentUserTimeoutBulkAction;
59
- idleLabel: string;
60
- busyLabel: string;
61
- buttonClassName: string;
62
- };
63
-
64
- /**
65
- * Dialog copy and button styling for one bulk action.
66
- *
67
- * @private function of AgentTimeoutsClient
68
- */
69
- type TimeoutManagerBulkActionConfig = TimeoutManagerBulkActionView & {
70
- confirmTitle: string;
71
- confirmMessage: string;
72
- confirmLabel: string;
73
- errorTitle: string;
74
- };
75
-
76
- /**
77
- * State and handlers exposed by `useAgentTimeoutsClientState`.
78
- *
79
- * @private function of AgentTimeoutsClient
80
- */
81
- type UseAgentTimeoutsClientStateResult = {
82
- bulkActions: ReadonlyArray<TimeoutManagerBulkActionView>;
83
- busyAction: TimeoutManagerActionKind | null;
84
- busyBulkAction: AgentUserTimeoutBulkAction | null;
85
- busyTimeoutId: string | null;
86
- counters: AgentUserTimeoutCounters | null;
87
- closeEditDialog: () => void;
88
- requestCloseEditDialog: () => void;
89
- editDraft: TimeoutEditDraft;
90
- editingTimeout: UserChatTimeout | null;
91
- errorMessage: string | null;
92
- filter: TimeoutManagerFilter;
93
- filteredTimeouts: Array<UserChatTimeout>;
94
- generatedAt: string | null;
95
- isLoading: boolean;
96
- isRefreshing: boolean;
97
- cancelTimeout: (timeout: UserChatTimeout) => Promise<void>;
98
- extendTimeout: (timeout: UserChatTimeout) => Promise<void>;
99
- openEditDialog: (timeout: UserChatTimeout) => void;
100
- refreshNow: () => Promise<void>;
101
- runBulkAction: (action: AgentUserTimeoutBulkAction) => Promise<void>;
102
- saveEdits: () => Promise<void>;
103
- selectFilter: (nextFilter: TimeoutManagerFilter) => void;
104
- toggleTimeoutPause: (timeout: UserChatTimeout) => Promise<void>;
105
- updateEditDueAtLocalValue: (nextValue: string) => void;
106
- updateEditMessageValue: (nextValue: string) => void;
107
- updateEditParametersValue: (nextValue: string) => void;
108
- updateEditRecurrenceMinutesValue: (nextValue: string) => void;
109
- };
110
-
111
- /**
112
- * Polling cadence for refreshing timeout data.
113
- *
114
- * @private function of AgentTimeoutsClient
115
- */
116
- const AGENT_TIMEOUT_MANAGER_POLL_INTERVAL_MS = 10_000;
117
-
118
- /**
119
- * UX copy/configuration for supported timeout-manager bulk actions.
120
- *
121
- * @private function of AgentTimeoutsClient
122
- */
123
- const TIMEOUT_MANAGER_BULK_ACTION_CONFIG: Record<AgentUserTimeoutBulkAction, TimeoutManagerBulkActionConfig> = {
124
- cancel_all_active: {
125
- action: 'cancel_all_active',
126
- idleLabel: 'Cancel active',
127
- busyLabel: 'Cancelling...',
128
- confirmTitle: 'Cancel all active timeouts',
129
- confirmMessage: 'Cancel all active timeouts for this agent across your chats?',
130
- confirmLabel: 'Cancel all',
131
- errorTitle: 'Bulk cancellation failed',
132
- buttonClassName:
133
- 'rounded-md border border-red-200 bg-red-50 px-3 py-1.5 text-xs font-semibold text-red-700 disabled:cursor-not-allowed disabled:opacity-60',
134
- },
135
- pause_all_active: {
136
- action: 'pause_all_active',
137
- idleLabel: 'Pause active',
138
- busyLabel: 'Pausing...',
139
- confirmTitle: 'Pause all active timeouts',
140
- confirmMessage: 'Pause all active queued timeouts for this agent across your chats?',
141
- confirmLabel: 'Pause all',
142
- errorTitle: 'Bulk pause failed',
143
- buttonClassName:
144
- 'rounded-md border border-amber-200 bg-amber-50 px-3 py-1.5 text-xs font-semibold text-amber-700 disabled:cursor-not-allowed disabled:opacity-60',
145
- },
146
- resume_all_paused: {
147
- action: 'resume_all_paused',
148
- idleLabel: 'Resume paused',
149
- busyLabel: 'Resuming...',
150
- confirmTitle: 'Resume all paused timeouts',
151
- confirmMessage: 'Resume all paused queued timeouts for this agent across your chats?',
152
- confirmLabel: 'Resume all',
153
- errorTitle: 'Bulk resume failed',
154
- buttonClassName:
155
- 'rounded-md border border-emerald-200 bg-emerald-50 px-3 py-1.5 text-xs font-semibold text-emerald-700 disabled:cursor-not-allowed disabled:opacity-60',
156
- },
157
- };
158
-
159
- /**
160
- * Render-ready bulk action list consumed by the page header.
161
- *
162
- * @private function of AgentTimeoutsClient
163
- */
164
- const TIMEOUT_MANAGER_BULK_ACTIONS: ReadonlyArray<TimeoutManagerBulkActionView> = createBulkActionViews();
165
-
166
- /**
167
- * Creates a render-ready list of bulk action buttons.
168
- *
169
- * @private function of AgentTimeoutsClient
170
- */
171
- function createBulkActionViews(): Array<TimeoutManagerBulkActionView> {
172
- return (
173
- Object.entries(TIMEOUT_MANAGER_BULK_ACTION_CONFIG) as Array<
174
- [AgentUserTimeoutBulkAction, TimeoutManagerBulkActionConfig]
175
- >
176
- ).map(([action, actionConfig]) => ({
177
- action,
178
- idleLabel: actionConfig.idleLabel,
179
- busyLabel: actionConfig.busyLabel,
180
- buttonClassName: actionConfig.buttonClassName,
181
- }));
182
- }
183
-
184
- /**
185
- * Creates the blank edit-draft state used when no timeout is selected.
186
- *
187
- * @private function of AgentTimeoutsClient
188
- */
189
- function createEmptyTimeoutEditDraft(): TimeoutEditDraft {
190
- return {
191
- dueAtLocalValue: '',
192
- recurrenceMinutesValue: '',
193
- messageValue: '',
194
- parametersValue: '{}',
195
- };
196
- }
197
-
198
- /**
199
- * Prefills the edit dialog from one timeout record.
200
- *
201
- * @private function of AgentTimeoutsClient
202
- */
203
- function createTimeoutEditDraft(timeout: UserChatTimeout): TimeoutEditDraft {
204
- return {
205
- dueAtLocalValue: toDateTimeLocalValue(timeout.dueAt),
206
- recurrenceMinutesValue: timeout.recurrenceIntervalMs
207
- ? String(Math.floor(timeout.recurrenceIntervalMs / 60_000))
208
- : '',
209
- messageValue: timeout.message || '',
210
- parametersValue: JSON.stringify(timeout.parameters || {}, null, 2),
211
- };
212
- }
213
-
214
- /**
215
- * Filters timeouts for the selected manager tab.
216
- *
217
- * @private function of AgentTimeoutsClient
218
- */
219
- function filterTimeoutsBySelectedView(
220
- timeouts: ReadonlyArray<UserChatTimeout>,
221
- filter: TimeoutManagerFilter,
222
- ): Array<UserChatTimeout> {
223
- if (filter === 'all') {
224
- return [...timeouts];
225
- }
226
-
227
- if (filter === 'active') {
228
- return timeouts.filter(
229
- (timeout) => (timeout.status === 'QUEUED' || timeout.status === 'RUNNING') && !timeout.pausedAt,
230
- );
231
- }
232
-
233
- if (filter === 'paused') {
234
- return timeouts.filter((timeout) => timeout.status === 'QUEUED' && Boolean(timeout.pausedAt));
235
- }
236
-
237
- return timeouts.filter(
238
- (timeout) =>
239
- timeout.status === 'COMPLETED' || timeout.status === 'FAILED' || timeout.status === 'CANCELLED',
240
- );
241
- }
242
-
243
- /**
244
- * Normalizes errors thrown while loading the timeout manager.
245
- *
246
- * @private function of AgentTimeoutsClient
247
- */
248
- function resolveTimeoutLoadErrorMessage(loadError: unknown): string {
249
- return loadError instanceof Error ? loadError.message : 'Failed to load agent timeouts.';
250
- }
251
-
252
- /**
253
- * Shows one timeout-manager alert dialog.
254
- *
255
- * @private function of AgentTimeoutsClient
256
- */
257
- async function showTimeoutAlert(title: string, message: string): Promise<void> {
258
- await showAlert({ title, message }).catch(() => undefined);
259
- }
260
-
261
- /**
262
- * Shows a failed timeout action using the original fallback copy.
263
- *
264
- * @private function of AgentTimeoutsClient
265
- */
266
- async function showTimeoutActionFailure(title: string, error: unknown, fallbackMessage: string): Promise<void> {
267
- await showTimeoutAlert(title, error instanceof Error ? error.message : fallbackMessage);
268
- }
269
-
270
- /**
271
- * Requests confirmation before one timeout cancellation.
272
- *
273
- * @private function of AgentTimeoutsClient
274
- */
275
- async function confirmTimeoutCancellation(timeoutId: string): Promise<boolean> {
276
- return showConfirm({
277
- title: 'Cancel timeout',
278
- message: `Cancel timeout "${timeoutId}"?`,
279
- confirmLabel: 'Cancel timeout',
280
- cancelLabel: 'Back',
281
- }).catch(() => false);
282
- }
283
-
284
- /**
285
- * Prompts the user for a positive number of extension minutes.
286
- *
287
- * @private function of AgentTimeoutsClient
288
- */
289
- async function requestTimeoutExtensionMinutes(): Promise<number | null> {
290
- const value = await showPrompt({
291
- title: 'Extend timeout',
292
- message: 'Add minutes to the current due time.',
293
- confirmLabel: 'Extend',
294
- cancelLabel: 'Back',
295
- placeholder: 'Minutes',
296
- inputLabel: 'Minutes',
297
- }).catch(() => null);
298
-
299
- if (value === null) {
300
- return null;
301
- }
302
-
303
- const minutes = Number.parseFloat(value.trim());
304
- if (!Number.isFinite(minutes) || minutes <= 0) {
305
- await showTimeoutAlert('Invalid value', 'Please enter a positive number of minutes.');
306
- return null;
307
- }
308
-
309
- return minutes;
310
- }
311
-
312
- /**
313
- * Requests confirmation before one bulk action.
314
- *
315
- * @private function of AgentTimeoutsClient
316
- */
317
- async function confirmTimeoutBulkAction(actionConfig: TimeoutManagerBulkActionConfig): Promise<boolean> {
318
- return showConfirm({
319
- title: actionConfig.confirmTitle,
320
- message: actionConfig.confirmMessage,
321
- confirmLabel: actionConfig.confirmLabel,
322
- cancelLabel: 'Back',
323
- }).catch(() => false);
324
- }
325
-
326
- /**
327
- * Validates and converts the edit dialog state into an API payload.
328
- *
329
- * @private function of AgentTimeoutsClient
330
- */
331
- async function createTimeoutEditPayload(
332
- editDraft: TimeoutEditDraft,
333
- ): Promise<AgentUserTimeoutUpdatePayload | null> {
334
- let parsedParameters: Record<string, unknown>;
335
- try {
336
- parsedParameters = parseTimeoutEditParameters(editDraft.parametersValue);
337
- } catch (error) {
338
- await showTimeoutActionFailure('Invalid parameters JSON', error, 'Failed to parse parameters JSON.');
339
- return null;
340
- }
341
-
342
- let recurrenceIntervalMs: number | null;
343
- try {
344
- recurrenceIntervalMs = parseTimeoutEditRecurrenceIntervalMs(editDraft.recurrenceMinutesValue);
345
- } catch (error) {
346
- await showTimeoutActionFailure(
347
- 'Invalid recurrence',
348
- error,
349
- 'Recurrence must be a positive number of minutes or empty.',
350
- );
351
- return null;
352
- }
353
-
354
- const dueAt = fromDateTimeLocalValue(editDraft.dueAtLocalValue);
355
- if (!dueAt) {
356
- await showTimeoutAlert('Invalid date', 'Next run must be a valid date and time.');
357
- return null;
358
- }
359
-
360
- const trimmedMessage = editDraft.messageValue.trim();
361
-
362
- return {
363
- dueAt,
364
- recurrenceIntervalMs,
365
- message: trimmedMessage ? trimmedMessage : null,
366
- parameters: parsedParameters,
367
- };
368
- }
369
-
370
- /**
371
- * Parses the JSON parameters field and guarantees an object result.
372
- *
373
- * @private function of AgentTimeoutsClient
374
- */
375
- function parseTimeoutEditParameters(parametersValue: string): Record<string, unknown> {
376
- const parsedJson = JSON.parse(parametersValue || '{}') as unknown;
377
- if (!parsedJson || typeof parsedJson !== 'object' || Array.isArray(parsedJson)) {
378
- throw new Error('Parameters JSON must be an object.');
379
- }
380
-
381
- return parsedJson as Record<string, unknown>;
382
- }
383
-
384
- /**
385
- * Parses the optional recurrence field into milliseconds.
386
- *
387
- * @private function of AgentTimeoutsClient
388
- */
389
- function parseTimeoutEditRecurrenceIntervalMs(recurrenceMinutesValue: string): number | null {
390
- const trimmedRecurrence = recurrenceMinutesValue.trim();
391
- if (!trimmedRecurrence) {
392
- return null;
393
- }
394
-
395
- const recurrenceMinutes = Number.parseFloat(trimmedRecurrence);
396
- if (!Number.isFinite(recurrenceMinutes) || recurrenceMinutes <= 0) {
397
- throw new Error('Recurrence must be a positive number of minutes or empty.');
398
- }
399
-
400
- return Math.floor(recurrenceMinutes * 60_000);
401
- }
402
-
403
- /**
404
- * Converts an ISO date into a `datetime-local` compatible value.
405
- *
406
- * @private function of AgentTimeoutsClient
407
- */
408
- function toDateTimeLocalValue(isoTimestamp: string): string {
409
- const timestamp = Date.parse(isoTimestamp);
410
- if (!Number.isFinite(timestamp)) {
411
- return '';
412
- }
413
-
414
- const date = new Date(timestamp);
415
- const year = String(date.getFullYear());
416
- const month = String(date.getMonth() + 1).padStart(2, '0');
417
- const day = String(date.getDate()).padStart(2, '0');
418
- const hours = String(date.getHours()).padStart(2, '0');
419
- const minutes = String(date.getMinutes()).padStart(2, '0');
420
-
421
- return `${year}-${month}-${day}T${hours}:${minutes}`;
422
- }
423
-
424
- /**
425
- * Parses one `datetime-local` value into ISO format.
426
- *
427
- * @private function of AgentTimeoutsClient
428
- */
429
- function fromDateTimeLocalValue(value: string): string | null {
430
- if (!value.trim()) {
431
- return null;
432
- }
433
-
434
- const timestamp = Date.parse(value);
435
- if (!Number.isFinite(timestamp)) {
436
- return null;
437
- }
438
-
439
- return new Date(timestamp).toISOString();
440
- }
441
-
442
- /**
443
- * Manages timeout-manager polling, mutations, filters, and edit-dialog state.
444
- *
445
- * @private function of AgentTimeoutsClient
446
- */
447
- export function useAgentTimeoutsClientState({
448
- agentName,
449
- }: UseAgentTimeoutsClientStateProps): UseAgentTimeoutsClientStateResult {
450
- const [timeouts, setTimeouts] = useState<Array<UserChatTimeout>>([]);
451
- const [counters, setCounters] = useState<AgentUserTimeoutCounters | null>(null);
452
- const [generatedAt, setGeneratedAt] = useState<string | null>(null);
453
- const [isLoading, setIsLoading] = useState(true);
454
- const [isRefreshing, setIsRefreshing] = useState(false);
455
- const [errorMessage, setErrorMessage] = useState<string | null>(null);
456
- const [filter, setFilter] = useState<TimeoutManagerFilter>('active');
457
- const [editingTimeout, setEditingTimeout] = useState<UserChatTimeout | null>(null);
458
- const [busyTimeoutId, setBusyTimeoutId] = useState<string | null>(null);
459
- const [busyAction, setBusyAction] = useState<TimeoutManagerActionKind | null>(null);
460
- const [busyBulkAction, setBusyBulkAction] = useState<AgentUserTimeoutBulkAction | null>(null);
461
- const [editDraft, setEditDraft] = useState<TimeoutEditDraft>(createEmptyTimeoutEditDraft);
462
-
463
- /**
464
- * Loads current agent-scoped timeout data.
465
- *
466
- * @private function of AgentTimeoutsClient
467
- */
468
- const refreshTimeouts = useCallback(
469
- async (showRefreshingState: boolean) => {
470
- if (showRefreshingState) {
471
- setIsRefreshing(true);
472
- }
473
-
474
- try {
475
- setErrorMessage(null);
476
- const payload = await fetchAgentUserTimeouts(agentName);
477
- setTimeouts(payload.items);
478
- setCounters(payload.counters);
479
- setGeneratedAt(payload.generatedAt);
480
- } catch (error) {
481
- setErrorMessage(resolveTimeoutLoadErrorMessage(error));
482
- } finally {
483
- setIsLoading(false);
484
- setIsRefreshing(false);
485
- }
486
- },
487
- [agentName],
488
- );
489
-
490
- useEffect(() => {
491
- void refreshTimeouts(false);
492
-
493
- const timer = window.setInterval(() => {
494
- void refreshTimeouts(true);
495
- }, AGENT_TIMEOUT_MANAGER_POLL_INTERVAL_MS);
496
-
497
- return () => window.clearInterval(timer);
498
- }, [refreshTimeouts]);
499
-
500
- /**
501
- * Runs one timeout mutation while keeping the busy state and local refresh consistent.
502
- *
503
- * @private function of AgentTimeoutsClient
504
- */
505
- const runBusyTimeoutAction = useCallback(
506
- async (timeout: UserChatTimeout, action: TimeoutManagerActionKind, worker: () => Promise<void>) => {
507
- try {
508
- setBusyTimeoutId(timeout.timeoutId);
509
- setBusyAction(action);
510
- await worker();
511
- await refreshTimeouts(false);
512
- } finally {
513
- setBusyTimeoutId(null);
514
- setBusyAction(null);
515
- }
516
- },
517
- [refreshTimeouts],
518
- );
519
-
520
- /**
521
- * Applies one timeout patch and refreshes the manager data.
522
- *
523
- * @private function of AgentTimeoutsClient
524
- */
525
- const applyTimeoutPatch = useCallback(
526
- async (timeout: UserChatTimeout, payload: AgentUserTimeoutUpdatePayload, action: TimeoutManagerActionKind) => {
527
- await runBusyTimeoutAction(timeout, action, async () => {
528
- await updateAgentUserTimeout(agentName, timeout.timeoutId, payload);
529
- });
530
- },
531
- [agentName, runBusyTimeoutAction],
532
- );
533
-
534
- /**
535
- * Opens the advanced timeout edit dialog with prefilled values.
536
- *
537
- * @private function of AgentTimeoutsClient
538
- */
539
- const openEditDialog = useCallback((timeout: UserChatTimeout) => {
540
- setEditingTimeout(timeout);
541
- setEditDraft(createTimeoutEditDraft(timeout));
542
- }, []);
543
-
544
- /**
545
- * Closes the edit dialog and resets its local form state.
546
- *
547
- * @private function of AgentTimeoutsClient
548
- */
549
- const closeEditDialog = useCallback(() => {
550
- setEditingTimeout(null);
551
- setEditDraft(createEmptyTimeoutEditDraft());
552
- }, []);
553
- const hasEditDraftUnsavedChanges = useMemo(() => {
554
- if (!editingTimeout) {
555
- return false;
556
- }
557
-
558
- const initialEditDraft = createTimeoutEditDraft(editingTimeout);
559
-
560
- return (
561
- editDraft.dueAtLocalValue !== initialEditDraft.dueAtLocalValue ||
562
- editDraft.recurrenceMinutesValue !== initialEditDraft.recurrenceMinutesValue ||
563
- editDraft.messageValue !== initialEditDraft.messageValue ||
564
- editDraft.parametersValue !== initialEditDraft.parametersValue
565
- );
566
- }, [editDraft, editingTimeout]);
567
- const { requestClose: requestCloseEditDialog } = useDirtyModalGuard({
568
- hasUnsavedChanges: hasEditDraftUnsavedChanges,
569
- isCloseBlocked: busyAction === 'save' && busyTimeoutId === editingTimeout?.timeoutId,
570
- onClose: closeEditDialog,
571
- });
572
-
573
- /**
574
- * Updates the selected manager filter.
575
- *
576
- * @private function of AgentTimeoutsClient
577
- */
578
- const selectFilter = useCallback((nextFilter: TimeoutManagerFilter) => {
579
- setFilter(nextFilter);
580
- }, []);
581
-
582
- /**
583
- * Forces an immediate manager refresh from the header button.
584
- *
585
- * @private function of AgentTimeoutsClient
586
- */
587
- const refreshNow = useCallback(async () => {
588
- await refreshTimeouts(true);
589
- }, [refreshTimeouts]);
590
-
591
- /**
592
- * Cancels one timeout after confirmation.
593
- *
594
- * @private function of AgentTimeoutsClient
595
- */
596
- const cancelTimeout = useCallback(
597
- async (timeout: UserChatTimeout) => {
598
- const isConfirmed = await confirmTimeoutCancellation(timeout.timeoutId);
599
- if (!isConfirmed) {
600
- return;
601
- }
602
-
603
- try {
604
- await runBusyTimeoutAction(timeout, 'cancel', async () => {
605
- await cancelAgentUserTimeout(agentName, timeout.timeoutId);
606
- });
607
- } catch (error) {
608
- await showTimeoutActionFailure('Cancellation failed', error, 'Failed to cancel timeout.');
609
- }
610
- },
611
- [agentName, runBusyTimeoutAction],
612
- );
613
-
614
- /**
615
- * Toggles one queued timeout between paused and active states.
616
- *
617
- * @private function of AgentTimeoutsClient
618
- */
619
- const toggleTimeoutPause = useCallback(
620
- async (timeout: UserChatTimeout) => {
621
- const isPaused = timeout.status === 'QUEUED' && Boolean(timeout.pausedAt);
622
-
623
- await applyTimeoutPatch(timeout, { paused: !isPaused }, isPaused ? 'resume' : 'pause');
624
- },
625
- [applyTimeoutPatch],
626
- );
627
-
628
- /**
629
- * Prompts for and applies a quick timeout extension.
630
- *
631
- * @private function of AgentTimeoutsClient
632
- */
633
- const extendTimeout = useCallback(
634
- async (timeout: UserChatTimeout) => {
635
- const minutes = await requestTimeoutExtensionMinutes();
636
- if (minutes === null) {
637
- return;
638
- }
639
-
640
- try {
641
- await applyTimeoutPatch(timeout, { extendByMs: Math.floor(minutes * 60_000) }, 'extend');
642
- } catch (error) {
643
- await showTimeoutActionFailure('Extension failed', error, 'Failed to extend timeout.');
644
- }
645
- },
646
- [applyTimeoutPatch],
647
- );
648
-
649
- /**
650
- * Executes one bulk timeout action and refreshes manager data.
651
- *
652
- * @private function of AgentTimeoutsClient
653
- */
654
- const runBulkAction = useCallback(
655
- async (action: AgentUserTimeoutBulkAction) => {
656
- const actionConfig = TIMEOUT_MANAGER_BULK_ACTION_CONFIG[action];
657
- const isConfirmed = await confirmTimeoutBulkAction(actionConfig);
658
- if (!isConfirmed) {
659
- return;
660
- }
661
-
662
- try {
663
- setBusyBulkAction(action);
664
- await runAgentUserTimeoutBulkAction(agentName, action);
665
- await refreshTimeouts(false);
666
- } catch (error) {
667
- await showTimeoutActionFailure(
668
- actionConfig.errorTitle,
669
- error,
670
- 'Failed to run timeout bulk action.',
671
- );
672
- } finally {
673
- setBusyBulkAction(null);
674
- }
675
- },
676
- [agentName, refreshTimeouts],
677
- );
678
-
679
- /**
680
- * Updates the next-run field in the edit dialog.
681
- *
682
- * @private function of AgentTimeoutsClient
683
- */
684
- const updateEditDueAtLocalValue = useCallback((nextValue: string) => {
685
- setEditDraft((currentDraft) => ({ ...currentDraft, dueAtLocalValue: nextValue }));
686
- }, []);
687
-
688
- /**
689
- * Updates the recurrence field in the edit dialog.
690
- *
691
- * @private function of AgentTimeoutsClient
692
- */
693
- const updateEditRecurrenceMinutesValue = useCallback((nextValue: string) => {
694
- setEditDraft((currentDraft) => ({ ...currentDraft, recurrenceMinutesValue: nextValue }));
695
- }, []);
696
-
697
- /**
698
- * Updates the wake-up message field in the edit dialog.
699
- *
700
- * @private function of AgentTimeoutsClient
701
- */
702
- const updateEditMessageValue = useCallback((nextValue: string) => {
703
- setEditDraft((currentDraft) => ({ ...currentDraft, messageValue: nextValue }));
704
- }, []);
705
-
706
- /**
707
- * Updates the JSON parameters field in the edit dialog.
708
- *
709
- * @private function of AgentTimeoutsClient
710
- */
711
- const updateEditParametersValue = useCallback((nextValue: string) => {
712
- setEditDraft((currentDraft) => ({ ...currentDraft, parametersValue: nextValue }));
713
- }, []);
714
-
715
- /**
716
- * Saves edits from the timeout dialog.
717
- *
718
- * @private function of AgentTimeoutsClient
719
- */
720
- const saveEdits = useCallback(async () => {
721
- if (!editingTimeout) {
722
- return;
723
- }
724
-
725
- const payload = await createTimeoutEditPayload(editDraft);
726
- if (!payload) {
727
- return;
728
- }
729
-
730
- try {
731
- await applyTimeoutPatch(editingTimeout, payload, 'save');
732
- closeEditDialog();
733
- } catch (error) {
734
- await showTimeoutActionFailure('Update failed', error, 'Failed to save timeout edits.');
735
- }
736
- }, [applyTimeoutPatch, closeEditDialog, editDraft, editingTimeout]);
737
-
738
- const filteredTimeouts = useMemo(() => filterTimeoutsBySelectedView(timeouts, filter), [filter, timeouts]);
739
-
740
- return {
741
- bulkActions: TIMEOUT_MANAGER_BULK_ACTIONS,
742
- busyAction,
743
- busyBulkAction,
744
- busyTimeoutId,
745
- counters,
746
- closeEditDialog,
747
- requestCloseEditDialog,
748
- editDraft,
749
- editingTimeout,
750
- errorMessage,
751
- filter,
752
- filteredTimeouts,
753
- generatedAt,
754
- isLoading,
755
- isRefreshing,
756
- cancelTimeout,
757
- extendTimeout,
758
- openEditDialog,
759
- refreshNow,
760
- runBulkAction,
761
- saveEdits,
762
- selectFilter,
763
- toggleTimeoutPause,
764
- updateEditDueAtLocalValue,
765
- updateEditMessageValue,
766
- updateEditParametersValue,
767
- updateEditRecurrenceMinutesValue,
768
- };
769
- }