@blocknote/xl-ai 0.47.3 → 0.48.1
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 +2 -2
- package/dist/blocknote-xl-ai.cjs.map +1 -1
- package/dist/blocknote-xl-ai.js +573 -925
- package/dist/blocknote-xl-ai.js.map +1 -1
- package/dist/locales.cjs +2 -2
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +1593 -1486
- package/dist/locales.js.map +1 -1
- package/dist/server-Ct45EOTu.cjs +36 -0
- package/dist/server-Ct45EOTu.cjs.map +1 -0
- package/dist/server-JIYg7ELG.js +1630 -0
- package/dist/server-JIYg7ELG.js.map +1 -0
- package/dist/server.cjs +1 -2
- package/dist/server.js +3 -23
- package/dist/style.css +2 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +13 -13
- package/src/api/formats/tests/sharedTestCases.ts +3 -3
- package/src/prosemirror/changeset.ts +8 -2
- package/src/prosemirror/rebaseTool.ts +1 -1
- package/dist/client-BPNTLm1-.cjs +0 -36
- package/dist/client-BPNTLm1-.cjs.map +0 -1
- package/dist/client-DHVeP6Er.js +0 -2149
- package/dist/client-DHVeP6Er.js.map +0 -1
- package/dist/server.cjs.map +0 -1
- package/dist/server.js.map +0 -1
- /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 → Add heading (h1) and code block_1_144961d511efe7e04c44ff79ecabf43e.json} +0 -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 → add a list (end)_1_ca20c0b56ff3bdfe67f76b3e1b3c82bc.json} +0 -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 → add a new paragraph (empty doc)_1_509f796014e0dae8a4a50e1aaab8a378.json} +0 -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 → add a new paragraph (end)_1_f4419c510915474907ca2fb35f92d2b8.json} +0 -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 → add a new paragraph (start)_1_3426f436a5b272f3b8e26edcec43fdae.json} +0 -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 → Add heading (h1) and code block_1_3f0b847de3745c61a82e3a9728770d4d.json} +0 -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 → add a list (end)_1_680d0a41316e174365d11814e9df7fda.json} +0 -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 → add a new paragraph (empty doc)_1_3f2fffcfa733575ca2a6c4f9d1a8f615.json} +0 -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 → add a new paragraph (end)_1_04b2bff7b39bfda09c5d3f116cbb53b9.json} +0 -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 → add a new paragraph (start)_1_45ec5a1e5fa6757f02843c8803e7a334.json} +0 -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_a10f3f8e8e6d938c54950352eae2f50f.json → Add heading (h1) and code block_1_ece60088a9ecb6767d83b6584bbec6d9.json} +0 -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_b0a300b9716085d9bfa169d8085d10b7.json → add a list (end)_1_64e60c0c2add32fbfe1da823b8c7990a.json} +0 -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_9d4f54665e392006af18af614d32e632.json → add a new paragraph (empty doc)_1_100f09592ece8a32c33dff2dc612c649.json} +0 -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_d862f2761b7f6594f4b571c7f8291820.json → add a new paragraph (end)_1_a2a9884926fbc5218a3f00c9952cefd5.json} +0 -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_94759353bbdb9e30152eb0164488ba89.json → add a new paragraph (start)_1_c85bbb5cec5410289d652e15b2df6fa3.json} +0 -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 → add and update paragraph_1_380a0c02b5089b38247457135c044cf7.json} +0 -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_ed2eea810db5ab73a8478e981735f2a6.json → add paragraph and update selection_1_298b51bb28c5f95ab9a00205d4e38460.json} +0 -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 → add and update paragraph_1_f6253c11196abdbeae0f898cc9df85eb.json} +0 -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_9d907341d7a5b18529ccaf20cacbbe6f.json → add paragraph and update selection_1_dc29d735348684d1ec3e290ad8c03a71.json} +0 -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_a562a7fd96440f9bfac43e04c1bf144a.json → add and update paragraph_1_a27ae10badcc3913a00eb86f77ac64db.json} +0 -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_6bb242aace6ad9ae71bcb369ce8208d4.json → add paragraph and update selection_1_86f10ca461ee44e74ae571fb9f214338.json} +0 -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 → delete first block_1_91346200727a71ab9ad8c5d014835688.json} +0 -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 → delete first block_1_150a539024aa981c9f6bcb068875a6c9.json} +0 -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_f51e5c59768fde7bccc5635d90890452.json → delete first block_1_1b3c4ac85d448677697457098332ceba.json} +0 -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 → clear block formatting_1_fc858b37cc10ed7b65802375977eaf7a.json} +0 -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 → drop mark and link and change text within mark_1_fe3cac9da9d1e17a20ee8c0c4380d925.json} +0 -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 → drop mark and link_1_f6ee881e6d3b4cd9553256523e67683a.json} +0 -0
- /package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/anthropic.messages/claude-3-7-sonnet-latest (streaming)/{fix spelling mid-word selection_1_ce6692c22eda2a757e123681118a333d.json → fix spelling mid-word selection_1_360f2cf4db48ef5b92c8e24ed0998167.json} +0 -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 → modify nested content_1_a57d7364de9ba3d72686aca4f3c424e4.json} +0 -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 → modify parent content_1_5f7043c9275e742ea47f92b66e65a845.json} +0 -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 → plain source block, add mention_1_ccd752aefdbc2252a5a09bebac393afb.json} +0 -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 → standard update_1_c44a31a1631a3a10efcd5e17645998f1.json} +0 -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 → styles + ic in source block, remove mark_1_df177a6a4f26b0fbcba307c6d21cab76.json} +0 -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 → styles + ic in source block, remove mention_1_4ba9f3411694f807e85e8e33f4b3c8cd.json} +0 -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 → styles + ic in source block, replace content_1_f5b001d0f8415a00e8b043f3e3e33535.json} +0 -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 → styles + ic in source block, update mention prop_1_c197e3f5ce1dbc1a68765acbd198881a.json} +0 -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 → styles + ic in source block, update text_1_a0b93418bb2a5c0049e0a5c896f72191.json} +0 -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 → styles + ic in target block, add mark (paragraph)_1_fb2285b8d362cb8adcf78f6039ad3058.json} +0 -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 → styles + ic in target block, add mark (word)_1_e0087b91327576eaff9f8d4d368e0a03.json} +0 -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_1ad7d1a857e525e2d0f5a8c85b645a0e.json → translate selection_1_4706b49daa5ad7afe9dfadded2e335c5.json} +0 -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 → turn paragraphs into list_1_a3ce79b4f32d1dd6ac04dbe6b69e187b.json} +0 -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 → update block prop and content_1_5bb684c9ae46815b5367a39bd42d5257.json} +0 -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 → update block prop_1_8469a78802d46f3d9ec74dd1fbf49fd8.json} +0 -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 → update block type and content_1_226cc5d7352c8c7e58a15d064543518c.json} +0 -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 → update block type_1_c4cc00889532e0baa73998da5e79c303.json} +0 -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 → clear block formatting_1_6c08229db90214b8a20b0d7dfefb2824.json} +0 -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 → drop mark and link and change text within mark_1_e5c77f0f881e77f6ee27a25f203ffdcb.json} +0 -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 → drop mark and link_1_b93576392cb38dc57acd85f7fc55c6cd.json} +0 -0
- /package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/groq.chat/llama-3.3-70b-versatile (streaming)/{fix spelling mid-word selection_1_8c47595610a6a2d15e1c5c751528e97a.json → fix spelling mid-word selection_1_9c19d479f2d356a48480d5ec5e384229.json} +0 -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 → modify nested content_1_f42fc26924afc557d18ef6696f36a8fa.json} +0 -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 → modify parent content_1_e8424752b43fa146d8575a475924de52.json} +0 -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 → plain source block, add mention_1_b18afae076d7f7f423477f1e1bc5813a.json} +0 -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 → standard update_1_529e09ae665507a31316cb632f5cabcd.json} +0 -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 → styles + ic in source block, remove mark_1_20036398e12cf4a20b50024ad5f30018.json} +0 -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 → styles + ic in source block, remove mention_1_ed131f0383e7709a4e5fae2df28af29a.json} +0 -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 → styles + ic in source block, replace content_1_51bfdc443e43bbf18599fcc3a16c5683.json} +0 -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 → styles + ic in source block, update mention prop_1_7641f5691799d2666855c113b6659b71.json} +0 -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 → styles + ic in source block, update text_1_8fcb24a91437026c480205de77507871.json} +0 -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 → styles + ic in target block, add mark (paragraph)_1_be126322b804c53145dbd35a6aa1131f.json} +0 -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 → styles + ic in target block, add mark (word)_1_ec13a3b1d4f97b79148833b507295ffa.json} +0 -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_59b3c2f2328276dc62dad98af951d63c.json → translate selection_1_f1a2ffb178b441d40625b8f110e3290f.json} +0 -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 → turn paragraphs into list_1_8367ba81813ffe9d2d17f2de266f3039.json} +0 -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 → update block prop and content_1_8557c5a4249c324adfff5d243645e3de.json} +0 -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 → update block prop_1_16dda1caa1f43ab624eb28a605179dd3.json} +0 -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 → update block type and content_1_8b167672c96bf3c69b9b146eb4f26451.json} +0 -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 → update block type_1_7326b3d0db43c8f399aba2bc44c80194.json} +0 -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_21bbf793e092bd207656f933b2274b21.json → clear block formatting_1_651c2e0b4f940c6cece61513462d2ddd.json} +0 -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_70261ec295eec99f6b835af3371749ef.json → drop mark and link and change text within mark_1_94f36faff958747b5d66a185e268bba7.json} +0 -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_45e52fc97822fb0e7573a6603137ab4e.json → drop mark and link_1_60bf97139612cd25b1f99502383df8aa.json} +0 -0
- /package/src/api/formats/html-blocks/__snapshots__/htmlBlocks.test.ts/Update/__msw_snapshots__/openai.responses/gpt-4o-2024-08-06 (streaming)/{fix spelling mid-word selection_1_74934d888aa5deba8c74b66c12d81443.json → fix spelling mid-word selection_1_db44da41b500c6883e215f2b6d013f58.json} +0 -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_bfd4f73138b34375f33d28b5ee48d971.json → modify nested content_1_f3a35d9120c6ff0e02a89548d8349363.json} +0 -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_df8380600ae416c0eb70034e41b59701.json → modify parent content_1_7205cf7ec3d86e8ebd9c555028c5db74.json} +0 -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_4579057dabcbe2f9f73c9a329a99393d.json → plain source block, add mention_1_d5759fe9868f60a47538d31361c68b3c.json} +0 -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_ede2a6f5b9da689056b55d71d91434fe.json → standard update_1_f6a167a6ea376d70d84dd9aac6ac7bb3.json} +0 -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_a6d8c670d163bd0cf79a424c6a6054a0.json → styles + ic in source block, remove mark_1_990c696cfe9af87de056328060fd1f93.json} +0 -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_ea57e8c6df3c134fa91348e7b71e7a57.json → styles + ic in source block, remove mention_1_fd4deb4dce4d79ae14939fda71c510fd.json} +0 -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_24429e5416bc371492edd73611cf3946.json → styles + ic in source block, replace content_1_6cd810cd03bff509578637fe27d13a92.json} +0 -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_079714c774da28b17075269c1cdd1696.json → styles + ic in source block, update mention prop_1_f0e30d1d6cbc94e6b7dcb8abb7e0221f.json} +0 -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_e0d8184c9829e07f8df2860248818bc8.json → styles + ic in source block, update text_1_1104dff815f18f8f786fb7d4e4522d47.json} +0 -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_6b7d5cf6029aa5db5a9aaad9264795f8.json → styles + ic in target block, add mark (paragraph)_1_e2f4cdb3df42b17c74cd1d2d00d2f8d5.json} +0 -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_ffc7b82f1fb9de2ffacf16dda33c09eb.json → styles + ic in target block, add mark (word)_1_6b5073ce92485be7974a344d50247b4a.json} +0 -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_b8200b55589e761efded3c08e8709a53.json → translate selection_1_d343e10867cc7b3d9850847c99826b61.json} +0 -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_30410f1a45a0de453f68c27fa57dded9.json → turn paragraphs into list_1_3373025fd96315ed15342f3a3a727771.json} +0 -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_2184f0d7adf54cebd8f2068b93783d8b.json → update block prop and content_1_780bfe04d42dd48e9115cba7c4582c01.json} +0 -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_56a595216306ecbe9557436eabd778b1.json → update block prop_1_667c03220ba6e678d0c91b9de092484b.json} +0 -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_894e0e3aa3fe005922264627bab288ea.json → update block type and content_1_f3c6521f6f12dc50dc16d0bbc277a858.json} +0 -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_0bf2510ac3023bb1a62d991c85655cba.json → update block type_1_7c4fbdcabcec0568ade27d2b47afbaab.json} +0 -0
|
@@ -0,0 +1,1630 @@
|
|
|
1
|
+
import { UnreachableCaseError as e, defaultProps as t, getBlock as n, getNodeById as r, getPmSchema as i, insertBlocks as a, isLinkInlineContent as o, isStyledTextInlineContent as s, removeAndInsertBlocks as c, trackPosition as l, updateBlockTr as u } from "@blocknote/core";
|
|
2
|
+
import { applySuggestions as d } from "@handlewithcare/prosemirror-suggest-changes";
|
|
3
|
+
import { Slice as f } from "prosemirror-model";
|
|
4
|
+
import { TextSelection as p } from "prosemirror-state";
|
|
5
|
+
import m from "lodash.merge";
|
|
6
|
+
import { asSchema as h, convertToModelMessages as g, isToolUIPart as _, jsonSchema as v, parsePartialJson as y, streamText as ee, tool as te } from "ai";
|
|
7
|
+
import ne from "lodash.isequal";
|
|
8
|
+
import { getErrorMessage as b } from "@ai-sdk/provider-utils";
|
|
9
|
+
import { Mapping as re, ReplaceAroundStep as ie, ReplaceStep as x, Transform as S } from "prosemirror-transform";
|
|
10
|
+
import { ChangeSet as C, simplifyChanges as ae } from "prosemirror-changeset";
|
|
11
|
+
//#region src/util/emptyBlock.ts
|
|
12
|
+
function w(e) {
|
|
13
|
+
return (e.type === "paragraph" || !e.type) && !e.content || Array.isArray(e.content) && e.content.length === 0;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/util/trimArray.ts
|
|
17
|
+
function oe(e, t, n = !0, r = !0) {
|
|
18
|
+
let i = 0, a = e.length;
|
|
19
|
+
if (n) for (; i < a && t(e[i]);) i++;
|
|
20
|
+
if (r) for (; a > i && t(e[a - 1]);) a--;
|
|
21
|
+
return e.slice(i, a);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/api/promptHelpers/trimEmptyBlocks.ts
|
|
25
|
+
function T(e, t) {
|
|
26
|
+
return oe(e, (e) => w(e) && t?.cursorBlockId !== e.id, t?.trimStart ?? !1, t?.trimEnd ?? !0);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/api/aiRequest/builder.ts
|
|
30
|
+
async function se(e) {
|
|
31
|
+
let { useSelection: t, deleteEmptyCursorBlock: n, streamToolsProvider: r, documentStateBuilder: i, onStart: a } = {
|
|
32
|
+
useSelection: e.useSelection ?? !1,
|
|
33
|
+
deleteEmptyCursorBlock: e.deleteEmptyCursorBlock ?? !0,
|
|
34
|
+
streamToolsProvider: e.streamToolsProvider ?? $.html.getStreamToolsProvider(),
|
|
35
|
+
documentStateBuilder: e.documentStateBuilder ?? $.html.defaultDocumentStateBuilder,
|
|
36
|
+
onStart: e.onStart ?? (() => {})
|
|
37
|
+
}, o = t ? void 0 : e.editor.getTextCursorPosition().block, s = o && n && w(o) && T(e.editor.document).length > 0 ? o.id : void 0, c = t ? e.editor.getSelectionCutBlocks(!0) : void 0, l = r.getStreamTools(e.editor, c ? {
|
|
38
|
+
from: c._meta.startPos,
|
|
39
|
+
to: c._meta.endPos
|
|
40
|
+
} : void 0, e.onBlockUpdated), u = {
|
|
41
|
+
editor: e.editor,
|
|
42
|
+
selectedBlocks: c?.blocks,
|
|
43
|
+
streamTools: l,
|
|
44
|
+
emptyCursorBlockToDelete: s,
|
|
45
|
+
onStart: a
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
...u,
|
|
49
|
+
documentState: await i(u)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/streamTool/jsonSchema.ts
|
|
54
|
+
function ce(e) {
|
|
55
|
+
let { properties: t, required: n, $defs: r, ...i } = e.inputSchema;
|
|
56
|
+
return {
|
|
57
|
+
schema: {
|
|
58
|
+
type: "object",
|
|
59
|
+
description: e.description,
|
|
60
|
+
properties: {
|
|
61
|
+
type: {
|
|
62
|
+
type: "string",
|
|
63
|
+
enum: [e.name]
|
|
64
|
+
},
|
|
65
|
+
...t
|
|
66
|
+
},
|
|
67
|
+
required: ["type", ...n ?? []],
|
|
68
|
+
additionalProperties: !1,
|
|
69
|
+
...i
|
|
70
|
+
},
|
|
71
|
+
$defs: r
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function E(e) {
|
|
75
|
+
let t = e.map((e) => ce(e)), n = {};
|
|
76
|
+
for (let e of t) for (let t in e.$defs) {
|
|
77
|
+
if (n[t] && !ne(n[t], e.$defs[t])) throw Error(`Duplicate, but different definition for ${t}`);
|
|
78
|
+
n[t] = e.$defs[t];
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: { operations: {
|
|
83
|
+
type: "array",
|
|
84
|
+
items: { anyOf: t.map((e) => e.schema) }
|
|
85
|
+
} },
|
|
86
|
+
additionalProperties: !1,
|
|
87
|
+
required: ["operations"],
|
|
88
|
+
$defs: Object.keys(n).length > 0 ? n : void 0
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function le(e) {
|
|
92
|
+
return { applyDocumentOperations: {
|
|
93
|
+
inputSchema: v(E(e)),
|
|
94
|
+
outputSchema: v({ type: "object" })
|
|
95
|
+
} };
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/streamTool/ChunkExecutionError.ts
|
|
99
|
+
var D = class extends Error {
|
|
100
|
+
aborted;
|
|
101
|
+
constructor(e, t, n) {
|
|
102
|
+
super(e, n), this.chunk = t, this.name = "ChunkExecutionError", this.aborted = n?.aborted ?? !1;
|
|
103
|
+
}
|
|
104
|
+
}, ue = class {
|
|
105
|
+
stream;
|
|
106
|
+
constructor(e, t) {
|
|
107
|
+
this.streamTools = e, this.abortSignal = t, this.stream = this.createStream();
|
|
108
|
+
}
|
|
109
|
+
createStream() {
|
|
110
|
+
let e, t = new TransformStream({
|
|
111
|
+
transform: async (t, n) => {
|
|
112
|
+
let r = typeof t == "string" ? await de(t, e?.isPossiblyPartial ?? !1, this.streamTools) : t;
|
|
113
|
+
r && (e = r, n.enqueue(r));
|
|
114
|
+
},
|
|
115
|
+
flush: (t) => {
|
|
116
|
+
e?.isPossiblyPartial && t.error(/* @__PURE__ */ Error("stream ended with a partial operation"));
|
|
117
|
+
}
|
|
118
|
+
}), [n, r] = t.readable.pipeThrough(this.createExecutor()).tee(), i = n.pipeTo(new WritableStream());
|
|
119
|
+
return {
|
|
120
|
+
writable: t.writable,
|
|
121
|
+
readable: r,
|
|
122
|
+
finishPromise: i
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
createExecutor() {
|
|
126
|
+
let e = this.streamTools.map((e) => e.executor());
|
|
127
|
+
return new TransformStream({ transform: async (t, n) => {
|
|
128
|
+
let r = !1;
|
|
129
|
+
for (let i of e) try {
|
|
130
|
+
if (await i.execute(t, this.abortSignal)) {
|
|
131
|
+
n.enqueue({
|
|
132
|
+
status: "ok",
|
|
133
|
+
chunk: t
|
|
134
|
+
}), r = !0;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
} catch (e) {
|
|
138
|
+
n.error(new D(`Tool execution failed: ${b(e)}`, t, {
|
|
139
|
+
cause: e,
|
|
140
|
+
aborted: this.abortSignal?.aborted ?? !1
|
|
141
|
+
}));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!r) {
|
|
145
|
+
let e = t.operation?.type || "unknown";
|
|
146
|
+
n.error(/* @__PURE__ */ Error(`No tool could handle operation of type: ${e}`));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
} });
|
|
150
|
+
}
|
|
151
|
+
get writable() {
|
|
152
|
+
return this.stream.writable;
|
|
153
|
+
}
|
|
154
|
+
get readable() {
|
|
155
|
+
return this.stream.readable;
|
|
156
|
+
}
|
|
157
|
+
async finish() {
|
|
158
|
+
await this.stream.finishPromise;
|
|
159
|
+
}
|
|
160
|
+
async executeOperationsArray(e) {
|
|
161
|
+
let t = this.writable.getWriter();
|
|
162
|
+
for await (let n of e) {
|
|
163
|
+
let e = await y(n);
|
|
164
|
+
if (e.state === "undefined-input" || e.state === "failed-parse" || !e) return;
|
|
165
|
+
await t.write(n);
|
|
166
|
+
}
|
|
167
|
+
await t.close(), await this.finish();
|
|
168
|
+
}
|
|
169
|
+
async execute(e) {
|
|
170
|
+
let t = this.writable.getWriter();
|
|
171
|
+
for await (let n of e) await t.write(n);
|
|
172
|
+
await t.close(), await this.finish();
|
|
173
|
+
}
|
|
174
|
+
async executeOne(e) {
|
|
175
|
+
await this.execute((async function* () {
|
|
176
|
+
yield {
|
|
177
|
+
operation: e,
|
|
178
|
+
isUpdateToPreviousOperation: !1,
|
|
179
|
+
isPossiblyPartial: !1,
|
|
180
|
+
metadata: {}
|
|
181
|
+
};
|
|
182
|
+
})());
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
async function de(e, t, n) {
|
|
186
|
+
let r = await y(e);
|
|
187
|
+
if (r.state === "undefined-input" || r.state === "failed-parse" || !r) return;
|
|
188
|
+
let i = n.find((e) => e.name === r.value?.type), a = i && i.validate(r.value);
|
|
189
|
+
if (a?.ok) return {
|
|
190
|
+
operation: a.value,
|
|
191
|
+
isPossiblyPartial: r.state === "repaired-parse",
|
|
192
|
+
isUpdateToPreviousOperation: t,
|
|
193
|
+
metadata: void 0
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/streamTool/vercelAiSdk/util/injectDocumentStateMessages.ts
|
|
198
|
+
function fe(e) {
|
|
199
|
+
return e.flatMap((e) => {
|
|
200
|
+
if (e.role === "user" && e.metadata?.documentState) {
|
|
201
|
+
let t = e.metadata.documentState;
|
|
202
|
+
return [{
|
|
203
|
+
role: "assistant",
|
|
204
|
+
id: "assistant-document-state-" + e.id,
|
|
205
|
+
parts: [...t.selection ? [
|
|
206
|
+
{
|
|
207
|
+
type: "text",
|
|
208
|
+
text: "This is the latest state of the selection (ignore previous selections, you MUST issue operations against this latest version of the selection):"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
type: "text",
|
|
212
|
+
text: JSON.stringify(t.selectedBlocks)
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
type: "text",
|
|
216
|
+
text: "This is the latest state of the entire document (INCLUDING the selected text), \nyou can use this to find the selected text to understand the context (but you MUST NOT issue operations against this document, you MUST issue operations against the selection):"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
type: "text",
|
|
220
|
+
text: JSON.stringify(t.blocks)
|
|
221
|
+
}
|
|
222
|
+
] : [{
|
|
223
|
+
type: "text",
|
|
224
|
+
text: "There is no active selection. This is the latest state of the document (ignore previous documents, you MUST issue operations against this latest version of the document). \nThe cursor is BETWEEN two blocks as indicated by cursor: true.\n" + (t.isEmptyDocument ? "Because the document is empty, YOU MUST 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).")
|
|
225
|
+
}, {
|
|
226
|
+
type: "text",
|
|
227
|
+
text: JSON.stringify(t.blocks)
|
|
228
|
+
}]]
|
|
229
|
+
}, e];
|
|
230
|
+
}
|
|
231
|
+
return [e];
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/streamTool/vercelAiSdk/util/toolDefinitions.ts
|
|
236
|
+
async function pe(e) {
|
|
237
|
+
let t = await Promise.all(Object.entries(e).map(async ([e, t]) => [e, {
|
|
238
|
+
description: t.description,
|
|
239
|
+
inputSchema: await h(t.inputSchema).jsonSchema,
|
|
240
|
+
outputSchema: await h(t.outputSchema).jsonSchema
|
|
241
|
+
}]));
|
|
242
|
+
return Object.fromEntries(t);
|
|
243
|
+
}
|
|
244
|
+
function me(e) {
|
|
245
|
+
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, te({
|
|
246
|
+
...t,
|
|
247
|
+
inputSchema: v(t.inputSchema),
|
|
248
|
+
outputSchema: v(t.outputSchema)
|
|
249
|
+
})]));
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/streamTool/vercelAiSdk/clientside/ClientSideTransport.ts
|
|
253
|
+
var O = {
|
|
254
|
+
"mistral.chat": { mode: "auto" },
|
|
255
|
+
"google.generative-ai": { mode: "auto" },
|
|
256
|
+
"groq.chat": { providerOptions: { groq: { structuredOutputs: !1 } } }
|
|
257
|
+
};
|
|
258
|
+
function he(e) {
|
|
259
|
+
return O[e.provider] || {};
|
|
260
|
+
}
|
|
261
|
+
var ge = class {
|
|
262
|
+
constructor(e) {
|
|
263
|
+
this.opts = e;
|
|
264
|
+
}
|
|
265
|
+
async streamText(e, t) {
|
|
266
|
+
let { model: n, _additionalOptions: r } = this.opts;
|
|
267
|
+
return ee({
|
|
268
|
+
model: n,
|
|
269
|
+
system: this.opts.systemPrompt,
|
|
270
|
+
messages: await g(fe(e)),
|
|
271
|
+
tools: t,
|
|
272
|
+
toolChoice: "required",
|
|
273
|
+
...r ?? {}
|
|
274
|
+
}).toUIMessageStream();
|
|
275
|
+
}
|
|
276
|
+
async sendMessages({ messages: e, body: t }) {
|
|
277
|
+
let n = this.opts.stream ?? !0, r = t.toolDefinitions, i = await me(r);
|
|
278
|
+
if (n) return await this.streamText(e, i);
|
|
279
|
+
throw Error("Not implemented (generateText)");
|
|
280
|
+
}
|
|
281
|
+
reconnectToStream() {
|
|
282
|
+
throw Error("Not implemented");
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/streamTool/vercelAiSdk/util/appendableStream.ts
|
|
287
|
+
function _e() {
|
|
288
|
+
let e, t = Promise.resolve(), n = !1, r, i = new Promise((e, t) => {
|
|
289
|
+
r = t;
|
|
290
|
+
});
|
|
291
|
+
i.catch(() => {});
|
|
292
|
+
let a = new ReadableStream({
|
|
293
|
+
start(t) {
|
|
294
|
+
e = t;
|
|
295
|
+
},
|
|
296
|
+
cancel(t) {
|
|
297
|
+
n = !0, e.error(t), r?.(t);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
async function o(r) {
|
|
301
|
+
if (n) throw Error("Appendable stream canceled, can't append");
|
|
302
|
+
let a = r.getReader();
|
|
303
|
+
return t = t.then(async () => {
|
|
304
|
+
for (;;) try {
|
|
305
|
+
let { done: t, value: r } = await Promise.race([a.read(), i]);
|
|
306
|
+
if (t || n) break;
|
|
307
|
+
e.enqueue(r);
|
|
308
|
+
} catch (t) {
|
|
309
|
+
n = !0, e.error(t);
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}), t;
|
|
313
|
+
}
|
|
314
|
+
async function s() {
|
|
315
|
+
await t, n || e.close();
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
output: a,
|
|
319
|
+
append: o,
|
|
320
|
+
finalize: s
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/util/stream.ts
|
|
325
|
+
function ve(e) {
|
|
326
|
+
return new ReadableStream({ async start(t) {
|
|
327
|
+
try {
|
|
328
|
+
for await (let n of e) t.enqueue(n);
|
|
329
|
+
t.close();
|
|
330
|
+
} catch (e) {
|
|
331
|
+
t.error(e);
|
|
332
|
+
}
|
|
333
|
+
} });
|
|
334
|
+
}
|
|
335
|
+
function k(e) {
|
|
336
|
+
if (e.locked) throw Error("Stream (source) is already locked and cannot be iterated.");
|
|
337
|
+
let t = e.pipeThrough(new TransformStream());
|
|
338
|
+
return t[Symbol.asyncIterator] = () => {
|
|
339
|
+
if (t.locked) throw Error("Stream is already locked and cannot be iterated again.");
|
|
340
|
+
let e = t.getReader();
|
|
341
|
+
return { async next() {
|
|
342
|
+
let { done: t, value: n } = await e.read();
|
|
343
|
+
return t ? {
|
|
344
|
+
done: !0,
|
|
345
|
+
value: void 0
|
|
346
|
+
} : {
|
|
347
|
+
done: !1,
|
|
348
|
+
value: n
|
|
349
|
+
};
|
|
350
|
+
} };
|
|
351
|
+
}, t;
|
|
352
|
+
}
|
|
353
|
+
function ye(e) {
|
|
354
|
+
return k(ve(e));
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/streamTool/filterNewOrUpdatedOperations.ts
|
|
358
|
+
async function* be(e, t) {
|
|
359
|
+
let n = 0, r = !0, i;
|
|
360
|
+
for await (let a of e) if (a.operations?.length) {
|
|
361
|
+
for (let e = n; e < a.operations.length; e++) {
|
|
362
|
+
let o = a.operations[e];
|
|
363
|
+
i = o, yield {
|
|
364
|
+
partialOperation: o,
|
|
365
|
+
isUpdateToPreviousOperation: e === n && !r,
|
|
366
|
+
isPossiblyPartial: e === a.operations.length - 1,
|
|
367
|
+
metadata: t
|
|
368
|
+
}, r = !1;
|
|
369
|
+
}
|
|
370
|
+
n = a.operations.length - 1;
|
|
371
|
+
}
|
|
372
|
+
if (!i) throw Error("No operations seen");
|
|
373
|
+
yield {
|
|
374
|
+
partialOperation: i,
|
|
375
|
+
isUpdateToPreviousOperation: !0,
|
|
376
|
+
isPossiblyPartial: !1,
|
|
377
|
+
metadata: t
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/streamTool/filterValidOperations.ts
|
|
382
|
+
async function* xe(e, t) {
|
|
383
|
+
let n = !1;
|
|
384
|
+
for await (let r of e) {
|
|
385
|
+
let e = r.operation;
|
|
386
|
+
e.ok ? (yield {
|
|
387
|
+
operation: e.value,
|
|
388
|
+
isUpdateToPreviousOperation: n ? !1 : r.isUpdateToPreviousOperation,
|
|
389
|
+
isPossiblyPartial: r.isPossiblyPartial,
|
|
390
|
+
metadata: r.metadata
|
|
391
|
+
}, n = !1) : (n ||= !r.isUpdateToPreviousOperation, t?.({
|
|
392
|
+
...r,
|
|
393
|
+
operation: e
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region src/streamTool/toValidatedOperations.ts
|
|
399
|
+
async function* Se(e, t) {
|
|
400
|
+
for await (let n of e) {
|
|
401
|
+
if (!n.partialOperation.type) {
|
|
402
|
+
yield {
|
|
403
|
+
operation: {
|
|
404
|
+
ok: !1,
|
|
405
|
+
error: "The `type` property of an operation is required."
|
|
406
|
+
},
|
|
407
|
+
isUpdateToPreviousOperation: n.isUpdateToPreviousOperation,
|
|
408
|
+
isPossiblyPartial: n.isPossiblyPartial,
|
|
409
|
+
metadata: n.metadata
|
|
410
|
+
};
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
let e = t.find((e) => e.name === n.partialOperation.type);
|
|
414
|
+
if (!e) {
|
|
415
|
+
yield {
|
|
416
|
+
operation: {
|
|
417
|
+
ok: !1,
|
|
418
|
+
error: `No matching function for ${n.partialOperation.type}`
|
|
419
|
+
},
|
|
420
|
+
isUpdateToPreviousOperation: n.isUpdateToPreviousOperation,
|
|
421
|
+
isPossiblyPartial: n.isPossiblyPartial,
|
|
422
|
+
metadata: n.metadata
|
|
423
|
+
};
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
yield {
|
|
427
|
+
operation: e.validate(n.partialOperation),
|
|
428
|
+
isUpdateToPreviousOperation: n.isUpdateToPreviousOperation,
|
|
429
|
+
isPossiblyPartial: n.isPossiblyPartial,
|
|
430
|
+
metadata: n.metadata
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/streamTool/preprocess.ts
|
|
436
|
+
async function* Ce(e, t) {
|
|
437
|
+
yield* xe(Se(e, t), (e) => {
|
|
438
|
+
if (!e.isPossiblyPartial) throw new D(`Invalid operation. ${b(e.operation.error)}`, e, { cause: e.operation.error });
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/streamTool/vercelAiSdk/util/UIMessageStreamToOperationsResult.ts
|
|
443
|
+
function A(e, t, n) {
|
|
444
|
+
return ye(Ce(be(k(e), n), t));
|
|
445
|
+
}
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/streamTool/vercelAiSdk/util/chatHandlers.ts
|
|
448
|
+
async function j(e, t, n, r) {
|
|
449
|
+
let i = new ue(e, r), a = _e(), o = a.output.pipeTo(i.writable), s = /* @__PURE__ */ new Map(), c = !0, l = t["~registerMessagesCallback"](() => {
|
|
450
|
+
we(t, (t) => {
|
|
451
|
+
if (!s.has(t.toolCallId)) {
|
|
452
|
+
let r = Te(e, t.toolName, t.toolCallId);
|
|
453
|
+
a.append(r.operationsStream), s.set(t.toolCallId, r), c && (c = !1, n?.());
|
|
454
|
+
}
|
|
455
|
+
return s.get(t.toolCallId);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
await new Promise((e) => {
|
|
459
|
+
let n = t["~registerStatusCallback"](() => {
|
|
460
|
+
(t.status === "ready" || t.status === "error") && (l(), n(), t.status !== "error" && r(), e());
|
|
461
|
+
}), r = t["~registerErrorCallback"](() => {
|
|
462
|
+
if (t.error) {
|
|
463
|
+
r();
|
|
464
|
+
for (let e of s.values()) e.complete || e.writer.abort(t.error);
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}), await a.finalize();
|
|
468
|
+
let u = await Promise.allSettled([i.finish(), o]), d = u[0];
|
|
469
|
+
if (u[1].status === "rejected" && (u[0].status !== "rejected" || u[0].reason !== u[1].reason)) throw Error("unexpected, pipeToPromise rejected but executor.finish() doesn't have same error!?");
|
|
470
|
+
let f;
|
|
471
|
+
if (d.status === "rejected") {
|
|
472
|
+
if (d.reason instanceof D) f = d.reason;
|
|
473
|
+
else if (!t.error) throw Error("Unexpected: no ChunkExecutionError but also no chat.error (network error?)");
|
|
474
|
+
}
|
|
475
|
+
let p = !1, m = Array.from(s.values().filter((e) => e.complete));
|
|
476
|
+
return m.forEach((e, n) => {
|
|
477
|
+
let r = e.toolCallId === f?.chunk.metadata.toolCallId;
|
|
478
|
+
r && (p = !0), p ? t.addToolOutput({
|
|
479
|
+
tool: m[n].toolName,
|
|
480
|
+
toolCallId: m[n].toolCallId,
|
|
481
|
+
state: "output-error",
|
|
482
|
+
errorText: JSON.stringify(r ? {
|
|
483
|
+
status: "error",
|
|
484
|
+
error: b(f)
|
|
485
|
+
} : { status: "not-executed-previous-tool-errored" })
|
|
486
|
+
}) : t.addToolOutput({
|
|
487
|
+
state: "output-available",
|
|
488
|
+
tool: m[n].toolName,
|
|
489
|
+
toolCallId: m[n].toolCallId,
|
|
490
|
+
output: { status: "ok" }
|
|
491
|
+
});
|
|
492
|
+
}), f ? {
|
|
493
|
+
ok: !1,
|
|
494
|
+
error: f
|
|
495
|
+
} : {
|
|
496
|
+
ok: !0,
|
|
497
|
+
value: void 0
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function we(e, t) {
|
|
501
|
+
for (let n of e.lastMessage?.parts ?? []) {
|
|
502
|
+
if (!_(n) || n.type.replace("tool-", "") !== "applyDocumentOperations") continue;
|
|
503
|
+
let e = n.toolCallId;
|
|
504
|
+
Ee(n, t({
|
|
505
|
+
toolName: n.type.replace("tool-", ""),
|
|
506
|
+
toolCallId: e
|
|
507
|
+
}));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function Te(e, t, n) {
|
|
511
|
+
let r = new TransformStream(), i = A(r.readable, e, { toolCallId: n });
|
|
512
|
+
return {
|
|
513
|
+
writer: r.writable.getWriter(),
|
|
514
|
+
complete: !1,
|
|
515
|
+
operationsStream: i,
|
|
516
|
+
toolName: t,
|
|
517
|
+
toolCallId: n
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function Ee(e, t) {
|
|
521
|
+
if (e.state === "input-streaming") {
|
|
522
|
+
let n = e.input;
|
|
523
|
+
n !== void 0 && t.writer.write(n);
|
|
524
|
+
} else if (e.state === "input-available") {
|
|
525
|
+
let n = e.input;
|
|
526
|
+
if (n === void 0) throw Error("input is undefined");
|
|
527
|
+
t.complete || (t.complete = !0, t.writer.write(n), t.writer.close());
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/api/aiRequest/sendMessageWithAIRequest.ts
|
|
532
|
+
async function De(e, t, n, r, i) {
|
|
533
|
+
let a = n ?? e.lastMessage;
|
|
534
|
+
if (!a) throw Error("No message to send");
|
|
535
|
+
a.metadata = m(a.metadata, { documentState: t.documentState });
|
|
536
|
+
let o = j(t.streamTools, e, t.onStart, i);
|
|
537
|
+
return r = m(r, {
|
|
538
|
+
metadata: { source: "blocknote-ai" },
|
|
539
|
+
body: { toolDefinitions: await pe(le(t.streamTools)) }
|
|
540
|
+
}), await e.sendMessage(n, r), await o;
|
|
541
|
+
}
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/api/promptHelpers/addCursorPosition.ts
|
|
544
|
+
function M(e, t) {
|
|
545
|
+
let n = e.getTextCursorPosition(), r = [];
|
|
546
|
+
for (let e of t) {
|
|
547
|
+
let t = e.id === n.block.id;
|
|
548
|
+
r.push({
|
|
549
|
+
id: e.id,
|
|
550
|
+
block: e.block
|
|
551
|
+
}), t && r.push({ cursor: !0 });
|
|
552
|
+
}
|
|
553
|
+
return r;
|
|
554
|
+
}
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region src/api/promptHelpers/convertBlocks.ts
|
|
557
|
+
async function N(e, t) {
|
|
558
|
+
return await Promise.all(e.map(async (e) => ({
|
|
559
|
+
id: e.id,
|
|
560
|
+
block: await t(e)
|
|
561
|
+
})));
|
|
562
|
+
}
|
|
563
|
+
//#endregion
|
|
564
|
+
//#region src/api/promptHelpers/flattenBlocks.ts
|
|
565
|
+
function P(e) {
|
|
566
|
+
return e.flatMap((e) => [{
|
|
567
|
+
...e,
|
|
568
|
+
children: []
|
|
569
|
+
}, ...P(e.children)]);
|
|
570
|
+
}
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/api/promptHelpers/suffixIds.ts
|
|
573
|
+
function F(e) {
|
|
574
|
+
return e.map((e) => typeof e == "object" && e && "id" in e ? {
|
|
575
|
+
...e,
|
|
576
|
+
id: `${e.id}$`
|
|
577
|
+
} : e);
|
|
578
|
+
}
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region src/api/formats/DocumentStateBuilder.ts
|
|
581
|
+
function I(e) {
|
|
582
|
+
return async (t) => t.selectedBlocks ? await ke(t.editor, e, { selectedBlocks: t.selectedBlocks }) : await Oe(t.editor, e, { excludeBlockIds: t.emptyCursorBlockToDelete ? [t.emptyCursorBlockToDelete] : void 0 });
|
|
583
|
+
}
|
|
584
|
+
async function Oe(e, t, n) {
|
|
585
|
+
let r = T(e.document).length === 0, i = e.getTextCursorPosition().block.id;
|
|
586
|
+
return {
|
|
587
|
+
selection: !1,
|
|
588
|
+
blocks: F(M(e, await N(P(T(e.document, { cursorBlockId: i })), async (n) => t(e, n))).filter((e) => "cursor" in e || !(n.excludeBlockIds || []).includes(e.id))),
|
|
589
|
+
isEmptyDocument: r
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
async function ke(e, t, n) {
|
|
593
|
+
return {
|
|
594
|
+
isEmptyDocument: T(e.document).length === 0,
|
|
595
|
+
selection: !0,
|
|
596
|
+
selectedBlocks: F(await N(P(n.selectedBlocks), async (n) => t(e, n))),
|
|
597
|
+
blocks: (await N(P(e.document), async (n) => t(e, n))).map(({ block: e }) => ({ block: e }))
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
//#endregion
|
|
601
|
+
//#region src/prosemirror/fragmentUtil.ts
|
|
602
|
+
function Ae(e) {
|
|
603
|
+
let t, n = !1;
|
|
604
|
+
return e.descendants((e, r) => n ? !1 : (e.isText && (n = !0, t = r), !0)), t;
|
|
605
|
+
}
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/prosemirror/agent.ts
|
|
608
|
+
function L(e) {
|
|
609
|
+
let t = i(e), { modification: n } = t.marks, r = [], a = new S(e.before);
|
|
610
|
+
for (let i = 0; i < e.steps.length; i++) {
|
|
611
|
+
let o = e.steps[i], s = new re(e.mapping.maps.slice(0, i)).invert();
|
|
612
|
+
if (o.structure) {
|
|
613
|
+
if (o instanceof x) {
|
|
614
|
+
if (o.to !== o.from + 1 || o.slice.openStart !== 0 || o.slice.openEnd !== 1 || o.slice.content.size !== 2) throw Error("Structure change is not in expected format (ReplaceStep)");
|
|
615
|
+
} else if (o instanceof ie) {
|
|
616
|
+
if (o.insert !== 1 || o.slice.size !== 2 || o.gapTo !== o.to - 1 || o.gapFrom !== o.from + 1) throw Error("Structure change is not in expected format (ReplaceAroundStep)");
|
|
617
|
+
} else throw Error("Step is not a ReplaceStep or ReplaceAroundStep");
|
|
618
|
+
let e = s.map(o.from), t = o.slice.content.firstChild, i = a.doc.resolve(a.mapping.map(e)).nodeAfter, c = t.marks || [];
|
|
619
|
+
t.type !== i.type && (c = n.create({
|
|
620
|
+
type: "nodeType",
|
|
621
|
+
previousValue: i.type.name,
|
|
622
|
+
newValue: t.type.name
|
|
623
|
+
}).addToSet(c));
|
|
624
|
+
let l = new Set([...Object.keys(t.attrs), ...Object.keys(i.attrs)]);
|
|
625
|
+
for (let e of l) t.attrs[e] !== i.attrs[e] && (c = n.create({
|
|
626
|
+
type: "attr",
|
|
627
|
+
attrName: e,
|
|
628
|
+
previousValue: i.attrs[e],
|
|
629
|
+
newValue: t.attrs[e]
|
|
630
|
+
}).addToSet(c));
|
|
631
|
+
let u = a.steps.length;
|
|
632
|
+
a.setNodeMarkup(a.mapping.map(e), t.type, t.attrs, c), r.push({
|
|
633
|
+
prosemirrorSteps: a.steps.slice(u),
|
|
634
|
+
selection: void 0,
|
|
635
|
+
type: "replace"
|
|
636
|
+
});
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
if (!(o instanceof x)) throw Error("Step is not a ReplaceStep");
|
|
640
|
+
let c = s.map(o.from), l = s.map(o.to);
|
|
641
|
+
if (o.slice.openStart > 0 || o.slice.openEnd > 0) throw Error("Slice has openStart or openEnd > 0, but structure=false");
|
|
642
|
+
r.push({
|
|
643
|
+
prosemirrorSteps: [],
|
|
644
|
+
selection: {
|
|
645
|
+
anchor: a.mapping.map(c),
|
|
646
|
+
head: a.mapping.map(l)
|
|
647
|
+
},
|
|
648
|
+
type: "select"
|
|
649
|
+
});
|
|
650
|
+
let u = o.slice.content.textBetween(0, o.slice.size), d = u === a.doc.textBetween(a.mapping.map(c), a.mapping.map(l)), m;
|
|
651
|
+
if (d) m = o.slice.content.size;
|
|
652
|
+
else if (u.length === 0) m = o.slice.content.size;
|
|
653
|
+
else {
|
|
654
|
+
let e = Ae(o.slice.content);
|
|
655
|
+
if (e === void 0) throw Error("unexpected: no first character found");
|
|
656
|
+
m = e + 1;
|
|
657
|
+
}
|
|
658
|
+
let h = a.mapping.map(l), g = a.mapping.map(l), _ = !0;
|
|
659
|
+
for (let e = m; e <= o.slice.content.size; e++) {
|
|
660
|
+
let n = _ && c !== l, i = a.steps.length;
|
|
661
|
+
if (n) {
|
|
662
|
+
let e = a.doc.resolve(a.mapping.map(c));
|
|
663
|
+
e.nodeAfter?.isBlock && a.addNodeMark(e.pos, t.mark("deletion", {})), a.addMark(e.pos, h, t.mark("deletion", {})), h = a.mapping.map(l);
|
|
664
|
+
}
|
|
665
|
+
let s = new f(o.slice.content.cut(0, e), 0, 0);
|
|
666
|
+
a.replace(g, h, s).addMark(g, g + s.content.size, t.mark("insertion", {})), a.doc.nodesBetween(g, g + s.content.size, (e, n) => n < g || n > g + s.content.size ? !0 : (e.isBlock && a.addNodeMark(n, t.mark("insertion", {})), !1)), h = a.mapping.slice(i).map(h);
|
|
667
|
+
let u = p.near(a.doc.resolve(g + s.content.size), -1);
|
|
668
|
+
r.push({
|
|
669
|
+
prosemirrorSteps: a.steps.slice(i),
|
|
670
|
+
selection: {
|
|
671
|
+
anchor: u.from,
|
|
672
|
+
head: u.from
|
|
673
|
+
},
|
|
674
|
+
type: n ? "replace" : "insert"
|
|
675
|
+
}), _ = !1;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return r;
|
|
679
|
+
}
|
|
680
|
+
async function R(t) {
|
|
681
|
+
let n = Math.random() * .3 + .85;
|
|
682
|
+
if (t.type === "select") await new Promise((e) => setTimeout(e, 100 * n));
|
|
683
|
+
else if (t.type === "insert") await new Promise((e) => setTimeout(e, 10 * n));
|
|
684
|
+
else if (t.type === "replace") await new Promise((e) => setTimeout(e, 200 * n));
|
|
685
|
+
else throw new e(t.type);
|
|
686
|
+
}
|
|
687
|
+
function z(e, t) {
|
|
688
|
+
e.setMeta("addToHistory", !1), t.selection && e.setMeta("aiAgent", { selection: {
|
|
689
|
+
anchor: t.selection.anchor,
|
|
690
|
+
head: t.selection.head
|
|
691
|
+
} });
|
|
692
|
+
for (let n of t.prosemirrorSteps) if (e.maybeStep(n).failed) throw Error("failed to apply step");
|
|
693
|
+
return e;
|
|
694
|
+
}
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region src/prosemirror/changeset.ts
|
|
697
|
+
function je(e, t, n) {
|
|
698
|
+
let r = new S(t);
|
|
699
|
+
for (let t of e) {
|
|
700
|
+
let e = new x(r.mapping.map(t.fromA), r.mapping.map(t.toA), n.slice(t.fromB, t.toB));
|
|
701
|
+
r.step(e);
|
|
702
|
+
}
|
|
703
|
+
let i = r.mapping.invert(), a = r.doc.content.findDiffStart(n.content);
|
|
704
|
+
for (; a !== null;) {
|
|
705
|
+
let t = n.resolve(a).nodeAfter, o = r.doc.resolve(a).nodeAfter;
|
|
706
|
+
if (!t || !o) throw Error("diffNode not found");
|
|
707
|
+
let s = !t.isLeaf && t.content.eq(o.content), c = s ? 1 : Math.min(t.nodeSize, o.nodeSize), l = a + c, u = i.map(a), d = i.map(l), f = e.length;
|
|
708
|
+
for (let t = 0; t < e.length; t++) if (e[t].fromA >= d) {
|
|
709
|
+
f = t;
|
|
710
|
+
break;
|
|
711
|
+
}
|
|
712
|
+
e.splice(f, 0, {
|
|
713
|
+
fromA: u,
|
|
714
|
+
toA: d,
|
|
715
|
+
fromB: a,
|
|
716
|
+
toB: l,
|
|
717
|
+
deleted: [],
|
|
718
|
+
inserted: [],
|
|
719
|
+
type: s ? "node-type-or-attr-update" : "mark-update"
|
|
720
|
+
}), r.step(new x(a, l, n.slice(a, l), s));
|
|
721
|
+
let p = r.doc.content.findDiffStart(n.content);
|
|
722
|
+
if (p === a) throw Error("diffStart not moving");
|
|
723
|
+
a = p;
|
|
724
|
+
}
|
|
725
|
+
return e;
|
|
726
|
+
}
|
|
727
|
+
var B = (e, t) => {
|
|
728
|
+
let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
|
|
729
|
+
e.descendants((e) => {
|
|
730
|
+
e.type.name === "tableCell" && n.add(JSON.stringify(e.toJSON()));
|
|
731
|
+
}), t.descendants((e) => {
|
|
732
|
+
e.type.name === "tableCell" && r.add(JSON.stringify(e.toJSON()));
|
|
733
|
+
});
|
|
734
|
+
let i = new Set([...n].filter((e) => r.has(e)));
|
|
735
|
+
return {
|
|
736
|
+
encodeCharacter: (e) => e,
|
|
737
|
+
encodeNodeStart: (e) => {
|
|
738
|
+
if (e.type.name === "tableCell") {
|
|
739
|
+
let t = JSON.stringify(e.toJSON());
|
|
740
|
+
return i.has(t) ? t : e.type.name;
|
|
741
|
+
}
|
|
742
|
+
return e.type.name;
|
|
743
|
+
},
|
|
744
|
+
encodeNodeEnd: (e) => {
|
|
745
|
+
if (e.type.name === "tableCell") {
|
|
746
|
+
let t = JSON.stringify(e.toJSON());
|
|
747
|
+
return i.has(t) ? t : -1;
|
|
748
|
+
}
|
|
749
|
+
return -1;
|
|
750
|
+
},
|
|
751
|
+
compareTokens: (e, t) => e === t
|
|
752
|
+
};
|
|
753
|
+
};
|
|
754
|
+
function V(e, t, n = !1, i, a) {
|
|
755
|
+
let o = r(e.id, t), s = new S(t);
|
|
756
|
+
u(s, o.posBeforeNode, e.block, i, a);
|
|
757
|
+
let c = s.doc, l = C.create(t, void 0, B(t, c));
|
|
758
|
+
if (l = l.addSteps(c, s.mapping.maps, 0), n && l.changes.length > 0) {
|
|
759
|
+
let e = l.changes[l.changes.length - 1], n = e.toA - e.fromA, r = e.toB - e.fromB;
|
|
760
|
+
if (n > r) {
|
|
761
|
+
let n = t.slice(e.fromA + r, e.toA);
|
|
762
|
+
s.step(new x(e.toB, e.toB, n)), c = s.doc, l = C.create(l.startDoc, void 0, B(l.startDoc, c)), l = l.addSteps(c, s.mapping.maps, 0);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
let d = [], f = ae(l.changes, c);
|
|
766
|
+
for (let e = 0; e < f.length; e++) {
|
|
767
|
+
let t = f[e], n = c.slice(t.fromB, t.toB);
|
|
768
|
+
if (n.openEnd === 1 && n.openStart === 0 && (t.type = "node-type-or-attr-update", n.size > 2)) {
|
|
769
|
+
let n = {
|
|
770
|
+
fromA: t.fromA,
|
|
771
|
+
toA: t.fromA + 1,
|
|
772
|
+
fromB: t.fromB,
|
|
773
|
+
toB: t.fromB + 1,
|
|
774
|
+
deleted: [],
|
|
775
|
+
inserted: [],
|
|
776
|
+
type: "node-type-or-attr-update"
|
|
777
|
+
}, r = {
|
|
778
|
+
fromA: t.fromA + 1,
|
|
779
|
+
toA: t.toA,
|
|
780
|
+
fromB: t.fromB + 1,
|
|
781
|
+
toB: t.toB,
|
|
782
|
+
deleted: [],
|
|
783
|
+
inserted: []
|
|
784
|
+
};
|
|
785
|
+
f.splice(e, 1, n, r), e++;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
je(f, t, c);
|
|
789
|
+
for (let e = 0; e < f.length; e++) {
|
|
790
|
+
let t = f[e], r = c.slice(t.fromB, t.toB);
|
|
791
|
+
if (r.openEnd > 0 && r.size > 1) throw Error("unexpected, openEnd > 0 and size > 1, this should have been split into two steps");
|
|
792
|
+
e === f.length - 1 && n && t.type === "mark-update" || d.push(new x(t.fromA, t.toA, r, t.type === "node-type-or-attr-update"));
|
|
793
|
+
}
|
|
794
|
+
return d;
|
|
795
|
+
}
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region src/streamTool/streamTool.ts
|
|
798
|
+
function H(e) {
|
|
799
|
+
return e;
|
|
800
|
+
}
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region src/util/AbortError.ts
|
|
803
|
+
var U = class extends Error {
|
|
804
|
+
constructor(e, t) {
|
|
805
|
+
super(e, t), this.name = "AbortError";
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region src/api/formats/base-tools/util/validateBlockArray.ts
|
|
810
|
+
function Me(e, t) {
|
|
811
|
+
if (!e || !Array.isArray(e) || e.length === 0) return {
|
|
812
|
+
ok: !1,
|
|
813
|
+
error: "blocks is required"
|
|
814
|
+
};
|
|
815
|
+
let n = [];
|
|
816
|
+
for (let r of e) {
|
|
817
|
+
let e = t(r);
|
|
818
|
+
if (!e.ok) return {
|
|
819
|
+
ok: !1,
|
|
820
|
+
error: `Invalid block: ${e.error}`
|
|
821
|
+
};
|
|
822
|
+
n.push(e.value);
|
|
823
|
+
}
|
|
824
|
+
return {
|
|
825
|
+
ok: !0,
|
|
826
|
+
value: n
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
//#endregion
|
|
830
|
+
//#region src/api/formats/base-tools/createAddBlocksTool.ts
|
|
831
|
+
function W(e) {
|
|
832
|
+
return (t, n) => {
|
|
833
|
+
let r = typeof e.schema == "function" ? e.schema(t) : e.schema;
|
|
834
|
+
return H({
|
|
835
|
+
name: "add",
|
|
836
|
+
description: e.description,
|
|
837
|
+
inputSchema: {
|
|
838
|
+
type: "object",
|
|
839
|
+
properties: {
|
|
840
|
+
referenceId: {
|
|
841
|
+
type: "string",
|
|
842
|
+
description: "MUST be an id of a block in the document"
|
|
843
|
+
},
|
|
844
|
+
position: {
|
|
845
|
+
type: "string",
|
|
846
|
+
enum: ["before", "after"],
|
|
847
|
+
description: "`after` to add blocks AFTER (below) the block with `referenceId`, `before` to add the block BEFORE (above)"
|
|
848
|
+
},
|
|
849
|
+
blocks: {
|
|
850
|
+
items: r.block,
|
|
851
|
+
type: "array"
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
required: [
|
|
855
|
+
"referenceId",
|
|
856
|
+
"position",
|
|
857
|
+
"blocks"
|
|
858
|
+
],
|
|
859
|
+
$defs: r.$defs
|
|
860
|
+
},
|
|
861
|
+
validate: (r) => {
|
|
862
|
+
if (r.type !== "add") return {
|
|
863
|
+
ok: !1,
|
|
864
|
+
error: "invalid operation type"
|
|
865
|
+
};
|
|
866
|
+
if (r.position !== "before" && r.position !== "after") return {
|
|
867
|
+
ok: !1,
|
|
868
|
+
error: "invalid position"
|
|
869
|
+
};
|
|
870
|
+
if (!r.referenceId || !r.blocks) return {
|
|
871
|
+
ok: !1,
|
|
872
|
+
error: "referenceId and blocks are required"
|
|
873
|
+
};
|
|
874
|
+
let i = r.referenceId;
|
|
875
|
+
if (n.idsSuffixed) {
|
|
876
|
+
if (!i?.endsWith("$")) return {
|
|
877
|
+
ok: !1,
|
|
878
|
+
error: "referenceId must end with $"
|
|
879
|
+
};
|
|
880
|
+
i = i.slice(0, -1);
|
|
881
|
+
}
|
|
882
|
+
if (!t.getBlock(i)) return {
|
|
883
|
+
ok: !1,
|
|
884
|
+
error: "referenceId not found"
|
|
885
|
+
};
|
|
886
|
+
let a = Me(r.blocks, (n) => e.validateBlock(n, t));
|
|
887
|
+
return a.ok ? {
|
|
888
|
+
ok: !0,
|
|
889
|
+
value: {
|
|
890
|
+
type: r.type,
|
|
891
|
+
referenceId: i,
|
|
892
|
+
position: r.position,
|
|
893
|
+
blocks: a.value
|
|
894
|
+
}
|
|
895
|
+
} : a;
|
|
896
|
+
},
|
|
897
|
+
executor: () => {
|
|
898
|
+
let r = [], i = {};
|
|
899
|
+
return { execute: async (o, s) => {
|
|
900
|
+
if (o.isUpdateToPreviousOperation || (r = []), o.operation.type !== "add") return !1;
|
|
901
|
+
let c = o.operation, l = await e.toJSONToolCall(t, {
|
|
902
|
+
...o,
|
|
903
|
+
operation: c
|
|
904
|
+
});
|
|
905
|
+
if (!l || o.isPossiblyPartial && w(l.blocks[l.blocks.length - 1])) return !0;
|
|
906
|
+
for (let o = 0; o < l.blocks.length; o++) {
|
|
907
|
+
let u = l.blocks[o], d = t.prosemirrorState.tr, f = [];
|
|
908
|
+
if (o < r.length) {
|
|
909
|
+
let n = await e.rebaseTool(r[o], t), i = V({
|
|
910
|
+
id: r[o],
|
|
911
|
+
block: u
|
|
912
|
+
}, n.doc, !1).map((e) => e.map(n.invertMap));
|
|
913
|
+
for (let e of i) d.step(e.map(d.mapping));
|
|
914
|
+
f = L(d), f = f.filter((e) => e.type !== "select");
|
|
915
|
+
} else {
|
|
916
|
+
let e = c.position === "after" ? i[c.referenceId] : void 0, t = a(d, [u], o > 0 ? r[o - 1] : e || c.referenceId, o > 0 ? "after" : c.position);
|
|
917
|
+
r.push(...t.map((e) => e.id)), f = L(d);
|
|
918
|
+
}
|
|
919
|
+
for (let e of f) {
|
|
920
|
+
if (s?.aborted) throw new U("Operation was aborted");
|
|
921
|
+
n.withDelays && await R(e), t.transact((t) => {
|
|
922
|
+
z(t, e);
|
|
923
|
+
}), n.onBlockUpdate?.(r[o]);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return o.isPossiblyPartial || c.position === "after" && (i[c.referenceId] = r[r.length - 1]), !0;
|
|
927
|
+
} };
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
//#endregion
|
|
933
|
+
//#region src/api/formats/base-tools/createUpdateBlockTool.ts
|
|
934
|
+
function G(e) {
|
|
935
|
+
return (t, n) => {
|
|
936
|
+
let r = typeof e.schema == "function" ? e.schema(t) : e.schema;
|
|
937
|
+
return H({
|
|
938
|
+
name: "update",
|
|
939
|
+
description: e.description,
|
|
940
|
+
inputSchema: {
|
|
941
|
+
type: "object",
|
|
942
|
+
properties: {
|
|
943
|
+
id: {
|
|
944
|
+
type: "string",
|
|
945
|
+
description: "id of block to update"
|
|
946
|
+
},
|
|
947
|
+
block: r.block
|
|
948
|
+
},
|
|
949
|
+
required: ["id", "block"],
|
|
950
|
+
$defs: r.$defs
|
|
951
|
+
},
|
|
952
|
+
validate: (r) => {
|
|
953
|
+
if (r.type !== "update") return {
|
|
954
|
+
ok: !1,
|
|
955
|
+
error: "invalid operation type"
|
|
956
|
+
};
|
|
957
|
+
if (!r.id) return {
|
|
958
|
+
ok: !1,
|
|
959
|
+
error: "id is required"
|
|
960
|
+
};
|
|
961
|
+
let i = r.id;
|
|
962
|
+
if (n.idsSuffixed) {
|
|
963
|
+
if (!i?.endsWith("$")) return {
|
|
964
|
+
ok: !1,
|
|
965
|
+
error: "id must end with $"
|
|
966
|
+
};
|
|
967
|
+
i = i.slice(0, -1);
|
|
968
|
+
}
|
|
969
|
+
if (!r.block) return {
|
|
970
|
+
ok: !1,
|
|
971
|
+
error: "block is required"
|
|
972
|
+
};
|
|
973
|
+
let a = t.getBlock(i);
|
|
974
|
+
if (!a) return {
|
|
975
|
+
ok: !1,
|
|
976
|
+
error: Error("Block not found (update)", { cause: { blockId: i } })
|
|
977
|
+
};
|
|
978
|
+
let o = e.validateBlock(r.block, t, a.type);
|
|
979
|
+
return o.ok ? {
|
|
980
|
+
ok: !0,
|
|
981
|
+
value: {
|
|
982
|
+
type: r.type,
|
|
983
|
+
id: i,
|
|
984
|
+
block: o.value
|
|
985
|
+
}
|
|
986
|
+
} : o;
|
|
987
|
+
},
|
|
988
|
+
executor: () => {
|
|
989
|
+
let r = 50, i = n.updateSelection ? {
|
|
990
|
+
from: l(t, n.updateSelection.from),
|
|
991
|
+
to: l(t, n.updateSelection.to)
|
|
992
|
+
} : void 0;
|
|
993
|
+
return { execute: async (a, o) => {
|
|
994
|
+
if (a.operation.type !== "update") return !1;
|
|
995
|
+
let s = a.operation;
|
|
996
|
+
if (a.isPossiblyPartial) {
|
|
997
|
+
let e = JSON.stringify(s.block).length;
|
|
998
|
+
if (e < r) return !0;
|
|
999
|
+
r = e + 50;
|
|
1000
|
+
} else r = 50;
|
|
1001
|
+
let c = await e.rebaseTool(s.id, t), l = i ? c.invertMap.invert().map(i.from()) : void 0, u = i ? c.invertMap.invert().map(i.to()) : void 0, d = await e.toJSONToolCall(t, {
|
|
1002
|
+
...a,
|
|
1003
|
+
operation: s
|
|
1004
|
+
});
|
|
1005
|
+
if (!d) return !0;
|
|
1006
|
+
let f = V(d, c.doc, a.isPossiblyPartial, l, u);
|
|
1007
|
+
if (f.length === 1 && a.isPossiblyPartial) return !0;
|
|
1008
|
+
let p = f.map((e) => e.map(c.invertMap)), m = new S(t.prosemirrorState.doc);
|
|
1009
|
+
for (let e of p) m.step(e.map(m.mapping));
|
|
1010
|
+
let h = L(m);
|
|
1011
|
+
for (let e of h) {
|
|
1012
|
+
if (o?.aborted) throw new U("Operation was aborted");
|
|
1013
|
+
n.withDelays && await R(e), t.transact((t) => {
|
|
1014
|
+
z(t, e);
|
|
1015
|
+
}), n.onBlockUpdate?.(s.id);
|
|
1016
|
+
}
|
|
1017
|
+
return !0;
|
|
1018
|
+
} };
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
//#endregion
|
|
1024
|
+
//#region src/api/formats/base-tools/delete.ts
|
|
1025
|
+
var K = (e, t) => H({
|
|
1026
|
+
name: "delete",
|
|
1027
|
+
description: "Delete a block",
|
|
1028
|
+
inputSchema: {
|
|
1029
|
+
type: "object",
|
|
1030
|
+
properties: { id: {
|
|
1031
|
+
type: "string",
|
|
1032
|
+
description: "id of block to delete"
|
|
1033
|
+
} },
|
|
1034
|
+
required: ["id"]
|
|
1035
|
+
},
|
|
1036
|
+
validate: (n) => {
|
|
1037
|
+
if (n.type !== "delete") return {
|
|
1038
|
+
ok: !1,
|
|
1039
|
+
error: "invalid operation type"
|
|
1040
|
+
};
|
|
1041
|
+
if (!n.id) return {
|
|
1042
|
+
ok: !1,
|
|
1043
|
+
error: "id is required"
|
|
1044
|
+
};
|
|
1045
|
+
let r = n.id;
|
|
1046
|
+
if (t.idsSuffixed) {
|
|
1047
|
+
if (!r?.endsWith("$")) return {
|
|
1048
|
+
ok: !1,
|
|
1049
|
+
error: "id must end with $"
|
|
1050
|
+
};
|
|
1051
|
+
r = r.slice(0, -1);
|
|
1052
|
+
}
|
|
1053
|
+
return e.getBlock(r) ? {
|
|
1054
|
+
ok: !0,
|
|
1055
|
+
value: {
|
|
1056
|
+
type: "delete",
|
|
1057
|
+
id: r
|
|
1058
|
+
}
|
|
1059
|
+
} : {
|
|
1060
|
+
ok: !1,
|
|
1061
|
+
error: Error("Block not found (delete)", { cause: { blockId: r } })
|
|
1062
|
+
};
|
|
1063
|
+
},
|
|
1064
|
+
executor: () => ({ execute: async (n) => {
|
|
1065
|
+
if (n.operation.type !== "delete") return !1;
|
|
1066
|
+
let r = n.operation, i = e.prosemirrorState.tr;
|
|
1067
|
+
c(i, [r.id], []);
|
|
1068
|
+
let a = L(i);
|
|
1069
|
+
for (let n of a) t.withDelays && await R(n), e.transact((e) => {
|
|
1070
|
+
z(e, n);
|
|
1071
|
+
}), t.onBlockUpdate?.(r.id);
|
|
1072
|
+
return !0;
|
|
1073
|
+
} })
|
|
1074
|
+
});
|
|
1075
|
+
//#endregion
|
|
1076
|
+
//#region src/api/formats/html-blocks/tools/getPartialHTML.ts
|
|
1077
|
+
function Ne(e) {
|
|
1078
|
+
let t = e.lastIndexOf("<"), n = e.lastIndexOf(">"), r = e;
|
|
1079
|
+
if (t > n && (r = e.substring(0, t), !r.trim())) return;
|
|
1080
|
+
let i = r.match(/&[a-zA-Z0-9]*$/);
|
|
1081
|
+
i && (r = r.substring(0, r.length - i[0].length));
|
|
1082
|
+
let a = new DOMParser().parseFromString(`<div>${r}</div>`, "text/html").body.firstChild;
|
|
1083
|
+
return a ? a.innerHTML : "";
|
|
1084
|
+
}
|
|
1085
|
+
//#endregion
|
|
1086
|
+
//#region src/prosemirror/rebaseTool.ts
|
|
1087
|
+
function q(e) {
|
|
1088
|
+
let t;
|
|
1089
|
+
if (d(e.prosemirrorState, (e) => {
|
|
1090
|
+
t = e;
|
|
1091
|
+
}), !t) throw Error("applySuggestionsTr is not set");
|
|
1092
|
+
return t;
|
|
1093
|
+
}
|
|
1094
|
+
function J(e, t) {
|
|
1095
|
+
let n = t.mapping.invert();
|
|
1096
|
+
return {
|
|
1097
|
+
doc: t.doc,
|
|
1098
|
+
tr: () => new S(t.doc),
|
|
1099
|
+
invertMap: n,
|
|
1100
|
+
rebaseTr: (t) => {
|
|
1101
|
+
if (t.steps.length === 0) throw Error("No steps to apply");
|
|
1102
|
+
let r = e.prosemirrorState.tr;
|
|
1103
|
+
for (let e of t.steps) {
|
|
1104
|
+
let t = e.map(n);
|
|
1105
|
+
if (!t) throw Error("Step is not mapped");
|
|
1106
|
+
r = r.step(t);
|
|
1107
|
+
}
|
|
1108
|
+
return r;
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
//#endregion
|
|
1113
|
+
//#region src/api/formats/html-blocks/tools/rebaseTool.ts
|
|
1114
|
+
async function Pe(e, t) {
|
|
1115
|
+
let r = q(t), i = n(r.doc, e);
|
|
1116
|
+
if (!i) throw Error("block not found");
|
|
1117
|
+
let a = await t.blocksToHTMLLossy([{
|
|
1118
|
+
...i,
|
|
1119
|
+
children: []
|
|
1120
|
+
}]), o = window.__TEST_OPTIONS?.mockID, s = await t.tryParseHTMLToBlocks(a);
|
|
1121
|
+
if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = o), s.length !== 1) throw Error("html diff invalid block count");
|
|
1122
|
+
let c = s[0];
|
|
1123
|
+
if (c.id = e, V({
|
|
1124
|
+
id: e,
|
|
1125
|
+
block: c
|
|
1126
|
+
}, r.doc).length) throw Error("html diff", { cause: {
|
|
1127
|
+
html: a,
|
|
1128
|
+
htmlBlock: c
|
|
1129
|
+
} });
|
|
1130
|
+
return J(t, r);
|
|
1131
|
+
}
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region src/api/formats/html-blocks/tools/validate.ts
|
|
1134
|
+
function Fe(e) {
|
|
1135
|
+
return typeof e == "string" ? {
|
|
1136
|
+
ok: !0,
|
|
1137
|
+
value: e
|
|
1138
|
+
} : {
|
|
1139
|
+
ok: !1,
|
|
1140
|
+
error: "block must be a string"
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
//#endregion
|
|
1144
|
+
//#region src/api/formats/html-blocks/tools/index.ts
|
|
1145
|
+
var Y = {
|
|
1146
|
+
add: W({
|
|
1147
|
+
description: "Insert new blocks",
|
|
1148
|
+
schema: { block: {
|
|
1149
|
+
type: "string",
|
|
1150
|
+
description: "html of block (MUST be a single, VALID HTML element)"
|
|
1151
|
+
} },
|
|
1152
|
+
validateBlock: Fe,
|
|
1153
|
+
rebaseTool: Pe,
|
|
1154
|
+
toJSONToolCall: async (e, t) => {
|
|
1155
|
+
let n = window.__TEST_OPTIONS?.mockID, r = (await Promise.all(t.operation.blocks.map(async (n) => {
|
|
1156
|
+
let r = t.isPossiblyPartial ? Ne(n) : n;
|
|
1157
|
+
return r ? (await e.tryParseHTMLToBlocks(r)).map((e) => (delete e.id, e)) : [];
|
|
1158
|
+
}))).flat();
|
|
1159
|
+
if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = n), r.length !== 0) return {
|
|
1160
|
+
...t.operation,
|
|
1161
|
+
blocks: r
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
}),
|
|
1165
|
+
update: G({
|
|
1166
|
+
description: "Update a block",
|
|
1167
|
+
schema: { block: {
|
|
1168
|
+
type: "string",
|
|
1169
|
+
description: "html of block (MUST be a single HTML element)"
|
|
1170
|
+
} },
|
|
1171
|
+
validateBlock: Fe,
|
|
1172
|
+
rebaseTool: Pe,
|
|
1173
|
+
toJSONToolCall: async (e, t) => {
|
|
1174
|
+
let n = t.isPossiblyPartial ? Ne(t.operation.block) : t.operation.block;
|
|
1175
|
+
if (!n) return;
|
|
1176
|
+
let r = (await e.tryParseHTMLToBlocks(n))[0];
|
|
1177
|
+
return window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), delete r.id, {
|
|
1178
|
+
...t.operation,
|
|
1179
|
+
block: r
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
}),
|
|
1183
|
+
delete: K
|
|
1184
|
+
};
|
|
1185
|
+
//#endregion
|
|
1186
|
+
//#region src/api/formats/html-blocks/htmlBlocks.ts
|
|
1187
|
+
function Ie(e, t, n, r, i) {
|
|
1188
|
+
if (typeof r == "boolean") {
|
|
1189
|
+
let t = r ? e.getSelectionCutBlocks(!0) : void 0;
|
|
1190
|
+
r = t ? {
|
|
1191
|
+
from: t._meta.startPos,
|
|
1192
|
+
to: t._meta.endPos
|
|
1193
|
+
} : void 0;
|
|
1194
|
+
}
|
|
1195
|
+
let a = n ?? {
|
|
1196
|
+
add: !0,
|
|
1197
|
+
update: !0,
|
|
1198
|
+
delete: !0
|
|
1199
|
+
};
|
|
1200
|
+
return [
|
|
1201
|
+
...a.update ? [Y.update(e, {
|
|
1202
|
+
idsSuffixed: !0,
|
|
1203
|
+
withDelays: t,
|
|
1204
|
+
updateSelection: r,
|
|
1205
|
+
onBlockUpdate: i
|
|
1206
|
+
})] : [],
|
|
1207
|
+
...a.add ? [Y.add(e, {
|
|
1208
|
+
idsSuffixed: !0,
|
|
1209
|
+
withDelays: t,
|
|
1210
|
+
onBlockUpdate: i
|
|
1211
|
+
})] : [],
|
|
1212
|
+
...a.delete ? [Y.delete(e, {
|
|
1213
|
+
idsSuffixed: !0,
|
|
1214
|
+
withDelays: t,
|
|
1215
|
+
onBlockUpdate: i
|
|
1216
|
+
})] : []
|
|
1217
|
+
];
|
|
1218
|
+
}
|
|
1219
|
+
var Le = {
|
|
1220
|
+
getStreamToolsProvider: (e = {}) => ({ getStreamTools: (t, n, r) => Ie(t, e.withDelays ?? !0, e.defaultStreamTools, n, r) }),
|
|
1221
|
+
systemPrompt: "You're manipulating a text document using HTML blocks. \nMake sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $). \nList 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.\nFor code blocks, you can use the `data-language` attribute on a <code> block (wrapped with <pre>) to specify the language.\n\nIf the user requests updates to the document, use the \"applyDocumentOperations\" tool to update the document.\n---\nIF there is no selection active in the latest state, first, determine what part of the document the user is talking about. You SHOULD probably take cursor info into account if needed.\n EXAMPLE: if user says \"below\" (without pointing to a specific part of the document) he / she probably indicates the block(s) after the cursor. \n EXAMPLE: If you want to insert content AT the cursor position (UNLESS indicated otherwise by the user), then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`\n---\n ",
|
|
1222
|
+
tools: Y,
|
|
1223
|
+
defaultDocumentStateBuilder: I(async (e, t) => e.blocksToHTMLLossy([t]))
|
|
1224
|
+
};
|
|
1225
|
+
//#endregion
|
|
1226
|
+
//#region src/api/schema/mergeSchema.ts
|
|
1227
|
+
function Re(e) {
|
|
1228
|
+
let t = {}, n = {};
|
|
1229
|
+
return e.forEach((e) => {
|
|
1230
|
+
let { type: r, ...i } = e.properties, a = JSON.stringify(i);
|
|
1231
|
+
t[a] ? t[a].push(r.enum[0]) : (t[a] = [r.enum[0]], n[a] = e);
|
|
1232
|
+
}), Object.keys(t).map((e) => {
|
|
1233
|
+
let r = n[e];
|
|
1234
|
+
return {
|
|
1235
|
+
...r,
|
|
1236
|
+
properties: {
|
|
1237
|
+
...r.properties,
|
|
1238
|
+
type: {
|
|
1239
|
+
type: "string",
|
|
1240
|
+
enum: t[e]
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
//#endregion
|
|
1247
|
+
//#region src/api/schema/schemaToJSONSchema.ts
|
|
1248
|
+
function ze(e) {
|
|
1249
|
+
return {
|
|
1250
|
+
type: "object",
|
|
1251
|
+
properties: Object.fromEntries(Object.entries(e).map(([e, t]) => [e, { type: t.propSchema }])),
|
|
1252
|
+
additionalProperties: !1
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
function Be() {
|
|
1256
|
+
return {
|
|
1257
|
+
type: "object",
|
|
1258
|
+
properties: {
|
|
1259
|
+
type: {
|
|
1260
|
+
type: "string",
|
|
1261
|
+
enum: ["text"]
|
|
1262
|
+
},
|
|
1263
|
+
text: { type: "string" },
|
|
1264
|
+
styles: { $ref: "#/$defs/styles" }
|
|
1265
|
+
},
|
|
1266
|
+
additionalProperties: !1,
|
|
1267
|
+
required: ["type", "text"]
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
function Ve(e) {
|
|
1271
|
+
return {
|
|
1272
|
+
type: "object",
|
|
1273
|
+
properties: Object.fromEntries(Object.entries(e).filter(([e, t]) => t.default !== void 0).map(([e, t]) => [e, {
|
|
1274
|
+
type: typeof t.default,
|
|
1275
|
+
enum: t.values
|
|
1276
|
+
}])),
|
|
1277
|
+
additionalProperties: !1
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
function He(e) {
|
|
1281
|
+
return {
|
|
1282
|
+
type: "array",
|
|
1283
|
+
items: { anyOf: Object.entries(e).map(([e, t]) => t === "text" ? { $ref: "#/$defs/styledtext" } : t === "link" ? {
|
|
1284
|
+
type: "object",
|
|
1285
|
+
properties: {
|
|
1286
|
+
type: {
|
|
1287
|
+
type: "string",
|
|
1288
|
+
enum: ["link"]
|
|
1289
|
+
},
|
|
1290
|
+
content: {
|
|
1291
|
+
type: "array",
|
|
1292
|
+
items: { $ref: "#/$defs/styledtext" }
|
|
1293
|
+
},
|
|
1294
|
+
href: { type: "string" }
|
|
1295
|
+
},
|
|
1296
|
+
additionalProperties: !1,
|
|
1297
|
+
required: [
|
|
1298
|
+
"type",
|
|
1299
|
+
"href",
|
|
1300
|
+
"content"
|
|
1301
|
+
]
|
|
1302
|
+
} : {
|
|
1303
|
+
type: "object",
|
|
1304
|
+
properties: {
|
|
1305
|
+
type: {
|
|
1306
|
+
type: "string",
|
|
1307
|
+
enum: [t.type]
|
|
1308
|
+
},
|
|
1309
|
+
content: t.content === "styled" ? {
|
|
1310
|
+
type: "array",
|
|
1311
|
+
items: { $ref: "#/$defs/styledtext" }
|
|
1312
|
+
} : void 0,
|
|
1313
|
+
props: Ve(t.propSchema)
|
|
1314
|
+
},
|
|
1315
|
+
additionalProperties: !1,
|
|
1316
|
+
required: ["type", ...t.content === "styled" ? ["content"] : []]
|
|
1317
|
+
}) }
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
function Ue(e) {
|
|
1321
|
+
return { anyOf: Re(Object.entries(e).map(([e, t]) => ({
|
|
1322
|
+
type: "object",
|
|
1323
|
+
properties: {
|
|
1324
|
+
type: {
|
|
1325
|
+
type: "string",
|
|
1326
|
+
enum: [t.type]
|
|
1327
|
+
},
|
|
1328
|
+
content: t.content === "inline" ? { $ref: "#/$defs/inlinecontent" } : t.content === "table" ? {
|
|
1329
|
+
type: "object",
|
|
1330
|
+
properties: {}
|
|
1331
|
+
} : void 0,
|
|
1332
|
+
props: Ve(t.propSchema)
|
|
1333
|
+
},
|
|
1334
|
+
additionalProperties: !1,
|
|
1335
|
+
required: ["type"]
|
|
1336
|
+
}))) };
|
|
1337
|
+
}
|
|
1338
|
+
function We(e) {
|
|
1339
|
+
let n = JSON.parse(JSON.stringify({
|
|
1340
|
+
blockSchema: e.blockSchema,
|
|
1341
|
+
inlineContentSchema: e.inlineContentSchema,
|
|
1342
|
+
styleSchema: e.styleSchema
|
|
1343
|
+
}));
|
|
1344
|
+
return {
|
|
1345
|
+
removeFileBlocks() {
|
|
1346
|
+
return n.blockSchema = Object.fromEntries(Object.entries(n.blockSchema).filter(([t, n]) => !e.blockSpecs[n.type].implementation.meta?.fileBlockAccept)), this;
|
|
1347
|
+
},
|
|
1348
|
+
removeDefaultProps() {
|
|
1349
|
+
return n.blockSchema = Object.fromEntries(Object.entries(n.blockSchema).map(([e, n]) => [e, {
|
|
1350
|
+
...n,
|
|
1351
|
+
propSchema: Object.fromEntries(Object.entries(n.propSchema).filter((e) => t[e[0]] === void 0))
|
|
1352
|
+
}])), this;
|
|
1353
|
+
},
|
|
1354
|
+
get() {
|
|
1355
|
+
return n;
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
function X(e) {
|
|
1360
|
+
return e = We(e).removeFileBlocks().removeDefaultProps().get(), { $defs: {
|
|
1361
|
+
styles: ze(e.styleSchema),
|
|
1362
|
+
styledtext: Be(),
|
|
1363
|
+
inlinecontent: He(e.inlineContentSchema),
|
|
1364
|
+
block: Ue(e.blockSchema)
|
|
1365
|
+
} };
|
|
1366
|
+
}
|
|
1367
|
+
//#endregion
|
|
1368
|
+
//#region src/api/formats/json/tools/validate.ts
|
|
1369
|
+
function Ge(e, t) {
|
|
1370
|
+
return !t.schema.inlineContentSchema[e.type] || s(e) && !("text" in e) ? !1 : o(e) ? !("content" in e) || !("href" in e) ? !1 : Ge(e.content, t) : !0;
|
|
1371
|
+
}
|
|
1372
|
+
function Ke(e, t, n) {
|
|
1373
|
+
let r = e.type || n, i = t.schema.blockSchema[r];
|
|
1374
|
+
if (!i) return {
|
|
1375
|
+
ok: !1,
|
|
1376
|
+
error: "block type not found in editor"
|
|
1377
|
+
};
|
|
1378
|
+
if (e.children, i.content === "none") {
|
|
1379
|
+
if (e.content) return {
|
|
1380
|
+
ok: !1,
|
|
1381
|
+
error: "block content not expected for this block type"
|
|
1382
|
+
};
|
|
1383
|
+
} else {
|
|
1384
|
+
if (!e.content) return {
|
|
1385
|
+
ok: !0,
|
|
1386
|
+
value: e
|
|
1387
|
+
};
|
|
1388
|
+
if (!Array.isArray(e.content)) return {
|
|
1389
|
+
ok: !1,
|
|
1390
|
+
error: "block content must be an array"
|
|
1391
|
+
};
|
|
1392
|
+
if (i.content === "table") return {
|
|
1393
|
+
ok: !0,
|
|
1394
|
+
value: e
|
|
1395
|
+
};
|
|
1396
|
+
if (!e.content.every((e) => Ge(e, t))) return {
|
|
1397
|
+
ok: !1,
|
|
1398
|
+
error: "block content must be an array of inline content"
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
return {
|
|
1402
|
+
ok: !0,
|
|
1403
|
+
value: e
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
//#endregion
|
|
1407
|
+
//#region src/api/formats/json/tools/index.ts
|
|
1408
|
+
var Z = {
|
|
1409
|
+
add: W({
|
|
1410
|
+
description: "Insert new blocks",
|
|
1411
|
+
schema: (e) => ({
|
|
1412
|
+
block: { $ref: "#/$defs/block" },
|
|
1413
|
+
...X(e.schema)
|
|
1414
|
+
}),
|
|
1415
|
+
validateBlock: Ke,
|
|
1416
|
+
rebaseTool: async (e, t) => J(t, q(t)),
|
|
1417
|
+
toJSONToolCall: async (e, t) => t.operation
|
|
1418
|
+
}),
|
|
1419
|
+
update: G({
|
|
1420
|
+
description: "Update a block, the new block will replace the existing block.",
|
|
1421
|
+
schema: (e) => ({
|
|
1422
|
+
block: { $ref: "#/$defs/block" },
|
|
1423
|
+
...X(e.schema)
|
|
1424
|
+
}),
|
|
1425
|
+
validateBlock: Ke,
|
|
1426
|
+
rebaseTool: async (e, t) => J(t, q(t)),
|
|
1427
|
+
toJSONToolCall: async (e, n) => {
|
|
1428
|
+
let r = Object.fromEntries(Object.entries(t).map(([e, t]) => [e, t.default]));
|
|
1429
|
+
return {
|
|
1430
|
+
...n.operation,
|
|
1431
|
+
block: {
|
|
1432
|
+
...n.operation.block,
|
|
1433
|
+
props: {
|
|
1434
|
+
...r,
|
|
1435
|
+
...n.operation.block.props
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
}),
|
|
1441
|
+
delete: K
|
|
1442
|
+
};
|
|
1443
|
+
//#endregion
|
|
1444
|
+
//#region src/api/formats/json/json.ts
|
|
1445
|
+
function qe(e, t, n, r, i) {
|
|
1446
|
+
if (typeof r == "boolean") {
|
|
1447
|
+
let t = r ? e.getSelectionCutBlocks(!0) : void 0;
|
|
1448
|
+
r = t ? {
|
|
1449
|
+
from: t._meta.startPos,
|
|
1450
|
+
to: t._meta.endPos
|
|
1451
|
+
} : void 0;
|
|
1452
|
+
}
|
|
1453
|
+
let a = n ?? {
|
|
1454
|
+
add: !0,
|
|
1455
|
+
update: !0,
|
|
1456
|
+
delete: !0
|
|
1457
|
+
};
|
|
1458
|
+
return [
|
|
1459
|
+
...a.update ? [Z.update(e, {
|
|
1460
|
+
idsSuffixed: !0,
|
|
1461
|
+
withDelays: t,
|
|
1462
|
+
updateSelection: r,
|
|
1463
|
+
onBlockUpdate: i
|
|
1464
|
+
})] : [],
|
|
1465
|
+
...a.add ? [Z.add(e, {
|
|
1466
|
+
idsSuffixed: !0,
|
|
1467
|
+
withDelays: t,
|
|
1468
|
+
onBlockUpdate: i
|
|
1469
|
+
})] : [],
|
|
1470
|
+
...a.delete ? [Z.delete(e, {
|
|
1471
|
+
idsSuffixed: !0,
|
|
1472
|
+
withDelays: t,
|
|
1473
|
+
onBlockUpdate: i
|
|
1474
|
+
})] : []
|
|
1475
|
+
];
|
|
1476
|
+
}
|
|
1477
|
+
var Je = {
|
|
1478
|
+
getStreamToolsProvider: (e = {}) => ({ getStreamTools: (t, n, r) => qe(t, e.withDelays ?? !0, e.defaultStreamTools, n, r) }),
|
|
1479
|
+
tools: Z,
|
|
1480
|
+
systemPrompt: "You're manipulating a text document using JSON blocks. \nMake sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $). \n\nIf the user requests updates to the document, use the \"applyDocumentOperations\" tool to update the document.\n---\nIF there is no selection active in the latest state, first, determine what part of the document the user is talking about. You SHOULD probably take cursor info into account if needed.\n EXAMPLE: if user says \"below\" (without pointing to a specific part of the document) he / she probably indicates the block(s) after the cursor. \n EXAMPLE: If you want to insert content AT the cursor position (UNLESS indicated otherwise by the user), then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`\n---\n ",
|
|
1481
|
+
defaultDocumentStateBuilder: I(async (e, t) => ({
|
|
1482
|
+
...t,
|
|
1483
|
+
id: void 0,
|
|
1484
|
+
children: void 0
|
|
1485
|
+
}))
|
|
1486
|
+
};
|
|
1487
|
+
//#endregion
|
|
1488
|
+
//#region src/api/formats/markdown-blocks/tools/rebaseTool.ts
|
|
1489
|
+
async function Ye(e, t) {
|
|
1490
|
+
let r = q(t), i = await t.blocksToMarkdownLossy([n(r.doc, e)]), a = V({
|
|
1491
|
+
id: e,
|
|
1492
|
+
block: (await t.tryParseMarkdownToBlocks(i))[0]
|
|
1493
|
+
}, r.doc), o = new re();
|
|
1494
|
+
for (let e of a) {
|
|
1495
|
+
let t = e.map(o);
|
|
1496
|
+
if (!t) throw Error("Failed to map step");
|
|
1497
|
+
r.step(t), o.appendMap(t.getMap());
|
|
1498
|
+
}
|
|
1499
|
+
return J(t, r);
|
|
1500
|
+
}
|
|
1501
|
+
//#endregion
|
|
1502
|
+
//#region src/api/formats/markdown-blocks/tools/validate.ts
|
|
1503
|
+
function Xe(e) {
|
|
1504
|
+
return typeof e == "string" ? {
|
|
1505
|
+
ok: !0,
|
|
1506
|
+
value: e
|
|
1507
|
+
} : {
|
|
1508
|
+
ok: !1,
|
|
1509
|
+
error: "block must be a string"
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
//#endregion
|
|
1513
|
+
//#region src/api/formats/markdown-blocks/tools/index.ts
|
|
1514
|
+
var Q = {
|
|
1515
|
+
add: W({
|
|
1516
|
+
description: "Insert new blocks",
|
|
1517
|
+
schema: {
|
|
1518
|
+
block: { $ref: "#/$defs/block" },
|
|
1519
|
+
$defs: { block: {
|
|
1520
|
+
type: "string",
|
|
1521
|
+
description: "markdown of block"
|
|
1522
|
+
} }
|
|
1523
|
+
},
|
|
1524
|
+
validateBlock: Xe,
|
|
1525
|
+
rebaseTool: Ye,
|
|
1526
|
+
toJSONToolCall: async (e, t) => {
|
|
1527
|
+
let n = await Promise.all(t.operation.blocks.map(async (t) => {
|
|
1528
|
+
let n = (await e.tryParseMarkdownToBlocks(t.trim()))[0];
|
|
1529
|
+
return delete n.id, n;
|
|
1530
|
+
}));
|
|
1531
|
+
return window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), {
|
|
1532
|
+
...t.operation,
|
|
1533
|
+
blocks: n
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
}),
|
|
1537
|
+
update: G({
|
|
1538
|
+
description: "Update a block, the new block will replace the existing block.",
|
|
1539
|
+
schema: {
|
|
1540
|
+
block: { $ref: "#/$defs/block" },
|
|
1541
|
+
$defs: { block: {
|
|
1542
|
+
type: "string",
|
|
1543
|
+
description: "markdown of block"
|
|
1544
|
+
} }
|
|
1545
|
+
},
|
|
1546
|
+
validateBlock: Xe,
|
|
1547
|
+
rebaseTool: Ye,
|
|
1548
|
+
toJSONToolCall: async (e, t) => {
|
|
1549
|
+
let n = (await e.tryParseMarkdownToBlocks(t.operation.block.trim()))[0];
|
|
1550
|
+
return delete n.id, window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = void 0), {
|
|
1551
|
+
...t.operation,
|
|
1552
|
+
block: n
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
}),
|
|
1556
|
+
delete: K
|
|
1557
|
+
};
|
|
1558
|
+
//#endregion
|
|
1559
|
+
//#region src/api/formats/markdown-blocks/markdownBlocks.ts
|
|
1560
|
+
function Ze(e, t, n, r, i) {
|
|
1561
|
+
if (typeof r == "boolean") {
|
|
1562
|
+
let t = r ? e.getSelectionCutBlocks(!0) : void 0;
|
|
1563
|
+
r = t ? {
|
|
1564
|
+
from: t._meta.startPos,
|
|
1565
|
+
to: t._meta.endPos
|
|
1566
|
+
} : void 0;
|
|
1567
|
+
}
|
|
1568
|
+
let a = n ?? {
|
|
1569
|
+
add: !0,
|
|
1570
|
+
update: !0,
|
|
1571
|
+
delete: !0
|
|
1572
|
+
};
|
|
1573
|
+
return [
|
|
1574
|
+
...a.update ? [Q.update(e, {
|
|
1575
|
+
idsSuffixed: !0,
|
|
1576
|
+
withDelays: t,
|
|
1577
|
+
updateSelection: r,
|
|
1578
|
+
onBlockUpdate: i
|
|
1579
|
+
})] : [],
|
|
1580
|
+
...a.add ? [Q.add(e, {
|
|
1581
|
+
idsSuffixed: !0,
|
|
1582
|
+
withDelays: t,
|
|
1583
|
+
onBlockUpdate: i
|
|
1584
|
+
})] : [],
|
|
1585
|
+
...a.delete ? [Q.delete(e, {
|
|
1586
|
+
idsSuffixed: !0,
|
|
1587
|
+
withDelays: t,
|
|
1588
|
+
onBlockUpdate: i
|
|
1589
|
+
})] : []
|
|
1590
|
+
];
|
|
1591
|
+
}
|
|
1592
|
+
//#endregion
|
|
1593
|
+
//#region src/api/formats/formats.ts
|
|
1594
|
+
var $ = {
|
|
1595
|
+
_experimental_json: Je,
|
|
1596
|
+
_experimental_markdown: {
|
|
1597
|
+
getStreamToolsProvider: (e = {}) => ({ getStreamTools: (t, n, r) => Ze(t, e.withDelays ?? !0, e.defaultStreamTools, n, r) }),
|
|
1598
|
+
systemPrompt: "You're manipulating a text document using Markdown blocks. \nMake sure to follow the json schema provided. When referencing ids they MUST be EXACTLY the same (including the trailing $). \nList items are 1 block with 1 list item each, so block content `- item1` is valid, but `- item1\n- item2` is invalid. We'll merge them automatically.\n\nIf the user requests updates to the document, use the \"applyDocumentOperations\" tool to update the document.\n---\nIF there is no selection active in the latest state, first, determine what part of the document the user is talking about. You SHOULD probably take cursor info into account if needed.\n EXAMPLE: if user says \"below\" (without pointing to a specific part of the document) he / she probably indicates the block(s) after the cursor. \n EXAMPLE: If you want to insert content AT the cursor position (UNLESS indicated otherwise by the user), then you need `referenceId` to point to the block before the cursor with position `after` (or block below and `before`\n---\n ",
|
|
1599
|
+
tools: Q,
|
|
1600
|
+
defaultDocumentStateBuilder: I(async (e, t) => e.blocksToMarkdownLossy([t]))
|
|
1601
|
+
},
|
|
1602
|
+
html: Le
|
|
1603
|
+
}, Qe = {
|
|
1604
|
+
addCursorPosition: M,
|
|
1605
|
+
flattenBlocks: P,
|
|
1606
|
+
suffixIDs: F,
|
|
1607
|
+
trimEmptyBlocks: T,
|
|
1608
|
+
convertBlocks: N
|
|
1609
|
+
};
|
|
1610
|
+
//#endregion
|
|
1611
|
+
//#region src/i18n/dictionary.ts
|
|
1612
|
+
function $e(e) {
|
|
1613
|
+
if (!e.dictionary.ai) throw Error("AI dictionary not found");
|
|
1614
|
+
return e.dictionary.ai;
|
|
1615
|
+
}
|
|
1616
|
+
//#endregion
|
|
1617
|
+
//#region src/blocknoteAIClient/client.ts
|
|
1618
|
+
var et = (e) => async (t, n) => {
|
|
1619
|
+
let r = new Request(t, n), i = e(r.url), a = new Request(i, {
|
|
1620
|
+
headers: r.headers,
|
|
1621
|
+
body: n?.body || r.body,
|
|
1622
|
+
method: r.method,
|
|
1623
|
+
duplex: "half"
|
|
1624
|
+
});
|
|
1625
|
+
return await fetch(a);
|
|
1626
|
+
};
|
|
1627
|
+
//#endregion
|
|
1628
|
+
export { E as _, q as a, j as c, O as d, he as f, ue as g, fe as h, $ as i, A as l, pe as m, $e as n, I as o, me as p, Qe as r, De as s, et as t, ge as u, le as v, se as y };
|
|
1629
|
+
|
|
1630
|
+
//# sourceMappingURL=server-JIYg7ELG.js.map
|