@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,3 +1,4 @@
1
+ import { spaceTrim } from 'spacetrim';
1
2
  import { $getTableName } from '@/src/database/$getTableName';
2
3
  import { $provideClientSql } from '@/src/database/$provideClientSql';
3
4
  import { isAgentsServerSqliteMode } from '@/src/database/agentsServerDatabaseMode';
@@ -97,19 +98,19 @@ export async function listUserChatSummarySeeds(options: ListUserChatsOptions): P
97
98
  shouldLoadAllUsersChats || (options.viewerIsAdmin && options.includeExternalChats);
98
99
 
99
100
  const whereClause = shouldLoadAllUsersChats
100
- ? `
101
+ ? spaceTrim(`
101
102
  "agentPermanentId" = $1
102
- `
103
+ `)
103
104
  : shouldLoadExternalChats
104
- ? `
105
+ ? spaceTrim(`
105
106
  "agentPermanentId" = $1
106
107
  AND ("source" <> '${USER_CHAT_SOURCES.WEB_UI}' OR "userId" = $2)
107
- `
108
- : `
108
+ `)
109
+ : spaceTrim(`
109
110
  "userId" = $1
110
111
  AND "agentPermanentId" = $2
111
112
  AND "source" = '${USER_CHAT_SOURCES.WEB_UI}'
112
- `;
113
+ `);
113
114
  const queryValues = shouldLoadAllUsersChats
114
115
  ? [options.agentPermanentId]
115
116
  : shouldLoadExternalChats
@@ -117,53 +118,55 @@ export async function listUserChatSummarySeeds(options: ListUserChatsOptions): P
117
118
  : [options.userId, options.agentPermanentId];
118
119
  try {
119
120
  const summaryRows = await sql.raw<Array<UserChatSummarySeedSqlRow>>(
120
- `
121
- SELECT
122
- "id",
123
- "createdAt",
124
- "updatedAt",
125
- "lastMessageAt",
126
- "title",
127
- "source",
128
- "userId",
129
- COALESCE(jsonb_array_length("messages"), 0) AS "messagesCount",
130
- COALESCE(
131
- (
132
- SELECT message."value"->>'content'
133
- FROM jsonb_array_elements("messages") WITH ORDINALITY AS message("value", "ordinality")
134
- WHERE UPPER(COALESCE(message."value"->>'sender', '')) = 'USER'
135
- ORDER BY message."ordinality" ASC
136
- LIMIT 1
137
- ),
138
- ''
139
- ) AS "firstUserMessageContent",
140
- COALESCE(
141
- (
142
- SELECT message."value"->>'content'
143
- FROM jsonb_array_elements("messages") WITH ORDINALITY AS message("value", "ordinality")
144
- WHERE LENGTH(BTRIM(COALESCE(message."value"->>'content', ''))) > 0
145
- ORDER BY message."ordinality" DESC
146
- LIMIT 1
147
- ),
148
- ''
149
- ) AS "lastPreviewMessageContent",
150
- COALESCE(
151
- (
152
- SELECT COUNT(*)::INT
153
- FROM jsonb_array_elements("messages") AS message("value")
154
- WHERE
155
- UPPER(COALESCE(message."value"->>'sender', '')) IN ('AGENT', 'MODEL')
156
- AND (
157
- COALESCE(message."value"->>'isComplete', '') = 'false'
158
- OR LOWER(COALESCE(message."value"->>'lifecycleState', '')) IN ('queued', 'running')
159
- )
160
- ),
161
- 0
162
- ) AS "pendingAssistantMessageCount"
163
- FROM ${userChatTableName}
164
- WHERE ${whereClause}
165
- ORDER BY "createdAt" DESC
166
- `,
121
+ spaceTrim(
122
+ (block) => `
123
+ SELECT
124
+ "id",
125
+ "createdAt",
126
+ "updatedAt",
127
+ "lastMessageAt",
128
+ "title",
129
+ "source",
130
+ "userId",
131
+ COALESCE(jsonb_array_length("messages"), 0) AS "messagesCount",
132
+ COALESCE(
133
+ (
134
+ SELECT message."value"->>'content'
135
+ FROM jsonb_array_elements("messages") WITH ORDINALITY AS message("value", "ordinality")
136
+ WHERE UPPER(COALESCE(message."value"->>'sender', '')) = 'USER'
137
+ ORDER BY message."ordinality" ASC
138
+ LIMIT 1
139
+ ),
140
+ ''
141
+ ) AS "firstUserMessageContent",
142
+ COALESCE(
143
+ (
144
+ SELECT message."value"->>'content'
145
+ FROM jsonb_array_elements("messages") WITH ORDINALITY AS message("value", "ordinality")
146
+ WHERE LENGTH(BTRIM(COALESCE(message."value"->>'content', ''))) > 0
147
+ ORDER BY message."ordinality" DESC
148
+ LIMIT 1
149
+ ),
150
+ ''
151
+ ) AS "lastPreviewMessageContent",
152
+ COALESCE(
153
+ (
154
+ SELECT COUNT(*)::INT
155
+ FROM jsonb_array_elements("messages") AS message("value")
156
+ WHERE
157
+ UPPER(COALESCE(message."value"->>'sender', '')) IN ('AGENT', 'MODEL')
158
+ AND (
159
+ COALESCE(message."value"->>'isComplete', '') = 'false'
160
+ OR LOWER(COALESCE(message."value"->>'lifecycleState', '')) IN ('queued', 'running')
161
+ )
162
+ ),
163
+ 0
164
+ ) AS "pendingAssistantMessageCount"
165
+ FROM ${userChatTableName}
166
+ WHERE ${block(whereClause)}
167
+ ORDER BY "createdAt" DESC
168
+ `,
169
+ ),
167
170
  queryValues,
168
171
  );
169
172
 
@@ -194,19 +197,19 @@ async function listUserChatSummarySeedsViaSqlite(options: ListUserChatsOptions):
194
197
  const shouldLoadExternalChats =
195
198
  shouldLoadAllUsersChats || (options.viewerIsAdmin && options.includeExternalChats);
196
199
  const whereClause = shouldLoadAllUsersChats
197
- ? `
200
+ ? spaceTrim(`
198
201
  chat."agentPermanentId" = ?
199
- `
202
+ `)
200
203
  : shouldLoadExternalChats
201
- ? `
204
+ ? spaceTrim(`
202
205
  chat."agentPermanentId" = ?
203
206
  AND (chat."source" <> ? OR chat."userId" = ?)
204
- `
205
- : `
207
+ `)
208
+ : spaceTrim(`
206
209
  chat."userId" = ?
207
210
  AND chat."agentPermanentId" = ?
208
211
  AND chat."source" = ?
209
- `;
212
+ `);
210
213
  const queryValues = shouldLoadAllUsersChats
211
214
  ? [options.agentPermanentId]
212
215
  : shouldLoadExternalChats
@@ -216,54 +219,56 @@ async function listUserChatSummarySeedsViaSqlite(options: ListUserChatsOptions):
216
219
  try {
217
220
  const summaryRows = database
218
221
  .prepare(
219
- `
220
- SELECT
221
- chat."id",
222
- chat."createdAt",
223
- chat."updatedAt",
224
- chat."lastMessageAt",
225
- chat."title",
226
- chat."source",
227
- chat."userId",
228
- COALESCE(json_array_length(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}), 0) AS "messagesCount",
229
- COALESCE(
230
- (
231
- SELECT CAST(json_extract(message.value, '$.content') AS TEXT)
232
- FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
233
- WHERE UPPER(CAST(COALESCE(json_extract(message.value, '$.sender'), '') AS TEXT)) = 'USER'
234
- ORDER BY CAST(message.key AS INTEGER) ASC
235
- LIMIT 1
236
- ),
237
- ''
238
- ) AS "firstUserMessageContent",
239
- COALESCE(
240
- (
241
- SELECT CAST(json_extract(message.value, '$.content') AS TEXT)
242
- FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
243
- WHERE LENGTH(TRIM(CAST(COALESCE(json_extract(message.value, '$.content'), '') AS TEXT))) > 0
244
- ORDER BY CAST(message.key AS INTEGER) DESC
245
- LIMIT 1
246
- ),
247
- ''
248
- ) AS "lastPreviewMessageContent",
249
- COALESCE(
250
- (
251
- SELECT COUNT(*)
252
- FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
253
- WHERE
254
- UPPER(CAST(COALESCE(json_extract(message.value, '$.sender'), '') AS TEXT)) IN ('AGENT', 'MODEL')
255
- AND (
256
- json_extract(message.value, '$.isComplete') = 0
257
- OR LOWER(CAST(COALESCE(json_extract(message.value, '$.isComplete'), '') AS TEXT)) = 'false'
258
- OR LOWER(CAST(COALESCE(json_extract(message.value, '$.lifecycleState'), '') AS TEXT)) IN ('queued', 'running')
259
- )
260
- ),
261
- 0
262
- ) AS "pendingAssistantMessageCount"
263
- FROM ${userChatTableName} AS chat
264
- WHERE ${whereClause}
265
- ORDER BY chat."createdAt" DESC
266
- `,
222
+ spaceTrim(
223
+ (block) => `
224
+ SELECT
225
+ chat."id",
226
+ chat."createdAt",
227
+ chat."updatedAt",
228
+ chat."lastMessageAt",
229
+ chat."title",
230
+ chat."source",
231
+ chat."userId",
232
+ COALESCE(json_array_length(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}), 0) AS "messagesCount",
233
+ COALESCE(
234
+ (
235
+ SELECT CAST(json_extract(message.value, '$.content') AS TEXT)
236
+ FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
237
+ WHERE UPPER(CAST(COALESCE(json_extract(message.value, '$.sender'), '') AS TEXT)) = 'USER'
238
+ ORDER BY CAST(message.key AS INTEGER) ASC
239
+ LIMIT 1
240
+ ),
241
+ ''
242
+ ) AS "firstUserMessageContent",
243
+ COALESCE(
244
+ (
245
+ SELECT CAST(json_extract(message.value, '$.content') AS TEXT)
246
+ FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
247
+ WHERE LENGTH(TRIM(CAST(COALESCE(json_extract(message.value, '$.content'), '') AS TEXT))) > 0
248
+ ORDER BY CAST(message.key AS INTEGER) DESC
249
+ LIMIT 1
250
+ ),
251
+ ''
252
+ ) AS "lastPreviewMessageContent",
253
+ COALESCE(
254
+ (
255
+ SELECT COUNT(*)
256
+ FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
257
+ WHERE
258
+ UPPER(CAST(COALESCE(json_extract(message.value, '$.sender'), '') AS TEXT)) IN ('AGENT', 'MODEL')
259
+ AND (
260
+ json_extract(message.value, '$.isComplete') = 0
261
+ OR LOWER(CAST(COALESCE(json_extract(message.value, '$.isComplete'), '') AS TEXT)) = 'false'
262
+ OR LOWER(CAST(COALESCE(json_extract(message.value, '$.lifecycleState'), '') AS TEXT)) IN ('queued', 'running')
263
+ )
264
+ ),
265
+ 0
266
+ ) AS "pendingAssistantMessageCount"
267
+ FROM ${userChatTableName} AS chat
268
+ WHERE ${block(whereClause)}
269
+ ORDER BY chat."createdAt" DESC
270
+ `,
271
+ ),
267
272
  )
268
273
  .all(...queryValues) as Array<UserChatSummarySeedSqlRow>;
269
274
 
@@ -410,10 +415,8 @@ async function listUserChatSummarySeedsViaSupabase(options: ListUserChatsOptions
410
415
 
411
416
  /**
412
417
  * Maps one full chat record into a lightweight summary seed.
413
- *
414
- * @private function of `userChat`
415
418
  */
416
- function createUserChatSummarySeedFromChatRecord(chat: UserChatRecord): UserChatSummarySeed {
419
+ export function createUserChatSummarySeedFromChatRecord(chat: UserChatRecord): UserChatSummarySeed {
417
420
  return {
418
421
  id: chat.id,
419
422
  createdAt: chat.createdAt,
@@ -3,6 +3,7 @@ import type { UserChatRecord } from './UserChatRecord';
3
3
  import { createUserChat } from './createUserChat';
4
4
  import { updateUserChatMessages } from './updateUserChatMessages';
5
5
  import { isFrozenUserChatSource, type UserChatSource } from './UserChatSource';
6
+ import { isUserChatNotFoundScopeError } from './UserChatScopeError';
6
7
 
7
8
  /**
8
9
  * Input payload for persisting one frozen external chat snapshot.
@@ -24,12 +25,26 @@ export async function persistFrozenUserChat(options: PersistFrozenUserChatOption
24
25
  }
25
26
 
26
27
  if (options.chatId) {
27
- return updateUserChatMessages({
28
- userId: options.userId,
29
- agentPermanentId: options.agentPermanentId,
30
- chatId: options.chatId,
31
- messages: options.messages,
32
- });
28
+ try {
29
+ return await updateUserChatMessages({
30
+ userId: options.userId,
31
+ agentPermanentId: options.agentPermanentId,
32
+ chatId: options.chatId,
33
+ messages: options.messages,
34
+ });
35
+ } catch (error) {
36
+ if (!isUserChatNotFoundScopeError(error)) {
37
+ throw error;
38
+ }
39
+
40
+ return createUserChat({
41
+ userId: options.userId,
42
+ agentPermanentId: options.agentPermanentId,
43
+ source: options.source,
44
+ chatId: options.chatId,
45
+ messages: options.messages,
46
+ });
47
+ }
33
48
  }
34
49
 
35
50
  return createUserChat({
@@ -9,7 +9,7 @@ import type { ChatMessage, ChatPrompt } from '@promptbook-local/types';
9
9
  import type { string_book } from '../../../../../src/book-2.0/agent-source/string_book';
10
10
  import type { ChatPromptResult } from '../../../../../src/execution/PromptResult';
11
11
  import { createImmediateUserChatAnswerModelRequirements } from './createImmediateUserChatAnswerModelRequirements';
12
- import { getUserChat } from './getUserChat';
12
+ import { getUserChatForJobRunner } from './getUserChatForJobRunner';
13
13
  import { getUserChatJobById } from './getUserChatJobById';
14
14
  import { mutateUserChat } from './mutateUserChat';
15
15
  import type { UserChatJobParameters, UserChatJobRecord } from './UserChatJobRecord';
@@ -109,11 +109,7 @@ async function resolveImmediateUserChatAnswerContext(
109
109
  return null;
110
110
  }
111
111
 
112
- const chat = await getUserChat({
113
- userId: job.userId,
114
- agentPermanentId: job.agentPermanentId,
115
- chatId: job.chatId,
116
- });
112
+ const chat = await getUserChatForJobRunner(job);
117
113
 
118
114
  if (!chat) {
119
115
  return null;
@@ -17,7 +17,7 @@ import {
17
17
  DEFAULT_USER_CHAT_JOB_HEARTBEAT_MAX_CONSECUTIVE_FAILURES,
18
18
  } from './createUserChatJobHeartbeatController';
19
19
  import { finalizeUserChatJob } from './finalizeUserChatJob';
20
- import { getUserChat } from './getUserChat';
20
+ import { getUserChatForJobRunner } from './getUserChatForJobRunner';
21
21
  import { heartbeatUserChatJob } from './heartbeatUserChatJob';
22
22
  import { persistUserChatJobTerminalState } from './persistUserChatJobTerminalState';
23
23
  import { persistUserChatJobProgressCard } from './persistUserChatJobProgressCard';
@@ -159,11 +159,7 @@ function createRunUserChatJobProgressReporter(
159
159
  */
160
160
  async function resolveRunUserChatJobStartContext(job: UserChatJobRecord): Promise<RunUserChatJobStartContext | null> {
161
161
  const [chat, userRow] = await Promise.all([
162
- getUserChat({
163
- userId: job.userId,
164
- agentPermanentId: job.agentPermanentId,
165
- chatId: job.chatId,
166
- }),
162
+ getUserChatForJobRunner(job),
167
163
  getUserById(job.userId),
168
164
  ]);
169
165
 
@@ -0,0 +1,63 @@
1
+ import type { ChatMessage } from '@promptbook-local/types';
2
+
3
+ /**
4
+ * JSON property stored on the first message of a frozen TEAM conversation.
5
+ *
6
+ * A message-level property keeps the relation backwards-compatible without changing the UserChat table.
7
+ */
8
+ const TEAM_MEMBER_USER_CHAT_CONTEXT_KEY = '__promptbookTeamMemberChat';
9
+
10
+ /**
11
+ * Primary chat information attached to a frozen teammate conversation.
12
+ */
13
+ export type TeamMemberUserChatContext = {
14
+ readonly version: 1;
15
+ readonly primaryAgentPermanentId: string;
16
+ readonly primaryAgentName: string;
17
+ readonly primaryChatId: string;
18
+ };
19
+
20
+ /**
21
+ * Adds the primary-chat relation to the first message of a frozen teammate transcript.
22
+ */
23
+ export function attachTeamMemberUserChatContext(
24
+ messages: ReadonlyArray<ChatMessage>,
25
+ context: TeamMemberUserChatContext,
26
+ ): Array<ChatMessage> {
27
+ const firstMessage = messages[0];
28
+ if (!firstMessage) {
29
+ return [...messages];
30
+ }
31
+
32
+ return [
33
+ {
34
+ ...firstMessage,
35
+ [TEAM_MEMBER_USER_CHAT_CONTEXT_KEY]: context,
36
+ } as ChatMessage,
37
+ ...messages.slice(1),
38
+ ];
39
+ }
40
+
41
+ /**
42
+ * Reads the optional primary-chat relation from a frozen teammate transcript.
43
+ */
44
+ export function getTeamMemberUserChatContext(messages: ReadonlyArray<ChatMessage>): TeamMemberUserChatContext | null {
45
+ const firstMessage = messages[0] as (ChatMessage & Record<string, unknown>) | undefined;
46
+ const value = firstMessage?.[TEAM_MEMBER_USER_CHAT_CONTEXT_KEY];
47
+
48
+ return isTeamMemberUserChatContext(value) ? value : null;
49
+ }
50
+
51
+ /**
52
+ * Validates the compact context stored in untrusted persisted message JSON.
53
+ */
54
+ function isTeamMemberUserChatContext(value: unknown): value is TeamMemberUserChatContext {
55
+ return Boolean(
56
+ value &&
57
+ typeof value === 'object' &&
58
+ (value as TeamMemberUserChatContext).version === 1 &&
59
+ typeof (value as TeamMemberUserChatContext).primaryAgentPermanentId === 'string' &&
60
+ typeof (value as TeamMemberUserChatContext).primaryAgentName === 'string' &&
61
+ typeof (value as TeamMemberUserChatContext).primaryChatId === 'string',
62
+ );
63
+ }
@@ -16,7 +16,11 @@ export { getUserChatJobByClientMessageId } from './userChat/getUserChatJobByClie
16
16
  export { heartbeatUserChatJob } from './userChat/heartbeatUserChatJob';
17
17
  export { isUserChatViewOnly } from './userChat/isUserChatViewOnly';
18
18
  export { listExpiredRunningUserChatJobs } from './userChat/listExpiredRunningUserChatJobs';
19
- export { listUserChats, listUserChatSummarySeeds } from './userChat/listUserChats';
19
+ export {
20
+ createUserChatSummarySeedFromChatRecord,
21
+ listUserChats,
22
+ listUserChatSummarySeeds,
23
+ } from './userChat/listUserChats';
20
24
  export { listUserChatJobActivityCounts, listUserChatJobs } from './userChat/listUserChatJobs';
21
25
  export { mutateUserChat } from './userChat/mutateUserChat';
22
26
  export { persistUserChatJobTerminalState } from './userChat/persistUserChatJobTerminalState';
@@ -4,7 +4,7 @@ import type { UserChatTimeout } from '../userChatClient';
4
4
  import { requestUserChatApi } from './requestUserChatApi';
5
5
 
6
6
  /**
7
- * Cancels one durable timeout in the agent-wide timeout manager.
7
+ * Cancels one planned message of the agent from its goal chat.
8
8
  *
9
9
  * @private shared helper for the Agents Server browser client
10
10
  */
@@ -14,6 +14,6 @@ export async function cancelAgentUserTimeout(agentName: string, timeoutId: strin
14
14
  {
15
15
  method: 'DELETE',
16
16
  },
17
- 'Failed to cancel agent timeout.',
17
+ 'Failed to cancel the planned message.',
18
18
  );
19
19
  }
@@ -4,7 +4,7 @@ import type { AgentUserTimeoutListResponse } from '../userChatClient';
4
4
  import { requestUserChatApi } from './requestUserChatApi';
5
5
 
6
6
  /**
7
- * Loads all durable timeouts for one user+agent across chats.
7
+ * Loads every planned message of one agent, as listed in its goal chat.
8
8
  *
9
9
  * @private shared helper for the Agents Server browser client
10
10
  */
@@ -15,6 +15,6 @@ export async function fetchAgentUserTimeouts(agentName: string): Promise<AgentUs
15
15
  method: 'GET',
16
16
  cache: 'no-store',
17
17
  },
18
- 'Failed to load agent timeouts.',
18
+ 'Failed to load planned messages.',
19
19
  );
20
20
  }
@@ -12,12 +12,10 @@ export { fetchAgentUserTimeouts } from './userChatClient/fetchAgentUserTimeouts'
12
12
  export { fetchUserChat } from './userChatClient/fetchUserChat';
13
13
  export { fetchUserChats } from './userChatClient/fetchUserChats';
14
14
  export { removeUserChat } from './userChatClient/removeUserChat';
15
- export { runAgentUserTimeoutBulkAction } from './userChatClient/runAgentUserTimeoutBulkAction';
16
15
  export { saveUserChatDraft } from './userChatClient/saveUserChatDraft';
17
16
  export { saveUserChatMessages } from './userChatClient/saveUserChatMessages';
18
17
  export { sendUserChatMessage } from './userChatClient/sendUserChatMessage';
19
18
  export { streamUserChat } from './userChatClient/streamUserChat';
20
- export { updateAgentUserTimeout } from './userChatClient/updateAgentUserTimeout';
21
19
  export { UserChatApiError } from './userChatClient/UserChatApiError';
22
20
 
23
21
  /**
@@ -39,12 +37,21 @@ export type UserChatSummary = {
39
37
  updatedAt: string;
40
38
  lastMessageAt: string | null;
41
39
  source: UserChatSource;
40
+ /**
41
+ * Database user id owning the chat, used to link a super-admin to its owner.
42
+ */
43
+ userId?: number;
42
44
  isReadOnly: boolean;
43
45
  /**
44
46
  * True when the chat belongs to a different user than the current viewer
45
47
  * (visible only to admins/super-admins browsing external chats).
46
48
  */
47
49
  isExternalUserChat?: boolean;
50
+ /**
51
+ * True for the singleton goal chat the agent keeps with itself, which is pinned above
52
+ * every other chat and rendered with its own icon.
53
+ */
54
+ isAgentGoalChat?: boolean;
48
55
  messagesCount: number;
49
56
  title: string;
50
57
  preview: string;
@@ -134,35 +141,6 @@ export type AgentUserTimeoutListResponse = {
134
141
  generatedAt: string;
135
142
  };
136
143
 
137
- /**
138
- * Editable timeout fields accepted by the agent-wide timeout update endpoint.
139
- */
140
- export type AgentUserTimeoutUpdatePayload = {
141
- dueAt?: string;
142
- recurrenceIntervalMs?: number | null;
143
- message?: string | null;
144
- parameters?: Record<string, unknown>;
145
- paused?: boolean;
146
- extendByMs?: number;
147
- };
148
-
149
- /**
150
- * Supported bulk timeout actions in the agent-wide timeout manager.
151
- */
152
- export type AgentUserTimeoutBulkAction = 'cancel_all_active' | 'pause_all_active' | 'resume_all_paused';
153
-
154
- /**
155
- * API payload returned after one bulk timeout action.
156
- */
157
- export type AgentUserTimeoutBulkActionResponse = {
158
- action: AgentUserTimeoutBulkAction;
159
- matchedCount: number;
160
- updatedCount: number;
161
- timeoutIds: Array<string>;
162
- hasMore: boolean;
163
- generatedAt: string;
164
- };
165
-
166
144
  /**
167
145
  * API payload for list endpoint.
168
146
  */
@@ -134,7 +134,11 @@ export type ListUserChatTimeoutsOptions = {
134
134
  * Query options for loading one timeout scoped only to user + agent.
135
135
  */
136
136
  export type GetAgentScopedUserChatTimeoutOptions = {
137
- userId: number;
137
+ /**
138
+ * Owning user, or `undefined` to span every user of the agent
139
+ * (used by the agent goal chat, which plans on behalf of the agent itself).
140
+ */
141
+ userId?: number;
138
142
  agentPermanentId: string;
139
143
  timeoutId: string;
140
144
  };
@@ -143,7 +147,11 @@ export type GetAgentScopedUserChatTimeoutOptions = {
143
147
  * Query options for listing all timeouts owned by one user+agent across chats.
144
148
  */
145
149
  export type ListAgentUserChatTimeoutsOptions = {
146
- userId: number;
150
+ /**
151
+ * Owning user, or `undefined` to span every user of the agent
152
+ * (used by the agent goal chat, which plans on behalf of the agent itself).
153
+ */
154
+ userId?: number;
147
155
  agentPermanentId: string;
148
156
  statuses?: ReadonlyArray<UserChatTimeoutStatus>;
149
157
  includePaused?: boolean;
@@ -1,3 +1,4 @@
1
+ import { spaceTrim } from 'spacetrim';
1
2
  import { $provideClientSql } from '@/src/database/$provideClientSql';
2
3
  import { isAgentsServerSqliteMode } from '@/src/database/agentsServerDatabaseMode';
3
4
  import type { UserChatTimeoutRecord, UserChatTimeoutRow } from '../UserChatTimeoutRecord';
@@ -32,31 +33,33 @@ export async function claimNextDueUserChatTimeout(
32
33
 
33
34
  try {
34
35
  claimedRows = await sql.raw<Array<UserChatTimeoutRow>>(
35
- `
36
- WITH candidate AS (
37
- SELECT timeout."id"
38
- FROM ${tableIdentifier} timeout
39
- WHERE timeout."status" = 'QUEUED'
40
- AND timeout."cancelRequestedAt" IS NULL
41
- AND timeout."pausedAt" IS NULL
42
- AND timeout."dueAt" <= CURRENT_TIMESTAMP
43
- ${preferredTimeoutClause}
44
- ORDER BY timeout."dueAt" ASC, timeout."createdAt" ASC
45
- LIMIT 1
46
- FOR UPDATE SKIP LOCKED
47
- )
48
- UPDATE ${tableIdentifier} timeout
49
- SET
50
- "status" = 'RUNNING',
51
- "updatedAt" = CURRENT_TIMESTAMP,
52
- "startedAt" = COALESCE(timeout."startedAt", CURRENT_TIMESTAMP),
53
- "leaseExpiresAt" = CURRENT_TIMESTAMP + ($1 * INTERVAL '1 millisecond'),
54
- "attemptCount" = timeout."attemptCount" + 1,
55
- "failureReason" = NULL
56
- FROM candidate
57
- WHERE timeout."id" = candidate."id"
58
- RETURNING timeout.*
59
- `,
36
+ spaceTrim(
37
+ (block) => `
38
+ WITH candidate AS (
39
+ SELECT timeout."id"
40
+ FROM ${tableIdentifier} timeout
41
+ WHERE timeout."status" = 'QUEUED'
42
+ AND timeout."cancelRequestedAt" IS NULL
43
+ AND timeout."pausedAt" IS NULL
44
+ AND timeout."dueAt" <= CURRENT_TIMESTAMP
45
+ ${block(preferredTimeoutClause)}
46
+ ORDER BY timeout."dueAt" ASC, timeout."createdAt" ASC
47
+ LIMIT 1
48
+ FOR UPDATE SKIP LOCKED
49
+ )
50
+ UPDATE ${tableIdentifier} timeout
51
+ SET
52
+ "status" = 'RUNNING',
53
+ "updatedAt" = CURRENT_TIMESTAMP,
54
+ "startedAt" = COALESCE(timeout."startedAt", CURRENT_TIMESTAMP),
55
+ "leaseExpiresAt" = CURRENT_TIMESTAMP + ($1 * INTERVAL '1 millisecond'),
56
+ "attemptCount" = timeout."attemptCount" + 1,
57
+ "failureReason" = NULL
58
+ FROM candidate
59
+ WHERE timeout."id" = candidate."id"
60
+ RETURNING timeout.*
61
+ `,
62
+ ),
60
63
  values,
61
64
  );
62
65
  } catch (error) {