@promptbook/cli 0.114.0-1 → 0.114.0-3

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 (199) hide show
  1. package/README.md +16 -15
  2. package/apps/agents-server/next.config.ts +11 -0
  3. package/apps/agents-server/package.json +6 -4
  4. package/apps/agents-server/playwright.config.ts +28 -38
  5. package/apps/agents-server/scripts/build-agents-server.js +62 -0
  6. package/apps/agents-server/scripts/build-e2e.js +38 -0
  7. package/apps/agents-server/scripts/ensure-root-dependencies.js +86 -0
  8. package/apps/agents-server/scripts/prerender-homepage.js +1 -1
  9. package/apps/agents-server/scripts/run-e2e-tests.js +34 -0
  10. package/apps/agents-server/scripts/run-npm.js +42 -0
  11. package/apps/agents-server/src/app/admin/email-server/page.tsx +14 -6
  12. package/apps/agents-server/src/app/api/elevenlabs/tts/route.ts +3 -3
  13. package/apps/agents-server/src/app/api/onboarding/book/route.ts +7 -6
  14. package/apps/agents-server/src/app/layout.tsx +6 -0
  15. package/apps/agents-server/src/app/superadmin/servers/ServersRegistryTable.tsx +105 -102
  16. package/apps/agents-server/src/app/superadmin/servers/useServersRegistryState.ts +15 -7
  17. package/apps/agents-server/src/components/AgentProjectDnsInstructions/AgentProjectDnsInstructions.tsx +11 -11
  18. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ManGoBookEditor.tsx +82 -0
  19. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/WizardShell.tsx +2 -2
  20. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/BookStep.tsx +13 -16
  21. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/ZadaniStep.tsx +4 -4
  22. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/bookSections.ts +23 -16
  23. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/bookSource.ts +54 -0
  24. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/bookService.ts +15 -8
  25. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/createManGoAgentSource.ts +3 -37
  26. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/createManGoOpenEditorRequest.ts +1 -1
  27. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/OnboardingProvider.tsx +2 -2
  28. package/apps/agents-server/src/components/UsersList/CreateUserDialog.tsx +13 -22
  29. package/apps/agents-server/src/components/UsersList/PasswordGeneratorDialog.tsx +216 -0
  30. package/apps/agents-server/src/components/UsersList/UsersList.tsx +16 -11
  31. package/apps/agents-server/src/components/UsersList/generateSecurePassword.ts +112 -24
  32. package/apps/agents-server/src/components/UsersList/userDialogClassNames.ts +11 -0
  33. package/apps/agents-server/src/languages/ServerTranslationKeys.ts +11 -0
  34. package/apps/agents-server/src/languages/translations/czech.yaml +11 -0
  35. package/apps/agents-server/src/languages/translations/english.yaml +11 -0
  36. package/apps/agents-server/src/utils/agentProjects/agentProjectHrefs.ts +11 -0
  37. package/apps/agents-server/src/utils/agentProjects/createAgentProjectDnsRecords.ts +53 -7
  38. package/apps/agents-server/src/utils/agentProjects/createAgentProjectMarkdownReferences.ts +37 -27
  39. package/apps/agents-server/src/utils/manGoOnboarding/manGoOnboardingAgentBooks.ts +2 -13
  40. package/apps/agents-server/src/utils/manGoOnboarding/manGoOnboardingAgentRuntime.ts +21 -73
  41. package/apps/agents-server/src/utils/stalwart/createEmailDnsInstructions.ts +9 -5
  42. package/apps/agents-server/src/utils/stalwart/readStalwartEmailSnapshot.ts +23 -5
  43. package/apps/agents-server/src/utils/stalwart/stalwartBootstrap.ts +2 -1
  44. package/apps/agents-server/src/utils/stalwart/stalwartMailBridge.ts +7 -0
  45. package/apps/agents-server/tests/e2e/e2eEnvironment.cjs +49 -0
  46. package/esm/index.es.js +1105 -273
  47. package/esm/index.es.js.map +1 -1
  48. package/esm/scripts/run-codex-prompts/common/runGoScript/scriptExecutionLog.d.ts +7 -0
  49. package/esm/scripts/run-codex-prompts/git/coderGitSync.d.ts +43 -0
  50. package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -0
  51. package/esm/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +8 -1
  52. package/esm/scripts/run-codex-prompts/ping/buildCoderPingPrompt.d.ts +20 -0
  53. package/esm/scripts/run-codex-prompts/ping/extractCoderPingAnswer.d.ts +9 -0
  54. package/esm/scripts/run-codex-prompts/ping/pingCoderHarness.d.ts +23 -0
  55. package/esm/scripts/run-codex-prompts/ping/printCoderPingResult.d.ts +5 -0
  56. package/esm/scripts/run-codex-prompts/prompts/findNextTodoPrompt.d.ts +2 -1
  57. package/esm/scripts/run-codex-prompts/prompts/isPromptCompatibleWithRunner.d.ts +27 -0
  58. package/esm/scripts/run-codex-prompts/prompts/listRunnablePrompts.d.ts +2 -1
  59. package/esm/scripts/run-codex-prompts/prompts/listUpcomingTasks.d.ts +2 -1
  60. package/esm/scripts/run-codex-prompts/prompts/replacePromptTodoStatusLine.d.ts +7 -0
  61. package/esm/scripts/run-codex-prompts/testing/TestBeforeMode.d.ts +16 -0
  62. package/esm/scripts/run-codex-prompts/testing/createTestBeforeRepairPrompt.d.ts +9 -0
  63. package/esm/scripts/run-codex-prompts/testing/limitTestOutput.d.ts +4 -0
  64. package/esm/scripts/run-codex-prompts/testing/runPromptTestCommand.d.ts +1 -2
  65. package/esm/scripts/run-codex-prompts/testing/runTestBefore.d.ts +24 -0
  66. package/esm/scripts/run-codex-prompts/ui/buildRunUiFrameShared.d.ts +1 -0
  67. package/esm/scripts/verify-prompts/verify-prompts.d.ts +5 -0
  68. package/esm/src/book-2.0/book-language-documentation/BookLanguageManualDictionary.d.ts +1 -15
  69. package/esm/src/book-2.0/book-language-documentation/getBookLanguageManualCommitmentGroups.d.ts +1 -1
  70. package/esm/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.d.ts +0 -4
  71. package/esm/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
  72. package/esm/src/book-components/Chat/utils/renderMarkdown.d.ts +7 -0
  73. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
  74. package/esm/src/cli/cli-commands/coder/agentCodingFile.d.ts +2 -3
  75. package/esm/src/cli/cli-commands/coder/ping.d.ts +10 -0
  76. package/esm/src/cli/cli-commands/coder/ping.test.d.ts +1 -0
  77. package/esm/src/cli/cli-commands/coder.d.ts +1 -0
  78. package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
  79. package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
  80. package/esm/src/cli/common/loadPromptsModule.d.ts +16 -0
  81. package/esm/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  82. package/esm/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  83. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
  84. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
  85. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
  86. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
  87. package/esm/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
  88. package/esm/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
  89. package/esm/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
  90. package/esm/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
  91. package/esm/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
  92. package/esm/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
  93. package/esm/src/version.d.ts +1 -1
  94. package/package.json +1 -1
  95. package/src/book-2.0/book-language-documentation/BookLanguageManualDictionary.ts +1 -15
  96. package/src/book-2.0/book-language-documentation/bookLanguageDocumentationExamples.ts +1 -2
  97. package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +92 -32
  98. package/src/book-2.0/book-language-documentation/czechBookLanguageManualDictionary.ts +16 -39
  99. package/src/book-2.0/book-language-documentation/englishBookLanguageManualDictionary.ts +16 -36
  100. package/src/book-2.0/book-language-documentation/getBookLanguageManualCommitmentGroups.ts +9 -1
  101. package/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.ts +4 -51
  102. package/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.ts +291 -4
  103. package/src/book-3.0/LiteAgent.ts +11 -9
  104. package/src/book-components/Chat/utils/$provideServerDomWindow.ts +77 -0
  105. package/src/book-components/Chat/utils/renderMarkdown.ts +135 -32
  106. package/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.ts +14 -0
  107. package/src/cli/cli-commands/agents-server/buildAgentsServer/ensureAgentsServerBuild.ts +1 -0
  108. package/src/cli/cli-commands/agents-server/startAgentsServer/createLocalAgentRunOptions.ts +1 -0
  109. package/src/cli/cli-commands/coder/add.ts +40 -12
  110. package/src/cli/cli-commands/coder/agentCodingFile.ts +6 -129
  111. package/src/cli/cli-commands/coder/generate-boilerplates.ts +31 -5
  112. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +1 -1
  113. package/src/cli/cli-commands/coder/init.ts +27 -1
  114. package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +1 -4
  115. package/src/cli/cli-commands/coder/ping.ts +72 -0
  116. package/src/cli/cli-commands/coder/run.ts +25 -2
  117. package/src/cli/cli-commands/coder/verify.ts +27 -12
  118. package/src/cli/cli-commands/coder.ts +4 -0
  119. package/src/cli/cli-commands/common/coderGitSyncCliOptions.ts +78 -0
  120. package/src/cli/cli-commands/run/prepareRunCommandResources.ts +2 -1
  121. package/src/cli/cli-commands/run/resolveRunInputParameters.ts +2 -1
  122. package/src/cli/cli-commands/runInteractiveChatbot.ts +2 -1
  123. package/src/cli/common/$provideLlmToolsForCli.ts +2 -1
  124. package/src/cli/common/loadPromptsModule.ts +13 -0
  125. package/src/conversion/archive/loadArchive.ts +2 -1
  126. package/src/conversion/archive/loadJsZipModule.ts +10 -0
  127. package/src/conversion/archive/saveArchive.ts +2 -1
  128. package/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.ts +13 -1
  129. package/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.ts +13 -1
  130. package/src/llm-providers/openai/OpenAiAgentKitExecutionTools.ts +6 -2
  131. package/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.ts +7 -5
  132. package/src/llm-providers/openai/OpenAiAssistantExecutionTools.ts +1 -1
  133. package/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.ts +1 -1
  134. package/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.ts +1 -1
  135. package/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.ts +1 -1
  136. package/src/llm-providers/openai/OpenAiCompatibleRequestManager.ts +12 -1
  137. package/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.ts +1 -1
  138. package/src/llm-providers/openai/utils/loadOpenAiAgentsModule.ts +11 -0
  139. package/src/llm-providers/openai/utils/uploadFilesToOpenAi.ts +1 -1
  140. package/src/other/templates/getTemplatesPipelineCollection.ts +731 -923
  141. package/src/remote-server/createRemoteClient.ts +12 -1
  142. package/src/scrapers/website/WebsiteScraper.ts +22 -2
  143. package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +101 -0
  144. package/src/utils/misc/createLazyModuleLoader.ts +27 -0
  145. package/src/version.ts +2 -2
  146. package/src/versions.txt +2 -1
  147. package/umd/index.umd.js +1180 -342
  148. package/umd/index.umd.js.map +1 -1
  149. package/umd/scripts/run-codex-prompts/common/runGoScript/scriptExecutionLog.d.ts +7 -0
  150. package/umd/scripts/run-codex-prompts/git/coderGitSync.d.ts +43 -0
  151. package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -0
  152. package/umd/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +8 -1
  153. package/umd/scripts/run-codex-prompts/ping/buildCoderPingPrompt.d.ts +20 -0
  154. package/umd/scripts/run-codex-prompts/ping/extractCoderPingAnswer.d.ts +9 -0
  155. package/umd/scripts/run-codex-prompts/ping/pingCoderHarness.d.ts +23 -0
  156. package/umd/scripts/run-codex-prompts/ping/printCoderPingResult.d.ts +5 -0
  157. package/umd/scripts/run-codex-prompts/prompts/findNextTodoPrompt.d.ts +2 -1
  158. package/umd/scripts/run-codex-prompts/prompts/isPromptCompatibleWithRunner.d.ts +27 -0
  159. package/umd/scripts/run-codex-prompts/prompts/listRunnablePrompts.d.ts +2 -1
  160. package/umd/scripts/run-codex-prompts/prompts/listUpcomingTasks.d.ts +2 -1
  161. package/umd/scripts/run-codex-prompts/prompts/replacePromptTodoStatusLine.d.ts +7 -0
  162. package/umd/scripts/run-codex-prompts/testing/TestBeforeMode.d.ts +16 -0
  163. package/umd/scripts/run-codex-prompts/testing/createTestBeforeRepairPrompt.d.ts +9 -0
  164. package/umd/scripts/run-codex-prompts/testing/limitTestOutput.d.ts +4 -0
  165. package/umd/scripts/run-codex-prompts/testing/runPromptTestCommand.d.ts +1 -2
  166. package/umd/scripts/run-codex-prompts/testing/runTestBefore.d.ts +24 -0
  167. package/umd/scripts/run-codex-prompts/ui/buildRunUiFrameShared.d.ts +1 -0
  168. package/umd/scripts/verify-prompts/verify-prompts.d.ts +5 -0
  169. package/umd/src/book-2.0/book-language-documentation/BookLanguageManualDictionary.d.ts +1 -15
  170. package/umd/src/book-2.0/book-language-documentation/getBookLanguageManualCommitmentGroups.d.ts +1 -1
  171. package/umd/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.d.ts +0 -4
  172. package/umd/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
  173. package/umd/src/book-components/Chat/utils/renderMarkdown.d.ts +7 -0
  174. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
  175. package/umd/src/cli/cli-commands/coder/agentCodingFile.d.ts +2 -3
  176. package/umd/src/cli/cli-commands/coder/ping.d.ts +10 -0
  177. package/umd/src/cli/cli-commands/coder/ping.test.d.ts +1 -0
  178. package/umd/src/cli/cli-commands/coder.d.ts +1 -0
  179. package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
  180. package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
  181. package/umd/src/cli/common/loadPromptsModule.d.ts +16 -0
  182. package/umd/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  183. package/umd/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  184. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
  185. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
  186. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
  187. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
  188. package/umd/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
  189. package/umd/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
  190. package/umd/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
  191. package/umd/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
  192. package/umd/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
  193. package/umd/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
  194. package/umd/src/version.d.ts +1 -1
  195. package/apps/agents-server/src/app/api/onboarding/draft/route.ts +0 -23
  196. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/BookLanguagePanel.tsx +0 -125
  197. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/MarkdownBookEditor.tsx +0 -154
  198. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/MarkdownPreview.tsx +0 -188
  199. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/draftService.ts +0 -32
@@ -1,7 +1,12 @@
1
1
  import { spaceTrim } from 'spacetrim';
2
+ import { parseAgentSourceWithCommitments } from '../agent-source/parseAgentSourceWithCommitments';
3
+ import type { string_book } from '../agent-source/string_book';
4
+ import type { BookCommitment } from '../../commitments/_base/BookCommitment';
5
+ import { getAllCommitmentTypes } from '../../commitments/_common/getAllCommitmentTypes';
2
6
  import { getCommitmentDefinition } from '../../commitments/_common/getCommitmentDefinition';
3
7
  import type { string_markdown } from '../../types/string_markdown';
4
8
  import { shiftMarkdownHeadingLevels } from '../../utils/markdown/shiftMarkdownHeadingLevels';
9
+ import { getSafeCodeBlock } from './getSafeCodeBlock';
5
10
 
6
11
  /**
7
12
  * Minimal commitment shape used by documentation renderers.
@@ -59,6 +64,23 @@ const CLOSED_COMMITMENT_TYPE = 'CLOSED';
59
64
  */
60
65
  const COMMITMENT_DOCUMENTATION_SECTION_HEADING_LEVEL = 2;
61
66
 
67
+ /**
68
+ * Markdown code blocks whose Book source is shown as a commitment example.
69
+ *
70
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
71
+ */
72
+ const BOOK_CODE_BLOCK_PATTERN = /(`{3,})book[^\n]*\n([\s\S]*?)\n\1/gu;
73
+
74
+ /**
75
+ * Recognized commitment types, ordered so compound keywords take priority over
76
+ * their shorter prefixes when reducing an example line by line.
77
+ *
78
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
79
+ */
80
+ const COMMITMENT_TYPES_BY_LENGTH = [...getAllCommitmentTypes()].sort(
81
+ (firstType, secondType) => secondType.length - firstType.length,
82
+ );
83
+
62
84
  /**
63
85
  * Removes the top-level heading from one commitment documentation block.
64
86
  *
@@ -76,12 +98,18 @@ function removeLeadingTopLevelHeading(markdown: string): string {
76
98
  *
77
99
  * @param title - Heading label for the subsection.
78
100
  * @param documentation - Raw commitment documentation markdown.
101
+ * @param group - Commitment family represented by the documentation entry.
79
102
  * @param headingLevelShift - How many levels the whole entry is nested by its host document.
80
103
  * @returns Markdown subsection introducing one commitment of the family.
81
104
  *
82
105
  * @private internal utility of `createStandaloneBookLanguageMarkdown`
83
106
  */
84
- function renderDocumentationSection(title: string, documentation: string, headingLevelShift: number): string {
107
+ function renderDocumentationSection(
108
+ title: string,
109
+ documentation: string,
110
+ group: GroupedCommitmentDocumentationSource,
111
+ headingLevelShift: number,
112
+ ): string {
85
113
  const headingPrefix = '#'.repeat(COMMITMENT_DOCUMENTATION_SECTION_HEADING_LEVEL + headingLevelShift);
86
114
 
87
115
  return spaceTrim(
@@ -90,7 +118,9 @@ function renderDocumentationSection(title: string, documentation: string, headin
90
118
 
91
119
  ${block(
92
120
  shiftMarkdownHeadingLevels(
93
- removeLeadingTopLevelHeading(documentation) as string_markdown,
121
+ removeLeadingTopLevelHeading(
122
+ renderFocusedCommitmentExamples(documentation, group),
123
+ ) as string_markdown,
94
124
  headingLevelShift + 1,
95
125
  ),
96
126
  )}
@@ -116,7 +146,10 @@ export function renderGroupedCommitmentDocumentationMarkdown(
116
146
  ): string {
117
147
  const commitmentTypes = new Set([group.primary.type, ...group.aliases]);
118
148
 
119
- if (commitmentTypes.has(OPEN_COMMITMENT_TYPE) && commitmentTypes.has(CLOSED_COMMITMENT_TYPE)) {
149
+ const isOpenClosedCommitmentFamily =
150
+ commitmentTypes.has(OPEN_COMMITMENT_TYPE) && commitmentTypes.has(CLOSED_COMMITMENT_TYPE);
151
+
152
+ if (isOpenClosedCommitmentFamily) {
120
153
  const openCommitmentDefinition = getCommitmentDefinition(OPEN_COMMITMENT_TYPE);
121
154
  const closedCommitmentDefinition = getCommitmentDefinition(CLOSED_COMMITMENT_TYPE);
122
155
 
@@ -127,6 +160,7 @@ export function renderGroupedCommitmentDocumentationMarkdown(
127
160
  renderDocumentationSection(
128
161
  OPEN_COMMITMENT_TYPE,
129
162
  openCommitmentDefinition.documentation,
163
+ group,
130
164
  headingLevelShift,
131
165
  ),
132
166
  )}
@@ -135,6 +169,7 @@ export function renderGroupedCommitmentDocumentationMarkdown(
135
169
  renderDocumentationSection(
136
170
  CLOSED_COMMITMENT_TYPE,
137
171
  closedCommitmentDefinition.documentation,
172
+ group,
138
173
  headingLevelShift,
139
174
  ),
140
175
  )}
@@ -144,7 +179,259 @@ export function renderGroupedCommitmentDocumentationMarkdown(
144
179
  }
145
180
 
146
181
  return shiftMarkdownHeadingLevels(
147
- removeLeadingTopLevelHeading(group.primary.documentation) as string_markdown,
182
+ removeLeadingTopLevelHeading(
183
+ renderFocusedCommitmentExamples(group.primary.documentation, group),
184
+ ) as string_markdown,
148
185
  headingLevelShift,
149
186
  );
150
187
  }
188
+
189
+ /**
190
+ * Rewrites Book examples in commitment documentation to show one canonical
191
+ * commitment in isolation, with only `GOAL` and `CLOSED` as supporting syntax.
192
+ *
193
+ * @param documentation - Raw commitment documentation markdown.
194
+ * @param group - Commitment family represented by the documentation entry.
195
+ * @returns Documentation whose Book examples use focused canonical syntax.
196
+ *
197
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
198
+ */
199
+ function renderFocusedCommitmentExamples(
200
+ documentation: string,
201
+ group: GroupedCommitmentDocumentationSource,
202
+ ): string {
203
+ return documentation.replace(BOOK_CODE_BLOCK_PATTERN, (codeBlock, _fence, source: string) => {
204
+ const focusedSource = createFocusedCommitmentExampleSource(source, group);
205
+ return focusedSource ? getSafeCodeBlock(focusedSource, 'book') : codeBlock;
206
+ });
207
+ }
208
+
209
+ /**
210
+ * Creates a focused Book source example for one commitment documentation entry.
211
+ *
212
+ * @param source - Original Book source from the commitment documentation.
213
+ * @param group - Commitment family represented by the documentation entry.
214
+ * @returns Focused source, or `null` when the source cannot be safely reduced.
215
+ *
216
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
217
+ */
218
+ function createFocusedCommitmentExampleSource(
219
+ source: string,
220
+ group: GroupedCommitmentDocumentationSource,
221
+ ): string | null {
222
+ const parsedSource = parseAgentSourceWithCommitments(source as string_book);
223
+ const commitmentTypes = new Set([group.primary.type, ...group.aliases]);
224
+ const isOpenClosedCommitmentFamily =
225
+ commitmentTypes.has(OPEN_COMMITMENT_TYPE) && commitmentTypes.has(CLOSED_COMMITMENT_TYPE);
226
+ const allowedCommitmentTypes = new Set([
227
+ group.primary.type,
228
+ ...group.aliases,
229
+ 'GOAL',
230
+ CLOSED_COMMITMENT_TYPE,
231
+ ]);
232
+ const canonicalTypeByCommitmentType = createCanonicalCommitmentTypeByCommitmentType(
233
+ group,
234
+ isOpenClosedCommitmentFamily,
235
+ );
236
+ const focusedCommitments = parsedSource.commitments
237
+ .filter((commitment) => allowedCommitmentTypes.has(commitment.type))
238
+ .map((commitment) => {
239
+ const type = canonicalTypeByCommitmentType.get(commitment.type) || commitment.type;
240
+ return `${type}${commitment.content ? ` ${commitment.content}` : ''}`;
241
+ });
242
+
243
+ if (focusedCommitments.length > 0) {
244
+ return finalizeFocusedCommitmentExampleSource(
245
+ getFocusedExampleAgentName(parsedSource.agentName),
246
+ focusedCommitments,
247
+ );
248
+ }
249
+
250
+ return createLineFocusedCommitmentExampleSource(source, group, isOpenClosedCommitmentFamily);
251
+ }
252
+
253
+ /**
254
+ * Creates a focused example when the Book parser cannot recognize the target
255
+ * commitment because it appears as the first source line or has a shared prefix.
256
+ *
257
+ * @param source - Original Book source from the documentation code block.
258
+ * @param group - Commitment family represented by the documentation entry.
259
+ * @param isOpenClosedCommitmentFamily - Whether the family contains both switch commitments.
260
+ * @returns Focused source, or `null` when the source does not use this commitment family.
261
+ *
262
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
263
+ */
264
+ function createLineFocusedCommitmentExampleSource(
265
+ source: string,
266
+ group: GroupedCommitmentDocumentationSource,
267
+ isOpenClosedCommitmentFamily: boolean,
268
+ ): string | null {
269
+ const sourceLines = source.split(/\r?\n/u);
270
+ const allowedCommitmentTypes = new Set([group.primary.type, ...group.aliases, 'GOAL', CLOSED_COMMITMENT_TYPE]);
271
+ const canonicalTypeByCommitmentType = createCanonicalCommitmentTypeByCommitmentType(
272
+ group,
273
+ isOpenClosedCommitmentFamily,
274
+ );
275
+ const focusedCommitments: Array<string> = [];
276
+ const firstSourceLine = sourceLines.find((line) => line.trim().length > 0) || null;
277
+ const firstCommitmentType = firstSourceLine ? getCommitmentTypeAtLine(firstSourceLine) : null;
278
+ const agentName = firstSourceLine && !firstCommitmentType ? firstSourceLine.trim() : null;
279
+ let activeFocusedCommitmentIndex: number | null = null;
280
+ let isInsideCodeBlock = false;
281
+
282
+ for (const sourceLine of sourceLines) {
283
+ const trimmedSourceLine = sourceLine.trim();
284
+
285
+ if (trimmedSourceLine.startsWith('```')) {
286
+ appendLineToActiveCommitment(focusedCommitments, activeFocusedCommitmentIndex, sourceLine);
287
+ isInsideCodeBlock = !isInsideCodeBlock;
288
+ continue;
289
+ }
290
+
291
+ if (isInsideCodeBlock) {
292
+ appendLineToActiveCommitment(focusedCommitments, activeFocusedCommitmentIndex, sourceLine);
293
+ continue;
294
+ }
295
+
296
+ const commitmentType = getCommitmentTypeAtLine(sourceLine);
297
+
298
+ if (!commitmentType) {
299
+ appendLineToActiveCommitment(focusedCommitments, activeFocusedCommitmentIndex, sourceLine);
300
+ continue;
301
+ }
302
+
303
+ if (!allowedCommitmentTypes.has(commitmentType)) {
304
+ activeFocusedCommitmentIndex = null;
305
+ continue;
306
+ }
307
+
308
+ const canonicalType = canonicalTypeByCommitmentType.get(commitmentType) || commitmentType;
309
+ const content = trimmedSourceLine.slice(commitmentType.length).trimStart();
310
+ focusedCommitments.push(`${canonicalType}${content ? ` ${content}` : ''}`);
311
+ activeFocusedCommitmentIndex = focusedCommitments.length - 1;
312
+ }
313
+
314
+ return finalizeFocusedCommitmentExampleSource(agentName, focusedCommitments);
315
+ }
316
+
317
+ /**
318
+ * Finds the longest supported commitment keyword at the start of a source line.
319
+ *
320
+ * @param sourceLine - One Book source line to inspect.
321
+ * @returns Matching commitment type, or `null` when the line is ordinary content.
322
+ *
323
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
324
+ */
325
+ function getCommitmentTypeAtLine(sourceLine: string): BookCommitment | null {
326
+ const trimmedSourceLine = sourceLine.trim();
327
+
328
+ return (
329
+ COMMITMENT_TYPES_BY_LENGTH.find(
330
+ (commitmentType) =>
331
+ trimmedSourceLine === commitmentType || trimmedSourceLine.startsWith(`${commitmentType} `),
332
+ ) || null
333
+ );
334
+ }
335
+
336
+ /**
337
+ * Appends a source line only when a focused commitment currently owns it.
338
+ *
339
+ * @param focusedCommitments - Focused commitments assembled from the example.
340
+ * @param activeFocusedCommitmentIndex - Index of the commitment receiving continuation lines.
341
+ * @param sourceLine - Source line to append.
342
+ *
343
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
344
+ */
345
+ function appendLineToActiveCommitment(
346
+ focusedCommitments: Array<string>,
347
+ activeFocusedCommitmentIndex: number | null,
348
+ sourceLine: string,
349
+ ): void {
350
+ if (activeFocusedCommitmentIndex === null) {
351
+ return;
352
+ }
353
+
354
+ focusedCommitments[activeFocusedCommitmentIndex] += `\n${sourceLine}`;
355
+ }
356
+
357
+ /**
358
+ * Adds the standard closing marker and formats one reduced Book example.
359
+ *
360
+ * @param agentName - Optional human-readable title retained from the original example.
361
+ * @param focusedCommitments - Canonical commitment blocks kept in the example.
362
+ * @returns Focused source, or `null` when no relevant commitment was found.
363
+ *
364
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
365
+ */
366
+ function finalizeFocusedCommitmentExampleSource(
367
+ agentName: string | null,
368
+ focusedCommitments: Array<string>,
369
+ ): string | null {
370
+ const normalizedFocusedCommitments = focusedCommitments.map((commitment) => commitment.trim());
371
+
372
+ if (normalizedFocusedCommitments.length === 0) {
373
+ return null;
374
+ }
375
+
376
+ const isClosedCommitmentIncluded = normalizedFocusedCommitments.some((commitment) =>
377
+ commitment.startsWith(CLOSED_COMMITMENT_TYPE),
378
+ );
379
+ const isOpenCommitmentIncluded = normalizedFocusedCommitments.some((commitment) =>
380
+ commitment.startsWith(OPEN_COMMITMENT_TYPE),
381
+ );
382
+
383
+ if (!isClosedCommitmentIncluded && !isOpenCommitmentIncluded) {
384
+ normalizedFocusedCommitments.push(CLOSED_COMMITMENT_TYPE);
385
+ }
386
+
387
+ return [agentName, ...normalizedFocusedCommitments]
388
+ .filter((line): line is string => Boolean(line))
389
+ .join('\n\n');
390
+ }
391
+
392
+ /**
393
+ * Keeps an example title unless the parser interpreted a commitment-only
394
+ * example's first line as its mandatory agent name.
395
+ *
396
+ * @param agentName - Parsed agent name from the original example.
397
+ * @returns Agent title suitable for a focused example, or `null` when absent.
398
+ *
399
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
400
+ */
401
+ function getFocusedExampleAgentName(agentName: string | null): string | null {
402
+ if (!agentName || getCommitmentDefinition(agentName as BookCommitment)) {
403
+ return null;
404
+ }
405
+
406
+ return agentName;
407
+ }
408
+
409
+ /**
410
+ * Maps aliases to the canonical keyword shown by a commitment example.
411
+ *
412
+ * `OPEN` and `CLOSED` share one documentation entry, but each remains a
413
+ * distinct keyword and must therefore retain its own spelling.
414
+ *
415
+ * @param group - Commitment family represented by the documentation entry.
416
+ * @param isOpenClosedCommitmentFamily - Whether the family contains both switch commitments.
417
+ * @returns Canonical keyword by accepted source keyword.
418
+ *
419
+ * @private internal utility of `createStandaloneBookLanguageMarkdown`
420
+ */
421
+ function createCanonicalCommitmentTypeByCommitmentType(
422
+ group: GroupedCommitmentDocumentationSource,
423
+ isOpenClosedCommitmentFamily: boolean,
424
+ ): ReadonlyMap<string, string> {
425
+ const canonicalTypeByCommitmentType = new Map<string, string>();
426
+
427
+ canonicalTypeByCommitmentType.set(group.primary.type, group.primary.type);
428
+
429
+ for (const alias of group.aliases) {
430
+ canonicalTypeByCommitmentType.set(
431
+ alias,
432
+ isOpenClosedCommitmentFamily ? alias : group.primary.type,
433
+ );
434
+ }
435
+
436
+ return canonicalTypeByCommitmentType;
437
+ }
@@ -1,10 +1,4 @@
1
- import {
2
- Agent as AgentFromKit,
3
- fileSearchTool,
4
- run,
5
- setDefaultOpenAIClient,
6
- setDefaultOpenAIKey,
7
- } from '@openai/agents';
1
+ import type { Agent as AgentFromKit } from '@openai/agents';
8
2
  import { readFile } from 'fs/promises';
9
3
  import { basename, resolve } from 'path';
10
4
  import { fileURLToPath } from 'url';
@@ -17,6 +11,7 @@ import { computeOpenAiUsage } from '../llm-providers/openai/computeOpenAiUsage';
17
11
  import { OPENAI_MODELS } from '../llm-providers/openai/openai-models';
18
12
  import { OpenAiAgentKitExecutionToolsToolBuilder } from '../llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder';
19
13
  import { OpenAiVectorStoreHandler } from '../llm-providers/openai/OpenAiVectorStoreHandler';
14
+ import { loadOpenAiAgentsModule } from '../llm-providers/openai/utils/loadOpenAiAgentsModule';
20
15
  import { $provideScriptingForNode } from '../scrapers/_common/register/$provideScriptingForNode';
21
16
  import type { string_knowledge_source_link } from '../types/string_knowledge_source_content';
22
17
  import type { string_markdown, string_markdown_text } from '../types/string_markdown';
@@ -112,6 +107,7 @@ export class LiteAgent {
112
107
  const preparedAgent = await this.prepareAgent();
113
108
  preparedAgent.toolBuilder?.clearRunState();
114
109
 
110
+ const { run } = await loadOpenAiAgentsModule();
115
111
  const result = await run(
116
112
  preparedAgent.agent,
117
113
  createLiteAgentPromptText(normalizedMessage, options.context, preparedAgent.modelRequirements.promptSuffix),
@@ -165,6 +161,12 @@ export class LiteAgent {
165
161
  userId: this.options.userId,
166
162
  });
167
163
  const client = await runtime.getClient();
164
+ const {
165
+ Agent: AgentFromKit,
166
+ fileSearchTool,
167
+ setDefaultOpenAIClient,
168
+ setDefaultOpenAIKey,
169
+ } = await loadOpenAiAgentsModule();
168
170
 
169
171
  setDefaultOpenAIClient(client as TODO_any);
170
172
 
@@ -190,9 +192,9 @@ export class LiteAgent {
190
192
  })
191
193
  : null;
192
194
  const agentTools =
193
- toolBuilder?.buildAgentKitTools({
195
+ (await toolBuilder?.buildAgentKitTools({
194
196
  tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
195
- }) || [];
197
+ })) || [];
196
198
  const normalizedKnowledgeSources = await normalizeLiteAgentKnowledgeSources(
197
199
  modelRequirements.knowledgeSources || [],
198
200
  resolvedSource.sourceDirectoryPath,
@@ -0,0 +1,77 @@
1
+ import type { WindowLike as DomWindowLike } from 'dompurify';
2
+ import { spaceTrim } from 'spacetrim';
3
+ import { assertsError } from '../../../errors/assertsError';
4
+ import { EnvironmentMismatchError } from '../../../errors/EnvironmentMismatchError';
5
+
6
+ /**
7
+ * Shared DOM window reused by every render which happens outside of a browser
8
+ *
9
+ * @private utility of `$provideServerDomWindow`
10
+ */
11
+ let serverDomWindow: DomWindowLike | null = null;
12
+
13
+ /**
14
+ * Provides a DOM `window` for runtimes which do not have one, for example Node.js during server-side rendering
15
+ *
16
+ * Note: `$` is used to indicate that this function is not a pure function - it creates and caches one shared DOM window
17
+ *
18
+ * @returns DOM window which can back a DOM-dependent library like `DOMPurify`
19
+ * @throws {EnvironmentMismatchError} When the current runtime can not create a DOM window
20
+ * @private utility of `renderMarkdown`
21
+ */
22
+ export function $provideServerDomWindow(): DomWindowLike {
23
+ if (serverDomWindow === null) {
24
+ const { JSDOM } = requireServerDomLibrary();
25
+ serverDomWindow = new JSDOM('').window as unknown as DomWindowLike;
26
+ }
27
+
28
+ return serverDomWindow;
29
+ }
30
+
31
+ /**
32
+ * Loads `jsdom` which backs the DOM window outside of a browser
33
+ *
34
+ * Note: [😷] `jsdom` reaches for Node.js built-ins like `fs`, `child_process` and `net`, so browser bundlers must
35
+ * never follow the `require` below - even though it is unreachable in a browser, bundlers resolve it statically.
36
+ * They are told to replace `jsdom` with an empty module by the `browser` field of the generated package
37
+ * manifests, which is written by `applyBrowserUnsupportedDependencyStubs` during the package generation.
38
+ *
39
+ * @returns The `jsdom` library
40
+ * @throws {EnvironmentMismatchError} When `jsdom` can not be loaded in the current runtime
41
+ * @private utility of `$provideServerDomWindow`
42
+ */
43
+ function requireServerDomLibrary(): typeof import('jsdom') {
44
+ let serverDomLibrary: Partial<typeof import('jsdom')> | null = null;
45
+ let serverDomLibraryError: Error | null = null;
46
+
47
+ try {
48
+ // Note: [😷] Keep `'jsdom'` written as a literal, bundlers do not replace a computed module name
49
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
50
+ serverDomLibrary = require('jsdom') as typeof import('jsdom');
51
+ } catch (error) {
52
+ assertsError(error);
53
+ serverDomLibraryError = error;
54
+ }
55
+
56
+ if (typeof serverDomLibrary?.JSDOM !== 'function') {
57
+ throw new EnvironmentMismatchError(
58
+ spaceTrim(
59
+ (block) => `
60
+ Markdown can not be rendered because there is no DOM in the current runtime.
61
+
62
+ Rendered markdown is sanitized through \`DOMPurify\`, which needs a DOM - the DOM of the browser
63
+ when the code runs in a browser and \`jsdom\` in every other runtime, for example during
64
+ server-side rendering in **Node.js**.
65
+
66
+ ${block(
67
+ serverDomLibraryError === null
68
+ ? 'The `jsdom` module was resolved but it does not export `JSDOM`, which happens when a bundler replaces `jsdom` with an empty module in a build which is neither a browser build nor a Node.js build.'
69
+ : `${serverDomLibraryError.name}: ${serverDomLibraryError.message}`,
70
+ )}
71
+ `,
72
+ ),
73
+ );
74
+ }
75
+
76
+ return serverDomLibrary as typeof import('jsdom');
77
+ }