@blocknote/xl-ai 0.42.3 → 0.44.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 (342) hide show
  1. package/dist/blocknote-xl-ai.cjs +1 -9
  2. package/dist/blocknote-xl-ai.cjs.map +1 -1
  3. package/dist/blocknote-xl-ai.js +586 -3175
  4. package/dist/blocknote-xl-ai.js.map +1 -1
  5. package/dist/client-C4uaJa77.js +2228 -0
  6. package/dist/client-C4uaJa77.js.map +1 -0
  7. package/dist/client-DrruPiJu.cjs +36 -0
  8. package/dist/client-DrruPiJu.cjs.map +1 -0
  9. package/dist/server.cjs +2 -0
  10. package/dist/server.cjs.map +1 -0
  11. package/dist/server.js +25 -0
  12. package/dist/server.js.map +1 -0
  13. package/dist/webpack-stats.json +1 -1
  14. package/package.json +15 -9
  15. package/src/AIExtension.ts +442 -415
  16. package/src/api/aiRequest/{execute.ts → builder.ts} +31 -44
  17. package/src/api/aiRequest/index.ts +2 -2
  18. package/src/api/aiRequest/sendMessageWithAIRequest.ts +66 -0
  19. package/src/api/aiRequest/types.ts +10 -23
  20. package/src/api/formats/DocumentStateBuilder.ts +153 -0
  21. package/src/api/formats/base-tools/createAddBlocksTool.ts +5 -1
  22. package/src/api/formats/base-tools/createUpdateBlockTool.ts +5 -1
  23. package/src/api/formats/formats.ts +62 -0
  24. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/Add heading (h1) and code block_1_21c6ffe4ff4bd18e2a782b926b61618c.json +15 -0
  25. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add a list (end)_1_d0219ee443d8f6d3563dcffcba160730.json +15 -0
  26. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add a new paragraph (empty doc)_1_0737d0ae03c2d0adf101da14bdef2414.json +15 -0
  27. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add a new paragraph (end)_1_25717cdb5e0dabfd9e85a28126fc6b5b.json +15 -0
  28. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add a new paragraph (start)_1_8fc8e14082d21bf98623cd9ef57bafff.json +15 -0
  29. 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_72b3fb10d4b64ad2c57b7e759fb45ea2.json +15 -0
  30. 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_6330fcc2bc48733981e5337c6f38fe08.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 a new paragraph (empty doc)_1_1df3fb78a5790897b37bfba0ae96be1e.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 a new paragraph (end)_1_13ac6e523b724ec3d4e4113c1f973f7d.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 new paragraph (start)_1_c7a2f3226a4ee862c75a049c92cea98f.json +15 -0
  34. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/Add heading (h1) and code block_1_1d3b032c0f42ea308a1e7a13160bec4b.json +15 -0
  35. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add a list (end)_1_e341e2801f875f5ac4e8a4508c274b08.json +15 -0
  36. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add a new paragraph (empty doc)_1_42ec272374b0f12670f81c091e9ceaca.json +15 -0
  37. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add a new paragraph (end)_1_86ff29befb09692b6ca78454082eb4a9.json +15 -0
  38. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add a new paragraph (start)_1_3fd9b56671a58b30eff463b30963b76b.json +15 -0
  39. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/Add heading (h1) and code block_1_a7541d4dff5630b127b0284a513d8cb6.json +15 -0
  40. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add a list (end)_1_5fa40270f0d516da79eb1a7f58c7f43f.json +15 -0
  41. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add a new paragraph (empty doc)_1_42ba165a69a6e53683cb40d6018445bf.json +15 -0
  42. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add a new paragraph (end)_1_b5d7570beb28712970433d8b53528829.json +15 -0
  43. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add a new paragraph (start)_1_94232233e44ede5453eea20dd949c070.json +15 -0
  44. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add and update paragraph_1_2dbe9e9945d6cabc0b02e812a6ba1b93.json +15 -0
  45. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add paragraph and update selection_1_039451748eb07d71d3d7f96c97950d62.json +15 -0
  46. 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_7a6f24c686aeb896da8088bd8ea14089.json +15 -0
  47. 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_a7597ddda3f5117e1572545c53c19414.json +15 -0
  48. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add and update paragraph_1_1f86584753177f1b06f2cab6a822316b.json +15 -0
  49. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add paragraph and update selection_1_bb81e06e77589983badfe53e3839ab83.json +15 -0
  50. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add and update paragraph_1_d6725684f23346e66f8289d5ba72d7c1.json +15 -0
  51. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add paragraph and update selection_1_8b11b2a66564f9985f33774d3862cd8c.json +15 -0
  52. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/delete first block_1_71dfbd70fa9bcd8c2378c0b255360279.json +15 -0
  53. 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_72e05e8a661b9149b89f8ca9a80a2129.json +15 -0
  54. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/delete first block_1_00d51791f8357a4bc061a2cf8ce067f1.json +15 -0
  55. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/delete first block_1_83607282733aee32b5769107be6b9428.json +15 -0
  56. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/clear block formatting_1_f3ecead131eac14f117b601ad92bae90.json +15 -0
  57. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/drop mark and link and change text within mark_1_6b686110fa540e40d81fd68ee23cde86.json +15 -0
  58. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/drop mark and link_1_fee0a33a7c0951dacc8fd9ba02adef0a.json +15 -0
  59. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/modify nested content_1_1d18b29fde3a6494f2d1df98d0689bcf.json +15 -0
  60. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/modify parent content_1_7d96675c4edc13f69084f42983de6d73.json +15 -0
  61. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/plain source block, add mention_1_785d7f53424b53e8b64f4732aa578c61.json +15 -0
  62. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/standard update_1_c01c22b2bf79f30908ce9ffb0798a79f.json +15 -0
  63. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, remove mark_1_66f540dda8b5f8e8713b9c6f0bdd4d3f.json +15 -0
  64. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, remove mention_1_9111f9b26383721d9186c99d035f44e8.json +15 -0
  65. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, replace content_1_6a2c68962725ab2dc43dc12b5e9e5d8f.json +15 -0
  66. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, update mention prop_1_60f48a7bd81fb6a72b96b284d61c6e53.json +15 -0
  67. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, update text_1_284f982ebe3b60bc15c674d63795a879.json +15 -0
  68. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in target block, add mark (paragraph)_1_6c8e4ac91518d57e4827481f00ddc38e.json +15 -0
  69. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in target block, add mark (word)_1_06f3ae0ab5b505f03cf8e0c6bd654b1e.json +15 -0
  70. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/translate selection_1_885e9088214dbb6d50dcda19d0056f3c.json +15 -0
  71. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/turn paragraphs into list_1_0e8f14f06679e951d88ec74919c24b90.json +15 -0
  72. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/update block prop and content_1_f6c1cfee51cd75204495d3db1d80350e.json +15 -0
  73. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/update block prop_1_759983067f25f0daafb42bc9fefcdb64.json +15 -0
  74. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/update block type and content_1_e9d9d699bbe4a3b6e754c530ffe56e2c.json +15 -0
  75. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/update block type_1_ac405ec31a0cb874515b0c5b6aa2eb2d.json +15 -0
  76. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/clear block formatting_1_1b60a2dae45a21cc2916e15e97bfd289.json +15 -0
  77. 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_a7e99401a3cc86c79b30fdf47b0dc28e.json +15 -0
  78. 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_75e458d048de9ef0fb1eef34109ec81b.json +15 -0
  79. 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_f81acd3a9fb46c387163c91724ec4c55.json +15 -0
  80. 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_49c9371e221a7966cac554b99ba56b02.json +15 -0
  81. 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_b2be33e4a07122a85e49b521c20f26db.json +15 -0
  82. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/standard update_1_08d79a078de070c800627c412f9a0d9f.json +15 -0
  83. 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_0d87ce48c7e9e690bde7fc3668fe735b.json +15 -0
  84. 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_a96e84a734674ca195c2b40bab34c2fa.json +15 -0
  85. 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_f5be35337d2ac3c65ec6363d4f347364.json +15 -0
  86. 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_a09c043f6d105b1496a7c79ce34e28d3.json +15 -0
  87. 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_dfc536ede5303a75993dea08764b318e.json +15 -0
  88. 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_ebbeca51137a25dc54cdb7bafab53bed.json +15 -0
  89. 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_d6f14d8cecee690c72107e57eee0efbf.json +15 -0
  90. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/translate selection_1_1e9c30fa14f61508e6d90cbfa4d9b891.json +15 -0
  91. 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_50b1aa228a2b2557dea5026daaef2fad.json +15 -0
  92. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/update block prop and content_1_4a65e945b3b6fac5d4a0cf8d623486d3.json +15 -0
  93. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/update block prop_1_83a73dcfd05a6cf6754e1eb24114c1f1.json +15 -0
  94. 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_7500fd44498888e45aedc9dfa669737c.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)/update block type_1_92eb84e55a7b9efe5daf52bef299b4a6.json +15 -0
  96. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/clear block formatting_1_c3fe0bb003a4e1d613472af309c46ab0.json +15 -0
  97. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/drop mark and link and change text within mark_1_9724ffa3960f9e2f0853ca65fa305d5a.json +15 -0
  98. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/drop mark and link_1_ab436caf1e1c8338ab798b9e41f27035.json +15 -0
  99. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/modify nested content_1_030d3ad5a7f2e03a8f141379accd970d.json +15 -0
  100. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/modify parent content_1_8123bc6c0c42f952c5081494aae87db3.json +15 -0
  101. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/plain source block, add mention_1_7740e1127e576e342300ad8ca046c116.json +15 -0
  102. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/standard update_1_b940b7342e81fb99f50941824dca6dc9.json +15 -0
  103. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, remove mark_1_69370edf5666084e6ab44e3c9a41fa12.json +15 -0
  104. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, remove mention_1_73ae7ea818d0050772e68d743b8c8f07.json +15 -0
  105. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, replace content_1_493b1cae062778312080cf9e73436d03.json +15 -0
  106. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, update mention prop_1_812164c840f1ad02eb52b9b82e8adad1.json +15 -0
  107. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, update text_1_28d3f4434e75617be2e5aaffcb5c1ca7.json +15 -0
  108. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in target block, add mark (paragraph)_1_2fcc358ab0331d440742d0b28cdbffcd.json +15 -0
  109. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in target block, add mark (word)_1_d51e7544c0fcb93030a9d4c14970a487.json +15 -0
  110. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/translate selection_1_f82bcc59263074bf367562f7380b9cef.json +15 -0
  111. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/turn paragraphs into list_1_34265b84999198d0abed53174f1081a1.json +15 -0
  112. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/update block prop and content_1_8a8bb024ac97dfc5a47387ceb86a483f.json +15 -0
  113. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/update block prop_1_4a0be63bfbef46eea3c480cd5c20d78b.json +15 -0
  114. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/update block type and content_1_2e78a51589c195d5f4a1668482db03c4.json +15 -0
  115. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/update block type_1_77c40f25fadd092d83b41c87d2b21055.json +15 -0
  116. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/clear block formatting_1_09ce4ed21f35db11e7e8abc53d8e897c.json +15 -0
  117. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/drop mark and link and change text within mark_1_1072f99168883f64e55663c24b1b0a0d.json +15 -0
  118. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/drop mark and link_1_d0d892fae6bedce4f397e9e70a26c548.json +15 -0
  119. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/modify nested content_1_dd6cb439703f9c3f9bad5e2cc1a911c2.json +15 -0
  120. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/modify parent content_1_3a1e3c71094e24988b7f754e1d329f94.json +15 -0
  121. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/plain source block, add mention_1_19d556214c5ef684a2c65e3a08f14ba1.json +15 -0
  122. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/standard update_1_e0e15748dddab0b96d9367062c1ee445.json +15 -0
  123. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, remove mark_1_c69996aacaf807f2f988d23570f1829e.json +15 -0
  124. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, remove mention_1_86a5a7047cd626ede49fa5336b0cfedf.json +15 -0
  125. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, replace content_1_c29ec07799c4f9099789d65b819038e8.json +15 -0
  126. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, update mention prop_1_0355ff1065aab025d93ccddb0d5a1005.json +15 -0
  127. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, update text_1_d2b04758b99475efcd78a137aa91cfe4.json +15 -0
  128. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in target block, add mark (paragraph)_1_071517f9f358c0806dd80b49096a405d.json +15 -0
  129. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in target block, add mark (word)_1_4bdc947c29ac3c96b95afac6843a6894.json +15 -0
  130. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/translate selection_1_94c4e51be42ba73c81d7edc503e92b40.json +15 -0
  131. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/turn paragraphs into list_1_63ec354cac388bce6c2b6d324473b48f.json +15 -0
  132. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/update block prop and content_1_9290d6b9a47efc6589359e2820ef6702.json +15 -0
  133. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/update block prop_1_220afe040247e0efb76c73bf82ed4d4e.json +15 -0
  134. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/update block type and content_1_8494a477cce9b50c531800a11a8fd6ef.json +15 -0
  135. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/update block type_1_c25f2e6f9ffe088112413cc2ca87e75a.json +15 -0
  136. package/src/api/formats/html-blocks/htmlBlocks.test.ts +190 -194
  137. package/src/api/formats/html-blocks/htmlBlocks.ts +22 -25
  138. package/src/api/formats/index.ts +2 -72
  139. package/src/api/formats/json/errorHandling.test.ts +30 -41
  140. package/src/api/formats/json/json.test.ts +1 -5
  141. package/src/api/formats/json/json.ts +26 -26
  142. package/src/api/formats/json/tools/jsontools.test.ts +2 -2
  143. package/src/api/formats/markdown-blocks/markdownBlocks.test.ts +1 -6
  144. package/src/api/formats/markdown-blocks/markdownBlocks.ts +23 -26
  145. package/src/api/formats/tests/sharedTestCases.ts +26 -18
  146. package/src/api/promptHelpers/addCursorPosition.ts +27 -23
  147. package/src/components/AIMenu/AIMenu.tsx +18 -10
  148. package/src/components/AIMenu/AIMenuController.tsx +83 -29
  149. package/src/components/AIMenu/PromptSuggestionMenu.tsx +4 -2
  150. package/src/components/AIMenu/getDefaultAIMenuItems.tsx +17 -5
  151. package/src/components/FormattingToolbar/AIToolbarButton.tsx +13 -8
  152. package/src/components/SuggestionMenu/getAISlashMenuItems.tsx +5 -2
  153. package/src/{i18n → hooks}/useAIDictionary.ts +1 -1
  154. package/src/index.ts +2 -5
  155. package/src/prosemirror/agent.test.ts +2 -2
  156. package/src/server.ts +11 -0
  157. package/src/streamTool/ChunkExecutionError.ts +13 -0
  158. package/src/streamTool/StreamToolExecutor.ts +23 -21
  159. package/src/streamTool/filterNewOrUpdatedOperations.ts +1 -0
  160. package/src/streamTool/index.ts +3 -1
  161. package/src/streamTool/jsonSchema.ts +10 -0
  162. package/src/streamTool/preprocess.ts +3 -1
  163. package/src/streamTool/streamTool.ts +10 -7
  164. package/src/streamTool/vercelAiSdk/clientside/ClientSideTransport.ts +15 -4
  165. package/src/streamTool/vercelAiSdk/util/appendableStream.test.ts +247 -0
  166. package/src/streamTool/vercelAiSdk/util/appendableStream.ts +72 -0
  167. package/src/streamTool/vercelAiSdk/util/chatHandlers.test.ts +229 -0
  168. package/src/streamTool/vercelAiSdk/util/chatHandlers.ts +49 -78
  169. package/src/streamTool/vercelAiSdk/util/injectDocumentStateMessages.ts +79 -0
  170. package/src/streamTool/vercelAiSdk/util/toolDefinitions.ts +40 -0
  171. package/src/testUtil/cases/combinedOperationsTestCases.ts +1 -1
  172. package/src/testUtil/cases/editors/blockFormatting.ts +2 -2
  173. package/src/testUtil/cases/editors/emptyEditor.ts +2 -2
  174. package/src/testUtil/cases/editors/formattingAndMentions.ts +2 -2
  175. package/src/testUtil/cases/editors/simpleEditor.ts +3 -3
  176. package/src/testUtil/cases/editors/tables.ts +2 -2
  177. package/src/testUtil/cases/updateOperationTestCases.ts +4 -4
  178. package/src/types.ts +30 -10
  179. package/src/util/AbortError.ts +9 -0
  180. package/types/src/AIExtension.d.ts +32 -40
  181. package/types/src/api/aiRequest/builder.d.ts +11 -0
  182. package/types/src/api/aiRequest/index.d.ts +2 -2
  183. package/types/src/api/aiRequest/sendMessageWithAIRequest.d.ts +21 -0
  184. package/types/src/api/aiRequest/types.d.ts +9 -18
  185. package/types/src/api/formats/DocumentStateBuilder.d.ts +53 -0
  186. package/types/src/api/formats/formats.d.ts +142 -0
  187. package/types/src/api/formats/html-blocks/htmlBlocks.d.ts +4 -16
  188. package/types/src/api/formats/index.d.ts +2 -166
  189. package/types/src/api/formats/json/json.d.ts +8 -17
  190. package/types/src/api/formats/markdown-blocks/markdownBlocks.d.ts +2 -18
  191. package/types/src/api/promptHelpers/addCursorPosition.d.ts +1 -2
  192. package/types/src/components/AIMenu/AIMenuController.d.ts +2 -0
  193. package/types/src/index.d.ts +2 -5
  194. package/types/src/server.d.ts +5 -0
  195. package/types/src/streamTool/ChunkExecutionError.d.ts +8 -0
  196. package/types/src/streamTool/StreamToolExecutor.d.ts +3 -7
  197. package/types/src/streamTool/index.d.ts +3 -1
  198. package/types/src/streamTool/jsonSchema.d.ts +2 -0
  199. package/types/src/streamTool/streamTool.d.ts +2 -2
  200. package/types/src/streamTool/vercelAiSdk/clientside/ClientSideTransport.d.ts +12 -0
  201. package/types/src/streamTool/vercelAiSdk/util/appendableStream.d.ts +13 -0
  202. package/types/src/streamTool/vercelAiSdk/util/appendableStream.test.d.ts +1 -0
  203. package/types/src/streamTool/vercelAiSdk/util/chatHandlers.d.ts +3 -4
  204. package/types/src/streamTool/vercelAiSdk/util/chatHandlers.test.d.ts +1 -0
  205. package/types/src/streamTool/vercelAiSdk/util/injectDocumentStateMessages.d.ts +2 -0
  206. package/types/src/streamTool/vercelAiSdk/util/toolDefinitions.d.ts +13 -0
  207. package/types/src/types.d.ts +24 -7
  208. package/types/src/util/AbortError.d.ts +6 -0
  209. package/src/api/aiRequest/defaultAIRequestSender.ts +0 -42
  210. package/src/api/formats/PromptBuilder.ts +0 -22
  211. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/Add heading (h1) and code block_1_2b1987665a8c6b76ea1cc84255389571.json +0 -15
  212. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add a list (end)_1_d09f092a3a86410797b84afbe6a05773.json +0 -15
  213. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add a new paragraph (empty doc)_1_ca2502e6ccea5088da25c3f548a88adc.json +0 -15
  214. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add a new paragraph (end)_1_97ed001b6f5aed92d99361bc27ca0de9.json +0 -15
  215. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add a new paragraph (start)_1_83b238d8e21398ee970fac58c746fe19.json +0 -15
  216. 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_138de1ba18f0c4a7c084805a95d8aced.json +0 -15
  217. 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_e8b5b0d45734575f7ba8e685f6787aca.json +0 -15
  218. 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 (empty doc)_1_1ac8c5c60083d88192ef7e84254cb786.json +0 -15
  219. 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_a33718ee9e8c30a7679da0e2ea5443bf.json +0 -15
  220. 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_9b1a71da901951950261005a76c3444a.json +0 -15
  221. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/Add heading (h1) and code block_1_d64b87442b874d6c9d4a16dcc4f0df14.json +0 -15
  222. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add a list (end)_1_acd39fdc6762628fe6f6f97d96d70a78.json +0 -15
  223. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add a new paragraph (empty doc)_1_3912ffdff061476f701b59e0f28a5515.json +0 -15
  224. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add a new paragraph (end)_1_f047b5323417dfe603d6f28a0f063aa2.json +0 -15
  225. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add a new paragraph (start)_1_6e56df97b3441430062e0b5d979d53c9.json +0 -15
  226. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/Add heading (h1) and code block_1_787274f40054195631a7e1b7f70b88f0.json +0 -15
  227. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add a list (end)_1_ac04492f6c52be72c3dc24214a0cf744.json +0 -15
  228. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add a new paragraph (empty doc)_1_5b51dd620d4b53f36159ec97780b2929.json +0 -15
  229. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add a new paragraph (end)_1_17d834e2d1cae83d1da0998fdfb46c08.json +0 -15
  230. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Add/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add a new paragraph (start)_1_fded5061f67d6e01b6704bcaf1181daa.json +0 -15
  231. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add and update paragraph_1_c859fc3e363e6b44c406982880adeaf8.json +0 -15
  232. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/add paragraph and update selection_1_a721c27bc0944c3390dbcf6cbc4aa30d.json +0 -15
  233. 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_fc80a600d06d9b0a834b3a8dc062d077.json +0 -15
  234. 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_ea6525e3996561d49f3baaa53e5f4367.json +0 -15
  235. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add and update paragraph_1_a6ed8e1b1d7287f11052e60d21aa3c61.json +0 -15
  236. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/add paragraph and update selection_1_3f688e4336780f36c03fe2e06fb38ae1.json +0 -15
  237. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add and update paragraph_1_2ac4e99d05838a4666b65cfe9ffceee9.json +0 -15
  238. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Combined/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/add paragraph and update selection_1_dafc9c956b17f814f2e5daf2effc4612.json +0 -15
  239. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/delete first block_1_24119724ddeddbe1d724375ad7546eef.json +0 -15
  240. 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_fd0a1c180a2d6c7165823af96ca7a444.json +0 -15
  241. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/delete first block_1_5c60f0de80e4a010dcf6e7b2f534b1d7.json +0 -15
  242. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Delete/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/delete first block_1_9ee58319810833bcc30596aa06091958.json +0 -15
  243. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/clear block formatting_1_327facc19973ed5bf5dfbb06bc842f58.json +0 -15
  244. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/drop mark and link and change text within mark_1_68d51d1950b2878e08616f9effbee616.json +0 -15
  245. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/drop mark and link_1_1acc3cfa3a758ee4118f48b99e56f7b5.json +0 -15
  246. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/modify nested content_1_9158921bdd72e8f26eed1d4a3ccff6a4.json +0 -15
  247. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/modify parent content_1_a2946c73d9c3eeca81e4b4b08213a8a2.json +0 -15
  248. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/plain source block, add mention_1_91c94c8501e2f1d5d25c8e9c360dd3d1.json +0 -15
  249. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/standard update_1_adde6c9d6144449d4c436ed39a9afcb1.json +0 -15
  250. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, remove mark_1_4d2b9b00dc36b2bb12aae561adde829e.json +0 -15
  251. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, remove mention_1_06ade1c91064a7b257315d7cfb3dae1c.json +0 -15
  252. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, replace content_1_24881d7683d6ecbd852f58f6580259f4.json +0 -15
  253. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, update mention prop_1_1c9a4f955e0248798e87ab2412de660d.json +0 -15
  254. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in source block, update text_1_9e3a8c2b7c0c40aa89c4b52ccf040007.json +0 -15
  255. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in target block, add mark (paragraph)_1_d4c19bfff5993efff243e799e4055cc9.json +0 -15
  256. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/styles + ic in target block, add mark (word)_1_e31071ae9ad80a23786ec0afc5106c32.json +0 -15
  257. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/translate selection_1_efc8d37a125c48a5d0af15ecaf8e4b20.json +0 -15
  258. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/turn paragraphs into list_1_3ba9845d9c519b43ddbadaddb122d431.json +0 -15
  259. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/update block prop and content_1_4f6fdb800f1928aed2629f707b95b0da.json +0 -15
  260. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/update block prop_1_b25dd6e47055e54d58f1fd1f18feb14d.json +0 -15
  261. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/update block type and content_1_de3f09510d3c3eee14653fe5799dbae7.json +0 -15
  262. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/update block type_1_d805af33ab12e1bf8f2cb1a055a91fbd.json +0 -15
  263. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/clear block formatting_1_3b802465d0bbbdbbcb387b14492eefcc.json +0 -15
  264. 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_1138449389739970ddab00e2ca2b4bca.json +0 -15
  265. 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_2f40ee8072a0c34e771a2bd001d04b3a.json +0 -15
  266. 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_3d19c192afee48b2656b6bdf3ac80415.json +0 -15
  267. 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_88d6bccbefaf007c2c02e7e007c0f70b.json +0 -15
  268. 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_89cf6c28cb2ec992330f7c1bdc342068.json +0 -15
  269. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/standard update_1_b300195a352d5bddf97a0136eeb314e6.json +0 -15
  270. 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_008db1a44c8ee4e4d98c2e62c05f1906.json +0 -15
  271. 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_9a1800c42b72be41038a25622ff00709.json +0 -15
  272. 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_0463e82390d623aec168d4e483a8e7c1.json +0 -15
  273. 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_cf6b0ebb12aa86b848af40e9fa5aa4c6.json +0 -15
  274. 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_2b8a7aa1c2a0945eb657e1784120dabc.json +0 -15
  275. 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_7f14399291525650d7f05c5015dd3b59.json +0 -15
  276. 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_710f89bc66a6352e1c21328e600f2536.json +0 -15
  277. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/translate selection_1_d2ee0ac3b245b97f7a730d85a4575ac3.json +0 -15
  278. 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_d2eeb79d3f7120d2c9d698e3b82c7362.json +0 -15
  279. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/update block prop and content_1_e22ef915ccf69ed6d2eb9f1a04b86c20.json +0 -15
  280. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/update block prop_1_6d4c550d09a7bfdb440308f277b85a11.json +0 -15
  281. 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_2448cba67be91338d1977d4a980761a6.json +0 -15
  282. 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_88fade9a250bf912d8d65f9db17e6de7.json +0 -15
  283. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/clear block formatting_1_67c4abf409c5217946a8fd26353f3d5c.json +0 -15
  284. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/drop mark and link and change text within mark_1_4d1645603f58ac95cefa5802e9d0b576.json +0 -15
  285. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/drop mark and link_1_8235f32b241ce454e355284db306f2b5.json +0 -15
  286. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/modify nested content_1_1e7e3f801e8b2fcad2e947f25b842d59.json +0 -15
  287. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/modify parent content_1_06951fbd3511111eb460efd853b4c6ee.json +0 -15
  288. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/plain source block, add mention_1_d27b598add3108097cd76a3113395221.json +0 -15
  289. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/standard update_1_3e742ef6a27c2a70d6a34483f81b80cd.json +0 -15
  290. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, remove mark_1_3157ee5ddce8f578c94b14a1d8ee0694.json +0 -15
  291. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, remove mention_1_53046bb3c98a3ecc79d2ccc9f9ee1f88.json +0 -15
  292. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, replace content_1_d2aedab8bc5dae6b29a5dd2da56165d7.json +0 -15
  293. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, update mention prop_1_fddbbf8781b8c27f9e51a3f0183f370c.json +0 -15
  294. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in source block, update text_1_350896c5ea1c2ae3930e8300d37eb670.json +0 -15
  295. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in target block, add mark (paragraph)_1_da57da0afcca08a77da5df430ef1db17.json +0 -15
  296. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/styles + ic in target block, add mark (word)_1_717f43f6e3302767b191ed31d11b1dd6.json +0 -15
  297. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/translate selection_1_0e4c67cc4858f5dfe2f2004e598cdfbd.json +0 -15
  298. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/turn paragraphs into list_1_03c3d437686de6faba00429649340a81.json +0 -15
  299. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/update block prop and content_1_dd58f52c343818059aa71a9676a172d2.json +0 -15
  300. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/update block prop_1_a4f7c3617705406313b619c566afef36.json +0 -15
  301. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/update block type and content_1_9b630368d36a8a4420b20bd1e82e455d.json +0 -15
  302. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming + generateObject)/update block type_1_5da70d5932f66c0ba6f5b15bbb05f68e.json +0 -15
  303. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/clear block formatting_1_ec9d93709e473574521d55108aa27f8f.json +0 -15
  304. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/drop mark and link and change text within mark_1_6b7b58db82605ee0f2fe5146738274dd.json +0 -15
  305. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/drop mark and link_1_4fa98468d00af0302fb35faba6aa2823.json +0 -15
  306. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/modify nested content_1_e761f6071dd9550f02555f17668007d5.json +0 -15
  307. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/modify parent content_1_57bc2951494344f4cd0062fefce14e5f.json +0 -15
  308. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/plain source block, add mention_1_88263a5a62758f9c809abbab15d1c4c7.json +0 -15
  309. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/standard update_1_a68854dc4dee1520292cf8b8816d3bf1.json +0 -15
  310. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, remove mark_1_44bcd73901e9f2eef1a454db1dd3a05d.json +0 -15
  311. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, remove mention_1_89aa084ced0d3526355fa9ec0a7a0f38.json +0 -15
  312. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, replace content_1_3f251996dcb01d2a4adcb6b548554cc5.json +0 -15
  313. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, update mention prop_1_61b231ae85994a3eec1c2eaabb2b3e80.json +0 -15
  314. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in source block, update text_1_3fd6871badc2f924056864cd76a571c0.json +0 -15
  315. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in target block, add mark (paragraph)_1_728e83ee8b26541816af7dcf417e127b.json +0 -15
  316. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/styles + ic in target block, add mark (word)_1_abd0a85b8c45cfa0b4449a382dc81602.json +0 -15
  317. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/translate selection_1_c0b30a449a94314760b815a202ee6f64.json +0 -15
  318. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/turn paragraphs into list_1_cfbaa99fe0298f4754b6bdd81c0a9601.json +0 -15
  319. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/update block prop and content_1_a560a1761f87da8f3bdb7b42357ba4ec.json +0 -15
  320. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/update block prop_1_d959d9e97f6cf99760b26b7d17c11244.json +0 -15
  321. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/update block type and content_1_649d6a7338cc6b674c4b4c38184c1037.json +0 -15
  322. package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/update block type_1_9cbb96117eed2b41fee6c0802fe00bb2.json +0 -15
  323. package/src/api/formats/html-blocks/defaultHTMLPromptBuilder.ts +0 -200
  324. package/src/api/formats/html-blocks/htmlPromptData.ts +0 -92
  325. package/src/api/formats/json/defaultJSONPromptBuilder.ts +0 -173
  326. package/src/api/formats/json/jsonPromptData.ts +0 -97
  327. package/src/api/formats/markdown-blocks/defaultMarkdownPromptBuilder.ts +0 -172
  328. package/src/api/formats/markdown-blocks/markdownPromptData.ts +0 -91
  329. package/src/components/AIMenu/BlockPositioner.tsx +0 -86
  330. package/src/streamTool/toolDefinitionsToToolSet.ts +0 -24
  331. package/types/src/api/aiRequest/defaultAIRequestSender.d.ts +0 -4
  332. package/types/src/api/aiRequest/execute.d.ts +0 -31
  333. package/types/src/api/formats/PromptBuilder.d.ts +0 -17
  334. package/types/src/api/formats/html-blocks/defaultHTMLPromptBuilder.d.ts +0 -3
  335. package/types/src/api/formats/html-blocks/htmlPromptData.d.ts +0 -31
  336. package/types/src/api/formats/json/defaultJSONPromptBuilder.d.ts +0 -3
  337. package/types/src/api/formats/json/jsonPromptData.d.ts +0 -76
  338. package/types/src/api/formats/markdown-blocks/defaultMarkdownPromptBuilder.d.ts +0 -3
  339. package/types/src/api/formats/markdown-blocks/markdownPromptData.d.ts +0 -52
  340. package/types/src/components/AIMenu/BlockPositioner.d.ts +0 -10
  341. package/types/src/streamTool/toolDefinitionsToToolSet.d.ts +0 -9
  342. /package/types/src/{i18n → hooks}/useAIDictionary.d.ts +0 -0
@@ -1,2444 +1,31 @@
1
- var ot = Object.defineProperty;
2
- var rt = (e, t, o) => t in e ? ot(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
- var M = (e, t, o) => rt(e, typeof t != "symbol" ? t + "" : t, o);
4
- import { Chat as nt } from "@ai-sdk/react";
5
- import { getPmSchema as st, UnreachableCaseError as Be, getNodeById as Me, updateBlockTr as it, insertBlocks as at, trackPosition as ae, removeAndInsertBlocks as lt, getBlock as Ee, defaultProps as _e, isStyledTextInlineContent as ct, isLinkInlineContent as ut, BlockNoteExtension as dt, filterSuggestionItems as pt, mergeCSSClasses as mt } from "@blocknote/core";
6
- import { applySuggestions as Ne, suggestChanges as ft, revertSuggestions as le } from "@blocknote/prosemirror-suggest-changes";
7
- import { Slice as G, Fragment as ce } from "prosemirror-model";
8
- import { TextSelection as ht, Plugin as Le, PluginKey as Ae } from "prosemirror-state";
9
- import { fixTablesKey as yt } from "prosemirror-tables";
10
- import { DecorationSet as ue, Decoration as de } from "prosemirror-view";
11
- import { defaultSelectionBuilder as gt } from "y-prosemirror";
12
- import bt from "lodash.isequal";
13
- import { getErrorMessage as K } from "@ai-sdk/provider-utils";
14
- import { parsePartialJson as De, isToolUIPart as kt, tool as St, jsonSchema as pe, generateObject as wt, convertToModelMessages as Y, streamObject as Tt, streamText as xt } from "ai";
15
- import { Transform as D, Mapping as je, ReplaceStep as N, ReplaceAroundStep as vt } from "prosemirror-transform";
16
- import { ChangeSet as me, simplifyChanges as Pt } from "prosemirror-changeset";
17
- import { jsxs as Ct, jsx as y } from "react/jsx-runtime";
18
- import { useBlockNoteContext as Ot, useComponentsContext as X, useSuggestionMenuKeyboardHandler as It, useBlockNoteEditor as Q, useUIElementPositioning as Bt } from "@blocknote/react";
19
- import E, { useState as $e, useCallback as $, useMemo as A, useEffect as He } from "react";
20
- import { useStore as qe } from "zustand";
21
- import { offset as Mt, size as Et, autoUpdate as _t } from "@floating-ui/react";
22
- const fe = (e) => {
23
- let t;
24
- const o = /* @__PURE__ */ new Set(), r = (c, u) => {
25
- const m = typeof c == "function" ? c(t) : c;
26
- if (!Object.is(m, t)) {
27
- const p = t;
28
- t = u ?? (typeof m != "object" || m === null) ? m : Object.assign({}, t, m), o.forEach((d) => d(t, p));
29
- }
30
- }, n = () => t, i = { setState: r, getState: n, getInitialState: () => l, subscribe: (c) => (o.add(c), () => o.delete(c)) }, l = t = e(r, n, i);
31
- return i;
32
- }, he = (e) => e ? fe(e) : fe;
33
- function Nt(e) {
34
- const { properties: t, required: o, $defs: r, ...n } = e.inputSchema;
35
- return {
36
- schema: {
37
- type: "object",
38
- description: e.description,
39
- properties: {
40
- type: {
41
- type: "string",
42
- enum: [e.name]
43
- },
44
- ...t
45
- },
46
- required: ["type", ...o ?? []],
47
- additionalProperties: !1,
48
- ...n
49
- },
50
- $defs: r
51
- };
52
- }
53
- function Lt(e) {
54
- const t = e.map((r) => Nt(r)), o = {};
55
- for (const r of t)
56
- for (const n in r.$defs) {
57
- if (o[n] && !bt(o[n], r.$defs[n]))
58
- throw new Error(`Duplicate, but different definition for ${n}`);
59
- o[n] = r.$defs[n];
60
- }
61
- return {
62
- type: "object",
63
- properties: {
64
- operations: {
65
- //description:
66
- // "Operations to apply to the document. Put all operations in this array in ONE tool call / function call. DO NOT use multiple operation arrays with parallel tool calls.",
67
- type: "array",
68
- items: {
69
- anyOf: t.map((r) => r.schema)
70
- }
71
- }
72
- },
73
- additionalProperties: !1,
74
- required: ["operations"],
75
- $defs: Object.keys(o).length > 0 ? o : void 0
76
- };
77
- }
78
- function At(e, t) {
79
- return {
80
- async sendAIRequest(o, r) {
81
- const n = await t(o);
82
- return await e(o.chat.messages, n), o.chat.sendMessage(void 0, {
83
- ...r,
84
- body: {
85
- ...(r == null ? void 0 : r.body) ?? {},
86
- toolDefinitions: {
87
- applyDocumentOperations: {
88
- name: "applyDocumentOperations",
89
- inputSchema: Lt(o.streamTools),
90
- outputSchema: { type: "object" }
91
- }
92
- }
93
- },
94
- // we pass the promptData as metadata
95
- // so the transport can decide whether or not to submit this to the server
96
- // (DefaultChatTransport will not)
97
- metadata: { promptData: n }
98
- });
99
- }
100
- };
101
- }
102
- class ze extends Error {
103
- constructor(t, o, r) {
104
- super(t, r), this.chunk = o, this.name = "ChunkExecutionError";
105
- }
106
- }
107
- class Dt {
108
- /**
109
- * @param streamTools - The StreamTools to use to apply the StreamToolCalls
110
- */
111
- constructor(t) {
112
- M(this, "stream");
113
- this.streamTools = t, this.stream = this.createStream();
114
- }
115
- createStream() {
116
- let t;
117
- const o = new TransformStream({
118
- transform: async (i, l) => {
119
- const c = typeof i == "string" ? await jt(
120
- i,
121
- (t == null ? void 0 : t.isPossiblyPartial) ?? !1,
122
- this.streamTools
123
- ) : i;
124
- c && (t = c, l.enqueue(c));
125
- },
126
- flush: (i) => {
127
- t != null && t.isPossiblyPartial && i.error(new Error("stream ended with a partial operation"));
128
- }
129
- }), r = o.readable.pipeThrough(this.createExecutor()), [n, s] = r.tee(), a = n.pipeTo(new WritableStream());
130
- return {
131
- writable: o.writable,
132
- // expose externalReadable to the consumer
133
- readable: s,
134
- finishPromise: a
135
- };
136
- }
137
- createExecutor() {
138
- const t = this.streamTools.map((o) => o.executor());
139
- return new TransformStream({
140
- transform: async (o, r) => {
141
- var s;
142
- let n = !1;
143
- for (const a of t)
144
- try {
145
- if (await a.execute(o)) {
146
- r.enqueue({ status: "ok", chunk: o }), n = !0;
147
- break;
148
- }
149
- } catch (i) {
150
- throw new ze(
151
- `Tool execution failed: ${K(i)}`,
152
- o,
153
- {
154
- cause: i
155
- }
156
- );
157
- }
158
- if (!n) {
159
- const a = ((s = o.operation) == null ? void 0 : s.type) || "unknown";
160
- throw new Error(
161
- `No tool could handle operation of type: ${a}`
162
- );
163
- }
164
- }
165
- });
166
- }
167
- /**
168
- * Returns a WritableStream that can be used to write StreamToolCalls to the executor.
169
- *
170
- * The WriteableStream accepts JSON strings or Operation objects.
171
- *
172
- * Make sure to call `close` on the StreamToolExecutor instead of on the writable returned here!
173
- */
174
- get writable() {
175
- return this.stream.writable;
176
- }
177
- /**
178
- * Returns a ReadableStream that can be used to read the results of the executor.
179
- */
180
- get readable() {
181
- return this.stream.readable;
182
- }
183
- async finish() {
184
- await this.stream.finishPromise;
185
- }
186
- async executeOperationsArray(t) {
187
- const o = this.writable.getWriter();
188
- for await (const r of t) {
189
- const n = await De(r);
190
- if (n.state === "undefined-input" || n.state === "failed-parse" || !n)
191
- return;
192
- await o.write(r);
193
- }
194
- await o.close(), await this.finish();
195
- }
196
- /**
197
- * Accepts an async iterable and writes each chunk to the internal stream.
198
- *
199
- * (alternative to writing to the writable stream using {@link writable})
200
- */
201
- async execute(t) {
202
- const o = this.writable.getWriter();
203
- for await (const r of t)
204
- await o.write(r);
205
- await o.close(), await this.finish();
206
- }
207
- /**
208
- * Accepts a single chunk and processes it using the same logic.
209
- *
210
- * (alternative to writing to the writable stream using {@link writable})
211
- */
212
- async executeOne(t) {
213
- await this.execute(
214
- async function* () {
215
- yield {
216
- operation: t,
217
- isUpdateToPreviousOperation: !1,
218
- isPossiblyPartial: !1,
219
- metadata: {}
220
- };
221
- }()
222
- );
223
- }
224
- }
225
- async function jt(e, t, o) {
226
- const r = await De(e);
227
- if (r.state === "undefined-input" || r.state === "failed-parse" || !r)
228
- return;
229
- const n = o.find((a) => {
230
- var i;
231
- return a.name === ((i = r.value) == null ? void 0 : i.type);
232
- }), s = n && n.validate(r.value);
233
- if (s != null && s.ok)
234
- return {
235
- operation: s.value,
236
- isPossiblyPartial: r.state === "repaired-parse",
237
- isUpdateToPreviousOperation: t,
238
- metadata: void 0
239
- };
240
- }
241
- function $t(e) {
242
- return new ReadableStream({
243
- async start(t) {
244
- try {
245
- for await (const o of e)
246
- t.enqueue(o);
247
- t.close();
248
- } catch (o) {
249
- t.error(o);
250
- }
251
- }
252
- });
253
- }
254
- function Je(e) {
255
- if (e.locked)
256
- throw new Error(
257
- "Stream (source) is already locked and cannot be iterated."
258
- );
259
- const t = e.pipeThrough(new TransformStream());
260
- return t[Symbol.asyncIterator] = () => {
261
- if (t.locked)
262
- throw new Error("Stream is already locked and cannot be iterated again.");
263
- const o = t.getReader();
264
- return {
265
- async next() {
266
- const { done: r, value: n } = await o.read();
267
- return r ? { done: !0, value: void 0 } : { done: !1, value: n };
268
- }
269
- };
270
- }, t;
271
- }
272
- function Ht(e) {
273
- return Je($t(e));
274
- }
275
- async function* qt(e, t) {
276
- var s;
277
- let o = 0, r = !0, n;
278
- for await (const a of e)
279
- if ((s = a.operations) != null && s.length) {
280
- for (let i = o; i < a.operations.length; i++) {
281
- const l = a.operations[i];
282
- n = l, yield {
283
- partialOperation: l,
284
- isUpdateToPreviousOperation: i === o && !r,
285
- isPossiblyPartial: i === a.operations.length - 1,
286
- metadata: t
287
- }, r = !1;
288
- }
289
- o = a.operations.length - 1;
290
- }
291
- if (!n)
292
- throw new Error("No operations seen");
293
- yield {
294
- partialOperation: n,
295
- isUpdateToPreviousOperation: !0,
296
- isPossiblyPartial: !1,
297
- metadata: t
298
- };
299
- }
300
- async function* zt(e, t) {
301
- let o = !1;
302
- for await (const r of e) {
303
- const n = r.operation;
304
- n.ok ? (yield {
305
- operation: n.value,
306
- isUpdateToPreviousOperation: o ? !1 : r.isUpdateToPreviousOperation,
307
- isPossiblyPartial: r.isPossiblyPartial,
308
- metadata: r.metadata
309
- }, o = !1) : (o = o || !r.isUpdateToPreviousOperation, t == null || t({
310
- ...r,
311
- operation: n
312
- }));
313
- }
314
- }
315
- async function* Jt(e, t) {
316
- for await (const o of e) {
317
- const r = t.find(
318
- (s) => s.name === o.partialOperation.type
319
- );
320
- if (!r) {
321
- yield {
322
- operation: {
323
- ok: !1,
324
- error: `No matching function for ${o.partialOperation.type}`
325
- },
326
- isUpdateToPreviousOperation: o.isUpdateToPreviousOperation,
327
- isPossiblyPartial: o.isPossiblyPartial,
328
- metadata: o.metadata
329
- };
330
- continue;
331
- }
332
- yield {
333
- operation: r.validate(o.partialOperation),
334
- isUpdateToPreviousOperation: o.isUpdateToPreviousOperation,
335
- isPossiblyPartial: o.isPossiblyPartial,
336
- metadata: o.metadata
337
- };
338
- }
339
- }
340
- async function* Ut(e, t) {
341
- const o = Jt(
342
- e,
343
- t
344
- );
345
- yield* zt(
346
- o,
347
- (n) => {
348
- if (!n.isPossiblyPartial)
349
- throw new Error("invalid operation: " + n.operation.error);
350
- }
351
- );
352
- }
353
- function Vt(e, t, o) {
354
- return Ht(
355
- Ut(
356
- qt(
357
- Je(e),
358
- o
359
- ),
360
- t
361
- )
362
- );
363
- }
364
- async function Ft(e, t, o) {
365
- const r = new Dt(e), n = Rt();
366
- n.output.pipeTo(r.writable);
367
- const s = /* @__PURE__ */ new Map();
368
- let a = !0;
369
- const i = t["~registerMessagesCallback"](() => {
370
- Zt(t, (d) => {
371
- if (!s.has(d.toolCallId)) {
372
- const h = Wt(
373
- e,
374
- d.toolName,
375
- d.toolCallId
376
- );
377
- n.append(h.operationsStream), s.set(d.toolCallId, h), a && (a = !1, o == null || o());
378
- }
379
- return s.get(d.toolCallId);
380
- });
381
- });
382
- await new Promise((d) => {
383
- const h = t["~registerStatusCallback"](() => {
384
- (t.status === "ready" || t.status === "error") && (i(), h(), t.status !== "error" && f(), d());
385
- }), f = t["~registerErrorCallback"](() => {
386
- if (t.error) {
387
- f();
388
- for (const k of s.values())
389
- k.complete || k.writer.abort(t.error);
390
- }
391
- });
392
- }), await n.finalize();
393
- const c = (await Promise.allSettled([r.finish()]))[0];
394
- let u;
395
- if (c.status === "rejected") {
396
- if (c.reason instanceof ze)
397
- u = c.reason;
398
- else if (!t.error)
399
- throw new Error(
400
- "Unexpected: no ChunkExecutionError but also no chat.error (network error?)"
401
- );
402
- }
403
- let m = !1;
404
- const p = Array.from(
405
- s.values().filter((d) => d.complete)
406
- );
407
- if (p.forEach((d, h) => {
408
- const f = d.toolCallId === (u == null ? void 0 : u.chunk.metadata.toolCallId);
409
- f && (m = !0), t.addToolResult({
410
- tool: p[h].toolName,
411
- toolCallId: p[h].toolCallId,
412
- output: m === !1 ? { status: "ok" } : f ? { status: "error", error: K(u) } : { status: "not-executed-previous-tool-errored" }
413
- });
414
- }), u)
415
- throw u;
416
- if (t.error)
417
- throw t.error;
418
- }
419
- function Rt() {
420
- let e, t = Promise.resolve(), o = !1;
421
- const r = new ReadableStream({
422
- start(a) {
423
- e = a;
424
- },
425
- cancel(a) {
426
- o = !0, e.error(a);
427
- }
428
- });
429
- async function n(a) {
430
- if (o)
431
- throw new Error("Appendable stream canceled, can't append");
432
- const i = a.getReader();
433
- return t = t.then(async () => {
434
- for (; ; )
435
- try {
436
- const { done: l, value: c } = await i.read();
437
- if (l || o)
438
- break;
439
- e.enqueue(c);
440
- } catch (l) {
441
- o = !0, e.error(l);
442
- break;
443
- }
444
- }), t;
445
- }
446
- async function s() {
447
- await t, o || e.close();
448
- }
449
- return { output: r, append: n, finalize: s };
450
- }
451
- function Zt(e, t) {
452
- var o;
453
- for (const r of ((o = e.lastMessage) == null ? void 0 : o.parts) ?? []) {
454
- if (!kt(r) || r.type.replace("tool-", "") !== "applyDocumentOperations")
455
- continue;
456
- const s = r.toolCallId, a = t({
457
- toolName: r.type.replace("tool-", ""),
458
- toolCallId: s
459
- });
460
- Yt(r, a);
461
- }
462
- }
463
- function Wt(e, t, o) {
464
- const r = new TransformStream(), n = Vt(
465
- r.readable,
466
- e,
467
- { toolCallId: o }
468
- );
469
- return {
470
- // stream,
471
- writer: r.writable.getWriter(),
472
- complete: !1,
473
- // executor,
474
- operationsStream: n,
475
- toolName: t,
476
- toolCallId: o
477
- };
478
- }
479
- function Yt(e, t) {
480
- if (e.state === "input-streaming") {
481
- const o = e.input;
482
- o !== void 0 && t.writer.write(o);
483
- } else if (e.state === "input-available") {
484
- const o = e.input;
485
- if (o === void 0)
486
- throw new Error("input is undefined");
487
- t.complete || (t.complete = !0, t.writer.write(o), t.writer.close());
488
- }
489
- }
490
- function ee(e) {
491
- return (e.type === "paragraph" || !e.type) && !e.content || Array.isArray(e.content) && e.content.length === 0;
492
- }
493
- function Gt(e, t, o = !0, r = !0) {
494
- let n = 0, s = e.length;
495
- if (o)
496
- for (; n < s && t(e[n]); )
497
- n++;
498
- if (r)
499
- for (; s > n && t(e[s - 1]); )
500
- s--;
501
- return e.slice(n, s);
502
- }
503
- function w(e, t) {
504
- return Gt(
505
- e,
506
- (r) => ee(r) && (t == null ? void 0 : t.cursorBlockId) !== r.id,
507
- (t == null ? void 0 : t.trimStart) ?? !1,
508
- (t == null ? void 0 : t.trimEnd) ?? !0
509
- );
510
- }
511
- function Kt(e) {
512
- const { useSelection: t, deleteEmptyCursorBlock: o, streamToolsProvider: r } = {
513
- useSelection: e.useSelection ?? !1,
514
- deleteEmptyCursorBlock: e.deleteEmptyCursorBlock ?? !0,
515
- streamToolsProvider: e.streamToolsProvider ?? O.html.getStreamToolsProvider()
516
- }, n = t ? void 0 : e.editor.getTextCursorPosition().block, s = n && o && ee(n) && w(e.editor.document).length > 0 ? n.id : void 0, a = t ? e.editor.getSelectionCutBlocks() : void 0, i = r.getStreamTools(
517
- e.editor,
518
- a ? {
519
- from: a._meta.startPos,
520
- to: a._meta.endPos
521
- } : void 0,
522
- e.onBlockUpdated
523
- );
524
- return {
525
- editor: e.editor,
526
- chat: e.chat,
527
- userPrompt: e.userPrompt,
528
- selectedBlocks: a == null ? void 0 : a.blocks,
529
- streamTools: i,
530
- emptyCursorBlockToDelete: s
531
- };
532
- }
533
- async function Xt(e) {
534
- const { aiRequest: t, sender: o, chatRequestOptions: r, onStart: n } = e, s = Ft(
535
- t.streamTools,
536
- t.chat,
537
- () => {
538
- n == null || n(), t.emptyCursorBlockToDelete && t.editor.getBlock(t.emptyCursorBlockToDelete) && t.editor.removeBlocks([t.emptyCursorBlockToDelete]);
539
- }
540
- );
541
- await o.sendAIRequest(t, r), await s;
542
- }
543
- function Qt(e, t) {
544
- e.length > 0 && e.push(
545
- {
546
- role: "assistant",
547
- id: "document-state-" + e.length,
548
- parts: [
549
- {
550
- type: "text",
551
- text: "This is the latest state of the selection (ignore previous selections, you MUST issue operations against this latest version of the selection):"
552
- },
553
- {
554
- type: "text",
555
- text: JSON.stringify(t.htmlSelectedBlocks)
556
- },
557
- {
558
- type: "text",
559
- text: "This is the latest state of the document (INCLUDING the selected text), find the selected text in there to understand the context:"
560
- },
561
- {
562
- type: "text",
563
- text: JSON.stringify(t.htmlDocument)
564
- }
565
- ]
566
- },
567
- {
568
- role: "user",
569
- id: "user-prompt-" + e.length,
570
- parts: [
571
- {
572
- type: "text",
573
- text: "The user asks you to do the following:"
574
- },
575
- {
576
- type: "text",
577
- text: t.userPrompt
578
- }
579
- ]
580
- }
581
- ), e.push(
582
- {
583
- role: "system",
584
- id: "document-state-intro",
585
- parts: [
586
- {
587
- type: "text",
588
- text: "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:"
589
- }
590
- ]
591
- },
592
- {
593
- role: "system",
594
- id: "document-state-selection",
595
- parts: [
596
- {
597
- type: "text",
598
- text: JSON.stringify(t.htmlSelectedBlocks)
599
- }
600
- ]
601
- },
602
- {
603
- role: "system",
604
- id: "document-state-context",
605
- parts: [
606
- {
607
- type: "text",
608
- text: "This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"
609
- },
610
- {
611
- type: "text",
612
- text: JSON.stringify(t.htmlDocument)
613
- }
614
- ]
615
- },
616
- {
617
- role: "user",
618
- id: "user-prompt",
619
- parts: [
620
- {
621
- type: "text",
622
- text: t.userPrompt
623
- }
624
- ]
625
- }
626
- );
627
- }
628
- function eo(e, t) {
629
- if (e.length > 0) {
630
- e.push(
631
- {
632
- role: "assistant",
633
- id: "document-state-" + e.length,
634
- parts: [
635
- {
636
- type: "text",
637
- text: "This is the latest state of the document (ignore previous documents, you MUST issue operations against this latest version of the document):"
638
- },
639
- {
640
- type: "text",
641
- text: JSON.stringify(t.htmlBlocks)
642
- }
643
- ]
644
- },
645
- {
646
- role: "user",
647
- id: "user-prompt-" + e.length,
648
- parts: [
649
- {
650
- type: "text",
651
- text: t.userPrompt
652
- }
653
- ]
654
- }
655
- );
656
- return;
657
- }
658
- e.push(
659
- {
660
- role: "system",
661
- id: "document-state-intro",
662
- parts: [
663
- {
664
- type: "text",
665
- text: "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 (wrapped with <pre>) to specify the language.\n This is the initial document as an array of html blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):"
666
- }
667
- ]
668
- },
669
- {
670
- role: "system",
671
- id: "document-state-data",
672
- parts: [
673
- {
674
- type: "text",
675
- text: JSON.stringify(t.htmlBlocks)
676
- }
677
- ]
678
- },
679
- {
680
- role: "system",
681
- id: "extended-instructions",
682
- parts: [
683
- {
684
- type: "text",
685
- text: '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), \n then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`).\n \n ' + (t.isEmptyDocument ? "Because the document is empty, first update the empty block before adding new blocks." : "Prefer updating existing blocks over removing and adding (but this also depends on the user's question).")
686
- }
687
- ]
688
- },
689
- {
690
- role: "user",
691
- id: "user-prompt",
692
- parts: [
693
- {
694
- type: "text",
695
- text: t.userPrompt
696
- }
697
- ]
698
- }
699
- );
700
- }
701
- const to = async (e, t) => {
702
- t.selection ? Qt(e, t) : eo(e, t);
703
- };
704
- function Z(e, t) {
705
- const o = e.getTextCursorPosition(), r = [];
706
- for (const n of t) {
707
- const s = n.id === o.block.id;
708
- r.push({
709
- id: n.id,
710
- block: n.block
711
- }), s && r.push({
712
- cursor: !0
713
- });
714
- }
715
- return r;
716
- }
717
- async function P(e, t) {
718
- return await Promise.all(e.map(async (o) => ({
719
- id: o.id,
720
- block: await t(o)
721
- })));
722
- }
723
- function T(e) {
724
- return e.flatMap((t) => [
725
- {
726
- ...t,
727
- children: []
728
- },
729
- ...T(t.children)
730
- ]);
731
- }
732
- function _(e) {
733
- return e.map((t) => typeof t == "object" && t && "id" in t ? {
734
- ...t,
735
- id: `${t.id}$`
736
- } : t);
737
- }
738
- async function oo(e) {
739
- return e.selectedBlocks ? {
740
- ...await Ve(e.editor, {
741
- selectedBlocks: e.selectedBlocks
742
- }),
743
- userPrompt: e.userPrompt
744
- } : {
745
- ...await Ue(e.editor, {
746
- excludeBlockIds: e.emptyCursorBlockToDelete ? [e.emptyCursorBlockToDelete] : void 0
747
- }),
748
- userPrompt: e.userPrompt
749
- };
750
- }
751
- async function Ue(e, t) {
752
- const o = w(e.document).length === 0, r = e.getTextCursorPosition().block.id, n = w(e.document, {
753
- cursorBlockId: r
754
- }), s = await P(
755
- T(n),
756
- async (c) => e.blocksToHTMLLossy([c])
757
- ), i = Z(e, s).filter(
758
- (c) => "cursor" in c || !(t.excludeBlockIds || []).includes(c.id)
759
- );
760
- return {
761
- selection: !1,
762
- htmlBlocks: _(i),
763
- isEmptyDocument: o
764
- };
765
- }
766
- async function Ve(e, t) {
767
- const o = w(e.document).length === 0, r = await P(
768
- T(t.selectedBlocks),
769
- async (s) => e.blocksToHTMLLossy([s])
770
- ), n = _(r);
771
- return {
772
- isEmptyDocument: o,
773
- selection: !0,
774
- htmlSelectedBlocks: n,
775
- htmlDocument: (await P(T(e.document), async (s) => e.blocksToHTMLLossy([s]))).map(({ block: s }) => ({ block: s }))
776
- // strip ids so LLM can't accidentally issue updates to ids not in selection
777
- };
778
- }
779
- function ro(e) {
780
- let t, o = !1;
781
- return e.descendants((r, n) => o ? !1 : (r.isText && (o = !0, t = n), !0)), t;
782
- }
783
- function J(e) {
784
- var s;
785
- const t = st(e), { modification: o } = t.marks, r = [], n = new D(e.before);
786
- for (let a = 0; a < e.steps.length; a++) {
787
- const i = e.steps[a], l = new je(e.mapping.maps.slice(0, a)).invert();
788
- if (i.structure) {
789
- if (i instanceof N) {
790
- if (i.to !== i.from + 1 || i.slice.openStart !== 0 || i.slice.openEnd !== 1 || i.slice.content.size !== 2)
791
- throw new Error(
792
- "Structure change is not in expected format (ReplaceStep)"
793
- );
794
- } else if (i instanceof vt) {
795
- if (i.insert !== 1 || i.slice.size !== 2 || i.gapTo !== i.to - 1 || i.gapFrom !== i.from + 1)
796
- throw new Error(
797
- "Structure change is not in expected format (ReplaceAroundStep)"
798
- );
799
- } else
800
- throw new Error("Step is not a ReplaceStep or ReplaceAroundStep");
801
- const b = l.map(i.from), g = i.slice.content.firstChild, v = n.doc.resolve(n.mapping.map(b)).nodeAfter;
802
- let S = g.marks || [];
803
- g.type !== v.type && (S = o.create({
804
- type: "nodeType",
805
- previousValue: v.type.name,
806
- newValue: g.type.name
807
- }).addToSet(S));
808
- const j = /* @__PURE__ */ new Set([
809
- ...Object.keys(g.attrs),
810
- ...Object.keys(v.attrs)
811
- ]);
812
- for (const C of j)
813
- g.attrs[C] !== v.attrs[C] && (S = o.create({
814
- type: "attr",
815
- attrName: C,
816
- previousValue: v.attrs[C],
817
- newValue: g.attrs[C]
818
- }).addToSet(S));
819
- const B = n.steps.length;
820
- n.setNodeMarkup(
821
- n.mapping.map(b),
822
- g.type,
823
- g.attrs,
824
- S
825
- ), r.push({
826
- prosemirrorSteps: n.steps.slice(B),
827
- selection: void 0,
828
- type: "replace"
829
- });
830
- continue;
831
- }
832
- if (!(i instanceof N))
833
- throw new Error("Step is not a ReplaceStep");
834
- const c = l.map(i.from), u = l.map(i.to);
835
- if (i.slice.openStart > 0 || i.slice.openEnd > 0)
836
- throw new Error(
837
- "Slice has openStart or openEnd > 0, but structure=false"
838
- );
839
- r.push({
840
- prosemirrorSteps: [],
841
- selection: {
842
- anchor: n.mapping.map(c),
843
- head: n.mapping.map(u)
844
- },
845
- type: "select"
846
- });
847
- const m = i.slice.content.textBetween(0, i.slice.size), p = m === n.doc.textBetween(n.mapping.map(c), n.mapping.map(u));
848
- let d;
849
- if (p)
850
- d = i.slice.content.size;
851
- else if (m.length === 0)
852
- d = i.slice.content.size;
853
- else {
854
- const b = ro(i.slice.content);
855
- if (b === void 0)
856
- throw new Error("unexpected: no first character found");
857
- d = b + 1;
858
- }
859
- let h = n.mapping.map(u);
860
- const f = n.mapping.map(u);
861
- let k = !0;
862
- for (let b = d; b <= i.slice.content.size; b++) {
863
- const g = k && c !== u, v = n.steps.length;
864
- if (g) {
865
- const B = n.doc.resolve(n.mapping.map(c));
866
- (s = B.nodeAfter) != null && s.isBlock && n.addNodeMark(B.pos, t.mark("deletion", {})), n.addMark(B.pos, h, t.mark("deletion", {})), h = n.mapping.map(u);
867
- }
868
- const S = new G(i.slice.content.cut(0, b), 0, 0);
869
- n.replace(f, h, S).addMark(
870
- f,
871
- f + S.content.size,
872
- t.mark("insertion", {})
873
- ), n.doc.nodesBetween(
874
- f,
875
- f + S.content.size,
876
- (B, C) => C < f || C > f + S.content.size ? !0 : (B.isBlock && n.addNodeMark(C, t.mark("insertion", {})), !1)
877
- ), h = n.mapping.slice(v).map(h);
878
- const j = ht.near(
879
- n.doc.resolve(f + S.content.size),
880
- -1
881
- );
882
- r.push({
883
- prosemirrorSteps: n.steps.slice(v),
884
- selection: {
885
- anchor: j.from,
886
- head: j.from
887
- },
888
- type: g ? "replace" : "insert"
889
- // 3. Insert the replacement character by character
890
- }), k = !1;
891
- }
892
- }
893
- return r;
894
- }
895
- async function te(e) {
896
- const t = Math.random() * 0.3 + 0.85;
897
- if (e.type === "select")
898
- await new Promise((o) => setTimeout(o, 100 * t));
899
- else if (e.type === "insert")
900
- await new Promise((o) => setTimeout(o, 10 * t));
901
- else if (e.type === "replace")
902
- await new Promise((o) => setTimeout(o, 200 * t));
903
- else
904
- throw new Be(e.type);
905
- }
906
- function oe(e, t) {
907
- e.setMeta("addToHistory", !1), t.selection && e.setMeta("aiAgent", {
908
- selection: {
909
- anchor: t.selection.anchor,
910
- head: t.selection.head
911
- }
912
- });
913
- for (const o of t.prosemirrorSteps)
914
- if (e.maybeStep(o).failed)
915
- throw new Error("failed to apply step");
916
- return e;
917
- }
918
- function no(e, t, o) {
919
- const r = new D(t);
920
- for (const a of e) {
921
- const i = new N(
922
- r.mapping.map(a.fromA),
923
- r.mapping.map(a.toA),
924
- o.slice(a.fromB, a.toB)
925
- );
926
- r.step(i);
927
- }
928
- const n = r.mapping.invert();
929
- let s = r.doc.content.findDiffStart(o.content);
930
- for (; s !== null; ) {
931
- const a = o.resolve(s).nodeAfter, i = r.doc.resolve(s).nodeAfter;
932
- if (!a || !i)
933
- throw new Error("diffNode not found");
934
- const l = !a.isLeaf && a.content.eq(i.content), c = l ? 1 : Math.min(a.nodeSize, i.nodeSize), u = s + c, m = n.map(s), p = n.map(u);
935
- let d = e.length;
936
- for (let f = 0; f < e.length; f++)
937
- if (e[f].fromA >= p) {
938
- d = f;
939
- break;
940
- }
941
- e.splice(d, 0, {
942
- fromA: m,
943
- toA: p,
944
- fromB: s,
945
- toB: u,
946
- deleted: [],
947
- inserted: [],
948
- type: l ? "node-type-or-attr-update" : "mark-update"
949
- }), r.step(
950
- new N(
951
- s,
952
- u,
953
- o.slice(s, u),
954
- l
955
- )
956
- );
957
- const h = r.doc.content.findDiffStart(o.content);
958
- if (h === s)
959
- throw new Error("diffStart not moving");
960
- s = h;
961
- }
962
- return e;
963
- }
964
- const ye = (e, t) => {
965
- const o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
966
- e.descendants((a) => {
967
- a.type.name === "tableCell" && o.add(JSON.stringify(a.toJSON()));
968
- }), t.descendants((a) => {
969
- a.type.name === "tableCell" && r.add(JSON.stringify(a.toJSON()));
970
- });
971
- const n = new Set(
972
- [...o].filter((a) => r.has(a))
973
- );
974
- return {
975
- encodeCharacter: (a) => a,
976
- encodeNodeStart: (a) => {
977
- if (a.type.name === "tableCell") {
978
- const i = JSON.stringify(a.toJSON());
979
- return n.has(i) ? i : a.type.name;
980
- }
981
- return a.type.name;
982
- },
983
- encodeNodeEnd: (a) => {
984
- if (a.type.name === "tableCell") {
985
- const i = JSON.stringify(a.toJSON());
986
- return n.has(i) ? i : -1;
987
- }
988
- return -1;
989
- },
990
- compareTokens: (a, i) => a === i
991
- };
992
- };
993
- function W(e, t, o = !1, r, n) {
994
- const s = Me(e.id, t), a = new D(t);
995
- it(
996
- a,
997
- s.posBeforeNode,
998
- e.block,
999
- r,
1000
- n
1001
- );
1002
- let i = a.doc, l = me.create(
1003
- t,
1004
- void 0,
1005
- ye(t, i)
1006
- );
1007
- if (l = l.addSteps(i, a.mapping.maps, 0), o && l.changes.length > 0) {
1008
- const m = l.changes[l.changes.length - 1], p = m.toA - m.fromA, d = m.toB - m.fromB;
1009
- if (p > d) {
1010
- const h = t.slice(
1011
- m.fromA + d,
1012
- m.toA
1013
- );
1014
- a.step(
1015
- new N(m.toB, m.toB, h)
1016
- ), i = a.doc, l = me.create(
1017
- l.startDoc,
1018
- void 0,
1019
- ye(l.startDoc, i)
1020
- ), l = l.addSteps(i, a.mapping.maps, 0);
1021
- }
1022
- }
1023
- const c = [], u = Pt(
1024
- l.changes,
1025
- i
1026
- );
1027
- for (let m = 0; m < u.length; m++) {
1028
- const p = u[m], d = i.slice(p.fromB, p.toB);
1029
- if (d.openEnd === 1 && d.openStart === 0 && (p.type = "node-type-or-attr-update", d.size > 2)) {
1030
- const h = {
1031
- fromA: p.fromA,
1032
- toA: p.fromA + 1,
1033
- fromB: p.fromB,
1034
- toB: p.fromB + 1,
1035
- deleted: [],
1036
- inserted: [],
1037
- type: "node-type-or-attr-update"
1038
- }, f = {
1039
- fromA: p.fromA + 1,
1040
- toA: p.toA,
1041
- fromB: p.fromB + 1,
1042
- toB: p.toB,
1043
- deleted: [],
1044
- inserted: []
1045
- };
1046
- u.splice(m, 1, h, f), m++;
1047
- }
1048
- }
1049
- no(u, t, i);
1050
- for (let m = 0; m < u.length; m++) {
1051
- const p = u[m], d = i.slice(p.fromB, p.toB);
1052
- if (d.openEnd > 0 && d.size > 1)
1053
- throw new Error(
1054
- "unexpected, openEnd > 0 and size > 1, this should have been split into two steps"
1055
- );
1056
- m === u.length - 1 && o && p.type === "mark-update" || c.push(
1057
- new N(
1058
- p.fromA,
1059
- p.toA,
1060
- d,
1061
- p.type === "node-type-or-attr-update"
1062
- )
1063
- );
1064
- }
1065
- return c;
1066
- }
1067
- function so(e, t) {
1068
- if (!e || !Array.isArray(e) || e.length === 0)
1069
- return {
1070
- ok: !1,
1071
- error: "blocks is required"
1072
- };
1073
- const o = [];
1074
- for (const r of e) {
1075
- const n = t(r);
1076
- if (!n.ok)
1077
- return {
1078
- ok: !1,
1079
- error: `Invalid block: ${n.error}`
1080
- };
1081
- o.push(n.value);
1082
- }
1083
- return {
1084
- ok: !0,
1085
- value: o
1086
- };
1087
- }
1088
- function re(e) {
1089
- return (t, o) => {
1090
- const r = typeof e.schema == "function" ? e.schema(t) : e.schema;
1091
- return {
1092
- name: "add",
1093
- description: e.description,
1094
- inputSchema: {
1095
- type: "object",
1096
- properties: {
1097
- referenceId: {
1098
- type: "string",
1099
- description: "MUST be an id of a block in the document"
1100
- },
1101
- position: {
1102
- type: "string",
1103
- enum: ["before", "after"],
1104
- description: "`after` to add blocks AFTER (below) the block with `referenceId`, `before` to add the block BEFORE (above)"
1105
- },
1106
- blocks: {
1107
- items: r.block,
1108
- type: "array"
1109
- }
1110
- },
1111
- required: ["referenceId", "position", "blocks"],
1112
- $defs: r.$defs
1113
- },
1114
- validate: (n) => {
1115
- if (n.type !== "add")
1116
- return {
1117
- ok: !1,
1118
- error: "invalid operation type"
1119
- };
1120
- if (n.position !== "before" && n.position !== "after")
1121
- return {
1122
- ok: !1,
1123
- error: "invalid position"
1124
- };
1125
- if (!n.referenceId || !n.blocks)
1126
- return {
1127
- ok: !1,
1128
- error: "referenceId and blocks are required"
1129
- };
1130
- let s = n.referenceId;
1131
- if (o.idsSuffixed) {
1132
- if (!(s != null && s.endsWith("$")))
1133
- return {
1134
- ok: !1,
1135
- error: "referenceId must end with $"
1136
- };
1137
- s = s.slice(0, -1);
1138
- }
1139
- if (!t.getBlock(s))
1140
- return {
1141
- ok: !1,
1142
- error: "referenceId not found"
1143
- };
1144
- const i = so(
1145
- n.blocks,
1146
- (l) => e.validateBlock(l, t)
1147
- );
1148
- return i.ok ? {
1149
- ok: !0,
1150
- value: {
1151
- type: n.type,
1152
- referenceId: s,
1153
- position: n.position,
1154
- blocks: i.value
1155
- }
1156
- } : i;
1157
- },
1158
- // Note: functionality mostly tested in jsontools.test.ts
1159
- // would be nicer to add a direct unit test
1160
- executor: () => {
1161
- let n = [];
1162
- const s = {};
1163
- return {
1164
- execute: async (a) => {
1165
- var c;
1166
- if (a.isUpdateToPreviousOperation || (n = []), a.operation.type !== "add")
1167
- return !1;
1168
- const i = a.operation, l = await e.toJSONToolCall(t, {
1169
- ...a,
1170
- operation: i
1171
- });
1172
- if (!l || a.isPossiblyPartial && ee(
1173
- l.blocks[l.blocks.length - 1]
1174
- ))
1175
- return !0;
1176
- for (let u = 0; u < l.blocks.length; u++) {
1177
- const m = l.blocks[u], p = t.prosemirrorState.tr;
1178
- let d = [];
1179
- if (u < n.length) {
1180
- const h = await e.rebaseTool(n[u], t), k = W(
1181
- {
1182
- id: n[u],
1183
- block: m
1184
- },
1185
- h.doc,
1186
- !1
1187
- ).map((b) => b.map(h.invertMap));
1188
- for (const b of k)
1189
- p.step(b.map(p.mapping));
1190
- d = J(p), d = d.filter(
1191
- (b) => b.type !== "select"
1192
- );
1193
- } else {
1194
- const h = i.position === "after" ? s[i.referenceId] : void 0, f = at(
1195
- p,
1196
- [m],
1197
- u > 0 ? n[u - 1] : h || i.referenceId,
1198
- u > 0 ? "after" : i.position
1199
- );
1200
- n.push(...f.map((k) => k.id)), d = J(p);
1201
- }
1202
- for (const h of d)
1203
- o.withDelays && await te(h), t.transact((f) => {
1204
- oe(f, h);
1205
- }), (c = o.onBlockUpdate) == null || c.call(o, n[u]);
1206
- }
1207
- return a.isPossiblyPartial || i.position === "after" && (s[i.referenceId] = n[n.length - 1]), !0;
1208
- }
1209
- };
1210
- }
1211
- };
1212
- };
1213
- }
1214
- function ne(e) {
1215
- return (t, o) => {
1216
- const r = typeof e.schema == "function" ? e.schema(t) : e.schema;
1217
- return {
1218
- name: "update",
1219
- description: e.description,
1220
- inputSchema: {
1221
- type: "object",
1222
- properties: {
1223
- id: {
1224
- type: "string",
1225
- description: "id of block to update"
1226
- },
1227
- block: r.block
1228
- },
1229
- required: ["id", "block"],
1230
- $defs: r.$defs
1231
- },
1232
- validate: (n) => {
1233
- if (n.type !== "update")
1234
- return {
1235
- ok: !1,
1236
- error: "invalid operation type"
1237
- };
1238
- if (!n.id)
1239
- return {
1240
- ok: !1,
1241
- error: "id is required"
1242
- };
1243
- let s = n.id;
1244
- if (o.idsSuffixed) {
1245
- if (!(s != null && s.endsWith("$")))
1246
- return {
1247
- ok: !1,
1248
- error: "id must end with $"
1249
- };
1250
- s = s.slice(0, -1);
1251
- }
1252
- if (!n.block)
1253
- return {
1254
- ok: !1,
1255
- error: "block is required"
1256
- };
1257
- const a = t.getBlock(s);
1258
- if (!a)
1259
- return console.error("BLOCK NOT FOUND", s), {
1260
- ok: !1,
1261
- error: "block not found"
1262
- };
1263
- const i = e.validateBlock(n.block, t, a.type);
1264
- return i.ok ? {
1265
- ok: !0,
1266
- value: {
1267
- type: n.type,
1268
- id: s,
1269
- block: i.value
1270
- }
1271
- } : i;
1272
- },
1273
- // Note: functionality mostly tested in jsontools.test.ts
1274
- // would be nicer to add a direct unit test
1275
- executor: () => {
1276
- let s = 50;
1277
- const a = o.updateSelection ? {
1278
- from: ae(t, o.updateSelection.from),
1279
- to: ae(t, o.updateSelection.to)
1280
- } : void 0;
1281
- return {
1282
- execute: async (i) => {
1283
- var b;
1284
- if (i.operation.type !== "update")
1285
- return !1;
1286
- const l = i.operation;
1287
- if (i.isPossiblyPartial) {
1288
- const g = JSON.stringify(l.block).length;
1289
- if (g < s)
1290
- return !0;
1291
- s = g + 50;
1292
- } else
1293
- s = 50;
1294
- const c = await e.rebaseTool(l.id, t), u = a ? c.invertMap.invert().map(a.from()) : void 0, m = a ? c.invertMap.invert().map(a.to()) : void 0, p = await e.toJSONToolCall(t, {
1295
- ...i,
1296
- operation: l
1297
- });
1298
- if (!p)
1299
- return !0;
1300
- const d = W(
1301
- p,
1302
- c.doc,
1303
- i.isPossiblyPartial,
1304
- u,
1305
- m
1306
- );
1307
- if (d.length === 1 && i.isPossiblyPartial)
1308
- return !0;
1309
- const h = d.map((g) => g.map(c.invertMap)), f = new D(t.prosemirrorState.doc);
1310
- for (const g of h)
1311
- f.step(g.map(f.mapping));
1312
- const k = J(f);
1313
- for (const g of k)
1314
- o.withDelays && await te(g), t.transact((v) => {
1315
- oe(v, g);
1316
- }), (b = o.onBlockUpdate) == null || b.call(o, l.id);
1317
- return !0;
1318
- }
1319
- };
1320
- }
1321
- };
1322
- };
1323
- }
1324
- const se = (e, t) => ({
1325
- name: "delete",
1326
- description: "Delete a block",
1327
- inputSchema: {
1328
- type: "object",
1329
- properties: {
1330
- id: {
1331
- type: "string",
1332
- description: "id of block to delete"
1333
- }
1334
- },
1335
- required: ["id"]
1336
- },
1337
- validate: (o) => {
1338
- if (o.type !== "delete")
1339
- return {
1340
- ok: !1,
1341
- error: "invalid operation type"
1342
- };
1343
- if (!o.id)
1344
- return {
1345
- ok: !1,
1346
- error: "id is required"
1347
- };
1348
- let r = o.id;
1349
- if (t.idsSuffixed) {
1350
- if (!(r != null && r.endsWith("$")))
1351
- return {
1352
- ok: !1,
1353
- error: "id must end with $"
1354
- };
1355
- r = r.slice(0, -1);
1356
- }
1357
- return e.getBlock(r) ? {
1358
- ok: !0,
1359
- value: {
1360
- type: "delete",
1361
- id: r
1362
- }
1363
- } : {
1364
- ok: !1,
1365
- error: "block not found"
1366
- };
1367
- },
1368
- // Note: functionality mostly tested in jsontools.test.ts
1369
- // would be nicer to add a direct unit test
1370
- executor: () => ({
1371
- execute: async (o) => {
1372
- var a;
1373
- if (o.operation.type !== "delete")
1374
- return !1;
1375
- const r = o.operation, n = e.prosemirrorState.tr;
1376
- lt(n, [r.id], []);
1377
- const s = J(n);
1378
- for (const i of s)
1379
- t.withDelays && await te(i), e.transact((l) => {
1380
- oe(l, i);
1381
- }), (a = t.onBlockUpdate) == null || a.call(t, r.id);
1382
- return !0;
1383
- }
1384
- })
1385
- });
1386
- function ge(e) {
1387
- const t = e.lastIndexOf("<"), o = e.lastIndexOf(">");
1388
- let r = e;
1389
- if (t > o && (r = e.substring(0, t), !r.trim()))
1390
- return;
1391
- const n = r.match(/&[a-zA-Z0-9]*$/);
1392
- n && (r = r.substring(
1393
- 0,
1394
- r.length - n[0].length
1395
- ));
1396
- const i = new DOMParser().parseFromString(
1397
- `<div>${r}</div>`,
1398
- "text/html"
1399
- ).body.firstChild;
1400
- return i ? i.innerHTML : "";
1401
- }
1402
- function U(e) {
1403
- let t;
1404
- if (Ne(e.prosemirrorState, (o) => {
1405
- t = o;
1406
- }), !t)
1407
- throw new Error("applySuggestionsTr is not set");
1408
- return t;
1409
- }
1410
- function V(e, t) {
1411
- const o = t.mapping.invert();
1412
- return {
1413
- doc: t.doc,
1414
- /**
1415
- * Return a new transform that has the projection applied.
1416
- * You can add new operations to this transform and later rebase those on the original document with `rebaseTr`
1417
- */
1418
- tr: () => new D(t.doc),
1419
- /**
1420
- * Invert map created by the projection.
1421
- * You can use this to map positions on the "clean" document (the projection) to positions on the original document
1422
- */
1423
- invertMap: o,
1424
- /**
1425
- * Return a new transaction based on the editor state with all the steps you made to `tr`.
1426
- * These steps are rebased on the original document.
1427
- */
1428
- rebaseTr: (r) => {
1429
- if (r.steps.length === 0)
1430
- throw new Error("No steps to apply");
1431
- let n = e.prosemirrorState.tr;
1432
- for (const s of r.steps) {
1433
- const a = s.map(o);
1434
- if (!a)
1435
- throw new Error("Step is not mapped");
1436
- n = n.step(a);
1437
- }
1438
- return n;
1439
- }
1440
- };
1441
- }
1442
- async function be(e, t) {
1443
- var c;
1444
- const o = U(t), r = Ee(o.doc, e);
1445
- if (!r)
1446
- throw new Error("block not found");
1447
- const n = await t.blocksToHTMLLossy([
1448
- {
1449
- ...r,
1450
- children: []
1451
- }
1452
- ]), s = (c = window.__TEST_OPTIONS) == null ? void 0 : c.mockID, a = await t.tryParseHTMLToBlocks(n);
1453
- if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = s), a.length !== 1)
1454
- throw new Error("html diff invalid block count");
1455
- const i = a[0];
1456
- if (i.id = e, W(
1457
- {
1458
- id: e,
1459
- block: i
1460
- },
1461
- o.doc
1462
- ).length)
1463
- throw new Error("html diff");
1464
- return V(t, o);
1465
- }
1466
- function ke(e) {
1467
- return typeof e != "string" ? {
1468
- ok: !1,
1469
- error: "block must be a string"
1470
- } : {
1471
- ok: !0,
1472
- value: e
1473
- };
1474
- }
1475
- const H = {
1476
- add: re({
1477
- description: "Insert new blocks",
1478
- schema: {
1479
- block: {
1480
- type: "string",
1481
- description: "html of block (MUST be a single, VALID HTML element)"
1482
- }
1483
- },
1484
- validateBlock: ke,
1485
- rebaseTool: be,
1486
- toJSONToolCall: async (e, t) => {
1487
- var n;
1488
- const o = (n = window.__TEST_OPTIONS) == null ? void 0 : n.mockID, r = (await Promise.all(
1489
- t.operation.blocks.map(async (s) => {
1490
- const a = t.isPossiblyPartial ? ge(s) : s;
1491
- return a ? (await e.tryParseHTMLToBlocks(a)).map(
1492
- (i) => (delete i.id, i)
1493
- ) : [];
1494
- })
1495
- )).flat();
1496
- if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = o), r.length !== 0)
1497
- return {
1498
- ...t.operation,
1499
- blocks: r
1500
- };
1501
- }
1502
- }),
1503
- update: ne({
1504
- description: "Update a block",
1505
- schema: {
1506
- block: {
1507
- type: "string",
1508
- description: "html of block (MUST be a single HTML element)"
1509
- }
1510
- },
1511
- validateBlock: ke,
1512
- rebaseTool: be,
1513
- toJSONToolCall: async (e, t) => {
1514
- const o = t.isPossiblyPartial ? ge(t.operation.block) : t.operation.block;
1515
- if (!o)
1516
- return;
1517
- const r = (await e.tryParseHTMLToBlocks(o))[0];
1518
- return window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), delete r.id, {
1519
- ...t.operation,
1520
- block: r
1521
- };
1522
- }
1523
- }),
1524
- delete: se
1525
- };
1526
- function io(e, t, o, r, n) {
1527
- if (typeof r == "boolean") {
1528
- const i = r ? e.getSelectionCutBlocks() : void 0;
1529
- r = i ? {
1530
- from: i._meta.startPos,
1531
- to: i._meta.endPos
1532
- } : void 0;
1533
- }
1534
- const s = o ?? {
1535
- add: !0,
1536
- update: !0,
1537
- delete: !0
1538
- };
1539
- return [
1540
- ...s.update ? [
1541
- H.update(e, {
1542
- idsSuffixed: !0,
1543
- withDelays: t,
1544
- updateSelection: r,
1545
- onBlockUpdate: n
1546
- })
1547
- ] : [],
1548
- ...s.add ? [H.add(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : [],
1549
- ...s.delete ? [H.delete(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : []
1550
- ];
1551
- }
1552
- const ao = {
1553
- /**
1554
- * Function to get the stream tools that can apply HTML block updates to the editor
1555
- */
1556
- getStreamToolsProvider: (e = {}) => ({
1557
- getStreamTools: (t, o, r) => io(
1558
- t,
1559
- e.withDelays ?? !0,
1560
- e.defaultStreamTools,
1561
- o,
1562
- r
1563
- )
1564
- }),
1565
- tools: H,
1566
- /**
1567
- * The default PromptBuilder that determines how a userPrompt is converted to an array of
1568
- * LLM Messages (CoreMessage[])
1569
- */
1570
- defaultPromptBuilder: to,
1571
- /**
1572
- * The default PromptInputDataBuilder that can take an editor and user request and convert it to the input required for the PromptBuilder
1573
- */
1574
- defaultPromptInputDataBuilder: oo,
1575
- /**
1576
- * Helper functions which can be used when implementing a custom PromptBuilder
1577
- */
1578
- promptHelpers: {
1579
- getDataForPromptNoSelection: Ue,
1580
- getDataForPromptWithSelection: Ve
1581
- }
1582
- };
1583
- async function lo(e) {
1584
- return e.selectedBlocks ? {
1585
- ...await Re(e.editor, {
1586
- selectedBlocks: e.selectedBlocks
1587
- }),
1588
- userPrompt: e.userPrompt
1589
- } : {
1590
- ...await Fe(e.editor, {
1591
- excludeBlockIds: e.emptyCursorBlockToDelete ? [e.emptyCursorBlockToDelete] : void 0
1592
- }),
1593
- userPrompt: e.userPrompt
1594
- };
1595
- }
1596
- async function Fe(e, t) {
1597
- const o = w(e.document).length === 0, r = e.getTextCursorPosition().block.id, n = w(e.document, {
1598
- cursorBlockId: r
1599
- }), s = await P(
1600
- T(n),
1601
- async (c) => ({
1602
- ...c,
1603
- children: void 0
1604
- })
1605
- ), i = Z(e, s).filter(
1606
- (c) => "cursor" in c || !(t.excludeBlockIds || []).includes(c.id)
1607
- );
1608
- return {
1609
- selection: !1,
1610
- jsonBlocks: _(i),
1611
- isEmptyDocument: o
1612
- };
1613
- }
1614
- async function Re(e, t) {
1615
- const o = w(e.document).length === 0, r = await P(
1616
- T(t.selectedBlocks),
1617
- async (s) => s
1618
- ), n = _(r);
1619
- return {
1620
- isEmptyDocument: o,
1621
- selection: !0,
1622
- jsonSelectedBlocks: n,
1623
- jsonDocument: (await P(T(e.document), async (s) => ({
1624
- ...s,
1625
- id: void 0,
1626
- // don't pass id, because LLM should use `jsonSelectedBlocks` for this
1627
- children: void 0
1628
- }))).map(({ block: s }) => ({ block: s }))
1629
- // strip ids so LLM can't accidentally issue updates to ids not in selection
1630
- };
1631
- }
1632
- function co(e) {
1633
- const t = {}, o = {};
1634
- return e.forEach((n) => {
1635
- const { type: s, ...a } = n.properties, i = JSON.stringify(a);
1636
- t[i] ? t[i].push(s.enum[0]) : (t[i] = [s.enum[0]], o[i] = n);
1637
- }), Object.keys(
1638
- t
1639
- ).map((n) => {
1640
- const s = o[n];
1641
- return {
1642
- ...s,
1643
- properties: {
1644
- ...s.properties,
1645
- type: {
1646
- type: "string",
1647
- enum: t[n]
1648
- }
1649
- }
1650
- };
1651
- });
1652
- }
1653
- function uo(e) {
1654
- return {
1655
- type: "object",
1656
- properties: Object.fromEntries(
1657
- Object.entries(e).map(([t, o]) => [
1658
- t,
1659
- {
1660
- type: o.propSchema
1661
- }
1662
- ])
1663
- ),
1664
- additionalProperties: !1
1665
- };
1666
- }
1667
- function po() {
1668
- return {
1669
- type: "object",
1670
- properties: {
1671
- type: {
1672
- type: "string",
1673
- enum: ["text"]
1674
- },
1675
- text: {
1676
- type: "string"
1677
- },
1678
- styles: {
1679
- $ref: "#/$defs/styles"
1680
- }
1681
- },
1682
- additionalProperties: !1,
1683
- required: ["type", "text"]
1684
- };
1685
- }
1686
- function Ze(e) {
1687
- return {
1688
- type: "object",
1689
- properties: Object.fromEntries(
1690
- Object.entries(e).filter(([t, o]) => o.default !== void 0).map(([t, o]) => [
1691
- t,
1692
- {
1693
- type: typeof o.default,
1694
- enum: o.values
1695
- }
1696
- ])
1697
- ),
1698
- additionalProperties: !1
1699
- };
1700
- }
1701
- function mo(e) {
1702
- return {
1703
- type: "array",
1704
- items: {
1705
- anyOf: Object.entries(e).map(([t, o]) => o === "text" ? {
1706
- $ref: "#/$defs/styledtext"
1707
- } : o === "link" ? {
1708
- type: "object",
1709
- properties: {
1710
- type: {
1711
- type: "string",
1712
- enum: ["link"]
1713
- },
1714
- content: {
1715
- type: "array",
1716
- items: {
1717
- $ref: "#/$defs/styledtext"
1718
- }
1719
- },
1720
- href: {
1721
- type: "string"
1722
- }
1723
- },
1724
- additionalProperties: !1,
1725
- required: ["type", "href", "content"]
1726
- } : {
1727
- type: "object",
1728
- properties: {
1729
- type: {
1730
- type: "string",
1731
- enum: [o.type]
1732
- },
1733
- content: o.content === "styled" ? {
1734
- type: "array",
1735
- items: {
1736
- $ref: "#/$defs/styledtext"
1737
- }
1738
- } : void 0,
1739
- props: Ze(o.propSchema)
1740
- },
1741
- additionalProperties: !1,
1742
- required: ["type", ...o.content === "styled" ? ["content"] : []]
1743
- })
1744
- }
1745
- };
1746
- }
1747
- function fo(e) {
1748
- return {
1749
- anyOf: co(
1750
- Object.entries(e).map(([t, o]) => ({
1751
- type: "object",
1752
- properties: {
1753
- type: {
1754
- type: "string",
1755
- enum: [o.type]
1756
- },
1757
- content: o.content === "inline" ? { $ref: "#/$defs/inlinecontent" } : o.content === "table" ? { type: "object", properties: {} } : void 0,
1758
- // filter out default props (TODO: make option)
1759
- props: Ze(o.propSchema)
1760
- // Object.fromEntries(
1761
- // Object.entries(val.propSchema).filter(
1762
- // (key) => typeof (defaultProps as any)[key[0]] === "undefined"
1763
- // )
1764
- // )
1765
- // ),
1766
- },
1767
- additionalProperties: !1,
1768
- required: ["type"]
1769
- //, ...(val.content === "inline" ? ["content"] : [])],
1770
- }))
1771
- )
1772
- };
1773
- }
1774
- function ho(e) {
1775
- const t = JSON.parse(
1776
- JSON.stringify({
1777
- blockSchema: e.blockSchema,
1778
- inlineContentSchema: e.inlineContentSchema,
1779
- styleSchema: e.styleSchema
1780
- })
1781
- );
1782
- return {
1783
- // TODO
1784
- removeFileBlocks() {
1785
- return t.blockSchema = Object.fromEntries(
1786
- Object.entries(t.blockSchema).filter(
1787
- ([o, r]) => {
1788
- var n;
1789
- return !((n = e.blockSpecs[r.type].implementation.meta) != null && n.fileBlockAccept);
1790
- }
1791
- )
1792
- ), this;
1793
- },
1794
- removeDefaultProps() {
1795
- return t.blockSchema = Object.fromEntries(
1796
- Object.entries(t.blockSchema).map(([o, r]) => [
1797
- o,
1798
- {
1799
- ...r,
1800
- propSchema: Object.fromEntries(
1801
- Object.entries(r.propSchema).filter(
1802
- (n) => typeof _e[n[0]] > "u"
1803
- )
1804
- )
1805
- }
1806
- ])
1807
- ), this;
1808
- },
1809
- get() {
1810
- return t;
1811
- }
1812
- };
1813
- }
1814
- function Se(e) {
1815
- return e = ho(e).removeFileBlocks().removeDefaultProps().get(), {
1816
- $defs: {
1817
- styles: uo(e.styleSchema),
1818
- styledtext: po(),
1819
- inlinecontent: mo(
1820
- e.inlineContentSchema
1821
- ),
1822
- block: fo(e.blockSchema)
1823
- }
1824
- };
1825
- }
1826
- function We(e, t) {
1827
- return !t.schema.inlineContentSchema[e.type] || ct(e) && !("text" in e) ? !1 : ut(e) ? !("content" in e) || !("href" in e) ? !1 : We(e.content, t) : !0;
1828
- }
1829
- function we(e, t, o) {
1830
- const r = e.type || o, n = t.schema.blockSchema[r];
1831
- if (!n)
1832
- return {
1833
- ok: !1,
1834
- error: "block type not found in editor"
1835
- };
1836
- if (e.children, n.content === "none") {
1837
- if (e.content)
1838
- return {
1839
- ok: !1,
1840
- error: "block content not expected for this block type"
1841
- };
1842
- } else {
1843
- if (!e.content)
1844
- return {
1845
- ok: !0,
1846
- value: e
1847
- };
1848
- if (!Array.isArray(e.content))
1849
- return {
1850
- ok: !1,
1851
- error: "block content must be an array"
1852
- };
1853
- if (n.content === "table")
1854
- return {
1855
- ok: !0,
1856
- value: e
1857
- };
1858
- if (!e.content.every((s) => We(s, t)))
1859
- return {
1860
- ok: !1,
1861
- error: "block content must be an array of inline content"
1862
- };
1863
- }
1864
- return {
1865
- ok: !0,
1866
- value: e
1867
- };
1868
- }
1869
- const q = {
1870
- add: re({
1871
- description: "Insert new blocks",
1872
- schema: (e) => ({
1873
- block: {
1874
- $ref: "#/$defs/block"
1875
- },
1876
- ...Se(e.schema)
1877
- }),
1878
- validateBlock: we,
1879
- rebaseTool: async (e, t) => V(t, U(t)),
1880
- toJSONToolCall: async (e, t) => t.operation
1881
- }),
1882
- update: ne({
1883
- description: "Update a block, the new block will replace the existing block.",
1884
- schema: (e) => ({
1885
- block: {
1886
- $ref: "#/$defs/block"
1887
- },
1888
- ...Se(e.schema)
1889
- }),
1890
- validateBlock: we,
1891
- rebaseTool: async (e, t) => V(t, U(t)),
1892
- toJSONToolCall: async (e, t) => {
1893
- const o = Object.fromEntries(
1894
- Object.entries(_e).map(([r, n]) => [r, n.default])
1895
- );
1896
- return {
1897
- ...t.operation,
1898
- block: {
1899
- ...t.operation.block,
1900
- props: {
1901
- ...o,
1902
- ...t.operation.block.props
1903
- }
1904
- }
1905
- };
1906
- }
1907
- }),
1908
- delete: se
1909
- };
1910
- function yo(e, t) {
1911
- e.length > 0 && e.push(
1912
- {
1913
- role: "assistant",
1914
- id: "document-state-" + e.length,
1915
- parts: [
1916
- {
1917
- type: "text",
1918
- text: "This is the latest state of the selection (ignore previous selections, you MUST issue operations against this latest version of the selection):"
1919
- },
1920
- {
1921
- type: "text",
1922
- text: JSON.stringify(t.jsonSelectedBlocks)
1923
- },
1924
- {
1925
- type: "text",
1926
- text: "This is the latest state of the document (INCLUDING the selected text), find the selected text in there to understand the context:"
1927
- },
1928
- {
1929
- type: "text",
1930
- text: JSON.stringify(t.jsonDocument)
1931
- }
1932
- ]
1933
- },
1934
- {
1935
- role: "user",
1936
- id: "user-prompt-" + e.length,
1937
- parts: [
1938
- {
1939
- type: "text",
1940
- text: "The user asks you to do the following:"
1941
- },
1942
- {
1943
- type: "text",
1944
- text: t.userPrompt
1945
- }
1946
- ]
1947
- }
1948
- ), e.push(
1949
- {
1950
- role: "system",
1951
- id: "document-state-intro",
1952
- parts: [
1953
- {
1954
- type: "text",
1955
- text: `You're manipulating a selected part of a text document using JSON blocks.
1956
- Make sure to follow the json schema provided and always include the trailing $ in ids.
1957
- This is the selection as an array of JSON blocks:`
1958
- },
1959
- {
1960
- type: "text",
1961
- text: JSON.stringify(t.jsonSelectedBlocks)
1962
- },
1963
- {
1964
- type: "text",
1965
- text: "This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"
1966
- },
1967
- {
1968
- type: "text",
1969
- text: JSON.stringify(t.jsonDocument)
1970
- }
1971
- ]
1972
- },
1973
- {
1974
- role: "user",
1975
- id: "user-prompt",
1976
- parts: [
1977
- {
1978
- type: "text",
1979
- text: t.userPrompt
1980
- }
1981
- ]
1982
- }
1983
- );
1984
- }
1985
- function go(e, t) {
1986
- if (e.length > 0) {
1987
- e.push(
1988
- {
1989
- role: "assistant",
1990
- id: "document-state-" + e.length,
1991
- parts: [
1992
- {
1993
- type: "text",
1994
- text: "This is the latest state of the document (ignore previous documents, you MUST issue operations against this latest version of the document):"
1995
- },
1996
- {
1997
- type: "text",
1998
- text: JSON.stringify(t.jsonBlocks)
1999
- }
2000
- ]
2001
- },
2002
- {
2003
- role: "user",
2004
- id: "user-prompt-" + e.length,
2005
- parts: [
2006
- {
2007
- type: "text",
2008
- text: t.userPrompt
2009
- }
2010
- ]
2011
- }
2012
- );
2013
- return;
2014
- }
2015
- e.push(
2016
- {
2017
- role: "system",
2018
- id: "document-state",
2019
- parts: [
2020
- {
2021
- type: "text",
2022
- text: `You're manipulating a text document using JSON blocks.
2023
- Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $).
2024
- This is the initial document as an array of JSON blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):`
2025
- },
2026
- {
2027
- type: "text",
2028
- text: JSON.stringify(t.jsonBlocks)
2029
- },
2030
- {
2031
- type: "text",
2032
- text: '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), \n then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`).\n \n ' + (t.isEmptyDocument ? "Because the document is empty, first update the empty block before adding new blocks." : "Prefer updating existing blocks over removing and adding (but this also depends on the user's question).")
2033
- }
2034
- ]
2035
- },
2036
- {
2037
- role: "user",
2038
- id: "user-prompt",
2039
- parts: [
2040
- {
2041
- type: "text",
2042
- text: t.userPrompt
2043
- }
2044
- ]
2045
- }
2046
- );
2047
- }
2048
- const bo = async (e, t) => {
2049
- t.selection ? yo(e, t) : go(e, t);
2050
- };
2051
- function ko(e, t, o, r, n) {
2052
- if (typeof r == "boolean") {
2053
- const i = r ? e.getSelectionCutBlocks() : void 0;
2054
- r = i ? {
2055
- from: i._meta.startPos,
2056
- to: i._meta.endPos
2057
- } : void 0;
2058
- }
2059
- const s = o ?? {
2060
- add: !0,
2061
- update: !0,
2062
- delete: !0
2063
- };
2064
- return [
2065
- ...s.update ? [
2066
- q.update(e, {
2067
- idsSuffixed: !0,
2068
- withDelays: t,
2069
- updateSelection: r,
2070
- onBlockUpdate: n
2071
- })
2072
- ] : [],
2073
- ...s.add ? [q.add(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : [],
2074
- ...s.delete ? [q.delete(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : []
2075
- ];
2076
- }
2077
- const So = {
2078
- /**
2079
- * Function to get the stream tools that can apply JSON block updates to the editor
2080
- */
2081
- getStreamToolsProvider: (e = {}) => ({
2082
- getStreamTools: (t, o, r) => ko(
2083
- t,
2084
- e.withDelays ?? !0,
2085
- e.defaultStreamTools,
2086
- o,
2087
- r
2088
- )
2089
- }),
2090
- tools: q,
2091
- /**
2092
- * The default PromptBuilder that determines how a userPrompt is converted to an array of
2093
- * LLM Messages (CoreMessage[])
2094
- */
2095
- defaultPromptBuilder: bo,
2096
- /**
2097
- * The default PromptInputDataBuilder that can take an editor and user request and convert it to the input required for the PromptBuilder
2098
- */
2099
- defaultPromptInputDataBuilder: lo,
2100
- /**
2101
- * Helper functions which can be used when implementing a custom PromptBuilder
2102
- */
2103
- promptHelpers: {
2104
- getDataForPromptNoSelection: Fe,
2105
- getDataForPromptWithSelection: Re
2106
- }
2107
- };
2108
- async function wo(e) {
2109
- return e.selectedBlocks ? {
2110
- ...await Ge(e.editor, {
2111
- selectedBlocks: e.selectedBlocks
2112
- }),
2113
- userPrompt: e.userPrompt
2114
- } : {
2115
- ...await Ye(e.editor, {
2116
- excludeBlockIds: e.emptyCursorBlockToDelete ? [e.emptyCursorBlockToDelete] : void 0
2117
- }),
2118
- userPrompt: e.userPrompt
2119
- };
2120
- }
2121
- async function Ye(e, t) {
2122
- const o = w(e.document).length === 0, r = e.getTextCursorPosition().block.id, n = w(e.document, {
2123
- cursorBlockId: r
2124
- }), s = await P(
2125
- T(n),
2126
- async (c) => e.blocksToMarkdownLossy([c])
2127
- ), i = Z(e, s).filter(
2128
- (c) => "cursor" in c || !(t.excludeBlockIds || []).includes(c.id)
2129
- );
2130
- return {
2131
- selection: !1,
2132
- markdownBlocks: _(i),
2133
- isEmptyDocument: o
2134
- };
2135
- }
2136
- async function Ge(e, t) {
2137
- const o = w(e.document).length === 0, r = await P(
2138
- T(t.selectedBlocks),
2139
- async (s) => e.blocksToMarkdownLossy([s])
2140
- ), n = _(r);
2141
- return {
2142
- isEmptyDocument: o,
2143
- selection: !0,
2144
- markdownSelectedBlocks: n,
2145
- markdownDocument: (await P(T(e.document), async (s) => e.blocksToMarkdownLossy([s]))).map(({ block: s }) => ({ block: s }))
2146
- // strip ids so LLM can't accidentally issue updates to ids not in selection
2147
- };
2148
- }
2149
- async function Te(e, t) {
2150
- const o = U(t), r = await t.blocksToMarkdownLossy([Ee(o.doc, e)]), n = await t.tryParseMarkdownToBlocks(r), s = W(
2151
- {
2152
- id: e,
2153
- block: n[0]
2154
- },
2155
- o.doc
2156
- ), a = new je();
2157
- for (const i of s) {
2158
- const l = i.map(a);
2159
- if (!l)
2160
- throw new Error("Failed to map step");
2161
- o.step(l), a.appendMap(l.getMap());
2162
- }
2163
- return V(t, o);
2164
- }
2165
- function xe(e) {
2166
- return typeof e != "string" ? {
2167
- ok: !1,
2168
- error: "block must be a string"
2169
- } : {
2170
- ok: !0,
2171
- value: e
2172
- };
2173
- }
2174
- const z = {
2175
- add: re({
2176
- description: "Insert new blocks",
2177
- schema: {
2178
- block: {
2179
- $ref: "#/$defs/block"
2180
- },
2181
- $defs: {
2182
- block: { type: "string", description: "markdown of block" }
2183
- }
2184
- },
2185
- validateBlock: xe,
2186
- rebaseTool: Te,
2187
- toJSONToolCall: async (e, t) => {
2188
- const o = await Promise.all(
2189
- t.operation.blocks.map(async (r) => {
2190
- const n = (await e.tryParseMarkdownToBlocks(r.trim()))[0];
2191
- return delete n.id, n;
2192
- })
2193
- );
2194
- return window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), {
2195
- ...t.operation,
2196
- blocks: o
2197
- };
2198
- }
2199
- }),
2200
- update: ne({
2201
- description: "Update a block, the new block will replace the existing block.",
2202
- schema: {
2203
- block: {
2204
- $ref: "#/$defs/block"
2205
- },
2206
- $defs: {
2207
- block: { type: "string", description: "markdown of block" }
2208
- }
2209
- },
2210
- validateBlock: xe,
2211
- rebaseTool: Te,
2212
- toJSONToolCall: async (e, t) => {
2213
- const o = (await e.tryParseMarkdownToBlocks(t.operation.block.trim()))[0];
2214
- return delete o.id, window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), {
2215
- ...t.operation,
2216
- block: o
2217
- };
2218
- }
2219
- }),
2220
- delete: se
2221
- };
2222
- function To(e, t) {
2223
- e.length > 0 && e.push(
2224
- {
2225
- role: "assistant",
2226
- id: "document-state-" + e.length,
2227
- parts: [
2228
- {
2229
- type: "text",
2230
- text: "This is the latest state of the selection (ignore previous selections, you MUST issue operations against this latest version of the selection):"
2231
- },
2232
- {
2233
- type: "text",
2234
- text: JSON.stringify(t.markdownSelectedBlocks)
2235
- },
2236
- {
2237
- type: "text",
2238
- text: "This is the latest state of the document (INCLUDING the selected text), find the selected text in there to understand the context:"
2239
- },
2240
- {
2241
- type: "text",
2242
- text: JSON.stringify(t.markdownDocument)
2243
- }
2244
- ]
2245
- },
2246
- {
2247
- role: "user",
2248
- id: "user-prompt-" + e.length,
2249
- parts: [
2250
- {
2251
- type: "text",
2252
- text: "The user asks you to do the following:"
2253
- },
2254
- {
2255
- type: "text",
2256
- text: t.userPrompt
2257
- }
2258
- ]
2259
- }
2260
- ), e.push(
2261
- {
2262
- role: "system",
2263
- id: "document-state-intro",
2264
- parts: [
2265
- {
2266
- type: "text",
2267
- text: `You're manipulating a selected part of a text document using Markdown blocks.
2268
- Make sure to follow the json schema provided and always include the trailing $ in ids.
2269
- This is the selection as an array of Markdown blocks:`
2270
- },
2271
- {
2272
- type: "text",
2273
- text: JSON.stringify(t.markdownSelectedBlocks)
2274
- },
2275
- {
2276
- type: "text",
2277
- text: "This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"
2278
- },
2279
- {
2280
- type: "text",
2281
- text: JSON.stringify(t.markdownDocument)
2282
- }
2283
- ]
2284
- },
2285
- {
2286
- role: "user",
2287
- id: "user-prompt",
2288
- parts: [
2289
- {
2290
- type: "text",
2291
- text: t.userPrompt
2292
- }
2293
- ]
2294
- }
2295
- );
2296
- }
2297
- function xo(e, t) {
2298
- if (e.length > 0) {
2299
- e.push(
2300
- {
2301
- role: "assistant",
2302
- id: "document-state-" + e.length,
2303
- parts: [
2304
- {
2305
- type: "text",
2306
- text: "This is the latest state of the document (ignore previous documents, you MUST issue operations against this latest version of the document):"
2307
- },
2308
- {
2309
- type: "text",
2310
- text: JSON.stringify(t.markdownBlocks)
2311
- }
2312
- ]
2313
- },
2314
- {
2315
- role: "user",
2316
- id: "user-prompt-" + e.length,
2317
- parts: [
2318
- {
2319
- type: "text",
2320
- text: t.userPrompt
2321
- }
2322
- ]
2323
- }
2324
- );
2325
- return;
2326
- }
2327
- e.push(
2328
- {
2329
- role: "system",
2330
- id: "document-state",
2331
- parts: [
2332
- {
2333
- type: "text",
2334
- text: `You're manipulating a text document using Markdown blocks.
2335
- Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $).
2336
- This is the initial document as an array of Markdown blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):`
2337
- },
2338
- {
2339
- type: "text",
2340
- text: JSON.stringify(t.markdownBlocks)
2341
- },
2342
- {
2343
- type: "text",
2344
- text: '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), \n then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`).\n \n ' + (t.isEmptyDocument ? "Because the document is empty, first update the empty block before adding new blocks." : "Prefer updating existing blocks over removing and adding (but this also depends on the user's question).")
2345
- }
2346
- ]
2347
- },
2348
- {
2349
- role: "user",
2350
- id: "user-prompt",
2351
- parts: [
2352
- {
2353
- type: "text",
2354
- text: t.userPrompt
2355
- }
2356
- ]
2357
- }
2358
- );
2359
- }
2360
- const vo = async (e, t) => {
2361
- t.selection ? To(e, t) : xo(e, t);
2362
- };
2363
- function Po(e, t, o, r, n) {
2364
- if (typeof r == "boolean") {
2365
- const i = r ? e.getSelectionCutBlocks() : void 0;
2366
- r = i ? {
2367
- from: i._meta.startPos,
2368
- to: i._meta.endPos
2369
- } : void 0;
2370
- }
2371
- const s = o ?? {
2372
- add: !0,
2373
- update: !0,
2374
- delete: !0
2375
- };
2376
- return [
2377
- ...s.update ? [
2378
- z.update(e, {
2379
- idsSuffixed: !0,
2380
- withDelays: t,
2381
- updateSelection: r,
2382
- onBlockUpdate: n
2383
- })
2384
- ] : [],
2385
- ...s.add ? [z.add(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : [],
2386
- ...s.delete ? [z.delete(e, { idsSuffixed: !0, withDelays: t, onBlockUpdate: n })] : []
2387
- ];
2388
- }
2389
- const Co = {
2390
- /**
2391
- * Function to get the stream tools that can apply Markdown block updates to the editor
2392
- */
2393
- getStreamToolsProvider: (e = {}) => ({
2394
- getStreamTools: (t, o, r) => Po(
2395
- t,
2396
- e.withDelays ?? !0,
2397
- e.defaultStreamTools,
2398
- o,
2399
- r
2400
- )
2401
- }),
2402
- tools: z,
2403
- /**
2404
- * The default PromptBuilder that determines how a userPrompt is converted to an array of
2405
- * LLM Messages (CoreMessage[])
2406
- */
2407
- defaultPromptBuilder: vo,
2408
- /**
2409
- * The default PromptInputDataBuilder that can take an editor and user request and convert it to the input required for the PromptBuilder
2410
- */
2411
- defaultPromptInputDataBuilder: wo,
2412
- /**
2413
- * Helper functions which can be used when implementing a custom PromptBuilder
2414
- */
2415
- promptHelpers: {
2416
- getDataForPromptNoSelection: Ye,
2417
- getDataForPromptWithSelection: Ge
2418
- }
2419
- }, O = {
2420
- _experimental_json: So,
2421
- _experimental_markdown: Co,
2422
- html: ao
2423
- }, xr = {
2424
- addCursorPosition: Z,
2425
- flattenBlocks: T,
2426
- suffixIDs: _,
2427
- trimEmptyBlocks: w,
2428
- convertBlocks: P
2429
- }, ve = new Ae("blocknote-agent-cursor");
2430
- function Oo(e) {
2431
- return new Le({
2432
- key: ve,
1
+ import { Chat as te } from "@ai-sdk/react";
2
+ import { createExtension as oe, createStore as V, getNodeById as ne, UnreachableCaseError as re, mergeCSSClasses as ie } from "@blocknote/core";
3
+ import { ForkYDocExtension as M, ShowSelectionExtension as T, filterSuggestionItems as ae, FormattingToolbarExtension as se } from "@blocknote/core/extensions";
4
+ import { suggestChanges as le, revertSuggestions as H, applySuggestions as ce } from "@blocknote/prosemirror-suggest-changes";
5
+ import { Slice as j, Fragment as R } from "prosemirror-model";
6
+ import { Plugin as K, PluginKey as W } from "prosemirror-state";
7
+ import { fixTablesKey as ue } from "prosemirror-tables";
8
+ import { DecorationSet as q, Decoration as Z } from "prosemirror-view";
9
+ import { defaultSelectionBuilder as me } from "y-prosemirror";
10
+ import { b as de, s as fe, c as w, a as y } from "./client-C4uaJa77.js";
11
+ import { C as dt, P as ft, S as gt, g as pt, d as ht, f as Ct, h as bt, j as vt, m as St, o as yt, n as wt, k as kt, p as It, i as _t, e as xt, l as Lt, t as Mt } from "./client-C4uaJa77.js";
12
+ import { jsxs as ge, jsx as l } from "react/jsx-runtime";
13
+ import { useBlockNoteContext as pe, useComponentsContext as P, useSuggestionMenuKeyboardHandler as he, useBlockNoteEditor as A, useExtension as _, useExtensionState as G, BlockPopover as Ce } from "@blocknote/react";
14
+ import S, { useState as $, useCallback as I, useMemo as k, useEffect as Y } from "react";
15
+ import { offset as be, size as ve } from "@floating-ui/react";
16
+ const D = new W("blocknote-agent-cursor");
17
+ function Se(e) {
18
+ return new K({
19
+ key: D,
2433
20
  view: (t) => ({}),
2434
21
  state: {
2435
22
  init: () => ({
2436
23
  selection: void 0
2437
24
  }),
2438
- apply: (t, o) => {
2439
- const r = t.getMeta("aiAgent");
2440
- return r ? {
2441
- selection: r.selection
25
+ apply: (t, n) => {
26
+ const o = t.getMeta("aiAgent");
27
+ return o ? {
28
+ selection: o.selection
2442
29
  } : {
2443
30
  selection: void 0
2444
31
  };
@@ -2446,513 +33,518 @@ function Oo(e) {
2446
33
  },
2447
34
  props: {
2448
35
  decorations: (t) => {
2449
- const { doc: o } = t, { selection: r } = ve.getState(t), n = [];
2450
- if (!r)
2451
- return ue.create(o, []);
2452
- n.push(
2453
- de.widget(r.head, () => Io(e), {
36
+ const { doc: n } = t, { selection: o } = D.getState(t), a = [];
37
+ if (!o)
38
+ return q.create(n, []);
39
+ a.push(
40
+ Z.widget(o.head, () => ye(e), {
2454
41
  key: "agent-cursor",
2455
42
  side: 10
2456
43
  })
2457
44
  );
2458
- const s = Math.min(r.anchor, r.head), a = Math.max(r.anchor, r.head);
2459
- return n.push(
2460
- de.inline(s, a, gt(e), {
45
+ const c = Math.min(o.anchor, o.head), i = Math.max(o.anchor, o.head);
46
+ return a.push(
47
+ Z.inline(c, i, me(e), {
2461
48
  inclusiveEnd: !0,
2462
49
  inclusiveStart: !1
2463
50
  })
2464
- ), ue.create(o, n);
51
+ ), q.create(n, a);
2465
52
  }
2466
53
  }
2467
54
  });
2468
55
  }
2469
- const Io = (e) => {
56
+ const ye = (e) => {
2470
57
  const t = document.createElement("span");
2471
58
  t.classList.add("bn-collaboration-cursor__base"), t.setAttribute("data-active", "true");
59
+ const n = document.createElement("span");
60
+ n.setAttribute("contentedEditable", "false"), n.classList.add("bn-collaboration-cursor__caret"), n.setAttribute("style", `background-color: ${e.color}`);
2472
61
  const o = document.createElement("span");
2473
- o.setAttribute("contentedEditable", "false"), o.classList.add("bn-collaboration-cursor__caret"), o.setAttribute("style", `background-color: ${e.color}`);
2474
- const r = document.createElement("span");
2475
- 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;
2476
- }, Bo = new Ae("blocknote-ai-plugin");
2477
- class Ke extends dt {
2478
- /**
2479
- * @internal use `createAIExtension` instead
2480
- */
2481
- constructor(o, r) {
2482
- super();
2483
- M(this, "chatSession");
2484
- M(this, "scrollInProgress", !1);
2485
- M(this, "autoScroll", !1);
2486
- // internal store including setters
2487
- M(this, "_store", he()((o) => ({
62
+ return o.classList.add("bn-collaboration-cursor__label"), o.setAttribute("style", `background-color: ${e.color}`), o.insertBefore(document.createTextNode(e.name), null), n.insertBefore(o, null), t.insertBefore(document.createTextNode("⁠"), null), t.insertBefore(n, null), t.insertBefore(document.createTextNode("⁠"), null), t;
63
+ }, we = new W("blocknote-ai-plugin"), b = oe(
64
+ ({
65
+ editor: e,
66
+ options: t
67
+ }) => {
68
+ const n = V(t ?? {}), o = V({
2488
69
  aiMenuState: "closed"
2489
- })));
2490
- /**
2491
- * Returns a zustand store with the global configuration of the AI Extension.
2492
- * These options are used by default across all LLM calls when calling {@link executeLLMRequest}
2493
- */
2494
- M(this, "options");
2495
- this.editor = o, this.options = he()((n) => ({
2496
- ...r
2497
- })), this.addProsemirrorPlugin(
2498
- new Le({
2499
- key: Bo,
2500
- filterTransaction: (n) => {
2501
- var a;
2502
- const s = this.store.getState().aiMenuState;
2503
- return !(s !== "closed" && s.status === "ai-writing" && (a = n.getMeta(yt)) != null && a.fixTables);
2504
- }
2505
- })
2506
- ), this.addProsemirrorPlugin(ft()), this.addProsemirrorPlugin(
2507
- Oo(
2508
- r.agentCursor || { name: "AI", color: "#8bc6ff" }
2509
- )
2510
- ), document.addEventListener(
2511
- "scroll",
2512
- () => {
2513
- this.scrollInProgress && (this.autoScroll = !1), this.scrollInProgress = !0;
2514
- },
2515
- !0
2516
- ), document.addEventListener(
2517
- "scrollend",
2518
- () => {
2519
- this.scrollInProgress = !1;
2520
- },
2521
- !0
2522
- );
2523
- }
2524
- static key() {
2525
- return "ai";
2526
- }
2527
- /**
2528
- * Returns a read-only zustand store with the state of the AI Extension
2529
- */
2530
- get store() {
2531
- return this._store;
2532
- }
2533
- /**
2534
- * Open the AI menu at a specific block
2535
- */
2536
- openAIMenuAtBlock(o) {
2537
- var n;
2538
- this.editor.setForceSelectionVisible(!0), this.editor.isEditable = !1, this._store.setState({
2539
- aiMenuState: {
2540
- blockId: o,
2541
- status: "user-input"
2542
- }
2543
70
  });
2544
- const r = (n = this.editor.domElement) == null ? void 0 : n.querySelector(
2545
- `[data-node-type="blockContainer"][data-id="${o}"]`
2546
- );
2547
- r == null || r.scrollIntoView({ block: "center" });
2548
- }
2549
- /**
2550
- * Close the AI menu
2551
- */
2552
- closeAIMenu() {
2553
- this._store.setState({
2554
- aiMenuState: "closed"
2555
- }), this.chatSession = void 0, this.editor.setForceSelectionVisible(!1), this.editor.isEditable = !0, this.editor.focus();
2556
- }
2557
- /**
2558
- * Accept the changes made by the LLM
2559
- */
2560
- acceptChanges() {
2561
- var r;
2562
- const o = this.editor.prosemirrorState.doc;
2563
- this.editor.exec((n, s) => le(n, (a) => {
2564
- s == null || s(a.setMeta("addToHistory", !1));
2565
- })), this.editor.exec((n, s) => {
2566
- const a = n.tr;
2567
- a.replace(
2568
- 0,
2569
- a.doc.content.size,
2570
- new G(ce.from(o), 0, 0)
2571
- );
2572
- const i = n.apply(a);
2573
- return Ne(i, (l) => {
2574
- s == null || s(
2575
- a.replace(
2576
- 0,
2577
- a.doc.content.size,
2578
- new G(ce.from(l.doc), 0, 0)
2579
- )
71
+ let a, c = !1;
72
+ return {
73
+ key: "ai",
74
+ options: n,
75
+ store: o,
76
+ mount({ signal: i }) {
77
+ let r = !1;
78
+ document.addEventListener(
79
+ "scroll",
80
+ () => {
81
+ r && (c = !1), r = !0;
82
+ },
83
+ {
84
+ capture: !0,
85
+ signal: i
86
+ }
87
+ ), document.addEventListener(
88
+ "scrollend",
89
+ () => {
90
+ r = !1;
91
+ },
92
+ {
93
+ capture: !0,
94
+ signal: i
95
+ }
2580
96
  );
2581
- });
2582
- }), (r = this.editor.forkYDocPlugin) == null || r.merge({ keepChanges: !0 }), this.closeAIMenu();
2583
- }
2584
- /**
2585
- * Reject the changes made by the LLM
2586
- */
2587
- rejectChanges() {
2588
- var o;
2589
- this.editor.exec((r, n) => le(r, (s) => {
2590
- n == null || n(s.setMeta("addToHistory", !1));
2591
- })), (o = this.editor.forkYDocPlugin) == null || o.merge({ keepChanges: !1 }), this.closeAIMenu();
2592
- }
2593
- /**
2594
- * Retry the previous LLM call.
2595
- *
2596
- * Only valid if the current status is "error"
2597
- */
2598
- async retry() {
2599
- var r;
2600
- const { aiMenuState: o } = this.store.getState();
2601
- if (o === "closed" || o.status !== "error" || !this.chatSession)
2602
- throw new Error("retry() is only valid when a previous response failed");
2603
- return ((r = this.chatSession) == null ? void 0 : r.chat.status) === "error" ? this.invokeAI({
2604
- ...this.chatSession.previousRequestOptions,
2605
- userPrompt: "An error occured in the previous request. Please retry to accomplish the last user prompt."
2606
- }) : this.invokeAI({
2607
- ...this.chatSession.previousRequestOptions,
2608
- userPrompt: "An error occured while executing the previous tool call. Please retry to accomplish the last user prompt."
2609
- });
2610
- }
2611
- /**
2612
- * Update the status of a call to an LLM
2613
- *
2614
- * @warning This method should usually only be used for advanced use-cases
2615
- * if you want to implement how an LLM call is executed. Usually, you should
2616
- * use {@link executeLLMRequest} instead which will handle the status updates for you.
2617
- */
2618
- setAIResponseStatus(o) {
2619
- const r = this.store.getState().aiMenuState;
2620
- if (r !== "closed")
2621
- if (o === "ai-writing" && this.editor.setForceSelectionVisible(!1), typeof o == "object") {
2622
- if (o.status !== "error")
2623
- throw new Be(o.status);
2624
- this._store.setState({
2625
- aiMenuState: {
2626
- status: o.status,
2627
- error: o.error,
2628
- blockId: r.blockId
97
+ },
98
+ prosemirrorPlugins: [
99
+ new K({
100
+ key: we,
101
+ filterTransaction: (i) => {
102
+ var s;
103
+ const r = o.state.aiMenuState;
104
+ return !(r !== "closed" && r.status === "ai-writing" && (s = i.getMeta(ue)) != null && s.fixTables);
2629
105
  }
2630
- });
2631
- } else
2632
- this._store.setState({
106
+ }),
107
+ le(),
108
+ Se(
109
+ (t == null ? void 0 : t.agentCursor) || { name: "AI", color: "#8bc6ff" }
110
+ )
111
+ ],
112
+ /**
113
+ * Open the AI menu at a specific block
114
+ */
115
+ openAIMenuAtBlock(i) {
116
+ var s, u;
117
+ (s = e.getExtension(T)) == null || s.showSelection(!0), e.isEditable = !1, o.setState({
2633
118
  aiMenuState: {
2634
- status: o,
2635
- blockId: r.blockId
119
+ blockId: i,
120
+ status: "user-input"
2636
121
  }
2637
122
  });
2638
- }
2639
- /**
2640
- * @deprecated Use {@link invokeAI} instead
2641
- */
2642
- async callLLM(o) {
2643
- return this.invokeAI(o);
2644
- }
2645
- /**
2646
- * Execute a call to an LLM and apply the result to the editor
2647
- */
2648
- async invokeAI(o) {
2649
- var r, n;
2650
- this.setAIResponseStatus("thinking"), (r = this.editor.forkYDocPlugin) == null || r.fork();
2651
- try {
2652
- this.chatSession ? this.chatSession.previousRequestOptions = o : this.chatSession = {
2653
- previousRequestOptions: o,
2654
- chat: new nt({
2655
- sendAutomaticallyWhen: () => !1,
2656
- transport: o.transport || this.options.getState().transport
2657
- })
2658
- };
2659
- const s = this.chatSession.chat;
2660
- o = {
2661
- ...this.options.getState(),
2662
- ...o
2663
- };
2664
- const i = o.aiRequestSender ?? At(
2665
- O.html.defaultPromptBuilder,
2666
- O.html.defaultPromptInputDataBuilder
2667
- ), l = Kt({
2668
- editor: this.editor,
2669
- chat: s,
2670
- userPrompt: o.userPrompt,
2671
- useSelection: o.useSelection,
2672
- deleteEmptyCursorBlock: o.deleteEmptyCursorBlock,
2673
- streamToolsProvider: o.streamToolsProvider,
2674
- onBlockUpdated: (c) => {
2675
- if (this._store.setState({
2676
- aiMenuState: {
2677
- blockId: c,
2678
- status: "ai-writing"
2679
- }
2680
- }), !this.autoScroll)
2681
- return;
2682
- const u = this._store.getState().aiMenuState, m = u === "closed" ? void 0 : u;
2683
- if (!m || m.status !== "ai-writing")
2684
- return;
2685
- const p = Me(
2686
- m.blockId,
2687
- this.editor.prosemirrorState.doc
123
+ const r = (u = e.domElement) == null ? void 0 : u.querySelector(
124
+ `[data-node-type="blockContainer"][data-id="${i}"]`
125
+ );
126
+ r == null || r.scrollIntoView({ block: "center" });
127
+ },
128
+ /**
129
+ * Close the AI menu
130
+ */
131
+ closeAIMenu() {
132
+ var i;
133
+ o.setState({
134
+ aiMenuState: "closed"
135
+ }), a = void 0, (i = e.getExtension(T)) == null || i.showSelection(!1), e.isEditable = !0, e.focus();
136
+ },
137
+ /**
138
+ * Accept the changes made by the LLM
139
+ */
140
+ acceptChanges() {
141
+ var r;
142
+ const i = e.prosemirrorState.doc;
143
+ e.exec((s, u) => H(s, (d) => {
144
+ u == null || u(d.setMeta("addToHistory", !1));
145
+ })), e.exec((s, u) => {
146
+ const d = s.tr;
147
+ d.replace(
148
+ 0,
149
+ d.doc.content.size,
150
+ new j(R.from(i), 0, 0)
2688
151
  );
2689
- if (!p)
2690
- return;
2691
- this.editor.prosemirrorView.domAtPos(
2692
- p.posBeforeNode + 1
2693
- ).node.scrollIntoView({
2694
- block: "center"
152
+ const g = s.apply(d);
153
+ return ce(g, (p) => {
154
+ u == null || u(
155
+ d.replace(
156
+ 0,
157
+ d.doc.content.size,
158
+ new j(R.from(p.doc), 0, 0)
159
+ )
160
+ );
2695
161
  });
162
+ }), (r = e.getExtension(M)) == null || r.merge({ keepChanges: !0 }), this.closeAIMenu();
163
+ },
164
+ /**
165
+ * Reject the changes made by the LLM
166
+ */
167
+ rejectChanges() {
168
+ var i;
169
+ e.exec((r, s) => H(r, (u) => {
170
+ s == null || s(u.setMeta("addToHistory", !1));
171
+ })), (i = e.getExtension(M)) == null || i.merge({ keepChanges: !1 }), this.closeAIMenu();
172
+ },
173
+ /**
174
+ * Abort the current LLM request.
175
+ *
176
+ * This will stop the ongoing request and revert any changes made by the AI.
177
+ * Only valid when there is an active AI request in progress.
178
+ */
179
+ async abort(i) {
180
+ const { aiMenuState: r } = o.state;
181
+ if (r === "closed" || !a || r.status !== "thinking" && r.status !== "ai-writing")
182
+ return;
183
+ const s = a.chat;
184
+ a.abortController.abort(i), await s.stop();
185
+ },
186
+ /**
187
+ * Retry the previous LLM call.
188
+ *
189
+ * Only valid if the current status is "error"
190
+ */
191
+ async retry() {
192
+ const { aiMenuState: i } = o.state;
193
+ if (i === "closed" || i.status !== "error" || !a)
194
+ throw new Error(
195
+ "retry() is only valid when a previous response failed"
196
+ );
197
+ return (a == null ? void 0 : a.chat.status) === "error" ? this.invokeAI({
198
+ ...a.previousRequestOptions,
199
+ userPrompt: "An error occured in the previous request. Please retry to accomplish the last user prompt."
200
+ }) : this.invokeAI({
201
+ ...a.previousRequestOptions,
202
+ userPrompt: "An error occured while executing the previous tool call. Please retry to accomplish the last user prompt."
203
+ });
204
+ },
205
+ /**
206
+ * Update the status of a call to an LLM
207
+ *
208
+ * @warning This method should usually only be used for advanced use-cases
209
+ * if you want to implement how an LLM call is executed. Usually, you should
210
+ * use {@link executeLLMRequest} instead which will handle the status updates for you.
211
+ */
212
+ setAIResponseStatus(i) {
213
+ var s;
214
+ const r = o.state.aiMenuState;
215
+ if (r !== "closed")
216
+ if (i === "ai-writing" && ((s = e.getExtension(T)) == null || s.showSelection(!1)), typeof i == "object") {
217
+ if (i.status !== "error")
218
+ throw new re(i.status);
219
+ this.store.setState({
220
+ aiMenuState: {
221
+ status: i.status,
222
+ error: i.error,
223
+ blockId: r.blockId
224
+ }
225
+ });
226
+ } else
227
+ this.store.setState({
228
+ aiMenuState: {
229
+ status: i,
230
+ blockId: r.blockId
231
+ }
232
+ });
233
+ },
234
+ /**
235
+ * @deprecated Use {@link invokeAI} instead
236
+ */
237
+ async callLLM(i) {
238
+ return this.invokeAI(i);
239
+ },
240
+ /**
241
+ * Execute a call to an LLM and apply the result to the editor
242
+ */
243
+ async invokeAI(i) {
244
+ var r, s, u, d;
245
+ this.setAIResponseStatus("thinking"), (r = e.getExtension(M)) == null || r.fork();
246
+ try {
247
+ const g = new AbortController();
248
+ a ? (a.previousRequestOptions = i, a.abortController = g) : a = {
249
+ previousRequestOptions: i,
250
+ chat: ((s = i.chatProvider) == null ? void 0 : s.call(i)) || ((d = (u = this.options.state).chatProvider) == null ? void 0 : d.call(u)) || new te({
251
+ sendAutomaticallyWhen: () => !1,
252
+ transport: i.transport || this.options.state.transport
253
+ }),
254
+ abortController: g
255
+ };
256
+ const p = a.chat;
257
+ i = {
258
+ ...n.state,
259
+ ...i
260
+ };
261
+ const h = await de({
262
+ editor: e,
263
+ useSelection: i.useSelection,
264
+ deleteEmptyCursorBlock: i.deleteEmptyCursorBlock,
265
+ streamToolsProvider: i.streamToolsProvider ?? this.options.state.streamToolsProvider,
266
+ documentStateBuilder: i.documentStateBuilder ?? this.options.state.documentStateBuilder,
267
+ onBlockUpdated: (v) => {
268
+ const B = o.state.aiMenuState, O = B === "closed" ? void 0 : B;
269
+ if (!O || O.status !== "ai-writing")
270
+ return;
271
+ const z = ne(
272
+ v,
273
+ e.prosemirrorState.doc
274
+ );
275
+ z && (o.setState({
276
+ aiMenuState: {
277
+ blockId: v,
278
+ status: "ai-writing"
279
+ }
280
+ }), c && e.prosemirrorView.domAtPos(
281
+ z.posBeforeNode + 1
282
+ ).node.scrollIntoView({
283
+ block: "center"
284
+ }));
285
+ },
286
+ onStart: () => {
287
+ c = !0, this.setAIResponseStatus("ai-writing"), h.emptyCursorBlockToDelete && h.editor.getBlock(h.emptyCursorBlockToDelete) && h.editor.removeBlocks([
288
+ h.emptyCursorBlockToDelete
289
+ ]);
290
+ }
291
+ }), m = await fe(
292
+ p,
293
+ h,
294
+ {
295
+ role: "user",
296
+ parts: [
297
+ {
298
+ type: "text",
299
+ text: i.userPrompt
300
+ }
301
+ ]
302
+ },
303
+ i.chatRequestOptions || this.options.state.chatRequestOptions,
304
+ a.abortController.signal
305
+ );
306
+ m.ok && p.status !== "error" || g.signal.aborted ? this.setAIResponseStatus("user-reviewing") : (console.warn("Error calling LLM", {
307
+ result: m,
308
+ chatStatus: p.status,
309
+ chatError: p.error
310
+ }), this.setAIResponseStatus({
311
+ status: "error",
312
+ error: m.ok ? p.error : m.error
313
+ }));
314
+ } catch (g) {
315
+ this.setAIResponseStatus({
316
+ status: "error",
317
+ error: g
318
+ }), console.error(
319
+ "Unexpected error calling LLM",
320
+ g,
321
+ a == null ? void 0 : a.chat.messages
322
+ );
2696
323
  }
2697
- });
2698
- await Xt({
2699
- aiRequest: l,
2700
- sender: i,
2701
- chatRequestOptions: o.chatRequestOptions,
2702
- onStart: () => {
2703
- this.autoScroll = !0, this.setAIResponseStatus("ai-writing");
2704
- }
2705
- }), this.setAIResponseStatus("user-reviewing");
2706
- } catch (s) {
2707
- this.setAIResponseStatus({
2708
- status: "error",
2709
- error: s
2710
- }), console.warn("Error calling LLM", s, (n = this.chatSession) == null ? void 0 : n.chat.messages);
2711
- }
324
+ }
325
+ };
2712
326
  }
2713
- }
2714
- function vr(e) {
2715
- return (t) => new Ke(t, e);
2716
- }
2717
- function I(e) {
2718
- return e.extension(Ke);
2719
- }
2720
- const Pr = (e) => async (t, o) => {
2721
- const r = new Request(t, o), n = e(r.url), s = new Request(n, {
2722
- headers: r.headers,
2723
- // if we just pass request.body, it's a readablestream which is not visible in chrome inspector,
2724
- // so use init?.body instead if it's available to make debugging easier
2725
- body: (o == null ? void 0 : o.body) || r.body,
2726
- method: r.method,
2727
- duplex: "half"
2728
- });
2729
- return await fetch(s);
2730
- };
2731
- var Xe = {
327
+ );
328
+ var J = {
2732
329
  color: void 0,
2733
330
  size: void 0,
2734
331
  className: void 0,
2735
332
  style: void 0,
2736
333
  attr: void 0
2737
- }, Pe = E.createContext && /* @__PURE__ */ E.createContext(Xe), Mo = ["attr", "size", "title"];
2738
- function Eo(e, t) {
334
+ }, N = S.createContext && /* @__PURE__ */ S.createContext(J), ke = ["attr", "size", "title"];
335
+ function Ie(e, t) {
2739
336
  if (e == null) return {};
2740
- var o = _o(e, t), r, n;
337
+ var n = _e(e, t), o, a;
2741
338
  if (Object.getOwnPropertySymbols) {
2742
- var s = Object.getOwnPropertySymbols(e);
2743
- for (n = 0; n < s.length; n++)
2744
- r = s[n], !(t.indexOf(r) >= 0) && Object.prototype.propertyIsEnumerable.call(e, r) && (o[r] = e[r]);
339
+ var c = Object.getOwnPropertySymbols(e);
340
+ for (a = 0; a < c.length; a++)
341
+ o = c[a], !(t.indexOf(o) >= 0) && Object.prototype.propertyIsEnumerable.call(e, o) && (n[o] = e[o]);
2745
342
  }
2746
- return o;
343
+ return n;
2747
344
  }
2748
- function _o(e, t) {
345
+ function _e(e, t) {
2749
346
  if (e == null) return {};
2750
- var o = {};
2751
- for (var r in e)
2752
- if (Object.prototype.hasOwnProperty.call(e, r)) {
2753
- if (t.indexOf(r) >= 0) continue;
2754
- o[r] = e[r];
347
+ var n = {};
348
+ for (var o in e)
349
+ if (Object.prototype.hasOwnProperty.call(e, o)) {
350
+ if (t.indexOf(o) >= 0) continue;
351
+ n[o] = e[o];
2755
352
  }
2756
- return o;
353
+ return n;
2757
354
  }
2758
- function F() {
2759
- return F = Object.assign ? Object.assign.bind() : function(e) {
355
+ function x() {
356
+ return x = Object.assign ? Object.assign.bind() : function(e) {
2760
357
  for (var t = 1; t < arguments.length; t++) {
2761
- var o = arguments[t];
2762
- for (var r in o)
2763
- Object.prototype.hasOwnProperty.call(o, r) && (e[r] = o[r]);
358
+ var n = arguments[t];
359
+ for (var o in n)
360
+ Object.prototype.hasOwnProperty.call(n, o) && (e[o] = n[o]);
2764
361
  }
2765
362
  return e;
2766
- }, F.apply(this, arguments);
363
+ }, x.apply(this, arguments);
2767
364
  }
2768
- function Ce(e, t) {
2769
- var o = Object.keys(e);
365
+ function F(e, t) {
366
+ var n = Object.keys(e);
2770
367
  if (Object.getOwnPropertySymbols) {
2771
- var r = Object.getOwnPropertySymbols(e);
2772
- t && (r = r.filter(function(n) {
2773
- return Object.getOwnPropertyDescriptor(e, n).enumerable;
2774
- })), o.push.apply(o, r);
368
+ var o = Object.getOwnPropertySymbols(e);
369
+ t && (o = o.filter(function(a) {
370
+ return Object.getOwnPropertyDescriptor(e, a).enumerable;
371
+ })), n.push.apply(n, o);
2775
372
  }
2776
- return o;
373
+ return n;
2777
374
  }
2778
- function R(e) {
375
+ function L(e) {
2779
376
  for (var t = 1; t < arguments.length; t++) {
2780
- var o = arguments[t] != null ? arguments[t] : {};
2781
- t % 2 ? Ce(Object(o), !0).forEach(function(r) {
2782
- No(e, r, o[r]);
2783
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(o)) : Ce(Object(o)).forEach(function(r) {
2784
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(o, r));
377
+ var n = arguments[t] != null ? arguments[t] : {};
378
+ t % 2 ? F(Object(n), !0).forEach(function(o) {
379
+ xe(e, o, n[o]);
380
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : F(Object(n)).forEach(function(o) {
381
+ Object.defineProperty(e, o, Object.getOwnPropertyDescriptor(n, o));
2785
382
  });
2786
383
  }
2787
384
  return e;
2788
385
  }
2789
- function No(e, t, o) {
2790
- return t = Lo(t), t in e ? Object.defineProperty(e, t, { value: o, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = o, e;
386
+ function xe(e, t, n) {
387
+ return t = Le(t), t in e ? Object.defineProperty(e, t, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = n, e;
2791
388
  }
2792
- function Lo(e) {
2793
- var t = Ao(e, "string");
389
+ function Le(e) {
390
+ var t = Me(e, "string");
2794
391
  return typeof t == "symbol" ? t : t + "";
2795
392
  }
2796
- function Ao(e, t) {
393
+ function Me(e, t) {
2797
394
  if (typeof e != "object" || !e) return e;
2798
- var o = e[Symbol.toPrimitive];
2799
- if (o !== void 0) {
2800
- var r = o.call(e, t);
2801
- if (typeof r != "object") return r;
395
+ var n = e[Symbol.toPrimitive];
396
+ if (n !== void 0) {
397
+ var o = n.call(e, t);
398
+ if (typeof o != "object") return o;
2802
399
  throw new TypeError("@@toPrimitive must return a primitive value.");
2803
400
  }
2804
401
  return (t === "string" ? String : Number)(e);
2805
402
  }
2806
- function Qe(e) {
2807
- return e && e.map((t, o) => /* @__PURE__ */ E.createElement(t.tag, R({
2808
- key: o
2809
- }, t.attr), Qe(t.child)));
403
+ function Q(e) {
404
+ return e && e.map((t, n) => /* @__PURE__ */ S.createElement(t.tag, L({
405
+ key: n
406
+ }, t.attr), Q(t.child)));
2810
407
  }
2811
- function x(e) {
2812
- return (t) => /* @__PURE__ */ E.createElement(Do, F({
2813
- attr: R({}, e.attr)
2814
- }, t), Qe(e.child));
408
+ function C(e) {
409
+ return (t) => /* @__PURE__ */ S.createElement(Te, x({
410
+ attr: L({}, e.attr)
411
+ }, t), Q(e.child));
2815
412
  }
2816
- function Do(e) {
2817
- var t = (o) => {
413
+ function Te(e) {
414
+ var t = (n) => {
2818
415
  var {
2819
- attr: r,
2820
- size: n,
2821
- title: s
2822
- } = e, a = Eo(e, Mo), i = n || o.size || "1em", l;
2823
- return o.className && (l = o.className), e.className && (l = (l ? l + " " : "") + e.className), /* @__PURE__ */ E.createElement("svg", F({
416
+ attr: o,
417
+ size: a,
418
+ title: c
419
+ } = e, i = Ie(e, ke), r = a || n.size || "1em", s;
420
+ return n.className && (s = n.className), e.className && (s = (s ? s + " " : "") + e.className), /* @__PURE__ */ S.createElement("svg", x({
2824
421
  stroke: "currentColor",
2825
422
  fill: "currentColor",
2826
423
  strokeWidth: "0"
2827
- }, o.attr, r, a, {
2828
- className: l,
2829
- style: R(R({
2830
- color: e.color || o.color
2831
- }, o.style), e.style),
2832
- height: i,
2833
- width: i,
424
+ }, n.attr, o, i, {
425
+ className: s,
426
+ style: L(L({
427
+ color: e.color || n.color
428
+ }, n.style), e.style),
429
+ height: r,
430
+ width: r,
2834
431
  xmlns: "http://www.w3.org/2000/svg"
2835
- }), s && /* @__PURE__ */ E.createElement("title", null, s), e.children);
432
+ }), c && /* @__PURE__ */ S.createElement("title", null, c), e.children);
2836
433
  };
2837
- return Pe !== void 0 ? /* @__PURE__ */ E.createElement(Pe.Consumer, null, (o) => t(o)) : t(Xe);
2838
- }
2839
- function et(e) {
2840
- return x({ 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);
434
+ return N !== void 0 ? /* @__PURE__ */ S.createElement(N.Consumer, null, (n) => t(n)) : t(J);
2841
435
  }
2842
- function Oe(e) {
2843
- return x({ 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);
436
+ function X(e) {
437
+ return C({ 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);
2844
438
  }
2845
- function jo(e) {
2846
- return x({ 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);
439
+ function U(e) {
440
+ return C({ 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);
2847
441
  }
2848
- function $o(e) {
2849
- return x({ 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);
442
+ function Pe(e) {
443
+ return C({ 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);
2850
444
  }
2851
- function Ho(e) {
2852
- return x({ 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);
445
+ function Ae(e) {
446
+ return C({ 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);
2853
447
  }
2854
- function qo(e) {
2855
- return x({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M13 6V21H11V6H5V4H19V6H13Z" }, child: [] }] })(e);
448
+ function Ee(e) {
449
+ return C({ 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);
2856
450
  }
2857
- function zo(e) {
2858
- return x({ 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);
451
+ function Be(e) {
452
+ return C({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M13 6V21H11V6H5V4H19V6H13Z" }, child: [] }] })(e);
2859
453
  }
2860
- function Jo(e) {
2861
- return x({ 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);
454
+ function Oe(e) {
455
+ return C({ 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);
2862
456
  }
2863
- function Uo(e) {
2864
- return x({ 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);
457
+ function ze(e) {
458
+ return C({ 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);
2865
459
  }
2866
- function Vo(e) {
2867
- return x({ 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);
460
+ function Ve(e) {
461
+ return C({ 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);
2868
462
  }
2869
- function ie(e) {
2870
- return x({ 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);
463
+ function He(e) {
464
+ return C({ 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);
2871
465
  }
2872
- function L(e) {
2873
- if (!e.dictionary.ai)
2874
- throw new Error("AI dictionary not found");
2875
- return e.dictionary.ai;
466
+ function E(e) {
467
+ return C({ 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);
2876
468
  }
2877
- function tt() {
2878
- const e = Ot();
2879
- return L(e.editor);
469
+ function ee() {
470
+ const e = pe();
471
+ return w(e.editor);
2880
472
  }
2881
- const Fo = (e) => {
2882
- const t = X(), { onManualPromptSubmit: o, promptText: r, onPromptTextChange: n } = e, [s, a] = $e(""), i = r || s, l = $(
2883
- async (f) => {
2884
- f.key === "Enter" && o(i);
473
+ const je = (e) => {
474
+ const t = P(), { onManualPromptSubmit: n, promptText: o, onPromptTextChange: a } = e, [c, i] = $(""), r = o || c, s = I(
475
+ async (m) => {
476
+ m.key === "Enter" && n(r);
2885
477
  },
2886
- [i, o]
2887
- ), c = $(
2888
- (f) => {
2889
- const k = f.currentTarget.value;
2890
- n && n(k), r === void 0 && a(k);
478
+ [r, n]
479
+ ), u = I(
480
+ (m) => {
481
+ const v = m.currentTarget.value;
482
+ a && a(v), o === void 0 && i(v);
2891
483
  },
2892
- [n, a, r]
2893
- ), u = A(() => pt(e.items, i), [i, e.items]), { selectedIndex: m, setSelectedIndex: p, handler: d } = It(u, (f) => f.onItemClick()), h = $(
2894
- (f) => {
2895
- f.key === "Enter" ? u.length > 0 ? d(f) : l(f) : d(f);
484
+ [a, i, o]
485
+ ), d = k(() => ae(e.items, r), [r, e.items]), { selectedIndex: g, setSelectedIndex: p, handler: f } = he(d, (m) => m.onItemClick()), h = I(
486
+ (m) => {
487
+ m.key === "Enter" ? d.length > 0 ? f(m) : s(m) : f(m);
2896
488
  },
2897
- [l, d, u.length]
489
+ [s, f, d.length]
2898
490
  );
2899
- return He(() => {
491
+ return Y(() => {
2900
492
  p(0);
2901
- }, [i, p]), /* @__PURE__ */ Ct("div", { className: "bn-combobox", children: [
2902
- /* @__PURE__ */ y(t.Generic.Form.Root, { children: /* @__PURE__ */ y(
493
+ }, [r, p]), /* @__PURE__ */ ge("div", { className: "bn-combobox", children: [
494
+ /* @__PURE__ */ l(t.Generic.Form.Root, { children: /* @__PURE__ */ l(
2903
495
  t.Generic.Form.TextInput,
2904
496
  {
2905
497
  className: "bn-combobox-input",
2906
498
  name: "ai-prompt",
2907
499
  variant: "large",
2908
500
  icon: e.icon,
2909
- value: i || "",
501
+ value: r || "",
2910
502
  autoFocus: !0,
2911
503
  placeholder: e.placeholder,
2912
504
  disabled: e.disabled,
2913
505
  onKeyDown: h,
2914
- onChange: c,
506
+ onChange: u,
2915
507
  autoComplete: "off",
2916
508
  rightSection: e.rightSection
2917
509
  },
2918
510
  "input-" + e.disabled
2919
511
  ) }),
2920
- /* @__PURE__ */ y(
512
+ /* @__PURE__ */ l(
2921
513
  t.SuggestionMenu.Root,
2922
514
  {
2923
515
  className: "bn-combobox-items",
2924
516
  id: "ai-suggestion-menu",
2925
- children: u.map((f, k) => /* @__PURE__ */ y(
517
+ children: d.map((m, v) => /* @__PURE__ */ l(
2926
518
  t.SuggestionMenu.Item,
2927
519
  {
2928
- className: mt(
520
+ className: ie(
2929
521
  "bn-suggestion-menu-item",
2930
- f.size === "small" ? "bn-suggestion-menu-item-small" : ""
522
+ m.size === "small" ? "bn-suggestion-menu-item-small" : ""
2931
523
  ),
2932
- id: `bn-suggestion-menu-item-${k}`,
2933
- isSelected: k === m,
2934
- onClick: f.onItemClick,
2935
- item: f
524
+ id: `bn-suggestion-menu-item-${v}`,
525
+ isSelected: v === g,
526
+ onClick: m.onItemClick,
527
+ item: m
2936
528
  },
2937
- f.title
529
+ m.title
2938
530
  ))
2939
531
  }
2940
532
  )
2941
533
  ] });
2942
534
  };
2943
- function Ro(e) {
2944
- const t = L(e), o = I(e);
2945
- return [
535
+ function Re(e) {
536
+ const t = w(e), n = e.getExtension(b);
537
+ return n ? [
2946
538
  {
2947
539
  key: "continue_writing",
2948
540
  title: t.ai_default_commands.continue_writing.title,
2949
541
  aliases: t.ai_default_commands.continue_writing.aliases,
2950
- icon: /* @__PURE__ */ y(Oe, { size: 18 }),
542
+ icon: /* @__PURE__ */ l(U, { size: 18 }),
2951
543
  onItemClick: async () => {
2952
- await o.invokeAI({
544
+ await n.invokeAI({
2953
545
  userPrompt: "Continue writing at the current cursor position related to the previous text. Add multiple blocks if needed. If the document looks like a template / draft, follow the template. Be extensive if needed.",
2954
546
  // By default, LLM will be able to add / update / delete blocks. For "continue writing", we only want to allow adding new blocks.
2955
- streamToolsProvider: O.html.getStreamToolsProvider({
547
+ streamToolsProvider: y.html.getStreamToolsProvider({
2956
548
  defaultStreamTools: {
2957
549
  add: !0,
2958
550
  delete: !1,
@@ -2967,12 +559,12 @@ function Ro(e) {
2967
559
  key: "summarize",
2968
560
  title: t.ai_default_commands.summarize.title,
2969
561
  aliases: t.ai_default_commands.summarize.aliases,
2970
- icon: /* @__PURE__ */ y(Ho, { size: 18 }),
562
+ icon: /* @__PURE__ */ l(Ee, { size: 18 }),
2971
563
  onItemClick: async () => {
2972
- await o.invokeAI({
564
+ await n.invokeAI({
2973
565
  userPrompt: "Summarize",
2974
566
  // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
2975
- streamToolsProvider: O.html.getStreamToolsProvider({
567
+ streamToolsProvider: y.html.getStreamToolsProvider({
2976
568
  defaultStreamTools: {
2977
569
  add: !0,
2978
570
  delete: !1,
@@ -2987,12 +579,12 @@ function Ro(e) {
2987
579
  key: "action_items",
2988
580
  title: t.ai_default_commands.add_action_items.title,
2989
581
  aliases: t.ai_default_commands.add_action_items.aliases,
2990
- icon: /* @__PURE__ */ y($o, { size: 18 }),
582
+ icon: /* @__PURE__ */ l(Ae, { size: 18 }),
2991
583
  onItemClick: async () => {
2992
- await o.invokeAI({
584
+ await n.invokeAI({
2993
585
  userPrompt: "Add action items",
2994
586
  // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
2995
- streamToolsProvider: O.html.getStreamToolsProvider({
587
+ streamToolsProvider: y.html.getStreamToolsProvider({
2996
588
  defaultStreamTools: {
2997
589
  add: !0,
2998
590
  delete: !1,
@@ -3007,28 +599,28 @@ function Ro(e) {
3007
599
  key: "write_anything",
3008
600
  title: t.ai_default_commands.write_anything.title,
3009
601
  aliases: t.ai_default_commands.write_anything.aliases,
3010
- icon: /* @__PURE__ */ y(Oe, { size: 18 }),
3011
- onItemClick: (r) => {
3012
- r(t.ai_default_commands.write_anything.prompt_placeholder);
602
+ icon: /* @__PURE__ */ l(U, { size: 18 }),
603
+ onItemClick: (o) => {
604
+ o(t.ai_default_commands.write_anything.prompt_placeholder);
3013
605
  },
3014
606
  size: "small"
3015
607
  }
3016
- ];
608
+ ] : [];
3017
609
  }
3018
- function Zo(e) {
3019
- const t = L(e), o = I(e);
3020
- return [
610
+ function qe(e) {
611
+ const t = w(e), n = e.getExtension(b);
612
+ return n ? [
3021
613
  {
3022
614
  key: "improve_writing",
3023
615
  title: t.ai_default_commands.improve_writing.title,
3024
616
  aliases: t.ai_default_commands.improve_writing.aliases,
3025
- icon: /* @__PURE__ */ y(qo, { size: 18 }),
617
+ icon: /* @__PURE__ */ l(Be, { size: 18 }),
3026
618
  onItemClick: async () => {
3027
- await o.invokeAI({
619
+ await n.invokeAI({
3028
620
  useSelection: !0,
3029
621
  userPrompt: "Improve writing",
3030
622
  // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
3031
- streamToolsProvider: O.html.getStreamToolsProvider({
623
+ streamToolsProvider: y.html.getStreamToolsProvider({
3032
624
  defaultStreamTools: {
3033
625
  add: !1,
3034
626
  delete: !1,
@@ -3043,13 +635,13 @@ function Zo(e) {
3043
635
  key: "fix_spelling",
3044
636
  title: t.ai_default_commands.fix_spelling.title,
3045
637
  aliases: t.ai_default_commands.fix_spelling.aliases,
3046
- icon: /* @__PURE__ */ y(Uo, { size: 18 }),
638
+ icon: /* @__PURE__ */ l(Ve, { size: 18 }),
3047
639
  onItemClick: async () => {
3048
- await o.invokeAI({
640
+ await n.invokeAI({
3049
641
  useSelection: !0,
3050
642
  userPrompt: "Fix spelling",
3051
643
  // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
3052
- streamToolsProvider: O.html.getStreamToolsProvider({
644
+ streamToolsProvider: y.html.getStreamToolsProvider({
3053
645
  defaultStreamTools: {
3054
646
  add: !1,
3055
647
  delete: !1,
@@ -3064,9 +656,9 @@ function Zo(e) {
3064
656
  key: "translate",
3065
657
  title: t.ai_default_commands.translate.title,
3066
658
  aliases: t.ai_default_commands.translate.aliases,
3067
- icon: /* @__PURE__ */ y(zo, { size: 18 }),
3068
- onItemClick: (r) => {
3069
- r(t.ai_default_commands.translate.prompt_placeholder);
659
+ icon: /* @__PURE__ */ l(Oe, { size: 18 }),
660
+ onItemClick: (o) => {
661
+ o(t.ai_default_commands.translate.prompt_placeholder);
3070
662
  },
3071
663
  size: "small"
3072
664
  },
@@ -3074,13 +666,13 @@ function Zo(e) {
3074
666
  key: "simplify",
3075
667
  title: t.ai_default_commands.simplify.title,
3076
668
  aliases: t.ai_default_commands.simplify.aliases,
3077
- icon: /* @__PURE__ */ y(jo, { size: 18 }),
669
+ icon: /* @__PURE__ */ l(Pe, { size: 18 }),
3078
670
  onItemClick: async () => {
3079
- await o.invokeAI({
671
+ await n.invokeAI({
3080
672
  useSelection: !0,
3081
673
  userPrompt: "Simplify",
3082
674
  // By default, LLM will be able to add / update / delete blocks. For "summarize", we only want to allow adding new blocks.
3083
- streamToolsProvider: O.html.getStreamToolsProvider({
675
+ streamToolsProvider: y.html.getStreamToolsProvider({
3084
676
  defaultStreamTools: {
3085
677
  add: !1,
3086
678
  delete: !1,
@@ -3091,18 +683,18 @@ function Zo(e) {
3091
683
  },
3092
684
  size: "small"
3093
685
  }
3094
- ];
686
+ ] : [];
3095
687
  }
3096
- function Wo(e) {
3097
- const t = L(e), o = I(e);
3098
- return [
688
+ function Ze(e) {
689
+ const t = w(e), n = e.getExtension(b);
690
+ return n ? [
3099
691
  {
3100
692
  key: "accept",
3101
693
  title: t.ai_menu.actions.accept.title,
3102
694
  aliases: t.ai_menu.actions.accept.aliases,
3103
- icon: /* @__PURE__ */ y(Jo, { size: 18 }),
695
+ icon: /* @__PURE__ */ l(ze, { size: 18 }),
3104
696
  onItemClick: () => {
3105
- o.acceptChanges();
697
+ n.acceptChanges();
3106
698
  },
3107
699
  size: "small"
3108
700
  },
@@ -3110,24 +702,24 @@ function Wo(e) {
3110
702
  key: "revert",
3111
703
  title: t.ai_menu.actions.revert.title,
3112
704
  aliases: t.ai_menu.actions.revert.aliases,
3113
- icon: /* @__PURE__ */ y(et, { size: 18 }),
705
+ icon: /* @__PURE__ */ l(X, { size: 18 }),
3114
706
  onItemClick: () => {
3115
- o.rejectChanges();
707
+ n.rejectChanges();
3116
708
  },
3117
709
  size: "small"
3118
710
  }
3119
- ];
711
+ ] : [];
3120
712
  }
3121
- function Yo(e) {
3122
- const t = L(e), o = I(e);
3123
- return [
713
+ function De(e) {
714
+ const t = w(e), n = e.getExtension(b);
715
+ return n ? [
3124
716
  {
3125
717
  key: "retry",
3126
718
  title: t.ai_menu.actions.retry.title,
3127
719
  aliases: t.ai_menu.actions.retry.aliases,
3128
- icon: /* @__PURE__ */ y(Vo, { size: 18 }),
720
+ icon: /* @__PURE__ */ l(He, { size: 18 }),
3129
721
  onItemClick: async () => {
3130
- await o.retry();
722
+ await n.retry();
3131
723
  },
3132
724
  size: "small"
3133
725
  },
@@ -3135,51 +727,50 @@ function Yo(e) {
3135
727
  key: "cancel",
3136
728
  title: t.ai_menu.actions.cancel.title,
3137
729
  aliases: t.ai_menu.actions.cancel.aliases,
3138
- icon: /* @__PURE__ */ y(et, { size: 18 }),
730
+ icon: /* @__PURE__ */ l(X, { size: 18 }),
3139
731
  onItemClick: () => {
3140
- o.rejectChanges();
732
+ n.rejectChanges();
3141
733
  },
3142
734
  size: "small"
3143
735
  }
3144
- ];
736
+ ] : [];
3145
737
  }
3146
- function Go(e, t) {
3147
- return t === "user-input" ? e.getSelection() ? Zo(e) : Ro(e) : t === "user-reviewing" ? Wo(e) : t === "error" ? Yo(e) : [];
738
+ function Ne(e, t) {
739
+ return t === "user-input" ? e.getSelection() ? qe(e) : Re(e) : t === "user-reviewing" ? Ze(e) : t === "error" ? De(e) : [];
3148
740
  }
3149
- const Ko = (e) => {
3150
- const t = Q(), [o, r] = $e(""), n = tt(), s = X(), a = I(t), i = qe(
3151
- a.store,
3152
- (d) => d.aiMenuState !== "closed" ? d.aiMenuState.status : "closed"
3153
- ), { items: l } = e, c = A(() => {
3154
- let d = [];
3155
- return l ? d = l(t, i) : d = Go(t, i), d.map((h) => ({
741
+ const Fe = (e) => {
742
+ const t = A(), [n, o] = $(""), a = ee(), c = P(), i = _(b), r = G(b, {
743
+ selector: (f) => f.aiMenuState !== "closed" ? f.aiMenuState.status : "closed"
744
+ }), { items: s } = e, u = k(() => {
745
+ let f = [];
746
+ return s ? f = s(t, r) : f = Ne(t, r), f.map((h) => ({
3156
747
  ...h,
3157
748
  onItemClick: () => {
3158
- h.onItemClick(r);
749
+ h.onItemClick(o);
3159
750
  }
3160
751
  }));
3161
- }, [l, i, t]), u = $(
3162
- async (d) => {
3163
- await a.invokeAI({
3164
- userPrompt: d,
752
+ }, [s, r, t]), d = I(
753
+ async (f) => {
754
+ await i.invokeAI({
755
+ userPrompt: f,
3165
756
  useSelection: t.getSelection() !== void 0
3166
757
  });
3167
758
  },
3168
- [a, t]
759
+ [i, t]
3169
760
  );
3170
- He(() => {
3171
- (i === "user-reviewing" || i === "error") && r("");
3172
- }, [i]);
3173
- const m = A(() => i === "thinking" ? n.ai_menu.status.thinking : i === "ai-writing" ? n.ai_menu.status.editing : i === "error" ? n.ai_menu.status.error : n.ai_menu.input_placeholder, [i, n]), p = A(() => {
3174
- if (i === "thinking" || i === "ai-writing")
3175
- return /* @__PURE__ */ y(
3176
- s.SuggestionMenu.Loader,
761
+ Y(() => {
762
+ (r === "ai-writing" || r === "user-reviewing" || r === "error") && o("");
763
+ }, [r]);
764
+ const g = k(() => r === "thinking" ? a.ai_menu.status.thinking : r === "ai-writing" ? a.ai_menu.status.editing : r === "error" ? a.ai_menu.status.error : a.ai_menu.input_placeholder, [r, a]), p = k(() => {
765
+ if (r === "thinking" || r === "ai-writing")
766
+ return /* @__PURE__ */ l(
767
+ c.SuggestionMenu.Loader,
3177
768
  {
3178
769
  className: "bn-suggestion-menu-loader bn-combobox-right-section"
3179
770
  }
3180
771
  );
3181
- if (i === "error")
3182
- return /* @__PURE__ */ y("div", { className: "bn-combobox-right-section bn-combobox-error", children: /* @__PURE__ */ y(
772
+ if (r === "error")
773
+ return /* @__PURE__ */ l("div", { className: "bn-combobox-right-section bn-combobox-error", children: /* @__PURE__ */ l(
3183
774
  "svg",
3184
775
  {
3185
776
  xmlns: "http://www.w3.org/2000/svg",
@@ -3187,315 +778,135 @@ const Ko = (e) => {
3187
778
  viewBox: "0 -960 960 960",
3188
779
  width: "1em",
3189
780
  fill: "currentColor",
3190
- children: /* @__PURE__ */ y("path", { d: "M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm0-160q17 0 28.5-11.5T520-480v-160q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640v160q0 17 11.5 28.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" })
781
+ children: /* @__PURE__ */ l("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" })
3191
782
  }
3192
783
  ) });
3193
- }, [s, i]);
3194
- return /* @__PURE__ */ y(
3195
- Fo,
3196
- {
3197
- onManualPromptSubmit: e.onManualPromptSubmit || u,
3198
- items: c,
3199
- promptText: o,
3200
- onPromptTextChange: r,
3201
- placeholder: m,
3202
- disabled: i === "thinking" || i === "ai-writing",
3203
- icon: /* @__PURE__ */ y("div", { className: "bn-combobox-icon", children: /* @__PURE__ */ y(ie, {}) }),
784
+ }, [c, r]);
785
+ return /* @__PURE__ */ l(
786
+ je,
787
+ {
788
+ onManualPromptSubmit: e.onManualPromptSubmit || d,
789
+ items: u,
790
+ promptText: n,
791
+ onPromptTextChange: o,
792
+ placeholder: g,
793
+ disabled: r === "thinking" || r === "ai-writing",
794
+ icon: /* @__PURE__ */ l("div", { className: "bn-combobox-icon", children: /* @__PURE__ */ l(E, {}) }),
3204
795
  rightSection: p
3205
796
  }
3206
797
  );
3207
- }, Xo = (e) => {
3208
- const t = e.blockID ? document.querySelector(`[data-id="${e.blockID}"]`) : void 0, o = A(() => t ? {
3209
- getBoundingClientRect: () => t.getBoundingClientRect(),
3210
- contextElement: t
3211
- } : null, [t]), { isMounted: r, ref: n, style: s, getFloatingProps: a, isPositioned: i } = Bt(!!t, o, 3e3, {
3212
- canDismiss: {
3213
- enabled: !0,
3214
- escapeKey: !0,
3215
- outsidePress: e.canDismissViaOutsidePress
3216
- },
3217
- placement: "bottom",
3218
- middleware: [
3219
- Mt(10),
3220
- // flip(),
3221
- Et({
3222
- apply({ rects: l, elements: c }) {
3223
- Object.assign(c.floating.style, {
3224
- width: `${l.reference.width}px`
3225
- });
798
+ }, st = (e) => {
799
+ const t = A(), n = _(b), o = G(b, {
800
+ editor: t,
801
+ selector: (r) => r.aiMenuState
802
+ }), a = o === "closed" ? void 0 : o.blockId, c = k(
803
+ () => ({
804
+ useFloatingOptions: {
805
+ open: o !== "closed",
806
+ placement: "bottom",
807
+ middleware: [
808
+ be(10),
809
+ // flip(),
810
+ ve({
811
+ apply({ rects: r, elements: s }) {
812
+ Object.assign(s.floating.style, {
813
+ width: `${r.reference.width}px`
814
+ });
815
+ }
816
+ })
817
+ ],
818
+ onOpenChange: (r) => {
819
+ r || o === "closed" || (o.status === "user-input" ? n.closeAIMenu() : (o.status === "user-reviewing" || o.status === "error") && n.rejectChanges());
820
+ }
821
+ },
822
+ useDismissProps: {
823
+ enabled: o === "closed" || o.status === "user-input",
824
+ // We should just be able to set `referencePress: true` instead of
825
+ // using this listener, but this doesn't seem to trigger.
826
+ // (probably because we don't assign the referenceProps to the reference element)
827
+ outsidePress: (r) => {
828
+ if (r.target instanceof Element) {
829
+ const s = r.target.closest(".bn-block");
830
+ s && s.getAttribute("data-id") === a && n.closeAIMenu();
831
+ }
832
+ return !0;
3226
833
  }
3227
- })
3228
- ],
3229
- onOpenChange: e.onOpenChange,
3230
- whileElementsMounted: (l, c, u) => _t(l, c, u, {
3231
- animationFrame: !0
3232
- }),
3233
- ...e.floatingOptions
3234
- });
3235
- return r ? /* @__PURE__ */ y(
3236
- "div",
3237
- {
3238
- ref: n,
3239
- style: {
3240
- ...s
3241
834
  },
3242
- ...a(),
3243
- children: i && e.children
3244
- }
3245
- ) : null;
3246
- }, Cr = (e) => {
3247
- const t = Q(), o = I(t), r = qe(o.store, (a) => a.aiMenuState), n = r === "closed" ? void 0 : r.blockId, s = e.aiMenu || Ko;
3248
- return /* @__PURE__ */ y(
3249
- Xo,
3250
- {
3251
- canDismissViaOutsidePress: r === "closed" || r.status === "user-input",
3252
- blockID: n,
3253
- onOpenChange: (a) => {
3254
- a || r === "closed" || (r.status === "user-input" ? o.closeAIMenu() : (r.status === "user-reviewing" || r.status === "error") && o.rejectChanges());
835
+ elementProps: {
836
+ style: {
837
+ zIndex: 100
838
+ }
3255
839
  },
3256
- children: /* @__PURE__ */ y(s, {})
3257
- }
3258
- );
3259
- }, Or = () => {
3260
- const e = tt(), t = X(), o = Q(), r = I(o), n = () => {
3261
- o.formattingToolbar.closeMenu();
3262
- const s = o.getSelection();
3263
- if (!s)
840
+ ...e.floatingUIOptions
841
+ }),
842
+ [n, o, a, e.floatingUIOptions]
843
+ ), i = e.aiMenu || Fe;
844
+ return /* @__PURE__ */ l(Ce, { blockId: a, ...c, children: o !== "closed" && /* @__PURE__ */ l(i, {}) });
845
+ }, lt = () => {
846
+ const e = ee(), t = P(), n = A(), o = _(b), a = _(se), c = () => {
847
+ const i = n.getSelection();
848
+ if (!i)
3264
849
  throw new Error("No selection");
3265
- const a = s.blocks[s.blocks.length - 1].id;
3266
- r.openAIMenuAtBlock(a);
850
+ const r = i.blocks[i.blocks.length - 1].id;
851
+ o.openAIMenuAtBlock(r), a.store.setState(!1);
3267
852
  };
3268
- return o.isEditable ? /* @__PURE__ */ y(
853
+ return n.isEditable ? /* @__PURE__ */ l(
3269
854
  t.Generic.Toolbar.Button,
3270
855
  {
3271
856
  className: "bn-button",
3272
857
  label: e.formatting_toolbar.ai.tooltip,
3273
858
  mainTooltip: e.formatting_toolbar.ai.tooltip,
3274
- icon: /* @__PURE__ */ y(ie, {}),
3275
- onClick: n
859
+ icon: /* @__PURE__ */ l(E, {}),
860
+ onClick: c
3276
861
  }
3277
862
  ) : null;
3278
- }, Qo = {
3279
- AI: ie
863
+ }, Ue = {
864
+ AI: E
3280
865
  };
3281
- function Ir(e) {
3282
- const t = I(e);
3283
- return [
866
+ function ct(e) {
867
+ const t = e.getExtension(b);
868
+ return t ? [
3284
869
  {
3285
870
  key: "ai",
3286
871
  onItemClick: () => {
3287
- const r = e.getTextCursorPosition();
3288
- r.block.content && Array.isArray(r.block.content) && // isarray check not ideal
3289
- r.block.content.length === 0 && r.prevBlock ? t.openAIMenuAtBlock(r.prevBlock.id) : t.openAIMenuAtBlock(r.block.id);
3290
- },
3291
- ...L(e).slash_menu.ai,
3292
- icon: /* @__PURE__ */ y(Qo.AI, {})
3293
- }
3294
- ];
3295
- }
3296
- function er(e) {
3297
- return Object.fromEntries(
3298
- Object.entries(e).map(([t, o]) => [
3299
- t,
3300
- St({
3301
- ...o,
3302
- inputSchema: pe(o.inputSchema),
3303
- outputSchema: pe(o.outputSchema)
3304
- })
3305
- ])
3306
- );
3307
- }
3308
- function tr(e, t) {
3309
- let o = "";
3310
- return e.pipeThrough(
3311
- new TransformStream({
3312
- start(r) {
3313
- r.enqueue({ type: "start" }), r.enqueue({ type: "start-step" }), r.enqueue({
3314
- type: "tool-input-start",
3315
- toolCallId: "call_object_1",
3316
- toolName: t
3317
- });
3318
- },
3319
- transform(r, n) {
3320
- switch (r.type) {
3321
- case "text-delta":
3322
- o += r.textDelta, n.enqueue({
3323
- type: "tool-input-delta",
3324
- toolCallId: "call_object_1",
3325
- inputTextDelta: r.textDelta
3326
- });
3327
- break;
3328
- case "object":
3329
- case "finish":
3330
- break;
3331
- case "error":
3332
- n.enqueue({
3333
- type: "error",
3334
- errorText: K(r.error)
3335
- });
3336
- break;
3337
- default: {
3338
- const s = r;
3339
- throw new Error(`Unsupported chunk type: ${s}`);
3340
- }
3341
- }
872
+ const o = e.getTextCursorPosition();
873
+ o.block.content && Array.isArray(o.block.content) && // isarray check not ideal
874
+ o.block.content.length === 0 && o.prevBlock ? t.openAIMenuAtBlock(o.prevBlock.id) : t.openAIMenuAtBlock(o.block.id);
3342
875
  },
3343
- async flush(r) {
3344
- r.enqueue({
3345
- type: "tool-input-available",
3346
- toolCallId: "call_object_1",
3347
- toolName: t,
3348
- input: JSON.parse(o)
3349
- }), r.enqueue({ type: "finish-step" }), r.enqueue({ type: "finish" });
3350
- }
3351
- })
3352
- );
3353
- }
3354
- function or(e, t) {
3355
- return new ReadableStream({
3356
- start(r) {
3357
- r.enqueue({ type: "start" }), r.enqueue({ type: "start-step" }), r.enqueue({
3358
- type: "tool-input-start",
3359
- toolCallId: "call_object_1",
3360
- toolName: t
3361
- }), r.enqueue({
3362
- type: "tool-input-delta",
3363
- toolCallId: "call_object_1",
3364
- inputTextDelta: JSON.stringify(e)
3365
- }), r.enqueue({
3366
- type: "tool-input-available",
3367
- toolCallId: "call_object_1",
3368
- toolName: t,
3369
- input: e
3370
- }), r.enqueue({ type: "finish-step" }), r.enqueue({ type: "finish" }), r.close();
3371
- }
3372
- });
3373
- }
3374
- const rr = {
3375
- "mistral.chat": {
3376
- mode: "auto"
3377
- },
3378
- "google.generative-ai": {
3379
- mode: "auto"
3380
- },
3381
- "groq.chat": {
3382
- providerOptions: {
3383
- groq: {
3384
- structuredOutputs: !1
3385
- }
876
+ ...w(e).slash_menu.ai,
877
+ icon: /* @__PURE__ */ l(Ue.AI, {})
3386
878
  }
3387
- }
3388
- };
3389
- function Ie(e) {
3390
- return rr[e.provider] || {};
3391
- }
3392
- class Br {
3393
- constructor(t) {
3394
- this.opts = t;
3395
- }
3396
- /**
3397
- * Calls an LLM with StreamTools, using the `generateObject` of the AI SDK.
3398
- *
3399
- * This is the non-streaming version.
3400
- */
3401
- async generateObject(t, o) {
3402
- const { model: r, _additionalOptions: n } = this.opts;
3403
- if (typeof r == "string")
3404
- throw new Error("model must be a LanguageModelV2");
3405
- const s = Object.keys(o)[0], a = o[s].inputSchema, i = await wt({
3406
- output: "object",
3407
- schema: a,
3408
- model: r,
3409
- mode: "tool",
3410
- messages: Y(t),
3411
- ...Ie(r),
3412
- ...n ?? {}
3413
- });
3414
- return or(i.object, s);
3415
- }
3416
- /**
3417
- * Calls an LLM with StreamTools, using the `streamObject` of the AI SDK.
3418
- *
3419
- * This is the streaming version.
3420
- */
3421
- async streamObject(t, o) {
3422
- const { model: r, _additionalOptions: n } = this.opts;
3423
- if (typeof r == "string")
3424
- throw new Error("model must be a LanguageModelV2");
3425
- const s = Object.keys(o)[0], a = o[s].inputSchema, i = Tt({
3426
- output: "object",
3427
- schema: a,
3428
- model: r,
3429
- mode: "tool",
3430
- messages: Y(t),
3431
- ...Ie(r),
3432
- ...n ?? {}
3433
- });
3434
- return tr(
3435
- i.fullStream,
3436
- s
3437
- );
3438
- }
3439
- /**
3440
- * Calls an LLM with StreamTools, using the `streamText` of the AI SDK.
3441
- *
3442
- * This is the streaming version.
3443
- */
3444
- async streamText(t, o) {
3445
- const { model: r, _additionalOptions: n } = this.opts;
3446
- return xt({
3447
- model: r,
3448
- messages: Y(t),
3449
- tools: o,
3450
- toolChoice: "required",
3451
- // extra options for streamObject
3452
- ...n ?? {}
3453
- // activeTools: ["applyDocumentOperations"],
3454
- }).toUIMessageStream();
3455
- }
3456
- async sendMessages({
3457
- messages: t,
3458
- body: o
3459
- // metadata,
3460
- }) {
3461
- const r = this.opts.stream ?? !0, n = o.toolDefinitions, s = er(n);
3462
- if (this.opts.objectGeneration)
3463
- return r ? this.streamObject(t, s) : this.generateObject(t, s);
3464
- if (r)
3465
- return await this.streamText(t, s);
3466
- throw new Error("Not implemented (generateText)");
3467
- }
3468
- reconnectToStream() {
3469
- throw new Error("Not implemented");
3470
- }
879
+ ] : [];
3471
880
  }
3472
881
  export {
3473
- Ke as AIExtension,
3474
- Ko as AIMenu,
3475
- Cr as AIMenuController,
3476
- Or as AIToolbarButton,
3477
- Xo as BlockPositioner,
3478
- ze as ChunkExecutionError,
3479
- Br as ClientSideTransport,
3480
- rr as PROVIDER_OVERRIDES,
3481
- Fo as PromptSuggestionMenu,
3482
- Dt as StreamToolExecutor,
3483
- O as aiDocumentFormats,
3484
- Kt as buildAIRequest,
3485
- vr as createAIExtension,
3486
- Lt as createStreamToolsArraySchema,
3487
- At as defaultAIRequestSender,
3488
- Xt as executeAIRequest,
3489
- Pr as fetchViaProxy,
3490
- L as getAIDictionary,
3491
- I as getAIExtension,
3492
- Ir as getAISlashMenuItems,
3493
- Go as getDefaultAIMenuItems,
3494
- Ie as getProviderOverrides,
3495
- or as objectAsToolCallInUIMessageStream,
3496
- Vt as objectStreamToOperationsResult,
3497
- tr as partialObjectStreamAsToolCallInUIMessageStream,
3498
- xr as promptHelpers,
3499
- er as toolDefinitionsToToolSet
882
+ b as AIExtension,
883
+ Fe as AIMenu,
884
+ st as AIMenuController,
885
+ lt as AIToolbarButton,
886
+ dt as ClientSideTransport,
887
+ ft as PROVIDER_OVERRIDES,
888
+ je as PromptSuggestionMenu,
889
+ gt as StreamToolExecutor,
890
+ pt as _getApplySuggestionsTr,
891
+ y as aiDocumentFormats,
892
+ de as buildAIRequest,
893
+ ht as createStreamToolsArraySchema,
894
+ Ct as fetchViaProxy,
895
+ w as getAIDictionary,
896
+ ct as getAISlashMenuItems,
897
+ Ne as getDefaultAIMenuItems,
898
+ bt as getProviderOverrides,
899
+ vt as injectDocumentStateMessages,
900
+ St as makeDocumentStateBuilder,
901
+ yt as objectAsToolCallInUIMessageStream,
902
+ wt as objectStreamToOperationsResult,
903
+ kt as partialObjectStreamAsToolCallInUIMessageStream,
904
+ It as promptHelpers,
905
+ fe as sendMessageWithAIRequest,
906
+ _t as setupToolCallStreaming,
907
+ xt as streamToolsToToolSet,
908
+ Lt as toolDefinitionsToToolSet,
909
+ Mt as toolSetToToolDefinitions,
910
+ ee as useAIDictionary
3500
911
  };
3501
912
  //# sourceMappingURL=blocknote-xl-ai.js.map