@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 type { Client } from 'pg';
2
3
  import { createAgentPersistenceRecords } from '../../../../../../src/collection/agent-collection/constructors/agent-collection-in-supabase/createAgentPersistenceRecords';
3
4
  import { DEFAULT_AGENT_VISIBILITY } from '../../agentVisibility';
@@ -40,7 +41,7 @@ export async function seedServerCoreAgents(
40
41
  );
41
42
 
42
43
  await client.query(
43
- `
44
+ spaceTrim(`
44
45
  INSERT INTO ${agentTableIdentifier} (
45
46
  "agentName",
46
47
  "createdAt",
@@ -56,7 +57,7 @@ export async function seedServerCoreAgents(
56
57
  "visibility"
57
58
  )
58
59
  VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8, $9::jsonb, $10, $11, $12)
59
- `,
60
+ `),
60
61
  [
61
62
  agentInsertRecord.agentName,
62
63
  agentInsertRecord.createdAt,
@@ -84,7 +85,7 @@ export async function seedServerCoreAgents(
84
85
  );
85
86
 
86
87
  await client.query(
87
- `
88
+ spaceTrim(`
88
89
  INSERT INTO ${agentHistoryTableIdentifier} (
89
90
  "createdAt",
90
91
  "agentName",
@@ -96,7 +97,7 @@ export async function seedServerCoreAgents(
96
97
  "versionName"
97
98
  )
98
99
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
99
- `,
100
+ `),
100
101
  [
101
102
  agentHistoryInsertRecord.createdAt,
102
103
  agentHistoryInsertRecord.agentName,
@@ -130,7 +131,7 @@ async function insertCoreFolder(
130
131
  const agentFolderTableIdentifier = quoteIdentifier(`${input.tablePrefix}AgentFolder`);
131
132
  const createdAt = new Date().toISOString();
132
133
  const insertResult = await client.query<{ id: number }>(
133
- `
134
+ spaceTrim(`
134
135
  INSERT INTO ${agentFolderTableIdentifier} (
135
136
  "name",
136
137
  "parentId",
@@ -142,7 +143,7 @@ async function insertCoreFolder(
142
143
  )
143
144
  VALUES ($1, NULL, $2, NULL, NULL, $3, NULL)
144
145
  RETURNING "id"
145
- `,
146
+ `),
146
147
  [CORE_AGENT_DIRECTORY_NAME, 0, createdAt],
147
148
  );
148
149
 
@@ -1,3 +1,4 @@
1
+ import { spaceTrim } from 'spacetrim';
1
2
  import { createAgentPersistenceRecords } from '../../../../../../src/collection/agent-collection/constructors/agent-collection-in-supabase/createAgentPersistenceRecords';
2
3
  import type { Client } from 'pg';
3
4
  import { DEFAULT_AGENT_VISIBILITY } from '../../agentVisibility';
@@ -34,7 +35,7 @@ export async function seedServerDefaultAgents(
34
35
  );
35
36
 
36
37
  await client.query(
37
- `
38
+ spaceTrim(`
38
39
  INSERT INTO ${agentTableIdentifier} (
39
40
  "agentName",
40
41
  "createdAt",
@@ -50,7 +51,7 @@ export async function seedServerDefaultAgents(
50
51
  "visibility"
51
52
  )
52
53
  VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8, $9::jsonb, $10, $11, $12)
53
- `,
54
+ `),
54
55
  [
55
56
  agentInsertRecord.agentName,
56
57
  agentInsertRecord.createdAt,
@@ -78,7 +79,7 @@ export async function seedServerDefaultAgents(
78
79
  );
79
80
 
80
81
  await client.query(
81
- `
82
+ spaceTrim(`
82
83
  INSERT INTO ${agentHistoryTableIdentifier} (
83
84
  "createdAt",
84
85
  "agentName",
@@ -90,7 +91,7 @@ export async function seedServerDefaultAgents(
90
91
  "versionName"
91
92
  )
92
93
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
93
- `,
94
+ `),
94
95
  [
95
96
  agentHistoryInsertRecord.createdAt,
96
97
  agentHistoryInsertRecord.agentName,
@@ -1,3 +1,4 @@
1
+ import { spaceTrim } from 'spacetrim';
1
2
  import { Client } from 'pg';
2
3
  import { createInsertStatement, quoteIdentifier, type SqlRecorder } from './createSqlRecorder';
3
4
  import type { NormalizedCreateServerInput } from './normalizeCreateServerInput';
@@ -20,10 +21,10 @@ export async function seedServerMetadata(
20
21
 
21
22
  for (const metadataEntry of input.metadataEntries) {
22
23
  await client.query(
23
- `
24
+ spaceTrim(`
24
25
  INSERT INTO ${metadataTableIdentifier} ("key", "value", "note", "createdAt", "updatedAt")
25
26
  VALUES ($1, $2, $3, now(), now())
26
- `,
27
+ `),
27
28
  [metadataEntry.key, metadataEntry.value, metadataEntry.note],
28
29
  );
29
30
 
@@ -1,3 +1,4 @@
1
+ import { spaceTrim } from 'spacetrim';
1
2
  import { Client } from 'pg';
2
3
  import { hashPassword } from '../../auth';
3
4
  import { createInsertStatement, quoteIdentifier, type SqlRecorder } from './createSqlRecorder';
@@ -23,10 +24,10 @@ export async function seedServerUsers(
23
24
  const passwordHash = await hashPassword(user.password);
24
25
 
25
26
  await client.query(
26
- `
27
+ spaceTrim(`
27
28
  INSERT INTO ${userTableIdentifier} ("username", "passwordHash", "isAdmin", "createdAt", "updatedAt")
28
29
  VALUES ($1, $2, $3, now(), now())
29
- `,
30
+ `),
30
31
  [user.username, passwordHash, user.isAdmin],
31
32
  );
32
33
 
@@ -47,12 +47,12 @@ export async function deleteManagedServer(options: {
47
47
  }
48
48
 
49
49
  const remainingRows = await client.query<Record<string, unknown>>(
50
- `
50
+ spaceTrim(`
51
51
  SELECT "id", "name", "environment", "domain", "tablePrefix", "createdAt", "updatedAt"
52
52
  FROM "${SERVER_REGISTRY_TABLE_NAME}"
53
53
  ORDER BY "name" ASC
54
54
  LIMIT 1
55
- `,
55
+ `),
56
56
  );
57
57
 
58
58
  await client.query('COMMIT');
@@ -0,0 +1,53 @@
1
+ import type { DnsRecordsSection } from '../dnsRecords/DnsRecordsSection';
2
+ import { createEmailDnsInstructions } from './createEmailDnsInstructions';
3
+
4
+ /**
5
+ * Creates the DNS section which makes agent email deliverable for one Agents Server domain.
6
+ *
7
+ * The DKIM records are intentionally not part of this section, because their public keys are generated by Stalwart
8
+ * and have to be copied from its authoritative zone on `/admin/email-server`.
9
+ *
10
+ * @param options - Email domain, public VPS IP address, and the current mail DNS state.
11
+ * @returns Email section.
12
+ *
13
+ * @private shared by the Agents Server DNS instruction views
14
+ */
15
+ export function createEmailDnsRecordsSection(options: {
16
+ /**
17
+ * Domain which sends and receives the agent email.
18
+ */
19
+ readonly domain: string;
20
+
21
+ /**
22
+ * Public VPS IP address, when known by the server.
23
+ */
24
+ readonly publicIpAddress: string | null | undefined;
25
+
26
+ /**
27
+ * Current DNS verification state of the mail records, when it is known.
28
+ */
29
+ readonly statusSummary?: string | null;
30
+
31
+ /**
32
+ * Whether the mail records currently need attention.
33
+ */
34
+ readonly isDnsIssue?: boolean;
35
+ }): DnsRecordsSection {
36
+ return {
37
+ id: 'email',
38
+ title: `Email for ${options.domain}`,
39
+ description: options.publicIpAddress
40
+ ? `Makes agent email deliverable. The A records use the detected public address of this VPS.`
41
+ : `Makes agent email deliverable. Replace <VPS_PUBLIC_IP> with the public address of this VPS.`,
42
+ variants: [
43
+ {
44
+ id: 'email',
45
+ label: 'Email',
46
+ recordSelection: 'all',
47
+ records: createEmailDnsInstructions(options.domain, options.publicIpAddress),
48
+ },
49
+ ],
50
+ statusSummary: options.statusSummary ?? null,
51
+ isDnsIssue: options.isDnsIssue,
52
+ };
53
+ }
@@ -41,12 +41,21 @@ export type UserChatSummary = {
41
41
  updatedAt: string;
42
42
  lastMessageAt: string | null;
43
43
  source: UserChatSource;
44
+ /**
45
+ * Database user id owning the chat, used to link a super-admin to its owner.
46
+ */
47
+ userId?: number;
44
48
  isReadOnly: boolean;
45
49
  /**
46
50
  * True when the chat belongs to a different user than the current viewer
47
51
  * (visible only to admins/super-admins browsing external chats).
48
52
  */
49
53
  isExternalUserChat: boolean;
54
+ /**
55
+ * True for the singleton goal chat the agent keeps with itself, which is pinned above
56
+ * every other chat and rendered with its own icon.
57
+ */
58
+ isAgentGoalChat: boolean;
50
59
  messagesCount: number;
51
60
  title: string;
52
61
  preview: string;
@@ -80,6 +89,10 @@ export type GetUserChatOptions = {
80
89
  * who may open other users' chats in a view-only mode.
81
90
  */
82
91
  viewerIsSuperAdmin?: boolean;
92
+ /**
93
+ * True when the viewer may read the agent source book and therefore also the agent goal chat.
94
+ */
95
+ viewerCanAccessAgentGoalChat?: boolean;
83
96
  agentPermanentId: string;
84
97
  chatId: string;
85
98
  };
@@ -6,6 +6,11 @@ export const USER_CHAT_SOURCES = {
6
6
  OPENAI_API: 'OPENAI_API',
7
7
  TEAM_MEMBER: 'TEAM_MEMBER',
8
8
  EMAIL: 'EMAIL',
9
+
10
+ /**
11
+ * Singleton chat every agent keeps with itself to plan work towards its goal.
12
+ */
13
+ AGENT_GOAL: 'AGENT_GOAL',
9
14
  } as const;
10
15
 
11
16
  /**
@@ -24,6 +29,10 @@ export function isFrozenUserChatSource(source: UserChatSource): boolean {
24
29
  * Resolves a compact chip label for one chat source.
25
30
  */
26
31
  export function getUserChatSourceChipLabel(source: UserChatSource): string | null {
32
+ if (source === USER_CHAT_SOURCES.AGENT_GOAL) {
33
+ return 'GOAL';
34
+ }
35
+
27
36
  if (source === USER_CHAT_SOURCES.OPENAI_API) {
28
37
  return 'API';
29
38
  }
@@ -43,6 +52,11 @@ export function getUserChatSourceChipLabel(source: UserChatSource): string | nul
43
52
  * Resolves the banner copy used for frozen external chats.
44
53
  */
45
54
  export function getUserChatSourceBannerLabel(source: UserChatSource): string | null {
55
+ if (source === USER_CHAT_SOURCES.AGENT_GOAL) {
56
+ // Note: Goal chats explain their own specialty through a dedicated notice instead of the generic frozen banner
57
+ return null;
58
+ }
59
+
46
60
  if (source === USER_CHAT_SOURCES.OPENAI_API) {
47
61
  return 'API key';
48
62
  }
@@ -2,7 +2,7 @@ import type { UserChatRecord, UserChatSummary, UserChatTimeoutActivity } from '.
2
2
  import { createUserChatRunningActivity } from './createUserChatRunningActivity';
3
3
  import { shortenText } from '../shortenText';
4
4
  import { textToPreviewText } from '../textToPreviewText';
5
- import { isFrozenUserChatSource } from './UserChatSource';
5
+ import { isFrozenUserChatSource, USER_CHAT_SOURCES } from './UserChatSource';
6
6
 
7
7
  /**
8
8
  * Max title length in chat list.
@@ -122,8 +122,14 @@ export function createUserChatSummaryFromSeed(
122
122
  options.activeJobCount && options.activeJobCount > 0
123
123
  ? options.activeJobCount
124
124
  : resolveSummaryPendingActivityCount(chat.updatedAt, chat.pendingAssistantMessageCount);
125
+ const isAgentGoalChat = chat.source === USER_CHAT_SOURCES.AGENT_GOAL;
126
+ // Note: Goal chats are owned by the agent rather than by any human, so they are never treated
127
+ // as somebody else's chat even when the viewer is not their stored owner
125
128
  const isExternalUserChat =
126
- options.viewerUserId !== undefined && chat.userId !== undefined && chat.userId !== options.viewerUserId;
129
+ !isAgentGoalChat &&
130
+ options.viewerUserId !== undefined &&
131
+ chat.userId !== undefined &&
132
+ chat.userId !== options.viewerUserId;
127
133
 
128
134
  return {
129
135
  id: chat.id,
@@ -131,8 +137,10 @@ export function createUserChatSummaryFromSeed(
131
137
  updatedAt: chat.updatedAt,
132
138
  lastMessageAt: chat.lastMessageAt,
133
139
  source: chat.source,
140
+ userId: chat.userId,
134
141
  isReadOnly: isFrozenUserChatSource(chat.source) || isExternalUserChat,
135
142
  isExternalUserChat,
143
+ isAgentGoalChat,
136
144
  messagesCount: chat.messagesCount,
137
145
  title: shortenText(storedTitle || titleSource || DEFAULT_CHAT_TITLE, CHAT_TITLE_MAX_LENGTH),
138
146
  preview: shortenText(previewSource, CHAT_PREVIEW_MAX_LENGTH),
@@ -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';
@@ -46,7 +47,7 @@ async function persistFinalUserChatJobStatus(options: {
46
47
  const sql = await $provideClientSql();
47
48
  const userChatJobTable = quoteIdentifier(await $getTableName('UserChatJob'));
48
49
  const rows = await sql.raw<Array<UserChatJobRecord>>(
49
- `
50
+ spaceTrim(`
50
51
  UPDATE ${userChatJobTable}
51
52
  SET
52
53
  "status" = $1,
@@ -79,7 +80,7 @@ async function persistFinalUserChatJobStatus(options: {
79
80
  "attemptCount",
80
81
  "provider",
81
82
  "failureReason"
82
- `,
83
+ `),
83
84
  [
84
85
  options.status,
85
86
  nowIso,
@@ -8,7 +8,14 @@ import { USER_CHAT_SOURCES } from './UserChatSource';
8
8
  * Loads one user chat by id.
9
9
  */
10
10
  export async function getUserChat(options: GetUserChatOptions): Promise<UserChatRecord | null> {
11
- const { userId, viewerIsAdmin = false, viewerIsSuperAdmin = false, agentPermanentId, chatId } = options;
11
+ const {
12
+ userId,
13
+ viewerIsAdmin = false,
14
+ viewerIsSuperAdmin = false,
15
+ viewerCanAccessAgentGoalChat = false,
16
+ agentPermanentId,
17
+ chatId,
18
+ } = options;
12
19
  const userChatTable = await provideUserChatTable();
13
20
 
14
21
  const { data, error } = await userChatTable
@@ -36,5 +43,13 @@ export async function getUserChat(options: GetUserChatOptions): Promise<UserChat
36
43
  return viewerIsSuperAdmin ? chat : null;
37
44
  }
38
45
 
46
+ if (chat.source === USER_CHAT_SOURCES.AGENT_GOAL) {
47
+ // Note: Goal chats follow agent-source-book access, and stay readable for the background
48
+ // workers that run under the goal chat's own owner identity
49
+ return viewerCanAccessAgentGoalChat || viewerIsAdmin || viewerIsSuperAdmin || chat.userId === userId
50
+ ? chat
51
+ : null;
52
+ }
53
+
39
54
  return viewerIsAdmin || viewerIsSuperAdmin ? chat : null;
40
55
  }
@@ -0,0 +1,31 @@
1
+ import { getUserChat } from './getUserChat';
2
+ import type { UserChatRecord } from './UserChatRecord';
3
+
4
+ /**
5
+ * Job identity a background runner needs to load the chat it is about to answer.
6
+ */
7
+ export type UserChatJobRunnerChatIdentity = {
8
+ readonly userId: number;
9
+ readonly agentPermanentId: string;
10
+ readonly chatId: string;
11
+ };
12
+
13
+ /**
14
+ * Loads the chat one durable job belongs to, on behalf of the background runner executing it.
15
+ *
16
+ * `getUserChat` answers a *viewer* and therefore discloses the externally created chat sources -
17
+ * `EMAIL`, `OPENAI_API` and `TEAM_MEMBER` - to administrators only. A background runner is not a
18
+ * viewer: it already owns the job, runs under the job owner's identity, and has to read every chat
19
+ * source. Without this distinction each externally created job is cancelled as if its chat had been
20
+ * deleted, so every inbound email stays unanswered.
21
+ */
22
+ export async function getUserChatForJobRunner(job: UserChatJobRunnerChatIdentity): Promise<UserChatRecord | null> {
23
+ return await getUserChat({
24
+ userId: job.userId,
25
+ // Note: The runner is trusted machinery behind an already-persisted job, not a person browsing
26
+ // somebody else's conversation
27
+ viewerIsAdmin: true,
28
+ agentPermanentId: job.agentPermanentId,
29
+ chatId: job.chatId,
30
+ });
31
+ }