@blocknote/xl-ai 0.31.0

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 (425) hide show
  1. package/LICENSE +373 -0
  2. package/dist/blocknote-xl-ai.cjs +20 -0
  3. package/dist/blocknote-xl-ai.cjs.map +1 -0
  4. package/dist/blocknote-xl-ai.js +2918 -0
  5. package/dist/blocknote-xl-ai.js.map +1 -0
  6. package/dist/locales.cjs +2 -0
  7. package/dist/locales.cjs.map +1 -0
  8. package/dist/locales.js +1424 -0
  9. package/dist/locales.js.map +1 -0
  10. package/dist/style.css +1 -0
  11. package/dist/webpack-stats.json +1 -0
  12. package/package.json +127 -0
  13. package/src/AIExtension.ts +419 -0
  14. package/src/api/LLMRequest.ts +236 -0
  15. package/src/api/LLMResponse.ts +64 -0
  16. package/src/api/formats/PromptBuilder.ts +46 -0
  17. package/src/api/formats/base-tools/createAddBlocksTool.ts +296 -0
  18. package/src/api/formats/base-tools/createUpdateBlockTool.ts +269 -0
  19. package/src/api/formats/base-tools/delete.ts +111 -0
  20. package/src/api/formats/base-tools/util/validateBlockArray.ts +32 -0
  21. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/Add heading (h1) and code block_1_112bacb4ae22459e8e8b87c510a5a1ab.json +15 -0
  22. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/add a list (end)_1_fd2cdf7edb597b5eee87ae1b4c9d8a9e.json +15 -0
  23. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/add a new paragraph (end)_1_f9f8cec49b3218519501c03ff5c4a3ba.json +15 -0
  24. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/add a new paragraph (start)_1_d152c585ba7d2fa6e68b1d4b063f266c.json +15 -0
  25. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (streaming)/add a new paragraph (start)_1_ae61114b97c12fbf57d14d6c64ffd647.json +15 -0
  26. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/Add heading (h1) and code block_1_c9a31b6237ae08647b85c7348edd052f.json +15 -0
  27. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/Add heading and code block_1_c9a31b6237ae08647b85c7348edd052f.json +15 -0
  28. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/add a list (end)_1_db45f2ba8778e15e8a5f7a320508be46.json +15 -0
  29. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/add a new paragraph (end)_1_f3eaf50ddad718f55acaa05dcc1a2809.json +15 -0
  30. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/add a new paragraph (start)_1_33db3205ea17e8f6ea3a5e2728b6f10e.json +15 -0
  31. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/Add heading (h1) and code block_1_5790f7702887daff99c884204e6ae3df.json +15 -0
  32. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/Add heading and code block_1_5790f7702887daff99c884204e6ae3df.json +15 -0
  33. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/add a list (end)_1_321607ef45a4235ca02c411097005de2.json +15 -0
  34. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/add a new paragraph (end)_1_709e808af3f5fb39418413416804a03e.json +15 -0
  35. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/add a new paragraph (start)_1_034fd3f9b57eba789a6449d5ff3714c4.json +15 -0
  36. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/Add heading (h1) and code block_1_084f72a77d80ec6bb6cd2081b3b1d301.json +15 -0
  37. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/Add heading and code block_1_084f72a77d80ec6bb6cd2081b3b1d301.json +15 -0
  38. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add a list (end)_1_5c081c7846ad89b59477ceda44c2a349.json +15 -0
  39. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add a new paragraph (end)_1_97770b1d0462a25cfacd049807a59110.json +15 -0
  40. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add a new paragraph (start)_1_ecf9943025fd7f7183aac8d86c4e0b6c.json +15 -0
  41. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/Add heading (h1) and code block_1_b19471ad74a7a4bf4b288369edf35407.json +15 -0
  42. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/Add heading and code block_1_b19471ad74a7a4bf4b288369edf35407.json +15 -0
  43. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add a list (end)_1_8105f57bbca898c1626edd5cd33308ed.json +15 -0
  44. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add a new paragraph (end)_1_2f4aa2dfa4f6046506c9e133c5d60e76.json +15 -0
  45. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add a new paragraph (start)_1_7352df4919df344c441fb32b5cdae62b.json +15 -0
  46. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/add and update paragraph_1_861b7da5f0734c4350466fb42da57dfe.json +15 -0
  47. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/add paragraph and update selection_1_4821f5b399d9ebc5b564c530740345ea.json +15 -0
  48. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/add and update paragraph_1_0d6f9f822d5ba2310e9cb3b5330d1ef0.json +15 -0
  49. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/add paragraph and update selection_1_0ca431ee9c56812e10198e60552a536f.json +15 -0
  50. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/add and update paragraph_1_96cb428c4df1b42645632abe5969170c.json +15 -0
  51. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/add paragraph and update selection_1_04f9e76ff73eff953288564e5385dbd4.json +15 -0
  52. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add and update paragraph_1_80b906ff9d95e8b88b30c4efd246dc4b.json +15 -0
  53. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add paragraph and update selection_1_f5cd402d603bead3d759ebb5485f39c3.json +15 -0
  54. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add and update paragraph_1_e0a277e6c9c61c532876788f8c914f42.json +15 -0
  55. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add paragraph and update selection_1_fc5837fa3ab53d1a511a8092a926d87d.json +15 -0
  56. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/delete first block_1_ba835c26344e8e2082ee1f404bacb992.json +15 -0
  57. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/delete first block_1_d857ced55373d86233599394800f1a63.json +15 -0
  58. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/delete first block_1_f88ee2c9e0a85200bb5550e4502fc0e5.json +15 -0
  59. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/delete first block_1_c2ce81529453c6009b31fc3e2d3f8aea.json +15 -0
  60. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/delete first block_1_90f8de8d41648f556395ecf223aa0e6e.json +15 -0
  61. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/drop mark and link and change text within mark_1_953804d0569e88c225ebe8711ac1d209.json +15 -0
  62. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/drop mark and link_1_9cfdcdc629e0d2c8ba65e699037e007c.json +15 -0
  63. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/modify nested content_1_595e0413e677a7d0e1cf7024e2cdbf11.json +15 -0
  64. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/modify parent content_1_8a40e8e484dd5e6352b3019e81255567.json +15 -0
  65. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/plain source block, add mention_1_03e2c4dfae2ceb146b12fc9a266da98e.json +15 -0
  66. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/standard update_1_f65e23072a2f6be046fc618e0dbf3949.json +15 -0
  67. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/styles + ic in source block, remove mark_1_3e4d4d1ba3f4c2e80cb1d38f35425665.json +15 -0
  68. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/styles + ic in source block, remove mention_1_7c0c0ebbf2e5eb36903b25d3e63f2a96.json +15 -0
  69. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/styles + ic in source block, replace content_1_f8c8827fbecd6977bdb2e5152b493530.json +15 -0
  70. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/styles + ic in source block, update mention prop_1_f4e5d300be72cb5a6c2ef33c32ce7325.json +15 -0
  71. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/styles + ic in source block, update text_1_388a274079ba06bcec0049a35278fc01.json +15 -0
  72. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/styles + ic in target block, add mark (paragraph)_1_c7be52683c9d405365815f334ed1f4db.json +15 -0
  73. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/styles + ic in target block, add mark (word)_1_9bc0da43041ca4b3a188fbdfd9562bae.json +15 -0
  74. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/translate selection_1_6f0c6d98d9a99081b01869826a538c74.json +15 -0
  75. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/turn paragraphs into list_1_122467a8b6979ad2a47b0417976218a9.json +15 -0
  76. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/update block type and content_1_ace9cde890d5c4b2a131f8867e7b5596.json +15 -0
  77. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8 (non-streaming)/update block type_1_d356646093fb778e9c8bce47f7133ef8.json +15 -0
  78. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/drop mark and link and change text within mark_1_6b9ad94993b0b3dc39ee8fab8057b967.json +15 -0
  79. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/drop mark and link_1_bde418f70f7c93522d3cff713cb6e8b2.json +15 -0
  80. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/modify nested content_1_6d6efada9f514cd6b5d479b784960905.json +15 -0
  81. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/modify parent content_1_0b00b5e42872d9f249427436ed23ca40.json +15 -0
  82. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/plain source block, add mention_1_a0f2a68ef2f46c1a3c014966a1d41463.json +15 -0
  83. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/standard update_1_69863686209bcd70d5d432c6c5646ec6.json +15 -0
  84. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/styles + ic in source block, remove mark_1_26a2249225e49ac962f2ffc4d186f048.json +15 -0
  85. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/styles + ic in source block, remove mention_1_8a9dfa091990b0ea68d8b5e600e5ded4.json +15 -0
  86. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/styles + ic in source block, replace content_1_b5da218448fab4a6144aee7b49fe7cfd.json +15 -0
  87. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/styles + ic in source block, update mention prop_1_93cd31cde8f8a9d7bcc6ec163bd82e32.json +15 -0
  88. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/styles + ic in source block, update text_1_98388769d4b6c534a448363e38006369.json +15 -0
  89. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/styles + ic in target block, add mark (paragraph)_1_039df897cf40b1464a3e77597698630f.json +15 -0
  90. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/styles + ic in target block, add mark (word)_1_ecfba97d707a7df556c8be55a94491bd.json +15 -0
  91. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/translate selection_1_674d4ec4b8af2ac528ec90892731f67a.json +15 -0
  92. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/turn paragraphs into list_1_1ec910c96203d1d86b7dcce97e352e91.json +15 -0
  93. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/update block type and content_1_56b6b0d7b3b4585a4ca5598979ccc319.json +15 -0
  94. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (non-streaming)/update block type_1_cec06b764f3e6538c0a0baeb04d60587.json +15 -0
  95. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/drop mark and link and change text within mark_1_60a05ae4a6b034fe6eaafb2b7bfb9638.json +15 -0
  96. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/drop mark and link_1_df81f4ea9e9cda25c1ef6b1d0de62e6e.json +15 -0
  97. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/modify nested content_1_c473102de44b6890149109c418f224a7.json +15 -0
  98. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/modify parent content_1_c8cc1e445e2ea3a61af98fae49719bb2.json +15 -0
  99. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/plain source block, add mention_1_e6db90ec1ad4b48b7e225a5ef7b7ea08.json +15 -0
  100. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/standard update_1_afb308d981984d812bf89191d498ddac.json +15 -0
  101. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/styles + ic in source block, remove mark_1_7d6962e90a2fb300f8efab2620d77389.json +15 -0
  102. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/styles + ic in source block, remove mention_1_a13d0c4ae92fddfbcbef8c619c092951.json +15 -0
  103. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/styles + ic in source block, replace content_1_8d4842fb70ad278064faa2c3c6efa73e.json +15 -0
  104. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/styles + ic in source block, update mention prop_1_70a3e6c68033303f4dce207ea802bba9.json +15 -0
  105. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/styles + ic in source block, update text_1_3f639531f292bf1edb20bbb65c6ad0e0.json +15 -0
  106. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/styles + ic in target block, add mark (paragraph)_1_ca41f979b0669b1a9285363b55a53b23.json +15 -0
  107. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/styles + ic in target block, add mark (word)_1_f3cba828671b95cae0b485ad554942cd.json +15 -0
  108. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/translate selection_1_54ec8515dd6ab214d8b92c5cf4f09529.json +15 -0
  109. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/turn paragraphs into list_1_ec7bd4074c354be223256a9d0ab17e64.json +15 -0
  110. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/update block type and content_1_d0dca6e4fab1bc2c56ba2099e199fb05.json +15 -0
  111. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/update block type_1_18c554c2e45b6f5a1f491396916dcb46.json +15 -0
  112. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/drop mark and link and change text within mark_1_feb4bd702156a044fe3c72729f12d83c.json +15 -0
  113. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/drop mark and link_1_1e8bbd364a267db768002ed243692a79.json +15 -0
  114. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/modify nested content_1_b48a9c33b3a0d37850bd38f4c95b310f.json +15 -0
  115. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/modify parent content_1_b8c66592925ae0e551a329b7b2f3b3e2.json +15 -0
  116. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/plain source block, add mention_1_196e976a8d5748fd3b667cc39b96cc4d.json +15 -0
  117. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/standard update_1_62ccc02aa192415d17e9a1f5c53dffb1.json +15 -0
  118. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, remove mark_1_ab9642000a9e81712bf7bf3292769536.json +15 -0
  119. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, remove mention_1_aedf9aba96ec8de63204dc0bd079cce0.json +15 -0
  120. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, replace content_1_4032f8de849b4d06146cea086f5faee0.json +15 -0
  121. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, update mention prop_1_37c8ad3a742c0e37960ee3c688ecff05.json +15 -0
  122. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, update text_1_34b0f8d08eec54b64843fe3f13048db5.json +15 -0
  123. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in target block, add mark (paragraph)_1_15ae85e2a52e28738a9cd2f4585a5e87.json +15 -0
  124. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in target block, add mark (word)_1_49c10b96b8a5342b3afe37277f0b2ec0.json +15 -0
  125. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/translate selection_1_83bf8aa261516bf197d1391294bbcb06.json +15 -0
  126. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/turn paragraphs into list_1_5aa207db4b8600962363d2352bf0b1c4.json +15 -0
  127. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/update block type and content_1_fa30ce9145d3237fa4a0b86a61965fb3.json +15 -0
  128. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/update block type_1_e5c648bb981ba9ce20b93054446c721d.json +15 -0
  129. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/drop mark and link and change text within mark_1_148394a5f5658c93445adc9e68410296.json +15 -0
  130. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/drop mark and link_1_b61d90f1021054f8bcf1258cf9d11fe4.json +15 -0
  131. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/modify nested content_1_6dcc3499f6996bd4b16327d079c23b21.json +15 -0
  132. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/modify parent content_1_efbe6b2b8f77c628de12b4ae99dc6939.json +15 -0
  133. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/plain source block, add mention_1_c3ec555a7988880acc8c448befdc501d.json +15 -0
  134. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/standard update_1_7f328ec2574aff0eba83678fedea486a.json +15 -0
  135. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, remove mark_1_2246a490805512b4459ec130c3f7b028.json +15 -0
  136. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, remove mention_1_089c1b96e5eef0e337d6ae0646f3670d.json +15 -0
  137. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, replace content_1_1b70479170637ef990c696b81982a9ff.json +15 -0
  138. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, update mention prop_1_8fc18a40e2b4ccc90a9be4a3a826572b.json +15 -0
  139. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, update text_1_7187509500683cd511ef79bc79adf45e.json +15 -0
  140. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in target block, add mark (paragraph)_1_263f9c25f7a85f762b255a3778136737.json +15 -0
  141. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in target block, add mark (word)_1_030b36dcdf89ff60ac373c9797f5caa8.json +15 -0
  142. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/translate selection_1_8cfca4c1847085a8a31be1818346738e.json +15 -0
  143. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/turn paragraphs into list_1_2f31610c836b996af773c3856634d5c3.json +15 -0
  144. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/update block type and content_1_6bc68512d0085273aa59c32b20ff22b9.json +15 -0
  145. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/update block type_1_171c87db8855dba2d6bbcd06ae45fbb5.json +15 -0
  146. package/src/api/formats/html-blocks/defaultHTMLPromptBuilder.ts +172 -0
  147. package/src/api/formats/html-blocks/htmlBlocks.test.ts +132 -0
  148. package/src/api/formats/html-blocks/htmlBlocks.ts +74 -0
  149. package/src/api/formats/html-blocks/htmlPromptData.ts +53 -0
  150. package/src/api/formats/html-blocks/tools/getPartialHTML.test.ts +76 -0
  151. package/src/api/formats/html-blocks/tools/getPartialHTML.ts +47 -0
  152. package/src/api/formats/html-blocks/tools/index.ts +112 -0
  153. package/src/api/formats/html-blocks/tools/rebaseTool.ts +56 -0
  154. package/src/api/formats/html-blocks/tools/validate.ts +15 -0
  155. package/src/api/formats/json/__snapshots__/json.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/Add heading (h1) and code block_1_4b13d164d4335cc9e201d217c288f3a0.json +15 -0
  156. package/src/api/formats/json/__snapshots__/json.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add a list (end)_1_2e1b3d58032f40317616d76bf4fea81c.json +15 -0
  157. package/src/api/formats/json/__snapshots__/json.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add a new paragraph (end)_1_4267ae57d44c64aa8b70a89aab67f159.json +15 -0
  158. package/src/api/formats/json/__snapshots__/json.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add a new paragraph (start)_1_9d50ec65e996e7a56294ea29bc698367.json +15 -0
  159. package/src/api/formats/json/__snapshots__/json.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/Add heading (h1) and code block_1_8c55f5cd009ab351956e1b40605abc34.json +15 -0
  160. package/src/api/formats/json/__snapshots__/json.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add a list (end)_1_eabec381f0f6973116f9e49dc86810d4.json +15 -0
  161. package/src/api/formats/json/__snapshots__/json.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add a new paragraph (end)_1_018cc4d3757dfb60819403609f61a74d.json +15 -0
  162. package/src/api/formats/json/__snapshots__/json.test.ts/Add/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add a new paragraph (start)_1_aeee8d53d8e28d27a45229e9f04bfd02.json +15 -0
  163. package/src/api/formats/json/__snapshots__/json.test.ts/Combined/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add and update paragraph_1_46911433377fbe117de27b4ebef430f5.json +15 -0
  164. package/src/api/formats/json/__snapshots__/json.test.ts/Combined/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/add paragraph and update selection_1_caeb25fbcd6743ad509ab18526f09180.json +15 -0
  165. package/src/api/formats/json/__snapshots__/json.test.ts/Combined/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add and update paragraph_1_049c64f71763963c05852957cdcd40bd.json +15 -0
  166. package/src/api/formats/json/__snapshots__/json.test.ts/Combined/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/add paragraph and update selection_1_d7907adc86da5742363bfc4422e490e6.json +15 -0
  167. package/src/api/formats/json/__snapshots__/json.test.ts/Delete/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/delete first block_1_5515f1ecee9bd348f415319f4a843add.json +15 -0
  168. package/src/api/formats/json/__snapshots__/json.test.ts/Delete/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/delete first block_1_7c35b931bd8677fa1920b9e5f8128f4a.json +15 -0
  169. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/clear block formatting_1_25bc98ef490234deedb61e16a00d439e.json +15 -0
  170. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/drop mark and link and change text within mark_1_c94d4dbaf7e20ccafc3a87f8933afd6a.json +15 -0
  171. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/drop mark and link_1_164602425b43f343ccbfb3c2f1509b58.json +15 -0
  172. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/modify nested content_1_60470c62411dbe76f9d1ebb97160e62c.json +15 -0
  173. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/modify parent content_1_603268f548d2c26969d79e4e170bd524.json +15 -0
  174. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/plain source block, add mention_1_dc3adc84764ea9dd8f20a906a4633334.json +15 -0
  175. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/standard update_1_6330ddde52ebd48c1e8914a970ad7849.json +15 -0
  176. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, remove mark_1_aa396a89a86700c7c1531127331c95b9.json +15 -0
  177. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, remove mention_1_e1de4a145c9a98804f8d1fd1ae811da4.json +15 -0
  178. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, replace content_1_ce587e62f1783dd0652ffea5d558fda6.json +15 -0
  179. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, update mention prop_1_c2fb024d9d7218c5051012323c39fa0d.json +15 -0
  180. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in source block, update text_1_e2f62ab4415528c63105a90c35e202f3.json +15 -0
  181. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in target block, add mark (paragraph)_1_fb966bb5f366d489cd267e48a7455c72.json +15 -0
  182. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/styles + ic in target block, add mark (word)_1_10409eb8f8e256c2c07ee05c2558a2a9.json +15 -0
  183. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/translate selection_1_e06a86826098274cfb35046f8f5f67a5.json +15 -0
  184. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/turn paragraphs into list_1_c704dd8060467f285e008fcfa10bd3b9.json +15 -0
  185. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/update block prop and content_1_be4a66aa5ee43a3fd916166e56052ad0.json +15 -0
  186. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/update block prop_1_697c8f64d854e5a824cb735c81d9b7ea.json +15 -0
  187. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/update block type and content_1_6b93af6e60c455fec9f8bde5b44e587d.json +15 -0
  188. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (non-streaming)/update block type_1_fd7ea265becc91c2e55258021a82a016.json +15 -0
  189. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/clear block formatting_1_e9409ed44af8d5b1f3ec7d3b7125386a.json +15 -0
  190. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/drop mark and link and change text within mark_1_35579261c0f297cf664524f0c5e08ff1.json +15 -0
  191. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/drop mark and link_1_d7303b2c5a80c7a016ba6caa2ae7be04.json +15 -0
  192. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/modify nested content_1_55d150e200dccb9c1ac1b325aa8d5a43.json +15 -0
  193. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/modify parent content_1_34fba8f0eb2af6cd8d1af416390d9dc4.json +15 -0
  194. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/plain source block, add mention_1_ae41cefb5832864a8a9b2e67c04c65b4.json +15 -0
  195. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/standard update_1_a7a20bf9510adbbafe889498aa22f0ce.json +15 -0
  196. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, remove mark_1_db2880a42dbde80ff9950f502ef1ab8f.json +15 -0
  197. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, remove mention_1_48523af48bae8448f99a3d4108bb8a55.json +15 -0
  198. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, replace content_1_024c55cd1b3177f362a2d606090ca19a.json +15 -0
  199. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, update mention prop_1_549dd0fe54084e4a98588be963db9361.json +15 -0
  200. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, update text_1_dbf2fb610e354e0daa60de0cbdd77aba.json +15 -0
  201. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in target block, add mark (paragraph)_1_8369c3cd3da93d0e734ed7092c0acf40.json +15 -0
  202. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/styles + ic in target block, add mark (word)_1_7033d19147879fada8c8142ee2be4803.json +15 -0
  203. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/translate selection_1_3f8ef537734ef9b7d2142c49bde8cbdd.json +15 -0
  204. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/turn paragraphs into list_1_f8fd91cad88cfec6db2a906b564d39d3.json +15 -0
  205. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/update block prop and content_1_708c779a29da274a24e34cea53755e3b.json +15 -0
  206. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/update block prop_1_67d9ce65ebaaf76b1dde8492176299fc.json +15 -0
  207. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/update block type and content_1_f9b7241b0cb9e9e098e13a58b47bfa62.json +15 -0
  208. package/src/api/formats/json/__snapshots__/json.test.ts/Update/__msw_snapshots__/openai.chat/gpt-4o-2024-08-06 (streaming)/update block type_1_dbb1b2b807becf642bb03a71e34b8e21.json +15 -0
  209. package/src/api/formats/json/defaultJSONPromptBuilder.ts +100 -0
  210. package/src/api/formats/json/errorHandling.test.ts +94 -0
  211. package/src/api/formats/json/json.test.ts +127 -0
  212. package/src/api/formats/json/json.ts +71 -0
  213. package/src/api/formats/json/jsonPromptData.ts +60 -0
  214. package/src/api/formats/json/tools/index.ts +62 -0
  215. package/src/api/formats/json/tools/jsontools.test.ts +122 -0
  216. package/src/api/formats/json/tools/validate.ts +107 -0
  217. package/src/api/formats/markdown-blocks/defaultMarkdownPromptBuilder.ts +111 -0
  218. package/src/api/formats/markdown-blocks/markdownBlocks.test.ts +138 -0
  219. package/src/api/formats/markdown-blocks/markdownBlocks.ts +71 -0
  220. package/src/api/formats/markdown-blocks/markdownPromptData.ts +51 -0
  221. package/src/api/formats/markdown-blocks/tools/index.ts +82 -0
  222. package/src/api/formats/markdown-blocks/tools/rebaseTool.ts +35 -0
  223. package/src/api/formats/markdown-blocks/tools/validate.ts +15 -0
  224. package/src/api/formats/tests/sharedTestCases.ts +151 -0
  225. package/src/api/formats/tests/validateTestEnvironment.test.ts +81 -0
  226. package/src/api/index.ts +45 -0
  227. package/src/api/promptHelpers/addCursorPosition.ts +34 -0
  228. package/src/api/promptHelpers/convertBlocks.ts +13 -0
  229. package/src/api/promptHelpers/flattenBlocks.ts +13 -0
  230. package/src/api/promptHelpers/index.ts +13 -0
  231. package/src/api/promptHelpers/suffixIds.ts +11 -0
  232. package/src/api/promptHelpers/trimEmptyBlocks.ts +25 -0
  233. package/src/api/schema/JSONSchema.ts +8 -0
  234. package/src/api/schema/__snapshots__/schemaToJSONSchema.test.ts.snap +235 -0
  235. package/src/api/schema/mergeSchema.ts +121 -0
  236. package/src/api/schema/schemaToJSONSchema.test.ts +12 -0
  237. package/src/api/schema/schemaToJSONSchema.ts +306 -0
  238. package/src/blocknoteAIClient/client.ts +75 -0
  239. package/src/components/AIMenu/AIMenu.tsx +142 -0
  240. package/src/components/AIMenu/AIMenuController.tsx +42 -0
  241. package/src/components/AIMenu/BlockPositioner.tsx +75 -0
  242. package/src/components/AIMenu/PromptSuggestionMenu.tsx +131 -0
  243. package/src/components/AIMenu/getDefaultAIMenuItems.tsx +288 -0
  244. package/src/components/FormattingToolbar/AIToolbarButton.tsx +45 -0
  245. package/src/components/SuggestionMenu/getAISlashMenuItems.tsx +47 -0
  246. package/src/i18n/dictionary.ts +11 -0
  247. package/src/i18n/locales/ar.ts +73 -0
  248. package/src/i18n/locales/de.ts +73 -0
  249. package/src/i18n/locales/en.ts +71 -0
  250. package/src/i18n/locales/es.ts +73 -0
  251. package/src/i18n/locales/fr.ts +73 -0
  252. package/src/i18n/locales/hr.ts +73 -0
  253. package/src/i18n/locales/index.ts +20 -0
  254. package/src/i18n/locales/is.ts +73 -0
  255. package/src/i18n/locales/it.ts +73 -0
  256. package/src/i18n/locales/ja.ts +73 -0
  257. package/src/i18n/locales/ko.ts +73 -0
  258. package/src/i18n/locales/nl.ts +73 -0
  259. package/src/i18n/locales/no.ts +73 -0
  260. package/src/i18n/locales/pl.ts +73 -0
  261. package/src/i18n/locales/pt.ts +73 -0
  262. package/src/i18n/locales/ru.ts +73 -0
  263. package/src/i18n/locales/sk.ts +73 -0
  264. package/src/i18n/locales/uk.ts +73 -0
  265. package/src/i18n/locales/vi.ts +73 -0
  266. package/src/i18n/locales/zh-tw.ts +73 -0
  267. package/src/i18n/locales/zh.ts +73 -0
  268. package/src/i18n/useAIDictionary.ts +8 -0
  269. package/src/index.ts +15 -0
  270. package/src/locales.ts +1 -0
  271. package/src/plugins/AgentCursorPlugin.ts +101 -0
  272. package/src/prosemirror/__snapshots__/agent.test.ts.snap +702 -0
  273. package/src/prosemirror/__snapshots__/changeset.test.ts.snap +1047 -0
  274. package/src/prosemirror/__snapshots__/rebaseTool.test.ts.snap +154 -0
  275. package/src/prosemirror/agent.test.ts +271 -0
  276. package/src/prosemirror/agent.ts +311 -0
  277. package/src/prosemirror/changeset.test.ts +95 -0
  278. package/src/prosemirror/changeset.ts +340 -0
  279. package/src/prosemirror/fragmentUtil.test.ts +85 -0
  280. package/src/prosemirror/fragmentUtil.ts +20 -0
  281. package/src/prosemirror/rebaseTool.test.ts +96 -0
  282. package/src/prosemirror/rebaseTool.ts +79 -0
  283. package/src/streamTool/README.md +12 -0
  284. package/src/streamTool/asTool.ts +44 -0
  285. package/src/streamTool/callLLMWithStreamTools.ts +352 -0
  286. package/src/streamTool/filterNewOrUpdatedOperations.test.ts +158 -0
  287. package/src/streamTool/filterNewOrUpdatedOperations.ts +64 -0
  288. package/src/streamTool/filterValidOperations.test.ts +104 -0
  289. package/src/streamTool/filterValidOperations.ts +47 -0
  290. package/src/streamTool/jsonSchema.ts +78 -0
  291. package/src/streamTool/preprocess.test.ts +207 -0
  292. package/src/streamTool/preprocess.ts +73 -0
  293. package/src/streamTool/streamTool.ts +94 -0
  294. package/src/streamTool/toValidatedOperations.test.ts +98 -0
  295. package/src/streamTool/toValidatedOperations.ts +49 -0
  296. package/src/style.css +33 -0
  297. package/src/testUtil/cases/addOperationTestCases.ts +89 -0
  298. package/src/testUtil/cases/combinedOperationsTestCases.ts +59 -0
  299. package/src/testUtil/cases/deleteOperationTestCases.ts +16 -0
  300. package/src/testUtil/cases/editors/blockFormatting.ts +33 -0
  301. package/src/testUtil/cases/editors/formattingAndMentions.ts +83 -0
  302. package/src/testUtil/cases/editors/simpleEditor.ts +56 -0
  303. package/src/testUtil/cases/editors/tables.ts +49 -0
  304. package/src/testUtil/cases/index.ts +110 -0
  305. package/src/testUtil/cases/schemas/mention.ts +34 -0
  306. package/src/testUtil/cases/updateOperationTestCases.ts +832 -0
  307. package/src/testUtil/suggestChangesTestUtil.ts +13 -0
  308. package/src/testUtil/testAIModels.ts +30 -0
  309. package/src/util/emptyBlock.ts +8 -0
  310. package/src/util/stream.ts +66 -0
  311. package/src/util/trimArray.ts +26 -0
  312. package/types/src/AIExtension.d.ts +127 -0
  313. package/types/src/api/LLMRequest.d.ts +116 -0
  314. package/types/src/api/LLMResponse.d.ts +51 -0
  315. package/types/src/api/formats/PromptBuilder.d.ts +31 -0
  316. package/types/src/api/formats/base-tools/createAddBlocksTool.d.ts +60 -0
  317. package/types/src/api/formats/base-tools/createUpdateBlockTool.d.ts +63 -0
  318. package/types/src/api/formats/base-tools/delete.d.ts +13 -0
  319. package/types/src/api/formats/base-tools/util/validateBlockArray.d.ts +3 -0
  320. package/types/src/api/formats/html-blocks/defaultHTMLPromptBuilder.d.ts +2 -0
  321. package/types/src/api/formats/html-blocks/htmlBlocks.d.ts +33 -0
  322. package/types/src/api/formats/html-blocks/htmlBlocks.test.d.ts +1 -0
  323. package/types/src/api/formats/html-blocks/htmlPromptData.d.ts +22 -0
  324. package/types/src/api/formats/html-blocks/tools/getPartialHTML.d.ts +14 -0
  325. package/types/src/api/formats/html-blocks/tools/getPartialHTML.test.d.ts +1 -0
  326. package/types/src/api/formats/html-blocks/tools/index.d.ts +23 -0
  327. package/types/src/api/formats/html-blocks/tools/rebaseTool.d.ts +7 -0
  328. package/types/src/api/formats/html-blocks/tools/validate.d.ts +2 -0
  329. package/types/src/api/formats/json/defaultJSONPromptBuilder.d.ts +2 -0
  330. package/types/src/api/formats/json/errorHandling.test.d.ts +1 -0
  331. package/types/src/api/formats/json/json.d.ts +33 -0
  332. package/types/src/api/formats/json/json.test.d.ts +1 -0
  333. package/types/src/api/formats/json/jsonPromptData.d.ts +34 -0
  334. package/types/src/api/formats/json/tools/index.d.ts +23 -0
  335. package/types/src/api/formats/json/tools/jsontools.test.d.ts +1 -0
  336. package/types/src/api/formats/json/tools/validate.d.ts +3 -0
  337. package/types/src/api/formats/markdown-blocks/defaultMarkdownPromptBuilder.d.ts +2 -0
  338. package/types/src/api/formats/markdown-blocks/markdownBlocks.d.ts +33 -0
  339. package/types/src/api/formats/markdown-blocks/markdownBlocks.test.d.ts +1 -0
  340. package/types/src/api/formats/markdown-blocks/markdownPromptData.d.ts +22 -0
  341. package/types/src/api/formats/markdown-blocks/tools/index.d.ts +23 -0
  342. package/types/src/api/formats/markdown-blocks/tools/rebaseTool.d.ts +8 -0
  343. package/types/src/api/formats/markdown-blocks/tools/validate.d.ts +2 -0
  344. package/types/src/api/formats/tests/sharedTestCases.d.ts +10 -0
  345. package/types/src/api/formats/tests/validateTestEnvironment.test.d.ts +1 -0
  346. package/types/src/api/index.d.ts +75 -0
  347. package/types/src/api/promptHelpers/addCursorPosition.d.ts +12 -0
  348. package/types/src/api/promptHelpers/convertBlocks.d.ts +5 -0
  349. package/types/src/api/promptHelpers/flattenBlocks.d.ts +2 -0
  350. package/types/src/api/promptHelpers/index.d.ts +12 -0
  351. package/types/src/api/promptHelpers/suffixIds.d.ts +1 -0
  352. package/types/src/api/promptHelpers/trimEmptyBlocks.d.ts +5 -0
  353. package/types/src/api/schema/JSONSchema.d.ts +8 -0
  354. package/types/src/api/schema/mergeSchema.d.ts +7 -0
  355. package/types/src/api/schema/schemaToJSONSchema.d.ts +80 -0
  356. package/types/src/api/schema/schemaToJSONSchema.test.d.ts +1 -0
  357. package/types/src/blocknoteAIClient/client.d.ts +38 -0
  358. package/types/src/components/AIMenu/AIMenu.d.ts +7 -0
  359. package/types/src/components/AIMenu/AIMenuController.d.ts +5 -0
  360. package/types/src/components/AIMenu/BlockPositioner.d.ts +7 -0
  361. package/types/src/components/AIMenu/PromptSuggestionMenu.d.ts +13 -0
  362. package/types/src/components/AIMenu/getDefaultAIMenuItems.d.ts +7 -0
  363. package/types/src/components/FormattingToolbar/AIToolbarButton.d.ts +1 -0
  364. package/types/src/components/SuggestionMenu/getAISlashMenuItems.d.ts +6 -0
  365. package/types/src/i18n/dictionary.d.ts +4 -0
  366. package/types/src/i18n/locales/ar.d.ts +2 -0
  367. package/types/src/i18n/locales/de.d.ts +2 -0
  368. package/types/src/i18n/locales/en.d.ts +77 -0
  369. package/types/src/i18n/locales/es.d.ts +2 -0
  370. package/types/src/i18n/locales/fr.d.ts +2 -0
  371. package/types/src/i18n/locales/hr.d.ts +2 -0
  372. package/types/src/i18n/locales/index.d.ts +20 -0
  373. package/types/src/i18n/locales/is.d.ts +2 -0
  374. package/types/src/i18n/locales/it.d.ts +2 -0
  375. package/types/src/i18n/locales/ja.d.ts +2 -0
  376. package/types/src/i18n/locales/ko.d.ts +2 -0
  377. package/types/src/i18n/locales/nl.d.ts +2 -0
  378. package/types/src/i18n/locales/no.d.ts +2 -0
  379. package/types/src/i18n/locales/pl.d.ts +2 -0
  380. package/types/src/i18n/locales/pt.d.ts +2 -0
  381. package/types/src/i18n/locales/ru.d.ts +2 -0
  382. package/types/src/i18n/locales/sk.d.ts +2 -0
  383. package/types/src/i18n/locales/uk.d.ts +2 -0
  384. package/types/src/i18n/locales/vi.d.ts +2 -0
  385. package/types/src/i18n/locales/zh-tw.d.ts +2 -0
  386. package/types/src/i18n/locales/zh.d.ts +2 -0
  387. package/types/src/i18n/useAIDictionary.d.ts +77 -0
  388. package/types/src/index.d.ts +12 -0
  389. package/types/src/locales.d.ts +1 -0
  390. package/types/src/plugins/AgentCursorPlugin.d.ts +15 -0
  391. package/types/src/prosemirror/agent.d.ts +20 -0
  392. package/types/src/prosemirror/agent.test.d.ts +1 -0
  393. package/types/src/prosemirror/changeset.d.ts +19 -0
  394. package/types/src/prosemirror/changeset.test.d.ts +1 -0
  395. package/types/src/prosemirror/fragmentUtil.d.ts +5 -0
  396. package/types/src/prosemirror/fragmentUtil.test.d.ts +1 -0
  397. package/types/src/prosemirror/rebaseTool.d.ts +36 -0
  398. package/types/src/prosemirror/rebaseTool.test.d.ts +1 -0
  399. package/types/src/streamTool/asTool.d.ts +15 -0
  400. package/types/src/streamTool/callLLMWithStreamTools.d.ts +74 -0
  401. package/types/src/streamTool/filterNewOrUpdatedOperations.d.ts +20 -0
  402. package/types/src/streamTool/filterNewOrUpdatedOperations.test.d.ts +1 -0
  403. package/types/src/streamTool/filterValidOperations.d.ts +21 -0
  404. package/types/src/streamTool/filterValidOperations.test.d.ts +1 -0
  405. package/types/src/streamTool/jsonSchema.d.ts +22 -0
  406. package/types/src/streamTool/preprocess.d.ts +22 -0
  407. package/types/src/streamTool/preprocess.test.d.ts +1 -0
  408. package/types/src/streamTool/streamTool.d.ts +80 -0
  409. package/types/src/streamTool/toValidatedOperations.d.ts +17 -0
  410. package/types/src/streamTool/toValidatedOperations.test.d.ts +1 -0
  411. package/types/src/testUtil/cases/addOperationTestCases.d.ts +2 -0
  412. package/types/src/testUtil/cases/combinedOperationsTestCases.d.ts +2 -0
  413. package/types/src/testUtil/cases/deleteOperationTestCases.d.ts +2 -0
  414. package/types/src/testUtil/cases/editors/blockFormatting.d.ts +553 -0
  415. package/types/src/testUtil/cases/editors/formattingAndMentions.d.ts +553 -0
  416. package/types/src/testUtil/cases/editors/simpleEditor.d.ts +1105 -0
  417. package/types/src/testUtil/cases/editors/tables.d.ts +553 -0
  418. package/types/src/testUtil/cases/index.d.ts +45 -0
  419. package/types/src/testUtil/cases/schemas/mention.d.ts +562 -0
  420. package/types/src/testUtil/cases/updateOperationTestCases.d.ts +6 -0
  421. package/types/src/testUtil/suggestChangesTestUtil.d.ts +3 -0
  422. package/types/src/testUtil/testAIModels.d.ts +5 -0
  423. package/types/src/util/emptyBlock.d.ts +2 -0
  424. package/types/src/util/stream.d.ts +16 -0
  425. package/types/src/util/trimArray.d.ts +1 -0
@@ -0,0 +1,2918 @@
1
+ var et = Object.defineProperty;
2
+ var tt = (e, t, o) => t in e ? et(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
+ var j = (e, t, o) => tt(e, typeof t != "symbol" ? t + "" : t, o);
4
+ import { getPmSchema as ot, UnreachableCaseError as Pe, getNodeById as rt, updateBlockTr as nt, insertBlocks as st, trackPosition as se, removeAndInsertBlocks as it, getBlock as Oe, defaultProps as Me, isStyledTextInlineContent as at, isLinkInlineContent as ct, BlockNoteExtension as lt, filterSuggestionItems as ut, mergeCSSClasses as dt } from "@blocknote/core";
5
+ import { applySuggestions as Be, suggestChanges as ft, revertSuggestions as ie } from "@blocknote/prosemirror-suggest-changes";
6
+ import { jsonSchema as Le, streamObject as pt, generateObject as mt, APICallError as ht, RetryError as yt } from "ai";
7
+ import { TextSelection as gt, Plugin as xe, PluginKey as _e } from "prosemirror-state";
8
+ import { fixTablesKey as kt } from "prosemirror-tables";
9
+ import bt from "lodash.isequal";
10
+ import { Slice as Y, Fragment as ae } from "prosemirror-model";
11
+ import { Transform as N, Mapping as Ie, ReplaceStep as x, ReplaceAroundStep as St } from "prosemirror-transform";
12
+ import { ChangeSet as ce, simplifyChanges as wt } from "prosemirror-changeset";
13
+ import { DecorationSet as le, Decoration as ue } from "prosemirror-view";
14
+ import { defaultSelectionBuilder as Tt } from "y-prosemirror";
15
+ import { jsxs as vt, jsx as y } from "react/jsx-runtime";
16
+ import { useBlockNoteContext as Ct, useComponentsContext as G, useSuggestionMenuKeyboardHandler as Pt, useBlockNoteEditor as K, useUIElementPositioning as Ot } from "@blocknote/react";
17
+ import B, { useState as Ee, useCallback as $, useMemo as I, useEffect as Ne } from "react";
18
+ import { useStore as Ae } from "zustand";
19
+ import { offset as Mt, size as Bt, autoUpdate as Lt } from "@floating-ui/react";
20
+ const de = (e) => {
21
+ let t;
22
+ const o = /* @__PURE__ */ new Set(), r = (u, p) => {
23
+ const l = typeof u == "function" ? u(t) : u;
24
+ if (!Object.is(l, t)) {
25
+ const m = t;
26
+ t = p ?? (typeof l != "object" || l === null) ? l : Object.assign({}, t, l), o.forEach((f) => f(t, m));
27
+ }
28
+ }, n = () => t, s = { setState: r, getState: n, getInitialState: () => c, subscribe: (u) => (o.add(u), () => o.delete(u)) }, c = t = e(r, n, s);
29
+ return s;
30
+ }, fe = (e) => e ? de(e) : de;
31
+ function xt(e) {
32
+ const { properties: t, required: o, $defs: r, ...n } = e.parameters;
33
+ return {
34
+ schema: {
35
+ type: "object",
36
+ description: e.description,
37
+ properties: {
38
+ type: {
39
+ type: "string",
40
+ enum: [e.name]
41
+ },
42
+ ...t
43
+ },
44
+ required: ["type", ...o ?? []],
45
+ additionalProperties: !1,
46
+ ...n
47
+ },
48
+ $defs: r
49
+ };
50
+ }
51
+ function je(e) {
52
+ const t = e.map((r) => xt(r)), o = {};
53
+ for (const r of t)
54
+ for (const n in r.$defs) {
55
+ if (o[n] && !bt(o[n], r.$defs[n]))
56
+ throw new Error(`Duplicate, but different definition for ${n}`);
57
+ o[n] = r.$defs[n];
58
+ }
59
+ return {
60
+ type: "object",
61
+ properties: {
62
+ operations: {
63
+ type: "array",
64
+ items: {
65
+ anyOf: t.map((r) => r.schema)
66
+ }
67
+ }
68
+ },
69
+ additionalProperties: !1,
70
+ required: ["operations"],
71
+ $defs: Object.keys(o).length > 0 ? o : void 0
72
+ };
73
+ }
74
+ function _t(e) {
75
+ return new ReadableStream({
76
+ async start(t) {
77
+ try {
78
+ for await (const o of e)
79
+ t.enqueue(o);
80
+ t.close();
81
+ } catch (o) {
82
+ t.error(o);
83
+ }
84
+ }
85
+ });
86
+ }
87
+ function E(e) {
88
+ if (e.locked)
89
+ throw new Error(
90
+ "Stream (source) is already locked and cannot be iterated."
91
+ );
92
+ const t = e.pipeThrough(new TransformStream());
93
+ return t[Symbol.asyncIterator] = () => {
94
+ if (t.locked)
95
+ throw new Error("Stream is already locked and cannot be iterated again.");
96
+ const o = t.getReader();
97
+ return {
98
+ async next() {
99
+ const { done: r, value: n } = await o.read();
100
+ return r ? { done: !0, value: void 0 } : { done: !1, value: n };
101
+ }
102
+ };
103
+ }, t;
104
+ }
105
+ function $e(e) {
106
+ return E(_t(e));
107
+ }
108
+ async function* It(e) {
109
+ var n;
110
+ let t = 0, o = !0, r;
111
+ for await (const i of e)
112
+ if ((n = i.operations) != null && n.length) {
113
+ for (let a = t; a < i.operations.length; a++) {
114
+ const s = i.operations[a];
115
+ r = s, yield {
116
+ partialOperation: s,
117
+ isUpdateToPreviousOperation: a === t && !o,
118
+ isPossiblyPartial: a === i.operations.length - 1
119
+ }, o = !1;
120
+ }
121
+ t = i.operations.length - 1;
122
+ }
123
+ if (!r)
124
+ throw new Error("No operations seen");
125
+ yield {
126
+ partialOperation: r,
127
+ isUpdateToPreviousOperation: !0,
128
+ isPossiblyPartial: !1
129
+ };
130
+ }
131
+ async function* De(e, t) {
132
+ let o = !1;
133
+ for await (const r of e) {
134
+ const n = r.operation;
135
+ n.ok ? (yield {
136
+ operation: n.value,
137
+ isUpdateToPreviousOperation: o ? !1 : r.isUpdateToPreviousOperation,
138
+ isPossiblyPartial: r.isPossiblyPartial
139
+ }, o = !1) : (o = o || !r.isUpdateToPreviousOperation, t == null || t({
140
+ ...r,
141
+ operation: n
142
+ }));
143
+ }
144
+ }
145
+ async function* Re(e, t) {
146
+ for await (const o of e) {
147
+ const r = t.find(
148
+ (i) => i.name === o.partialOperation.type
149
+ );
150
+ if (!r) {
151
+ yield {
152
+ operation: {
153
+ ok: !1,
154
+ error: `No matching function for ${o.partialOperation.type}`
155
+ },
156
+ isUpdateToPreviousOperation: o.isUpdateToPreviousOperation,
157
+ isPossiblyPartial: o.isPossiblyPartial
158
+ };
159
+ continue;
160
+ }
161
+ yield {
162
+ operation: r.validate(o.partialOperation),
163
+ isUpdateToPreviousOperation: o.isUpdateToPreviousOperation,
164
+ isPossiblyPartial: o.isPossiblyPartial
165
+ };
166
+ }
167
+ }
168
+ async function* Et(e, t) {
169
+ const o = Re(
170
+ e,
171
+ t
172
+ );
173
+ yield* De(
174
+ o,
175
+ (n) => {
176
+ if (!n.isPossiblyPartial)
177
+ throw new Error("invalid operation: " + n.operation.error);
178
+ }
179
+ );
180
+ }
181
+ async function* Nt(e, t) {
182
+ const o = Re(
183
+ e,
184
+ t
185
+ );
186
+ yield* De(
187
+ o,
188
+ (n) => {
189
+ throw new Error("invalid operation: " + n.operation.error);
190
+ }
191
+ );
192
+ }
193
+ async function At(e, t) {
194
+ const { _generateObjectOptions: o, ...r } = t;
195
+ if (o && ("output" in o || "schema" in o))
196
+ throw new Error(
197
+ "Cannot provide output or schema in _generateObjectOptions"
198
+ );
199
+ const i = {
200
+ // non-overridable options for streamObject
201
+ output: "object",
202
+ schema: Le(je(e)),
203
+ // configurable options for streamObject
204
+ // - optional, with defaults
205
+ // mistral somehow needs "auto", while groq/llama needs "tool"
206
+ // TODO: further research this and / or make configurable
207
+ // for now stick to "tool" by default as this has been tested mostly
208
+ mode: r.model.provider === "mistral.chat" ? "auto" : "tool",
209
+ // - mandatory ones:
210
+ ...r,
211
+ // extra options for streamObject
212
+ ...o ?? {}
213
+ }, a = await mt(i), s = jt(a.object);
214
+ if (!s.ok)
215
+ throw new Error(s.error);
216
+ let c;
217
+ return {
218
+ streamObjectResult: void 0,
219
+ generateObjectResult: a,
220
+ get operationsSource() {
221
+ return c || (c = $e(
222
+ Nt(s.value, e)
223
+ )), c;
224
+ },
225
+ async getGeneratedOperations() {
226
+ return a.object;
227
+ }
228
+ };
229
+ }
230
+ function jt(e) {
231
+ if (!e || typeof e != "object" || !("operations" in e) || !Array.isArray(e.operations))
232
+ return {
233
+ ok: !1,
234
+ error: "No operations returned"
235
+ };
236
+ const t = e.operations;
237
+ async function* o() {
238
+ for (const r of t)
239
+ yield {
240
+ partialOperation: r,
241
+ isUpdateToPreviousOperation: !1,
242
+ isPossiblyPartial: !1
243
+ };
244
+ }
245
+ return {
246
+ ok: !0,
247
+ value: o()
248
+ };
249
+ }
250
+ async function $t(e, t, o = () => {
251
+ }) {
252
+ const { _streamObjectOptions: r, ...n } = t;
253
+ if (r && ("output" in r || "schema" in r))
254
+ throw new Error("Cannot provide output or schema in _streamObjectOptions");
255
+ const a = {
256
+ // non-overridable options for streamObject
257
+ output: "object",
258
+ schema: Le(je(e)),
259
+ // configurable options for streamObject
260
+ // - optional, with defaults
261
+ // mistral somehow needs "auto", while groq/llama needs "tool"
262
+ // TODO: further research this and / or make configurable
263
+ // for now stick to "tool" by default as this has been tested mostly
264
+ mode: n.model.provider === "mistral.chat" ? "auto" : "tool",
265
+ // - mandatory ones:
266
+ ...n,
267
+ // extra options for streamObject
268
+ ...t._streamObjectOptions ?? {}
269
+ }, s = pt(a);
270
+ let c;
271
+ const [u, p] = s.fullStream.tee(), l = (async () => {
272
+ let m = {
273
+ operations: []
274
+ };
275
+ const f = E(
276
+ Ht(p)
277
+ );
278
+ for await (const h of f)
279
+ h && typeof h == "object" && "operations" in h && (m = h);
280
+ return m;
281
+ })();
282
+ return {
283
+ streamObjectResult: s,
284
+ generateObjectResult: void 0,
285
+ get operationsSource() {
286
+ return c || (c = $e(
287
+ Et(
288
+ It(
289
+ Dt(
290
+ Rt(
291
+ E(u)
292
+ ),
293
+ o
294
+ )
295
+ ),
296
+ e
297
+ )
298
+ )), c;
299
+ },
300
+ async getGeneratedOperations() {
301
+ return l;
302
+ }
303
+ };
304
+ }
305
+ async function* Dt(e, t) {
306
+ let o = !0;
307
+ for await (const r of e)
308
+ o && (t(), o = !1), yield r;
309
+ }
310
+ function Rt(e) {
311
+ return E(
312
+ e.pipeThrough(
313
+ new TransformStream({
314
+ transform(t, o) {
315
+ switch (t.type) {
316
+ case "object":
317
+ o.enqueue(t.object);
318
+ break;
319
+ case "text-delta":
320
+ case "finish":
321
+ break;
322
+ case "error":
323
+ o.error(t.error);
324
+ break;
325
+ default: {
326
+ const r = t;
327
+ throw new Error(`Unsupported chunk type: ${r}`);
328
+ }
329
+ }
330
+ }
331
+ })
332
+ )
333
+ );
334
+ }
335
+ function Ht(e) {
336
+ return E(
337
+ e.pipeThrough(
338
+ new TransformStream({
339
+ transform(t, o) {
340
+ switch (t.type) {
341
+ case "object":
342
+ o.enqueue(t.object);
343
+ break;
344
+ case "text-delta":
345
+ case "finish":
346
+ break;
347
+ case "error":
348
+ break;
349
+ default: {
350
+ const r = t;
351
+ throw new Error(`Unsupported chunk type: ${r}`);
352
+ }
353
+ }
354
+ }
355
+ })
356
+ )
357
+ );
358
+ }
359
+ function X(e) {
360
+ return (e.type === "paragraph" || !e.type) && !e.content || Array.isArray(e.content) && e.content.length === 0;
361
+ }
362
+ class qt {
363
+ /**
364
+ * @internal
365
+ */
366
+ constructor(t, o, r) {
367
+ this.messages = t, this.llmResult = o, this.streamTools = r;
368
+ }
369
+ /**
370
+ * Apply the operations to the editor and return a stream of results.
371
+ *
372
+ * (this method consumes underlying streams in `llmResult`)
373
+ */
374
+ async *applyToolCalls() {
375
+ let t = this.llmResult.operationsSource;
376
+ for (const o of this.streamTools)
377
+ t = o.execute(t);
378
+ yield* t;
379
+ }
380
+ /**
381
+ * Helper method to apply all operations to the editor if you're not interested in intermediate operations and results.
382
+ *
383
+ * (this method consumes underlying streams in `llmResult`)
384
+ */
385
+ async execute() {
386
+ for await (const t of this.applyToolCalls())
387
+ ;
388
+ }
389
+ /**
390
+ * @internal
391
+ */
392
+ async _logToolCalls() {
393
+ for await (const t of this.llmResult.operationsSource)
394
+ console.log(JSON.stringify(t, null, 2));
395
+ }
396
+ }
397
+ function U(e, t) {
398
+ const o = e.getTextCursorPosition(), r = [];
399
+ for (const n of t) {
400
+ const i = n.id === o.block.id;
401
+ r.push({
402
+ id: n.id,
403
+ block: n.block
404
+ }), i && r.push({
405
+ cursor: !0
406
+ });
407
+ }
408
+ return r;
409
+ }
410
+ async function C(e, t) {
411
+ return await Promise.all(e.map(async (o) => ({
412
+ id: o.id,
413
+ block: await t(o)
414
+ })));
415
+ }
416
+ function T(e) {
417
+ return e.flatMap((t) => [
418
+ {
419
+ ...t,
420
+ children: []
421
+ },
422
+ ...T(t.children)
423
+ ]);
424
+ }
425
+ function L(e) {
426
+ return e.map((t) => typeof t == "object" && t && "id" in t ? {
427
+ ...t,
428
+ id: `${t.id}$`
429
+ } : t);
430
+ }
431
+ function zt(e, t, o = !0, r = !0) {
432
+ let n = 0, i = e.length;
433
+ if (o)
434
+ for (; n < i && t(e[n]); )
435
+ n++;
436
+ if (r)
437
+ for (; i > n && t(e[i - 1]); )
438
+ i--;
439
+ return e.slice(n, i);
440
+ }
441
+ function F(e, t) {
442
+ return zt(
443
+ e,
444
+ (r) => X(r),
445
+ (t == null ? void 0 : t.trimStart) ?? !1,
446
+ (t == null ? void 0 : t.trimEnd) ?? !0
447
+ );
448
+ }
449
+ async function He(e, t) {
450
+ const o = F(e.document), r = await C(
451
+ T(o),
452
+ async (s) => e.blocksToHTMLLossy([s])
453
+ ), i = U(e, r).filter(
454
+ (s) => "cursor" in s || !(t.excludeBlockIds || []).includes(s.id)
455
+ );
456
+ return {
457
+ htmlBlocks: L(i)
458
+ };
459
+ }
460
+ async function qe(e, t) {
461
+ const o = await C(
462
+ T(t.selectedBlocks),
463
+ async (n) => e.blocksToHTMLLossy([n])
464
+ );
465
+ return {
466
+ htmlSelectedBlocks: L(o),
467
+ htmlDocument: (await C(T(e.document), async (n) => e.blocksToHTMLLossy([n]))).map(({ block: n }) => ({ block: n }))
468
+ // strip ids so LLM can't accidentally issue updates to ids not in selection
469
+ };
470
+ }
471
+ function Ut(e) {
472
+ return [
473
+ {
474
+ role: "system",
475
+ content: "You're manipulating a selected part of a text document using HTML blocks. \n Make sure to follow the json schema provided and always include the trailing $ in ids. \n List items are 1 block with 1 list item each, so block content `<ul><li>item1</li></ul>` is valid, but `<ul><li>item1</li><li>item2</li></ul>` is invalid. We'll merge them automatically.\n This is the selection as an array of html blocks:"
476
+ },
477
+ {
478
+ role: "system",
479
+ content: JSON.stringify(e.htmlSelectedBlocks)
480
+ },
481
+ {
482
+ role: "system",
483
+ content: "This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"
484
+ },
485
+ {
486
+ role: "system",
487
+ content: JSON.stringify(e.htmlDocument)
488
+ },
489
+ {
490
+ role: "system",
491
+ content: "The user asks you to do the following:"
492
+ },
493
+ {
494
+ role: "user",
495
+ content: e.userPrompt
496
+ }
497
+ ];
498
+ }
499
+ function Ft(e) {
500
+ return [
501
+ {
502
+ role: "system",
503
+ content: "You're manipulating a text document using HTML blocks. \n Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $). \n List items are 1 block with 1 list item each, so block content `<ul><li>item1</li></ul>` is valid, but `<ul><li>item1</li><li>item2</li></ul>` is invalid. We'll merge them automatically.\n For code blocks, you can use the `data-language` attribute on a code block to specify the language.\n This is the document as an array of html blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):"
504
+ },
505
+ {
506
+ role: "system",
507
+ content: JSON.stringify(e.htmlBlocks)
508
+ },
509
+ {
510
+ role: "system",
511
+ content: "The user asks you to do the following:"
512
+ },
513
+ {
514
+ role: "user",
515
+ content: e.userPrompt
516
+ },
517
+ {
518
+ role: "system",
519
+ content: 'First, determine what part of the document the user is talking about. You SHOULD probably take cursor info into account if needed.\n EXAMPLE: if user says "below" (without pointing to a specific part of the document) he / she probably indicates the block(s) after the cursor. \n EXAMPLE: If you want to insert content AT the cursor position (UNLESS indicated otherwise by the user), then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`).\n \n Prefer updating existing blocks over removing and adding (but this also depends on the user\'s question).'
520
+ }
521
+ ];
522
+ }
523
+ const Jt = async (e, t) => {
524
+ if (t.selectedBlocks) {
525
+ const o = await qe(e, {
526
+ selectedBlocks: t.selectedBlocks
527
+ });
528
+ return t.previousMessages ? [
529
+ ...t.previousMessages,
530
+ {
531
+ role: "system",
532
+ content: `After processing the previous response, this is the updated selection.
533
+ Ignore previous documents, you MUST issue operations against this latest version of the document:`
534
+ },
535
+ {
536
+ role: "system",
537
+ content: JSON.stringify(o.htmlSelectedBlocks)
538
+ },
539
+ {
540
+ role: "system",
541
+ content: "This is the updated entire document:"
542
+ },
543
+ {
544
+ role: "system",
545
+ content: JSON.stringify(o.htmlDocument)
546
+ },
547
+ {
548
+ role: "system",
549
+ content: `You SHOULD use "update" operations to update blocks you added / edited previously
550
+ (unless the user explicitly asks you otherwise to add or delete other blocks).
551
+
552
+ The user now asks you to do the following:`
553
+ },
554
+ {
555
+ role: "user",
556
+ content: t.userPrompt
557
+ }
558
+ ] : Ut({
559
+ ...o,
560
+ userPrompt: t.userPrompt
561
+ });
562
+ } else {
563
+ const o = await He(e, t);
564
+ return t.previousMessages ? [
565
+ ...t.previousMessages,
566
+ {
567
+ role: "system",
568
+ content: `After processing the previous response, this is the updated document.
569
+ Ignore previous documents, you MUST issue operations against this latest version of the document:`
570
+ },
571
+ {
572
+ role: "system",
573
+ content: JSON.stringify(o.htmlBlocks)
574
+ },
575
+ {
576
+ role: "system",
577
+ content: `You SHOULD use "update" operations to update blocks you added / edited previously
578
+ (unless the user explicitly asks you otherwise to add or delete other blocks).
579
+
580
+ The user now asks you to do the following:`
581
+ },
582
+ {
583
+ role: "user",
584
+ content: t.userPrompt
585
+ }
586
+ ] : Ft({
587
+ ...o,
588
+ userPrompt: t.userPrompt
589
+ });
590
+ }
591
+ };
592
+ function Vt(e) {
593
+ let t, o = !1;
594
+ return e.descendants((r, n) => o ? !1 : (r.isText && (o = !0, t = n), !0)), t;
595
+ }
596
+ function D(e) {
597
+ var i;
598
+ const t = ot(e), { modification: o } = t.marks, r = [], n = new N(e.before);
599
+ for (let a = 0; a < e.steps.length; a++) {
600
+ const s = e.steps[a], c = new Ie(e.mapping.maps.slice(0, a)).invert();
601
+ if (s.structure) {
602
+ if (s instanceof x) {
603
+ if (s.to !== s.from + 1 || s.slice.openStart !== 0 || s.slice.openEnd !== 1 || s.slice.content.size !== 2)
604
+ throw new Error(
605
+ "Structure change is not in expected format (ReplaceStep)"
606
+ );
607
+ } else if (s instanceof St) {
608
+ if (s.insert !== 1 || s.slice.size !== 2 || s.gapTo !== s.to - 1 || s.gapFrom !== s.from + 1)
609
+ throw new Error(
610
+ "Structure change is not in expected format (ReplaceAroundStep)"
611
+ );
612
+ } else
613
+ throw new Error("Step is not a ReplaceStep or ReplaceAroundStep");
614
+ const b = c.map(s.from), g = s.slice.content.firstChild, k = n.doc.resolve(n.mapping.map(b)).nodeAfter;
615
+ let w = g.marks || [];
616
+ g.type !== k.type && (w = o.create({
617
+ type: "nodeType",
618
+ previousValue: k.type.name,
619
+ newValue: g.type.name
620
+ }).addToSet(w));
621
+ const A = /* @__PURE__ */ new Set([
622
+ ...Object.keys(g.attrs),
623
+ ...Object.keys(k.attrs)
624
+ ]);
625
+ for (const P of A)
626
+ g.attrs[P] !== k.attrs[P] && (w = o.create({
627
+ type: "attr",
628
+ attrName: P,
629
+ previousValue: k.attrs[P],
630
+ newValue: g.attrs[P]
631
+ }).addToSet(w));
632
+ const M = n.steps.length;
633
+ n.setNodeMarkup(
634
+ n.mapping.map(b),
635
+ g.type,
636
+ g.attrs,
637
+ w
638
+ ), r.push({
639
+ prosemirrorSteps: n.steps.slice(M),
640
+ selection: void 0,
641
+ type: "replace"
642
+ });
643
+ continue;
644
+ }
645
+ if (!(s instanceof x))
646
+ throw new Error("Step is not a ReplaceStep");
647
+ const u = c.map(s.from), p = c.map(s.to);
648
+ if (s.slice.openStart > 0 || s.slice.openEnd > 0)
649
+ throw new Error(
650
+ "Slice has openStart or openEnd > 0, but structure=false"
651
+ );
652
+ r.push({
653
+ prosemirrorSteps: [],
654
+ selection: {
655
+ anchor: n.mapping.map(u),
656
+ head: n.mapping.map(p)
657
+ },
658
+ type: "select"
659
+ });
660
+ const l = s.slice.content.textBetween(0, s.slice.size), m = l === n.doc.textBetween(n.mapping.map(u), n.mapping.map(p));
661
+ let f;
662
+ if (m)
663
+ f = s.slice.content.size;
664
+ else if (l.length === 0)
665
+ f = s.slice.content.size;
666
+ else {
667
+ const b = Vt(s.slice.content);
668
+ if (b === void 0)
669
+ throw new Error("unexpected: no first character found");
670
+ f = b + 1;
671
+ }
672
+ let h = n.mapping.map(p);
673
+ const d = n.mapping.map(p);
674
+ let S = !0;
675
+ for (let b = f; b <= s.slice.content.size; b++) {
676
+ const g = S && u !== p, k = n.steps.length;
677
+ if (g) {
678
+ const M = n.doc.resolve(n.mapping.map(u));
679
+ (i = M.nodeAfter) != null && i.isBlock && n.addNodeMark(M.pos, t.mark("deletion", {})), n.addMark(M.pos, h, t.mark("deletion", {})), h = n.mapping.map(p);
680
+ }
681
+ const w = new Y(s.slice.content.cut(0, b), 0, 0);
682
+ n.replace(d, h, w).addMark(
683
+ d,
684
+ d + w.content.size,
685
+ t.mark("insertion", {})
686
+ ), n.doc.nodesBetween(
687
+ d,
688
+ d + w.content.size,
689
+ (M, P) => P < d || P > d + w.content.size ? !0 : (M.isBlock && n.addNodeMark(P, t.mark("insertion", {})), !1)
690
+ ), h = n.mapping.slice(k).map(h);
691
+ const A = gt.near(
692
+ n.doc.resolve(d + w.content.size),
693
+ -1
694
+ );
695
+ r.push({
696
+ prosemirrorSteps: n.steps.slice(k),
697
+ selection: {
698
+ anchor: A.from,
699
+ head: A.from
700
+ },
701
+ type: g ? "replace" : "insert"
702
+ // 3. Insert the replacement character by character
703
+ }), S = !1;
704
+ }
705
+ }
706
+ return r;
707
+ }
708
+ async function Q(e) {
709
+ const t = Math.random() * 0.3 + 0.85;
710
+ if (e.type === "select")
711
+ await new Promise((o) => setTimeout(o, 100 * t));
712
+ else if (e.type === "insert")
713
+ await new Promise((o) => setTimeout(o, 10 * t));
714
+ else if (e.type === "replace")
715
+ await new Promise((o) => setTimeout(o, 200 * t));
716
+ else
717
+ throw new Pe(e.type);
718
+ }
719
+ function ee(e, t) {
720
+ e.setMeta("addToHistory", !1), t.selection && e.setMeta("aiAgent", {
721
+ selection: {
722
+ anchor: t.selection.anchor,
723
+ head: t.selection.head
724
+ }
725
+ });
726
+ for (const o of t.prosemirrorSteps)
727
+ if (e.maybeStep(o).failed)
728
+ throw new Error("failed to apply step");
729
+ return e;
730
+ }
731
+ function Zt(e, t, o) {
732
+ const r = new N(t);
733
+ for (const a of e) {
734
+ const s = new x(
735
+ r.mapping.map(a.fromA),
736
+ r.mapping.map(a.toA),
737
+ o.slice(a.fromB, a.toB)
738
+ );
739
+ r.step(s);
740
+ }
741
+ const n = r.mapping.invert();
742
+ let i = r.doc.content.findDiffStart(o.content);
743
+ for (; i !== null; ) {
744
+ const a = o.resolve(i).nodeAfter, s = r.doc.resolve(i).nodeAfter;
745
+ if (!a || !s)
746
+ throw new Error("diffNode not found");
747
+ const c = !a.isLeaf && a.content.eq(s.content), u = c ? 1 : Math.min(a.nodeSize, s.nodeSize), p = i + u, l = n.map(i), m = n.map(p);
748
+ let f = e.length;
749
+ for (let d = 0; d < e.length; d++)
750
+ if (e[d].fromA >= m) {
751
+ f = d;
752
+ break;
753
+ }
754
+ e.splice(f, 0, {
755
+ fromA: l,
756
+ toA: m,
757
+ fromB: i,
758
+ toB: p,
759
+ deleted: [],
760
+ inserted: [],
761
+ type: c ? "node-type-or-attr-update" : "mark-update"
762
+ }), r.step(
763
+ new x(
764
+ i,
765
+ p,
766
+ o.slice(i, p),
767
+ c
768
+ )
769
+ );
770
+ const h = r.doc.content.findDiffStart(o.content);
771
+ if (h === i)
772
+ throw new Error("diffStart not moving");
773
+ i = h;
774
+ }
775
+ return e;
776
+ }
777
+ const pe = (e, t) => {
778
+ const o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
779
+ e.descendants((a) => {
780
+ a.type.name === "tableCell" && o.add(JSON.stringify(a.toJSON()));
781
+ }), t.descendants((a) => {
782
+ a.type.name === "tableCell" && r.add(JSON.stringify(a.toJSON()));
783
+ });
784
+ const n = new Set(
785
+ [...o].filter((a) => r.has(a))
786
+ );
787
+ return {
788
+ encodeCharacter: (a) => a,
789
+ encodeNodeStart: (a) => {
790
+ if (a.type.name === "tableCell") {
791
+ const s = JSON.stringify(a.toJSON());
792
+ return n.has(s) ? s : a.type.name;
793
+ }
794
+ return a.type.name;
795
+ },
796
+ encodeNodeEnd: (a) => {
797
+ if (a.type.name === "tableCell") {
798
+ const s = JSON.stringify(a.toJSON());
799
+ return n.has(s) ? s : -1;
800
+ }
801
+ return -1;
802
+ },
803
+ compareTokens: (a, s) => a === s
804
+ };
805
+ };
806
+ function J(e, t, o = !1, r, n) {
807
+ const i = rt(e.id, t), a = new N(t);
808
+ nt(
809
+ a,
810
+ i.posBeforeNode,
811
+ e.block,
812
+ r,
813
+ n
814
+ );
815
+ let s = a.doc, c = ce.create(
816
+ t,
817
+ void 0,
818
+ pe(t, s)
819
+ );
820
+ if (c = c.addSteps(s, a.mapping.maps, 0), o && c.changes.length > 0) {
821
+ const l = c.changes[c.changes.length - 1], m = l.toA - l.fromA, f = l.toB - l.fromB;
822
+ if (m > f) {
823
+ const h = t.slice(
824
+ l.fromA + f,
825
+ l.toA
826
+ );
827
+ a.step(
828
+ new x(l.toB, l.toB, h)
829
+ ), s = a.doc, c = ce.create(
830
+ c.startDoc,
831
+ void 0,
832
+ pe(c.startDoc, s)
833
+ ), c = c.addSteps(s, a.mapping.maps, 0);
834
+ }
835
+ }
836
+ const u = [], p = wt(
837
+ c.changes,
838
+ s
839
+ );
840
+ for (let l = 0; l < p.length; l++) {
841
+ const m = p[l], f = s.slice(m.fromB, m.toB);
842
+ if (f.openEnd === 1 && f.openStart === 0 && (m.type = "node-type-or-attr-update", f.size > 2)) {
843
+ const h = {
844
+ fromA: m.fromA,
845
+ toA: m.fromA + 1,
846
+ fromB: m.fromB,
847
+ toB: m.fromB + 1,
848
+ deleted: [],
849
+ inserted: [],
850
+ type: "node-type-or-attr-update"
851
+ }, d = {
852
+ fromA: m.fromA + 1,
853
+ toA: m.toA,
854
+ fromB: m.fromB + 1,
855
+ toB: m.toB,
856
+ deleted: [],
857
+ inserted: []
858
+ };
859
+ p.splice(l, 1, h, d), l++;
860
+ }
861
+ }
862
+ Zt(p, t, s);
863
+ for (let l = 0; l < p.length; l++) {
864
+ const m = p[l], f = s.slice(m.fromB, m.toB);
865
+ if (f.openEnd > 0 && f.size > 1)
866
+ throw new Error(
867
+ "unexpected, openEnd > 0 and size > 1, this should have been split into two steps"
868
+ );
869
+ l === p.length - 1 && o && m.type === "mark-update" || u.push(
870
+ new x(
871
+ m.fromA,
872
+ m.toA,
873
+ f,
874
+ m.type === "node-type-or-attr-update"
875
+ )
876
+ );
877
+ }
878
+ return u;
879
+ }
880
+ function Wt(e, t) {
881
+ if (!e || !Array.isArray(e) || e.length === 0)
882
+ return {
883
+ ok: !1,
884
+ error: "blocks is required"
885
+ };
886
+ const o = [];
887
+ for (const r of e) {
888
+ const n = t(r);
889
+ if (!n.ok)
890
+ return {
891
+ ok: !1,
892
+ error: `Invalid block: ${n.error}`
893
+ };
894
+ o.push(n.value);
895
+ }
896
+ return {
897
+ ok: !0,
898
+ value: o
899
+ };
900
+ }
901
+ function te(e) {
902
+ return (t, o) => {
903
+ const r = typeof e.schema == "function" ? e.schema(t) : e.schema;
904
+ return {
905
+ name: "add",
906
+ description: e.description,
907
+ parameters: {
908
+ type: "object",
909
+ properties: {
910
+ referenceId: {
911
+ type: "string",
912
+ description: "MUST be an id of a block in the document"
913
+ },
914
+ position: {
915
+ type: "string",
916
+ enum: ["before", "after"],
917
+ description: "`after` to add blocks AFTER (below) the block with `referenceId`, `before` to add the block BEFORE (above)"
918
+ },
919
+ blocks: {
920
+ items: r.block,
921
+ type: "array"
922
+ }
923
+ },
924
+ required: ["referenceId", "position", "blocks"],
925
+ $defs: r.$defs
926
+ },
927
+ validate: (n) => {
928
+ if (n.type !== "add")
929
+ return {
930
+ ok: !1,
931
+ error: "invalid operation type"
932
+ };
933
+ if (n.position !== "before" && n.position !== "after")
934
+ return {
935
+ ok: !1,
936
+ error: "invalid position"
937
+ };
938
+ if (!n.referenceId || !n.blocks)
939
+ return {
940
+ ok: !1,
941
+ error: "referenceId and blocks are required"
942
+ };
943
+ let i = n.referenceId;
944
+ if (o.idsSuffixed) {
945
+ if (!(i != null && i.endsWith("$")))
946
+ return {
947
+ ok: !1,
948
+ error: "referenceId must end with $"
949
+ };
950
+ i = i.slice(0, -1);
951
+ }
952
+ if (!t.getBlock(i))
953
+ return {
954
+ ok: !1,
955
+ error: "referenceId not found"
956
+ };
957
+ const s = Wt(
958
+ n.blocks,
959
+ (c) => e.validateBlock(c, t)
960
+ );
961
+ return s.ok ? {
962
+ ok: !0,
963
+ value: {
964
+ type: n.type,
965
+ referenceId: i,
966
+ position: n.position,
967
+ blocks: s.value
968
+ }
969
+ } : s;
970
+ },
971
+ // Note: functionality mostly tested in jsontools.test.ts
972
+ // would be nicer to add a direct unit test
973
+ execute: async function* (n) {
974
+ var s;
975
+ let i = [];
976
+ const a = {};
977
+ for await (const c of n) {
978
+ if (c.isUpdateToPreviousOperation || (i = []), c.operation.type !== "add") {
979
+ yield c;
980
+ continue;
981
+ }
982
+ const u = c.operation, p = await e.toJSONToolCall(t, {
983
+ ...c,
984
+ operation: u
985
+ });
986
+ if (p && !(c.isPossiblyPartial && X(
987
+ p.blocks[p.blocks.length - 1]
988
+ ))) {
989
+ for (let l = 0; l < p.blocks.length; l++) {
990
+ const m = p.blocks[l], f = t.prosemirrorState.tr;
991
+ let h = [];
992
+ if (l < i.length) {
993
+ const d = await e.rebaseTool(i[l], t), b = J(
994
+ {
995
+ id: i[l],
996
+ block: m
997
+ },
998
+ d.doc,
999
+ !1
1000
+ ).map((g) => g.map(d.invertMap));
1001
+ for (const g of b)
1002
+ f.step(g.map(f.mapping));
1003
+ h = D(f), h = h.filter((g) => g.type !== "select");
1004
+ } else {
1005
+ const d = u.position === "after" ? a[u.referenceId] : void 0, S = st(
1006
+ f,
1007
+ [m],
1008
+ l > 0 ? i[l - 1] : d || u.referenceId,
1009
+ l > 0 ? "after" : u.position
1010
+ );
1011
+ i.push(...S.map((b) => b.id)), h = D(f);
1012
+ }
1013
+ h.find((d) => d.type === "replace");
1014
+ for (const d of h)
1015
+ o.withDelays && await Q(d), t.transact((S) => {
1016
+ ee(S, d);
1017
+ }), (s = o.onBlockUpdate) == null || s.call(o, i[l]);
1018
+ }
1019
+ c.isPossiblyPartial || u.position === "after" && (a[u.referenceId] = i[i.length - 1]);
1020
+ }
1021
+ }
1022
+ }
1023
+ };
1024
+ };
1025
+ }
1026
+ function oe(e) {
1027
+ return (t, o) => {
1028
+ const r = typeof e.schema == "function" ? e.schema(t) : e.schema;
1029
+ return {
1030
+ name: "update",
1031
+ description: e.description,
1032
+ parameters: {
1033
+ type: "object",
1034
+ properties: {
1035
+ id: {
1036
+ type: "string",
1037
+ description: "id of block to update"
1038
+ },
1039
+ block: r.block
1040
+ },
1041
+ required: ["id", "block"],
1042
+ $defs: r.$defs
1043
+ },
1044
+ validate: (n) => {
1045
+ if (n.type !== "update")
1046
+ return {
1047
+ ok: !1,
1048
+ error: "invalid operation type"
1049
+ };
1050
+ if (!n.id)
1051
+ return {
1052
+ ok: !1,
1053
+ error: "id is required"
1054
+ };
1055
+ let i = n.id;
1056
+ if (o.idsSuffixed) {
1057
+ if (!(i != null && i.endsWith("$")))
1058
+ return {
1059
+ ok: !1,
1060
+ error: "id must end with $"
1061
+ };
1062
+ i = i.slice(0, -1);
1063
+ }
1064
+ if (!n.block)
1065
+ return {
1066
+ ok: !1,
1067
+ error: "block is required"
1068
+ };
1069
+ const a = t.getBlock(i);
1070
+ if (!a)
1071
+ return console.error("BLOCK NOT FOUND", i), {
1072
+ ok: !1,
1073
+ error: "block not found"
1074
+ };
1075
+ const s = e.validateBlock(n.block, t, a.type);
1076
+ return s.ok ? {
1077
+ ok: !0,
1078
+ value: {
1079
+ type: n.type,
1080
+ id: i,
1081
+ block: s.value
1082
+ }
1083
+ } : s;
1084
+ },
1085
+ // Note: functionality mostly tested in jsontools.test.ts
1086
+ // would be nicer to add a direct unit test
1087
+ execute: async function* (n) {
1088
+ var c;
1089
+ let a = 50;
1090
+ const s = o.updateSelection ? {
1091
+ from: se(t, o.updateSelection.from),
1092
+ to: se(t, o.updateSelection.to)
1093
+ } : void 0;
1094
+ for await (const u of n) {
1095
+ if (u.operation.type !== "update") {
1096
+ yield u;
1097
+ continue;
1098
+ }
1099
+ const p = u.operation;
1100
+ if (u.isPossiblyPartial) {
1101
+ const k = JSON.stringify(p.block).length;
1102
+ if (k < a)
1103
+ continue;
1104
+ a = k + 50;
1105
+ } else
1106
+ a = 50;
1107
+ const l = await e.rebaseTool(p.id, t), m = s ? l.invertMap.invert().map(s.from()) : void 0, f = s ? l.invertMap.invert().map(s.to()) : void 0, h = await e.toJSONToolCall(t, u);
1108
+ if (!h)
1109
+ continue;
1110
+ const d = J(
1111
+ h,
1112
+ l.doc,
1113
+ u.isPossiblyPartial,
1114
+ m,
1115
+ f
1116
+ );
1117
+ if (d.length === 1 && u.isPossiblyPartial)
1118
+ continue;
1119
+ const S = d.map((k) => k.map(l.invertMap)), b = new N(t.prosemirrorState.doc);
1120
+ for (const k of S)
1121
+ b.step(k.map(b.mapping));
1122
+ const g = D(b);
1123
+ for (const k of g)
1124
+ o.withDelays && await Q(k), t.transact((w) => {
1125
+ ee(w, k);
1126
+ }), (c = o.onBlockUpdate) == null || c.call(o, p.id);
1127
+ }
1128
+ }
1129
+ };
1130
+ };
1131
+ }
1132
+ const re = (e, t) => ({
1133
+ name: "delete",
1134
+ description: "Delete a block",
1135
+ parameters: {
1136
+ type: "object",
1137
+ properties: {
1138
+ id: {
1139
+ type: "string",
1140
+ description: "id of block to delete"
1141
+ }
1142
+ },
1143
+ required: ["id"]
1144
+ },
1145
+ validate: (o) => {
1146
+ if (o.type !== "delete")
1147
+ return {
1148
+ ok: !1,
1149
+ error: "invalid operation type"
1150
+ };
1151
+ if (!o.id)
1152
+ return {
1153
+ ok: !1,
1154
+ error: "id is required"
1155
+ };
1156
+ let r = o.id;
1157
+ if (t.idsSuffixed) {
1158
+ if (!(r != null && r.endsWith("$")))
1159
+ return {
1160
+ ok: !1,
1161
+ error: "id must end with $"
1162
+ };
1163
+ r = r.slice(0, -1);
1164
+ }
1165
+ return e.getBlock(r) ? {
1166
+ ok: !0,
1167
+ value: {
1168
+ type: "delete",
1169
+ id: r
1170
+ }
1171
+ } : {
1172
+ ok: !1,
1173
+ error: "block not found"
1174
+ };
1175
+ },
1176
+ // Note: functionality mostly tested in jsontools.test.ts
1177
+ // would be nicer to add a direct unit test
1178
+ execute: async function* (o) {
1179
+ var r;
1180
+ for await (const n of o) {
1181
+ if (n.operation.type !== "delete") {
1182
+ yield n;
1183
+ continue;
1184
+ }
1185
+ const i = n.operation, a = e.prosemirrorState.tr;
1186
+ it(a, [i.id], []);
1187
+ const s = D(a);
1188
+ for (const c of s)
1189
+ t.withDelays && await Q(c), e.transact((u) => {
1190
+ ee(u, c);
1191
+ }), (r = t.onBlockUpdate) == null || r.call(t, i.id);
1192
+ }
1193
+ }
1194
+ });
1195
+ function me(e) {
1196
+ const t = e.lastIndexOf("<"), o = e.lastIndexOf(">");
1197
+ let r = e;
1198
+ if (t > o && (r = e.substring(0, t), !r.trim()))
1199
+ return;
1200
+ const n = r.match(/&[a-zA-Z0-9]*$/);
1201
+ n && (r = r.substring(
1202
+ 0,
1203
+ r.length - n[0].length
1204
+ ));
1205
+ const s = new DOMParser().parseFromString(
1206
+ `<div>${r}</div>`,
1207
+ "text/html"
1208
+ ).body.firstChild;
1209
+ return s ? s.innerHTML : "";
1210
+ }
1211
+ function R(e) {
1212
+ let t;
1213
+ if (Be(e.prosemirrorState, (o) => {
1214
+ t = o;
1215
+ }), !t)
1216
+ throw new Error("applySuggestionsTr is not set");
1217
+ return t;
1218
+ }
1219
+ function H(e, t) {
1220
+ const o = t.mapping.invert();
1221
+ return {
1222
+ doc: t.doc,
1223
+ /**
1224
+ * Return a new transform that has the projection applied.
1225
+ * You can add new operations to this transform and later rebase those on the original document with `rebaseTr`
1226
+ */
1227
+ tr: () => new N(t.doc),
1228
+ /**
1229
+ * Invert map created by the projection.
1230
+ * You can use this to map positions on the "clean" document (the projection) to positions on the original document
1231
+ */
1232
+ invertMap: o,
1233
+ /**
1234
+ * Return a new transaction based on the editor state with all the steps you made to `tr`.
1235
+ * These steps are rebased on the original document.
1236
+ */
1237
+ rebaseTr: (r) => {
1238
+ if (r.steps.length === 0)
1239
+ throw new Error("No steps to apply");
1240
+ let n = e.prosemirrorState.tr;
1241
+ for (const i of r.steps) {
1242
+ const a = i.map(o);
1243
+ if (!a)
1244
+ throw new Error("Step is not mapped");
1245
+ n = n.step(a);
1246
+ }
1247
+ return n;
1248
+ }
1249
+ };
1250
+ }
1251
+ async function he(e, t) {
1252
+ var u;
1253
+ const o = R(t), r = Oe(o.doc, e);
1254
+ if (!r)
1255
+ throw new Error("block not found");
1256
+ const n = await t.blocksToHTMLLossy([
1257
+ {
1258
+ ...r,
1259
+ children: []
1260
+ }
1261
+ ]), i = (u = window.__TEST_OPTIONS) == null ? void 0 : u.mockID, a = await t.tryParseHTMLToBlocks(n);
1262
+ if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = i), a.length !== 1)
1263
+ throw new Error("html diff invalid block count");
1264
+ const s = a[0];
1265
+ if (s.id = e, J(
1266
+ {
1267
+ id: e,
1268
+ block: s
1269
+ },
1270
+ o.doc
1271
+ ).length)
1272
+ throw new Error("html diff");
1273
+ return H(t, o);
1274
+ }
1275
+ function ye(e) {
1276
+ return typeof e != "string" ? {
1277
+ ok: !1,
1278
+ error: "block must be a string"
1279
+ } : {
1280
+ ok: !0,
1281
+ value: e
1282
+ };
1283
+ }
1284
+ const V = {
1285
+ add: te({
1286
+ description: "Insert new blocks",
1287
+ schema: {
1288
+ block: {
1289
+ $ref: "#/$defs/block"
1290
+ },
1291
+ $defs: {
1292
+ block: {
1293
+ type: "string",
1294
+ description: "html of block (MUST be a single HTML element)"
1295
+ }
1296
+ }
1297
+ },
1298
+ validateBlock: ye,
1299
+ rebaseTool: he,
1300
+ toJSONToolCall: async (e, t) => {
1301
+ var n;
1302
+ const o = (n = window.__TEST_OPTIONS) == null ? void 0 : n.mockID, r = (await Promise.all(
1303
+ t.operation.blocks.map(async (i) => {
1304
+ const a = t.isPossiblyPartial ? me(i) : i;
1305
+ return a ? (await e.tryParseHTMLToBlocks(a)).map(
1306
+ (s) => (delete s.id, s)
1307
+ ) : [];
1308
+ })
1309
+ )).flat();
1310
+ if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = o), r.length !== 0)
1311
+ return {
1312
+ ...t.operation,
1313
+ blocks: r
1314
+ };
1315
+ }
1316
+ }),
1317
+ update: oe({
1318
+ description: "Update a block",
1319
+ schema: {
1320
+ block: {
1321
+ $ref: "#/$defs/block"
1322
+ },
1323
+ $defs: {
1324
+ block: {
1325
+ type: "string",
1326
+ description: "html of block (MUST be a single HTML element)"
1327
+ }
1328
+ }
1329
+ },
1330
+ validateBlock: ye,
1331
+ rebaseTool: he,
1332
+ toJSONToolCall: async (e, t) => {
1333
+ const o = t.isPossiblyPartial ? me(t.operation.block) : t.operation.block;
1334
+ if (!o)
1335
+ return;
1336
+ const r = (await e.tryParseHTMLToBlocks(o))[0];
1337
+ return window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), delete r.id, {
1338
+ ...t.operation,
1339
+ block: r
1340
+ };
1341
+ }
1342
+ }),
1343
+ delete: re
1344
+ };
1345
+ function Yt(e, t, o, r, n) {
1346
+ const i = {
1347
+ add: !0,
1348
+ update: !0,
1349
+ delete: !0,
1350
+ ...o
1351
+ };
1352
+ return [
1353
+ ...i.update ? [
1354
+ V.update(e, {
1355
+ idsSuffixed: !0,
1356
+ withDelays: t,
1357
+ updateSelection: r,
1358
+ onBlockUpdate: n
1359
+ })
1360
+ ] : [],
1361
+ ...i.add ? [V.add(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : [],
1362
+ ...i.delete ? [V.delete(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : []
1363
+ ];
1364
+ }
1365
+ const ze = {
1366
+ /**
1367
+ * Function to get the stream tools that can apply HTML block updates to the editor
1368
+ */
1369
+ getStreamTools: Yt,
1370
+ /**
1371
+ * The default PromptBuilder that determines how a userPrompt is converted to an array of
1372
+ * LLM Messages (CoreMessage[])
1373
+ */
1374
+ defaultPromptBuilder: Jt,
1375
+ /**
1376
+ * Helper functions which can be used when implementing a custom PromptBuilder
1377
+ */
1378
+ promptHelpers: {
1379
+ getDataForPromptNoSelection: He,
1380
+ getDataForPromptWithSelection: qe
1381
+ }
1382
+ };
1383
+ async function Gt(e, t) {
1384
+ const {
1385
+ userPrompt: o,
1386
+ useSelection: r,
1387
+ deleteEmptyCursorBlock: n,
1388
+ stream: i,
1389
+ onStart: a,
1390
+ withDelays: s,
1391
+ dataFormat: c,
1392
+ previousResponse: u,
1393
+ ...p
1394
+ } = {
1395
+ maxRetries: 2,
1396
+ deleteEmptyCursorBlock: !0,
1397
+ stream: !0,
1398
+ withDelays: !0,
1399
+ dataFormat: ze,
1400
+ ...t
1401
+ }, l = t.promptBuilder ?? c.defaultPromptBuilder, m = c.getStreamTools, f = r ? void 0 : e.getTextCursorPosition().block, h = f && n && X(f) ? f.id : void 0, d = r ? e.getSelectionCutBlocks() : void 0;
1402
+ let S;
1403
+ u && (S = u.messages, S.push({
1404
+ role: "assistant",
1405
+ content: `These are the operations returned by a previous LLM call:
1406
+ ` + JSON.stringify(
1407
+ await u.llmResult.getGeneratedOperations()
1408
+ )
1409
+ }));
1410
+ const b = await l(e, {
1411
+ selectedBlocks: d == null ? void 0 : d.blocks,
1412
+ userPrompt: o,
1413
+ excludeBlockIds: h ? [h] : void 0,
1414
+ previousMessages: S
1415
+ }), g = m(
1416
+ e,
1417
+ s,
1418
+ t.defaultStreamTools,
1419
+ d ? { from: d._meta.startPos, to: d._meta.endPos } : void 0,
1420
+ t.onBlockUpdate
1421
+ );
1422
+ let k;
1423
+ return i ? k = await $t(
1424
+ g,
1425
+ {
1426
+ messages: b,
1427
+ ...p
1428
+ },
1429
+ () => {
1430
+ h && e.removeBlocks([h]), a == null || a();
1431
+ }
1432
+ ) : (k = await At(g, {
1433
+ messages: b,
1434
+ ...p
1435
+ }), h && e.removeBlocks([h]), a == null || a()), new qt(b, k, g);
1436
+ }
1437
+ async function Ue(e, t) {
1438
+ const o = F(e.document), r = await C(
1439
+ T(o),
1440
+ async (s) => ({
1441
+ ...s,
1442
+ children: void 0
1443
+ })
1444
+ ), i = U(e, r).filter(
1445
+ (s) => "cursor" in s || !(t.excludeBlockIds || []).includes(s.id)
1446
+ );
1447
+ return {
1448
+ jsonBlocks: L(i)
1449
+ };
1450
+ }
1451
+ async function Fe(e, t) {
1452
+ const o = await C(
1453
+ T(t.selectedBlocks),
1454
+ async (n) => n
1455
+ );
1456
+ return {
1457
+ jsonSelectedBlocks: L(o),
1458
+ jsonDocument: (await C(T(e.document), async (n) => ({
1459
+ ...n,
1460
+ id: void 0,
1461
+ // don't pass id, because LLM should use `jsonSelectedBlocks` for this
1462
+ children: void 0
1463
+ }))).map(({ block: n }) => ({ block: n }))
1464
+ // strip ids so LLM can't accidentally issue updates to ids not in selection
1465
+ };
1466
+ }
1467
+ function Kt(e) {
1468
+ return [
1469
+ {
1470
+ role: "system",
1471
+ content: `You're manipulating a selected part of a text document using JSON blocks.
1472
+ Make sure to follow the json schema provided and always include the trailing $ in ids.
1473
+ This is the selection as an array of JSON blocks:`
1474
+ },
1475
+ {
1476
+ role: "system",
1477
+ content: JSON.stringify(e.jsonSelectedBlocks)
1478
+ },
1479
+ {
1480
+ role: "system",
1481
+ content: "This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"
1482
+ },
1483
+ {
1484
+ role: "system",
1485
+ content: JSON.stringify(e.jsonDocument)
1486
+ },
1487
+ {
1488
+ role: "system",
1489
+ content: "The user asks you to do the following:"
1490
+ },
1491
+ {
1492
+ role: "user",
1493
+ content: e.userPrompt
1494
+ }
1495
+ ];
1496
+ }
1497
+ function Xt(e) {
1498
+ return [
1499
+ {
1500
+ role: "system",
1501
+ content: `You're manipulating a text document using JSON blocks.
1502
+ Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $).
1503
+ This is the document as an array of JSON blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):`
1504
+ },
1505
+ {
1506
+ role: "system",
1507
+ content: JSON.stringify(e.jsonBlocks)
1508
+ },
1509
+ {
1510
+ role: "system",
1511
+ content: "The user asks you to do the following:"
1512
+ },
1513
+ {
1514
+ role: "user",
1515
+ content: e.userPrompt
1516
+ },
1517
+ {
1518
+ role: "system",
1519
+ content: 'First, determine what part of the document the user is talking about. You SHOULD probably take cursor info into account if needed.\n EXAMPLE: if user says "below" (without pointing to a specific part of the document) he / she probably indicates the block(s) after the cursor. \n EXAMPLE: If you want to insert content AT the cursor position (UNLESS indicated otherwise by the user), then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`).\n \n Prefer updating blocks over adding or removing (but this also depends on the user\'s question).'
1520
+ }
1521
+ ];
1522
+ }
1523
+ const Qt = async (e, t) => {
1524
+ if (t.selectedBlocks) {
1525
+ const o = await Fe(e, {
1526
+ selectedBlocks: t.selectedBlocks
1527
+ });
1528
+ return Kt({
1529
+ ...o,
1530
+ userPrompt: t.userPrompt
1531
+ });
1532
+ } else {
1533
+ const o = await Ue(e, t);
1534
+ return Xt({
1535
+ ...o,
1536
+ userPrompt: t.userPrompt
1537
+ });
1538
+ }
1539
+ };
1540
+ function eo(e) {
1541
+ const t = {}, o = {};
1542
+ return e.forEach((n) => {
1543
+ const { type: i, ...a } = n.properties, s = JSON.stringify(a);
1544
+ t[s] ? t[s].push(i.enum[0]) : (t[s] = [i.enum[0]], o[s] = n);
1545
+ }), Object.keys(
1546
+ t
1547
+ ).map((n) => {
1548
+ const i = o[n];
1549
+ return {
1550
+ ...i,
1551
+ properties: {
1552
+ ...i.properties,
1553
+ type: {
1554
+ type: "string",
1555
+ enum: t[n]
1556
+ }
1557
+ }
1558
+ };
1559
+ });
1560
+ }
1561
+ function to(e) {
1562
+ return {
1563
+ type: "object",
1564
+ properties: Object.fromEntries(
1565
+ Object.entries(e).map(([t, o]) => [
1566
+ t,
1567
+ {
1568
+ type: o.propSchema
1569
+ }
1570
+ ])
1571
+ ),
1572
+ additionalProperties: !1
1573
+ };
1574
+ }
1575
+ function oo() {
1576
+ return {
1577
+ type: "object",
1578
+ properties: {
1579
+ type: {
1580
+ type: "string",
1581
+ enum: ["text"]
1582
+ },
1583
+ text: {
1584
+ type: "string"
1585
+ },
1586
+ styles: {
1587
+ $ref: "#/$defs/styles"
1588
+ }
1589
+ },
1590
+ additionalProperties: !1,
1591
+ required: ["type", "text"]
1592
+ };
1593
+ }
1594
+ function Je(e) {
1595
+ return {
1596
+ type: "object",
1597
+ properties: Object.fromEntries(
1598
+ Object.entries(e).filter(([t, o]) => o.default !== void 0).map(([t, o]) => [
1599
+ t,
1600
+ {
1601
+ type: typeof o.default,
1602
+ enum: o.values
1603
+ }
1604
+ ])
1605
+ ),
1606
+ additionalProperties: !1
1607
+ };
1608
+ }
1609
+ function ro(e) {
1610
+ return {
1611
+ type: "array",
1612
+ items: {
1613
+ anyOf: Object.entries(e).map(([t, o]) => o === "text" ? {
1614
+ $ref: "#/$defs/styledtext"
1615
+ } : o === "link" ? {
1616
+ type: "object",
1617
+ properties: {
1618
+ type: {
1619
+ type: "string",
1620
+ enum: ["link"]
1621
+ },
1622
+ content: {
1623
+ type: "array",
1624
+ items: {
1625
+ $ref: "#/$defs/styledtext"
1626
+ }
1627
+ },
1628
+ href: {
1629
+ type: "string"
1630
+ }
1631
+ },
1632
+ additionalProperties: !1,
1633
+ required: ["type", "href", "content"]
1634
+ } : {
1635
+ type: "object",
1636
+ properties: {
1637
+ type: {
1638
+ type: "string",
1639
+ enum: [o.type]
1640
+ },
1641
+ content: o.content === "styled" ? {
1642
+ type: "array",
1643
+ items: {
1644
+ $ref: "#/$defs/styledtext"
1645
+ }
1646
+ } : void 0,
1647
+ props: Je(o.propSchema)
1648
+ },
1649
+ additionalProperties: !1,
1650
+ required: ["type", ...o.content === "styled" ? ["content"] : []]
1651
+ })
1652
+ }
1653
+ };
1654
+ }
1655
+ function no(e) {
1656
+ return {
1657
+ anyOf: eo(
1658
+ Object.entries(e).map(([t, o]) => ({
1659
+ type: "object",
1660
+ properties: {
1661
+ type: {
1662
+ type: "string",
1663
+ enum: [o.type]
1664
+ },
1665
+ content: o.content === "inline" ? { $ref: "#/$defs/inlinecontent" } : o.content === "table" ? { type: "object", properties: {} } : void 0,
1666
+ // filter out default props (TODO: make option)
1667
+ props: Je(o.propSchema)
1668
+ // Object.fromEntries(
1669
+ // Object.entries(val.propSchema).filter(
1670
+ // (key) => typeof (defaultProps as any)[key[0]] === "undefined"
1671
+ // )
1672
+ // )
1673
+ // ),
1674
+ },
1675
+ additionalProperties: !1,
1676
+ required: ["type"]
1677
+ //, ...(val.content === "inline" ? ["content"] : [])],
1678
+ }))
1679
+ )
1680
+ };
1681
+ }
1682
+ function so(e) {
1683
+ const t = JSON.parse(
1684
+ JSON.stringify({
1685
+ blockSchema: e.blockSchema,
1686
+ inlineContentSchema: e.inlineContentSchema,
1687
+ styleSchema: e.styleSchema
1688
+ })
1689
+ );
1690
+ return {
1691
+ removeFileBlocks() {
1692
+ return t.blockSchema = Object.fromEntries(
1693
+ Object.entries(t.blockSchema).filter(
1694
+ ([o, r]) => !r.isFileBlock
1695
+ )
1696
+ ), this;
1697
+ },
1698
+ removeDefaultProps() {
1699
+ return t.blockSchema = Object.fromEntries(
1700
+ Object.entries(t.blockSchema).map(([o, r]) => [
1701
+ o,
1702
+ {
1703
+ ...r,
1704
+ propSchema: Object.fromEntries(
1705
+ Object.entries(r.propSchema).filter(
1706
+ (n) => typeof Me[n[0]] > "u"
1707
+ )
1708
+ )
1709
+ }
1710
+ ])
1711
+ ), this;
1712
+ },
1713
+ get() {
1714
+ return t;
1715
+ }
1716
+ };
1717
+ }
1718
+ function ge(e) {
1719
+ return e = so(e).removeFileBlocks().removeDefaultProps().get(), {
1720
+ $defs: {
1721
+ styles: to(e.styleSchema),
1722
+ styledtext: oo(),
1723
+ inlinecontent: ro(
1724
+ e.inlineContentSchema
1725
+ ),
1726
+ block: no(e.blockSchema)
1727
+ }
1728
+ };
1729
+ }
1730
+ function Ve(e, t) {
1731
+ return !t.schema.inlineContentSchema[e.type] || at(e) && !("text" in e) ? !1 : ct(e) ? !("content" in e) || !("href" in e) ? !1 : Ve(e.content, t) : !0;
1732
+ }
1733
+ function ke(e, t, o) {
1734
+ const r = e.type || o, n = t.schema.blockSchema[r];
1735
+ if (!n)
1736
+ return {
1737
+ ok: !1,
1738
+ error: "block type not found in editor"
1739
+ };
1740
+ if (e.children, n.content === "none") {
1741
+ if (e.content)
1742
+ return {
1743
+ ok: !1,
1744
+ error: "block content not expected for this block type"
1745
+ };
1746
+ } else {
1747
+ if (!e.content)
1748
+ return {
1749
+ ok: !0,
1750
+ value: e
1751
+ };
1752
+ if (!Array.isArray(e.content))
1753
+ return {
1754
+ ok: !1,
1755
+ error: "block content must be an array"
1756
+ };
1757
+ if (n.content === "table")
1758
+ return {
1759
+ ok: !0,
1760
+ value: e
1761
+ };
1762
+ if (!e.content.every((i) => Ve(i, t)))
1763
+ return {
1764
+ ok: !1,
1765
+ error: "block content must be an array of inline content"
1766
+ };
1767
+ }
1768
+ return {
1769
+ ok: !0,
1770
+ value: e
1771
+ };
1772
+ }
1773
+ const Z = {
1774
+ add: te({
1775
+ description: "Insert new blocks",
1776
+ schema: (e) => ({
1777
+ block: {
1778
+ $ref: "#/$defs/block"
1779
+ },
1780
+ ...ge(e.schema)
1781
+ }),
1782
+ validateBlock: ke,
1783
+ rebaseTool: async (e, t) => H(t, R(t)),
1784
+ toJSONToolCall: async (e, t) => t.operation
1785
+ }),
1786
+ update: oe({
1787
+ description: "Update a block, the new block will replace the existing block.",
1788
+ schema: (e) => ({
1789
+ block: {
1790
+ $ref: "#/$defs/block"
1791
+ },
1792
+ ...ge(e.schema)
1793
+ }),
1794
+ validateBlock: ke,
1795
+ rebaseTool: async (e, t) => H(t, R(t)),
1796
+ toJSONToolCall: async (e, t) => {
1797
+ const o = Object.fromEntries(
1798
+ Object.entries(Me).map(([r, n]) => [r, n.default])
1799
+ );
1800
+ return {
1801
+ ...t.operation,
1802
+ block: {
1803
+ ...t.operation.block,
1804
+ props: {
1805
+ ...o,
1806
+ ...t.operation.block.props
1807
+ }
1808
+ }
1809
+ };
1810
+ }
1811
+ }),
1812
+ delete: re
1813
+ };
1814
+ function io(e, t, o, r) {
1815
+ const n = {
1816
+ add: !0,
1817
+ update: !0,
1818
+ delete: !0,
1819
+ ...o
1820
+ };
1821
+ return [
1822
+ ...n.update ? [
1823
+ Z.update(e, {
1824
+ idsSuffixed: !0,
1825
+ withDelays: t,
1826
+ updateSelection: r
1827
+ })
1828
+ ] : [],
1829
+ ...n.add ? [Z.add(e, { idsSuffixed: !0, withDelays: t })] : [],
1830
+ ...n.delete ? [Z.delete(e, { idsSuffixed: !0, withDelays: t })] : []
1831
+ ];
1832
+ }
1833
+ const ao = {
1834
+ /**
1835
+ * Function to get the stream tools that can apply BlockNote JSON block updates to the editor
1836
+ */
1837
+ getStreamTools: io,
1838
+ /**
1839
+ * The default PromptBuilder that determines how a userPrompt is converted to an array of
1840
+ * LLM Messages (CoreMessage[])
1841
+ */
1842
+ defaultPromptBuilder: Qt,
1843
+ /**
1844
+ * Helper functions which can be used when implementing a custom PromptBuilder
1845
+ */
1846
+ promptHelpers: {
1847
+ getDataForPromptNoSelection: Ue,
1848
+ getDataForPromptWithSelection: Fe
1849
+ }
1850
+ };
1851
+ async function Ze(e, t) {
1852
+ const o = F(e.document), r = await C(
1853
+ T(o),
1854
+ async (s) => e.blocksToMarkdownLossy([s])
1855
+ ), i = U(e, r).filter(
1856
+ (s) => "cursor" in s || !(t.excludeBlockIds || []).includes(s.id)
1857
+ );
1858
+ return {
1859
+ markdownBlocks: L(i)
1860
+ };
1861
+ }
1862
+ async function We(e, t) {
1863
+ const o = await C(
1864
+ T(t.selectedBlocks),
1865
+ async (n) => e.blocksToMarkdownLossy([n])
1866
+ );
1867
+ return {
1868
+ markdownSelectedBlocks: L(o),
1869
+ markdownDocument: (await C(T(e.document), async (n) => e.blocksToMarkdownLossy([n]))).map(({ block: n }) => ({ block: n }))
1870
+ // strip ids so LLM can't accidentally issue updates to ids not in selection
1871
+ };
1872
+ }
1873
+ function co(e) {
1874
+ return [
1875
+ {
1876
+ role: "system",
1877
+ content: `You're manipulating a selected part of a text document using markdown blocks.
1878
+ Make sure to follow the json schema provided and always include the trailing $ in ids.
1879
+ This is the selection as an array of markdown blocks:`
1880
+ },
1881
+ {
1882
+ role: "system",
1883
+ content: JSON.stringify(e.markdownSelectedBlocks)
1884
+ },
1885
+ {
1886
+ role: "system",
1887
+ content: "This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"
1888
+ },
1889
+ {
1890
+ role: "system",
1891
+ content: JSON.stringify(e.markdownDocument)
1892
+ },
1893
+ {
1894
+ role: "system",
1895
+ content: "The user asks you to do the following:"
1896
+ },
1897
+ {
1898
+ role: "user",
1899
+ content: e.userPrompt
1900
+ }
1901
+ ];
1902
+ }
1903
+ function lo(e) {
1904
+ return [
1905
+ {
1906
+ role: "system",
1907
+ content: `You're manipulating a text document using markdown blocks.
1908
+ Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $).
1909
+ This is the document as an array of markdown blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):`
1910
+ },
1911
+ {
1912
+ role: "system",
1913
+ content: JSON.stringify(e.markdownBlocks)
1914
+ },
1915
+ {
1916
+ role: "system",
1917
+ content: "The user asks you to do the following:"
1918
+ },
1919
+ {
1920
+ role: "user",
1921
+ content: e.userPrompt
1922
+ },
1923
+ {
1924
+ role: "system",
1925
+ content: 'First, determine what part of the document the user is talking about. You SHOULD probably take cursor info into account if needed.\n EXAMPLE: if user says "below" (without pointing to a specific part of the document) he / she probably indicates the block(s) after the cursor. \n EXAMPLE: If you want to insert content AT the cursor position (UNLESS indicated otherwise by the user), then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`).\n \n Prefer updating blocks over adding or removing (but this also depends on the user\'s question).'
1926
+ }
1927
+ ];
1928
+ }
1929
+ const uo = async (e, t) => {
1930
+ if (t.selectedBlocks) {
1931
+ const o = await We(e, {
1932
+ selectedBlocks: t.selectedBlocks
1933
+ });
1934
+ return co({
1935
+ ...o,
1936
+ userPrompt: t.userPrompt
1937
+ });
1938
+ } else {
1939
+ const o = await Ze(e, t);
1940
+ return lo({
1941
+ ...o,
1942
+ userPrompt: t.userPrompt
1943
+ });
1944
+ }
1945
+ };
1946
+ async function be(e, t) {
1947
+ const o = R(t), r = await t.blocksToMarkdownLossy([Oe(o.doc, e)]), n = await t.tryParseMarkdownToBlocks(r), i = J(
1948
+ {
1949
+ id: e,
1950
+ block: n[0]
1951
+ },
1952
+ o.doc
1953
+ ), a = new Ie();
1954
+ for (const s of i) {
1955
+ const c = s.map(a);
1956
+ if (!c)
1957
+ throw new Error("Failed to map step");
1958
+ o.step(c), a.appendMap(c.getMap());
1959
+ }
1960
+ return H(t, o);
1961
+ }
1962
+ function Se(e) {
1963
+ return typeof e != "string" ? {
1964
+ ok: !1,
1965
+ error: "block must be a string"
1966
+ } : {
1967
+ ok: !0,
1968
+ value: e
1969
+ };
1970
+ }
1971
+ const W = {
1972
+ add: te({
1973
+ description: "Insert new blocks",
1974
+ schema: {
1975
+ block: {
1976
+ $ref: "#/$defs/block"
1977
+ },
1978
+ $defs: {
1979
+ block: { type: "string", description: "markdown of block" }
1980
+ }
1981
+ },
1982
+ validateBlock: Se,
1983
+ rebaseTool: be,
1984
+ toJSONToolCall: async (e, t) => {
1985
+ const o = await Promise.all(
1986
+ t.operation.blocks.map(async (r) => {
1987
+ const n = (await e.tryParseMarkdownToBlocks(r.trim()))[0];
1988
+ return delete n.id, n;
1989
+ })
1990
+ );
1991
+ return window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), {
1992
+ ...t.operation,
1993
+ blocks: o
1994
+ };
1995
+ }
1996
+ }),
1997
+ update: oe({
1998
+ description: "Update a block, the new block will replace the existing block.",
1999
+ schema: {
2000
+ block: {
2001
+ $ref: "#/$defs/block"
2002
+ },
2003
+ $defs: {
2004
+ block: { type: "string", description: "markdown of block" }
2005
+ }
2006
+ },
2007
+ validateBlock: Se,
2008
+ rebaseTool: be,
2009
+ toJSONToolCall: async (e, t) => {
2010
+ const o = (await e.tryParseMarkdownToBlocks(t.operation.block.trim()))[0];
2011
+ return delete o.id, window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), {
2012
+ ...t.operation,
2013
+ block: o
2014
+ };
2015
+ }
2016
+ }),
2017
+ delete: re
2018
+ };
2019
+ function fo(e, t, o, r) {
2020
+ const n = {
2021
+ add: !0,
2022
+ update: !0,
2023
+ delete: !0,
2024
+ ...o
2025
+ };
2026
+ return [
2027
+ ...n.update ? [
2028
+ W.update(e, {
2029
+ idsSuffixed: !0,
2030
+ withDelays: t,
2031
+ updateSelection: r
2032
+ })
2033
+ ] : [],
2034
+ ...n.add ? [W.add(e, { idsSuffixed: !0, withDelays: t })] : [],
2035
+ ...n.delete ? [W.delete(e, { idsSuffixed: !0, withDelays: t })] : []
2036
+ ];
2037
+ }
2038
+ const po = {
2039
+ /**
2040
+ * Function to get the stream tools that can apply BlockNote Markdown block updates to the editor
2041
+ */
2042
+ getStreamTools: fo,
2043
+ /**
2044
+ * The default PromptBuilder that determines how a userPrompt is converted to an array of
2045
+ * LLM Messages (CoreMessage[])
2046
+ */
2047
+ defaultPromptBuilder: uo,
2048
+ /**
2049
+ * Helper functions which can be used when implementing a custom PromptBuilder
2050
+ */
2051
+ promptHelpers: {
2052
+ getDataForPromptNoSelection: Ze,
2053
+ getDataForPromptWithSelection: We
2054
+ }
2055
+ }, ir = {
2056
+ addCursorPosition: U,
2057
+ flattenBlocks: T,
2058
+ suffixIDs: L,
2059
+ trimEmptyBlocks: F,
2060
+ convertBlocks: C
2061
+ }, mo = {
2062
+ _experimental_json: ao,
2063
+ _experimental_markdown: po,
2064
+ html: ze
2065
+ }, we = new _e("blocknote-agent-cursor");
2066
+ function ho(e) {
2067
+ return new xe({
2068
+ key: we,
2069
+ view: (t) => ({}),
2070
+ state: {
2071
+ init: () => ({
2072
+ selection: void 0
2073
+ }),
2074
+ apply: (t, o) => {
2075
+ const r = t.getMeta("aiAgent");
2076
+ return r ? {
2077
+ selection: r.selection
2078
+ } : {
2079
+ selection: void 0
2080
+ };
2081
+ }
2082
+ },
2083
+ props: {
2084
+ decorations: (t) => {
2085
+ const { doc: o } = t, { selection: r } = we.getState(t), n = [];
2086
+ if (!r)
2087
+ return le.create(o, []);
2088
+ n.push(
2089
+ ue.widget(r.head, () => yo(e), {
2090
+ key: "agent-cursor",
2091
+ side: 10
2092
+ })
2093
+ );
2094
+ const i = Math.min(r.anchor, r.head), a = Math.max(r.anchor, r.head);
2095
+ return n.push(
2096
+ ue.inline(i, a, Tt(e), {
2097
+ inclusiveEnd: !0,
2098
+ inclusiveStart: !1
2099
+ })
2100
+ ), le.create(o, n);
2101
+ }
2102
+ }
2103
+ });
2104
+ }
2105
+ const yo = (e) => {
2106
+ const t = document.createElement("span");
2107
+ t.classList.add("bn-collaboration-cursor__base"), t.setAttribute("data-active", "true");
2108
+ const o = document.createElement("span");
2109
+ o.setAttribute("contentedEditable", "false"), o.classList.add("bn-collaboration-cursor__caret"), o.setAttribute("style", `background-color: ${e.color}`);
2110
+ const r = document.createElement("span");
2111
+ return r.classList.add("bn-collaboration-cursor__label"), r.setAttribute("style", `background-color: ${e.color}`), r.insertBefore(document.createTextNode(e.name), null), o.insertBefore(r, null), t.insertBefore(document.createTextNode("⁠"), null), t.insertBefore(o, null), t.insertBefore(document.createTextNode("⁠"), null), t;
2112
+ }, go = new _e("blocknote-ai-plugin");
2113
+ class Ye extends lt {
2114
+ /**
2115
+ * @internal use `createAIExtension` instead
2116
+ */
2117
+ constructor(o, r) {
2118
+ super();
2119
+ j(this, "previousRequestOptions");
2120
+ // internal store including setters
2121
+ j(this, "_store", fe()((o) => ({
2122
+ aiMenuState: "closed"
2123
+ })));
2124
+ /**
2125
+ * Returns a zustand store with the global configuration of the AI Extension.
2126
+ * These options are used by default across all LLM calls when calling {@link doLLMRequest}
2127
+ */
2128
+ j(this, "options");
2129
+ this.editor = o, this.options = fe()((n) => ({
2130
+ dataFormat: mo.html,
2131
+ stream: !0,
2132
+ ...r
2133
+ })), this.addProsemirrorPlugin(
2134
+ new xe({
2135
+ key: go,
2136
+ filterTransaction: (n) => {
2137
+ var a;
2138
+ const i = this.store.getState().aiMenuState;
2139
+ return !(i !== "closed" && i.status === "ai-writing" && (a = n.getMeta(kt)) != null && a.fixTables);
2140
+ }
2141
+ })
2142
+ ), this.addProsemirrorPlugin(ft()), this.addProsemirrorPlugin(
2143
+ ho(
2144
+ r.agentCursor || { name: "AI", color: "#8bc6ff" }
2145
+ )
2146
+ );
2147
+ }
2148
+ static name() {
2149
+ return "ai";
2150
+ }
2151
+ /**
2152
+ * Returns a read-only zustand store with the state of the AI Extension
2153
+ */
2154
+ get store() {
2155
+ return this._store;
2156
+ }
2157
+ /**
2158
+ * Open the AI menu at a specific block
2159
+ */
2160
+ openAIMenuAtBlock(o) {
2161
+ this.editor.setForceSelectionVisible(!0), this.editor.isEditable = !1, this._store.setState({
2162
+ aiMenuState: {
2163
+ blockId: o,
2164
+ status: "user-input"
2165
+ }
2166
+ });
2167
+ }
2168
+ /**
2169
+ * Close the AI menu
2170
+ */
2171
+ closeAIMenu() {
2172
+ this.previousRequestOptions = void 0, this._store.setState({
2173
+ aiMenuState: "closed",
2174
+ llmResponse: void 0
2175
+ }), this.editor.setForceSelectionVisible(!1), this.editor.isEditable = !0, this.editor.focus();
2176
+ }
2177
+ /**
2178
+ * Accept the changes made by the LLM
2179
+ */
2180
+ acceptChanges() {
2181
+ var r;
2182
+ const o = this.editor.prosemirrorState.doc;
2183
+ this.editor.exec((n, i) => ie(n, (a) => {
2184
+ i == null || i(a.setMeta("addToHistory", !1));
2185
+ })), this.editor.exec((n, i) => {
2186
+ const a = n.tr;
2187
+ a.replace(
2188
+ 0,
2189
+ a.doc.content.size,
2190
+ new Y(ae.from(o), 0, 0)
2191
+ );
2192
+ const s = n.apply(a);
2193
+ return Be(s, (c) => {
2194
+ i == null || i(
2195
+ a.replace(
2196
+ 0,
2197
+ a.doc.content.size,
2198
+ new Y(ae.from(c.doc), 0, 0)
2199
+ )
2200
+ );
2201
+ });
2202
+ }), (r = this.editor.forkYDocPlugin) == null || r.merge({ keepChanges: !0 }), this.closeAIMenu();
2203
+ }
2204
+ /**
2205
+ * Reject the changes made by the LLM
2206
+ */
2207
+ rejectChanges() {
2208
+ var o;
2209
+ this.editor.exec((r, n) => ie(r, (i) => {
2210
+ n == null || n(i.setMeta("addToHistory", !1));
2211
+ })), (o = this.editor.forkYDocPlugin) == null || o.merge({ keepChanges: !1 }), this.closeAIMenu();
2212
+ }
2213
+ /**
2214
+ * Retry the previous LLM call.
2215
+ *
2216
+ * Only valid if the current status is "error"
2217
+ */
2218
+ async retry() {
2219
+ const o = this.store.getState().aiMenuState;
2220
+ if (o === "closed" || o.status !== "error" || !this.previousRequestOptions)
2221
+ throw new Error("retry() is only valid when a previous response failed");
2222
+ if (o.error instanceof ht || o.error instanceof yt)
2223
+ return this.callLLM(this.previousRequestOptions);
2224
+ {
2225
+ const r = o.error instanceof Error ? o.error.message : String(o.error);
2226
+ return this.callLLM({
2227
+ userPrompt: `An error occured: ${r}
2228
+ Please retry the previous user request.`
2229
+ });
2230
+ }
2231
+ }
2232
+ /**
2233
+ * Update the status of a call to an LLM
2234
+ *
2235
+ * @warning This method should usually only be used for advanced use-cases
2236
+ * if you want to implement how an LLM call is executed. Usually, you should
2237
+ * use {@link doLLMRequest} instead which will handle the status updates for you.
2238
+ */
2239
+ setAIResponseStatus(o) {
2240
+ const r = this.store.getState().aiMenuState;
2241
+ if (r !== "closed")
2242
+ if (o === "ai-writing" && this.editor.setForceSelectionVisible(!1), typeof o == "object") {
2243
+ if (o.status !== "error")
2244
+ throw new Pe(o.status);
2245
+ this._store.setState({
2246
+ aiMenuState: {
2247
+ status: o.status,
2248
+ error: o.error,
2249
+ blockId: r.blockId
2250
+ }
2251
+ });
2252
+ } else
2253
+ this._store.setState({
2254
+ aiMenuState: {
2255
+ status: o,
2256
+ blockId: r.blockId
2257
+ }
2258
+ });
2259
+ }
2260
+ /**
2261
+ * Execute a call to an LLM and apply the result to the editor
2262
+ */
2263
+ async callLLM(o) {
2264
+ var n;
2265
+ this.setAIResponseStatus("thinking"), (n = this.editor.forkYDocPlugin) == null || n.fork();
2266
+ let r;
2267
+ try {
2268
+ const i = {
2269
+ ...this.options.getState(),
2270
+ ...o,
2271
+ previousResponse: this.store.getState().llmResponse
2272
+ };
2273
+ this.previousRequestOptions = i, r = await Gt(this.editor, {
2274
+ ...i,
2275
+ onStart: () => {
2276
+ var a;
2277
+ this.setAIResponseStatus("ai-writing"), (a = o.onStart) == null || a.call(o);
2278
+ },
2279
+ onBlockUpdate: (a) => {
2280
+ var s;
2281
+ this._store.setState({
2282
+ aiMenuState: {
2283
+ blockId: a,
2284
+ status: "ai-writing"
2285
+ }
2286
+ }), (s = o.onBlockUpdate) == null || s.call(o, a);
2287
+ }
2288
+ }), this._store.setState({
2289
+ llmResponse: r
2290
+ }), await r.execute(), this.setAIResponseStatus("user-reviewing");
2291
+ } catch (i) {
2292
+ this.setAIResponseStatus({
2293
+ status: "error",
2294
+ error: i
2295
+ }), console.warn("Error calling LLM", i);
2296
+ }
2297
+ return r;
2298
+ }
2299
+ }
2300
+ function ar(e) {
2301
+ return (t) => new Ye(t, e);
2302
+ }
2303
+ function O(e) {
2304
+ return e.extension(Ye);
2305
+ }
2306
+ const ko = (e, t) => async (o, r) => {
2307
+ const n = new Request(o, r), i = new Request(
2308
+ `${e}?provider=${encodeURIComponent(
2309
+ t
2310
+ )}&url=${encodeURIComponent(n.url)}`,
2311
+ {
2312
+ headers: n.headers,
2313
+ // if we just pass request.body, it's a readablestream which is not visible in chrome inspector,
2314
+ // so use init?.body instead if it's available to make debugging easier
2315
+ body: (r == null ? void 0 : r.body) || n.body,
2316
+ method: n.method,
2317
+ duplex: "half"
2318
+ }
2319
+ );
2320
+ try {
2321
+ return await fetch(i);
2322
+ } catch (a) {
2323
+ throw new TypeError("fetch failed", {
2324
+ cause: a
2325
+ });
2326
+ }
2327
+ };
2328
+ function cr(e) {
2329
+ return {
2330
+ /**
2331
+ * Get settings for AI SDK providers. Pass the returned objects when creating the AI SDK provider, e.g.:
2332
+ *
2333
+ * createOpenAI({
2334
+ * ...client.getProviderSettings("openai"),
2335
+ * })("gpt-4o-2024-08-06", {});
2336
+ *
2337
+ * Explanation: we override the `fetch` and `apiKey` parameters of the AI SDK provider to instead
2338
+ * use the BlockNote AI server to proxy requests to the provider.
2339
+ *
2340
+ * Note: the `apiKey` is the API key for the @blocknote/xl-ai-server AI server, not the model provider.
2341
+ * The correct API key for the model provider will be added by the BlockNote AI server.
2342
+ */
2343
+ getProviderSettings: (t) => ({
2344
+ apiKey: e.apiKey,
2345
+ fetch: ko(e.baseURL, t)
2346
+ })
2347
+ };
2348
+ }
2349
+ var Ge = {
2350
+ color: void 0,
2351
+ size: void 0,
2352
+ className: void 0,
2353
+ style: void 0,
2354
+ attr: void 0
2355
+ }, Te = B.createContext && /* @__PURE__ */ B.createContext(Ge), bo = ["attr", "size", "title"];
2356
+ function So(e, t) {
2357
+ if (e == null) return {};
2358
+ var o = wo(e, t), r, n;
2359
+ if (Object.getOwnPropertySymbols) {
2360
+ var i = Object.getOwnPropertySymbols(e);
2361
+ for (n = 0; n < i.length; n++)
2362
+ r = i[n], !(t.indexOf(r) >= 0) && Object.prototype.propertyIsEnumerable.call(e, r) && (o[r] = e[r]);
2363
+ }
2364
+ return o;
2365
+ }
2366
+ function wo(e, t) {
2367
+ if (e == null) return {};
2368
+ var o = {};
2369
+ for (var r in e)
2370
+ if (Object.prototype.hasOwnProperty.call(e, r)) {
2371
+ if (t.indexOf(r) >= 0) continue;
2372
+ o[r] = e[r];
2373
+ }
2374
+ return o;
2375
+ }
2376
+ function q() {
2377
+ return q = Object.assign ? Object.assign.bind() : function(e) {
2378
+ for (var t = 1; t < arguments.length; t++) {
2379
+ var o = arguments[t];
2380
+ for (var r in o)
2381
+ Object.prototype.hasOwnProperty.call(o, r) && (e[r] = o[r]);
2382
+ }
2383
+ return e;
2384
+ }, q.apply(this, arguments);
2385
+ }
2386
+ function ve(e, t) {
2387
+ var o = Object.keys(e);
2388
+ if (Object.getOwnPropertySymbols) {
2389
+ var r = Object.getOwnPropertySymbols(e);
2390
+ t && (r = r.filter(function(n) {
2391
+ return Object.getOwnPropertyDescriptor(e, n).enumerable;
2392
+ })), o.push.apply(o, r);
2393
+ }
2394
+ return o;
2395
+ }
2396
+ function z(e) {
2397
+ for (var t = 1; t < arguments.length; t++) {
2398
+ var o = arguments[t] != null ? arguments[t] : {};
2399
+ t % 2 ? ve(Object(o), !0).forEach(function(r) {
2400
+ To(e, r, o[r]);
2401
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(o)) : ve(Object(o)).forEach(function(r) {
2402
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(o, r));
2403
+ });
2404
+ }
2405
+ return e;
2406
+ }
2407
+ function To(e, t, o) {
2408
+ return t = vo(t), t in e ? Object.defineProperty(e, t, { value: o, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = o, e;
2409
+ }
2410
+ function vo(e) {
2411
+ var t = Co(e, "string");
2412
+ return typeof t == "symbol" ? t : t + "";
2413
+ }
2414
+ function Co(e, t) {
2415
+ if (typeof e != "object" || !e) return e;
2416
+ var o = e[Symbol.toPrimitive];
2417
+ if (o !== void 0) {
2418
+ var r = o.call(e, t);
2419
+ if (typeof r != "object") return r;
2420
+ throw new TypeError("@@toPrimitive must return a primitive value.");
2421
+ }
2422
+ return (t === "string" ? String : Number)(e);
2423
+ }
2424
+ function Ke(e) {
2425
+ return e && e.map((t, o) => /* @__PURE__ */ B.createElement(t.tag, z({
2426
+ key: o
2427
+ }, t.attr), Ke(t.child)));
2428
+ }
2429
+ function v(e) {
2430
+ return (t) => /* @__PURE__ */ B.createElement(Po, q({
2431
+ attr: z({}, e.attr)
2432
+ }, t), Ke(e.child));
2433
+ }
2434
+ function Po(e) {
2435
+ var t = (o) => {
2436
+ var {
2437
+ attr: r,
2438
+ size: n,
2439
+ title: i
2440
+ } = e, a = So(e, bo), s = n || o.size || "1em", c;
2441
+ return o.className && (c = o.className), e.className && (c = (c ? c + " " : "") + e.className), /* @__PURE__ */ B.createElement("svg", q({
2442
+ stroke: "currentColor",
2443
+ fill: "currentColor",
2444
+ strokeWidth: "0"
2445
+ }, o.attr, r, a, {
2446
+ className: c,
2447
+ style: z(z({
2448
+ color: e.color || o.color
2449
+ }, o.style), e.style),
2450
+ height: s,
2451
+ width: s,
2452
+ xmlns: "http://www.w3.org/2000/svg"
2453
+ }), i && /* @__PURE__ */ B.createElement("title", null, i), e.children);
2454
+ };
2455
+ return Te !== void 0 ? /* @__PURE__ */ B.createElement(Te.Consumer, null, (o) => t(o)) : t(Ge);
2456
+ }
2457
+ function Xe(e) {
2458
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M8 7V11L2 6L8 1V5H13C17.4183 5 21 8.58172 21 13C21 17.4183 17.4183 21 13 21H4V19H13C16.3137 19 19 16.3137 19 13C19 9.68629 16.3137 7 13 7H8Z" }, child: [] }] })(e);
2459
+ }
2460
+ function Ce(e) {
2461
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M17.8492 11.6983L17.1421 10.9912L7.24264 20.8907H3V16.648L14.3137 5.33432L19.9706 10.9912C20.3611 11.3817 20.3611 12.0149 19.9706 12.4054L12.8995 19.4765L11.4853 18.0622L17.8492 11.6983ZM15.7279 9.57696L14.3137 8.16274L5 17.4765V18.8907H6.41421L15.7279 9.57696ZM18.5563 2.50589L21.3848 5.33432C21.7753 5.72484 21.7753 6.35801 21.3848 6.74853L19.9706 8.16274L15.7279 3.9201L17.1421 2.50589C17.5327 2.11537 18.1658 2.11537 18.5563 2.50589Z" }, child: [] }] })(e);
2462
+ }
2463
+ function Oo(e) {
2464
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M15.1986 9.94447C14.7649 9.5337 14.4859 8.98613 14.4085 8.39384L14.0056 5.31138L11.275 6.79724C10.7503 7.08274 10.1433 7.17888 9.55608 7.06948L6.49998 6.50015L7.06931 9.55625C7.17871 10.1435 7.08257 10.7505 6.79707 11.2751L5.31121 14.0057L8.39367 14.4086C8.98596 14.4861 9.53353 14.7651 9.94431 15.1987L12.0821 17.4557L13.4178 14.6486C13.6745 14.1092 14.109 13.6747 14.6484 13.418L17.4555 12.0823L15.1986 9.94447ZM15.2238 15.5079L13.0111 20.1581C12.8687 20.4573 12.5107 20.5844 12.2115 20.442C12.1448 20.4103 12.0845 20.3665 12.0337 20.3129L8.49229 16.5741C8.39749 16.474 8.27113 16.4096 8.13445 16.3918L3.02816 15.7243C2.69958 15.6814 2.46804 15.3802 2.51099 15.0516C2.52056 14.9784 2.54359 14.9075 2.5789 14.8426L5.04031 10.3192C5.1062 10.1981 5.12839 10.058 5.10314 9.92253L4.16 4.85991C4.09931 4.53414 4.3142 4.22086 4.63997 4.16017C4.7126 4.14664 4.78711 4.14664 4.85974 4.16017L9.92237 5.10331C10.0579 5.12855 10.198 5.10637 10.319 5.04048L14.8424 2.57907C15.1335 2.42068 15.4979 2.52825 15.6562 2.81931C15.6916 2.88421 15.7146 2.95507 15.7241 3.02833L16.3916 8.13462C16.4095 8.2713 16.4739 8.39766 16.5739 8.49245L20.3127 12.0338C20.5533 12.2617 20.5636 12.6415 20.3357 12.8821C20.2849 12.9357 20.2246 12.9795 20.1579 13.0112L15.5078 15.224C15.3833 15.2832 15.283 15.3835 15.2238 15.5079ZM16.0206 17.435L17.4348 16.0208L21.6775 20.2634L20.2633 21.6776L16.0206 17.435Z" }, child: [] }] })(e);
2465
+ }
2466
+ function Mo(e) {
2467
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M8.00008 6V9H5.00008V6H8.00008ZM3.00008 4V11H10.0001V4H3.00008ZM13.0001 4H21.0001V6H13.0001V4ZM13.0001 11H21.0001V13H13.0001V11ZM13.0001 18H21.0001V20H13.0001V18ZM10.7072 16.2071L9.29297 14.7929L6.00008 18.0858L4.20718 16.2929L2.79297 17.7071L6.00008 20.9142L10.7072 16.2071Z" }, child: [] }] })(e);
2468
+ }
2469
+ function Bo(e) {
2470
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M15 18H16.5C17.8807 18 19 16.8807 19 15.5C19 14.1193 17.8807 13 16.5 13H3V11H16.5C18.9853 11 21 13.0147 21 15.5C21 17.9853 18.9853 20 16.5 20H15V22L11 19L15 16V18ZM3 4H21V6H3V4ZM9 18V20H3V18H9Z" }, child: [] }] })(e);
2471
+ }
2472
+ function Lo(e) {
2473
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M13 6V21H11V6H5V4H19V6H13Z" }, child: [] }] })(e);
2474
+ }
2475
+ function xo(e) {
2476
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M6.23509 6.45329C4.85101 7.89148 4 9.84636 4 12C4 16.4183 7.58172 20 12 20C13.0808 20 14.1116 19.7857 15.0521 19.3972C15.1671 18.6467 14.9148 17.9266 14.8116 17.6746C14.582 17.115 13.8241 16.1582 12.5589 14.8308C12.2212 14.4758 12.2429 14.2035 12.3636 13.3943L12.3775 13.3029C12.4595 12.7486 12.5971 12.4209 14.4622 12.1248C15.4097 11.9746 15.6589 12.3533 16.0043 12.8777C16.0425 12.9358 16.0807 12.9928 16.1198 13.0499C16.4479 13.5297 16.691 13.6394 17.0582 13.8064C17.2227 13.881 17.428 13.9751 17.7031 14.1314C18.3551 14.504 18.3551 14.9247 18.3551 15.8472V15.9518C18.3551 16.3434 18.3168 16.6872 18.2566 16.9859C19.3478 15.6185 20 13.8854 20 12C20 8.70089 18.003 5.8682 15.1519 4.64482C14.5987 5.01813 13.8398 5.54726 13.575 5.91C13.4396 6.09538 13.2482 7.04166 12.6257 7.11976C12.4626 7.14023 12.2438 7.12589 12.012 7.11097C11.3905 7.07058 10.5402 7.01606 10.268 7.75495C10.0952 8.2232 10.0648 9.49445 10.6239 10.1543C10.7134 10.2597 10.7307 10.4547 10.6699 10.6735C10.59 10.9608 10.4286 11.1356 10.3783 11.1717C10.2819 11.1163 10.0896 10.8931 9.95938 10.7412C9.64554 10.3765 9.25405 9.92233 8.74797 9.78176C8.56395 9.73083 8.36166 9.68867 8.16548 9.64736C7.6164 9.53227 6.99443 9.40134 6.84992 9.09302C6.74442 8.8672 6.74488 8.55621 6.74529 8.22764C6.74529 7.8112 6.74529 7.34029 6.54129 6.88256C6.46246 6.70541 6.35689 6.56446 6.23509 6.45329ZM12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22Z" }, child: [] }] })(e);
2477
+ }
2478
+ function _o(e) {
2479
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M9.9997 15.1709L19.1921 5.97852L20.6063 7.39273L9.9997 17.9993L3.63574 11.6354L5.04996 10.2212L9.9997 15.1709Z" }, child: [] }] })(e);
2480
+ }
2481
+ function Io(e) {
2482
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M9.9997 15.1709L19.1921 5.97852L20.6063 7.39273L9.9997 17.9993L3.63574 11.6354L5.04996 10.2212L9.9997 15.1709Z" }, child: [] }] })(e);
2483
+ }
2484
+ function Eo(e) {
2485
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M12 4C9.4095 4 7.10606 5.23053 5.64274 7.14274L8 9.5H2V3.5L4.21863 5.71863C6.05061 3.452 8.85558 2 12 2 17.5228 2 22 6.47715 22 12H20C20 7.58172 16.4183 4 12 4ZM4 12C4 16.4183 7.58172 20 12 20 14.5905 20 16.894 18.7695 18.3573 16.8573L16 14.5 22 14.5V20.5L19.7814 18.2814C17.9494 20.548 15.1444 22 12 22 6.47715 22 2 17.5228 2 12H4Z" }, child: [] }] })(e);
2486
+ }
2487
+ function ne(e) {
2488
+ return v({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M17.0007 1.20825 18.3195 3.68108 20.7923 4.99992 18.3195 6.31876 17.0007 8.79159 15.6818 6.31876 13.209 4.99992 15.6818 3.68108 17.0007 1.20825ZM8.00065 4.33325 10.6673 9.33325 15.6673 11.9999 10.6673 14.6666 8.00065 19.6666 5.33398 14.6666.333984 11.9999 5.33398 9.33325 8.00065 4.33325ZM19.6673 16.3333 18.0007 13.2083 16.334 16.3333 13.209 17.9999 16.334 19.6666 18.0007 22.7916 19.6673 19.6666 22.7923 17.9999 19.6673 16.3333Z" }, child: [] }] })(e);
2489
+ }
2490
+ function _(e) {
2491
+ if (!e.dictionary.ai)
2492
+ throw new Error("AI dictionary not found");
2493
+ return e.dictionary.ai;
2494
+ }
2495
+ function Qe() {
2496
+ const e = Ct();
2497
+ return _(e.editor);
2498
+ }
2499
+ const No = (e) => {
2500
+ const t = G(), { onManualPromptSubmit: o, promptText: r, onPromptTextChange: n } = e, [i, a] = Ee(""), s = r || i, c = $(
2501
+ async (d) => {
2502
+ d.key === "Enter" && o(s);
2503
+ },
2504
+ [s, o]
2505
+ ), u = $(
2506
+ (d) => {
2507
+ const S = d.currentTarget.value;
2508
+ n && n(S), r === void 0 && a(S);
2509
+ },
2510
+ [n, a, r]
2511
+ ), p = I(() => ut(e.items, s), [s, e.items]), { selectedIndex: l, setSelectedIndex: m, handler: f } = Pt(p, (d) => d.onItemClick()), h = $(
2512
+ (d) => {
2513
+ d.key === "Enter" ? p.length > 0 ? f(d) : c(d) : f(d);
2514
+ },
2515
+ [c, f, p.length]
2516
+ );
2517
+ return Ne(() => {
2518
+ m(0);
2519
+ }, [s, m]), /* @__PURE__ */ vt("div", { className: "bn-combobox", children: [
2520
+ /* @__PURE__ */ y(t.Generic.Form.Root, { children: /* @__PURE__ */ y(
2521
+ t.Generic.Form.TextInput,
2522
+ {
2523
+ className: "bn-combobox-input",
2524
+ name: "ai-prompt",
2525
+ variant: "large",
2526
+ icon: e.icon,
2527
+ value: s || "",
2528
+ autoFocus: !0,
2529
+ placeholder: e.placeholder,
2530
+ disabled: e.disabled,
2531
+ onKeyDown: h,
2532
+ onChange: u,
2533
+ autoComplete: "off",
2534
+ rightSection: e.rightSection
2535
+ },
2536
+ "input-" + e.disabled
2537
+ ) }),
2538
+ /* @__PURE__ */ y(
2539
+ t.SuggestionMenu.Root,
2540
+ {
2541
+ className: "bn-combobox-items",
2542
+ id: "ai-suggestion-menu",
2543
+ children: p.map((d, S) => /* @__PURE__ */ y(
2544
+ t.SuggestionMenu.Item,
2545
+ {
2546
+ className: dt(
2547
+ "bn-suggestion-menu-item",
2548
+ d.size === "small" ? "bn-suggestion-menu-item-small" : ""
2549
+ ),
2550
+ id: `bn-suggestion-menu-item-${S}`,
2551
+ isSelected: S === l,
2552
+ onClick: d.onItemClick,
2553
+ item: d
2554
+ },
2555
+ d.title
2556
+ ))
2557
+ }
2558
+ )
2559
+ ] });
2560
+ };
2561
+ function Ao(e) {
2562
+ const t = _(e), o = O(e);
2563
+ return [
2564
+ {
2565
+ key: "continue_writing",
2566
+ title: t.ai_default_commands.continue_writing.title,
2567
+ aliases: t.ai_default_commands.continue_writing.aliases,
2568
+ icon: /* @__PURE__ */ y(Ce, { size: 18 }),
2569
+ onItemClick: async () => {
2570
+ await o.callLLM({
2571
+ userPrompt: "Continue writing: write more text at the current cursor position related to the previous text",
2572
+ // By default, LLM will be able to add / update / delete blocks. For "continue writing", we only want to allow adding new blocks.
2573
+ defaultStreamTools: {
2574
+ add: !0,
2575
+ delete: !1,
2576
+ update: !1
2577
+ }
2578
+ });
2579
+ },
2580
+ size: "small"
2581
+ },
2582
+ {
2583
+ key: "summarize",
2584
+ title: t.ai_default_commands.summarize.title,
2585
+ aliases: t.ai_default_commands.summarize.aliases,
2586
+ icon: /* @__PURE__ */ y(Bo, { size: 18 }),
2587
+ onItemClick: async () => {
2588
+ await o.callLLM({
2589
+ userPrompt: "Summarize",
2590
+ // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
2591
+ defaultStreamTools: {
2592
+ add: !0,
2593
+ delete: !1,
2594
+ update: !1
2595
+ }
2596
+ });
2597
+ },
2598
+ size: "small"
2599
+ },
2600
+ {
2601
+ key: "action_items",
2602
+ title: t.ai_default_commands.add_action_items.title,
2603
+ aliases: t.ai_default_commands.add_action_items.aliases,
2604
+ icon: /* @__PURE__ */ y(Mo, { size: 18 }),
2605
+ onItemClick: async () => {
2606
+ await o.callLLM({
2607
+ userPrompt: "Add action items",
2608
+ // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
2609
+ defaultStreamTools: {
2610
+ add: !0,
2611
+ delete: !1,
2612
+ update: !1
2613
+ }
2614
+ });
2615
+ },
2616
+ size: "small"
2617
+ },
2618
+ {
2619
+ key: "write_anything",
2620
+ title: t.ai_default_commands.write_anything.title,
2621
+ aliases: t.ai_default_commands.write_anything.aliases,
2622
+ icon: /* @__PURE__ */ y(Ce, { size: 18 }),
2623
+ onItemClick: (r) => {
2624
+ r(t.ai_default_commands.write_anything.prompt_placeholder);
2625
+ },
2626
+ size: "small"
2627
+ }
2628
+ ];
2629
+ }
2630
+ function jo(e) {
2631
+ const t = _(e), o = O(e);
2632
+ return [
2633
+ {
2634
+ key: "improve_writing",
2635
+ title: t.ai_default_commands.improve_writing.title,
2636
+ aliases: t.ai_default_commands.improve_writing.aliases,
2637
+ icon: /* @__PURE__ */ y(Lo, { size: 18 }),
2638
+ onItemClick: async () => {
2639
+ await o.callLLM({
2640
+ useSelection: !0,
2641
+ userPrompt: "Improve writing",
2642
+ // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
2643
+ defaultStreamTools: {
2644
+ add: !1,
2645
+ delete: !1,
2646
+ update: !0
2647
+ }
2648
+ });
2649
+ },
2650
+ size: "small"
2651
+ },
2652
+ {
2653
+ key: "fix_spelling",
2654
+ title: t.ai_default_commands.fix_spelling.title,
2655
+ aliases: t.ai_default_commands.fix_spelling.aliases,
2656
+ icon: /* @__PURE__ */ y(Io, { size: 18 }),
2657
+ onItemClick: async () => {
2658
+ await o.callLLM({
2659
+ useSelection: !0,
2660
+ userPrompt: "Fix spelling",
2661
+ // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
2662
+ defaultStreamTools: {
2663
+ add: !1,
2664
+ delete: !1,
2665
+ update: !0
2666
+ }
2667
+ });
2668
+ },
2669
+ size: "small"
2670
+ },
2671
+ {
2672
+ key: "translate",
2673
+ title: t.ai_default_commands.translate.title,
2674
+ aliases: t.ai_default_commands.translate.aliases,
2675
+ icon: /* @__PURE__ */ y(xo, { size: 18 }),
2676
+ onItemClick: (r) => {
2677
+ r(t.ai_default_commands.translate.prompt_placeholder);
2678
+ },
2679
+ size: "small"
2680
+ },
2681
+ {
2682
+ key: "simplify",
2683
+ title: t.ai_default_commands.simplify.title,
2684
+ aliases: t.ai_default_commands.simplify.aliases,
2685
+ icon: /* @__PURE__ */ y(Oo, { size: 18 }),
2686
+ onItemClick: async () => {
2687
+ await o.callLLM({
2688
+ useSelection: !0,
2689
+ userPrompt: "Simplify",
2690
+ // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
2691
+ defaultStreamTools: {
2692
+ add: !1,
2693
+ delete: !1,
2694
+ update: !0
2695
+ }
2696
+ });
2697
+ },
2698
+ size: "small"
2699
+ }
2700
+ ];
2701
+ }
2702
+ function $o(e) {
2703
+ const t = _(e), o = O(e);
2704
+ return [
2705
+ {
2706
+ key: "accept",
2707
+ title: t.ai_menu.actions.accept.title,
2708
+ aliases: t.ai_menu.actions.accept.aliases,
2709
+ icon: /* @__PURE__ */ y(_o, { size: 18 }),
2710
+ onItemClick: () => {
2711
+ o.acceptChanges();
2712
+ },
2713
+ size: "small"
2714
+ },
2715
+ {
2716
+ key: "revert",
2717
+ title: t.ai_menu.actions.revert.title,
2718
+ aliases: t.ai_menu.actions.revert.aliases,
2719
+ icon: /* @__PURE__ */ y(Xe, { size: 18 }),
2720
+ onItemClick: () => {
2721
+ o.rejectChanges();
2722
+ },
2723
+ size: "small"
2724
+ }
2725
+ ];
2726
+ }
2727
+ function Do(e) {
2728
+ const t = _(e), o = O(e);
2729
+ return [
2730
+ {
2731
+ key: "retry",
2732
+ title: t.ai_menu.actions.retry.title,
2733
+ aliases: t.ai_menu.actions.retry.aliases,
2734
+ icon: /* @__PURE__ */ y(Eo, { size: 18 }),
2735
+ onItemClick: async () => {
2736
+ await o.retry();
2737
+ },
2738
+ size: "small"
2739
+ },
2740
+ {
2741
+ key: "cancel",
2742
+ title: t.ai_menu.actions.cancel.title,
2743
+ aliases: t.ai_menu.actions.cancel.aliases,
2744
+ icon: /* @__PURE__ */ y(Xe, { size: 18 }),
2745
+ onItemClick: () => {
2746
+ o.rejectChanges();
2747
+ },
2748
+ size: "small"
2749
+ }
2750
+ ];
2751
+ }
2752
+ function Ro(e, t) {
2753
+ return t === "user-input" ? e.getSelection() ? jo(e) : Ao(e) : t === "user-reviewing" ? $o(e) : t === "error" ? Do(e) : [];
2754
+ }
2755
+ const Ho = (e) => {
2756
+ const t = K(), [o, r] = Ee(""), n = Qe(), i = G(), a = O(t), s = Ae(
2757
+ a.store,
2758
+ (f) => f.aiMenuState !== "closed" ? f.aiMenuState.status : "closed"
2759
+ ), { items: c } = e, u = I(() => {
2760
+ let f = [];
2761
+ return c ? f = c(t, s) : f = Ro(t, s), f.map((h) => ({
2762
+ ...h,
2763
+ onItemClick: () => {
2764
+ h.onItemClick(r);
2765
+ }
2766
+ }));
2767
+ }, [c, s, t]), p = $(
2768
+ async (f) => {
2769
+ await a.callLLM({
2770
+ userPrompt: f,
2771
+ useSelection: t.getSelection() !== void 0
2772
+ });
2773
+ },
2774
+ [a, t]
2775
+ );
2776
+ Ne(() => {
2777
+ (s === "user-reviewing" || s === "error") && r("");
2778
+ }, [s]);
2779
+ const l = I(() => s === "thinking" ? n.ai_menu.status.thinking : s === "ai-writing" ? n.ai_menu.status.editing : s === "error" ? n.ai_menu.status.error : n.ai_menu.input_placeholder, [s, n]), m = I(() => {
2780
+ if (s === "thinking" || s === "ai-writing")
2781
+ return /* @__PURE__ */ y(
2782
+ i.SuggestionMenu.Loader,
2783
+ {
2784
+ className: "bn-suggestion-menu-loader bn-combobox-right-section"
2785
+ }
2786
+ );
2787
+ if (s === "error")
2788
+ return /* @__PURE__ */ y("div", { className: "bn-combobox-right-section bn-combobox-error", children: /* @__PURE__ */ y(
2789
+ "svg",
2790
+ {
2791
+ xmlns: "http://www.w3.org/2000/svg",
2792
+ height: "1em",
2793
+ viewBox: "0 -960 960 960",
2794
+ width: "1em",
2795
+ fill: "currentColor",
2796
+ children: /* @__PURE__ */ y("path", { d: "M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm0-160q17 0 28.5-11.5T520-480v-160q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640v160q0 17 11.5 28.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" })
2797
+ }
2798
+ ) });
2799
+ }, [i, s]);
2800
+ return /* @__PURE__ */ y(
2801
+ No,
2802
+ {
2803
+ onManualPromptSubmit: e.onManualPromptSubmit || p,
2804
+ items: u,
2805
+ promptText: o,
2806
+ onPromptTextChange: r,
2807
+ placeholder: l,
2808
+ disabled: s === "thinking" || s === "ai-writing",
2809
+ icon: /* @__PURE__ */ y("div", { className: "bn-combobox-icon", children: /* @__PURE__ */ y(ne, {}) }),
2810
+ rightSection: m
2811
+ }
2812
+ );
2813
+ }, qo = (e) => {
2814
+ const t = e.blockID ? document.querySelector(`[data-id="${e.blockID}"]`) : void 0, o = I(() => t ? {
2815
+ getBoundingClientRect: () => t.getBoundingClientRect(),
2816
+ contextElement: t
2817
+ } : null, [t]), { isMounted: r, ref: n, style: i, getFloatingProps: a, isPositioned: s } = Ot(!!t, o, 3e3, {
2818
+ canDismiss: {
2819
+ enabled: !0,
2820
+ escapeKey: !0,
2821
+ outsidePress: e.canDismissViaOutsidePress
2822
+ },
2823
+ placement: "bottom",
2824
+ middleware: [
2825
+ Mt(10),
2826
+ // flip(),
2827
+ Bt({
2828
+ apply({ rects: c, elements: u }) {
2829
+ Object.assign(u.floating.style, {
2830
+ width: `${c.reference.width}px`
2831
+ });
2832
+ }
2833
+ })
2834
+ ],
2835
+ onOpenChange: e.onOpenChange,
2836
+ whileElementsMounted: (c, u, p) => Lt(c, u, p, {
2837
+ animationFrame: !0
2838
+ })
2839
+ });
2840
+ return r ? /* @__PURE__ */ y(
2841
+ "div",
2842
+ {
2843
+ ref: n,
2844
+ style: {
2845
+ ...i
2846
+ },
2847
+ ...a(),
2848
+ children: s && e.children
2849
+ }
2850
+ ) : null;
2851
+ }, lr = (e) => {
2852
+ const t = K(), o = O(t), r = Ae(o.store, (a) => a.aiMenuState), n = r === "closed" ? void 0 : r.blockId, i = e.aiMenu || Ho;
2853
+ return /* @__PURE__ */ y(
2854
+ qo,
2855
+ {
2856
+ canDismissViaOutsidePress: r === "closed" || r.status === "user-input",
2857
+ blockID: n,
2858
+ onOpenChange: (a) => {
2859
+ a || r === "closed" || (r.status === "user-input" ? o.closeAIMenu() : (r.status === "user-reviewing" || r.status === "error") && o.rejectChanges());
2860
+ },
2861
+ children: /* @__PURE__ */ y(i, {})
2862
+ }
2863
+ );
2864
+ }, ur = () => {
2865
+ const e = Qe(), t = G(), o = K(), r = O(o), n = () => {
2866
+ o.formattingToolbar.closeMenu();
2867
+ const i = o.getSelection();
2868
+ if (!i)
2869
+ throw new Error("No selection");
2870
+ const a = i.blocks[i.blocks.length - 1].id;
2871
+ r.openAIMenuAtBlock(a);
2872
+ };
2873
+ return o.isEditable ? /* @__PURE__ */ y(
2874
+ t.Generic.Toolbar.Button,
2875
+ {
2876
+ className: "bn-button",
2877
+ label: e.formatting_toolbar.ai.tooltip,
2878
+ mainTooltip: e.formatting_toolbar.ai.tooltip,
2879
+ icon: /* @__PURE__ */ y(ne, {}),
2880
+ onClick: n
2881
+ }
2882
+ ) : null;
2883
+ }, zo = {
2884
+ AI: ne
2885
+ };
2886
+ function dr(e) {
2887
+ const t = O(e);
2888
+ return [
2889
+ {
2890
+ key: "ai",
2891
+ onItemClick: () => {
2892
+ const r = e.getTextCursorPosition();
2893
+ r.block.content && Array.isArray(r.block.content) && // isarray check not ideal
2894
+ r.block.content.length === 0 && r.prevBlock ? t.openAIMenuAtBlock(r.prevBlock.id) : t.openAIMenuAtBlock(r.block.id);
2895
+ },
2896
+ ..._(e).slash_menu.ai,
2897
+ icon: /* @__PURE__ */ y(zo.AI, {})
2898
+ }
2899
+ ];
2900
+ }
2901
+ export {
2902
+ Ye as AIExtension,
2903
+ Ho as AIMenu,
2904
+ lr as AIMenuController,
2905
+ ur as AIToolbarButton,
2906
+ qo as BlockPositioner,
2907
+ No as PromptSuggestionMenu,
2908
+ Gt as callLLM,
2909
+ ar as createAIExtension,
2910
+ cr as createBlockNoteAIClient,
2911
+ _ as getAIDictionary,
2912
+ O as getAIExtension,
2913
+ dr as getAISlashMenuItems,
2914
+ Ro as getDefaultAIMenuItems,
2915
+ mo as llmFormats,
2916
+ ir as promptHelpers
2917
+ };
2918
+ //# sourceMappingURL=blocknote-xl-ai.js.map