@promptbook/cli 0.114.0-2 → 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 (105) hide show
  1. package/apps/agents-server/next.config.ts +11 -0
  2. package/apps/agents-server/src/app/layout.tsx +6 -0
  3. package/esm/index.es.js +677 -199
  4. package/esm/index.es.js.map +1 -1
  5. package/esm/scripts/run-codex-prompts/common/runGoScript/scriptExecutionLog.d.ts +7 -0
  6. package/esm/scripts/run-codex-prompts/git/coderGitSync.d.ts +43 -0
  7. package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -0
  8. package/esm/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +8 -1
  9. package/esm/scripts/run-codex-prompts/ping/buildCoderPingPrompt.d.ts +20 -0
  10. package/esm/scripts/run-codex-prompts/ping/extractCoderPingAnswer.d.ts +9 -0
  11. package/esm/scripts/run-codex-prompts/ping/pingCoderHarness.d.ts +23 -0
  12. package/esm/scripts/run-codex-prompts/ping/printCoderPingResult.d.ts +5 -0
  13. package/esm/scripts/verify-prompts/verify-prompts.d.ts +5 -0
  14. package/esm/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
  15. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
  16. package/esm/src/cli/cli-commands/coder/ping.d.ts +2 -5
  17. package/esm/src/cli/cli-commands/coder.d.ts +1 -1
  18. package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
  19. package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
  20. package/esm/src/cli/common/loadPromptsModule.d.ts +16 -0
  21. package/esm/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  22. package/esm/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  23. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
  24. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
  25. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
  26. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
  27. package/esm/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
  28. package/esm/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
  29. package/esm/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
  30. package/esm/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
  31. package/esm/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
  32. package/esm/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
  33. package/esm/src/version.d.ts +1 -1
  34. package/package.json +1 -1
  35. package/src/book-3.0/LiteAgent.ts +11 -9
  36. package/src/book-components/Chat/utils/$provideServerDomWindow.ts +77 -0
  37. package/src/book-components/Chat/utils/renderMarkdown.ts +2 -23
  38. package/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.ts +14 -0
  39. package/src/cli/cli-commands/agents-server/buildAgentsServer/ensureAgentsServerBuild.ts +1 -0
  40. package/src/cli/cli-commands/coder/add.ts +40 -12
  41. package/src/cli/cli-commands/coder/generate-boilerplates.ts +31 -5
  42. package/src/cli/cli-commands/coder/init.ts +27 -1
  43. package/src/cli/cli-commands/coder/ping.ts +23 -45
  44. package/src/cli/cli-commands/coder/verify.ts +27 -12
  45. package/src/cli/cli-commands/coder.ts +3 -3
  46. package/src/cli/cli-commands/common/coderGitSyncCliOptions.ts +78 -0
  47. package/src/cli/cli-commands/run/prepareRunCommandResources.ts +2 -1
  48. package/src/cli/cli-commands/run/resolveRunInputParameters.ts +2 -1
  49. package/src/cli/cli-commands/runInteractiveChatbot.ts +2 -1
  50. package/src/cli/common/$provideLlmToolsForCli.ts +2 -1
  51. package/src/cli/common/loadPromptsModule.ts +13 -0
  52. package/src/conversion/archive/loadArchive.ts +2 -1
  53. package/src/conversion/archive/loadJsZipModule.ts +10 -0
  54. package/src/conversion/archive/saveArchive.ts +2 -1
  55. package/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.ts +13 -1
  56. package/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.ts +13 -1
  57. package/src/llm-providers/openai/OpenAiAgentKitExecutionTools.ts +6 -2
  58. package/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.ts +7 -5
  59. package/src/llm-providers/openai/OpenAiAssistantExecutionTools.ts +1 -1
  60. package/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.ts +1 -1
  61. package/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.ts +1 -1
  62. package/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.ts +1 -1
  63. package/src/llm-providers/openai/OpenAiCompatibleRequestManager.ts +12 -1
  64. package/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.ts +1 -1
  65. package/src/llm-providers/openai/utils/loadOpenAiAgentsModule.ts +11 -0
  66. package/src/llm-providers/openai/utils/uploadFilesToOpenAi.ts +1 -1
  67. package/src/other/templates/getTemplatesPipelineCollection.ts +678 -967
  68. package/src/remote-server/createRemoteClient.ts +12 -1
  69. package/src/scrapers/website/WebsiteScraper.ts +22 -2
  70. package/src/utils/misc/createLazyModuleLoader.ts +27 -0
  71. package/src/version.ts +2 -2
  72. package/src/versions.txt +1 -0
  73. package/umd/index.umd.js +750 -266
  74. package/umd/index.umd.js.map +1 -1
  75. package/umd/scripts/run-codex-prompts/common/runGoScript/scriptExecutionLog.d.ts +7 -0
  76. package/umd/scripts/run-codex-prompts/git/coderGitSync.d.ts +43 -0
  77. package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -0
  78. package/umd/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +8 -1
  79. package/umd/scripts/run-codex-prompts/ping/buildCoderPingPrompt.d.ts +20 -0
  80. package/umd/scripts/run-codex-prompts/ping/extractCoderPingAnswer.d.ts +9 -0
  81. package/umd/scripts/run-codex-prompts/ping/pingCoderHarness.d.ts +23 -0
  82. package/umd/scripts/run-codex-prompts/ping/printCoderPingResult.d.ts +5 -0
  83. package/umd/scripts/verify-prompts/verify-prompts.d.ts +5 -0
  84. package/umd/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
  85. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
  86. package/umd/src/cli/cli-commands/coder/ping.d.ts +2 -5
  87. package/umd/src/cli/cli-commands/coder.d.ts +1 -1
  88. package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
  89. package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
  90. package/umd/src/cli/common/loadPromptsModule.d.ts +16 -0
  91. package/umd/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  92. package/umd/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  93. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
  94. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
  95. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
  96. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
  97. package/umd/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
  98. package/umd/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
  99. package/umd/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
  100. package/umd/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
  101. package/umd/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
  102. package/umd/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
  103. package/umd/src/version.d.ts +1 -1
  104. package/esm/scripts/run-agent-chat/runCoderPing.d.ts +0 -48
  105. package/umd/scripts/run-agent-chat/runCoderPing.d.ts +0 -48
@@ -0,0 +1,78 @@
1
+ import type {
2
+ Command as Program /* <- Note: [🔸] Using Program because Command is misleading name */,
3
+ } from 'commander';
4
+ import { spaceTrim } from 'spacetrim';
5
+ import type { CoderGitSyncOptions } from '../../../../scripts/run-codex-prompts/git/coderGitSync';
6
+ import { NotAllowed } from '../../../errors/NotAllowed';
7
+
8
+ export type { CoderGitSyncOptions };
9
+
10
+ /**
11
+ * Commander option bag for the shared `ptbk coder` git synchronization flags.
12
+ *
13
+ * @private internal utility of `promptbookCli`
14
+ */
15
+ export type CoderGitSyncCliOptions = {
16
+ readonly commit: boolean;
17
+ readonly autoPush: boolean;
18
+ readonly autoPull: boolean;
19
+ };
20
+
21
+ /**
22
+ * Description block shared by the `ptbk coder` commands which can synchronize their changes with git.
23
+ *
24
+ * @private internal utility of `promptbookCli`
25
+ */
26
+ export const CODER_GIT_SYNC_DESCRIPTION = spaceTrim(`
27
+ Git synchronization:
28
+ - --auto-pull pulls the latest changes before this command changes anything
29
+ - --commit commits the changes made by this command
30
+ - --auto-push pushes the created commit to the remote repository
31
+ `);
32
+
33
+ /**
34
+ * Registers the shared `--commit`, `--auto-push` and `--auto-pull` flags on a `ptbk coder` command.
35
+ *
36
+ * Note: Unlike `ptbk coder run`, which commits by default and opts out through `--no-commit`,
37
+ * these commands never touch git unless the flags are used explicitly.
38
+ *
39
+ * @private internal utility of `promptbookCli`
40
+ */
41
+ export function addCoderGitSyncOptions(command: Program): void {
42
+ command.option('--commit', 'Commit the changes made by this command with the coding-agent git identity', false);
43
+ command.option('--auto-push', 'Automatically git push the created commit, requires --commit', false);
44
+ command.option(
45
+ '--auto-pull',
46
+ 'Automatically git pull the latest changes before this command changes anything',
47
+ false,
48
+ );
49
+ }
50
+
51
+ /**
52
+ * Converts the Commander git synchronization flags into normalized git synchronization options.
53
+ *
54
+ * @private internal utility of `promptbookCli`
55
+ */
56
+ export function normalizeCoderGitSyncCliOptions(cliOptions: CoderGitSyncCliOptions): CoderGitSyncOptions {
57
+ if (cliOptions.autoPush && !cliOptions.commit) {
58
+ throw new NotAllowed(
59
+ spaceTrim(`
60
+ Flag \`--auto-push\` can be used only together with \`--commit\`.
61
+
62
+ **There is nothing to push when the changes are not committed.**
63
+
64
+ Actionable hint:
65
+ - Add \`--commit\`, for example \`ptbk coder init --commit --auto-push\`.
66
+ `),
67
+ );
68
+ }
69
+
70
+ return {
71
+ isCommitEnabled: cliOptions.commit,
72
+ isAutoPushEnabled: cliOptions.autoPush,
73
+ isAutoPullEnabled: cliOptions.autoPull,
74
+ };
75
+ }
76
+
77
+ // Note: [🟡] Code for CLI git synchronization options [coderGitSyncCliOptions](src/cli/cli-commands/common/coderGitSyncCliOptions.ts) should never be published outside of `@promptbook/cli`
78
+ // Note: [💞] Ignore a discrepancy between file name and exported helper names
@@ -1,7 +1,6 @@
1
1
  import colors from 'colors';
2
2
  import { writeFile } from 'fs/promises';
3
3
  import { join } from 'path';
4
- import prompts from 'prompts';
5
4
  import { spaceTrim } from 'spacetrim';
6
5
  import { getAllCommitmentsToolFunctionsForNode } from '../../../commitments/_common/getAllCommitmentsToolFunctionsForNode';
7
6
  import { DEFAULT_MAX_EXECUTION_ATTEMPTS } from '../../../config';
@@ -24,6 +23,7 @@ import { JavascriptExecutionTools } from '../../../scripting/javascript/Javascri
24
23
  import { isFileExisting } from '../../../utils/files/isFileExisting';
25
24
  import { $getCompiledBook } from '../../../wizard/$getCompiledBook';
26
25
  import { $provideLlmToolsForCli } from '../../common/$provideLlmToolsForCli';
26
+ import { loadPromptsModule } from '../../common/loadPromptsModule';
27
27
  import type { RunCommandCliOptions } from './runCommandAction';
28
28
 
29
29
  /**
@@ -156,6 +156,7 @@ async function resolveRunPipelineSource(pipelineSource?: string): Promise<string
156
156
  return pipelineSource;
157
157
  }
158
158
 
159
+ const { default: prompts } = await loadPromptsModule();
159
160
  const response = await prompts({
160
161
  type: 'text',
161
162
  name: 'pipelineSource',
@@ -1,10 +1,10 @@
1
1
  import colors from 'colors';
2
- import prompts from 'prompts';
3
2
  import { spaceTrim } from 'spacetrim';
4
3
  import type { PipelineJson } from '../../../pipeline/PipelineJson/PipelineJson';
5
4
  import type { string_parameter_name, string_parameter_value } from '../../../types/string_name';
6
5
  import { countLines } from '../../../utils/expectation-counters/countLines';
7
6
  import type { TODO_any } from '../../../utils/organization/TODO_any';
7
+ import { loadPromptsModule } from '../../common/loadPromptsModule';
8
8
 
9
9
  /**
10
10
  * Resolves all missing input parameters while keeping the current interactive and non-interactive behavior.
@@ -24,6 +24,7 @@ export async function resolveRunInputParameters(options: {
24
24
  return process.exit(1);
25
25
  }
26
26
 
27
+ const { default: prompts } = await loadPromptsModule();
27
28
  const response = await prompts(questions as TODO_any);
28
29
  // <- TODO: [🧠][🍼] Change behavior according to the formfactor
29
30
 
@@ -1,11 +1,11 @@
1
1
  import colors from 'colors';
2
- import prompts from 'prompts';
3
2
  import { spaceTrim } from 'spacetrim';
4
3
  import { forTime } from 'waitasecond';
5
4
  import { assertsError } from '../../errors/assertsError';
6
5
  import type { PipelineExecutor } from '../../execution/PipelineExecutor';
7
6
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
8
7
  import { just } from '../../utils/organization/just';
8
+ import { loadPromptsModule } from '../common/loadPromptsModule';
9
9
 
10
10
  /**
11
11
  * Options for running the interactive chatbot
@@ -90,6 +90,7 @@ export async function runInteractiveChatbot(options: RunInteractiveChatbotOption
90
90
  console.info(colors.gray(`---`));
91
91
  }
92
92
 
93
+ const { default: prompts } = await loadPromptsModule();
93
94
  const response = await prompts({
94
95
  type: 'text',
95
96
  name: 'userMessage',
@@ -1,5 +1,4 @@
1
1
  import colors from 'colors';
2
- import prompts from 'prompts';
3
2
  import { spaceTrim } from 'spacetrim';
4
3
  import { CLI_APP_ID } from '../../config';
5
4
  import { UnexpectedError } from '../../errors/UnexpectedError';
@@ -14,6 +13,7 @@ import type { really_unknown } from '../../utils/organization/really_unknown';
14
13
  import { TODO_USE } from '../../utils/organization/TODO_USE';
15
14
  import { isValidEmail } from '../../utils/validators/email/isValidEmail';
16
15
  import { isValidUrl } from '../../utils/validators/url/isValidUrl';
16
+ import { loadPromptsModule } from './loadPromptsModule';
17
17
 
18
18
  /**
19
19
  * Options for provide Llm tools for Cli.
@@ -110,6 +110,7 @@ export async function $provideLlmToolsForCli(options: ProvideLlmToolsForCliOptio
110
110
  ),
111
111
  );
112
112
 
113
+ const { default: prompts } = await loadPromptsModule();
113
114
  const { username, password } = await prompts([
114
115
  {
115
116
  type: 'text',
@@ -0,0 +1,13 @@
1
+ import { createLazyModuleLoader } from '../../utils/misc/createLazyModuleLoader';
2
+
3
+ /**
4
+ * Loads the interactive terminal prompt library (`prompts`) on demand
5
+ *
6
+ * Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast - most commands never ask the user
7
+ * anything interactively
8
+ *
9
+ * @private internal utility of Promptbook CLI
10
+ */
11
+ export const loadPromptsModule = createLazyModuleLoader(() => import('prompts'));
12
+
13
+ // Note: [🟡] Code for CLI prompt loading [loadPromptsModule](src/cli/common/loadPromptsModule.ts) should never be published outside of `@promptbook/cli`
@@ -1,10 +1,10 @@
1
- import JSZip from 'jszip';
2
1
  import { UnexpectedError } from '../../errors/UnexpectedError';
3
2
  import type { FilesystemTools } from '../../execution/FilesystemTools';
4
3
  import { jsonParse } from '../../formats/json/utils/jsonParse';
5
4
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
6
5
  import type { string_filename } from '../../types/string_filename';
7
6
  import { validatePipeline } from '../validation/validatePipeline';
7
+ import { loadJsZipModule } from './loadJsZipModule';
8
8
 
9
9
  /**
10
10
  * Loads the books from the archive file with `.bookc` extension
@@ -24,6 +24,7 @@ export async function loadArchive(
24
24
  }
25
25
 
26
26
  const data = await fs.readFile(filePath);
27
+ const { default: JSZip } = await loadJsZipModule();
27
28
  const archive = await JSZip.loadAsync(data);
28
29
 
29
30
  const indexFile = archive.file('index.book.json');
@@ -0,0 +1,10 @@
1
+ import { createLazyModuleLoader } from '../../utils/misc/createLazyModuleLoader';
2
+
3
+ /**
4
+ * Loads the ZIP archive library (`jszip`) on demand
5
+ *
6
+ * Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
7
+ *
8
+ * @private internal utility of `loadArchive` and `saveArchive`
9
+ */
10
+ export const loadJsZipModule = createLazyModuleLoader(() => import('jszip'));
@@ -1,10 +1,10 @@
1
- import JSZip from 'jszip';
2
1
  import { UnexpectedError } from '../../errors/UnexpectedError';
3
2
  import type { FilesystemTools } from '../../execution/FilesystemTools';
4
3
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
5
4
  import type { string_filename } from '../../types/string_filename';
6
5
  import { stringifyPipelineJson } from '../../utils/editable/utils/stringifyPipelineJson';
7
6
  import { validatePipeline } from '../validation/validatePipeline';
7
+ import { loadJsZipModule } from './loadJsZipModule';
8
8
 
9
9
  /**
10
10
  * Saves the given books into an archive file with `.bookc` extension
@@ -29,6 +29,7 @@ export async function saveArchive(
29
29
  validatePipeline(pipelineJson);
30
30
  }
31
31
 
32
+ const { default: JSZip } = await loadJsZipModule();
32
33
  const archive = new JSZip();
33
34
 
34
35
  const collectionJsonString = stringifyPipelineJson(collectionJson);
@@ -1,5 +1,5 @@
1
1
  import type { ClientOptions } from '@anthropic-ai/sdk';
2
- import Anthropic from '@anthropic-ai/sdk';
2
+ import type Anthropic from '@anthropic-ai/sdk';
3
3
  import type { MessageCreateParamsNonStreaming } from '@anthropic-ai/sdk/resources';
4
4
  import Bottleneck from 'bottleneck';
5
5
  import colors from 'colors'; // <- TODO: [🔶] Make system to put color and style to both node and browser
@@ -19,6 +19,7 @@ import type { string_name } from '../../types/string_name';
19
19
  import type { string_title } from '../../types/string_title';
20
20
  import type { string_date_iso8601 } from '../../types/string_token';
21
21
  import { $getCurrentDate } from '../../utils/misc/$getCurrentDate';
22
+ import { createLazyModuleLoader } from '../../utils/misc/createLazyModuleLoader';
22
23
  import type { chococake } from '../../utils/organization/really_any';
23
24
  import type { TODO_any } from '../../utils/organization/TODO_any';
24
25
  import { templateParameters } from '../../utils/parameters/templateParameters';
@@ -36,6 +37,15 @@ const ANTHROPIC_PROVIDER_PROFILE: ChatParticipant = {
36
37
  color: '#d97706',
37
38
  } as const;
38
39
 
40
+ /**
41
+ * Loads the Anthropic Claude SDK (`@anthropic-ai/sdk`) on demand
42
+ *
43
+ * Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
44
+ *
45
+ * @private internal utility of `AnthropicClaudeExecutionTools`
46
+ */
47
+ const loadAnthropicClaudeModule = createLazyModuleLoader(() => import('@anthropic-ai/sdk'));
48
+
39
49
  /**
40
50
  * Execution Tools for calling Anthropic Claude API.
41
51
  *
@@ -80,6 +90,8 @@ export class AnthropicClaudeExecutionTools implements LlmExecutionTools /* <- TO
80
90
  const anthropicOptions: ClientOptions = { ...this.options };
81
91
  delete (anthropicOptions as chococake).isVerbose;
82
92
  delete (anthropicOptions as chococake).isProxied;
93
+
94
+ const { Anthropic } = await loadAnthropicClaudeModule();
83
95
  this.client = new Anthropic(anthropicOptions);
84
96
  }
85
97
 
@@ -1,4 +1,4 @@
1
- import { AzureKeyCredential, OpenAIClient } from '@azure/openai';
1
+ import type { OpenAIClient } from '@azure/openai';
2
2
  import Bottleneck from 'bottleneck';
3
3
  import colors from 'colors'; // <- TODO: [🔶] Make system to put color and style to both node and browser
4
4
  import type { ChatParticipant } from '../../book-components/Chat/types/ChatParticipant';
@@ -18,6 +18,7 @@ import type { string_completion_prompt } from '../../types/string_prompt';
18
18
  import type { string_title } from '../../types/string_title';
19
19
  import type { string_date_iso8601 } from '../../types/string_token';
20
20
  import { $getCurrentDate } from '../../utils/misc/$getCurrentDate';
21
+ import { createLazyModuleLoader } from '../../utils/misc/createLazyModuleLoader';
21
22
  import { keepTypeImported } from '../../utils/organization/keepTypeImported';
22
23
  import { templateParameters } from '../../utils/parameters/templateParameters';
23
24
  import { exportJson } from '../../utils/serialization/exportJson';
@@ -35,6 +36,15 @@ const AZURE_OPENAI_PROVIDER_PROFILE: ChatParticipant = {
35
36
 
36
37
  keepTypeImported<Usage>();
37
38
 
39
+ /**
40
+ * Loads the Azure OpenAI SDK (`@azure/openai`) on demand
41
+ *
42
+ * Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
43
+ *
44
+ * @private internal utility of `AzureOpenAiExecutionTools`
45
+ */
46
+ const loadAzureOpenAiModule = createLazyModuleLoader(() => import('@azure/openai'));
47
+
38
48
  /**
39
49
  * Execution Tools for calling Azure OpenAI API.
40
50
  *
@@ -77,6 +87,8 @@ export class AzureOpenAiExecutionTools implements LlmExecutionTools /* <- TODO:
77
87
 
78
88
  public async getClient(): Promise<OpenAIClient> {
79
89
  if (this.client === null) {
90
+ const { AzureKeyCredential, OpenAIClient } = await loadAzureOpenAiModule();
91
+
80
92
  this.client = new OpenAIClient(
81
93
  `https://${this.options.resourceName}.openai.azure.com/`,
82
94
  new AzureKeyCredential(this.options.apiKey),
@@ -1,4 +1,4 @@
1
- import { Agent as AgentFromKit, run, setDefaultOpenAIClient, setDefaultOpenAIKey } from '@openai/agents';
1
+ import type { Agent as AgentFromKit } from '@openai/agents';
2
2
  import { NotYetImplementedError } from '../../errors/NotYetImplementedError';
3
3
  import { PipelineExecutionError } from '../../errors/PipelineExecutionError';
4
4
  import type { CallChatModelStreamOptions, LlmExecutionTools } from '../../execution/LlmExecutionTools';
@@ -23,6 +23,7 @@ import { OpenAiAgentKitExecutionToolsOutputTypeMapper } from './OpenAiAgentKitEx
23
23
  import { OpenAiAgentKitExecutionToolsToolBuilder } from './OpenAiAgentKitExecutionToolsToolBuilder';
24
24
  import type { OpenAiCompatibleExecutionToolsNonProxiedOptions } from './OpenAiCompatibleExecutionToolsOptions';
25
25
  import { OpenAiVectorStoreHandler } from './OpenAiVectorStoreHandler';
26
+ import { loadOpenAiAgentsModule } from './utils/loadOpenAiAgentsModule';
26
27
 
27
28
  /**
28
29
  * Constant for default agent kit model name.
@@ -211,7 +212,8 @@ export class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler imple
211
212
  });
212
213
  }
213
214
 
214
- const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
215
+ const { Agent: AgentFromKit } = await loadOpenAiAgentsModule();
216
+ const agentKitTools = await this.buildAgentKitTools({ tools, vectorStoreId });
215
217
  const openAiAgentKitAgent = new AgentFromKit({
216
218
  name,
217
219
  model: this.agentKitModelName,
@@ -275,6 +277,7 @@ export class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler imple
275
277
  agentName: agentForRun.name,
276
278
  input: inputItems,
277
279
  };
280
+ const { run } = await loadOpenAiAgentsModule();
278
281
  const streamResult = await run(agentForRun, inputItems, {
279
282
  stream: true,
280
283
  maxTurns: 200,
@@ -433,6 +436,7 @@ export class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler imple
433
436
  * Ensures the AgentKit SDK is wired to the OpenAI client and API key.
434
437
  */
435
438
  private async ensureAgentKitDefaults(): Promise<void> {
439
+ const { setDefaultOpenAIClient, setDefaultOpenAIKey } = await loadOpenAiAgentsModule();
436
440
  const client = await this.getClient();
437
441
  setDefaultOpenAIClient(client as TODO_any);
438
442
 
@@ -1,5 +1,4 @@
1
1
  import type { Tool as AgentKitTool } from '@openai/agents';
2
- import { Agent as AgentFromKit, fileSearchTool, tool as agentKitTool, webSearchTool } from '@openai/agents';
3
2
  import { spaceTrim } from 'spacetrim';
4
3
  import { parseToolExecutionEnvelope } from '../../commitments/_common/toolExecutionEnvelope';
5
4
  import type { ToolCallProgressUpdate } from '../../commitments/_common/toolRuntimeContext';
@@ -26,6 +25,7 @@ import type { TODO_any } from '../../utils/organization/TODO_any';
26
25
  import type { OpenAiAgentKitExecutionToolsOptions } from './OpenAiAgentKitExecutionToolsOptions';
27
26
  import type { OpenAiCompatibleExecutionToolsNonProxiedOptions } from './OpenAiCompatibleExecutionToolsOptions';
28
27
  import { buildToolInvocationScript } from './utils/buildToolInvocationScript';
28
+ import { loadOpenAiAgentsModule } from './utils/loadOpenAiAgentsModule';
29
29
 
30
30
  /**
31
31
  * Constant for default model used for nested DeepSearch tool invocations.
@@ -98,11 +98,12 @@ export class OpenAiAgentKitExecutionToolsToolBuilder {
98
98
  /**
99
99
  * Builds the tool list for AgentKit, including hosted file search when applicable.
100
100
  */
101
- public buildAgentKitTools(options: {
101
+ public async buildAgentKitTools(options: {
102
102
  readonly tools?: ModelRequirements['tools'];
103
103
  readonly vectorStoreId?: string;
104
- }): Array<AgentKitTool> {
104
+ }): Promise<Array<AgentKitTool>> {
105
105
  const { tools, vectorStoreId } = options;
106
+ const { fileSearchTool, tool: agentKitTool } = await loadOpenAiAgentsModule();
106
107
  const agentKitTools: Array<AgentKitTool> = [];
107
108
 
108
109
  if (vectorStoreId) {
@@ -117,7 +118,7 @@ export class OpenAiAgentKitExecutionToolsToolBuilder {
117
118
 
118
119
  for (const toolDefinition of tools) {
119
120
  if (this.isDeepSearchToolDefinition(toolDefinition)) {
120
- agentKitTools.push(this.createDeepSearchAgentKitTool(toolDefinition));
121
+ agentKitTools.push(await this.createDeepSearchAgentKitTool(toolDefinition));
121
122
  continue;
122
123
  }
123
124
 
@@ -376,7 +377,8 @@ export class OpenAiAgentKitExecutionToolsToolBuilder {
376
377
  /**
377
378
  * Creates the native Agent SDK tool used for `USE DEEPSEARCH`.
378
379
  */
379
- private createDeepSearchAgentKitTool(toolDefinition: AgentKitToolDefinition): AgentKitTool {
380
+ private async createDeepSearchAgentKitTool(toolDefinition: AgentKitToolDefinition): Promise<AgentKitTool> {
381
+ const { Agent: AgentFromKit, webSearchTool } = await loadOpenAiAgentsModule();
380
382
  const deepSearchAgent = new AgentFromKit({
381
383
  name: 'DeepSearch',
382
384
  model: DEFAULT_DEEP_SEARCH_MODEL_NAME,
@@ -1,4 +1,4 @@
1
- import OpenAI from 'openai';
1
+ import type OpenAI from 'openai';
2
2
  import { NotAllowed } from '../../errors/NotAllowed';
3
3
  import { NotYetImplementedError } from '../../errors/NotYetImplementedError';
4
4
  import { PipelineExecutionError } from '../../errors/PipelineExecutionError';
@@ -1,5 +1,5 @@
1
1
  import colors from 'colors'; // <- TODO: [🔶] Make system to put color and style to both node and browser
2
- import OpenAI from 'openai';
2
+ import type OpenAI from 'openai';
3
3
  import { PipelineExecutionError } from '../../errors/PipelineExecutionError';
4
4
  import type { ChatPromptResult } from '../../execution/PromptResult';
5
5
  import type { Prompt } from '../../types/Prompt';
@@ -1,5 +1,5 @@
1
1
  import colors from 'colors'; // <- TODO: [🔶] Make system to put color and style to both node and browser
2
- import OpenAI from 'openai';
2
+ import type OpenAI from 'openai';
3
3
  import { spaceTrim } from 'spacetrim';
4
4
  import { parseToolExecutionEnvelope } from '../../commitments/_common/toolExecutionEnvelope';
5
5
  import type { ToolCallProgressUpdate } from '../../commitments/_common/toolRuntimeContext';
@@ -1,5 +1,5 @@
1
1
  import colors from 'colors';
2
- import OpenAI from 'openai';
2
+ import type OpenAI from 'openai';
3
3
  import { assertsError } from '../../errors/assertsError';
4
4
  import { PipelineExecutionError } from '../../errors/PipelineExecutionError';
5
5
  import type { AvailableModel } from '../../execution/AvailableModel';
@@ -1,11 +1,21 @@
1
1
  import Bottleneck from 'bottleneck';
2
2
  import colors from 'colors';
3
3
  import type { ClientOptions } from 'openai';
4
- import OpenAI from 'openai';
4
+ import type OpenAI from 'openai';
5
5
  import { API_REQUEST_TIMEOUT, CONNECTION_RETRIES_LIMIT, DEFAULT_MAX_REQUESTS_PER_MINUTE } from '../../config';
6
6
  import { assertsError } from '../../errors/assertsError';
7
+ import { createLazyModuleLoader } from '../../utils/misc/createLazyModuleLoader';
7
8
  import type { OpenAiCompatibleExecutionToolsNonProxiedOptions } from './OpenAiCompatibleExecutionToolsOptions';
8
9
 
10
+ /**
11
+ * Loads the OpenAI SDK (`openai`) on demand
12
+ *
13
+ * Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
14
+ *
15
+ * @private internal utility of `OpenAiCompatibleRequestManager`
16
+ */
17
+ const loadOpenAiModule = createLazyModuleLoader(() => import('openai'));
18
+
9
19
  /**
10
20
  * Manages OpenAI-compatible client creation plus shared retry and rate-limit behavior.
11
21
  *
@@ -36,6 +46,7 @@ export class OpenAiCompatibleRequestManager {
36
46
  maxRetries: CONNECTION_RETRIES_LIMIT,
37
47
  } as ClientOptions;
38
48
 
49
+ const { default: OpenAI } = await loadOpenAiModule();
39
50
  this.client = new OpenAI(enhancedOptions);
40
51
  }
41
52
 
@@ -1,5 +1,5 @@
1
1
  import colors from 'colors';
2
- import OpenAI from 'openai';
2
+ import type OpenAI from 'openai';
3
3
  import { assertsError } from '../../../errors/assertsError';
4
4
  import { PipelineExecutionError } from '../../../errors/PipelineExecutionError';
5
5
  import type { AvailableModel } from '../../../execution/AvailableModel';
@@ -0,0 +1,11 @@
1
+ import { createLazyModuleLoader } from '../../../utils/misc/createLazyModuleLoader';
2
+
3
+ /**
4
+ * Loads the OpenAI AgentKit SDK (`@openai/agents`) on demand
5
+ *
6
+ * Note: [🐌] The AgentKit SDK is one of the heaviest dependencies of Promptbook, loading it eagerly would slow down
7
+ * every single run of the `ptbk` CLI utility even when no AgentKit agent is used
8
+ *
9
+ * @private internal utility of `@promptbook/openai`
10
+ */
11
+ export const loadOpenAiAgentsModule = createLazyModuleLoader(() => import('@openai/agents'));
@@ -1,4 +1,4 @@
1
- import OpenAI from 'openai';
1
+ import type OpenAI from 'openai';
2
2
 
3
3
  /**
4
4
  * Uploads files to OpenAI and returns their IDs