@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
package/LICENSE ADDED
@@ -0,0 +1,373 @@
1
+ Mozilla Public License Version 2.0
2
+ ==================================
3
+
4
+ 1. Definitions
5
+ --------------
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, import, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You. For
80
+ purposes of this definition, "control" means (a) the power, direct
81
+ or indirect, to cause the direction or management of such entity,
82
+ whether by contract or otherwise, or (b) ownership of more than
83
+ fifty percent (50%) of the outstanding shares or beneficial
84
+ ownership of such entity.
85
+
86
+ 2. License Grants and Conditions
87
+ --------------------------------
88
+
89
+ 2.1. Grants
90
+
91
+ Each Contributor hereby grants You a world-wide, royalty-free,
92
+ non-exclusive license:
93
+
94
+ (a) under intellectual property rights (other than patent or trademark)
95
+ Licensable by such Contributor to use, reproduce, make available,
96
+ modify, display, perform, distribute, and otherwise exploit its
97
+ Contributions, either on an unmodified basis, with Modifications, or
98
+ as part of a Larger Work; and
99
+
100
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
101
+ for sale, have made, import, and otherwise transfer either its
102
+ Contributions or its Contributor Version.
103
+
104
+ 2.2. Effective Date
105
+
106
+ The licenses granted in Section 2.1 with respect to any Contribution
107
+ become effective for each Contribution on the date the Contributor first
108
+ distributes such Contribution.
109
+
110
+ 2.3. Limitations on Grant Scope
111
+
112
+ The licenses granted in this Section 2 are the only rights granted under
113
+ this License. No additional rights or licenses will be implied from the
114
+ distribution or licensing of Covered Software under this License.
115
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
116
+ Contributor:
117
+
118
+ (a) for any code that a Contributor has removed from Covered Software;
119
+ or
120
+
121
+ (b) for infringements caused by: (i) Your and any other third party's
122
+ modifications of Covered Software, or (ii) the combination of its
123
+ Contributions with other software (except as part of its Contributor
124
+ Version); or
125
+
126
+ (c) under Patent Claims infringed by Covered Software in the absence of
127
+ its Contributions.
128
+
129
+ This License does not grant any rights in the trademarks, service marks,
130
+ or logos of any Contributor (except as may be necessary to comply with
131
+ the notice requirements in Section 3.4).
132
+
133
+ 2.4. Subsequent Licenses
134
+
135
+ No Contributor makes additional grants as a result of Your choice to
136
+ distribute the Covered Software under a subsequent version of this
137
+ License (see Section 10.2) or under the terms of a Secondary License (if
138
+ permitted under the terms of Section 3.3).
139
+
140
+ 2.5. Representation
141
+
142
+ Each Contributor represents that the Contributor believes its
143
+ Contributions are its original creation(s) or it has sufficient rights
144
+ to grant the rights to its Contributions conveyed by this License.
145
+
146
+ 2.6. Fair Use
147
+
148
+ This License is not intended to limit any rights You have under
149
+ applicable copyright doctrines of fair use, fair dealing, or other
150
+ equivalents.
151
+
152
+ 2.7. Conditions
153
+
154
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
+ in Section 2.1.
156
+
157
+ 3. Responsibilities
158
+ -------------------
159
+
160
+ 3.1. Distribution of Source Form
161
+
162
+ All distribution of Covered Software in Source Code Form, including any
163
+ Modifications that You create or to which You contribute, must be under
164
+ the terms of this License. You must inform recipients that the Source
165
+ Code Form of the Covered Software is governed by the terms of this
166
+ License, and how they can obtain a copy of this License. You may not
167
+ attempt to alter or restrict the recipients' rights in the Source Code
168
+ Form.
169
+
170
+ 3.2. Distribution of Executable Form
171
+
172
+ If You distribute Covered Software in Executable Form then:
173
+
174
+ (a) such Covered Software must also be made available in Source Code
175
+ Form, as described in Section 3.1, and You must inform recipients of
176
+ the Executable Form how they can obtain a copy of such Source Code
177
+ Form by reasonable means in a timely manner, at a charge no more
178
+ than the cost of distribution to the recipient; and
179
+
180
+ (b) You may distribute such Executable Form under the terms of this
181
+ License, or sublicense it under different terms, provided that the
182
+ license for the Executable Form does not attempt to limit or alter
183
+ the recipients' rights in the Source Code Form under this License.
184
+
185
+ 3.3. Distribution of a Larger Work
186
+
187
+ You may create and distribute a Larger Work under terms of Your choice,
188
+ provided that You also comply with the requirements of this License for
189
+ the Covered Software. If the Larger Work is a combination of Covered
190
+ Software with a work governed by one or more Secondary Licenses, and the
191
+ Covered Software is not Incompatible With Secondary Licenses, this
192
+ License permits You to additionally distribute such Covered Software
193
+ under the terms of such Secondary License(s), so that the recipient of
194
+ the Larger Work may, at their option, further distribute the Covered
195
+ Software under the terms of either this License or such Secondary
196
+ License(s).
197
+
198
+ 3.4. Notices
199
+
200
+ You may not remove or alter the substance of any license notices
201
+ (including copyright notices, patent notices, disclaimers of warranty,
202
+ or limitations of liability) contained within the Source Code Form of
203
+ the Covered Software, except that You may alter any license notices to
204
+ the extent required to remedy known factual inaccuracies.
205
+
206
+ 3.5. Application of Additional Terms
207
+
208
+ You may choose to offer, and to charge a fee for, warranty, support,
209
+ indemnity or liability obligations to one or more recipients of Covered
210
+ Software. However, You may do so only on Your own behalf, and not on
211
+ behalf of any Contributor. You must make it absolutely clear that any
212
+ such warranty, support, indemnity, or liability obligation is offered by
213
+ You alone, and You hereby agree to indemnify every Contributor for any
214
+ liability incurred by such Contributor as a result of warranty, support,
215
+ indemnity or liability terms You offer. You may include additional
216
+ disclaimers of warranty and limitations of liability specific to any
217
+ jurisdiction.
218
+
219
+ 4. Inability to Comply Due to Statute or Regulation
220
+ ---------------------------------------------------
221
+
222
+ If it is impossible for You to comply with any of the terms of this
223
+ License with respect to some or all of the Covered Software due to
224
+ statute, judicial order, or regulation then You must: (a) comply with
225
+ the terms of this License to the maximum extent possible; and (b)
226
+ describe the limitations and the code they affect. Such description must
227
+ be placed in a text file included with all distributions of the Covered
228
+ Software under this License. Except to the extent prohibited by statute
229
+ or regulation, such description must be sufficiently detailed for a
230
+ recipient of ordinary skill to be able to understand it.
231
+
232
+ 5. Termination
233
+ --------------
234
+
235
+ 5.1. The rights granted under this License will terminate automatically
236
+ if You fail to comply with any of its terms. However, if You become
237
+ compliant, then the rights granted under this License from a particular
238
+ Contributor are reinstated (a) provisionally, unless and until such
239
+ Contributor explicitly and finally terminates Your grants, and (b) on an
240
+ ongoing basis, if such Contributor fails to notify You of the
241
+ non-compliance by some reasonable means prior to 60 days after You have
242
+ come back into compliance. Moreover, Your grants from a particular
243
+ Contributor are reinstated on an ongoing basis if such Contributor
244
+ notifies You of the non-compliance by some reasonable means, this is the
245
+ first time You have received notice of non-compliance with this License
246
+ from such Contributor, and You become compliant prior to 30 days after
247
+ Your receipt of the notice.
248
+
249
+ 5.2. If You initiate litigation against any entity by asserting a patent
250
+ infringement claim (excluding declaratory judgment actions,
251
+ counter-claims, and cross-claims) alleging that a Contributor Version
252
+ directly or indirectly infringes any patent, then the rights granted to
253
+ You by any and all Contributors for the Covered Software under Section
254
+ 2.1 of this License shall terminate.
255
+
256
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257
+ end user license agreements (excluding distributors and resellers) which
258
+ have been validly granted by You or Your distributors under this License
259
+ prior to termination shall survive termination.
260
+
261
+ ************************************************************************
262
+ * *
263
+ * 6. Disclaimer of Warranty *
264
+ * ------------------------- *
265
+ * *
266
+ * Covered Software is provided under this License on an "as is" *
267
+ * basis, without warranty of any kind, either expressed, implied, or *
268
+ * statutory, including, without limitation, warranties that the *
269
+ * Covered Software is free of defects, merchantable, fit for a *
270
+ * particular purpose or non-infringing. The entire risk as to the *
271
+ * quality and performance of the Covered Software is with You. *
272
+ * Should any Covered Software prove defective in any respect, You *
273
+ * (not any Contributor) assume the cost of any necessary servicing, *
274
+ * repair, or correction. This disclaimer of warranty constitutes an *
275
+ * essential part of this License. No use of any Covered Software is *
276
+ * authorized under this License except under this disclaimer. *
277
+ * *
278
+ ************************************************************************
279
+
280
+ ************************************************************************
281
+ * *
282
+ * 7. Limitation of Liability *
283
+ * -------------------------- *
284
+ * *
285
+ * Under no circumstances and under no legal theory, whether tort *
286
+ * (including negligence), contract, or otherwise, shall any *
287
+ * Contributor, or anyone who distributes Covered Software as *
288
+ * permitted above, be liable to You for any direct, indirect, *
289
+ * special, incidental, or consequential damages of any character *
290
+ * including, without limitation, damages for lost profits, loss of *
291
+ * goodwill, work stoppage, computer failure or malfunction, or any *
292
+ * and all other commercial damages or losses, even if such party *
293
+ * shall have been informed of the possibility of such damages. This *
294
+ * limitation of liability shall not apply to liability for death or *
295
+ * personal injury resulting from such party's negligence to the *
296
+ * extent applicable law prohibits such limitation. Some *
297
+ * jurisdictions do not allow the exclusion or limitation of *
298
+ * incidental or consequential damages, so this exclusion and *
299
+ * limitation may not apply to You. *
300
+ * *
301
+ ************************************************************************
302
+
303
+ 8. Litigation
304
+ -------------
305
+
306
+ Any litigation relating to this License may be brought only in the
307
+ courts of a jurisdiction where the defendant maintains its principal
308
+ place of business and such litigation shall be governed by laws of that
309
+ jurisdiction, without reference to its conflict-of-law provisions.
310
+ Nothing in this Section shall prevent a party's ability to bring
311
+ cross-claims or counter-claims.
312
+
313
+ 9. Miscellaneous
314
+ ----------------
315
+
316
+ This License represents the complete agreement concerning the subject
317
+ matter hereof. If any provision of this License is held to be
318
+ unenforceable, such provision shall be reformed only to the extent
319
+ necessary to make it enforceable. Any law or regulation which provides
320
+ that the language of a contract shall be construed against the drafter
321
+ shall not be used to construe this License against a Contributor.
322
+
323
+ 10. Versions of the License
324
+ ---------------------------
325
+
326
+ 10.1. New Versions
327
+
328
+ Mozilla Foundation is the license steward. Except as provided in Section
329
+ 10.3, no one other than the license steward has the right to modify or
330
+ publish new versions of this License. Each version will be given a
331
+ distinguishing version number.
332
+
333
+ 10.2. Effect of New Versions
334
+
335
+ You may distribute the Covered Software under the terms of the version
336
+ of the License under which You originally received the Covered Software,
337
+ or under the terms of any subsequent version published by the license
338
+ steward.
339
+
340
+ 10.3. Modified Versions
341
+
342
+ If you create software not governed by this License, and you want to
343
+ create a new license for such software, you may create and use a
344
+ modified version of this License if you rename the license and remove
345
+ any references to the name of the license steward (except to note that
346
+ such modified license differs from this License).
347
+
348
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
349
+ Licenses
350
+
351
+ If You choose to distribute Source Code Form that is Incompatible With
352
+ Secondary Licenses under the terms of this version of the License, the
353
+ notice described in Exhibit B of this License must be attached.
354
+
355
+ Exhibit A - Source Code Form License Notice
356
+ -------------------------------------------
357
+
358
+ This Source Code Form is subject to the terms of the Mozilla Public
359
+ License, v. 2.0. If a copy of the MPL was not distributed with this
360
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
361
+
362
+ If it is not possible or desirable to put the notice in a particular
363
+ file, then You may include the notice in a location (such as a LICENSE
364
+ file in a relevant directory) where a recipient would be likely to look
365
+ for such a notice.
366
+
367
+ You may add additional accurate notices of copyright ownership.
368
+
369
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
370
+ ---------------------------------------------------------
371
+
372
+ This Source Code Form is "Incompatible With Secondary Licenses", as
373
+ defined by the Mozilla Public License, v. 2.0.
@@ -0,0 +1,20 @@
1
+ "use strict";var Ye=Object.defineProperty;var Ge=(e,t,o)=>t in e?Ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var H=(e,t,o)=>Ge(e,typeof t!="symbol"?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("@blocknote/core"),A=require("@blocknote/prosemirror-suggest-changes"),j=require("ai"),R=require("prosemirror-state"),Ke=require("prosemirror-tables"),Xe=require("lodash.isequal"),$=require("prosemirror-model"),v=require("prosemirror-transform"),K=require("prosemirror-changeset"),z=require("prosemirror-view"),Qe=require("y-prosemirror"),y=require("react/jsx-runtime"),B=require("@blocknote/react"),T=require("react"),Ce=require("zustand"),X=require("@floating-ui/react"),Pe=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},et=Pe(Xe),L=Pe(T),ue=e=>{let t;const o=new Set,r=(u,f)=>{const l=typeof u=="function"?u(t):u;if(!Object.is(l,t)){const m=t;t=f??(typeof l!="object"||l===null)?l:Object.assign({},t,l),o.forEach(p=>p(t,m))}},n=()=>t,s={setState:r,getState:n,getInitialState:()=>c,subscribe:u=>(o.add(u),()=>o.delete(u))},c=t=e(r,n,s);return s},de=e=>e?ue(e):ue;function tt(e){const{properties:t,required:o,$defs:r,...n}=e.parameters;return{schema:{type:"object",description:e.description,properties:{type:{type:"string",enum:[e.name]},...t},required:["type",...o??[]],additionalProperties:!1,...n},$defs:r}}function Oe(e){const t=e.map(r=>tt(r)),o={};for(const r of t)for(const n in r.$defs){if(o[n]&&!et.default(o[n],r.$defs[n]))throw new Error(`Duplicate, but different definition for ${n}`);o[n]=r.$defs[n]}return{type:"object",properties:{operations:{type:"array",items:{anyOf:t.map(r=>r.schema)}}},additionalProperties:!1,required:["operations"],$defs:Object.keys(o).length>0?o:void 0}}function ot(e){return new ReadableStream({async start(t){try{for await(const o of e)t.enqueue(o);t.close()}catch(o){t.error(o)}}})}function D(e){if(e.locked)throw new Error("Stream (source) is already locked and cannot be iterated.");const t=e.pipeThrough(new TransformStream);return t[Symbol.asyncIterator]=()=>{if(t.locked)throw new Error("Stream is already locked and cannot be iterated again.");const o=t.getReader();return{async next(){const{done:r,value:n}=await o.read();return r?{done:!0,value:void 0}:{done:!1,value:n}}}},t}function xe(e){return D(ot(e))}async function*rt(e){var n;let t=0,o=!0,r;for await(const i of e)if((n=i.operations)!=null&&n.length){for(let a=t;a<i.operations.length;a++){const s=i.operations[a];r=s,yield{partialOperation:s,isUpdateToPreviousOperation:a===t&&!o,isPossiblyPartial:a===i.operations.length-1},o=!1}t=i.operations.length-1}if(!r)throw new Error("No operations seen");yield{partialOperation:r,isUpdateToPreviousOperation:!0,isPossiblyPartial:!1}}async function*Me(e,t){let o=!1;for await(const r of e){const n=r.operation;n.ok?(yield{operation:n.value,isUpdateToPreviousOperation:o?!1:r.isUpdateToPreviousOperation,isPossiblyPartial:r.isPossiblyPartial},o=!1):(o=o||!r.isUpdateToPreviousOperation,t==null||t({...r,operation:n}))}}async function*Be(e,t){for await(const o of e){const r=t.find(i=>i.name===o.partialOperation.type);if(!r){yield{operation:{ok:!1,error:`No matching function for ${o.partialOperation.type}`},isUpdateToPreviousOperation:o.isUpdateToPreviousOperation,isPossiblyPartial:o.isPossiblyPartial};continue}yield{operation:r.validate(o.partialOperation),isUpdateToPreviousOperation:o.isUpdateToPreviousOperation,isPossiblyPartial:o.isPossiblyPartial}}}async function*nt(e,t){const o=Be(e,t);yield*Me(o,n=>{if(!n.isPossiblyPartial)throw new Error("invalid operation: "+n.operation.error)})}async function*st(e,t){const o=Be(e,t);yield*Me(o,n=>{throw new Error("invalid operation: "+n.operation.error)})}async function it(e,t){const{_generateObjectOptions:o,...r}=t;if(o&&("output"in o||"schema"in o))throw new Error("Cannot provide output or schema in _generateObjectOptions");const i={output:"object",schema:j.jsonSchema(Oe(e)),mode:r.model.provider==="mistral.chat"?"auto":"tool",...r,...o??{}},a=await j.generateObject(i),s=at(a.object);if(!s.ok)throw new Error(s.error);let c;return{streamObjectResult:void 0,generateObjectResult:a,get operationsSource(){return c||(c=xe(st(s.value,e))),c},async getGeneratedOperations(){return a.object}}}function at(e){if(!e||typeof e!="object"||!("operations"in e)||!Array.isArray(e.operations))return{ok:!1,error:"No operations returned"};const t=e.operations;async function*o(){for(const r of t)yield{partialOperation:r,isUpdateToPreviousOperation:!1,isPossiblyPartial:!1}}return{ok:!0,value:o()}}async function ct(e,t,o=()=>{}){const{_streamObjectOptions:r,...n}=t;if(r&&("output"in r||"schema"in r))throw new Error("Cannot provide output or schema in _streamObjectOptions");const a={output:"object",schema:j.jsonSchema(Oe(e)),mode:n.model.provider==="mistral.chat"?"auto":"tool",...n,...t._streamObjectOptions??{}},s=j.streamObject(a);let c;const[u,f]=s.fullStream.tee(),l=(async()=>{let m={operations:[]};const p=D(dt(f));for await(const h of p)h&&typeof h=="object"&&"operations"in h&&(m=h);return m})();return{streamObjectResult:s,generateObjectResult:void 0,get operationsSource(){return c||(c=xe(nt(rt(lt(ut(D(u)),o)),e))),c},async getGeneratedOperations(){return l}}}async function*lt(e,t){let o=!0;for await(const r of e)o&&(t(),o=!1),yield r}function ut(e){return D(e.pipeThrough(new TransformStream({transform(t,o){switch(t.type){case"object":o.enqueue(t.object);break;case"text-delta":case"finish":break;case"error":o.error(t.error);break;default:{const r=t;throw new Error(`Unsupported chunk type: ${r}`)}}}})))}function dt(e){return D(e.pipeThrough(new TransformStream({transform(t,o){switch(t.type){case"object":o.enqueue(t.object);break;case"text-delta":case"finish":break;case"error":break;default:{const r=t;throw new Error(`Unsupported chunk type: ${r}`)}}}})))}function oe(e){return(e.type==="paragraph"||!e.type)&&!e.content||Array.isArray(e.content)&&e.content.length===0}class pt{constructor(t,o,r){this.messages=t,this.llmResult=o,this.streamTools=r}async*applyToolCalls(){let t=this.llmResult.operationsSource;for(const o of this.streamTools)t=o.execute(t);yield*t}async execute(){for await(const t of this.applyToolCalls());}async _logToolCalls(){for await(const t of this.llmResult.operationsSource)console.log(JSON.stringify(t,null,2))}}function W(e,t){const o=e.getTextCursorPosition(),r=[];for(const n of t){const i=n.id===o.block.id;r.push({id:n.id,block:n.block}),i&&r.push({cursor:!0})}return r}async function x(e,t){return await Promise.all(e.map(async o=>({id:o.id,block:await t(o)})))}function P(e){return e.flatMap(t=>[{...t,children:[]},...P(t.children)])}function E(e){return e.map(t=>typeof t=="object"&&t&&"id"in t?{...t,id:`${t.id}$`}:t)}function ft(e,t,o=!0,r=!0){let n=0,i=e.length;if(o)for(;n<i&&t(e[n]);)n++;if(r)for(;i>n&&t(e[i-1]);)i--;return e.slice(n,i)}function Y(e,t){return ft(e,r=>oe(r),(t==null?void 0:t.trimStart)??!1,(t==null?void 0:t.trimEnd)??!0)}async function Ie(e,t){const o=Y(e.document),r=await x(P(o),async s=>e.blocksToHTMLLossy([s])),i=W(e,r).filter(s=>"cursor"in s||!(t.excludeBlockIds||[]).includes(s.id));return{htmlBlocks:E(i)}}async function _e(e,t){const o=await x(P(t.selectedBlocks),async n=>e.blocksToHTMLLossy([n]));return{htmlSelectedBlocks:E(o),htmlDocument:(await x(P(e.document),async n=>e.blocksToHTMLLossy([n]))).map(({block:n})=>({block:n}))}}function mt(e){return[{role:"system",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:"},{role:"system",content:JSON.stringify(e.htmlSelectedBlocks)},{role:"system",content:"This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"},{role:"system",content:JSON.stringify(e.htmlDocument)},{role:"system",content:"The user asks you to do the following:"},{role:"user",content:e.userPrompt}]}function ht(e){return[{role:"system",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):"},{role:"system",content:JSON.stringify(e.htmlBlocks)},{role:"system",content:"The user asks you to do the following:"},{role:"user",content:e.userPrompt},{role:"system",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).'}]}const yt=async(e,t)=>{if(t.selectedBlocks){const o=await _e(e,{selectedBlocks:t.selectedBlocks});return t.previousMessages?[...t.previousMessages,{role:"system",content:`After processing the previous response, this is the updated selection.
2
+ Ignore previous documents, you MUST issue operations against this latest version of the document:`},{role:"system",content:JSON.stringify(o.htmlSelectedBlocks)},{role:"system",content:"This is the updated entire document:"},{role:"system",content:JSON.stringify(o.htmlDocument)},{role:"system",content:`You SHOULD use "update" operations to update blocks you added / edited previously
3
+ (unless the user explicitly asks you otherwise to add or delete other blocks).
4
+
5
+ The user now asks you to do the following:`},{role:"user",content:t.userPrompt}]:mt({...o,userPrompt:t.userPrompt})}else{const o=await Ie(e,t);return t.previousMessages?[...t.previousMessages,{role:"system",content:`After processing the previous response, this is the updated document.
6
+ Ignore previous documents, you MUST issue operations against this latest version of the document:`},{role:"system",content:JSON.stringify(o.htmlBlocks)},{role:"system",content:`You SHOULD use "update" operations to update blocks you added / edited previously
7
+ (unless the user explicitly asks you otherwise to add or delete other blocks).
8
+
9
+ The user now asks you to do the following:`},{role:"user",content:t.userPrompt}]:ht({...o,userPrompt:t.userPrompt})}};function gt(e){let t,o=!1;return e.descendants((r,n)=>o?!1:(r.isText&&(o=!0,t=n),!0)),t}function U(e){var i;const t=w.getPmSchema(e),{modification:o}=t.marks,r=[],n=new v.Transform(e.before);for(let a=0;a<e.steps.length;a++){const s=e.steps[a],c=new v.Mapping(e.mapping.maps.slice(0,a)).invert();if(s.structure){if(s instanceof v.ReplaceStep){if(s.to!==s.from+1||s.slice.openStart!==0||s.slice.openEnd!==1||s.slice.content.size!==2)throw new Error("Structure change is not in expected format (ReplaceStep)")}else if(s instanceof v.ReplaceAroundStep){if(s.insert!==1||s.slice.size!==2||s.gapTo!==s.to-1||s.gapFrom!==s.from+1)throw new Error("Structure change is not in expected format (ReplaceAroundStep)")}else throw new Error("Step is not a ReplaceStep or ReplaceAroundStep");const b=c.map(s.from),g=s.slice.content.firstChild,k=n.doc.resolve(n.mapping.map(b)).nodeAfter;let C=g.marks||[];g.type!==k.type&&(C=o.create({type:"nodeType",previousValue:k.type.name,newValue:g.type.name}).addToSet(C));const q=new Set([...Object.keys(g.attrs),...Object.keys(k.attrs)]);for(const M of q)g.attrs[M]!==k.attrs[M]&&(C=o.create({type:"attr",attrName:M,previousValue:k.attrs[M],newValue:g.attrs[M]}).addToSet(C));const _=n.steps.length;n.setNodeMarkup(n.mapping.map(b),g.type,g.attrs,C),r.push({prosemirrorSteps:n.steps.slice(_),selection:void 0,type:"replace"});continue}if(!(s instanceof v.ReplaceStep))throw new Error("Step is not a ReplaceStep");const u=c.map(s.from),f=c.map(s.to);if(s.slice.openStart>0||s.slice.openEnd>0)throw new Error("Slice has openStart or openEnd > 0, but structure=false");r.push({prosemirrorSteps:[],selection:{anchor:n.mapping.map(u),head:n.mapping.map(f)},type:"select"});const l=s.slice.content.textBetween(0,s.slice.size),m=l===n.doc.textBetween(n.mapping.map(u),n.mapping.map(f));let p;if(m)p=s.slice.content.size;else if(l.length===0)p=s.slice.content.size;else{const b=gt(s.slice.content);if(b===void 0)throw new Error("unexpected: no first character found");p=b+1}let h=n.mapping.map(f);const d=n.mapping.map(f);let S=!0;for(let b=p;b<=s.slice.content.size;b++){const g=S&&u!==f,k=n.steps.length;if(g){const _=n.doc.resolve(n.mapping.map(u));(i=_.nodeAfter)!=null&&i.isBlock&&n.addNodeMark(_.pos,t.mark("deletion",{})),n.addMark(_.pos,h,t.mark("deletion",{})),h=n.mapping.map(f)}const C=new $.Slice(s.slice.content.cut(0,b),0,0);n.replace(d,h,C).addMark(d,d+C.content.size,t.mark("insertion",{})),n.doc.nodesBetween(d,d+C.content.size,(_,M)=>M<d||M>d+C.content.size?!0:(_.isBlock&&n.addNodeMark(M,t.mark("insertion",{})),!1)),h=n.mapping.slice(k).map(h);const q=R.TextSelection.near(n.doc.resolve(d+C.content.size),-1);r.push({prosemirrorSteps:n.steps.slice(k),selection:{anchor:q.from,head:q.from},type:g?"replace":"insert"}),S=!1}}return r}async function re(e){const t=Math.random()*.3+.85;if(e.type==="select")await new Promise(o=>setTimeout(o,100*t));else if(e.type==="insert")await new Promise(o=>setTimeout(o,10*t));else if(e.type==="replace")await new Promise(o=>setTimeout(o,200*t));else throw new w.UnreachableCaseError(e.type)}function ne(e,t){e.setMeta("addToHistory",!1),t.selection&&e.setMeta("aiAgent",{selection:{anchor:t.selection.anchor,head:t.selection.head}});for(const o of t.prosemirrorSteps)if(e.maybeStep(o).failed)throw new Error("failed to apply step");return e}function kt(e,t,o){const r=new v.Transform(t);for(const a of e){const s=new v.ReplaceStep(r.mapping.map(a.fromA),r.mapping.map(a.toA),o.slice(a.fromB,a.toB));r.step(s)}const n=r.mapping.invert();let i=r.doc.content.findDiffStart(o.content);for(;i!==null;){const a=o.resolve(i).nodeAfter,s=r.doc.resolve(i).nodeAfter;if(!a||!s)throw new Error("diffNode not found");const c=!a.isLeaf&&a.content.eq(s.content),u=c?1:Math.min(a.nodeSize,s.nodeSize),f=i+u,l=n.map(i),m=n.map(f);let p=e.length;for(let d=0;d<e.length;d++)if(e[d].fromA>=m){p=d;break}e.splice(p,0,{fromA:l,toA:m,fromB:i,toB:f,deleted:[],inserted:[],type:c?"node-type-or-attr-update":"mark-update"}),r.step(new v.ReplaceStep(i,f,o.slice(i,f),c));const h=r.doc.content.findDiffStart(o.content);if(h===i)throw new Error("diffStart not moving");i=h}return e}const pe=(e,t)=>{const o=new Set,r=new Set;e.descendants(a=>{a.type.name==="tableCell"&&o.add(JSON.stringify(a.toJSON()))}),t.descendants(a=>{a.type.name==="tableCell"&&r.add(JSON.stringify(a.toJSON()))});const n=new Set([...o].filter(a=>r.has(a)));return{encodeCharacter:a=>a,encodeNodeStart:a=>{if(a.type.name==="tableCell"){const s=JSON.stringify(a.toJSON());return n.has(s)?s:a.type.name}return a.type.name},encodeNodeEnd:a=>{if(a.type.name==="tableCell"){const s=JSON.stringify(a.toJSON());return n.has(s)?s:-1}return-1},compareTokens:(a,s)=>a===s}};function G(e,t,o=!1,r,n){const i=w.getNodeById(e.id,t),a=new v.Transform(t);w.updateBlockTr(a,i.posBeforeNode,e.block,r,n);let s=a.doc,c=K.ChangeSet.create(t,void 0,pe(t,s));if(c=c.addSteps(s,a.mapping.maps,0),o&&c.changes.length>0){const l=c.changes[c.changes.length-1],m=l.toA-l.fromA,p=l.toB-l.fromB;if(m>p){const h=t.slice(l.fromA+p,l.toA);a.step(new v.ReplaceStep(l.toB,l.toB,h)),s=a.doc,c=K.ChangeSet.create(c.startDoc,void 0,pe(c.startDoc,s)),c=c.addSteps(s,a.mapping.maps,0)}}const u=[],f=K.simplifyChanges(c.changes,s);for(let l=0;l<f.length;l++){const m=f[l],p=s.slice(m.fromB,m.toB);if(p.openEnd===1&&p.openStart===0&&(m.type="node-type-or-attr-update",p.size>2)){const h={fromA:m.fromA,toA:m.fromA+1,fromB:m.fromB,toB:m.fromB+1,deleted:[],inserted:[],type:"node-type-or-attr-update"},d={fromA:m.fromA+1,toA:m.toA,fromB:m.fromB+1,toB:m.toB,deleted:[],inserted:[]};f.splice(l,1,h,d),l++}}kt(f,t,s);for(let l=0;l<f.length;l++){const m=f[l],p=s.slice(m.fromB,m.toB);if(p.openEnd>0&&p.size>1)throw new Error("unexpected, openEnd > 0 and size > 1, this should have been split into two steps");l===f.length-1&&o&&m.type==="mark-update"||u.push(new v.ReplaceStep(m.fromA,m.toA,p,m.type==="node-type-or-attr-update"))}return u}function bt(e,t){if(!e||!Array.isArray(e)||e.length===0)return{ok:!1,error:"blocks is required"};const o=[];for(const r of e){const n=t(r);if(!n.ok)return{ok:!1,error:`Invalid block: ${n.error}`};o.push(n.value)}return{ok:!0,value:o}}function se(e){return(t,o)=>{const r=typeof e.schema=="function"?e.schema(t):e.schema;return{name:"add",description:e.description,parameters:{type:"object",properties:{referenceId:{type:"string",description:"MUST be an id of a block in the document"},position:{type:"string",enum:["before","after"],description:"`after` to add blocks AFTER (below) the block with `referenceId`, `before` to add the block BEFORE (above)"},blocks:{items:r.block,type:"array"}},required:["referenceId","position","blocks"],$defs:r.$defs},validate:n=>{if(n.type!=="add")return{ok:!1,error:"invalid operation type"};if(n.position!=="before"&&n.position!=="after")return{ok:!1,error:"invalid position"};if(!n.referenceId||!n.blocks)return{ok:!1,error:"referenceId and blocks are required"};let i=n.referenceId;if(o.idsSuffixed){if(!(i!=null&&i.endsWith("$")))return{ok:!1,error:"referenceId must end with $"};i=i.slice(0,-1)}if(!t.getBlock(i))return{ok:!1,error:"referenceId not found"};const s=bt(n.blocks,c=>e.validateBlock(c,t));return s.ok?{ok:!0,value:{type:n.type,referenceId:i,position:n.position,blocks:s.value}}:s},execute:async function*(n){var s;let i=[];const a={};for await(const c of n){if(c.isUpdateToPreviousOperation||(i=[]),c.operation.type!=="add"){yield c;continue}const u=c.operation,f=await e.toJSONToolCall(t,{...c,operation:u});if(f&&!(c.isPossiblyPartial&&oe(f.blocks[f.blocks.length-1]))){for(let l=0;l<f.blocks.length;l++){const m=f.blocks[l],p=t.prosemirrorState.tr;let h=[];if(l<i.length){const d=await e.rebaseTool(i[l],t),b=G({id:i[l],block:m},d.doc,!1).map(g=>g.map(d.invertMap));for(const g of b)p.step(g.map(p.mapping));h=U(p),h=h.filter(g=>g.type!=="select")}else{const d=u.position==="after"?a[u.referenceId]:void 0,S=w.insertBlocks(p,[m],l>0?i[l-1]:d||u.referenceId,l>0?"after":u.position);i.push(...S.map(b=>b.id)),h=U(p)}h.find(d=>d.type==="replace");for(const d of h)o.withDelays&&await re(d),t.transact(S=>{ne(S,d)}),(s=o.onBlockUpdate)==null||s.call(o,i[l])}c.isPossiblyPartial||u.position==="after"&&(a[u.referenceId]=i[i.length-1])}}}}}}function ie(e){return(t,o)=>{const r=typeof e.schema=="function"?e.schema(t):e.schema;return{name:"update",description:e.description,parameters:{type:"object",properties:{id:{type:"string",description:"id of block to update"},block:r.block},required:["id","block"],$defs:r.$defs},validate:n=>{if(n.type!=="update")return{ok:!1,error:"invalid operation type"};if(!n.id)return{ok:!1,error:"id is required"};let i=n.id;if(o.idsSuffixed){if(!(i!=null&&i.endsWith("$")))return{ok:!1,error:"id must end with $"};i=i.slice(0,-1)}if(!n.block)return{ok:!1,error:"block is required"};const a=t.getBlock(i);if(!a)return console.error("BLOCK NOT FOUND",i),{ok:!1,error:"block not found"};const s=e.validateBlock(n.block,t,a.type);return s.ok?{ok:!0,value:{type:n.type,id:i,block:s.value}}:s},execute:async function*(n){var c;let a=50;const s=o.updateSelection?{from:w.trackPosition(t,o.updateSelection.from),to:w.trackPosition(t,o.updateSelection.to)}:void 0;for await(const u of n){if(u.operation.type!=="update"){yield u;continue}const f=u.operation;if(u.isPossiblyPartial){const k=JSON.stringify(f.block).length;if(k<a)continue;a=k+50}else a=50;const l=await e.rebaseTool(f.id,t),m=s?l.invertMap.invert().map(s.from()):void 0,p=s?l.invertMap.invert().map(s.to()):void 0,h=await e.toJSONToolCall(t,u);if(!h)continue;const d=G(h,l.doc,u.isPossiblyPartial,m,p);if(d.length===1&&u.isPossiblyPartial)continue;const S=d.map(k=>k.map(l.invertMap)),b=new v.Transform(t.prosemirrorState.doc);for(const k of S)b.step(k.map(b.mapping));const g=U(b);for(const k of g)o.withDelays&&await re(k),t.transact(C=>{ne(C,k)}),(c=o.onBlockUpdate)==null||c.call(o,f.id)}}}}}const ae=(e,t)=>({name:"delete",description:"Delete a block",parameters:{type:"object",properties:{id:{type:"string",description:"id of block to delete"}},required:["id"]},validate:o=>{if(o.type!=="delete")return{ok:!1,error:"invalid operation type"};if(!o.id)return{ok:!1,error:"id is required"};let r=o.id;if(t.idsSuffixed){if(!(r!=null&&r.endsWith("$")))return{ok:!1,error:"id must end with $"};r=r.slice(0,-1)}return e.getBlock(r)?{ok:!0,value:{type:"delete",id:r}}:{ok:!1,error:"block not found"}},execute:async function*(o){var r;for await(const n of o){if(n.operation.type!=="delete"){yield n;continue}const i=n.operation,a=e.prosemirrorState.tr;w.removeAndInsertBlocks(a,[i.id],[]);const s=U(a);for(const c of s)t.withDelays&&await re(c),e.transact(u=>{ne(u,c)}),(r=t.onBlockUpdate)==null||r.call(t,i.id)}}});function fe(e){const t=e.lastIndexOf("<"),o=e.lastIndexOf(">");let r=e;if(t>o&&(r=e.substring(0,t),!r.trim()))return;const n=r.match(/&[a-zA-Z0-9]*$/);n&&(r=r.substring(0,r.length-n[0].length));const s=new DOMParser().parseFromString(`<div>${r}</div>`,"text/html").body.firstChild;return s?s.innerHTML:""}function F(e){let t;if(A.applySuggestions(e.prosemirrorState,o=>{t=o}),!t)throw new Error("applySuggestionsTr is not set");return t}function J(e,t){const o=t.mapping.invert();return{doc:t.doc,tr:()=>new v.Transform(t.doc),invertMap:o,rebaseTr:r=>{if(r.steps.length===0)throw new Error("No steps to apply");let n=e.prosemirrorState.tr;for(const i of r.steps){const a=i.map(o);if(!a)throw new Error("Step is not mapped");n=n.step(a)}return n}}}async function me(e,t){var u;const o=F(t),r=w.getBlock(o.doc,e);if(!r)throw new Error("block not found");const n=await t.blocksToHTMLLossy([{...r,children:[]}]),i=(u=window.__TEST_OPTIONS)==null?void 0:u.mockID,a=await t.tryParseHTMLToBlocks(n);if(window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=i),a.length!==1)throw new Error("html diff invalid block count");const s=a[0];if(s.id=e,G({id:e,block:s},o.doc).length)throw new Error("html diff");return J(t,o)}function he(e){return typeof e!="string"?{ok:!1,error:"block must be a string"}:{ok:!0,value:e}}const Q={add:se({description:"Insert new blocks",schema:{block:{$ref:"#/$defs/block"},$defs:{block:{type:"string",description:"html of block (MUST be a single HTML element)"}}},validateBlock:he,rebaseTool:me,toJSONToolCall:async(e,t)=>{var n;const o=(n=window.__TEST_OPTIONS)==null?void 0:n.mockID,r=(await Promise.all(t.operation.blocks.map(async i=>{const a=t.isPossiblyPartial?fe(i):i;return a?(await e.tryParseHTMLToBlocks(a)).map(s=>(delete s.id,s)):[]}))).flat();if(window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=o),r.length!==0)return{...t.operation,blocks:r}}}),update:ie({description:"Update a block",schema:{block:{$ref:"#/$defs/block"},$defs:{block:{type:"string",description:"html of block (MUST be a single HTML element)"}}},validateBlock:he,rebaseTool:me,toJSONToolCall:async(e,t)=>{const o=t.isPossiblyPartial?fe(t.operation.block):t.operation.block;if(!o)return;const r=(await e.tryParseHTMLToBlocks(o))[0];return window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=void 0),delete r.id,{...t.operation,block:r}}}),delete:ae};function St(e,t,o,r,n){const i={add:!0,update:!0,delete:!0,...o};return[...i.update?[Q.update(e,{idsSuffixed:!0,withDelays:t,updateSelection:r,onBlockUpdate:n})]:[],...i.add?[Q.add(e,{idsSuffixed:!0,withDelays:t,onBlockUpdate:n})]:[],...i.delete?[Q.delete(e,{idsSuffixed:!0,withDelays:t,onBlockUpdate:n})]:[]]}const Le={getStreamTools:St,defaultPromptBuilder:yt,promptHelpers:{getDataForPromptNoSelection:Ie,getDataForPromptWithSelection:_e}};async function Ee(e,t){const{userPrompt:o,useSelection:r,deleteEmptyCursorBlock:n,stream:i,onStart:a,withDelays:s,dataFormat:c,previousResponse:u,...f}={maxRetries:2,deleteEmptyCursorBlock:!0,stream:!0,withDelays:!0,dataFormat:Le,...t},l=t.promptBuilder??c.defaultPromptBuilder,m=c.getStreamTools,p=r?void 0:e.getTextCursorPosition().block,h=p&&n&&oe(p)?p.id:void 0,d=r?e.getSelectionCutBlocks():void 0;let S;u&&(S=u.messages,S.push({role:"assistant",content:`These are the operations returned by a previous LLM call:
10
+ `+JSON.stringify(await u.llmResult.getGeneratedOperations())}));const b=await l(e,{selectedBlocks:d==null?void 0:d.blocks,userPrompt:o,excludeBlockIds:h?[h]:void 0,previousMessages:S}),g=m(e,s,t.defaultStreamTools,d?{from:d._meta.startPos,to:d._meta.endPos}:void 0,t.onBlockUpdate);let k;return i?k=await ct(g,{messages:b,...f},()=>{h&&e.removeBlocks([h]),a==null||a()}):(k=await it(g,{messages:b,...f}),h&&e.removeBlocks([h]),a==null||a()),new pt(b,k,g)}async function Ne(e,t){const o=Y(e.document),r=await x(P(o),async s=>({...s,children:void 0})),i=W(e,r).filter(s=>"cursor"in s||!(t.excludeBlockIds||[]).includes(s.id));return{jsonBlocks:E(i)}}async function je(e,t){const o=await x(P(t.selectedBlocks),async n=>n);return{jsonSelectedBlocks:E(o),jsonDocument:(await x(P(e.document),async n=>({...n,id:void 0,children:void 0}))).map(({block:n})=>({block:n}))}}function wt(e){return[{role:"system",content:`You're manipulating a selected part of a text document using JSON blocks.
11
+ Make sure to follow the json schema provided and always include the trailing $ in ids.
12
+ This is the selection as an array of JSON blocks:`},{role:"system",content:JSON.stringify(e.jsonSelectedBlocks)},{role:"system",content:"This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"},{role:"system",content:JSON.stringify(e.jsonDocument)},{role:"system",content:"The user asks you to do the following:"},{role:"user",content:e.userPrompt}]}function Tt(e){return[{role:"system",content:`You're manipulating a text document using JSON blocks.
13
+ Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $).
14
+ This is the document as an array of JSON blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):`},{role:"system",content:JSON.stringify(e.jsonBlocks)},{role:"system",content:"The user asks you to do the following:"},{role:"user",content:e.userPrompt},{role:"system",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).'}]}const vt=async(e,t)=>{if(t.selectedBlocks){const o=await je(e,{selectedBlocks:t.selectedBlocks});return wt({...o,userPrompt:t.userPrompt})}else{const o=await Ne(e,t);return Tt({...o,userPrompt:t.userPrompt})}};function Ct(e){const t={},o={};return e.forEach(n=>{const{type:i,...a}=n.properties,s=JSON.stringify(a);t[s]?t[s].push(i.enum[0]):(t[s]=[i.enum[0]],o[s]=n)}),Object.keys(t).map(n=>{const i=o[n];return{...i,properties:{...i.properties,type:{type:"string",enum:t[n]}}}})}function Pt(e){return{type:"object",properties:Object.fromEntries(Object.entries(e).map(([t,o])=>[t,{type:o.propSchema}])),additionalProperties:!1}}function Ot(){return{type:"object",properties:{type:{type:"string",enum:["text"]},text:{type:"string"},styles:{$ref:"#/$defs/styles"}},additionalProperties:!1,required:["type","text"]}}function Ae(e){return{type:"object",properties:Object.fromEntries(Object.entries(e).filter(([t,o])=>o.default!==void 0).map(([t,o])=>[t,{type:typeof o.default,enum:o.values}])),additionalProperties:!1}}function xt(e){return{type:"array",items:{anyOf:Object.entries(e).map(([t,o])=>o==="text"?{$ref:"#/$defs/styledtext"}:o==="link"?{type:"object",properties:{type:{type:"string",enum:["link"]},content:{type:"array",items:{$ref:"#/$defs/styledtext"}},href:{type:"string"}},additionalProperties:!1,required:["type","href","content"]}:{type:"object",properties:{type:{type:"string",enum:[o.type]},content:o.content==="styled"?{type:"array",items:{$ref:"#/$defs/styledtext"}}:void 0,props:Ae(o.propSchema)},additionalProperties:!1,required:["type",...o.content==="styled"?["content"]:[]]})}}}function Mt(e){return{anyOf:Ct(Object.entries(e).map(([t,o])=>({type:"object",properties:{type:{type:"string",enum:[o.type]},content:o.content==="inline"?{$ref:"#/$defs/inlinecontent"}:o.content==="table"?{type:"object",properties:{}}:void 0,props:Ae(o.propSchema)},additionalProperties:!1,required:["type"]})))}}function Bt(e){const t=JSON.parse(JSON.stringify({blockSchema:e.blockSchema,inlineContentSchema:e.inlineContentSchema,styleSchema:e.styleSchema}));return{removeFileBlocks(){return t.blockSchema=Object.fromEntries(Object.entries(t.blockSchema).filter(([o,r])=>!r.isFileBlock)),this},removeDefaultProps(){return t.blockSchema=Object.fromEntries(Object.entries(t.blockSchema).map(([o,r])=>[o,{...r,propSchema:Object.fromEntries(Object.entries(r.propSchema).filter(n=>typeof w.defaultProps[n[0]]>"u"))}])),this},get(){return t}}}function ye(e){return e=Bt(e).removeFileBlocks().removeDefaultProps().get(),{$defs:{styles:Pt(e.styleSchema),styledtext:Ot(),inlinecontent:xt(e.inlineContentSchema),block:Mt(e.blockSchema)}}}function $e(e,t){return!t.schema.inlineContentSchema[e.type]||w.isStyledTextInlineContent(e)&&!("text"in e)?!1:w.isLinkInlineContent(e)?!("content"in e)||!("href"in e)?!1:$e(e.content,t):!0}function ge(e,t,o){const r=e.type||o,n=t.schema.blockSchema[r];if(!n)return{ok:!1,error:"block type not found in editor"};if(e.children,n.content==="none"){if(e.content)return{ok:!1,error:"block content not expected for this block type"}}else{if(!e.content)return{ok:!0,value:e};if(!Array.isArray(e.content))return{ok:!1,error:"block content must be an array"};if(n.content==="table")return{ok:!0,value:e};if(!e.content.every(i=>$e(i,t)))return{ok:!1,error:"block content must be an array of inline content"}}return{ok:!0,value:e}}const ee={add:se({description:"Insert new blocks",schema:e=>({block:{$ref:"#/$defs/block"},...ye(e.schema)}),validateBlock:ge,rebaseTool:async(e,t)=>J(t,F(t)),toJSONToolCall:async(e,t)=>t.operation}),update:ie({description:"Update a block, the new block will replace the existing block.",schema:e=>({block:{$ref:"#/$defs/block"},...ye(e.schema)}),validateBlock:ge,rebaseTool:async(e,t)=>J(t,F(t)),toJSONToolCall:async(e,t)=>{const o=Object.fromEntries(Object.entries(w.defaultProps).map(([r,n])=>[r,n.default]));return{...t.operation,block:{...t.operation.block,props:{...o,...t.operation.block.props}}}}}),delete:ae};function It(e,t,o,r){const n={add:!0,update:!0,delete:!0,...o};return[...n.update?[ee.update(e,{idsSuffixed:!0,withDelays:t,updateSelection:r})]:[],...n.add?[ee.add(e,{idsSuffixed:!0,withDelays:t})]:[],...n.delete?[ee.delete(e,{idsSuffixed:!0,withDelays:t})]:[]]}const _t={getStreamTools:It,defaultPromptBuilder:vt,promptHelpers:{getDataForPromptNoSelection:Ne,getDataForPromptWithSelection:je}};async function De(e,t){const o=Y(e.document),r=await x(P(o),async s=>e.blocksToMarkdownLossy([s])),i=W(e,r).filter(s=>"cursor"in s||!(t.excludeBlockIds||[]).includes(s.id));return{markdownBlocks:E(i)}}async function Re(e,t){const o=await x(P(t.selectedBlocks),async n=>e.blocksToMarkdownLossy([n]));return{markdownSelectedBlocks:E(o),markdownDocument:(await x(P(e.document),async n=>e.blocksToMarkdownLossy([n]))).map(({block:n})=>({block:n}))}}function Lt(e){return[{role:"system",content:`You're manipulating a selected part of a text document using markdown blocks.
15
+ Make sure to follow the json schema provided and always include the trailing $ in ids.
16
+ This is the selection as an array of markdown blocks:`},{role:"system",content:JSON.stringify(e.markdownSelectedBlocks)},{role:"system",content:"This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"},{role:"system",content:JSON.stringify(e.markdownDocument)},{role:"system",content:"The user asks you to do the following:"},{role:"user",content:e.userPrompt}]}function Et(e){return[{role:"system",content:`You're manipulating a text document using markdown blocks.
17
+ Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $).
18
+ This is the document as an array of markdown blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):`},{role:"system",content:JSON.stringify(e.markdownBlocks)},{role:"system",content:"The user asks you to do the following:"},{role:"user",content:e.userPrompt},{role:"system",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).'}]}const Nt=async(e,t)=>{if(t.selectedBlocks){const o=await Re(e,{selectedBlocks:t.selectedBlocks});return Lt({...o,userPrompt:t.userPrompt})}else{const o=await De(e,t);return Et({...o,userPrompt:t.userPrompt})}};async function ke(e,t){const o=F(t),r=await t.blocksToMarkdownLossy([w.getBlock(o.doc,e)]),n=await t.tryParseMarkdownToBlocks(r),i=G({id:e,block:n[0]},o.doc),a=new v.Mapping;for(const s of i){const c=s.map(a);if(!c)throw new Error("Failed to map step");o.step(c),a.appendMap(c.getMap())}return J(t,o)}function be(e){return typeof e!="string"?{ok:!1,error:"block must be a string"}:{ok:!0,value:e}}const te={add:se({description:"Insert new blocks",schema:{block:{$ref:"#/$defs/block"},$defs:{block:{type:"string",description:"markdown of block"}}},validateBlock:be,rebaseTool:ke,toJSONToolCall:async(e,t)=>{const o=await Promise.all(t.operation.blocks.map(async r=>{const n=(await e.tryParseMarkdownToBlocks(r.trim()))[0];return delete n.id,n}));return window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=void 0),{...t.operation,blocks:o}}}),update:ie({description:"Update a block, the new block will replace the existing block.",schema:{block:{$ref:"#/$defs/block"},$defs:{block:{type:"string",description:"markdown of block"}}},validateBlock:be,rebaseTool:ke,toJSONToolCall:async(e,t)=>{const o=(await e.tryParseMarkdownToBlocks(t.operation.block.trim()))[0];return delete o.id,window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=void 0),{...t.operation,block:o}}}),delete:ae};function jt(e,t,o,r){const n={add:!0,update:!0,delete:!0,...o};return[...n.update?[te.update(e,{idsSuffixed:!0,withDelays:t,updateSelection:r})]:[],...n.add?[te.add(e,{idsSuffixed:!0,withDelays:t})]:[],...n.delete?[te.delete(e,{idsSuffixed:!0,withDelays:t})]:[]]}const At={getStreamTools:jt,defaultPromptBuilder:Nt,promptHelpers:{getDataForPromptNoSelection:De,getDataForPromptWithSelection:Re}},$t={addCursorPosition:W,flattenBlocks:P,suffixIDs:E,trimEmptyBlocks:Y,convertBlocks:x},qe={_experimental_json:_t,_experimental_markdown:At,html:Le},Se=new R.PluginKey("blocknote-agent-cursor");function Dt(e){return new R.Plugin({key:Se,view:t=>({}),state:{init:()=>({selection:void 0}),apply:(t,o)=>{const r=t.getMeta("aiAgent");return r?{selection:r.selection}:{selection:void 0}}},props:{decorations:t=>{const{doc:o}=t,{selection:r}=Se.getState(t),n=[];if(!r)return z.DecorationSet.create(o,[]);n.push(z.Decoration.widget(r.head,()=>Rt(e),{key:"agent-cursor",side:10}));const i=Math.min(r.anchor,r.head),a=Math.max(r.anchor,r.head);return n.push(z.Decoration.inline(i,a,Qe.defaultSelectionBuilder(e),{inclusiveEnd:!0,inclusiveStart:!1})),z.DecorationSet.create(o,n)}}})}const Rt=e=>{const t=document.createElement("span");t.classList.add("bn-collaboration-cursor__base"),t.setAttribute("data-active","true");const o=document.createElement("span");o.setAttribute("contentedEditable","false"),o.classList.add("bn-collaboration-cursor__caret"),o.setAttribute("style",`background-color: ${e.color}`);const r=document.createElement("span");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},qt=new R.PluginKey("blocknote-ai-plugin");class ce extends w.BlockNoteExtension{constructor(o,r){super();H(this,"previousRequestOptions");H(this,"_store",de()(o=>({aiMenuState:"closed"})));H(this,"options");this.editor=o,this.options=de()(n=>({dataFormat:qe.html,stream:!0,...r})),this.addProsemirrorPlugin(new R.Plugin({key:qt,filterTransaction:n=>{var a;const i=this.store.getState().aiMenuState;return!(i!=="closed"&&i.status==="ai-writing"&&(a=n.getMeta(Ke.fixTablesKey))!=null&&a.fixTables)}})),this.addProsemirrorPlugin(A.suggestChanges()),this.addProsemirrorPlugin(Dt(r.agentCursor||{name:"AI",color:"#8bc6ff"}))}static name(){return"ai"}get store(){return this._store}openAIMenuAtBlock(o){this.editor.setForceSelectionVisible(!0),this.editor.isEditable=!1,this._store.setState({aiMenuState:{blockId:o,status:"user-input"}})}closeAIMenu(){this.previousRequestOptions=void 0,this._store.setState({aiMenuState:"closed",llmResponse:void 0}),this.editor.setForceSelectionVisible(!1),this.editor.isEditable=!0,this.editor.focus()}acceptChanges(){var r;const o=this.editor.prosemirrorState.doc;this.editor.exec((n,i)=>A.revertSuggestions(n,a=>{i==null||i(a.setMeta("addToHistory",!1))})),this.editor.exec((n,i)=>{const a=n.tr;a.replace(0,a.doc.content.size,new $.Slice($.Fragment.from(o),0,0));const s=n.apply(a);return A.applySuggestions(s,c=>{i==null||i(a.replace(0,a.doc.content.size,new $.Slice($.Fragment.from(c.doc),0,0)))})}),(r=this.editor.forkYDocPlugin)==null||r.merge({keepChanges:!0}),this.closeAIMenu()}rejectChanges(){var o;this.editor.exec((r,n)=>A.revertSuggestions(r,i=>{n==null||n(i.setMeta("addToHistory",!1))})),(o=this.editor.forkYDocPlugin)==null||o.merge({keepChanges:!1}),this.closeAIMenu()}async retry(){const o=this.store.getState().aiMenuState;if(o==="closed"||o.status!=="error"||!this.previousRequestOptions)throw new Error("retry() is only valid when a previous response failed");if(o.error instanceof j.APICallError||o.error instanceof j.RetryError)return this.callLLM(this.previousRequestOptions);{const r=o.error instanceof Error?o.error.message:String(o.error);return this.callLLM({userPrompt:`An error occured: ${r}
19
+ Please retry the previous user request.`})}}setAIResponseStatus(o){const r=this.store.getState().aiMenuState;if(r!=="closed")if(o==="ai-writing"&&this.editor.setForceSelectionVisible(!1),typeof o=="object"){if(o.status!=="error")throw new w.UnreachableCaseError(o.status);this._store.setState({aiMenuState:{status:o.status,error:o.error,blockId:r.blockId}})}else this._store.setState({aiMenuState:{status:o,blockId:r.blockId}})}async callLLM(o){var n;this.setAIResponseStatus("thinking"),(n=this.editor.forkYDocPlugin)==null||n.fork();let r;try{const i={...this.options.getState(),...o,previousResponse:this.store.getState().llmResponse};this.previousRequestOptions=i,r=await Ee(this.editor,{...i,onStart:()=>{var a;this.setAIResponseStatus("ai-writing"),(a=o.onStart)==null||a.call(o)},onBlockUpdate:a=>{var s;this._store.setState({aiMenuState:{blockId:a,status:"ai-writing"}}),(s=o.onBlockUpdate)==null||s.call(o,a)}}),this._store.setState({llmResponse:r}),await r.execute(),this.setAIResponseStatus("user-reviewing")}catch(i){this.setAIResponseStatus({status:"error",error:i}),console.warn("Error calling LLM",i)}return r}}function Ht(e){return t=>new ce(t,e)}function I(e){return e.extension(ce)}const zt=(e,t)=>async(o,r)=>{const n=new Request(o,r),i=new Request(`${e}?provider=${encodeURIComponent(t)}&url=${encodeURIComponent(n.url)}`,{headers:n.headers,body:(r==null?void 0:r.body)||n.body,method:n.method,duplex:"half"});try{return await fetch(i)}catch(a){throw new TypeError("fetch failed",{cause:a})}};function Ut(e){return{getProviderSettings:t=>({apiKey:e.apiKey,fetch:zt(e.baseURL,t)})}}var He={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},we=L.default.createContext&&L.default.createContext(He),Ft=["attr","size","title"];function Jt(e,t){if(e==null)return{};var o=Vt(e,t),r,n;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function Vt(e,t){if(e==null)return{};var o={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;o[r]=e[r]}return o}function V(){return V=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},V.apply(this,arguments)}function Te(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),o.push.apply(o,r)}return o}function Z(e){for(var t=1;t<arguments.length;t++){var o=arguments[t]!=null?arguments[t]:{};t%2?Te(Object(o),!0).forEach(function(r){Zt(e,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):Te(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function Zt(e,t,o){return t=Wt(t),t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function Wt(e){var t=Yt(e,"string");return typeof t=="symbol"?t:t+""}function Yt(e,t){if(typeof e!="object"||!e)return e;var o=e[Symbol.toPrimitive];if(o!==void 0){var r=o.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function ze(e){return e&&e.map((t,o)=>L.default.createElement(t.tag,Z({key:o},t.attr),ze(t.child)))}function O(e){return t=>L.default.createElement(Gt,V({attr:Z({},e.attr)},t),ze(e.child))}function Gt(e){var t=o=>{var{attr:r,size:n,title:i}=e,a=Jt(e,Ft),s=n||o.size||"1em",c;return o.className&&(c=o.className),e.className&&(c=(c?c+" ":"")+e.className),L.default.createElement("svg",V({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},o.attr,r,a,{className:c,style:Z(Z({color:e.color||o.color},o.style),e.style),height:s,width:s,xmlns:"http://www.w3.org/2000/svg"}),i&&L.default.createElement("title",null,i),e.children)};return we!==void 0?L.default.createElement(we.Consumer,null,o=>t(o)):t(He)}function Ue(e){return O({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)}function ve(e){return O({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)}function Kt(e){return O({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)}function Xt(e){return O({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)}function Qt(e){return O({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)}function eo(e){return O({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M13 6V21H11V6H5V4H19V6H13Z"},child:[]}]})(e)}function to(e){return O({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)}function oo(e){return O({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)}function ro(e){return O({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)}function no(e){return O({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)}function le(e){return O({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)}function N(e){if(!e.dictionary.ai)throw new Error("AI dictionary not found");return e.dictionary.ai}function Fe(){const e=B.useBlockNoteContext();return N(e.editor)}const Je=e=>{const t=B.useComponentsContext(),{onManualPromptSubmit:o,promptText:r,onPromptTextChange:n}=e,[i,a]=T.useState(""),s=r||i,c=T.useCallback(async d=>{d.key==="Enter"&&o(s)},[s,o]),u=T.useCallback(d=>{const S=d.currentTarget.value;n&&n(S),r===void 0&&a(S)},[n,a,r]),f=T.useMemo(()=>w.filterSuggestionItems(e.items,s),[s,e.items]),{selectedIndex:l,setSelectedIndex:m,handler:p}=B.useSuggestionMenuKeyboardHandler(f,d=>d.onItemClick()),h=T.useCallback(d=>{d.key==="Enter"?f.length>0?p(d):c(d):p(d)},[c,p,f.length]);return T.useEffect(()=>{m(0)},[s,m]),y.jsxs("div",{className:"bn-combobox",children:[y.jsx(t.Generic.Form.Root,{children:y.jsx(t.Generic.Form.TextInput,{className:"bn-combobox-input",name:"ai-prompt",variant:"large",icon:e.icon,value:s||"",autoFocus:!0,placeholder:e.placeholder,disabled:e.disabled,onKeyDown:h,onChange:u,autoComplete:"off",rightSection:e.rightSection},"input-"+e.disabled)}),y.jsx(t.SuggestionMenu.Root,{className:"bn-combobox-items",id:"ai-suggestion-menu",children:f.map((d,S)=>y.jsx(t.SuggestionMenu.Item,{className:w.mergeCSSClasses("bn-suggestion-menu-item",d.size==="small"?"bn-suggestion-menu-item-small":""),id:`bn-suggestion-menu-item-${S}`,isSelected:S===l,onClick:d.onItemClick,item:d},d.title))})]})};function so(e){const t=N(e),o=I(e);return[{key:"continue_writing",title:t.ai_default_commands.continue_writing.title,aliases:t.ai_default_commands.continue_writing.aliases,icon:y.jsx(ve,{size:18}),onItemClick:async()=>{await o.callLLM({userPrompt:"Continue writing: write more text at the current cursor position related to the previous text",defaultStreamTools:{add:!0,delete:!1,update:!1}})},size:"small"},{key:"summarize",title:t.ai_default_commands.summarize.title,aliases:t.ai_default_commands.summarize.aliases,icon:y.jsx(Qt,{size:18}),onItemClick:async()=>{await o.callLLM({userPrompt:"Summarize",defaultStreamTools:{add:!0,delete:!1,update:!1}})},size:"small"},{key:"action_items",title:t.ai_default_commands.add_action_items.title,aliases:t.ai_default_commands.add_action_items.aliases,icon:y.jsx(Xt,{size:18}),onItemClick:async()=>{await o.callLLM({userPrompt:"Add action items",defaultStreamTools:{add:!0,delete:!1,update:!1}})},size:"small"},{key:"write_anything",title:t.ai_default_commands.write_anything.title,aliases:t.ai_default_commands.write_anything.aliases,icon:y.jsx(ve,{size:18}),onItemClick:r=>{r(t.ai_default_commands.write_anything.prompt_placeholder)},size:"small"}]}function io(e){const t=N(e),o=I(e);return[{key:"improve_writing",title:t.ai_default_commands.improve_writing.title,aliases:t.ai_default_commands.improve_writing.aliases,icon:y.jsx(eo,{size:18}),onItemClick:async()=>{await o.callLLM({useSelection:!0,userPrompt:"Improve writing",defaultStreamTools:{add:!1,delete:!1,update:!0}})},size:"small"},{key:"fix_spelling",title:t.ai_default_commands.fix_spelling.title,aliases:t.ai_default_commands.fix_spelling.aliases,icon:y.jsx(ro,{size:18}),onItemClick:async()=>{await o.callLLM({useSelection:!0,userPrompt:"Fix spelling",defaultStreamTools:{add:!1,delete:!1,update:!0}})},size:"small"},{key:"translate",title:t.ai_default_commands.translate.title,aliases:t.ai_default_commands.translate.aliases,icon:y.jsx(to,{size:18}),onItemClick:r=>{r(t.ai_default_commands.translate.prompt_placeholder)},size:"small"},{key:"simplify",title:t.ai_default_commands.simplify.title,aliases:t.ai_default_commands.simplify.aliases,icon:y.jsx(Kt,{size:18}),onItemClick:async()=>{await o.callLLM({useSelection:!0,userPrompt:"Simplify",defaultStreamTools:{add:!1,delete:!1,update:!0}})},size:"small"}]}function ao(e){const t=N(e),o=I(e);return[{key:"accept",title:t.ai_menu.actions.accept.title,aliases:t.ai_menu.actions.accept.aliases,icon:y.jsx(oo,{size:18}),onItemClick:()=>{o.acceptChanges()},size:"small"},{key:"revert",title:t.ai_menu.actions.revert.title,aliases:t.ai_menu.actions.revert.aliases,icon:y.jsx(Ue,{size:18}),onItemClick:()=>{o.rejectChanges()},size:"small"}]}function co(e){const t=N(e),o=I(e);return[{key:"retry",title:t.ai_menu.actions.retry.title,aliases:t.ai_menu.actions.retry.aliases,icon:y.jsx(no,{size:18}),onItemClick:async()=>{await o.retry()},size:"small"},{key:"cancel",title:t.ai_menu.actions.cancel.title,aliases:t.ai_menu.actions.cancel.aliases,icon:y.jsx(Ue,{size:18}),onItemClick:()=>{o.rejectChanges()},size:"small"}]}function Ve(e,t){return t==="user-input"?e.getSelection()?io(e):so(e):t==="user-reviewing"?ao(e):t==="error"?co(e):[]}const Ze=e=>{const t=B.useBlockNoteEditor(),[o,r]=T.useState(""),n=Fe(),i=B.useComponentsContext(),a=I(t),s=Ce.useStore(a.store,p=>p.aiMenuState!=="closed"?p.aiMenuState.status:"closed"),{items:c}=e,u=T.useMemo(()=>{let p=[];return c?p=c(t,s):p=Ve(t,s),p.map(h=>({...h,onItemClick:()=>{h.onItemClick(r)}}))},[c,s,t]),f=T.useCallback(async p=>{await a.callLLM({userPrompt:p,useSelection:t.getSelection()!==void 0})},[a,t]);T.useEffect(()=>{(s==="user-reviewing"||s==="error")&&r("")},[s]);const l=T.useMemo(()=>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=T.useMemo(()=>{if(s==="thinking"||s==="ai-writing")return y.jsx(i.SuggestionMenu.Loader,{className:"bn-suggestion-menu-loader bn-combobox-right-section"});if(s==="error")return y.jsx("div",{className:"bn-combobox-right-section bn-combobox-error",children:y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"1em",viewBox:"0 -960 960 960",width:"1em",fill:"currentColor",children:y.jsx("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"})})})},[i,s]);return y.jsx(Je,{onManualPromptSubmit:e.onManualPromptSubmit||f,items:u,promptText:o,onPromptTextChange:r,placeholder:l,disabled:s==="thinking"||s==="ai-writing",icon:y.jsx("div",{className:"bn-combobox-icon",children:y.jsx(le,{})}),rightSection:m})},We=e=>{const t=e.blockID?document.querySelector(`[data-id="${e.blockID}"]`):void 0,o=T.useMemo(()=>t?{getBoundingClientRect:()=>t.getBoundingClientRect(),contextElement:t}:null,[t]),{isMounted:r,ref:n,style:i,getFloatingProps:a,isPositioned:s}=B.useUIElementPositioning(!!t,o,3e3,{canDismiss:{enabled:!0,escapeKey:!0,outsidePress:e.canDismissViaOutsidePress},placement:"bottom",middleware:[X.offset(10),X.size({apply({rects:c,elements:u}){Object.assign(u.floating.style,{width:`${c.reference.width}px`})}})],onOpenChange:e.onOpenChange,whileElementsMounted:(c,u,f)=>X.autoUpdate(c,u,f,{animationFrame:!0})});return r?y.jsx("div",{ref:n,style:{...i},...a(),children:s&&e.children}):null},lo=e=>{const t=B.useBlockNoteEditor(),o=I(t),r=Ce.useStore(o.store,a=>a.aiMenuState),n=r==="closed"?void 0:r.blockId,i=e.aiMenu||Ze;return y.jsx(We,{canDismissViaOutsidePress:r==="closed"||r.status==="user-input",blockID:n,onOpenChange:a=>{a||r==="closed"||(r.status==="user-input"?o.closeAIMenu():(r.status==="user-reviewing"||r.status==="error")&&o.rejectChanges())},children:y.jsx(i,{})})},uo=()=>{const e=Fe(),t=B.useComponentsContext(),o=B.useBlockNoteEditor(),r=I(o),n=()=>{o.formattingToolbar.closeMenu();const i=o.getSelection();if(!i)throw new Error("No selection");const a=i.blocks[i.blocks.length-1].id;r.openAIMenuAtBlock(a)};return o.isEditable?y.jsx(t.Generic.Toolbar.Button,{className:"bn-button",label:e.formatting_toolbar.ai.tooltip,mainTooltip:e.formatting_toolbar.ai.tooltip,icon:y.jsx(le,{}),onClick:n}):null},po={AI:le};function fo(e){const t=I(e);return[{key:"ai",onItemClick:()=>{const r=e.getTextCursorPosition();r.block.content&&Array.isArray(r.block.content)&&r.block.content.length===0&&r.prevBlock?t.openAIMenuAtBlock(r.prevBlock.id):t.openAIMenuAtBlock(r.block.id)},...N(e).slash_menu.ai,icon:y.jsx(po.AI,{})}]}exports.AIExtension=ce;exports.AIMenu=Ze;exports.AIMenuController=lo;exports.AIToolbarButton=uo;exports.BlockPositioner=We;exports.PromptSuggestionMenu=Je;exports.callLLM=Ee;exports.createAIExtension=Ht;exports.createBlockNoteAIClient=Ut;exports.getAIDictionary=N;exports.getAIExtension=I;exports.getAISlashMenuItems=fo;exports.getDefaultAIMenuItems=Ve;exports.llmFormats=qe;exports.promptHelpers=$t;
20
+ //# sourceMappingURL=blocknote-xl-ai.cjs.map