@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.
- package/dist/blocknote-xl-ai.cjs +1 -9
- package/dist/blocknote-xl-ai.cjs.map +1 -1
- package/dist/blocknote-xl-ai.js +586 -3175
- package/dist/blocknote-xl-ai.js.map +1 -1
- package/dist/client-C4uaJa77.js +2228 -0
- package/dist/client-C4uaJa77.js.map +1 -0
- package/dist/client-DrruPiJu.cjs +36 -0
- package/dist/client-DrruPiJu.cjs.map +1 -0
- package/dist/server.cjs +2 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.js +25 -0
- package/dist/server.js.map +1 -0
- package/dist/webpack-stats.json +1 -1
- package/package.json +15 -9
- package/src/AIExtension.ts +442 -415
- package/src/api/aiRequest/{execute.ts → builder.ts} +31 -44
- package/src/api/aiRequest/index.ts +2 -2
- package/src/api/aiRequest/sendMessageWithAIRequest.ts +66 -0
- package/src/api/aiRequest/types.ts +10 -23
- package/src/api/formats/DocumentStateBuilder.ts +153 -0
- package/src/api/formats/base-tools/createAddBlocksTool.ts +5 -1
- package/src/api/formats/base-tools/createUpdateBlockTool.ts +5 -1
- package/src/api/formats/formats.ts +62 -0
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/src/api/formats/html-blocks/htmlBlocks.test.ts +190 -194
- package/src/api/formats/html-blocks/htmlBlocks.ts +22 -25
- package/src/api/formats/index.ts +2 -72
- package/src/api/formats/json/errorHandling.test.ts +30 -41
- package/src/api/formats/json/json.test.ts +1 -5
- package/src/api/formats/json/json.ts +26 -26
- package/src/api/formats/json/tools/jsontools.test.ts +2 -2
- package/src/api/formats/markdown-blocks/markdownBlocks.test.ts +1 -6
- package/src/api/formats/markdown-blocks/markdownBlocks.ts +23 -26
- package/src/api/formats/tests/sharedTestCases.ts +26 -18
- package/src/api/promptHelpers/addCursorPosition.ts +27 -23
- package/src/components/AIMenu/AIMenu.tsx +18 -10
- package/src/components/AIMenu/AIMenuController.tsx +83 -29
- package/src/components/AIMenu/PromptSuggestionMenu.tsx +4 -2
- package/src/components/AIMenu/getDefaultAIMenuItems.tsx +17 -5
- package/src/components/FormattingToolbar/AIToolbarButton.tsx +13 -8
- package/src/components/SuggestionMenu/getAISlashMenuItems.tsx +5 -2
- package/src/{i18n → hooks}/useAIDictionary.ts +1 -1
- package/src/index.ts +2 -5
- package/src/prosemirror/agent.test.ts +2 -2
- package/src/server.ts +11 -0
- package/src/streamTool/ChunkExecutionError.ts +13 -0
- package/src/streamTool/StreamToolExecutor.ts +23 -21
- package/src/streamTool/filterNewOrUpdatedOperations.ts +1 -0
- package/src/streamTool/index.ts +3 -1
- package/src/streamTool/jsonSchema.ts +10 -0
- package/src/streamTool/preprocess.ts +3 -1
- package/src/streamTool/streamTool.ts +10 -7
- package/src/streamTool/vercelAiSdk/clientside/ClientSideTransport.ts +15 -4
- package/src/streamTool/vercelAiSdk/util/appendableStream.test.ts +247 -0
- package/src/streamTool/vercelAiSdk/util/appendableStream.ts +72 -0
- package/src/streamTool/vercelAiSdk/util/chatHandlers.test.ts +229 -0
- package/src/streamTool/vercelAiSdk/util/chatHandlers.ts +49 -78
- package/src/streamTool/vercelAiSdk/util/injectDocumentStateMessages.ts +79 -0
- package/src/streamTool/vercelAiSdk/util/toolDefinitions.ts +40 -0
- package/src/testUtil/cases/combinedOperationsTestCases.ts +1 -1
- package/src/testUtil/cases/editors/blockFormatting.ts +2 -2
- package/src/testUtil/cases/editors/emptyEditor.ts +2 -2
- package/src/testUtil/cases/editors/formattingAndMentions.ts +2 -2
- package/src/testUtil/cases/editors/simpleEditor.ts +3 -3
- package/src/testUtil/cases/editors/tables.ts +2 -2
- package/src/testUtil/cases/updateOperationTestCases.ts +4 -4
- package/src/types.ts +30 -10
- package/src/util/AbortError.ts +9 -0
- package/types/src/AIExtension.d.ts +32 -40
- package/types/src/api/aiRequest/builder.d.ts +11 -0
- package/types/src/api/aiRequest/index.d.ts +2 -2
- package/types/src/api/aiRequest/sendMessageWithAIRequest.d.ts +21 -0
- package/types/src/api/aiRequest/types.d.ts +9 -18
- package/types/src/api/formats/DocumentStateBuilder.d.ts +53 -0
- package/types/src/api/formats/formats.d.ts +142 -0
- package/types/src/api/formats/html-blocks/htmlBlocks.d.ts +4 -16
- package/types/src/api/formats/index.d.ts +2 -166
- package/types/src/api/formats/json/json.d.ts +8 -17
- package/types/src/api/formats/markdown-blocks/markdownBlocks.d.ts +2 -18
- package/types/src/api/promptHelpers/addCursorPosition.d.ts +1 -2
- package/types/src/components/AIMenu/AIMenuController.d.ts +2 -0
- package/types/src/index.d.ts +2 -5
- package/types/src/server.d.ts +5 -0
- package/types/src/streamTool/ChunkExecutionError.d.ts +8 -0
- package/types/src/streamTool/StreamToolExecutor.d.ts +3 -7
- package/types/src/streamTool/index.d.ts +3 -1
- package/types/src/streamTool/jsonSchema.d.ts +2 -0
- package/types/src/streamTool/streamTool.d.ts +2 -2
- package/types/src/streamTool/vercelAiSdk/clientside/ClientSideTransport.d.ts +12 -0
- package/types/src/streamTool/vercelAiSdk/util/appendableStream.d.ts +13 -0
- package/types/src/streamTool/vercelAiSdk/util/appendableStream.test.d.ts +1 -0
- package/types/src/streamTool/vercelAiSdk/util/chatHandlers.d.ts +3 -4
- package/types/src/streamTool/vercelAiSdk/util/chatHandlers.test.d.ts +1 -0
- package/types/src/streamTool/vercelAiSdk/util/injectDocumentStateMessages.d.ts +2 -0
- package/types/src/streamTool/vercelAiSdk/util/toolDefinitions.d.ts +13 -0
- package/types/src/types.d.ts +24 -7
- package/types/src/util/AbortError.d.ts +6 -0
- package/src/api/aiRequest/defaultAIRequestSender.ts +0 -42
- package/src/api/formats/PromptBuilder.ts +0 -22
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/src/api/formats/html-blocks/defaultHTMLPromptBuilder.ts +0 -200
- package/src/api/formats/html-blocks/htmlPromptData.ts +0 -92
- package/src/api/formats/json/defaultJSONPromptBuilder.ts +0 -173
- package/src/api/formats/json/jsonPromptData.ts +0 -97
- package/src/api/formats/markdown-blocks/defaultMarkdownPromptBuilder.ts +0 -172
- package/src/api/formats/markdown-blocks/markdownPromptData.ts +0 -91
- package/src/components/AIMenu/BlockPositioner.tsx +0 -86
- package/src/streamTool/toolDefinitionsToToolSet.ts +0 -24
- package/types/src/api/aiRequest/defaultAIRequestSender.d.ts +0 -4
- package/types/src/api/aiRequest/execute.d.ts +0 -31
- package/types/src/api/formats/PromptBuilder.d.ts +0 -17
- package/types/src/api/formats/html-blocks/defaultHTMLPromptBuilder.d.ts +0 -3
- package/types/src/api/formats/html-blocks/htmlPromptData.d.ts +0 -31
- package/types/src/api/formats/json/defaultJSONPromptBuilder.d.ts +0 -3
- package/types/src/api/formats/json/jsonPromptData.d.ts +0 -76
- package/types/src/api/formats/markdown-blocks/defaultMarkdownPromptBuilder.d.ts +0 -3
- package/types/src/api/formats/markdown-blocks/markdownPromptData.d.ts +0 -52
- package/types/src/components/AIMenu/BlockPositioner.d.ts +0 -10
- package/types/src/streamTool/toolDefinitionsToToolSet.d.ts +0 -9
- /package/types/src/{i18n → hooks}/useAIDictionary.d.ts +0 -0
package/dist/blocknote-xl-ai.cjs
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
"use strict";var ot=Object.defineProperty;var rt=(e,t,o)=>t in e?ot(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var L=(e,t,o)=>rt(e,typeof t!="symbol"?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const nt=require("@ai-sdk/react"),b=require("@blocknote/core"),$=require("@blocknote/prosemirror-suggest-changes"),H=require("prosemirror-model"),U=require("prosemirror-state"),st=require("prosemirror-tables"),J=require("prosemirror-view"),it=require("y-prosemirror"),at=require("lodash.isequal"),re=require("@ai-sdk/provider-utils"),T=require("ai"),x=require("prosemirror-transform"),ee=require("prosemirror-changeset"),y=require("react/jsx-runtime"),_=require("@blocknote/react"),w=require("react"),Ie=require("zustand"),te=require("@floating-ui/react"),Oe=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},lt=Oe(at),j=Oe(w),me=e=>{let t;const o=new Set,r=(c,u)=>{const m=typeof c=="function"?c(t):c;if(!Object.is(m,t)){const p=t;t=u??(typeof m!="object"||m===null)?m:Object.assign({},t,m),o.forEach(d=>d(t,p))}},n=()=>t,i={setState:r,getState:n,getInitialState:()=>l,subscribe:c=>(o.add(c),()=>o.delete(c))},l=t=e(r,n,i);return i},fe=e=>e?me(e):me;function ct(e){const{properties:t,required:o,$defs:r,...n}=e.inputSchema;return{schema:{type:"object",description:e.description,properties:{type:{type:"string",enum:[e.name]},...t},required:["type",...o??[]],additionalProperties:!1,...n},$defs:r}}function Me(e){const t=e.map(r=>ct(r)),o={};for(const r of t)for(const n in r.$defs){if(o[n]&&!lt.default(o[n],r.$defs[n]))throw new Error(`Duplicate, but different definition for ${n}`);o[n]=r.$defs[n]}return{type:"object",properties:{operations:{type:"array",items:{anyOf:t.map(r=>r.schema)}}},additionalProperties:!1,required:["operations"],$defs:Object.keys(o).length>0?o:void 0}}function Be(e,t){return{async sendAIRequest(o,r){const n=await t(o);return await e(o.chat.messages,n),o.chat.sendMessage(void 0,{...r,body:{...(r==null?void 0:r.body)??{},toolDefinitions:{applyDocumentOperations:{name:"applyDocumentOperations",inputSchema:Me(o.streamTools),outputSchema:{type:"object"}}}},metadata:{promptData:n}})}}}class ne extends Error{constructor(t,o,r){super(t,r),this.chunk=o,this.name="ChunkExecutionError"}}class Ee{constructor(t){L(this,"stream");this.streamTools=t,this.stream=this.createStream()}createStream(){let t;const o=new TransformStream({transform:async(i,l)=>{const c=typeof i=="string"?await ut(i,(t==null?void 0:t.isPossiblyPartial)??!1,this.streamTools):i;c&&(t=c,l.enqueue(c))},flush:i=>{t!=null&&t.isPossiblyPartial&&i.error(new Error("stream ended with a partial operation"))}}),r=o.readable.pipeThrough(this.createExecutor()),[n,s]=r.tee(),a=n.pipeTo(new WritableStream);return{writable:o.writable,readable:s,finishPromise:a}}createExecutor(){const t=this.streamTools.map(o=>o.executor());return new TransformStream({transform:async(o,r)=>{var s;let n=!1;for(const a of t)try{if(await a.execute(o)){r.enqueue({status:"ok",chunk:o}),n=!0;break}}catch(i){throw new ne(`Tool execution failed: ${re.getErrorMessage(i)}`,o,{cause:i})}if(!n){const a=((s=o.operation)==null?void 0:s.type)||"unknown";throw new Error(`No tool could handle operation of type: ${a}`)}}})}get writable(){return this.stream.writable}get readable(){return this.stream.readable}async finish(){await this.stream.finishPromise}async executeOperationsArray(t){const o=this.writable.getWriter();for await(const r of t){const n=await T.parsePartialJson(r);if(n.state==="undefined-input"||n.state==="failed-parse"||!n)return;await o.write(r)}await o.close(),await this.finish()}async execute(t){const o=this.writable.getWriter();for await(const r of t)await o.write(r);await o.close(),await this.finish()}async executeOne(t){await this.execute(async function*(){yield{operation:t,isUpdateToPreviousOperation:!1,isPossiblyPartial:!1,metadata:{}}}())}}async function ut(e,t,o){const r=await T.parsePartialJson(e);if(r.state==="undefined-input"||r.state==="failed-parse"||!r)return;const n=o.find(a=>{var i;return a.name===((i=r.value)==null?void 0:i.type)}),s=n&&n.validate(r.value);if(s!=null&&s.ok)return{operation:s.value,isPossiblyPartial:r.state==="repaired-parse",isUpdateToPreviousOperation:t,metadata:void 0}}function dt(e){return new ReadableStream({async start(t){try{for await(const o of e)t.enqueue(o);t.close()}catch(o){t.error(o)}}})}function _e(e){if(e.locked)throw new Error("Stream (source) is already locked and cannot be iterated.");const t=e.pipeThrough(new TransformStream);return t[Symbol.asyncIterator]=()=>{if(t.locked)throw new Error("Stream is already locked and cannot be iterated again.");const o=t.getReader();return{async next(){const{done:r,value:n}=await o.read();return r?{done:!0,value:void 0}:{done:!1,value:n}}}},t}function pt(e){return _e(dt(e))}async function*mt(e,t){var s;let o=0,r=!0,n;for await(const a of e)if((s=a.operations)!=null&&s.length){for(let i=o;i<a.operations.length;i++){const l=a.operations[i];n=l,yield{partialOperation:l,isUpdateToPreviousOperation:i===o&&!r,isPossiblyPartial:i===a.operations.length-1,metadata:t},r=!1}o=a.operations.length-1}if(!n)throw new Error("No operations seen");yield{partialOperation:n,isUpdateToPreviousOperation:!0,isPossiblyPartial:!1,metadata:t}}async function*ft(e,t){let o=!1;for await(const r of e){const n=r.operation;n.ok?(yield{operation:n.value,isUpdateToPreviousOperation:o?!1:r.isUpdateToPreviousOperation,isPossiblyPartial:r.isPossiblyPartial,metadata:r.metadata},o=!1):(o=o||!r.isUpdateToPreviousOperation,t==null||t({...r,operation:n}))}}async function*ht(e,t){for await(const o of e){const r=t.find(s=>s.name===o.partialOperation.type);if(!r){yield{operation:{ok:!1,error:`No matching function for ${o.partialOperation.type}`},isUpdateToPreviousOperation:o.isUpdateToPreviousOperation,isPossiblyPartial:o.isPossiblyPartial,metadata:o.metadata};continue}yield{operation:r.validate(o.partialOperation),isUpdateToPreviousOperation:o.isUpdateToPreviousOperation,isPossiblyPartial:o.isPossiblyPartial,metadata:o.metadata}}}async function*yt(e,t){const o=ht(e,t);yield*ft(o,n=>{if(!n.isPossiblyPartial)throw new Error("invalid operation: "+n.operation.error)})}function Ae(e,t,o){return pt(yt(mt(_e(e),o),t))}async function gt(e,t,o){const r=new Ee(e),n=bt();n.output.pipeTo(r.writable);const s=new Map;let a=!0;const i=t["~registerMessagesCallback"](()=>{St(t,d=>{if(!s.has(d.toolCallId)){const h=kt(e,d.toolName,d.toolCallId);n.append(h.operationsStream),s.set(d.toolCallId,h),a&&(a=!1,o==null||o())}return s.get(d.toolCallId)})});await new Promise(d=>{const h=t["~registerStatusCallback"](()=>{(t.status==="ready"||t.status==="error")&&(i(),h(),t.status!=="error"&&f(),d())}),f=t["~registerErrorCallback"](()=>{if(t.error){f();for(const k of s.values())k.complete||k.writer.abort(t.error)}})}),await n.finalize();const c=(await Promise.allSettled([r.finish()]))[0];let u;if(c.status==="rejected"){if(c.reason instanceof ne)u=c.reason;else if(!t.error)throw new Error("Unexpected: no ChunkExecutionError but also no chat.error (network error?)")}let m=!1;const p=Array.from(s.values().filter(d=>d.complete));if(p.forEach((d,h)=>{const f=d.toolCallId===(u==null?void 0:u.chunk.metadata.toolCallId);f&&(m=!0),t.addToolResult({tool:p[h].toolName,toolCallId:p[h].toolCallId,output:m===!1?{status:"ok"}:f?{status:"error",error:re.getErrorMessage(u)}:{status:"not-executed-previous-tool-errored"}})}),u)throw u;if(t.error)throw t.error}function bt(){let e,t=Promise.resolve(),o=!1;const r=new ReadableStream({start(a){e=a},cancel(a){o=!0,e.error(a)}});async function n(a){if(o)throw new Error("Appendable stream canceled, can't append");const i=a.getReader();return t=t.then(async()=>{for(;;)try{const{done:l,value:c}=await i.read();if(l||o)break;e.enqueue(c)}catch(l){o=!0,e.error(l);break}}),t}async function s(){await t,o||e.close()}return{output:r,append:n,finalize:s}}function St(e,t){var o;for(const r of((o=e.lastMessage)==null?void 0:o.parts)??[]){if(!T.isToolUIPart(r)||r.type.replace("tool-","")!=="applyDocumentOperations")continue;const s=r.toolCallId,a=t({toolName:r.type.replace("tool-",""),toolCallId:s});wt(r,a)}}function kt(e,t,o){const r=new TransformStream,n=Ae(r.readable,e,{toolCallId:o});return{writer:r.writable.getWriter(),complete:!1,operationsStream:n,toolName:t,toolCallId:o}}function wt(e,t){if(e.state==="input-streaming"){const o=e.input;o!==void 0&&t.writer.write(o)}else if(e.state==="input-available"){const o=e.input;if(o===void 0)throw new Error("input is undefined");t.complete||(t.complete=!0,t.writer.write(o),t.writer.close())}}function se(e){return(e.type==="paragraph"||!e.type)&&!e.content||Array.isArray(e.content)&&e.content.length===0}function xt(e,t,o=!0,r=!0){let n=0,s=e.length;if(o)for(;n<s&&t(e[n]);)n++;if(r)for(;s>n&&t(e[s-1]);)s--;return e.slice(n,s)}function P(e,t){return xt(e,r=>se(r)&&(t==null?void 0:t.cursorBlockId)!==r.id,(t==null?void 0:t.trimStart)??!1,(t==null?void 0:t.trimEnd)??!0)}function Ne(e){const{useSelection:t,deleteEmptyCursorBlock:o,streamToolsProvider:r}={useSelection:e.useSelection??!1,deleteEmptyCursorBlock:e.deleteEmptyCursorBlock??!0,streamToolsProvider:e.streamToolsProvider??M.html.getStreamToolsProvider()},n=t?void 0:e.editor.getTextCursorPosition().block,s=n&&o&&se(n)&&P(e.editor.document).length>0?n.id:void 0,a=t?e.editor.getSelectionCutBlocks():void 0,i=r.getStreamTools(e.editor,a?{from:a._meta.startPos,to:a._meta.endPos}:void 0,e.onBlockUpdated);return{editor:e.editor,chat:e.chat,userPrompt:e.userPrompt,selectedBlocks:a==null?void 0:a.blocks,streamTools:i,emptyCursorBlockToDelete:s}}async function Le(e){const{aiRequest:t,sender:o,chatRequestOptions:r,onStart:n}=e,s=gt(t.streamTools,t.chat,()=>{n==null||n(),t.emptyCursorBlockToDelete&&t.editor.getBlock(t.emptyCursorBlockToDelete)&&t.editor.removeBlocks([t.emptyCursorBlockToDelete])});await o.sendAIRequest(t,r),await s}function Tt(e,t){e.length>0&&e.push({role:"assistant",id:"document-state-"+e.length,parts:[{type:"text",text:"This is the latest state of the selection (ignore previous selections, you MUST issue operations against this latest version of the selection):"},{type:"text",text:JSON.stringify(t.htmlSelectedBlocks)},{type:"text",text:"This is the latest state of the document (INCLUDING the selected text), find the selected text in there to understand the context:"},{type:"text",text:JSON.stringify(t.htmlDocument)}]},{role:"user",id:"user-prompt-"+e.length,parts:[{type:"text",text:"The user asks you to do the following:"},{type:"text",text:t.userPrompt}]}),e.push({role:"system",id:"document-state-intro",parts:[{type:"text",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:"}]},{role:"system",id:"document-state-selection",parts:[{type:"text",text:JSON.stringify(t.htmlSelectedBlocks)}]},{role:"system",id:"document-state-context",parts:[{type:"text",text:"This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"},{type:"text",text:JSON.stringify(t.htmlDocument)}]},{role:"user",id:"user-prompt",parts:[{type:"text",text:t.userPrompt}]})}function vt(e,t){if(e.length>0){e.push({role:"assistant",id:"document-state-"+e.length,parts:[{type:"text",text:"This is the latest state of the document (ignore previous documents, you MUST issue operations against this latest version of the document):"},{type:"text",text:JSON.stringify(t.htmlBlocks)}]},{role:"user",id:"user-prompt-"+e.length,parts:[{type:"text",text:t.userPrompt}]});return}e.push({role:"system",id:"document-state-intro",parts:[{type:"text",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):"}]},{role:"system",id:"document-state-data",parts:[{type:"text",text:JSON.stringify(t.htmlBlocks)}]},{role:"system",id:"extended-instructions",parts:[{type:"text",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).")}]},{role:"user",id:"user-prompt",parts:[{type:"text",text:t.userPrompt}]})}const Pt=async(e,t)=>{t.selection?Tt(e,t):vt(e,t)};function X(e,t){const o=e.getTextCursorPosition(),r=[];for(const n of t){const s=n.id===o.block.id;r.push({id:n.id,block:n.block}),s&&r.push({cursor:!0})}return r}async function B(e,t){return await Promise.all(e.map(async o=>({id:o.id,block:await t(o)})))}function C(e){return e.flatMap(t=>[{...t,children:[]},...C(t.children)])}function D(e){return e.map(t=>typeof t=="object"&&t&&"id"in t?{...t,id:`${t.id}$`}:t)}async function Ct(e){return e.selectedBlocks?{...await De(e.editor,{selectedBlocks:e.selectedBlocks}),userPrompt:e.userPrompt}:{...await je(e.editor,{excludeBlockIds:e.emptyCursorBlockToDelete?[e.emptyCursorBlockToDelete]:void 0}),userPrompt:e.userPrompt}}async function je(e,t){const o=P(e.document).length===0,r=e.getTextCursorPosition().block.id,n=P(e.document,{cursorBlockId:r}),s=await B(C(n),async c=>e.blocksToHTMLLossy([c])),i=X(e,s).filter(c=>"cursor"in c||!(t.excludeBlockIds||[]).includes(c.id));return{selection:!1,htmlBlocks:D(i),isEmptyDocument:o}}async function De(e,t){const o=P(e.document).length===0,r=await B(C(t.selectedBlocks),async s=>e.blocksToHTMLLossy([s])),n=D(r);return{isEmptyDocument:o,selection:!0,htmlSelectedBlocks:n,htmlDocument:(await B(C(e.document),async s=>e.blocksToHTMLLossy([s]))).map(({block:s})=>({block:s}))}}function It(e){let t,o=!1;return e.descendants((r,n)=>o?!1:(r.isText&&(o=!0,t=n),!0)),t}function Z(e){var s;const t=b.getPmSchema(e),{modification:o}=t.marks,r=[],n=new x.Transform(e.before);for(let a=0;a<e.steps.length;a++){const i=e.steps[a],l=new x.Mapping(e.mapping.maps.slice(0,a)).invert();if(i.structure){if(i instanceof x.ReplaceStep){if(i.to!==i.from+1||i.slice.openStart!==0||i.slice.openEnd!==1||i.slice.content.size!==2)throw new Error("Structure change is not in expected format (ReplaceStep)")}else if(i instanceof x.ReplaceAroundStep){if(i.insert!==1||i.slice.size!==2||i.gapTo!==i.to-1||i.gapFrom!==i.from+1)throw new Error("Structure change is not in expected format (ReplaceAroundStep)")}else throw new Error("Step is not a ReplaceStep or ReplaceAroundStep");const S=l.map(i.from),g=i.slice.content.firstChild,O=n.doc.resolve(n.mapping.map(S)).nodeAfter;let v=g.marks||[];g.type!==O.type&&(v=o.create({type:"nodeType",previousValue:O.type.name,newValue:g.type.name}).addToSet(v));const z=new Set([...Object.keys(g.attrs),...Object.keys(O.attrs)]);for(const E of z)g.attrs[E]!==O.attrs[E]&&(v=o.create({type:"attr",attrName:E,previousValue:O.attrs[E],newValue:g.attrs[E]}).addToSet(v));const N=n.steps.length;n.setNodeMarkup(n.mapping.map(S),g.type,g.attrs,v),r.push({prosemirrorSteps:n.steps.slice(N),selection:void 0,type:"replace"});continue}if(!(i instanceof x.ReplaceStep))throw new Error("Step is not a ReplaceStep");const c=l.map(i.from),u=l.map(i.to);if(i.slice.openStart>0||i.slice.openEnd>0)throw new Error("Slice has openStart or openEnd > 0, but structure=false");r.push({prosemirrorSteps:[],selection:{anchor:n.mapping.map(c),head:n.mapping.map(u)},type:"select"});const m=i.slice.content.textBetween(0,i.slice.size),p=m===n.doc.textBetween(n.mapping.map(c),n.mapping.map(u));let d;if(p)d=i.slice.content.size;else if(m.length===0)d=i.slice.content.size;else{const S=It(i.slice.content);if(S===void 0)throw new Error("unexpected: no first character found");d=S+1}let h=n.mapping.map(u);const f=n.mapping.map(u);let k=!0;for(let S=d;S<=i.slice.content.size;S++){const g=k&&c!==u,O=n.steps.length;if(g){const N=n.doc.resolve(n.mapping.map(c));(s=N.nodeAfter)!=null&&s.isBlock&&n.addNodeMark(N.pos,t.mark("deletion",{})),n.addMark(N.pos,h,t.mark("deletion",{})),h=n.mapping.map(u)}const v=new H.Slice(i.slice.content.cut(0,S),0,0);n.replace(f,h,v).addMark(f,f+v.content.size,t.mark("insertion",{})),n.doc.nodesBetween(f,f+v.content.size,(N,E)=>E<f||E>f+v.content.size?!0:(N.isBlock&&n.addNodeMark(E,t.mark("insertion",{})),!1)),h=n.mapping.slice(O).map(h);const z=U.TextSelection.near(n.doc.resolve(f+v.content.size),-1);r.push({prosemirrorSteps:n.steps.slice(O),selection:{anchor:z.from,head:z.from},type:g?"replace":"insert"}),k=!1}}return r}async function ie(e){const t=Math.random()*.3+.85;if(e.type==="select")await new Promise(o=>setTimeout(o,100*t));else if(e.type==="insert")await new Promise(o=>setTimeout(o,10*t));else if(e.type==="replace")await new Promise(o=>setTimeout(o,200*t));else throw new b.UnreachableCaseError(e.type)}function ae(e,t){e.setMeta("addToHistory",!1),t.selection&&e.setMeta("aiAgent",{selection:{anchor:t.selection.anchor,head:t.selection.head}});for(const o of t.prosemirrorSteps)if(e.maybeStep(o).failed)throw new Error("failed to apply step");return e}function Ot(e,t,o){const r=new x.Transform(t);for(const a of e){const i=new x.ReplaceStep(r.mapping.map(a.fromA),r.mapping.map(a.toA),o.slice(a.fromB,a.toB));r.step(i)}const n=r.mapping.invert();let s=r.doc.content.findDiffStart(o.content);for(;s!==null;){const a=o.resolve(s).nodeAfter,i=r.doc.resolve(s).nodeAfter;if(!a||!i)throw new Error("diffNode not found");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);let d=e.length;for(let f=0;f<e.length;f++)if(e[f].fromA>=p){d=f;break}e.splice(d,0,{fromA:m,toA:p,fromB:s,toB:u,deleted:[],inserted:[],type:l?"node-type-or-attr-update":"mark-update"}),r.step(new x.ReplaceStep(s,u,o.slice(s,u),l));const h=r.doc.content.findDiffStart(o.content);if(h===s)throw new Error("diffStart not moving");s=h}return e}const he=(e,t)=>{const o=new Set,r=new Set;e.descendants(a=>{a.type.name==="tableCell"&&o.add(JSON.stringify(a.toJSON()))}),t.descendants(a=>{a.type.name==="tableCell"&&r.add(JSON.stringify(a.toJSON()))});const n=new Set([...o].filter(a=>r.has(a)));return{encodeCharacter:a=>a,encodeNodeStart:a=>{if(a.type.name==="tableCell"){const i=JSON.stringify(a.toJSON());return n.has(i)?i:a.type.name}return a.type.name},encodeNodeEnd:a=>{if(a.type.name==="tableCell"){const i=JSON.stringify(a.toJSON());return n.has(i)?i:-1}return-1},compareTokens:(a,i)=>a===i}};function Q(e,t,o=!1,r,n){const s=b.getNodeById(e.id,t),a=new x.Transform(t);b.updateBlockTr(a,s.posBeforeNode,e.block,r,n);let i=a.doc,l=ee.ChangeSet.create(t,void 0,he(t,i));if(l=l.addSteps(i,a.mapping.maps,0),o&&l.changes.length>0){const m=l.changes[l.changes.length-1],p=m.toA-m.fromA,d=m.toB-m.fromB;if(p>d){const h=t.slice(m.fromA+d,m.toA);a.step(new x.ReplaceStep(m.toB,m.toB,h)),i=a.doc,l=ee.ChangeSet.create(l.startDoc,void 0,he(l.startDoc,i)),l=l.addSteps(i,a.mapping.maps,0)}}const c=[],u=ee.simplifyChanges(l.changes,i);for(let m=0;m<u.length;m++){const p=u[m],d=i.slice(p.fromB,p.toB);if(d.openEnd===1&&d.openStart===0&&(p.type="node-type-or-attr-update",d.size>2)){const h={fromA:p.fromA,toA:p.fromA+1,fromB:p.fromB,toB:p.fromB+1,deleted:[],inserted:[],type:"node-type-or-attr-update"},f={fromA:p.fromA+1,toA:p.toA,fromB:p.fromB+1,toB:p.toB,deleted:[],inserted:[]};u.splice(m,1,h,f),m++}}Ot(u,t,i);for(let m=0;m<u.length;m++){const p=u[m],d=i.slice(p.fromB,p.toB);if(d.openEnd>0&&d.size>1)throw new Error("unexpected, openEnd > 0 and size > 1, this should have been split into two steps");m===u.length-1&&o&&p.type==="mark-update"||c.push(new x.ReplaceStep(p.fromA,p.toA,d,p.type==="node-type-or-attr-update"))}return c}function Mt(e,t){if(!e||!Array.isArray(e)||e.length===0)return{ok:!1,error:"blocks is required"};const o=[];for(const r of e){const n=t(r);if(!n.ok)return{ok:!1,error:`Invalid block: ${n.error}`};o.push(n.value)}return{ok:!0,value:o}}function le(e){return(t,o)=>{const r=typeof e.schema=="function"?e.schema(t):e.schema;return{name:"add",description:e.description,inputSchema:{type:"object",properties:{referenceId:{type:"string",description:"MUST be an id of a block in the document"},position:{type:"string",enum:["before","after"],description:"`after` to add blocks AFTER (below) the block with `referenceId`, `before` to add the block BEFORE (above)"},blocks:{items:r.block,type:"array"}},required:["referenceId","position","blocks"],$defs:r.$defs},validate:n=>{if(n.type!=="add")return{ok:!1,error:"invalid operation type"};if(n.position!=="before"&&n.position!=="after")return{ok:!1,error:"invalid position"};if(!n.referenceId||!n.blocks)return{ok:!1,error:"referenceId and blocks are required"};let s=n.referenceId;if(o.idsSuffixed){if(!(s!=null&&s.endsWith("$")))return{ok:!1,error:"referenceId must end with $"};s=s.slice(0,-1)}if(!t.getBlock(s))return{ok:!1,error:"referenceId not found"};const i=Mt(n.blocks,l=>e.validateBlock(l,t));return i.ok?{ok:!0,value:{type:n.type,referenceId:s,position:n.position,blocks:i.value}}:i},executor:()=>{let n=[];const s={};return{execute:async a=>{var c;if(a.isUpdateToPreviousOperation||(n=[]),a.operation.type!=="add")return!1;const i=a.operation,l=await e.toJSONToolCall(t,{...a,operation:i});if(!l||a.isPossiblyPartial&&se(l.blocks[l.blocks.length-1]))return!0;for(let u=0;u<l.blocks.length;u++){const m=l.blocks[u],p=t.prosemirrorState.tr;let d=[];if(u<n.length){const h=await e.rebaseTool(n[u],t),k=Q({id:n[u],block:m},h.doc,!1).map(S=>S.map(h.invertMap));for(const S of k)p.step(S.map(p.mapping));d=Z(p),d=d.filter(S=>S.type!=="select")}else{const h=i.position==="after"?s[i.referenceId]:void 0,f=b.insertBlocks(p,[m],u>0?n[u-1]:h||i.referenceId,u>0?"after":i.position);n.push(...f.map(k=>k.id)),d=Z(p)}for(const h of d)o.withDelays&&await ie(h),t.transact(f=>{ae(f,h)}),(c=o.onBlockUpdate)==null||c.call(o,n[u])}return a.isPossiblyPartial||i.position==="after"&&(s[i.referenceId]=n[n.length-1]),!0}}}}}}function ce(e){return(t,o)=>{const r=typeof e.schema=="function"?e.schema(t):e.schema;return{name:"update",description:e.description,inputSchema:{type:"object",properties:{id:{type:"string",description:"id of block to update"},block:r.block},required:["id","block"],$defs:r.$defs},validate:n=>{if(n.type!=="update")return{ok:!1,error:"invalid operation type"};if(!n.id)return{ok:!1,error:"id is required"};let s=n.id;if(o.idsSuffixed){if(!(s!=null&&s.endsWith("$")))return{ok:!1,error:"id must end with $"};s=s.slice(0,-1)}if(!n.block)return{ok:!1,error:"block is required"};const a=t.getBlock(s);if(!a)return console.error("BLOCK NOT FOUND",s),{ok:!1,error:"block not found"};const i=e.validateBlock(n.block,t,a.type);return i.ok?{ok:!0,value:{type:n.type,id:s,block:i.value}}:i},executor:()=>{let s=50;const a=o.updateSelection?{from:b.trackPosition(t,o.updateSelection.from),to:b.trackPosition(t,o.updateSelection.to)}:void 0;return{execute:async i=>{var S;if(i.operation.type!=="update")return!1;const l=i.operation;if(i.isPossiblyPartial){const g=JSON.stringify(l.block).length;if(g<s)return!0;s=g+50}else s=50;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,{...i,operation:l});if(!p)return!0;const d=Q(p,c.doc,i.isPossiblyPartial,u,m);if(d.length===1&&i.isPossiblyPartial)return!0;const h=d.map(g=>g.map(c.invertMap)),f=new x.Transform(t.prosemirrorState.doc);for(const g of h)f.step(g.map(f.mapping));const k=Z(f);for(const g of k)o.withDelays&&await ie(g),t.transact(O=>{ae(O,g)}),(S=o.onBlockUpdate)==null||S.call(o,l.id);return!0}}}}}}const ue=(e,t)=>({name:"delete",description:"Delete a block",inputSchema:{type:"object",properties:{id:{type:"string",description:"id of block to delete"}},required:["id"]},validate:o=>{if(o.type!=="delete")return{ok:!1,error:"invalid operation type"};if(!o.id)return{ok:!1,error:"id is required"};let r=o.id;if(t.idsSuffixed){if(!(r!=null&&r.endsWith("$")))return{ok:!1,error:"id must end with $"};r=r.slice(0,-1)}return e.getBlock(r)?{ok:!0,value:{type:"delete",id:r}}:{ok:!1,error:"block not found"}},executor:()=>({execute:async o=>{var a;if(o.operation.type!=="delete")return!1;const r=o.operation,n=e.prosemirrorState.tr;b.removeAndInsertBlocks(n,[r.id],[]);const s=Z(n);for(const i of s)t.withDelays&&await ie(i),e.transact(l=>{ae(l,i)}),(a=t.onBlockUpdate)==null||a.call(t,r.id);return!0}})});function ye(e){const t=e.lastIndexOf("<"),o=e.lastIndexOf(">");let r=e;if(t>o&&(r=e.substring(0,t),!r.trim()))return;const n=r.match(/&[a-zA-Z0-9]*$/);n&&(r=r.substring(0,r.length-n[0].length));const i=new DOMParser().parseFromString(`<div>${r}</div>`,"text/html").body.firstChild;return i?i.innerHTML:""}function W(e){let t;if($.applySuggestions(e.prosemirrorState,o=>{t=o}),!t)throw new Error("applySuggestionsTr is not set");return t}function Y(e,t){const o=t.mapping.invert();return{doc:t.doc,tr:()=>new x.Transform(t.doc),invertMap:o,rebaseTr:r=>{if(r.steps.length===0)throw new Error("No steps to apply");let n=e.prosemirrorState.tr;for(const s of r.steps){const a=s.map(o);if(!a)throw new Error("Step is not mapped");n=n.step(a)}return n}}}async function ge(e,t){var c;const o=W(t),r=b.getBlock(o.doc,e);if(!r)throw new Error("block not found");const n=await t.blocksToHTMLLossy([{...r,children:[]}]),s=(c=window.__TEST_OPTIONS)==null?void 0:c.mockID,a=await t.tryParseHTMLToBlocks(n);if(window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=s),a.length!==1)throw new Error("html diff invalid block count");const i=a[0];if(i.id=e,Q({id:e,block:i},o.doc).length)throw new Error("html diff");return Y(t,o)}function be(e){return typeof e!="string"?{ok:!1,error:"block must be a string"}:{ok:!0,value:e}}const R={add:le({description:"Insert new blocks",schema:{block:{type:"string",description:"html of block (MUST be a single, VALID HTML element)"}},validateBlock:be,rebaseTool:ge,toJSONToolCall:async(e,t)=>{var n;const o=(n=window.__TEST_OPTIONS)==null?void 0:n.mockID,r=(await Promise.all(t.operation.blocks.map(async s=>{const a=t.isPossiblyPartial?ye(s):s;return a?(await e.tryParseHTMLToBlocks(a)).map(i=>(delete i.id,i)):[]}))).flat();if(window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=o),r.length!==0)return{...t.operation,blocks:r}}}),update:ce({description:"Update a block",schema:{block:{type:"string",description:"html of block (MUST be a single HTML element)"}},validateBlock:be,rebaseTool:ge,toJSONToolCall:async(e,t)=>{const o=t.isPossiblyPartial?ye(t.operation.block):t.operation.block;if(!o)return;const r=(await e.tryParseHTMLToBlocks(o))[0];return window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=void 0),delete r.id,{...t.operation,block:r}}}),delete:ue};function Bt(e,t,o,r,n){if(typeof r=="boolean"){const i=r?e.getSelectionCutBlocks():void 0;r=i?{from:i._meta.startPos,to:i._meta.endPos}:void 0}const s=o??{add:!0,update:!0,delete:!0};return[...s.update?[R.update(e,{idsSuffixed:!0,withDelays:t,updateSelection:r,onBlockUpdate:n})]:[],...s.add?[R.add(e,{idsSuffixed:!0,withDelays:t,onBlockUpdate:n})]:[],...s.delete?[R.delete(e,{idsSuffixed:!0,withDelays:t,onBlockUpdate:n})]:[]]}const Et={getStreamToolsProvider:(e={})=>({getStreamTools:(t,o,r)=>Bt(t,e.withDelays??!0,e.defaultStreamTools,o,r)}),tools:R,defaultPromptBuilder:Pt,defaultPromptInputDataBuilder:Ct,promptHelpers:{getDataForPromptNoSelection:je,getDataForPromptWithSelection:De}};async function _t(e){return e.selectedBlocks?{...await $e(e.editor,{selectedBlocks:e.selectedBlocks}),userPrompt:e.userPrompt}:{...await qe(e.editor,{excludeBlockIds:e.emptyCursorBlockToDelete?[e.emptyCursorBlockToDelete]:void 0}),userPrompt:e.userPrompt}}async function qe(e,t){const o=P(e.document).length===0,r=e.getTextCursorPosition().block.id,n=P(e.document,{cursorBlockId:r}),s=await B(C(n),async c=>({...c,children:void 0})),i=X(e,s).filter(c=>"cursor"in c||!(t.excludeBlockIds||[]).includes(c.id));return{selection:!1,jsonBlocks:D(i),isEmptyDocument:o}}async function $e(e,t){const o=P(e.document).length===0,r=await B(C(t.selectedBlocks),async s=>s),n=D(r);return{isEmptyDocument:o,selection:!0,jsonSelectedBlocks:n,jsonDocument:(await B(C(e.document),async s=>({...s,id:void 0,children:void 0}))).map(({block:s})=>({block:s}))}}function At(e){const t={},o={};return e.forEach(n=>{const{type:s,...a}=n.properties,i=JSON.stringify(a);t[i]?t[i].push(s.enum[0]):(t[i]=[s.enum[0]],o[i]=n)}),Object.keys(t).map(n=>{const s=o[n];return{...s,properties:{...s.properties,type:{type:"string",enum:t[n]}}}})}function Nt(e){return{type:"object",properties:Object.fromEntries(Object.entries(e).map(([t,o])=>[t,{type:o.propSchema}])),additionalProperties:!1}}function Lt(){return{type:"object",properties:{type:{type:"string",enum:["text"]},text:{type:"string"},styles:{$ref:"#/$defs/styles"}},additionalProperties:!1,required:["type","text"]}}function He(e){return{type:"object",properties:Object.fromEntries(Object.entries(e).filter(([t,o])=>o.default!==void 0).map(([t,o])=>[t,{type:typeof o.default,enum:o.values}])),additionalProperties:!1}}function jt(e){return{type:"array",items:{anyOf:Object.entries(e).map(([t,o])=>o==="text"?{$ref:"#/$defs/styledtext"}:o==="link"?{type:"object",properties:{type:{type:"string",enum:["link"]},content:{type:"array",items:{$ref:"#/$defs/styledtext"}},href:{type:"string"}},additionalProperties:!1,required:["type","href","content"]}:{type:"object",properties:{type:{type:"string",enum:[o.type]},content:o.content==="styled"?{type:"array",items:{$ref:"#/$defs/styledtext"}}:void 0,props:He(o.propSchema)},additionalProperties:!1,required:["type",...o.content==="styled"?["content"]:[]]})}}}function Dt(e){return{anyOf:At(Object.entries(e).map(([t,o])=>({type:"object",properties:{type:{type:"string",enum:[o.type]},content:o.content==="inline"?{$ref:"#/$defs/inlinecontent"}:o.content==="table"?{type:"object",properties:{}}:void 0,props:He(o.propSchema)},additionalProperties:!1,required:["type"]})))}}function qt(e){const t=JSON.parse(JSON.stringify({blockSchema:e.blockSchema,inlineContentSchema:e.inlineContentSchema,styleSchema:e.styleSchema}));return{removeFileBlocks(){return t.blockSchema=Object.fromEntries(Object.entries(t.blockSchema).filter(([o,r])=>{var n;return!((n=e.blockSpecs[r.type].implementation.meta)!=null&&n.fileBlockAccept)})),this},removeDefaultProps(){return t.blockSchema=Object.fromEntries(Object.entries(t.blockSchema).map(([o,r])=>[o,{...r,propSchema:Object.fromEntries(Object.entries(r.propSchema).filter(n=>typeof b.defaultProps[n[0]]>"u"))}])),this},get(){return t}}}function Se(e){return e=qt(e).removeFileBlocks().removeDefaultProps().get(),{$defs:{styles:Nt(e.styleSchema),styledtext:Lt(),inlinecontent:jt(e.inlineContentSchema),block:Dt(e.blockSchema)}}}function Ue(e,t){return!t.schema.inlineContentSchema[e.type]||b.isStyledTextInlineContent(e)&&!("text"in e)?!1:b.isLinkInlineContent(e)?!("content"in e)||!("href"in e)?!1:Ue(e.content,t):!0}function ke(e,t,o){const r=e.type||o,n=t.schema.blockSchema[r];if(!n)return{ok:!1,error:"block type not found in editor"};if(e.children,n.content==="none"){if(e.content)return{ok:!1,error:"block content not expected for this block type"}}else{if(!e.content)return{ok:!0,value:e};if(!Array.isArray(e.content))return{ok:!1,error:"block content must be an array"};if(n.content==="table")return{ok:!0,value:e};if(!e.content.every(s=>Ue(s,t)))return{ok:!1,error:"block content must be an array of inline content"}}return{ok:!0,value:e}}const V={add:le({description:"Insert new blocks",schema:e=>({block:{$ref:"#/$defs/block"},...Se(e.schema)}),validateBlock:ke,rebaseTool:async(e,t)=>Y(t,W(t)),toJSONToolCall:async(e,t)=>t.operation}),update:ce({description:"Update a block, the new block will replace the existing block.",schema:e=>({block:{$ref:"#/$defs/block"},...Se(e.schema)}),validateBlock:ke,rebaseTool:async(e,t)=>Y(t,W(t)),toJSONToolCall:async(e,t)=>{const o=Object.fromEntries(Object.entries(b.defaultProps).map(([r,n])=>[r,n.default]));return{...t.operation,block:{...t.operation.block,props:{...o,...t.operation.block.props}}}}}),delete:ue};function $t(e,t){e.length>0&&e.push({role:"assistant",id:"document-state-"+e.length,parts:[{type:"text",text:"This is the latest state of the selection (ignore previous selections, you MUST issue operations against this latest version of the selection):"},{type:"text",text:JSON.stringify(t.jsonSelectedBlocks)},{type:"text",text:"This is the latest state of the document (INCLUDING the selected text), find the selected text in there to understand the context:"},{type:"text",text:JSON.stringify(t.jsonDocument)}]},{role:"user",id:"user-prompt-"+e.length,parts:[{type:"text",text:"The user asks you to do the following:"},{type:"text",text:t.userPrompt}]}),e.push({role:"system",id:"document-state-intro",parts:[{type:"text",text:`You're manipulating a selected part of a text document using JSON blocks.
|
|
2
|
-
Make sure to follow the json schema provided and always include the trailing $ in ids.
|
|
3
|
-
This is the selection as an array of JSON blocks:`},{type:"text",text:JSON.stringify(t.jsonSelectedBlocks)},{type:"text",text:"This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"},{type:"text",text:JSON.stringify(t.jsonDocument)}]},{role:"user",id:"user-prompt",parts:[{type:"text",text:t.userPrompt}]})}function Ht(e,t){if(e.length>0){e.push({role:"assistant",id:"document-state-"+e.length,parts:[{type:"text",text:"This is the latest state of the document (ignore previous documents, you MUST issue operations against this latest version of the document):"},{type:"text",text:JSON.stringify(t.jsonBlocks)}]},{role:"user",id:"user-prompt-"+e.length,parts:[{type:"text",text:t.userPrompt}]});return}e.push({role:"system",id:"document-state",parts:[{type:"text",text:`You're manipulating a text document using JSON blocks.
|
|
4
|
-
Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $).
|
|
5
|
-
This is the initial document as an array of JSON blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):`},{type:"text",text:JSON.stringify(t.jsonBlocks)},{type:"text",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).")}]},{role:"user",id:"user-prompt",parts:[{type:"text",text:t.userPrompt}]})}const Ut=async(e,t)=>{t.selection?$t(e,t):Ht(e,t)};function zt(e,t,o,r,n){if(typeof r=="boolean"){const i=r?e.getSelectionCutBlocks():void 0;r=i?{from:i._meta.startPos,to:i._meta.endPos}:void 0}const s=o??{add:!0,update:!0,delete:!0};return[...s.update?[V.update(e,{idsSuffixed:!0,withDelays:t,updateSelection:r,onBlockUpdate:n})]:[],...s.add?[V.add(e,{idsSuffixed:!0,withDelays:t,onBlockUpdate:n})]:[],...s.delete?[V.delete(e,{idsSuffixed:!0,withDelays:t,onBlockUpdate:n})]:[]]}const Jt={getStreamToolsProvider:(e={})=>({getStreamTools:(t,o,r)=>zt(t,e.withDelays??!0,e.defaultStreamTools,o,r)}),tools:V,defaultPromptBuilder:Ut,defaultPromptInputDataBuilder:_t,promptHelpers:{getDataForPromptNoSelection:qe,getDataForPromptWithSelection:$e}};async function Rt(e){return e.selectedBlocks?{...await Je(e.editor,{selectedBlocks:e.selectedBlocks}),userPrompt:e.userPrompt}:{...await ze(e.editor,{excludeBlockIds:e.emptyCursorBlockToDelete?[e.emptyCursorBlockToDelete]:void 0}),userPrompt:e.userPrompt}}async function ze(e,t){const o=P(e.document).length===0,r=e.getTextCursorPosition().block.id,n=P(e.document,{cursorBlockId:r}),s=await B(C(n),async c=>e.blocksToMarkdownLossy([c])),i=X(e,s).filter(c=>"cursor"in c||!(t.excludeBlockIds||[]).includes(c.id));return{selection:!1,markdownBlocks:D(i),isEmptyDocument:o}}async function Je(e,t){const o=P(e.document).length===0,r=await B(C(t.selectedBlocks),async s=>e.blocksToMarkdownLossy([s])),n=D(r);return{isEmptyDocument:o,selection:!0,markdownSelectedBlocks:n,markdownDocument:(await B(C(e.document),async s=>e.blocksToMarkdownLossy([s]))).map(({block:s})=>({block:s}))}}async function we(e,t){const o=W(t),r=await t.blocksToMarkdownLossy([b.getBlock(o.doc,e)]),n=await t.tryParseMarkdownToBlocks(r),s=Q({id:e,block:n[0]},o.doc),a=new x.Mapping;for(const i of s){const l=i.map(a);if(!l)throw new Error("Failed to map step");o.step(l),a.appendMap(l.getMap())}return Y(t,o)}function xe(e){return typeof e!="string"?{ok:!1,error:"block must be a string"}:{ok:!0,value:e}}const F={add:le({description:"Insert new blocks",schema:{block:{$ref:"#/$defs/block"},$defs:{block:{type:"string",description:"markdown of block"}}},validateBlock:xe,rebaseTool:we,toJSONToolCall:async(e,t)=>{const o=await Promise.all(t.operation.blocks.map(async r=>{const n=(await e.tryParseMarkdownToBlocks(r.trim()))[0];return delete n.id,n}));return window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=void 0),{...t.operation,blocks:o}}}),update:ce({description:"Update a block, the new block will replace the existing block.",schema:{block:{$ref:"#/$defs/block"},$defs:{block:{type:"string",description:"markdown of block"}}},validateBlock:xe,rebaseTool:we,toJSONToolCall:async(e,t)=>{const o=(await e.tryParseMarkdownToBlocks(t.operation.block.trim()))[0];return delete o.id,window.__TEST_OPTIONS&&(window.__TEST_OPTIONS.mockID=void 0),{...t.operation,block:o}}}),delete:ue};function Vt(e,t){e.length>0&&e.push({role:"assistant",id:"document-state-"+e.length,parts:[{type:"text",text:"This is the latest state of the selection (ignore previous selections, you MUST issue operations against this latest version of the selection):"},{type:"text",text:JSON.stringify(t.markdownSelectedBlocks)},{type:"text",text:"This is the latest state of the document (INCLUDING the selected text), find the selected text in there to understand the context:"},{type:"text",text:JSON.stringify(t.markdownDocument)}]},{role:"user",id:"user-prompt-"+e.length,parts:[{type:"text",text:"The user asks you to do the following:"},{type:"text",text:t.userPrompt}]}),e.push({role:"system",id:"document-state-intro",parts:[{type:"text",text:`You're manipulating a selected part of a text document using Markdown blocks.
|
|
6
|
-
Make sure to follow the json schema provided and always include the trailing $ in ids.
|
|
7
|
-
This is the selection as an array of Markdown blocks:`},{type:"text",text:JSON.stringify(t.markdownSelectedBlocks)},{type:"text",text:"This is the entire document (INCLUDING the selected text), find the selected text in there to understand the context:"},{type:"text",text:JSON.stringify(t.markdownDocument)}]},{role:"user",id:"user-prompt",parts:[{type:"text",text:t.userPrompt}]})}function Ft(e,t){if(e.length>0){e.push({role:"assistant",id:"document-state-"+e.length,parts:[{type:"text",text:"This is the latest state of the document (ignore previous documents, you MUST issue operations against this latest version of the document):"},{type:"text",text:JSON.stringify(t.markdownBlocks)}]},{role:"user",id:"user-prompt-"+e.length,parts:[{type:"text",text:t.userPrompt}]});return}e.push({role:"system",id:"document-state",parts:[{type:"text",text:`You're manipulating a text document using Markdown blocks.
|
|
8
|
-
Make sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $).
|
|
9
|
-
This is the initial document as an array of Markdown blocks (the cursor is BETWEEN two blocks as indicated by cursor: true):`},{type:"text",text:JSON.stringify(t.markdownBlocks)},{type:"text",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).")}]},{role:"user",id:"user-prompt",parts:[{type:"text",text:t.userPrompt}]})}const Zt=async(e,t)=>{t.selection?Vt(e,t):Ft(e,t)};function Wt(e,t,o,r,n){if(typeof r=="boolean"){const i=r?e.getSelectionCutBlocks():void 0;r=i?{from:i._meta.startPos,to:i._meta.endPos}:void 0}const s=o??{add:!0,update:!0,delete:!0};return[...s.update?[F.update(e,{idsSuffixed:!0,withDelays:t,updateSelection:r,onBlockUpdate:n})]:[],...s.add?[F.add(e,{idsSuffixed:!0,withDelays:t,onBlockUpdate:n})]:[],...s.delete?[F.delete(e,{idsSuffixed:!0,withDelays:t,onBlockUpdate:n})]:[]]}const Yt={getStreamToolsProvider:(e={})=>({getStreamTools:(t,o,r)=>Wt(t,e.withDelays??!0,e.defaultStreamTools,o,r)}),tools:F,defaultPromptBuilder:Zt,defaultPromptInputDataBuilder:Rt,promptHelpers:{getDataForPromptNoSelection:ze,getDataForPromptWithSelection:Je}},M={_experimental_json:Jt,_experimental_markdown:Yt,html:Et},Gt={addCursorPosition:X,flattenBlocks:C,suffixIDs:D,trimEmptyBlocks:P,convertBlocks:B},Te=new U.PluginKey("blocknote-agent-cursor");function Kt(e){return new U.Plugin({key:Te,view:t=>({}),state:{init:()=>({selection:void 0}),apply:(t,o)=>{const r=t.getMeta("aiAgent");return r?{selection:r.selection}:{selection:void 0}}},props:{decorations:t=>{const{doc:o}=t,{selection:r}=Te.getState(t),n=[];if(!r)return J.DecorationSet.create(o,[]);n.push(J.Decoration.widget(r.head,()=>Xt(e),{key:"agent-cursor",side:10}));const s=Math.min(r.anchor,r.head),a=Math.max(r.anchor,r.head);return n.push(J.Decoration.inline(s,a,it.defaultSelectionBuilder(e),{inclusiveEnd:!0,inclusiveStart:!1})),J.DecorationSet.create(o,n)}}})}const Xt=e=>{const t=document.createElement("span");t.classList.add("bn-collaboration-cursor__base"),t.setAttribute("data-active","true");const o=document.createElement("span");o.setAttribute("contentedEditable","false"),o.classList.add("bn-collaboration-cursor__caret"),o.setAttribute("style",`background-color: ${e.color}`);const r=document.createElement("span");return r.classList.add("bn-collaboration-cursor__label"),r.setAttribute("style",`background-color: ${e.color}`),r.insertBefore(document.createTextNode(e.name),null),o.insertBefore(r,null),t.insertBefore(document.createTextNode(""),null),t.insertBefore(o,null),t.insertBefore(document.createTextNode(""),null),t},Qt=new U.PluginKey("blocknote-ai-plugin");class de extends b.BlockNoteExtension{constructor(o,r){super();L(this,"chatSession");L(this,"scrollInProgress",!1);L(this,"autoScroll",!1);L(this,"_store",fe()(o=>({aiMenuState:"closed"})));L(this,"options");this.editor=o,this.options=fe()(n=>({...r})),this.addProsemirrorPlugin(new U.Plugin({key:Qt,filterTransaction:n=>{var a;const s=this.store.getState().aiMenuState;return!(s!=="closed"&&s.status==="ai-writing"&&(a=n.getMeta(st.fixTablesKey))!=null&&a.fixTables)}})),this.addProsemirrorPlugin($.suggestChanges()),this.addProsemirrorPlugin(Kt(r.agentCursor||{name:"AI",color:"#8bc6ff"})),document.addEventListener("scroll",()=>{this.scrollInProgress&&(this.autoScroll=!1),this.scrollInProgress=!0},!0),document.addEventListener("scrollend",()=>{this.scrollInProgress=!1},!0)}static key(){return"ai"}get store(){return this._store}openAIMenuAtBlock(o){var n;this.editor.setForceSelectionVisible(!0),this.editor.isEditable=!1,this._store.setState({aiMenuState:{blockId:o,status:"user-input"}});const r=(n=this.editor.domElement)==null?void 0:n.querySelector(`[data-node-type="blockContainer"][data-id="${o}"]`);r==null||r.scrollIntoView({block:"center"})}closeAIMenu(){this._store.setState({aiMenuState:"closed"}),this.chatSession=void 0,this.editor.setForceSelectionVisible(!1),this.editor.isEditable=!0,this.editor.focus()}acceptChanges(){var r;const o=this.editor.prosemirrorState.doc;this.editor.exec((n,s)=>$.revertSuggestions(n,a=>{s==null||s(a.setMeta("addToHistory",!1))})),this.editor.exec((n,s)=>{const a=n.tr;a.replace(0,a.doc.content.size,new H.Slice(H.Fragment.from(o),0,0));const i=n.apply(a);return $.applySuggestions(i,l=>{s==null||s(a.replace(0,a.doc.content.size,new H.Slice(H.Fragment.from(l.doc),0,0)))})}),(r=this.editor.forkYDocPlugin)==null||r.merge({keepChanges:!0}),this.closeAIMenu()}rejectChanges(){var o;this.editor.exec((r,n)=>$.revertSuggestions(r,s=>{n==null||n(s.setMeta("addToHistory",!1))})),(o=this.editor.forkYDocPlugin)==null||o.merge({keepChanges:!1}),this.closeAIMenu()}async retry(){var r;const{aiMenuState:o}=this.store.getState();if(o==="closed"||o.status!=="error"||!this.chatSession)throw new Error("retry() is only valid when a previous response failed");return((r=this.chatSession)==null?void 0:r.chat.status)==="error"?this.invokeAI({...this.chatSession.previousRequestOptions,userPrompt:"An error occured in the previous request. Please retry to accomplish the last user prompt."}):this.invokeAI({...this.chatSession.previousRequestOptions,userPrompt:"An error occured while executing the previous tool call. Please retry to accomplish the last user prompt."})}setAIResponseStatus(o){const r=this.store.getState().aiMenuState;if(r!=="closed")if(o==="ai-writing"&&this.editor.setForceSelectionVisible(!1),typeof o=="object"){if(o.status!=="error")throw new b.UnreachableCaseError(o.status);this._store.setState({aiMenuState:{status:o.status,error:o.error,blockId:r.blockId}})}else this._store.setState({aiMenuState:{status:o,blockId:r.blockId}})}async callLLM(o){return this.invokeAI(o)}async invokeAI(o){var r,n;this.setAIResponseStatus("thinking"),(r=this.editor.forkYDocPlugin)==null||r.fork();try{this.chatSession?this.chatSession.previousRequestOptions=o:this.chatSession={previousRequestOptions:o,chat:new nt.Chat({sendAutomaticallyWhen:()=>!1,transport:o.transport||this.options.getState().transport})};const s=this.chatSession.chat;o={...this.options.getState(),...o};const i=o.aiRequestSender??Be(M.html.defaultPromptBuilder,M.html.defaultPromptInputDataBuilder),l=Ne({editor:this.editor,chat:s,userPrompt:o.userPrompt,useSelection:o.useSelection,deleteEmptyCursorBlock:o.deleteEmptyCursorBlock,streamToolsProvider:o.streamToolsProvider,onBlockUpdated:c=>{if(this._store.setState({aiMenuState:{blockId:c,status:"ai-writing"}}),!this.autoScroll)return;const u=this._store.getState().aiMenuState,m=u==="closed"?void 0:u;if(!m||m.status!=="ai-writing")return;const p=b.getNodeById(m.blockId,this.editor.prosemirrorState.doc);if(!p)return;this.editor.prosemirrorView.domAtPos(p.posBeforeNode+1).node.scrollIntoView({block:"center"})}});await Le({aiRequest:l,sender:i,chatRequestOptions:o.chatRequestOptions,onStart:()=>{this.autoScroll=!0,this.setAIResponseStatus("ai-writing")}}),this.setAIResponseStatus("user-reviewing")}catch(s){this.setAIResponseStatus({status:"error",error:s}),console.warn("Error calling LLM",s,(n=this.chatSession)==null?void 0:n.chat.messages)}}}function eo(e){return t=>new de(t,e)}function A(e){return e.extension(de)}const to=e=>async(t,o)=>{const r=new Request(t,o),n=e(r.url),s=new Request(n,{headers:r.headers,body:(o==null?void 0:o.body)||r.body,method:r.method,duplex:"half"});return await fetch(s)};var Re={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ve=j.default.createContext&&j.default.createContext(Re),oo=["attr","size","title"];function ro(e,t){if(e==null)return{};var o=no(e,t),r,n;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function no(e,t){if(e==null)return{};var o={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;o[r]=e[r]}return o}function G(){return G=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},G.apply(this,arguments)}function Pe(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),o.push.apply(o,r)}return o}function K(e){for(var t=1;t<arguments.length;t++){var o=arguments[t]!=null?arguments[t]:{};t%2?Pe(Object(o),!0).forEach(function(r){so(e,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):Pe(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function so(e,t,o){return t=io(t),t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function io(e){var t=ao(e,"string");return typeof t=="symbol"?t:t+""}function ao(e,t){if(typeof e!="object"||!e)return e;var o=e[Symbol.toPrimitive];if(o!==void 0){var r=o.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Ve(e){return e&&e.map((t,o)=>j.default.createElement(t.tag,K({key:o},t.attr),Ve(t.child)))}function I(e){return t=>j.default.createElement(lo,G({attr:K({},e.attr)},t),Ve(e.child))}function lo(e){var t=o=>{var{attr:r,size:n,title:s}=e,a=ro(e,oo),i=n||o.size||"1em",l;return o.className&&(l=o.className),e.className&&(l=(l?l+" ":"")+e.className),j.default.createElement("svg",G({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},o.attr,r,a,{className:l,style:K(K({color:e.color||o.color},o.style),e.style),height:i,width:i,xmlns:"http://www.w3.org/2000/svg"}),s&&j.default.createElement("title",null,s),e.children)};return ve!==void 0?j.default.createElement(ve.Consumer,null,o=>t(o)):t(Re)}function Fe(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M8 7V11L2 6L8 1V5H13C17.4183 5 21 8.58172 21 13C21 17.4183 17.4183 21 13 21H4V19H13C16.3137 19 19 16.3137 19 13C19 9.68629 16.3137 7 13 7H8Z"},child:[]}]})(e)}function Ce(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M17.8492 11.6983L17.1421 10.9912L7.24264 20.8907H3V16.648L14.3137 5.33432L19.9706 10.9912C20.3611 11.3817 20.3611 12.0149 19.9706 12.4054L12.8995 19.4765L11.4853 18.0622L17.8492 11.6983ZM15.7279 9.57696L14.3137 8.16274L5 17.4765V18.8907H6.41421L15.7279 9.57696ZM18.5563 2.50589L21.3848 5.33432C21.7753 5.72484 21.7753 6.35801 21.3848 6.74853L19.9706 8.16274L15.7279 3.9201L17.1421 2.50589C17.5327 2.11537 18.1658 2.11537 18.5563 2.50589Z"},child:[]}]})(e)}function co(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M15.1986 9.94447C14.7649 9.5337 14.4859 8.98613 14.4085 8.39384L14.0056 5.31138L11.275 6.79724C10.7503 7.08274 10.1433 7.17888 9.55608 7.06948L6.49998 6.50015L7.06931 9.55625C7.17871 10.1435 7.08257 10.7505 6.79707 11.2751L5.31121 14.0057L8.39367 14.4086C8.98596 14.4861 9.53353 14.7651 9.94431 15.1987L12.0821 17.4557L13.4178 14.6486C13.6745 14.1092 14.109 13.6747 14.6484 13.418L17.4555 12.0823L15.1986 9.94447ZM15.2238 15.5079L13.0111 20.1581C12.8687 20.4573 12.5107 20.5844 12.2115 20.442C12.1448 20.4103 12.0845 20.3665 12.0337 20.3129L8.49229 16.5741C8.39749 16.474 8.27113 16.4096 8.13445 16.3918L3.02816 15.7243C2.69958 15.6814 2.46804 15.3802 2.51099 15.0516C2.52056 14.9784 2.54359 14.9075 2.5789 14.8426L5.04031 10.3192C5.1062 10.1981 5.12839 10.058 5.10314 9.92253L4.16 4.85991C4.09931 4.53414 4.3142 4.22086 4.63997 4.16017C4.7126 4.14664 4.78711 4.14664 4.85974 4.16017L9.92237 5.10331C10.0579 5.12855 10.198 5.10637 10.319 5.04048L14.8424 2.57907C15.1335 2.42068 15.4979 2.52825 15.6562 2.81931C15.6916 2.88421 15.7146 2.95507 15.7241 3.02833L16.3916 8.13462C16.4095 8.2713 16.4739 8.39766 16.5739 8.49245L20.3127 12.0338C20.5533 12.2617 20.5636 12.6415 20.3357 12.8821C20.2849 12.9357 20.2246 12.9795 20.1579 13.0112L15.5078 15.224C15.3833 15.2832 15.283 15.3835 15.2238 15.5079ZM16.0206 17.435L17.4348 16.0208L21.6775 20.2634L20.2633 21.6776L16.0206 17.435Z"},child:[]}]})(e)}function uo(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M8.00008 6V9H5.00008V6H8.00008ZM3.00008 4V11H10.0001V4H3.00008ZM13.0001 4H21.0001V6H13.0001V4ZM13.0001 11H21.0001V13H13.0001V11ZM13.0001 18H21.0001V20H13.0001V18ZM10.7072 16.2071L9.29297 14.7929L6.00008 18.0858L4.20718 16.2929L2.79297 17.7071L6.00008 20.9142L10.7072 16.2071Z"},child:[]}]})(e)}function po(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M15 18H16.5C17.8807 18 19 16.8807 19 15.5C19 14.1193 17.8807 13 16.5 13H3V11H16.5C18.9853 11 21 13.0147 21 15.5C21 17.9853 18.9853 20 16.5 20H15V22L11 19L15 16V18ZM3 4H21V6H3V4ZM9 18V20H3V18H9Z"},child:[]}]})(e)}function mo(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M13 6V21H11V6H5V4H19V6H13Z"},child:[]}]})(e)}function fo(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M6.23509 6.45329C4.85101 7.89148 4 9.84636 4 12C4 16.4183 7.58172 20 12 20C13.0808 20 14.1116 19.7857 15.0521 19.3972C15.1671 18.6467 14.9148 17.9266 14.8116 17.6746C14.582 17.115 13.8241 16.1582 12.5589 14.8308C12.2212 14.4758 12.2429 14.2035 12.3636 13.3943L12.3775 13.3029C12.4595 12.7486 12.5971 12.4209 14.4622 12.1248C15.4097 11.9746 15.6589 12.3533 16.0043 12.8777C16.0425 12.9358 16.0807 12.9928 16.1198 13.0499C16.4479 13.5297 16.691 13.6394 17.0582 13.8064C17.2227 13.881 17.428 13.9751 17.7031 14.1314C18.3551 14.504 18.3551 14.9247 18.3551 15.8472V15.9518C18.3551 16.3434 18.3168 16.6872 18.2566 16.9859C19.3478 15.6185 20 13.8854 20 12C20 8.70089 18.003 5.8682 15.1519 4.64482C14.5987 5.01813 13.8398 5.54726 13.575 5.91C13.4396 6.09538 13.2482 7.04166 12.6257 7.11976C12.4626 7.14023 12.2438 7.12589 12.012 7.11097C11.3905 7.07058 10.5402 7.01606 10.268 7.75495C10.0952 8.2232 10.0648 9.49445 10.6239 10.1543C10.7134 10.2597 10.7307 10.4547 10.6699 10.6735C10.59 10.9608 10.4286 11.1356 10.3783 11.1717C10.2819 11.1163 10.0896 10.8931 9.95938 10.7412C9.64554 10.3765 9.25405 9.92233 8.74797 9.78176C8.56395 9.73083 8.36166 9.68867 8.16548 9.64736C7.6164 9.53227 6.99443 9.40134 6.84992 9.09302C6.74442 8.8672 6.74488 8.55621 6.74529 8.22764C6.74529 7.8112 6.74529 7.34029 6.54129 6.88256C6.46246 6.70541 6.35689 6.56446 6.23509 6.45329ZM12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22Z"},child:[]}]})(e)}function ho(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M9.9997 15.1709L19.1921 5.97852L20.6063 7.39273L9.9997 17.9993L3.63574 11.6354L5.04996 10.2212L9.9997 15.1709Z"},child:[]}]})(e)}function yo(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M9.9997 15.1709L19.1921 5.97852L20.6063 7.39273L9.9997 17.9993L3.63574 11.6354L5.04996 10.2212L9.9997 15.1709Z"},child:[]}]})(e)}function go(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M12 4C9.4095 4 7.10606 5.23053 5.64274 7.14274L8 9.5H2V3.5L4.21863 5.71863C6.05061 3.452 8.85558 2 12 2 17.5228 2 22 6.47715 22 12H20C20 7.58172 16.4183 4 12 4ZM4 12C4 16.4183 7.58172 20 12 20 14.5905 20 16.894 18.7695 18.3573 16.8573L16 14.5 22 14.5V20.5L19.7814 18.2814C17.9494 20.548 15.1444 22 12 22 6.47715 22 2 17.5228 2 12H4Z"},child:[]}]})(e)}function pe(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M17.0007 1.20825 18.3195 3.68108 20.7923 4.99992 18.3195 6.31876 17.0007 8.79159 15.6818 6.31876 13.209 4.99992 15.6818 3.68108 17.0007 1.20825ZM8.00065 4.33325 10.6673 9.33325 15.6673 11.9999 10.6673 14.6666 8.00065 19.6666 5.33398 14.6666.333984 11.9999 5.33398 9.33325 8.00065 4.33325ZM19.6673 16.3333 18.0007 13.2083 16.334 16.3333 13.209 17.9999 16.334 19.6666 18.0007 22.7916 19.6673 19.6666 22.7923 17.9999 19.6673 16.3333Z"},child:[]}]})(e)}function q(e){if(!e.dictionary.ai)throw new Error("AI dictionary not found");return e.dictionary.ai}function Ze(){const e=_.useBlockNoteContext();return q(e.editor)}const We=e=>{const t=_.useComponentsContext(),{onManualPromptSubmit:o,promptText:r,onPromptTextChange:n}=e,[s,a]=w.useState(""),i=r||s,l=w.useCallback(async f=>{f.key==="Enter"&&o(i)},[i,o]),c=w.useCallback(f=>{const k=f.currentTarget.value;n&&n(k),r===void 0&&a(k)},[n,a,r]),u=w.useMemo(()=>b.filterSuggestionItems(e.items,i),[i,e.items]),{selectedIndex:m,setSelectedIndex:p,handler:d}=_.useSuggestionMenuKeyboardHandler(u,f=>f.onItemClick()),h=w.useCallback(f=>{f.key==="Enter"?u.length>0?d(f):l(f):d(f)},[l,d,u.length]);return w.useEffect(()=>{p(0)},[i,p]),y.jsxs("div",{className:"bn-combobox",children:[y.jsx(t.Generic.Form.Root,{children:y.jsx(t.Generic.Form.TextInput,{className:"bn-combobox-input",name:"ai-prompt",variant:"large",icon:e.icon,value:i||"",autoFocus:!0,placeholder:e.placeholder,disabled:e.disabled,onKeyDown:h,onChange:c,autoComplete:"off",rightSection:e.rightSection},"input-"+e.disabled)}),y.jsx(t.SuggestionMenu.Root,{className:"bn-combobox-items",id:"ai-suggestion-menu",children:u.map((f,k)=>y.jsx(t.SuggestionMenu.Item,{className:b.mergeCSSClasses("bn-suggestion-menu-item",f.size==="small"?"bn-suggestion-menu-item-small":""),id:`bn-suggestion-menu-item-${k}`,isSelected:k===m,onClick:f.onItemClick,item:f},f.title))})]})};function bo(e){const t=q(e),o=A(e);return[{key:"continue_writing",title:t.ai_default_commands.continue_writing.title,aliases:t.ai_default_commands.continue_writing.aliases,icon:y.jsx(Ce,{size:18}),onItemClick:async()=>{await o.invokeAI({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.",streamToolsProvider:M.html.getStreamToolsProvider({defaultStreamTools:{add:!0,delete:!1,update:!1}})})},size:"small"},{key:"summarize",title:t.ai_default_commands.summarize.title,aliases:t.ai_default_commands.summarize.aliases,icon:y.jsx(po,{size:18}),onItemClick:async()=>{await o.invokeAI({userPrompt:"Summarize",streamToolsProvider:M.html.getStreamToolsProvider({defaultStreamTools:{add:!0,delete:!1,update:!1}})})},size:"small"},{key:"action_items",title:t.ai_default_commands.add_action_items.title,aliases:t.ai_default_commands.add_action_items.aliases,icon:y.jsx(uo,{size:18}),onItemClick:async()=>{await o.invokeAI({userPrompt:"Add action items",streamToolsProvider:M.html.getStreamToolsProvider({defaultStreamTools:{add:!0,delete:!1,update:!1}})})},size:"small"},{key:"write_anything",title:t.ai_default_commands.write_anything.title,aliases:t.ai_default_commands.write_anything.aliases,icon:y.jsx(Ce,{size:18}),onItemClick:r=>{r(t.ai_default_commands.write_anything.prompt_placeholder)},size:"small"}]}function So(e){const t=q(e),o=A(e);return[{key:"improve_writing",title:t.ai_default_commands.improve_writing.title,aliases:t.ai_default_commands.improve_writing.aliases,icon:y.jsx(mo,{size:18}),onItemClick:async()=>{await o.invokeAI({useSelection:!0,userPrompt:"Improve writing",streamToolsProvider:M.html.getStreamToolsProvider({defaultStreamTools:{add:!1,delete:!1,update:!0}})})},size:"small"},{key:"fix_spelling",title:t.ai_default_commands.fix_spelling.title,aliases:t.ai_default_commands.fix_spelling.aliases,icon:y.jsx(yo,{size:18}),onItemClick:async()=>{await o.invokeAI({useSelection:!0,userPrompt:"Fix spelling",streamToolsProvider:M.html.getStreamToolsProvider({defaultStreamTools:{add:!1,delete:!1,update:!0}})})},size:"small"},{key:"translate",title:t.ai_default_commands.translate.title,aliases:t.ai_default_commands.translate.aliases,icon:y.jsx(fo,{size:18}),onItemClick:r=>{r(t.ai_default_commands.translate.prompt_placeholder)},size:"small"},{key:"simplify",title:t.ai_default_commands.simplify.title,aliases:t.ai_default_commands.simplify.aliases,icon:y.jsx(co,{size:18}),onItemClick:async()=>{await o.invokeAI({useSelection:!0,userPrompt:"Simplify",streamToolsProvider:M.html.getStreamToolsProvider({defaultStreamTools:{add:!1,delete:!1,update:!0}})})},size:"small"}]}function ko(e){const t=q(e),o=A(e);return[{key:"accept",title:t.ai_menu.actions.accept.title,aliases:t.ai_menu.actions.accept.aliases,icon:y.jsx(ho,{size:18}),onItemClick:()=>{o.acceptChanges()},size:"small"},{key:"revert",title:t.ai_menu.actions.revert.title,aliases:t.ai_menu.actions.revert.aliases,icon:y.jsx(Fe,{size:18}),onItemClick:()=>{o.rejectChanges()},size:"small"}]}function wo(e){const t=q(e),o=A(e);return[{key:"retry",title:t.ai_menu.actions.retry.title,aliases:t.ai_menu.actions.retry.aliases,icon:y.jsx(go,{size:18}),onItemClick:async()=>{await o.retry()},size:"small"},{key:"cancel",title:t.ai_menu.actions.cancel.title,aliases:t.ai_menu.actions.cancel.aliases,icon:y.jsx(Fe,{size:18}),onItemClick:()=>{o.rejectChanges()},size:"small"}]}function Ye(e,t){return t==="user-input"?e.getSelection()?So(e):bo(e):t==="user-reviewing"?ko(e):t==="error"?wo(e):[]}const Ge=e=>{const t=_.useBlockNoteEditor(),[o,r]=w.useState(""),n=Ze(),s=_.useComponentsContext(),a=A(t),i=Ie.useStore(a.store,d=>d.aiMenuState!=="closed"?d.aiMenuState.status:"closed"),{items:l}=e,c=w.useMemo(()=>{let d=[];return l?d=l(t,i):d=Ye(t,i),d.map(h=>({...h,onItemClick:()=>{h.onItemClick(r)}}))},[l,i,t]),u=w.useCallback(async d=>{await a.invokeAI({userPrompt:d,useSelection:t.getSelection()!==void 0})},[a,t]);w.useEffect(()=>{(i==="user-reviewing"||i==="error")&&r("")},[i]);const m=w.useMemo(()=>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=w.useMemo(()=>{if(i==="thinking"||i==="ai-writing")return y.jsx(s.SuggestionMenu.Loader,{className:"bn-suggestion-menu-loader bn-combobox-right-section"});if(i==="error")return y.jsx("div",{className:"bn-combobox-right-section bn-combobox-error",children:y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"1em",viewBox:"0 -960 960 960",width:"1em",fill:"currentColor",children:y.jsx("path",{d:"M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm0-160q17 0 28.5-11.5T520-480v-160q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640v160q0 17 11.5 28.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"})})})},[s,i]);return y.jsx(We,{onManualPromptSubmit:e.onManualPromptSubmit||u,items:c,promptText:o,onPromptTextChange:r,placeholder:m,disabled:i==="thinking"||i==="ai-writing",icon:y.jsx("div",{className:"bn-combobox-icon",children:y.jsx(pe,{})}),rightSection:p})},Ke=e=>{const t=e.blockID?document.querySelector(`[data-id="${e.blockID}"]`):void 0,o=w.useMemo(()=>t?{getBoundingClientRect:()=>t.getBoundingClientRect(),contextElement:t}:null,[t]),{isMounted:r,ref:n,style:s,getFloatingProps:a,isPositioned:i}=_.useUIElementPositioning(!!t,o,3e3,{canDismiss:{enabled:!0,escapeKey:!0,outsidePress:e.canDismissViaOutsidePress},placement:"bottom",middleware:[te.offset(10),te.size({apply({rects:l,elements:c}){Object.assign(c.floating.style,{width:`${l.reference.width}px`})}})],onOpenChange:e.onOpenChange,whileElementsMounted:(l,c,u)=>te.autoUpdate(l,c,u,{animationFrame:!0}),...e.floatingOptions});return r?y.jsx("div",{ref:n,style:{...s},...a(),children:i&&e.children}):null},xo=e=>{const t=_.useBlockNoteEditor(),o=A(t),r=Ie.useStore(o.store,a=>a.aiMenuState),n=r==="closed"?void 0:r.blockId,s=e.aiMenu||Ge;return y.jsx(Ke,{canDismissViaOutsidePress:r==="closed"||r.status==="user-input",blockID:n,onOpenChange:a=>{a||r==="closed"||(r.status==="user-input"?o.closeAIMenu():(r.status==="user-reviewing"||r.status==="error")&&o.rejectChanges())},children:y.jsx(s,{})})},To=()=>{const e=Ze(),t=_.useComponentsContext(),o=_.useBlockNoteEditor(),r=A(o),n=()=>{o.formattingToolbar.closeMenu();const s=o.getSelection();if(!s)throw new Error("No selection");const a=s.blocks[s.blocks.length-1].id;r.openAIMenuAtBlock(a)};return o.isEditable?y.jsx(t.Generic.Toolbar.Button,{className:"bn-button",label:e.formatting_toolbar.ai.tooltip,mainTooltip:e.formatting_toolbar.ai.tooltip,icon:y.jsx(pe,{}),onClick:n}):null},vo={AI:pe};function Po(e){const t=A(e);return[{key:"ai",onItemClick:()=>{const r=e.getTextCursorPosition();r.block.content&&Array.isArray(r.block.content)&&r.block.content.length===0&&r.prevBlock?t.openAIMenuAtBlock(r.prevBlock.id):t.openAIMenuAtBlock(r.block.id)},...q(e).slash_menu.ai,icon:y.jsx(vo.AI,{})}]}function Xe(e){return Object.fromEntries(Object.entries(e).map(([t,o])=>[t,T.tool({...o,inputSchema:T.jsonSchema(o.inputSchema),outputSchema:T.jsonSchema(o.outputSchema)})]))}function Qe(e,t){let o="";return e.pipeThrough(new TransformStream({start(r){r.enqueue({type:"start"}),r.enqueue({type:"start-step"}),r.enqueue({type:"tool-input-start",toolCallId:"call_object_1",toolName:t})},transform(r,n){switch(r.type){case"text-delta":o+=r.textDelta,n.enqueue({type:"tool-input-delta",toolCallId:"call_object_1",inputTextDelta:r.textDelta});break;case"object":case"finish":break;case"error":n.enqueue({type:"error",errorText:re.getErrorMessage(r.error)});break;default:{const s=r;throw new Error(`Unsupported chunk type: ${s}`)}}},async flush(r){r.enqueue({type:"tool-input-available",toolCallId:"call_object_1",toolName:t,input:JSON.parse(o)}),r.enqueue({type:"finish-step"}),r.enqueue({type:"finish"})}}))}function et(e,t){return new ReadableStream({start(r){r.enqueue({type:"start"}),r.enqueue({type:"start-step"}),r.enqueue({type:"tool-input-start",toolCallId:"call_object_1",toolName:t}),r.enqueue({type:"tool-input-delta",toolCallId:"call_object_1",inputTextDelta:JSON.stringify(e)}),r.enqueue({type:"tool-input-available",toolCallId:"call_object_1",toolName:t,input:e}),r.enqueue({type:"finish-step"}),r.enqueue({type:"finish"}),r.close()}})}const tt={"mistral.chat":{mode:"auto"},"google.generative-ai":{mode:"auto"},"groq.chat":{providerOptions:{groq:{structuredOutputs:!1}}}};function oe(e){return tt[e.provider]||{}}class Co{constructor(t){this.opts=t}async generateObject(t,o){const{model:r,_additionalOptions:n}=this.opts;if(typeof r=="string")throw new Error("model must be a LanguageModelV2");const s=Object.keys(o)[0],a=o[s].inputSchema,i=await T.generateObject({output:"object",schema:a,model:r,mode:"tool",messages:T.convertToModelMessages(t),...oe(r),...n??{}});return et(i.object,s)}async streamObject(t,o){const{model:r,_additionalOptions:n}=this.opts;if(typeof r=="string")throw new Error("model must be a LanguageModelV2");const s=Object.keys(o)[0],a=o[s].inputSchema,i=T.streamObject({output:"object",schema:a,model:r,mode:"tool",messages:T.convertToModelMessages(t),...oe(r),...n??{}});return Qe(i.fullStream,s)}async streamText(t,o){const{model:r,_additionalOptions:n}=this.opts;return T.streamText({model:r,messages:T.convertToModelMessages(t),tools:o,toolChoice:"required",...n??{}}).toUIMessageStream()}async sendMessages({messages:t,body:o}){const r=this.opts.stream??!0,n=o.toolDefinitions,s=Xe(n);if(this.opts.objectGeneration)return r?this.streamObject(t,s):this.generateObject(t,s);if(r)return await this.streamText(t,s);throw new Error("Not implemented (generateText)")}reconnectToStream(){throw new Error("Not implemented")}}exports.AIExtension=de;exports.AIMenu=Ge;exports.AIMenuController=xo;exports.AIToolbarButton=To;exports.BlockPositioner=Ke;exports.ChunkExecutionError=ne;exports.ClientSideTransport=Co;exports.PROVIDER_OVERRIDES=tt;exports.PromptSuggestionMenu=We;exports.StreamToolExecutor=Ee;exports.aiDocumentFormats=M;exports.buildAIRequest=Ne;exports.createAIExtension=eo;exports.createStreamToolsArraySchema=Me;exports.defaultAIRequestSender=Be;exports.executeAIRequest=Le;exports.fetchViaProxy=to;exports.getAIDictionary=q;exports.getAIExtension=A;exports.getAISlashMenuItems=Po;exports.getDefaultAIMenuItems=Ye;exports.getProviderOverrides=oe;exports.objectAsToolCallInUIMessageStream=et;exports.objectStreamToOperationsResult=Ae;exports.partialObjectStreamAsToolCallInUIMessageStream=Qe;exports.promptHelpers=Gt;exports.toolDefinitionsToToolSet=Xe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("@ai-sdk/react"),w=require("@blocknote/core"),v=require("@blocknote/core/extensions"),M=require("@blocknote/prosemirror-suggest-changes"),T=require("prosemirror-model"),P=require("prosemirror-state"),G=require("prosemirror-tables"),_=require("prosemirror-view"),Y=require("y-prosemirror"),l=require("./client-DrruPiJu.cjs"),c=require("react/jsx-runtime"),g=require("@blocknote/react"),p=require("react"),q=require("@floating-ui/react"),J=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},k=J(p),R=new P.PluginKey("blocknote-agent-cursor");function Q(e){return new P.Plugin({key:R,view:t=>({}),state:{init:()=>({selection:void 0}),apply:(t,n)=>{const o=t.getMeta("aiAgent");return o?{selection:o.selection}:{selection:void 0}}},props:{decorations:t=>{const{doc:n}=t,{selection:o}=R.getState(t),s=[];if(!o)return _.DecorationSet.create(n,[]);s.push(_.Decoration.widget(o.head,()=>X(e),{key:"agent-cursor",side:10}));const u=Math.min(o.anchor,o.head),i=Math.max(o.anchor,o.head);return s.push(_.Decoration.inline(u,i,Y.defaultSelectionBuilder(e),{inclusiveEnd:!0,inclusiveStart:!1})),_.DecorationSet.create(n,s)}}})}const X=e=>{const t=document.createElement("span");t.classList.add("bn-collaboration-cursor__base"),t.setAttribute("data-active","true");const n=document.createElement("span");n.setAttribute("contentedEditable","false"),n.classList.add("bn-collaboration-cursor__caret"),n.setAttribute("style",`background-color: ${e.color}`);const o=document.createElement("span");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},ee=new P.PluginKey("blocknote-ai-plugin"),x=w.createExtension(({editor:e,options:t})=>{const n=w.createStore(t??{}),o=w.createStore({aiMenuState:"closed"});let s,u=!1;return{key:"ai",options:n,store:o,mount({signal:i}){let r=!1;document.addEventListener("scroll",()=>{r&&(u=!1),r=!0},{capture:!0,signal:i}),document.addEventListener("scrollend",()=>{r=!1},{capture:!0,signal:i})},prosemirrorPlugins:[new P.Plugin({key:ee,filterTransaction:i=>{var a;const r=o.state.aiMenuState;return!(r!=="closed"&&r.status==="ai-writing"&&(a=i.getMeta(G.fixTablesKey))!=null&&a.fixTables)}}),M.suggestChanges(),Q((t==null?void 0:t.agentCursor)||{name:"AI",color:"#8bc6ff"})],openAIMenuAtBlock(i){var a,m;(a=e.getExtension(v.ShowSelectionExtension))==null||a.showSelection(!0),e.isEditable=!1,o.setState({aiMenuState:{blockId:i,status:"user-input"}});const r=(m=e.domElement)==null?void 0:m.querySelector(`[data-node-type="blockContainer"][data-id="${i}"]`);r==null||r.scrollIntoView({block:"center"})},closeAIMenu(){var i;o.setState({aiMenuState:"closed"}),s=void 0,(i=e.getExtension(v.ShowSelectionExtension))==null||i.showSelection(!1),e.isEditable=!0,e.focus()},acceptChanges(){var r;const i=e.prosemirrorState.doc;e.exec((a,m)=>M.revertSuggestions(a,f=>{m==null||m(f.setMeta("addToHistory",!1))})),e.exec((a,m)=>{const f=a.tr;f.replace(0,f.doc.content.size,new T.Slice(T.Fragment.from(i),0,0));const C=a.apply(f);return M.applySuggestions(C,b=>{m==null||m(f.replace(0,f.doc.content.size,new T.Slice(T.Fragment.from(b.doc),0,0)))})}),(r=e.getExtension(v.ForkYDocExtension))==null||r.merge({keepChanges:!0}),this.closeAIMenu()},rejectChanges(){var i;e.exec((r,a)=>M.revertSuggestions(r,m=>{a==null||a(m.setMeta("addToHistory",!1))})),(i=e.getExtension(v.ForkYDocExtension))==null||i.merge({keepChanges:!1}),this.closeAIMenu()},async abort(i){const{aiMenuState:r}=o.state;if(r==="closed"||!s||r.status!=="thinking"&&r.status!=="ai-writing")return;const a=s.chat;s.abortController.abort(i),await a.stop()},async retry(){const{aiMenuState:i}=o.state;if(i==="closed"||i.status!=="error"||!s)throw new Error("retry() is only valid when a previous response failed");return(s==null?void 0:s.chat.status)==="error"?this.invokeAI({...s.previousRequestOptions,userPrompt:"An error occured in the previous request. Please retry to accomplish the last user prompt."}):this.invokeAI({...s.previousRequestOptions,userPrompt:"An error occured while executing the previous tool call. Please retry to accomplish the last user prompt."})},setAIResponseStatus(i){var a;const r=o.state.aiMenuState;if(r!=="closed")if(i==="ai-writing"&&((a=e.getExtension(v.ShowSelectionExtension))==null||a.showSelection(!1)),typeof i=="object"){if(i.status!=="error")throw new w.UnreachableCaseError(i.status);this.store.setState({aiMenuState:{status:i.status,error:i.error,blockId:r.blockId}})}else this.store.setState({aiMenuState:{status:i,blockId:r.blockId}})},async callLLM(i){return this.invokeAI(i)},async invokeAI(i){var r,a,m,f;this.setAIResponseStatus("thinking"),(r=e.getExtension(v.ForkYDocExtension))==null||r.fork();try{const C=new AbortController;s?(s.previousRequestOptions=i,s.abortController=C):s={previousRequestOptions:i,chat:((a=i.chatProvider)==null?void 0:a.call(i))||((f=(m=this.options.state).chatProvider)==null?void 0:f.call(m))||new $.Chat({sendAutomaticallyWhen:()=>!1,transport:i.transport||this.options.state.transport}),abortController:C};const b=s.chat;i={...n.state,...i};const S=await l.buildAIRequest({editor:e,useSelection:i.useSelection,deleteEmptyCursorBlock:i.deleteEmptyCursorBlock,streamToolsProvider:i.streamToolsProvider??this.options.state.streamToolsProvider,documentStateBuilder:i.documentStateBuilder??this.options.state.documentStateBuilder,onBlockUpdated:y=>{const D=o.state.aiMenuState,O=D==="closed"?void 0:D;if(!O||O.status!=="ai-writing")return;const B=w.getNodeById(y,e.prosemirrorState.doc);B&&(o.setState({aiMenuState:{blockId:y,status:"ai-writing"}}),u&&e.prosemirrorView.domAtPos(B.posBeforeNode+1).node.scrollIntoView({block:"center"}))},onStart:()=>{u=!0,this.setAIResponseStatus("ai-writing"),S.emptyCursorBlockToDelete&&S.editor.getBlock(S.emptyCursorBlockToDelete)&&S.editor.removeBlocks([S.emptyCursorBlockToDelete])}}),d=await l.sendMessageWithAIRequest(b,S,{role:"user",parts:[{type:"text",text:i.userPrompt}]},i.chatRequestOptions||this.options.state.chatRequestOptions,s.abortController.signal);d.ok&&b.status!=="error"||C.signal.aborted?this.setAIResponseStatus("user-reviewing"):(console.warn("Error calling LLM",{result:d,chatStatus:b.status,chatError:b.error}),this.setAIResponseStatus({status:"error",error:d.ok?b.error:d.error}))}catch(C){this.setAIResponseStatus({status:"error",error:C}),console.error("Unexpected error calling LLM",C,s==null?void 0:s.chat.messages)}}}});var Z={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},V=k.default.createContext&&k.default.createContext(Z),te=["attr","size","title"];function oe(e,t){if(e==null)return{};var n=ne(e,t),o,s;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(s=0;s<u.length;s++)o=u[s],!(t.indexOf(o)>=0)&&Object.prototype.propertyIsEnumerable.call(e,o)&&(n[o]=e[o])}return n}function ne(e,t){if(e==null)return{};var n={};for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){if(t.indexOf(o)>=0)continue;n[o]=e[o]}return n}function A(){return A=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},A.apply(this,arguments)}function z(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,o)}return n}function L(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?z(Object(n),!0).forEach(function(o){re(e,o,n[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):z(Object(n)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(n,o))})}return e}function re(e,t,n){return t=ie(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ie(e){var t=se(e,"string");return typeof t=="symbol"?t:t+""}function se(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var o=n.call(e,t);if(typeof o!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function N(e){return e&&e.map((t,n)=>k.default.createElement(t.tag,L({key:n},t.attr),N(t.child)))}function I(e){return t=>k.default.createElement(ae,A({attr:L({},e.attr)},t),N(e.child))}function ae(e){var t=n=>{var{attr:o,size:s,title:u}=e,i=oe(e,te),r=s||n.size||"1em",a;return n.className&&(a=n.className),e.className&&(a=(a?a+" ":"")+e.className),k.default.createElement("svg",A({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,o,i,{className:a,style:L(L({color:e.color||n.color},n.style),e.style),height:r,width:r,xmlns:"http://www.w3.org/2000/svg"}),u&&k.default.createElement("title",null,u),e.children)};return V!==void 0?k.default.createElement(V.Consumer,null,n=>t(n)):t(Z)}function F(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M8 7V11L2 6L8 1V5H13C17.4183 5 21 8.58172 21 13C21 17.4183 17.4183 21 13 21H4V19H13C16.3137 19 19 16.3137 19 13C19 9.68629 16.3137 7 13 7H8Z"},child:[]}]})(e)}function H(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M17.8492 11.6983L17.1421 10.9912L7.24264 20.8907H3V16.648L14.3137 5.33432L19.9706 10.9912C20.3611 11.3817 20.3611 12.0149 19.9706 12.4054L12.8995 19.4765L11.4853 18.0622L17.8492 11.6983ZM15.7279 9.57696L14.3137 8.16274L5 17.4765V18.8907H6.41421L15.7279 9.57696ZM18.5563 2.50589L21.3848 5.33432C21.7753 5.72484 21.7753 6.35801 21.3848 6.74853L19.9706 8.16274L15.7279 3.9201L17.1421 2.50589C17.5327 2.11537 18.1658 2.11537 18.5563 2.50589Z"},child:[]}]})(e)}function le(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M15.1986 9.94447C14.7649 9.5337 14.4859 8.98613 14.4085 8.39384L14.0056 5.31138L11.275 6.79724C10.7503 7.08274 10.1433 7.17888 9.55608 7.06948L6.49998 6.50015L7.06931 9.55625C7.17871 10.1435 7.08257 10.7505 6.79707 11.2751L5.31121 14.0057L8.39367 14.4086C8.98596 14.4861 9.53353 14.7651 9.94431 15.1987L12.0821 17.4557L13.4178 14.6486C13.6745 14.1092 14.109 13.6747 14.6484 13.418L17.4555 12.0823L15.1986 9.94447ZM15.2238 15.5079L13.0111 20.1581C12.8687 20.4573 12.5107 20.5844 12.2115 20.442C12.1448 20.4103 12.0845 20.3665 12.0337 20.3129L8.49229 16.5741C8.39749 16.474 8.27113 16.4096 8.13445 16.3918L3.02816 15.7243C2.69958 15.6814 2.46804 15.3802 2.51099 15.0516C2.52056 14.9784 2.54359 14.9075 2.5789 14.8426L5.04031 10.3192C5.1062 10.1981 5.12839 10.058 5.10314 9.92253L4.16 4.85991C4.09931 4.53414 4.3142 4.22086 4.63997 4.16017C4.7126 4.14664 4.78711 4.14664 4.85974 4.16017L9.92237 5.10331C10.0579 5.12855 10.198 5.10637 10.319 5.04048L14.8424 2.57907C15.1335 2.42068 15.4979 2.52825 15.6562 2.81931C15.6916 2.88421 15.7146 2.95507 15.7241 3.02833L16.3916 8.13462C16.4095 8.2713 16.4739 8.39766 16.5739 8.49245L20.3127 12.0338C20.5533 12.2617 20.5636 12.6415 20.3357 12.8821C20.2849 12.9357 20.2246 12.9795 20.1579 13.0112L15.5078 15.224C15.3833 15.2832 15.283 15.3835 15.2238 15.5079ZM16.0206 17.435L17.4348 16.0208L21.6775 20.2634L20.2633 21.6776L16.0206 17.435Z"},child:[]}]})(e)}function ce(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M8.00008 6V9H5.00008V6H8.00008ZM3.00008 4V11H10.0001V4H3.00008ZM13.0001 4H21.0001V6H13.0001V4ZM13.0001 11H21.0001V13H13.0001V11ZM13.0001 18H21.0001V20H13.0001V18ZM10.7072 16.2071L9.29297 14.7929L6.00008 18.0858L4.20718 16.2929L2.79297 17.7071L6.00008 20.9142L10.7072 16.2071Z"},child:[]}]})(e)}function ue(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M15 18H16.5C17.8807 18 19 16.8807 19 15.5C19 14.1193 17.8807 13 16.5 13H3V11H16.5C18.9853 11 21 13.0147 21 15.5C21 17.9853 18.9853 20 16.5 20H15V22L11 19L15 16V18ZM3 4H21V6H3V4ZM9 18V20H3V18H9Z"},child:[]}]})(e)}function me(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M13 6V21H11V6H5V4H19V6H13Z"},child:[]}]})(e)}function de(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M6.23509 6.45329C4.85101 7.89148 4 9.84636 4 12C4 16.4183 7.58172 20 12 20C13.0808 20 14.1116 19.7857 15.0521 19.3972C15.1671 18.6467 14.9148 17.9266 14.8116 17.6746C14.582 17.115 13.8241 16.1582 12.5589 14.8308C12.2212 14.4758 12.2429 14.2035 12.3636 13.3943L12.3775 13.3029C12.4595 12.7486 12.5971 12.4209 14.4622 12.1248C15.4097 11.9746 15.6589 12.3533 16.0043 12.8777C16.0425 12.9358 16.0807 12.9928 16.1198 13.0499C16.4479 13.5297 16.691 13.6394 17.0582 13.8064C17.2227 13.881 17.428 13.9751 17.7031 14.1314C18.3551 14.504 18.3551 14.9247 18.3551 15.8472V15.9518C18.3551 16.3434 18.3168 16.6872 18.2566 16.9859C19.3478 15.6185 20 13.8854 20 12C20 8.70089 18.003 5.8682 15.1519 4.64482C14.5987 5.01813 13.8398 5.54726 13.575 5.91C13.4396 6.09538 13.2482 7.04166 12.6257 7.11976C12.4626 7.14023 12.2438 7.12589 12.012 7.11097C11.3905 7.07058 10.5402 7.01606 10.268 7.75495C10.0952 8.2232 10.0648 9.49445 10.6239 10.1543C10.7134 10.2597 10.7307 10.4547 10.6699 10.6735C10.59 10.9608 10.4286 11.1356 10.3783 11.1717C10.2819 11.1163 10.0896 10.8931 9.95938 10.7412C9.64554 10.3765 9.25405 9.92233 8.74797 9.78176C8.56395 9.73083 8.36166 9.68867 8.16548 9.64736C7.6164 9.53227 6.99443 9.40134 6.84992 9.09302C6.74442 8.8672 6.74488 8.55621 6.74529 8.22764C6.74529 7.8112 6.74529 7.34029 6.54129 6.88256C6.46246 6.70541 6.35689 6.56446 6.23509 6.45329ZM12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22Z"},child:[]}]})(e)}function fe(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M9.9997 15.1709L19.1921 5.97852L20.6063 7.39273L9.9997 17.9993L3.63574 11.6354L5.04996 10.2212L9.9997 15.1709Z"},child:[]}]})(e)}function ge(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M9.9997 15.1709L19.1921 5.97852L20.6063 7.39273L9.9997 17.9993L3.63574 11.6354L5.04996 10.2212L9.9997 15.1709Z"},child:[]}]})(e)}function pe(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M12 4C9.4095 4 7.10606 5.23053 5.64274 7.14274L8 9.5H2V3.5L4.21863 5.71863C6.05061 3.452 8.85558 2 12 2 17.5228 2 22 6.47715 22 12H20C20 7.58172 16.4183 4 12 4ZM4 12C4 16.4183 7.58172 20 12 20 14.5905 20 16.894 18.7695 18.3573 16.8573L16 14.5 22 14.5V20.5L19.7814 18.2814C17.9494 20.548 15.1444 22 12 22 6.47715 22 2 17.5228 2 12H4Z"},child:[]}]})(e)}function E(e){return I({attr:{viewBox:"0 0 24 24",fill:"currentColor"},child:[{tag:"path",attr:{d:"M17.0007 1.20825 18.3195 3.68108 20.7923 4.99992 18.3195 6.31876 17.0007 8.79159 15.6818 6.31876 13.209 4.99992 15.6818 3.68108 17.0007 1.20825ZM8.00065 4.33325 10.6673 9.33325 15.6673 11.9999 10.6673 14.6666 8.00065 19.6666 5.33398 14.6666.333984 11.9999 5.33398 9.33325 8.00065 4.33325ZM19.6673 16.3333 18.0007 13.2083 16.334 16.3333 13.209 17.9999 16.334 19.6666 18.0007 22.7916 19.6673 19.6666 22.7923 17.9999 19.6673 16.3333Z"},child:[]}]})(e)}function j(){const e=g.useBlockNoteContext();return l.getAIDictionary(e.editor)}const U=e=>{const t=g.useComponentsContext(),{onManualPromptSubmit:n,promptText:o,onPromptTextChange:s}=e,[u,i]=p.useState(""),r=o||u,a=p.useCallback(async d=>{d.key==="Enter"&&n(r)},[r,n]),m=p.useCallback(d=>{const y=d.currentTarget.value;s&&s(y),o===void 0&&i(y)},[s,i,o]),f=p.useMemo(()=>v.filterSuggestionItems(e.items,r),[r,e.items]),{selectedIndex:C,setSelectedIndex:b,handler:h}=g.useSuggestionMenuKeyboardHandler(f,d=>d.onItemClick()),S=p.useCallback(d=>{d.key==="Enter"?f.length>0?h(d):a(d):h(d)},[a,h,f.length]);return p.useEffect(()=>{b(0)},[r,b]),c.jsxs("div",{className:"bn-combobox",children:[c.jsx(t.Generic.Form.Root,{children:c.jsx(t.Generic.Form.TextInput,{className:"bn-combobox-input",name:"ai-prompt",variant:"large",icon:e.icon,value:r||"",autoFocus:!0,placeholder:e.placeholder,disabled:e.disabled,onKeyDown:S,onChange:m,autoComplete:"off",rightSection:e.rightSection},"input-"+e.disabled)}),c.jsx(t.SuggestionMenu.Root,{className:"bn-combobox-items",id:"ai-suggestion-menu",children:f.map((d,y)=>c.jsx(t.SuggestionMenu.Item,{className:w.mergeCSSClasses("bn-suggestion-menu-item",d.size==="small"?"bn-suggestion-menu-item-small":""),id:`bn-suggestion-menu-item-${y}`,isSelected:y===C,onClick:d.onItemClick,item:d},d.title))})]})};function he(e){const t=l.getAIDictionary(e),n=e.getExtension(x);return n?[{key:"continue_writing",title:t.ai_default_commands.continue_writing.title,aliases:t.ai_default_commands.continue_writing.aliases,icon:c.jsx(H,{size:18}),onItemClick:async()=>{await n.invokeAI({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.",streamToolsProvider:l.aiDocumentFormats.html.getStreamToolsProvider({defaultStreamTools:{add:!0,delete:!1,update:!1}})})},size:"small"},{key:"summarize",title:t.ai_default_commands.summarize.title,aliases:t.ai_default_commands.summarize.aliases,icon:c.jsx(ue,{size:18}),onItemClick:async()=>{await n.invokeAI({userPrompt:"Summarize",streamToolsProvider:l.aiDocumentFormats.html.getStreamToolsProvider({defaultStreamTools:{add:!0,delete:!1,update:!1}})})},size:"small"},{key:"action_items",title:t.ai_default_commands.add_action_items.title,aliases:t.ai_default_commands.add_action_items.aliases,icon:c.jsx(ce,{size:18}),onItemClick:async()=>{await n.invokeAI({userPrompt:"Add action items",streamToolsProvider:l.aiDocumentFormats.html.getStreamToolsProvider({defaultStreamTools:{add:!0,delete:!1,update:!1}})})},size:"small"},{key:"write_anything",title:t.ai_default_commands.write_anything.title,aliases:t.ai_default_commands.write_anything.aliases,icon:c.jsx(H,{size:18}),onItemClick:o=>{o(t.ai_default_commands.write_anything.prompt_placeholder)},size:"small"}]:[]}function Ce(e){const t=l.getAIDictionary(e),n=e.getExtension(x);return n?[{key:"improve_writing",title:t.ai_default_commands.improve_writing.title,aliases:t.ai_default_commands.improve_writing.aliases,icon:c.jsx(me,{size:18}),onItemClick:async()=>{await n.invokeAI({useSelection:!0,userPrompt:"Improve writing",streamToolsProvider:l.aiDocumentFormats.html.getStreamToolsProvider({defaultStreamTools:{add:!1,delete:!1,update:!0}})})},size:"small"},{key:"fix_spelling",title:t.ai_default_commands.fix_spelling.title,aliases:t.ai_default_commands.fix_spelling.aliases,icon:c.jsx(ge,{size:18}),onItemClick:async()=>{await n.invokeAI({useSelection:!0,userPrompt:"Fix spelling",streamToolsProvider:l.aiDocumentFormats.html.getStreamToolsProvider({defaultStreamTools:{add:!1,delete:!1,update:!0}})})},size:"small"},{key:"translate",title:t.ai_default_commands.translate.title,aliases:t.ai_default_commands.translate.aliases,icon:c.jsx(de,{size:18}),onItemClick:o=>{o(t.ai_default_commands.translate.prompt_placeholder)},size:"small"},{key:"simplify",title:t.ai_default_commands.simplify.title,aliases:t.ai_default_commands.simplify.aliases,icon:c.jsx(le,{size:18}),onItemClick:async()=>{await n.invokeAI({useSelection:!0,userPrompt:"Simplify",streamToolsProvider:l.aiDocumentFormats.html.getStreamToolsProvider({defaultStreamTools:{add:!1,delete:!1,update:!0}})})},size:"small"}]:[]}function be(e){const t=l.getAIDictionary(e),n=e.getExtension(x);return n?[{key:"accept",title:t.ai_menu.actions.accept.title,aliases:t.ai_menu.actions.accept.aliases,icon:c.jsx(fe,{size:18}),onItemClick:()=>{n.acceptChanges()},size:"small"},{key:"revert",title:t.ai_menu.actions.revert.title,aliases:t.ai_menu.actions.revert.aliases,icon:c.jsx(F,{size:18}),onItemClick:()=>{n.rejectChanges()},size:"small"}]:[]}function Se(e){const t=l.getAIDictionary(e),n=e.getExtension(x);return n?[{key:"retry",title:t.ai_menu.actions.retry.title,aliases:t.ai_menu.actions.retry.aliases,icon:c.jsx(pe,{size:18}),onItemClick:async()=>{await n.retry()},size:"small"},{key:"cancel",title:t.ai_menu.actions.cancel.title,aliases:t.ai_menu.actions.cancel.aliases,icon:c.jsx(F,{size:18}),onItemClick:()=>{n.rejectChanges()},size:"small"}]:[]}function W(e,t){return t==="user-input"?e.getSelection()?Ce(e):he(e):t==="user-reviewing"?be(e):t==="error"?Se(e):[]}const K=e=>{const t=g.useBlockNoteEditor(),[n,o]=p.useState(""),s=j(),u=g.useComponentsContext(),i=g.useExtension(x),r=g.useExtensionState(x,{selector:h=>h.aiMenuState!=="closed"?h.aiMenuState.status:"closed"}),{items:a}=e,m=p.useMemo(()=>{let h=[];return a?h=a(t,r):h=W(t,r),h.map(S=>({...S,onItemClick:()=>{S.onItemClick(o)}}))},[a,r,t]),f=p.useCallback(async h=>{await i.invokeAI({userPrompt:h,useSelection:t.getSelection()!==void 0})},[i,t]);p.useEffect(()=>{(r==="ai-writing"||r==="user-reviewing"||r==="error")&&o("")},[r]);const C=p.useMemo(()=>r==="thinking"?s.ai_menu.status.thinking:r==="ai-writing"?s.ai_menu.status.editing:r==="error"?s.ai_menu.status.error:s.ai_menu.input_placeholder,[r,s]),b=p.useMemo(()=>{if(r==="thinking"||r==="ai-writing")return c.jsx(u.SuggestionMenu.Loader,{className:"bn-suggestion-menu-loader bn-combobox-right-section"});if(r==="error")return c.jsx("div",{className:"bn-combobox-right-section bn-combobox-error",children:c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"1em",viewBox:"0 -960 960 960",width:"1em",fill:"currentColor",children:c.jsx("path",{d:"M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm0-160q17 0 28.5-11.5T520-480v-160q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640v160q0 17 11.5 28.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"})})})},[u,r]);return c.jsx(U,{onManualPromptSubmit:e.onManualPromptSubmit||f,items:m,promptText:n,onPromptTextChange:o,placeholder:C,disabled:r==="thinking"||r==="ai-writing",icon:c.jsx("div",{className:"bn-combobox-icon",children:c.jsx(E,{})}),rightSection:b})},xe=e=>{const t=g.useBlockNoteEditor(),n=g.useExtension(x),o=g.useExtensionState(x,{editor:t,selector:r=>r.aiMenuState}),s=o==="closed"?void 0:o.blockId,u=p.useMemo(()=>({useFloatingOptions:{open:o!=="closed",placement:"bottom",middleware:[q.offset(10),q.size({apply({rects:r,elements:a}){Object.assign(a.floating.style,{width:`${r.reference.width}px`})}})],onOpenChange:r=>{r||o==="closed"||(o.status==="user-input"?n.closeAIMenu():(o.status==="user-reviewing"||o.status==="error")&&n.rejectChanges())}},useDismissProps:{enabled:o==="closed"||o.status==="user-input",outsidePress:r=>{if(r.target instanceof Element){const a=r.target.closest(".bn-block");a&&a.getAttribute("data-id")===s&&n.closeAIMenu()}return!0}},elementProps:{style:{zIndex:100}},...e.floatingUIOptions}),[n,o,s,e.floatingUIOptions]),i=e.aiMenu||K;return c.jsx(g.BlockPopover,{blockId:s,...u,children:o!=="closed"&&c.jsx(i,{})})},Ie=()=>{const e=j(),t=g.useComponentsContext(),n=g.useBlockNoteEditor(),o=g.useExtension(x),s=g.useExtension(v.FormattingToolbarExtension),u=()=>{const i=n.getSelection();if(!i)throw new Error("No selection");const r=i.blocks[i.blocks.length-1].id;o.openAIMenuAtBlock(r),s.store.setState(!1)};return n.isEditable?c.jsx(t.Generic.Toolbar.Button,{className:"bn-button",label:e.formatting_toolbar.ai.tooltip,mainTooltip:e.formatting_toolbar.ai.tooltip,icon:c.jsx(E,{}),onClick:u}):null},ye={AI:E};function ve(e){const t=e.getExtension(x);return t?[{key:"ai",onItemClick:()=>{const o=e.getTextCursorPosition();o.block.content&&Array.isArray(o.block.content)&&o.block.content.length===0&&o.prevBlock?t.openAIMenuAtBlock(o.prevBlock.id):t.openAIMenuAtBlock(o.block.id)},...l.getAIDictionary(e).slash_menu.ai,icon:c.jsx(ye.AI,{})}]:[]}exports.ClientSideTransport=l.ClientSideTransport;exports.PROVIDER_OVERRIDES=l.PROVIDER_OVERRIDES;exports.StreamToolExecutor=l.StreamToolExecutor;exports._getApplySuggestionsTr=l.getApplySuggestionsTr;exports.aiDocumentFormats=l.aiDocumentFormats;exports.buildAIRequest=l.buildAIRequest;exports.createStreamToolsArraySchema=l.createStreamToolsArraySchema;exports.fetchViaProxy=l.fetchViaProxy;exports.getAIDictionary=l.getAIDictionary;exports.getProviderOverrides=l.getProviderOverrides;exports.injectDocumentStateMessages=l.injectDocumentStateMessages;exports.makeDocumentStateBuilder=l.makeDocumentStateBuilder;exports.objectAsToolCallInUIMessageStream=l.objectAsToolCallInUIMessageStream;exports.objectStreamToOperationsResult=l.objectStreamToOperationsResult;exports.partialObjectStreamAsToolCallInUIMessageStream=l.partialObjectStreamAsToolCallInUIMessageStream;exports.promptHelpers=l.promptHelpers;exports.sendMessageWithAIRequest=l.sendMessageWithAIRequest;exports.setupToolCallStreaming=l.setupToolCallStreaming;exports.streamToolsToToolSet=l.streamToolsToToolSet;exports.toolDefinitionsToToolSet=l.toolDefinitionsToToolSet;exports.toolSetToToolDefinitions=l.toolSetToToolDefinitions;exports.AIExtension=x;exports.AIMenu=K;exports.AIMenuController=xe;exports.AIToolbarButton=Ie;exports.PromptSuggestionMenu=U;exports.getAISlashMenuItems=ve;exports.getDefaultAIMenuItems=W;exports.useAIDictionary=j;
|
|
10
2
|
//# sourceMappingURL=blocknote-xl-ai.cjs.map
|