@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/README.md CHANGED
@@ -647,26 +647,27 @@ ptbk coder verify
647
647
  | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | ------ | ---- | ----- | ------------------------------------------------------------------------ |
648
648
  | `ptbk coder init` | Creates `prompts/`, `prompts/done/`, the project-generic template files materialized in `prompts/templates/` (currently `common.md`), and a starter `AGENTS.md`; ensures `.env` contains `CODING_AGENT_GIT_NAME`, `CODING_AGENT_GIT_EMAIL`, and `CODING_AGENT_GIT_SIGNING_KEY`; adds helper coder scripts to `package.json`; ensures `.gitignore` contains `/.promptbook`; and configures `.vscode/settings.json` to save pasted prompt images into `prompts/screenshots/`. |
649
649
  | `ptbk coder generate-boilerplates` | Creates new prompt markdown files with fresh emoji tags so you can quickly fill in coding tasks; `--template` accepts either a built-in alias or a markdown file path relative to the project root. |
650
- | `ptbk coder run` | Picks the next ready prompt, appends optional context, runs it through the selected coding agent, can optionally verify each attempt with a shell test command and feed failing output back for retries, then marks success or failure, commits the result, and pushes only when `--auto-push` is enabled. |
650
+ | `ptbk coder run` | Picks the next ready prompt, can run tests before coding to stop or repair pre-existing failures, appends optional context, runs it through the selected coding agent, can optionally verify each attempt with a shell test command and feed failing output back for retries, then marks success or failure, commits the result, and pushes only when `--auto-push` is enabled. |
651
651
  | `ptbk coder find-refactor-candidates` | Scans the repository for oversized or overpacked files and writes prompt files for likely refactors; `--level <xlow | low | medium | high | xhigh | extreme>` ranges from a very benevolent scan to a very aggressive sweep. |
652
652
  | `ptbk coder verify` | Walks through completed prompts, archives truly finished work, and adds follow-up repair prompts for unfinished results. |
653
653
 
654
654
  #### Most useful `ptbk coder run` flags
655
655
 
656
- | Flag | Purpose |
657
- | -------------------------- | -------------------------------------------------------------------------------------------------- |
658
- | `--harness <name>` | Selects the coding harness. |
659
- | `--model <model>` | Chooses the runner model; required for `openai-codex` and `gemini`, optional for `github-copilot`. |
660
- | `--context <text-or-file>` | Appends extra instructions inline or from a file like `AGENTS.md`. |
661
- | `--test <command>` | Runs a verification command after each prompt attempt and feeds failing output back for retries. |
662
- | `--thinking-level <level>` | Sets reasoning effort for supported runners. |
663
- | `--no-auto` | Waits for user confirmation before each prompt instead of running automatically through the queue. |
664
- | `--ignore-git-changes` | Disables the clean-working-tree guard. |
665
- | `--priority <n>` | Runs only prompts at or above the given priority. |
666
- | `--dry-run` | Prints which prompts are ready instead of executing them. |
667
- | `--allow-credits` | Lets OpenAI Codex spend credits when required. |
668
- | `--auto-push` | Pushes each successful coding-agent commit to the configured remote. |
669
- | `--auto-migrate` | Runs testing-server database migrations after each successful prompt. |
656
+ | Flag | Purpose |
657
+ | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
658
+ | `--harness <name>` | Selects the coding harness. |
659
+ | `--model <model>` | Chooses the runner model; required for `openai-codex` and `gemini`, optional for `github-copilot`. |
660
+ | `--context <text-or-file>` | Appends extra instructions inline or from a file like `AGENTS.md`. |
661
+ | `--test <command>` | Runs a verification command after each prompt attempt and feeds failing output back for retries. |
662
+ | `--test-before <mode>` | Runs tests before coding: `no` (default), `yes-and-fail` (stop with results), or `yes-and-fix` (create one repair prompt first); defaults to `npm test` when enabled without `--test`. |
663
+ | `--thinking-level <level>` | Sets reasoning effort for supported runners. |
664
+ | `--no-auto` | Waits for user confirmation before each prompt instead of running automatically through the queue. |
665
+ | `--ignore-git-changes` | Disables the clean-working-tree guard. |
666
+ | `--priority <n>` | Runs only prompts at or above the given priority. |
667
+ | `--dry-run` | Prints which prompts are ready instead of executing them. |
668
+ | `--allow-credits` | Lets OpenAI Codex spend credits when required. |
669
+ | `--auto-push` | Pushes each successful coding-agent commit to the configured remote. |
670
+ | `--auto-migrate` | Runs testing-server database migrations after each successful prompt. |
670
671
 
671
672
  #### Typical usage pattern
672
673
 
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-1';
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
  */
@@ -28093,6 +28160,14 @@ const DETAILS_PLACEHOLDER_WRAPPED_REGEX = new RegExp(`<p>\\s*(${DETAILS_PLACEHOL
28093
28160
  * @private utility of `renderMarkdown`
28094
28161
  */
28095
28162
  const INLINE_REFERENCE_REGEX = /\[\[([^\]\r\n]+?)\]\]/g;
28163
+ /**
28164
+ * Pattern matching ordinary markdown links that can be promoted to inline reference chips.
28165
+ *
28166
+ * Images are intentionally captured separately and left unchanged by the replacement helper.
28167
+ *
28168
+ * @private utility of `renderMarkdown`
28169
+ */
28170
+ const MARKDOWN_INLINE_REFERENCE_LINK_REGEX = /(!?)\[([^\]\r\n]*)\]\(\s*(<[^>\r\n]+>|[^)\s]+)(?:\s+(?:"[^"\r\n]*"|'[^'\r\n]*'|\([^)]*\)))?\s*\)/g;
28096
28171
  /**
28097
28172
  * Collection of math delimiter definitions.
28098
28173
  */
@@ -28182,19 +28257,6 @@ function createMarkdownSanitizer(sanitizerWindow) {
28182
28257
  registerMarkdownSanitizerHooks(markdownSanitizer);
28183
28258
  return markdownSanitizer;
28184
28259
  }
28185
- /**
28186
- * Lazily creates the JSDOM window used by server-side markdown sanitization.
28187
- *
28188
- * @private utility of `renderMarkdown`
28189
- */
28190
- function getServerMarkdownSanitizerWindow() {
28191
- if (!serverMarkdownSanitizerWindow) {
28192
- // eslint-disable-next-line @typescript-eslint/no-var-requires
28193
- const { JSDOM } = require('jsdom');
28194
- serverMarkdownSanitizerWindow = new JSDOM('').window;
28195
- }
28196
- return serverMarkdownSanitizerWindow;
28197
- }
28198
28260
  /**
28199
28261
  * Returns the shared DOMPurify instance appropriate for the current runtime.
28200
28262
  *
@@ -28205,7 +28267,7 @@ function getMarkdownSanitizer() {
28205
28267
  browserMarkdownSanitizer !== null && browserMarkdownSanitizer !== void 0 ? browserMarkdownSanitizer : (browserMarkdownSanitizer = createMarkdownSanitizer(window));
28206
28268
  return browserMarkdownSanitizer;
28207
28269
  }
28208
- serverMarkdownSanitizer !== null && serverMarkdownSanitizer !== void 0 ? serverMarkdownSanitizer : (serverMarkdownSanitizer = createMarkdownSanitizer(getServerMarkdownSanitizerWindow()));
28270
+ serverMarkdownSanitizer !== null && serverMarkdownSanitizer !== void 0 ? serverMarkdownSanitizer : (serverMarkdownSanitizer = createMarkdownSanitizer($provideServerDomWindow()));
28209
28271
  return serverMarkdownSanitizer;
28210
28272
  }
28211
28273
  /**
@@ -28330,11 +28392,12 @@ const CHAT_MARKDOWN_CONVERTER = createChatMarkdownConverter();
28330
28392
  * outer `<details>` and optional `<summary>` markup untouched.
28331
28393
  *
28332
28394
  * @param detailsBlock - Raw `<details>...</details>` HTML captured from markdown.
28395
+ * @param options - Markdown rendering options to reuse for the details body.
28333
28396
  * @returns `<details>` HTML whose body has been converted from markdown to HTML.
28334
28397
  *
28335
28398
  * @private utility of `renderMarkdown`
28336
28399
  */
28337
- function renderDetailsBlock(detailsBlock) {
28400
+ function renderDetailsBlock(detailsBlock, options) {
28338
28401
  var _a, _b;
28339
28402
  const openTagMatch = detailsBlock.match(/^<details\b[^>]*>/i);
28340
28403
  const closeTagMatch = detailsBlock.match(/<\/details\s*>$/i);
@@ -28347,7 +28410,7 @@ function renderDetailsBlock(detailsBlock) {
28347
28410
  const summaryMatch = innerContent.match(/^(\s*<summary\b[^>]*>[\s\S]*?<\/summary\s*>)([\s\S]*)$/i);
28348
28411
  const summaryHtml = (_a = summaryMatch === null || summaryMatch === void 0 ? void 0 : summaryMatch[1]) !== null && _a !== void 0 ? _a : '';
28349
28412
  const bodyMarkdown = ((_b = summaryMatch === null || summaryMatch === void 0 ? void 0 : summaryMatch[2]) !== null && _b !== void 0 ? _b : innerContent);
28350
- const renderedBody = renderMarkdown(bodyMarkdown);
28413
+ const renderedBody = renderMarkdown(bodyMarkdown, options);
28351
28414
  return `${openTag}${summaryHtml}${renderedBody}${closeTag}`;
28352
28415
  }
28353
28416
  /**
@@ -28384,16 +28447,17 @@ function maskMarkdownCodeSegments(markdown) {
28384
28447
  * processes their content.
28385
28448
  *
28386
28449
  * @param markdown - Markdown text that may contain raw HTML `<details>` blocks.
28450
+ * @param options - Markdown rendering options to reuse for the details body.
28387
28451
  * @returns Masked markdown and a restore helper that returns `string_html`.
28388
28452
  *
28389
28453
  * @private utility of `renderMarkdown`
28390
28454
  */
28391
- function maskDetailsBlocks(markdown) {
28455
+ function maskDetailsBlocks(markdown, options) {
28392
28456
  const blocks = [];
28393
28457
  DETAILS_BLOCK_REGEX.lastIndex = 0;
28394
28458
  const masked = markdown.replace(DETAILS_BLOCK_REGEX, (match) => {
28395
28459
  const placeholder = `${DETAILS_PLACEHOLDER_PREFIX}${blocks.length}__`;
28396
- blocks.push(renderDetailsBlock(match));
28460
+ blocks.push(renderDetailsBlock(match, options));
28397
28461
  return placeholder;
28398
28462
  });
28399
28463
  return {
@@ -28494,6 +28558,79 @@ function createMarkdownInlineReferenceByKey(references) {
28494
28558
  }
28495
28559
  return referenceByKey;
28496
28560
  }
28561
+ /**
28562
+ * Returns whether a href starts with a configured source href prefix.
28563
+ *
28564
+ * @param href - Markdown link destination.
28565
+ * @param sourceHrefPrefix - Configured source href prefix.
28566
+ * @returns Whether the href belongs to the source prefix.
28567
+ *
28568
+ * @private utility of `renderMarkdown`
28569
+ */
28570
+ function doesHrefStartWithSourceHrefPrefix(href, sourceHrefPrefix) {
28571
+ if (href === sourceHrefPrefix) {
28572
+ return true;
28573
+ }
28574
+ const normalizedSourceHrefPrefix = sourceHrefPrefix.endsWith('/') ? sourceHrefPrefix : `${sourceHrefPrefix}/`;
28575
+ return href.startsWith(normalizedSourceHrefPrefix);
28576
+ }
28577
+ /**
28578
+ * Returns a comparable path for an absolute href when the configured source prefix is relative.
28579
+ *
28580
+ * @param href - Href to normalize.
28581
+ * @returns Absolute URL pathname or the original href when it is relative/invalid.
28582
+ *
28583
+ * @private utility of `renderMarkdown`
28584
+ */
28585
+ function resolveAbsoluteHrefPath(href) {
28586
+ try {
28587
+ return new URL(href).pathname;
28588
+ }
28589
+ catch (_a) {
28590
+ return href;
28591
+ }
28592
+ }
28593
+ /**
28594
+ * Returns whether one markdown link destination belongs to one inline reference.
28595
+ *
28596
+ * Relative project paths also match absolute URLs on the current server, which keeps
28597
+ * server-generated relative links and model-generated absolute links consistent.
28598
+ *
28599
+ * @param reference - Candidate inline reference.
28600
+ * @param href - Markdown link destination.
28601
+ * @returns Whether the href should render as the reference chip.
28602
+ *
28603
+ * @private utility of `renderMarkdown`
28604
+ */
28605
+ function doesMarkdownInlineReferenceMatchHref(reference, href) {
28606
+ const normalizedHref = href.trim();
28607
+ return (reference.sourceHrefPrefixes || []).some((sourceHrefPrefix) => {
28608
+ const normalizedSourceHrefPrefix = sourceHrefPrefix.trim();
28609
+ if (!normalizedSourceHrefPrefix) {
28610
+ return false;
28611
+ }
28612
+ if (doesHrefStartWithSourceHrefPrefix(normalizedHref, normalizedSourceHrefPrefix)) {
28613
+ return true;
28614
+ }
28615
+ const isRelativeSourceHrefPrefix = !/^[a-z][a-z0-9+.-]*:/i.test(normalizedSourceHrefPrefix);
28616
+ const isAbsoluteHref = /^[a-z][a-z0-9+.-]*:/i.test(normalizedHref);
28617
+ return (isRelativeSourceHrefPrefix &&
28618
+ isAbsoluteHref &&
28619
+ doesHrefStartWithSourceHrefPrefix(resolveAbsoluteHrefPath(normalizedHref), normalizedSourceHrefPrefix));
28620
+ });
28621
+ }
28622
+ /**
28623
+ * Finds the inline reference represented by a markdown link destination.
28624
+ *
28625
+ * @param references - Inline references available to the markdown renderer.
28626
+ * @param href - Markdown link destination.
28627
+ * @returns Matching reference or `undefined` when the href is unrelated.
28628
+ *
28629
+ * @private utility of `renderMarkdown`
28630
+ */
28631
+ function findMarkdownInlineReferenceByHref(references, href) {
28632
+ return references.find((reference) => doesMarkdownInlineReferenceMatchHref(reference, href));
28633
+ }
28497
28634
  /**
28498
28635
  * Renders one inline reference as raw HTML that is sanitized by the shared markdown sanitizer.
28499
28636
  *
@@ -28573,10 +28710,18 @@ function applyMarkdownInlineReferences(markdown, options) {
28573
28710
  if (referenceByKey.size === 0) {
28574
28711
  return markdown;
28575
28712
  }
28576
- return markdown.replace(INLINE_REFERENCE_REGEX, (match, rawReference) => {
28713
+ const markdownWithInlineReferenceTokens = markdown.replace(INLINE_REFERENCE_REGEX, (match, rawReference) => {
28577
28714
  const reference = referenceByKey.get(normalizeMarkdownInlineReferenceKey(rawReference));
28578
28715
  return reference ? renderMarkdownInlineReferenceHtml(reference, className) : match;
28579
28716
  });
28717
+ return markdownWithInlineReferenceTokens.replace(MARKDOWN_INLINE_REFERENCE_LINK_REGEX, (match, imageMarker, _linkLabel, rawHref) => {
28718
+ if (imageMarker) {
28719
+ return match;
28720
+ }
28721
+ const href = rawHref.replace(/^<|>$/g, '');
28722
+ const reference = findMarkdownInlineReferenceByHref(references, href);
28723
+ return reference ? renderMarkdownInlineReferenceHtml(reference, className) : match;
28724
+ });
28580
28725
  }
28581
28726
  /**
28582
28727
  * Loads KaTeX CSS in browser environments that need to display math output.
@@ -28614,7 +28759,7 @@ function renderMarkdown(markdown, options) {
28614
28759
  const converter = options ? createChatMarkdownConverter(options) : CHAT_MARKDOWN_CONVERTER;
28615
28760
  try {
28616
28761
  const normalizedMarkdown = normalizeMarkdownSublists(markdown);
28617
- const { masked: maskedMarkdown, restore: restoreDetails } = maskDetailsBlocks(normalizedMarkdown);
28762
+ const { masked: maskedMarkdown, restore: restoreDetails } = maskDetailsBlocks(normalizedMarkdown, options);
28618
28763
  const { masked: codeMaskedMarkdown, restore: restoreCode } = maskMarkdownCodeSegments(maskedMarkdown);
28619
28764
  const referencedMarkdown = applyMarkdownInlineReferences(codeMaskedMarkdown, options);
28620
28765
  const inlineReferenceMarkdown = restoreCode(referencedMarkdown);
@@ -47717,19 +47862,6 @@ class DatabaseError extends Error {
47717
47862
  }
47718
47863
  // TODO: [🐱‍🚀] Explain that NotFoundError ([🐱‍🚀] and other specific errors) has priority over DatabaseError in some contexts
47719
47864
 
47720
- /**
47721
- * This error type indicates that you try to use a feature that is not available in the current environment
47722
- *
47723
- * @public exported from `@promptbook/core`
47724
- */
47725
- class EnvironmentMismatchError extends Error {
47726
- constructor(message) {
47727
- super(message);
47728
- this.name = 'EnvironmentMismatchError';
47729
- Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
47730
- }
47731
- }
47732
-
47733
47865
  /**
47734
47866
  * This error occurs when some expectation is not met in the execution of the pipeline
47735
47867
  *
@@ -53169,6 +53301,41 @@ function buildToolInvocationScript(options) {
53169
53301
  `;
53170
53302
  }
53171
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
+
53172
53339
  /**
53173
53340
  * Constant for default model used for nested DeepSearch tool invocations.
53174
53341
  */
@@ -53222,8 +53389,9 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
53222
53389
  /**
53223
53390
  * Builds the tool list for AgentKit, including hosted file search when applicable.
53224
53391
  */
53225
- buildAgentKitTools(options) {
53392
+ async buildAgentKitTools(options) {
53226
53393
  const { tools, vectorStoreId } = options;
53394
+ const { fileSearchTool, tool: agentKitTool } = await loadOpenAiAgentsModule();
53227
53395
  const agentKitTools = [];
53228
53396
  if (vectorStoreId) {
53229
53397
  agentKitTools.push(fileSearchTool(vectorStoreId));
@@ -53234,11 +53402,11 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
53234
53402
  let scriptTools = null;
53235
53403
  for (const toolDefinition of tools) {
53236
53404
  if (this.isDeepSearchToolDefinition(toolDefinition)) {
53237
- agentKitTools.push(this.createDeepSearchAgentKitTool(toolDefinition));
53405
+ agentKitTools.push(await this.createDeepSearchAgentKitTool(toolDefinition));
53238
53406
  continue;
53239
53407
  }
53240
53408
  scriptTools !== null && scriptTools !== void 0 ? scriptTools : (scriptTools = this.resolveScriptTools());
53241
- agentKitTools.push(tool({
53409
+ agentKitTools.push(agentKitTool({
53242
53410
  name: toolDefinition.name,
53243
53411
  description: toolDefinition.description,
53244
53412
  parameters: this.normalizeAgentKitToolParameters(toolDefinition.parameters),
@@ -53445,8 +53613,9 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
53445
53613
  /**
53446
53614
  * Creates the native Agent SDK tool used for `USE DEEPSEARCH`.
53447
53615
  */
53448
- createDeepSearchAgentKitTool(toolDefinition) {
53449
- const deepSearchAgent = new Agent$1({
53616
+ async createDeepSearchAgentKitTool(toolDefinition) {
53617
+ const { Agent: AgentFromKit, webSearchTool } = await loadOpenAiAgentsModule();
53618
+ const deepSearchAgent = new AgentFromKit({
53450
53619
  name: 'DeepSearch',
53451
53620
  model: DEFAULT_DEEP_SEARCH_MODEL_NAME,
53452
53621
  instructions: this.createDeepSearchAgentInstructions(toolDefinition.description),
@@ -54772,6 +54941,14 @@ class OpenAiCompatibleNonChatPromptCaller {
54772
54941
  }
54773
54942
  }
54774
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'));
54775
54952
  /**
54776
54953
  * Manages OpenAI-compatible client creation plus shared retry and rate-limit behavior.
54777
54954
  *
@@ -54798,6 +54975,7 @@ class OpenAiCompatibleRequestManager {
54798
54975
  timeout: API_REQUEST_TIMEOUT,
54799
54976
  maxRetries: CONNECTION_RETRIES_LIMIT,
54800
54977
  };
54978
+ const { default: OpenAI } = await loadOpenAiModule();
54801
54979
  this.client = new OpenAI(enhancedOptions);
54802
54980
  }
54803
54981
  return this.client;
@@ -56945,8 +57123,9 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
56945
57123
  vectorStoreId,
56946
57124
  });
56947
57125
  }
56948
- const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
56949
- const openAiAgentKitAgent = new Agent$1({
57126
+ const { Agent: AgentFromKit } = await loadOpenAiAgentsModule();
57127
+ const agentKitTools = await this.buildAgentKitTools({ tools, vectorStoreId });
57128
+ const openAiAgentKitAgent = new AgentFromKit({
56950
57129
  name,
56951
57130
  model: this.agentKitModelName,
56952
57131
  instructions: instructions || 'You are a helpful assistant.',
@@ -56991,6 +57170,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
56991
57170
  agentName: agentForRun.name,
56992
57171
  input: inputItems,
56993
57172
  };
57173
+ const { run } = await loadOpenAiAgentsModule();
56994
57174
  const streamResult = await run(agentForRun, inputItems, {
56995
57175
  stream: true,
56996
57176
  maxTurns: 200,
@@ -57133,6 +57313,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
57133
57313
  * Ensures the AgentKit SDK is wired to the OpenAI client and API key.
57134
57314
  */
57135
57315
  async ensureAgentKitDefaults() {
57316
+ const { setDefaultOpenAIClient, setDefaultOpenAIKey } = await loadOpenAiAgentsModule();
57136
57317
  const client = await this.getClient();
57137
57318
  setDefaultOpenAIClient(client);
57138
57319
  const apiKey = this.agentKitOptions.apiKey;