@promptbook/components 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 (45) hide show
  1. package/esm/index.es.js +133 -43
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
  4. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
  5. package/esm/src/cli/cli-commands/coder/ping.d.ts +2 -5
  6. package/esm/src/cli/cli-commands/coder.d.ts +1 -1
  7. package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
  8. package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
  9. package/esm/src/cli/common/loadPromptsModule.d.ts +16 -0
  10. package/esm/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  11. package/esm/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  12. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
  13. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
  14. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
  15. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
  16. package/esm/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
  17. package/esm/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
  18. package/esm/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
  19. package/esm/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
  20. package/esm/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
  21. package/esm/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
  22. package/esm/src/version.d.ts +1 -1
  23. package/package.json +4 -1
  24. package/umd/index.umd.js +143 -52
  25. package/umd/index.umd.js.map +1 -1
  26. package/umd/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
  27. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
  28. package/umd/src/cli/cli-commands/coder/ping.d.ts +2 -5
  29. package/umd/src/cli/cli-commands/coder.d.ts +1 -1
  30. package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
  31. package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
  32. package/umd/src/cli/common/loadPromptsModule.d.ts +16 -0
  33. package/umd/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  34. package/umd/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  35. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
  36. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
  37. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
  38. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
  39. package/umd/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
  40. package/umd/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
  41. package/umd/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
  42. package/umd/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
  43. package/umd/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
  44. package/umd/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
  45. package/umd/src/version.d.ts +1 -1
package/esm/index.es.js CHANGED
@@ -21,10 +21,8 @@ import 'moment/locale/cs';
21
21
  import { forTime } from 'waitasecond';
22
22
  import sha256 from 'crypto-js/sha256';
23
23
  import papaparse from 'papaparse';
24
- import { fileSearchTool, tool, Agent as Agent$1, webSearchTool, run, setDefaultOpenAIClient, setDefaultOpenAIKey } from '@openai/agents';
25
24
  import colors from 'colors';
26
25
  import Bottleneck from 'bottleneck';
27
- import OpenAI from 'openai';
28
26
  import QRCode from 'qrcode';
29
27
 
30
28
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -41,7 +39,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
41
39
  * @generated
42
40
  * @see https://github.com/webgptorg/promptbook
43
41
  */
44
- const PROMPTBOOK_ENGINE_VERSION = '0.114.0-2';
42
+ const PROMPTBOOK_ENGINE_VERSION = '0.114.0-3';
45
43
  /**
46
44
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
47
45
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -27753,6 +27751,81 @@ function parseMessageButtons(content) {
27753
27751
  };
27754
27752
  }
27755
27753
 
27754
+ /**
27755
+ * This error type indicates that you try to use a feature that is not available in the current environment
27756
+ *
27757
+ * @public exported from `@promptbook/core`
27758
+ */
27759
+ class EnvironmentMismatchError extends Error {
27760
+ constructor(message) {
27761
+ super(message);
27762
+ this.name = 'EnvironmentMismatchError';
27763
+ Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
27764
+ }
27765
+ }
27766
+
27767
+ /**
27768
+ * Shared DOM window reused by every render which happens outside of a browser
27769
+ *
27770
+ * @private utility of `$provideServerDomWindow`
27771
+ */
27772
+ let serverDomWindow = null;
27773
+ /**
27774
+ * Provides a DOM `window` for runtimes which do not have one, for example Node.js during server-side rendering
27775
+ *
27776
+ * Note: `$` is used to indicate that this function is not a pure function - it creates and caches one shared DOM window
27777
+ *
27778
+ * @returns DOM window which can back a DOM-dependent library like `DOMPurify`
27779
+ * @throws {EnvironmentMismatchError} When the current runtime can not create a DOM window
27780
+ * @private utility of `renderMarkdown`
27781
+ */
27782
+ function $provideServerDomWindow() {
27783
+ if (serverDomWindow === null) {
27784
+ const { JSDOM } = requireServerDomLibrary();
27785
+ serverDomWindow = new JSDOM('').window;
27786
+ }
27787
+ return serverDomWindow;
27788
+ }
27789
+ /**
27790
+ * Loads `jsdom` which backs the DOM window outside of a browser
27791
+ *
27792
+ * Note: [😷] `jsdom` reaches for Node.js built-ins like `fs`, `child_process` and `net`, so browser bundlers must
27793
+ * never follow the `require` below - even though it is unreachable in a browser, bundlers resolve it statically.
27794
+ * They are told to replace `jsdom` with an empty module by the `browser` field of the generated package
27795
+ * manifests, which is written by `applyBrowserUnsupportedDependencyStubs` during the package generation.
27796
+ *
27797
+ * @returns The `jsdom` library
27798
+ * @throws {EnvironmentMismatchError} When `jsdom` can not be loaded in the current runtime
27799
+ * @private utility of `$provideServerDomWindow`
27800
+ */
27801
+ function requireServerDomLibrary() {
27802
+ let serverDomLibrary = null;
27803
+ let serverDomLibraryError = null;
27804
+ try {
27805
+ // Note: [😷] Keep `'jsdom'` written as a literal, bundlers do not replace a computed module name
27806
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
27807
+ serverDomLibrary = require('jsdom');
27808
+ }
27809
+ catch (error) {
27810
+ assertsError(error);
27811
+ serverDomLibraryError = error;
27812
+ }
27813
+ if (typeof (serverDomLibrary === null || serverDomLibrary === void 0 ? void 0 : serverDomLibrary.JSDOM) !== 'function') {
27814
+ throw new EnvironmentMismatchError(spaceTrim$1((block) => `
27815
+ Markdown can not be rendered because there is no DOM in the current runtime.
27816
+
27817
+ Rendered markdown is sanitized through \`DOMPurify\`, which needs a DOM - the DOM of the browser
27818
+ when the code runs in a browser and \`jsdom\` in every other runtime, for example during
27819
+ server-side rendering in **Node.js**.
27820
+
27821
+ ${block(serverDomLibraryError === null
27822
+ ? '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.'
27823
+ : `${serverDomLibraryError.name}: ${serverDomLibraryError.message}`)}
27824
+ `));
27825
+ }
27826
+ return serverDomLibrary;
27827
+ }
27828
+
27756
27829
  /**
27757
27830
  * Default citation identifier used for simplified citation markers without an explicit position.
27758
27831
  *
@@ -28049,12 +28122,6 @@ let browserMarkdownSanitizer = null;
28049
28122
  * @private utility of `renderMarkdown`
28050
28123
  */
28051
28124
  let serverMarkdownSanitizer = null;
28052
- /**
28053
- * Shared JSDOM window backing the server-side DOMPurify instance.
28054
- *
28055
- * @private utility of `renderMarkdown`
28056
- */
28057
- let serverMarkdownSanitizerWindow = null;
28058
28125
  /**
28059
28126
  * Pattern matching CODE FENCE.
28060
28127
  */
@@ -28190,19 +28257,6 @@ function createMarkdownSanitizer(sanitizerWindow) {
28190
28257
  registerMarkdownSanitizerHooks(markdownSanitizer);
28191
28258
  return markdownSanitizer;
28192
28259
  }
28193
- /**
28194
- * Lazily creates the JSDOM window used by server-side markdown sanitization.
28195
- *
28196
- * @private utility of `renderMarkdown`
28197
- */
28198
- function getServerMarkdownSanitizerWindow() {
28199
- if (!serverMarkdownSanitizerWindow) {
28200
- // eslint-disable-next-line @typescript-eslint/no-var-requires
28201
- const { JSDOM } = require('jsdom');
28202
- serverMarkdownSanitizerWindow = new JSDOM('').window;
28203
- }
28204
- return serverMarkdownSanitizerWindow;
28205
- }
28206
28260
  /**
28207
28261
  * Returns the shared DOMPurify instance appropriate for the current runtime.
28208
28262
  *
@@ -28213,7 +28267,7 @@ function getMarkdownSanitizer() {
28213
28267
  browserMarkdownSanitizer !== null && browserMarkdownSanitizer !== void 0 ? browserMarkdownSanitizer : (browserMarkdownSanitizer = createMarkdownSanitizer(window));
28214
28268
  return browserMarkdownSanitizer;
28215
28269
  }
28216
- serverMarkdownSanitizer !== null && serverMarkdownSanitizer !== void 0 ? serverMarkdownSanitizer : (serverMarkdownSanitizer = createMarkdownSanitizer(getServerMarkdownSanitizerWindow()));
28270
+ serverMarkdownSanitizer !== null && serverMarkdownSanitizer !== void 0 ? serverMarkdownSanitizer : (serverMarkdownSanitizer = createMarkdownSanitizer($provideServerDomWindow()));
28217
28271
  return serverMarkdownSanitizer;
28218
28272
  }
28219
28273
  /**
@@ -47808,19 +47862,6 @@ class DatabaseError extends Error {
47808
47862
  }
47809
47863
  // TODO: [🐱‍🚀] Explain that NotFoundError ([🐱‍🚀] and other specific errors) has priority over DatabaseError in some contexts
47810
47864
 
47811
- /**
47812
- * This error type indicates that you try to use a feature that is not available in the current environment
47813
- *
47814
- * @public exported from `@promptbook/core`
47815
- */
47816
- class EnvironmentMismatchError extends Error {
47817
- constructor(message) {
47818
- super(message);
47819
- this.name = 'EnvironmentMismatchError';
47820
- Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
47821
- }
47822
- }
47823
-
47824
47865
  /**
47825
47866
  * This error occurs when some expectation is not met in the execution of the pipeline
47826
47867
  *
@@ -53260,6 +53301,41 @@ function buildToolInvocationScript(options) {
53260
53301
  `;
53261
53302
  }
53262
53303
 
53304
+ /**
53305
+ * Creates a loader which imports one module on the first call and reuses the very same module afterwards
53306
+ *
53307
+ * Note: [🐌] Heavy third-party dependencies are imported lazily to keep the startup of the Promptbook CLI fast.
53308
+ * A statically imported dependency is loaded every single time the bundle is loaded, even when the running
53309
+ * command never touches it. A lazily imported dependency is loaded only when the feature is really used.
53310
+ *
53311
+ * @example
53312
+ * const loadJsdomModule = createLazyModuleLoader(() => import('jsdom'));
53313
+ * const { JSDOM } = await loadJsdomModule();
53314
+ *
53315
+ * @private internal utility of Promptbook
53316
+ */
53317
+ function createLazyModuleLoader(importModule) {
53318
+ let importedModulePromise = null;
53319
+ return function loadModule() {
53320
+ if (importedModulePromise === null) {
53321
+ importedModulePromise = importModule();
53322
+ }
53323
+ return importedModulePromise;
53324
+ };
53325
+ }
53326
+ // Note: [🐌] Do not convert the lazy `import(...)` calls back to static `import` statements, it would bring back the
53327
+ // slow startup of the `ptbk` CLI utility
53328
+
53329
+ /**
53330
+ * Loads the OpenAI AgentKit SDK (`@openai/agents`) on demand
53331
+ *
53332
+ * Note: [🐌] The AgentKit SDK is one of the heaviest dependencies of Promptbook, loading it eagerly would slow down
53333
+ * every single run of the `ptbk` CLI utility even when no AgentKit agent is used
53334
+ *
53335
+ * @private internal utility of `@promptbook/openai`
53336
+ */
53337
+ const loadOpenAiAgentsModule = createLazyModuleLoader(() => import('@openai/agents'));
53338
+
53263
53339
  /**
53264
53340
  * Constant for default model used for nested DeepSearch tool invocations.
53265
53341
  */
@@ -53313,8 +53389,9 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
53313
53389
  /**
53314
53390
  * Builds the tool list for AgentKit, including hosted file search when applicable.
53315
53391
  */
53316
- buildAgentKitTools(options) {
53392
+ async buildAgentKitTools(options) {
53317
53393
  const { tools, vectorStoreId } = options;
53394
+ const { fileSearchTool, tool: agentKitTool } = await loadOpenAiAgentsModule();
53318
53395
  const agentKitTools = [];
53319
53396
  if (vectorStoreId) {
53320
53397
  agentKitTools.push(fileSearchTool(vectorStoreId));
@@ -53325,11 +53402,11 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
53325
53402
  let scriptTools = null;
53326
53403
  for (const toolDefinition of tools) {
53327
53404
  if (this.isDeepSearchToolDefinition(toolDefinition)) {
53328
- agentKitTools.push(this.createDeepSearchAgentKitTool(toolDefinition));
53405
+ agentKitTools.push(await this.createDeepSearchAgentKitTool(toolDefinition));
53329
53406
  continue;
53330
53407
  }
53331
53408
  scriptTools !== null && scriptTools !== void 0 ? scriptTools : (scriptTools = this.resolveScriptTools());
53332
- agentKitTools.push(tool({
53409
+ agentKitTools.push(agentKitTool({
53333
53410
  name: toolDefinition.name,
53334
53411
  description: toolDefinition.description,
53335
53412
  parameters: this.normalizeAgentKitToolParameters(toolDefinition.parameters),
@@ -53536,8 +53613,9 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
53536
53613
  /**
53537
53614
  * Creates the native Agent SDK tool used for `USE DEEPSEARCH`.
53538
53615
  */
53539
- createDeepSearchAgentKitTool(toolDefinition) {
53540
- const deepSearchAgent = new Agent$1({
53616
+ async createDeepSearchAgentKitTool(toolDefinition) {
53617
+ const { Agent: AgentFromKit, webSearchTool } = await loadOpenAiAgentsModule();
53618
+ const deepSearchAgent = new AgentFromKit({
53541
53619
  name: 'DeepSearch',
53542
53620
  model: DEFAULT_DEEP_SEARCH_MODEL_NAME,
53543
53621
  instructions: this.createDeepSearchAgentInstructions(toolDefinition.description),
@@ -54863,6 +54941,14 @@ class OpenAiCompatibleNonChatPromptCaller {
54863
54941
  }
54864
54942
  }
54865
54943
 
54944
+ /**
54945
+ * Loads the OpenAI SDK (`openai`) on demand
54946
+ *
54947
+ * Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
54948
+ *
54949
+ * @private internal utility of `OpenAiCompatibleRequestManager`
54950
+ */
54951
+ const loadOpenAiModule = createLazyModuleLoader(() => import('openai'));
54866
54952
  /**
54867
54953
  * Manages OpenAI-compatible client creation plus shared retry and rate-limit behavior.
54868
54954
  *
@@ -54889,6 +54975,7 @@ class OpenAiCompatibleRequestManager {
54889
54975
  timeout: API_REQUEST_TIMEOUT,
54890
54976
  maxRetries: CONNECTION_RETRIES_LIMIT,
54891
54977
  };
54978
+ const { default: OpenAI } = await loadOpenAiModule();
54892
54979
  this.client = new OpenAI(enhancedOptions);
54893
54980
  }
54894
54981
  return this.client;
@@ -57036,8 +57123,9 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
57036
57123
  vectorStoreId,
57037
57124
  });
57038
57125
  }
57039
- const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
57040
- const openAiAgentKitAgent = new Agent$1({
57126
+ const { Agent: AgentFromKit } = await loadOpenAiAgentsModule();
57127
+ const agentKitTools = await this.buildAgentKitTools({ tools, vectorStoreId });
57128
+ const openAiAgentKitAgent = new AgentFromKit({
57041
57129
  name,
57042
57130
  model: this.agentKitModelName,
57043
57131
  instructions: instructions || 'You are a helpful assistant.',
@@ -57082,6 +57170,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
57082
57170
  agentName: agentForRun.name,
57083
57171
  input: inputItems,
57084
57172
  };
57173
+ const { run } = await loadOpenAiAgentsModule();
57085
57174
  const streamResult = await run(agentForRun, inputItems, {
57086
57175
  stream: true,
57087
57176
  maxTurns: 200,
@@ -57224,6 +57313,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
57224
57313
  * Ensures the AgentKit SDK is wired to the OpenAI client and API key.
57225
57314
  */
57226
57315
  async ensureAgentKitDefaults() {
57316
+ const { setDefaultOpenAIClient, setDefaultOpenAIKey } = await loadOpenAiAgentsModule();
57227
57317
  const client = await this.getClient();
57228
57318
  setDefaultOpenAIClient(client);
57229
57319
  const apiKey = this.agentKitOptions.apiKey;