@promptbook/components 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 (58) hide show
  1. package/README.md +16 -15
  2. package/esm/index.es.js +230 -49
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/src/book-2.0/book-language-documentation/BookLanguageManualDictionary.d.ts +1 -15
  5. package/esm/src/book-2.0/book-language-documentation/getBookLanguageManualCommitmentGroups.d.ts +1 -1
  6. package/esm/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.d.ts +0 -4
  7. package/esm/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
  8. package/esm/src/book-components/Chat/utils/renderMarkdown.d.ts +7 -0
  9. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
  10. package/esm/src/cli/cli-commands/coder/agentCodingFile.d.ts +2 -3
  11. package/esm/src/cli/cli-commands/coder/ping.d.ts +10 -0
  12. package/esm/src/cli/cli-commands/coder/ping.test.d.ts +1 -0
  13. package/esm/src/cli/cli-commands/coder.d.ts +1 -0
  14. package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
  15. package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
  16. package/esm/src/cli/common/loadPromptsModule.d.ts +16 -0
  17. package/esm/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  18. package/esm/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  19. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
  20. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
  21. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
  22. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
  23. package/esm/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
  24. package/esm/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
  25. package/esm/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
  26. package/esm/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
  27. package/esm/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
  28. package/esm/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
  29. package/esm/src/version.d.ts +1 -1
  30. package/package.json +4 -1
  31. package/umd/index.umd.js +240 -58
  32. package/umd/index.umd.js.map +1 -1
  33. package/umd/src/book-2.0/book-language-documentation/BookLanguageManualDictionary.d.ts +1 -15
  34. package/umd/src/book-2.0/book-language-documentation/getBookLanguageManualCommitmentGroups.d.ts +1 -1
  35. package/umd/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.d.ts +0 -4
  36. package/umd/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
  37. package/umd/src/book-components/Chat/utils/renderMarkdown.d.ts +7 -0
  38. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
  39. package/umd/src/cli/cli-commands/coder/agentCodingFile.d.ts +2 -3
  40. package/umd/src/cli/cli-commands/coder/ping.d.ts +10 -0
  41. package/umd/src/cli/cli-commands/coder/ping.test.d.ts +1 -0
  42. package/umd/src/cli/cli-commands/coder.d.ts +1 -0
  43. package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
  44. package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
  45. package/umd/src/cli/common/loadPromptsModule.d.ts +16 -0
  46. package/umd/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  47. package/umd/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  48. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
  49. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
  50. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
  51. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
  52. package/umd/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
  53. package/umd/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
  54. package/umd/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
  55. package/umd/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
  56. package/umd/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
  57. package/umd/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
  58. package/umd/src/version.d.ts +1 -1
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('spacetrim'), require('react'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('crypto'), require('moment'), require('mime-types'), require('react-dom'), require('@monaco-editor/react'), require('rxjs'), require('dompurify'), require('katex'), require('showdown'), require('html-to-image'), require('jspdf'), require('react-dom/client'), require('lucide-react'), require('moment/locale/cs'), require('waitasecond'), require('crypto-js/sha256'), require('papaparse'), require('@openai/agents'), require('colors'), require('bottleneck'), require('openai'), require('qrcode')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'spacetrim', 'react', 'crypto-js', 'crypto-js/enc-hex', 'path', 'crypto', 'moment', 'mime-types', 'react-dom', '@monaco-editor/react', 'rxjs', 'dompurify', 'katex', 'showdown', 'html-to-image', 'jspdf', 'react-dom/client', 'lucide-react', 'moment/locale/cs', 'waitasecond', 'crypto-js/sha256', 'papaparse', '@openai/agents', 'colors', 'bottleneck', 'openai', 'qrcode'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-components"] = {}, global.jsxRuntime, global.spacetrim, global.react, global.CryptoJS, global.hexEncoder, global.path, null, global.moment, global.mimeTypes, global.reactDom, global.MonacoEditor, global.rxjs, global.createDOMPurify, global.katex, global.showdown, global.htmlToImage, global.jspdf, global.client, global.lucideReact, null, global.waitasecond, global.sha256, global.papaparse, global.agents, global.colors, global.Bottleneck, global.OpenAI, global.QRCode));
5
- })(this, (function (exports, jsxRuntime, spacetrim, react, CryptoJS, hexEncoder, path, crypto$1, moment, mimeTypes, reactDom, MonacoEditor, rxjs, createDOMPurify, katex, showdown, htmlToImage, jspdf, client, lucideReact, cs, waitasecond, sha256, papaparse, agents, colors, Bottleneck, OpenAI, QRCode) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('spacetrim'), require('react'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('crypto'), require('moment'), require('mime-types'), require('react-dom'), require('@monaco-editor/react'), require('rxjs'), require('dompurify'), require('katex'), require('showdown'), require('html-to-image'), require('jspdf'), require('react-dom/client'), require('lucide-react'), require('moment/locale/cs'), require('waitasecond'), require('crypto-js/sha256'), require('papaparse'), require('colors'), require('bottleneck'), require('qrcode')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'spacetrim', 'react', 'crypto-js', 'crypto-js/enc-hex', 'path', 'crypto', 'moment', 'mime-types', 'react-dom', '@monaco-editor/react', 'rxjs', 'dompurify', 'katex', 'showdown', 'html-to-image', 'jspdf', 'react-dom/client', 'lucide-react', 'moment/locale/cs', 'waitasecond', 'crypto-js/sha256', 'papaparse', 'colors', 'bottleneck', 'qrcode'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-components"] = {}, global.jsxRuntime, global.spacetrim, global.react, global.CryptoJS, global.hexEncoder, global.path, null, global.moment, global.mimeTypes, global.reactDom, global.MonacoEditor, global.rxjs, global.createDOMPurify, global.katex, global.showdown, global.htmlToImage, global.jspdf, global.client, global.lucideReact, null, global.waitasecond, global.sha256, global.papaparse, global.colors, global.Bottleneck, global.QRCode));
5
+ })(this, (function (exports, jsxRuntime, spacetrim, react, CryptoJS, hexEncoder, path, crypto$1, moment, mimeTypes, reactDom, MonacoEditor, rxjs, createDOMPurify, katex, showdown, htmlToImage, jspdf, client, lucideReact, cs, waitasecond, sha256, papaparse, colors, Bottleneck, QRCode) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -17,7 +17,6 @@
17
17
  var papaparse__default = /*#__PURE__*/_interopDefaultLegacy(papaparse);
18
18
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
19
19
  var Bottleneck__default = /*#__PURE__*/_interopDefaultLegacy(Bottleneck);
20
- var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
21
20
  var QRCode__default = /*#__PURE__*/_interopDefaultLegacy(QRCode);
22
21
 
23
22
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -34,7 +33,7 @@
34
33
  * @generated
35
34
  * @see https://github.com/webgptorg/promptbook
36
35
  */
37
- const PROMPTBOOK_ENGINE_VERSION = '0.114.0-1';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.114.0-3';
38
37
  /**
39
38
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
40
39
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -27746,6 +27745,81 @@
27746
27745
  };
27747
27746
  }
27748
27747
 
27748
+ /**
27749
+ * This error type indicates that you try to use a feature that is not available in the current environment
27750
+ *
27751
+ * @public exported from `@promptbook/core`
27752
+ */
27753
+ class EnvironmentMismatchError extends Error {
27754
+ constructor(message) {
27755
+ super(message);
27756
+ this.name = 'EnvironmentMismatchError';
27757
+ Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
27758
+ }
27759
+ }
27760
+
27761
+ /**
27762
+ * Shared DOM window reused by every render which happens outside of a browser
27763
+ *
27764
+ * @private utility of `$provideServerDomWindow`
27765
+ */
27766
+ let serverDomWindow = null;
27767
+ /**
27768
+ * Provides a DOM `window` for runtimes which do not have one, for example Node.js during server-side rendering
27769
+ *
27770
+ * Note: `$` is used to indicate that this function is not a pure function - it creates and caches one shared DOM window
27771
+ *
27772
+ * @returns DOM window which can back a DOM-dependent library like `DOMPurify`
27773
+ * @throws {EnvironmentMismatchError} When the current runtime can not create a DOM window
27774
+ * @private utility of `renderMarkdown`
27775
+ */
27776
+ function $provideServerDomWindow() {
27777
+ if (serverDomWindow === null) {
27778
+ const { JSDOM } = requireServerDomLibrary();
27779
+ serverDomWindow = new JSDOM('').window;
27780
+ }
27781
+ return serverDomWindow;
27782
+ }
27783
+ /**
27784
+ * Loads `jsdom` which backs the DOM window outside of a browser
27785
+ *
27786
+ * Note: [😷] `jsdom` reaches for Node.js built-ins like `fs`, `child_process` and `net`, so browser bundlers must
27787
+ * never follow the `require` below - even though it is unreachable in a browser, bundlers resolve it statically.
27788
+ * They are told to replace `jsdom` with an empty module by the `browser` field of the generated package
27789
+ * manifests, which is written by `applyBrowserUnsupportedDependencyStubs` during the package generation.
27790
+ *
27791
+ * @returns The `jsdom` library
27792
+ * @throws {EnvironmentMismatchError} When `jsdom` can not be loaded in the current runtime
27793
+ * @private utility of `$provideServerDomWindow`
27794
+ */
27795
+ function requireServerDomLibrary() {
27796
+ let serverDomLibrary = null;
27797
+ let serverDomLibraryError = null;
27798
+ try {
27799
+ // Note: [😷] Keep `'jsdom'` written as a literal, bundlers do not replace a computed module name
27800
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
27801
+ serverDomLibrary = require('jsdom');
27802
+ }
27803
+ catch (error) {
27804
+ assertsError(error);
27805
+ serverDomLibraryError = error;
27806
+ }
27807
+ if (typeof (serverDomLibrary === null || serverDomLibrary === void 0 ? void 0 : serverDomLibrary.JSDOM) !== 'function') {
27808
+ throw new EnvironmentMismatchError(spacetrim.spaceTrim((block) => `
27809
+ Markdown can not be rendered because there is no DOM in the current runtime.
27810
+
27811
+ Rendered markdown is sanitized through \`DOMPurify\`, which needs a DOM - the DOM of the browser
27812
+ when the code runs in a browser and \`jsdom\` in every other runtime, for example during
27813
+ server-side rendering in **Node.js**.
27814
+
27815
+ ${block(serverDomLibraryError === null
27816
+ ? '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.'
27817
+ : `${serverDomLibraryError.name}: ${serverDomLibraryError.message}`)}
27818
+ `));
27819
+ }
27820
+ return serverDomLibrary;
27821
+ }
27822
+
27749
27823
  /**
27750
27824
  * Default citation identifier used for simplified citation markers without an explicit position.
27751
27825
  *
@@ -28042,12 +28116,6 @@
28042
28116
  * @private utility of `renderMarkdown`
28043
28117
  */
28044
28118
  let serverMarkdownSanitizer = null;
28045
- /**
28046
- * Shared JSDOM window backing the server-side DOMPurify instance.
28047
- *
28048
- * @private utility of `renderMarkdown`
28049
- */
28050
- let serverMarkdownSanitizerWindow = null;
28051
28119
  /**
28052
28120
  * Pattern matching CODE FENCE.
28053
28121
  */
@@ -28086,6 +28154,14 @@
28086
28154
  * @private utility of `renderMarkdown`
28087
28155
  */
28088
28156
  const INLINE_REFERENCE_REGEX = /\[\[([^\]\r\n]+?)\]\]/g;
28157
+ /**
28158
+ * Pattern matching ordinary markdown links that can be promoted to inline reference chips.
28159
+ *
28160
+ * Images are intentionally captured separately and left unchanged by the replacement helper.
28161
+ *
28162
+ * @private utility of `renderMarkdown`
28163
+ */
28164
+ const MARKDOWN_INLINE_REFERENCE_LINK_REGEX = /(!?)\[([^\]\r\n]*)\]\(\s*(<[^>\r\n]+>|[^)\s]+)(?:\s+(?:"[^"\r\n]*"|'[^'\r\n]*'|\([^)]*\)))?\s*\)/g;
28089
28165
  /**
28090
28166
  * Collection of math delimiter definitions.
28091
28167
  */
@@ -28175,19 +28251,6 @@
28175
28251
  registerMarkdownSanitizerHooks(markdownSanitizer);
28176
28252
  return markdownSanitizer;
28177
28253
  }
28178
- /**
28179
- * Lazily creates the JSDOM window used by server-side markdown sanitization.
28180
- *
28181
- * @private utility of `renderMarkdown`
28182
- */
28183
- function getServerMarkdownSanitizerWindow() {
28184
- if (!serverMarkdownSanitizerWindow) {
28185
- // eslint-disable-next-line @typescript-eslint/no-var-requires
28186
- const { JSDOM } = require('jsdom');
28187
- serverMarkdownSanitizerWindow = new JSDOM('').window;
28188
- }
28189
- return serverMarkdownSanitizerWindow;
28190
- }
28191
28254
  /**
28192
28255
  * Returns the shared DOMPurify instance appropriate for the current runtime.
28193
28256
  *
@@ -28198,7 +28261,7 @@
28198
28261
  browserMarkdownSanitizer !== null && browserMarkdownSanitizer !== void 0 ? browserMarkdownSanitizer : (browserMarkdownSanitizer = createMarkdownSanitizer(window));
28199
28262
  return browserMarkdownSanitizer;
28200
28263
  }
28201
- serverMarkdownSanitizer !== null && serverMarkdownSanitizer !== void 0 ? serverMarkdownSanitizer : (serverMarkdownSanitizer = createMarkdownSanitizer(getServerMarkdownSanitizerWindow()));
28264
+ serverMarkdownSanitizer !== null && serverMarkdownSanitizer !== void 0 ? serverMarkdownSanitizer : (serverMarkdownSanitizer = createMarkdownSanitizer($provideServerDomWindow()));
28202
28265
  return serverMarkdownSanitizer;
28203
28266
  }
28204
28267
  /**
@@ -28323,11 +28386,12 @@
28323
28386
  * outer `<details>` and optional `<summary>` markup untouched.
28324
28387
  *
28325
28388
  * @param detailsBlock - Raw `<details>...</details>` HTML captured from markdown.
28389
+ * @param options - Markdown rendering options to reuse for the details body.
28326
28390
  * @returns `<details>` HTML whose body has been converted from markdown to HTML.
28327
28391
  *
28328
28392
  * @private utility of `renderMarkdown`
28329
28393
  */
28330
- function renderDetailsBlock(detailsBlock) {
28394
+ function renderDetailsBlock(detailsBlock, options) {
28331
28395
  var _a, _b;
28332
28396
  const openTagMatch = detailsBlock.match(/^<details\b[^>]*>/i);
28333
28397
  const closeTagMatch = detailsBlock.match(/<\/details\s*>$/i);
@@ -28340,7 +28404,7 @@
28340
28404
  const summaryMatch = innerContent.match(/^(\s*<summary\b[^>]*>[\s\S]*?<\/summary\s*>)([\s\S]*)$/i);
28341
28405
  const summaryHtml = (_a = summaryMatch === null || summaryMatch === void 0 ? void 0 : summaryMatch[1]) !== null && _a !== void 0 ? _a : '';
28342
28406
  const bodyMarkdown = ((_b = summaryMatch === null || summaryMatch === void 0 ? void 0 : summaryMatch[2]) !== null && _b !== void 0 ? _b : innerContent);
28343
- const renderedBody = renderMarkdown(bodyMarkdown);
28407
+ const renderedBody = renderMarkdown(bodyMarkdown, options);
28344
28408
  return `${openTag}${summaryHtml}${renderedBody}${closeTag}`;
28345
28409
  }
28346
28410
  /**
@@ -28377,16 +28441,17 @@
28377
28441
  * processes their content.
28378
28442
  *
28379
28443
  * @param markdown - Markdown text that may contain raw HTML `<details>` blocks.
28444
+ * @param options - Markdown rendering options to reuse for the details body.
28380
28445
  * @returns Masked markdown and a restore helper that returns `string_html`.
28381
28446
  *
28382
28447
  * @private utility of `renderMarkdown`
28383
28448
  */
28384
- function maskDetailsBlocks(markdown) {
28449
+ function maskDetailsBlocks(markdown, options) {
28385
28450
  const blocks = [];
28386
28451
  DETAILS_BLOCK_REGEX.lastIndex = 0;
28387
28452
  const masked = markdown.replace(DETAILS_BLOCK_REGEX, (match) => {
28388
28453
  const placeholder = `${DETAILS_PLACEHOLDER_PREFIX}${blocks.length}__`;
28389
- blocks.push(renderDetailsBlock(match));
28454
+ blocks.push(renderDetailsBlock(match, options));
28390
28455
  return placeholder;
28391
28456
  });
28392
28457
  return {
@@ -28487,6 +28552,79 @@
28487
28552
  }
28488
28553
  return referenceByKey;
28489
28554
  }
28555
+ /**
28556
+ * Returns whether a href starts with a configured source href prefix.
28557
+ *
28558
+ * @param href - Markdown link destination.
28559
+ * @param sourceHrefPrefix - Configured source href prefix.
28560
+ * @returns Whether the href belongs to the source prefix.
28561
+ *
28562
+ * @private utility of `renderMarkdown`
28563
+ */
28564
+ function doesHrefStartWithSourceHrefPrefix(href, sourceHrefPrefix) {
28565
+ if (href === sourceHrefPrefix) {
28566
+ return true;
28567
+ }
28568
+ const normalizedSourceHrefPrefix = sourceHrefPrefix.endsWith('/') ? sourceHrefPrefix : `${sourceHrefPrefix}/`;
28569
+ return href.startsWith(normalizedSourceHrefPrefix);
28570
+ }
28571
+ /**
28572
+ * Returns a comparable path for an absolute href when the configured source prefix is relative.
28573
+ *
28574
+ * @param href - Href to normalize.
28575
+ * @returns Absolute URL pathname or the original href when it is relative/invalid.
28576
+ *
28577
+ * @private utility of `renderMarkdown`
28578
+ */
28579
+ function resolveAbsoluteHrefPath(href) {
28580
+ try {
28581
+ return new URL(href).pathname;
28582
+ }
28583
+ catch (_a) {
28584
+ return href;
28585
+ }
28586
+ }
28587
+ /**
28588
+ * Returns whether one markdown link destination belongs to one inline reference.
28589
+ *
28590
+ * Relative project paths also match absolute URLs on the current server, which keeps
28591
+ * server-generated relative links and model-generated absolute links consistent.
28592
+ *
28593
+ * @param reference - Candidate inline reference.
28594
+ * @param href - Markdown link destination.
28595
+ * @returns Whether the href should render as the reference chip.
28596
+ *
28597
+ * @private utility of `renderMarkdown`
28598
+ */
28599
+ function doesMarkdownInlineReferenceMatchHref(reference, href) {
28600
+ const normalizedHref = href.trim();
28601
+ return (reference.sourceHrefPrefixes || []).some((sourceHrefPrefix) => {
28602
+ const normalizedSourceHrefPrefix = sourceHrefPrefix.trim();
28603
+ if (!normalizedSourceHrefPrefix) {
28604
+ return false;
28605
+ }
28606
+ if (doesHrefStartWithSourceHrefPrefix(normalizedHref, normalizedSourceHrefPrefix)) {
28607
+ return true;
28608
+ }
28609
+ const isRelativeSourceHrefPrefix = !/^[a-z][a-z0-9+.-]*:/i.test(normalizedSourceHrefPrefix);
28610
+ const isAbsoluteHref = /^[a-z][a-z0-9+.-]*:/i.test(normalizedHref);
28611
+ return (isRelativeSourceHrefPrefix &&
28612
+ isAbsoluteHref &&
28613
+ doesHrefStartWithSourceHrefPrefix(resolveAbsoluteHrefPath(normalizedHref), normalizedSourceHrefPrefix));
28614
+ });
28615
+ }
28616
+ /**
28617
+ * Finds the inline reference represented by a markdown link destination.
28618
+ *
28619
+ * @param references - Inline references available to the markdown renderer.
28620
+ * @param href - Markdown link destination.
28621
+ * @returns Matching reference or `undefined` when the href is unrelated.
28622
+ *
28623
+ * @private utility of `renderMarkdown`
28624
+ */
28625
+ function findMarkdownInlineReferenceByHref(references, href) {
28626
+ return references.find((reference) => doesMarkdownInlineReferenceMatchHref(reference, href));
28627
+ }
28490
28628
  /**
28491
28629
  * Renders one inline reference as raw HTML that is sanitized by the shared markdown sanitizer.
28492
28630
  *
@@ -28566,10 +28704,18 @@
28566
28704
  if (referenceByKey.size === 0) {
28567
28705
  return markdown;
28568
28706
  }
28569
- return markdown.replace(INLINE_REFERENCE_REGEX, (match, rawReference) => {
28707
+ const markdownWithInlineReferenceTokens = markdown.replace(INLINE_REFERENCE_REGEX, (match, rawReference) => {
28570
28708
  const reference = referenceByKey.get(normalizeMarkdownInlineReferenceKey(rawReference));
28571
28709
  return reference ? renderMarkdownInlineReferenceHtml(reference, className) : match;
28572
28710
  });
28711
+ return markdownWithInlineReferenceTokens.replace(MARKDOWN_INLINE_REFERENCE_LINK_REGEX, (match, imageMarker, _linkLabel, rawHref) => {
28712
+ if (imageMarker) {
28713
+ return match;
28714
+ }
28715
+ const href = rawHref.replace(/^<|>$/g, '');
28716
+ const reference = findMarkdownInlineReferenceByHref(references, href);
28717
+ return reference ? renderMarkdownInlineReferenceHtml(reference, className) : match;
28718
+ });
28573
28719
  }
28574
28720
  /**
28575
28721
  * Loads KaTeX CSS in browser environments that need to display math output.
@@ -28607,7 +28753,7 @@
28607
28753
  const converter = options ? createChatMarkdownConverter(options) : CHAT_MARKDOWN_CONVERTER;
28608
28754
  try {
28609
28755
  const normalizedMarkdown = normalizeMarkdownSublists(markdown);
28610
- const { masked: maskedMarkdown, restore: restoreDetails } = maskDetailsBlocks(normalizedMarkdown);
28756
+ const { masked: maskedMarkdown, restore: restoreDetails } = maskDetailsBlocks(normalizedMarkdown, options);
28611
28757
  const { masked: codeMaskedMarkdown, restore: restoreCode } = maskMarkdownCodeSegments(maskedMarkdown);
28612
28758
  const referencedMarkdown = applyMarkdownInlineReferences(codeMaskedMarkdown, options);
28613
28759
  const inlineReferenceMarkdown = restoreCode(referencedMarkdown);
@@ -47710,19 +47856,6 @@
47710
47856
  }
47711
47857
  // TODO: [🐱‍🚀] Explain that NotFoundError ([🐱‍🚀] and other specific errors) has priority over DatabaseError in some contexts
47712
47858
 
47713
- /**
47714
- * This error type indicates that you try to use a feature that is not available in the current environment
47715
- *
47716
- * @public exported from `@promptbook/core`
47717
- */
47718
- class EnvironmentMismatchError extends Error {
47719
- constructor(message) {
47720
- super(message);
47721
- this.name = 'EnvironmentMismatchError';
47722
- Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
47723
- }
47724
- }
47725
-
47726
47859
  /**
47727
47860
  * This error occurs when some expectation is not met in the execution of the pipeline
47728
47861
  *
@@ -53162,6 +53295,41 @@
53162
53295
  `;
53163
53296
  }
53164
53297
 
53298
+ /**
53299
+ * Creates a loader which imports one module on the first call and reuses the very same module afterwards
53300
+ *
53301
+ * Note: [🐌] Heavy third-party dependencies are imported lazily to keep the startup of the Promptbook CLI fast.
53302
+ * A statically imported dependency is loaded every single time the bundle is loaded, even when the running
53303
+ * command never touches it. A lazily imported dependency is loaded only when the feature is really used.
53304
+ *
53305
+ * @example
53306
+ * const loadJsdomModule = createLazyModuleLoader(() => import('jsdom'));
53307
+ * const { JSDOM } = await loadJsdomModule();
53308
+ *
53309
+ * @private internal utility of Promptbook
53310
+ */
53311
+ function createLazyModuleLoader(importModule) {
53312
+ let importedModulePromise = null;
53313
+ return function loadModule() {
53314
+ if (importedModulePromise === null) {
53315
+ importedModulePromise = importModule();
53316
+ }
53317
+ return importedModulePromise;
53318
+ };
53319
+ }
53320
+ // Note: [🐌] Do not convert the lazy `import(...)` calls back to static `import` statements, it would bring back the
53321
+ // slow startup of the `ptbk` CLI utility
53322
+
53323
+ /**
53324
+ * Loads the OpenAI AgentKit SDK (`@openai/agents`) on demand
53325
+ *
53326
+ * Note: [🐌] The AgentKit SDK is one of the heaviest dependencies of Promptbook, loading it eagerly would slow down
53327
+ * every single run of the `ptbk` CLI utility even when no AgentKit agent is used
53328
+ *
53329
+ * @private internal utility of `@promptbook/openai`
53330
+ */
53331
+ const loadOpenAiAgentsModule = createLazyModuleLoader(() => import('@openai/agents'));
53332
+
53165
53333
  /**
53166
53334
  * Constant for default model used for nested DeepSearch tool invocations.
53167
53335
  */
@@ -53215,11 +53383,12 @@
53215
53383
  /**
53216
53384
  * Builds the tool list for AgentKit, including hosted file search when applicable.
53217
53385
  */
53218
- buildAgentKitTools(options) {
53386
+ async buildAgentKitTools(options) {
53219
53387
  const { tools, vectorStoreId } = options;
53388
+ const { fileSearchTool, tool: agentKitTool } = await loadOpenAiAgentsModule();
53220
53389
  const agentKitTools = [];
53221
53390
  if (vectorStoreId) {
53222
- agentKitTools.push(agents.fileSearchTool(vectorStoreId));
53391
+ agentKitTools.push(fileSearchTool(vectorStoreId));
53223
53392
  }
53224
53393
  if (!tools || tools.length === 0) {
53225
53394
  return agentKitTools;
@@ -53227,11 +53396,11 @@
53227
53396
  let scriptTools = null;
53228
53397
  for (const toolDefinition of tools) {
53229
53398
  if (this.isDeepSearchToolDefinition(toolDefinition)) {
53230
- agentKitTools.push(this.createDeepSearchAgentKitTool(toolDefinition));
53399
+ agentKitTools.push(await this.createDeepSearchAgentKitTool(toolDefinition));
53231
53400
  continue;
53232
53401
  }
53233
53402
  scriptTools !== null && scriptTools !== void 0 ? scriptTools : (scriptTools = this.resolveScriptTools());
53234
- agentKitTools.push(agents.tool({
53403
+ agentKitTools.push(agentKitTool({
53235
53404
  name: toolDefinition.name,
53236
53405
  description: toolDefinition.description,
53237
53406
  parameters: this.normalizeAgentKitToolParameters(toolDefinition.parameters),
@@ -53438,12 +53607,13 @@
53438
53607
  /**
53439
53608
  * Creates the native Agent SDK tool used for `USE DEEPSEARCH`.
53440
53609
  */
53441
- createDeepSearchAgentKitTool(toolDefinition) {
53442
- const deepSearchAgent = new agents.Agent({
53610
+ async createDeepSearchAgentKitTool(toolDefinition) {
53611
+ const { Agent: AgentFromKit, webSearchTool } = await loadOpenAiAgentsModule();
53612
+ const deepSearchAgent = new AgentFromKit({
53443
53613
  name: 'DeepSearch',
53444
53614
  model: DEFAULT_DEEP_SEARCH_MODEL_NAME,
53445
53615
  instructions: this.createDeepSearchAgentInstructions(toolDefinition.description),
53446
- tools: [agents.webSearchTool({ searchContextSize: 'high' })],
53616
+ tools: [webSearchTool({ searchContextSize: 'high' })],
53447
53617
  });
53448
53618
  return deepSearchAgent.asTool({
53449
53619
  toolName: toolDefinition.name,
@@ -54765,6 +54935,14 @@
54765
54935
  }
54766
54936
  }
54767
54937
 
54938
+ /**
54939
+ * Loads the OpenAI SDK (`openai`) on demand
54940
+ *
54941
+ * Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
54942
+ *
54943
+ * @private internal utility of `OpenAiCompatibleRequestManager`
54944
+ */
54945
+ const loadOpenAiModule = createLazyModuleLoader(() => import('openai'));
54768
54946
  /**
54769
54947
  * Manages OpenAI-compatible client creation plus shared retry and rate-limit behavior.
54770
54948
  *
@@ -54791,7 +54969,8 @@
54791
54969
  timeout: API_REQUEST_TIMEOUT,
54792
54970
  maxRetries: CONNECTION_RETRIES_LIMIT,
54793
54971
  };
54794
- this.client = new OpenAI__default["default"](enhancedOptions);
54972
+ const { default: OpenAI } = await loadOpenAiModule();
54973
+ this.client = new OpenAI(enhancedOptions);
54795
54974
  }
54796
54975
  return this.client;
54797
54976
  }
@@ -56938,8 +57117,9 @@
56938
57117
  vectorStoreId,
56939
57118
  });
56940
57119
  }
56941
- const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
56942
- const openAiAgentKitAgent = new agents.Agent({
57120
+ const { Agent: AgentFromKit } = await loadOpenAiAgentsModule();
57121
+ const agentKitTools = await this.buildAgentKitTools({ tools, vectorStoreId });
57122
+ const openAiAgentKitAgent = new AgentFromKit({
56943
57123
  name,
56944
57124
  model: this.agentKitModelName,
56945
57125
  instructions: instructions || 'You are a helpful assistant.',
@@ -56984,7 +57164,8 @@
56984
57164
  agentName: agentForRun.name,
56985
57165
  input: inputItems,
56986
57166
  };
56987
- const streamResult = await agents.run(agentForRun, inputItems, {
57167
+ const { run } = await loadOpenAiAgentsModule();
57168
+ const streamResult = await run(agentForRun, inputItems, {
56988
57169
  stream: true,
56989
57170
  maxTurns: 200,
56990
57171
  context: {
@@ -57126,11 +57307,12 @@
57126
57307
  * Ensures the AgentKit SDK is wired to the OpenAI client and API key.
57127
57308
  */
57128
57309
  async ensureAgentKitDefaults() {
57310
+ const { setDefaultOpenAIClient, setDefaultOpenAIKey } = await loadOpenAiAgentsModule();
57129
57311
  const client = await this.getClient();
57130
- agents.setDefaultOpenAIClient(client);
57312
+ setDefaultOpenAIClient(client);
57131
57313
  const apiKey = this.agentKitOptions.apiKey;
57132
57314
  if (apiKey && typeof apiKey === 'string') {
57133
- agents.setDefaultOpenAIKey(apiKey);
57315
+ setDefaultOpenAIKey(apiKey);
57134
57316
  }
57135
57317
  }
57136
57318
  /**