@copilotkit/react-textarea 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454
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/CHANGELOG.md +2456 -0
- package/README.md +46 -0
- package/dist/chunk-23Q6A46J.mjs +103 -0
- package/dist/chunk-23Q6A46J.mjs.map +1 -0
- package/dist/chunk-2C7O2EVM.mjs +27 -0
- package/dist/chunk-2C7O2EVM.mjs.map +1 -0
- package/dist/chunk-2QDCE7PD.mjs +32 -0
- package/dist/chunk-2QDCE7PD.mjs.map +1 -0
- package/dist/chunk-2VMZ5ZWT.mjs +229 -0
- package/dist/chunk-2VMZ5ZWT.mjs.map +1 -0
- package/dist/chunk-3PQ7GSFE.mjs +17 -0
- package/dist/chunk-3PQ7GSFE.mjs.map +1 -0
- package/dist/chunk-4CVSOOJY.mjs +30 -0
- package/dist/chunk-4CVSOOJY.mjs.map +1 -0
- package/dist/chunk-4NHVQZ67.mjs +108 -0
- package/dist/chunk-4NHVQZ67.mjs.map +1 -0
- package/dist/chunk-4PDYALMP.mjs +52 -0
- package/dist/chunk-4PDYALMP.mjs.map +1 -0
- package/dist/chunk-4XXU5BSA.mjs +125 -0
- package/dist/chunk-4XXU5BSA.mjs.map +1 -0
- package/dist/chunk-5UNJXFUO.mjs +29 -0
- package/dist/chunk-5UNJXFUO.mjs.map +1 -0
- package/dist/chunk-7L6GIHDM.mjs +39 -0
- package/dist/chunk-7L6GIHDM.mjs.map +1 -0
- package/dist/chunk-7LSRNPNI.mjs +59 -0
- package/dist/chunk-7LSRNPNI.mjs.map +1 -0
- package/dist/chunk-ABYCGF77.mjs +31 -0
- package/dist/chunk-ABYCGF77.mjs.map +1 -0
- package/dist/chunk-AJ5OMEXM.mjs +13 -0
- package/dist/chunk-AJ5OMEXM.mjs.map +1 -0
- package/dist/chunk-BNBGJBBM.mjs +60 -0
- package/dist/chunk-BNBGJBBM.mjs.map +1 -0
- package/dist/chunk-D47EKHIF.mjs +26 -0
- package/dist/chunk-D47EKHIF.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +1 -0
- package/dist/chunk-DE5K76I2.mjs.map +1 -0
- package/dist/chunk-DFTV4TST.mjs +36 -0
- package/dist/chunk-DFTV4TST.mjs.map +1 -0
- package/dist/chunk-DRV2FOHZ.mjs +70 -0
- package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
- package/dist/chunk-ECR45NSD.mjs +104 -0
- package/dist/chunk-ECR45NSD.mjs.map +1 -0
- package/dist/chunk-EJGGLWWR.mjs +82 -0
- package/dist/chunk-EJGGLWWR.mjs.map +1 -0
- package/dist/chunk-F6GMWOLE.mjs +93 -0
- package/dist/chunk-F6GMWOLE.mjs.map +1 -0
- package/dist/chunk-GQN2HYFJ.mjs +22 -0
- package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
- package/dist/chunk-H4VKQGVU.mjs +1 -0
- package/dist/chunk-H4VKQGVU.mjs.map +1 -0
- package/dist/chunk-HDBI2WN5.mjs +113 -0
- package/dist/chunk-HDBI2WN5.mjs.map +1 -0
- package/dist/chunk-I72DKFHD.mjs +114 -0
- package/dist/chunk-I72DKFHD.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +1 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-KMVGEY7Q.mjs +51 -0
- package/dist/chunk-KMVGEY7Q.mjs.map +1 -0
- package/dist/chunk-KNQIEOFP.mjs +19 -0
- package/dist/chunk-KNQIEOFP.mjs.map +1 -0
- package/dist/chunk-L7VVZH4Q.mjs +1 -0
- package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
- package/dist/chunk-LQ2OWQU7.mjs +49 -0
- package/dist/chunk-LQ2OWQU7.mjs.map +1 -0
- package/dist/chunk-LYB4B6MK.mjs +19 -0
- package/dist/chunk-LYB4B6MK.mjs.map +1 -0
- package/dist/chunk-MCNXIA4Q.mjs +75 -0
- package/dist/chunk-MCNXIA4Q.mjs.map +1 -0
- package/dist/chunk-MGYT7RNL.mjs +32 -0
- package/dist/chunk-MGYT7RNL.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +1 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +59 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-PZYM7K4Y.mjs +265 -0
- package/dist/chunk-PZYM7K4Y.mjs.map +1 -0
- package/dist/chunk-QFXR6DOA.mjs +64 -0
- package/dist/chunk-QFXR6DOA.mjs.map +1 -0
- package/dist/chunk-QJNFNPWH.mjs +85 -0
- package/dist/chunk-QJNFNPWH.mjs.map +1 -0
- package/dist/chunk-RUV6NBIF.mjs +1 -0
- package/dist/chunk-RUV6NBIF.mjs.map +1 -0
- package/dist/chunk-RXV67GJN.mjs +168 -0
- package/dist/chunk-RXV67GJN.mjs.map +1 -0
- package/dist/chunk-T6MTDQZ7.mjs +45 -0
- package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
- package/dist/chunk-VSVQZUPW.mjs +124 -0
- package/dist/chunk-VSVQZUPW.mjs.map +1 -0
- package/dist/chunk-WADHCMPK.mjs +1 -0
- package/dist/chunk-WADHCMPK.mjs.map +1 -0
- package/dist/chunk-WGWQRALG.mjs +83 -0
- package/dist/chunk-WGWQRALG.mjs.map +1 -0
- package/dist/chunk-WJHSY5T6.mjs +1 -0
- package/dist/chunk-WJHSY5T6.mjs.map +1 -0
- package/dist/chunk-XW3ICO4S.mjs +25 -0
- package/dist/chunk-XW3ICO4S.mjs.map +1 -0
- package/dist/chunk-YLFAIYRY.mjs +50 -0
- package/dist/chunk-YLFAIYRY.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.css +9 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.css.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +43 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1795 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +40 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/render-element.d.ts +6 -0
- package/dist/components/base-copilot-textarea/render-element.js +75 -0
- package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-element.mjs +8 -0
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.d.ts +6 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js +72 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +8 -0
- package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.ts +8 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +112 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +9 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.d.ts +3 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js +83 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +8 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.css +9 -0
- package/dist/components/copilot-textarea/copilot-textarea.css.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.d.ts +171 -0
- package/dist/components/copilot-textarea/copilot-textarea.js +2289 -0
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.mjs +49 -0
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +18 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.js +44 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +10 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +18 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js +174 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +16 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +12 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js +912 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +23 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +16 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +606 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +18 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +14 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +629 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +19 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +16 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +133 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +12 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +4 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +629 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +20 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -0
- package/dist/components/index.css +9 -0
- package/dist/components/index.css.map +1 -0
- package/dist/components/index.d.ts +15 -0
- package/dist/components/index.js +2293 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +53 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/components/manual-ui/chip-with-icon.d.ts +10 -0
- package/dist/components/manual-ui/chip-with-icon.js +38 -0
- package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
- package/dist/components/manual-ui/chip-with-icon.mjs +15 -0
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -0
- package/dist/components/source-search-box/source-search-box.d.ts +16 -0
- package/dist/components/source-search-box/source-search-box.js +240 -0
- package/dist/components/source-search-box/source-search-box.js.map +1 -0
- package/dist/components/source-search-box/source-search-box.mjs +13 -0
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -0
- package/dist/components/ui/button.d.ts +14 -0
- package/dist/components/ui/button.js +114 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/button.mjs +11 -0
- package/dist/components/ui/button.mjs.map +1 -0
- package/dist/components/ui/command.d.ts +53 -0
- package/dist/components/ui/command.js +285 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/command.mjs +26 -0
- package/dist/components/ui/command.mjs.map +1 -0
- package/dist/components/ui/dialog.d.ts +19 -0
- package/dist/components/ui/dialog.js +183 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dialog.mjs +21 -0
- package/dist/components/ui/dialog.mjs.map +1 -0
- package/dist/components/ui/label.d.ts +8 -0
- package/dist/components/ui/label.js +87 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/label.mjs +9 -0
- package/dist/components/ui/label.mjs.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +19 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +2 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +15 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +180 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +11 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.d.ts +8 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js +194 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +9 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.ts +7 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js +180 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +10 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +19 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +2 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +22 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +153 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +9 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +23 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +228 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +9 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -0
- package/dist/hooks/misc/use-autosize-textarea.d.ts +5 -0
- package/dist/hooks/misc/use-autosize-textarea.js +37 -0
- package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
- package/dist/hooks/misc/use-autosize-textarea.mjs +8 -0
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -0
- package/dist/index.css +644 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2298 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +64 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/debouncer.d.ts +11 -0
- package/dist/lib/debouncer.js +76 -0
- package/dist/lib/debouncer.js.map +1 -0
- package/dist/lib/debouncer.mjs +8 -0
- package/dist/lib/debouncer.mjs.map +1 -0
- package/dist/lib/editor-to-text.d.ts +7 -0
- package/dist/lib/editor-to-text.js +69 -0
- package/dist/lib/editor-to-text.js.map +1 -0
- package/dist/lib/editor-to-text.mjs +8 -0
- package/dist/lib/editor-to-text.mjs.map +1 -0
- package/dist/lib/get-text-around-cursor.d.ts +15 -0
- package/dist/lib/get-text-around-cursor.js +131 -0
- package/dist/lib/get-text-around-cursor.js.map +1 -0
- package/dist/lib/get-text-around-cursor.mjs +14 -0
- package/dist/lib/get-text-around-cursor.mjs.map +1 -0
- package/dist/lib/retry.d.ts +3 -0
- package/dist/lib/retry.js +43 -0
- package/dist/lib/retry.js.map +1 -0
- package/dist/lib/retry.mjs +8 -0
- package/dist/lib/retry.mjs.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.d.ts +8 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js +51 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +8 -0
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.d.ts +8 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js +46 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +8 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.d.ts +5 -0
- package/dist/lib/slatejs-edits/replace-text.js +53 -0
- package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.mjs +8 -0
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.d.ts +8 -0
- package/dist/lib/slatejs-edits/with-partial-history.js +133 -0
- package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.mjs +10 -0
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -0
- package/dist/lib/stream-promise-flatten.d.ts +12 -0
- package/dist/lib/stream-promise-flatten.js +72 -0
- package/dist/lib/stream-promise-flatten.js.map +1 -0
- package/dist/lib/stream-promise-flatten.mjs +8 -0
- package/dist/lib/stream-promise-flatten.mjs.map +1 -0
- package/dist/lib/utils.d.ts +9 -0
- package/dist/lib/utils.js +94 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.mjs +16 -0
- package/dist/lib/utils.mjs.map +1 -0
- package/dist/lib/utils.test.d.ts +2 -0
- package/dist/lib/utils.test.js +9 -0
- package/dist/lib/utils.test.js.map +1 -0
- package/dist/lib/utils.test.mjs +7 -0
- package/dist/lib/utils.test.mjs.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +23 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +19 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +20 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js +287 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +13 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.d.ts +15 -0
- package/dist/types/autosuggestions-config/editing-api-config.js +108 -0
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.mjs +12 -0
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -0
- package/dist/types/autosuggestions-config/index.d.ts +10 -0
- package/dist/types/autosuggestions-config/index.js +287 -0
- package/dist/types/autosuggestions-config/index.js.map +1 -0
- package/dist/types/autosuggestions-config/index.mjs +14 -0
- package/dist/types/autosuggestions-config/index.mjs.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.d.ts +15 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js +101 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +12 -0
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +3 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +19 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +15 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js +90 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +12 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -0
- package/dist/types/base/autosuggestion-state.d.ts +8 -0
- package/dist/types/base/autosuggestion-state.js +19 -0
- package/dist/types/base/autosuggestion-state.js.map +1 -0
- package/dist/types/base/autosuggestion-state.mjs +1 -0
- package/dist/types/base/autosuggestion-state.mjs.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.d.ts +19 -0
- package/dist/types/base/autosuggestions-bare-function.js +19 -0
- package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.mjs +1 -0
- package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -0
- package/dist/types/base/base-autosuggestions-config.d.ts +83 -0
- package/dist/types/base/base-autosuggestions-config.js +54 -0
- package/dist/types/base/base-autosuggestions-config.js.map +1 -0
- package/dist/types/base/base-autosuggestions-config.mjs +8 -0
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -0
- package/dist/types/base/base-copilot-textarea-props.d.ts +5 -0
- package/dist/types/base/base-copilot-textarea-props.js +19 -0
- package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
- package/dist/types/base/base-copilot-textarea-props.mjs +1 -0
- package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -0
- package/dist/types/base/custom-editor.d.ts +29 -0
- package/dist/types/base/custom-editor.js +19 -0
- package/dist/types/base/custom-editor.js.map +1 -0
- package/dist/types/base/custom-editor.mjs +1 -0
- package/dist/types/base/custom-editor.mjs.map +1 -0
- package/dist/types/base/editor-autocomplete-state.d.ts +10 -0
- package/dist/types/base/editor-autocomplete-state.js +40 -0
- package/dist/types/base/editor-autocomplete-state.js.map +1 -0
- package/dist/types/base/editor-autocomplete-state.mjs +9 -0
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -0
- package/dist/types/base/index.d.ts +54 -0
- package/dist/types/base/index.js +56 -0
- package/dist/types/base/index.js.map +1 -0
- package/dist/types/base/index.mjs +9 -0
- package/dist/types/base/index.mjs.map +1 -0
- package/dist/types/html-copilot-textarea-element.d.ts +7 -0
- package/dist/types/html-copilot-textarea-element.js +19 -0
- package/dist/types/html-copilot-textarea-element.js.map +1 -0
- package/dist/types/html-copilot-textarea-element.mjs +2 -0
- package/dist/types/html-copilot-textarea-element.mjs.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +289 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +19 -0
- package/dist/types/index.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +95 -0
- package/postcss.config.js +12 -0
- package/src/components/base-copilot-textarea/base-copilot-textarea.css +9 -0
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +317 -0
- package/src/components/base-copilot-textarea/render-element.tsx +39 -0
- package/src/components/base-copilot-textarea/render-placeholder.tsx +23 -0
- package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +80 -0
- package/src/components/base-copilot-textarea/use-add-branding-css.tsx +74 -0
- package/src/components/copilot-textarea/copilot-textarea.tsx +210 -0
- package/src/components/hovering-toolbar/hovering-editor-provider.tsx +31 -0
- package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +100 -0
- package/src/components/hovering-toolbar/hovering-toolbar.tsx +151 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +276 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +31 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +55 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/index.ts +2 -0
- package/src/components/index.ts +4 -0
- package/src/components/manual-ui/chip-with-icon.tsx +17 -0
- package/src/components/source-search-box/source-search-box.tsx +117 -0
- package/src/components/ui/button.tsx +49 -0
- package/src/components/ui/command.tsx +141 -0
- package/src/components/ui/dialog.tsx +107 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/context/index.ts +1 -0
- package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +142 -0
- package/src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx +100 -0
- package/src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts +93 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +114 -0
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +214 -0
- package/src/hooks/misc/use-autosize-textarea.tsx +18 -0
- package/src/index.tsx +7 -0
- package/src/lib/debouncer.ts +36 -0
- package/src/lib/editor-to-text.ts +61 -0
- package/src/lib/get-text-around-cursor.ts +135 -0
- package/src/lib/retry.tsx +23 -0
- package/src/lib/slatejs-edits/add-autocompletions.ts +30 -0
- package/src/lib/slatejs-edits/clear-autocompletions.ts +19 -0
- package/src/lib/slatejs-edits/replace-text.ts +28 -0
- package/src/lib/slatejs-edits/with-partial-history.ts +149 -0
- package/src/lib/stream-promise-flatten.ts +33 -0
- package/src/lib/utils.test.ts +7 -0
- package/src/lib/utils.ts +49 -0
- package/src/styles.css +3 -0
- package/src/types/autosuggestions-config/autosuggestions-config-user-specified.tsx +19 -0
- package/src/types/autosuggestions-config/autosuggestions-config.tsx +30 -0
- package/src/types/autosuggestions-config/editing-api-config.tsx +96 -0
- package/src/types/autosuggestions-config/index.ts +8 -0
- package/src/types/autosuggestions-config/insertions-api-config.tsx +87 -0
- package/src/types/autosuggestions-config/subtypes/make-system-prompt.ts +1 -0
- package/src/types/autosuggestions-config/suggestions-api-config.tsx +76 -0
- package/src/types/base/autosuggestion-state.ts +6 -0
- package/src/types/base/autosuggestions-bare-function.ts +30 -0
- package/src/types/base/base-autosuggestions-config.tsx +123 -0
- package/src/types/base/base-copilot-textarea-props.tsx +58 -0
- package/src/types/base/custom-editor.tsx +29 -0
- package/src/types/base/editor-autocomplete-state.ts +20 -0
- package/src/types/base/index.ts +6 -0
- package/src/types/html-copilot-textarea-element.ts +5 -0
- package/src/types/index.ts +3 -0
- package/tailwind.config.js +9 -0
- package/tsconfig.json +12 -0
- package/tsup.config.ts +16 -0
- package/typedoc.json +4 -0
package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
2
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import { AutosuggestionsBareFunction } from "../../types";
|
|
5
|
+
import { retry } from "../../lib/retry";
|
|
6
|
+
import { InsertionEditorState } from "../../types/base/autosuggestions-bare-function";
|
|
7
|
+
import { SuggestionsApiConfig } from "../../types/autosuggestions-config/suggestions-api-config";
|
|
8
|
+
import {
|
|
9
|
+
Message,
|
|
10
|
+
Role,
|
|
11
|
+
TextMessage,
|
|
12
|
+
convertGqlOutputToMessages,
|
|
13
|
+
convertMessagesToGqlInput,
|
|
14
|
+
filterAgentStateMessages,
|
|
15
|
+
CopilotRequestType,
|
|
16
|
+
} from "@copilotkit/runtime-client-gql";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
20
|
+
* The function takes in the text before and after the cursor, and an abort signal.
|
|
21
|
+
* It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.
|
|
22
|
+
* The function returns the suggestion from the API response.
|
|
23
|
+
*
|
|
24
|
+
* @param textareaPurpose - The purpose of the textarea. This is included in the system message.
|
|
25
|
+
* @param apiEndpoint - The API endpoint to send the autosuggestion request to.
|
|
26
|
+
* @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.
|
|
27
|
+
* @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.
|
|
28
|
+
* @param contextCategories - The categories of context strings we want to include. By default, we include the (default) "global" context category.
|
|
29
|
+
* @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
30
|
+
*/
|
|
31
|
+
export function useMakeStandardAutosuggestionFunction(
|
|
32
|
+
textareaPurpose: string,
|
|
33
|
+
contextCategories: string[],
|
|
34
|
+
apiConfig: SuggestionsApiConfig,
|
|
35
|
+
): AutosuggestionsBareFunction {
|
|
36
|
+
const { getContextString, copilotApiConfig, runtimeClient } = useCopilotContext();
|
|
37
|
+
const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
|
|
38
|
+
const headers = {
|
|
39
|
+
...copilotApiConfig.headers,
|
|
40
|
+
...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),
|
|
41
|
+
};
|
|
42
|
+
const { maxTokens, stop, temperature = 0 } = apiConfig;
|
|
43
|
+
|
|
44
|
+
return useCallback(
|
|
45
|
+
async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {
|
|
46
|
+
const res = await retry(async () => {
|
|
47
|
+
// @ts-expect-error -- Passing null is forbidden, but we're filtering it later
|
|
48
|
+
const messages: Message[] = [
|
|
49
|
+
new TextMessage({
|
|
50
|
+
role: Role.System,
|
|
51
|
+
content: apiConfig.makeSystemPrompt(
|
|
52
|
+
textareaPurpose,
|
|
53
|
+
getContextString([], contextCategories),
|
|
54
|
+
),
|
|
55
|
+
}),
|
|
56
|
+
...apiConfig.fewShotMessages,
|
|
57
|
+
editorState.textAfterCursor != ""
|
|
58
|
+
? new TextMessage({
|
|
59
|
+
role: Role.User,
|
|
60
|
+
content: editorState.textAfterCursor,
|
|
61
|
+
})
|
|
62
|
+
: null,
|
|
63
|
+
new TextMessage({
|
|
64
|
+
role: Role.User,
|
|
65
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
|
|
66
|
+
}),
|
|
67
|
+
new TextMessage({
|
|
68
|
+
role: Role.User,
|
|
69
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
|
|
70
|
+
}),
|
|
71
|
+
].filter(Boolean);
|
|
72
|
+
|
|
73
|
+
const response = await runtimeClient
|
|
74
|
+
.generateCopilotResponse({
|
|
75
|
+
data: {
|
|
76
|
+
frontend: {
|
|
77
|
+
actions: [],
|
|
78
|
+
url: window.location.href,
|
|
79
|
+
},
|
|
80
|
+
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
81
|
+
metadata: {
|
|
82
|
+
requestType: CopilotRequestType.TextareaCompletion,
|
|
83
|
+
},
|
|
84
|
+
forwardedParameters: {
|
|
85
|
+
maxTokens,
|
|
86
|
+
stop,
|
|
87
|
+
temperature,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
properties,
|
|
91
|
+
signal: abortSignal,
|
|
92
|
+
})
|
|
93
|
+
.toPromise();
|
|
94
|
+
|
|
95
|
+
let result = "";
|
|
96
|
+
for (const message of convertGqlOutputToMessages(
|
|
97
|
+
response.data?.generateCopilotResponse?.messages ?? [],
|
|
98
|
+
)) {
|
|
99
|
+
if (abortSignal.aborted) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (message.isTextMessage()) {
|
|
103
|
+
result += message.content;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return result;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return res;
|
|
111
|
+
},
|
|
112
|
+
[apiConfig, getContextString, contextCategories, textareaPurpose],
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
2
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import {
|
|
5
|
+
CopilotRuntimeClient,
|
|
6
|
+
Message,
|
|
7
|
+
Role,
|
|
8
|
+
TextMessage,
|
|
9
|
+
convertGqlOutputToMessages,
|
|
10
|
+
convertMessagesToGqlInput,
|
|
11
|
+
filterAgentStateMessages,
|
|
12
|
+
CopilotRequestType,
|
|
13
|
+
} from "@copilotkit/runtime-client-gql";
|
|
14
|
+
import { retry } from "../../lib/retry";
|
|
15
|
+
import {
|
|
16
|
+
EditingEditorState,
|
|
17
|
+
Generator_InsertionOrEditingSuggestion,
|
|
18
|
+
} from "../../types/base/autosuggestions-bare-function";
|
|
19
|
+
import { InsertionsApiConfig } from "../../types/autosuggestions-config/insertions-api-config";
|
|
20
|
+
import { EditingApiConfig } from "../../types/autosuggestions-config/editing-api-config";
|
|
21
|
+
import { DocumentPointer } from "@copilotkit/react-core";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
25
|
+
* The function takes in the text before and after the cursor, and an abort signal.
|
|
26
|
+
* It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.
|
|
27
|
+
* The function returns the suggestion from the API response.
|
|
28
|
+
*
|
|
29
|
+
* @param textareaPurpose - The purpose of the textarea. This is included in the system message.
|
|
30
|
+
* @param apiEndpoint - The API endpoint to send the autosuggestion request to.
|
|
31
|
+
* @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.
|
|
32
|
+
* @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.
|
|
33
|
+
* @param contextCategories - The categories of context strings we want to include. By default, we include the (default) "global" context category.
|
|
34
|
+
* @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
35
|
+
*/
|
|
36
|
+
export function useMakeStandardInsertionOrEditingFunction(
|
|
37
|
+
textareaPurpose: string,
|
|
38
|
+
contextCategories: string[],
|
|
39
|
+
insertionApiConfig: InsertionsApiConfig,
|
|
40
|
+
editingApiConfig: EditingApiConfig,
|
|
41
|
+
): Generator_InsertionOrEditingSuggestion {
|
|
42
|
+
const { getContextString, copilotApiConfig, runtimeClient } = useCopilotContext();
|
|
43
|
+
const headers = {
|
|
44
|
+
...(copilotApiConfig.publicApiKey
|
|
45
|
+
? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }
|
|
46
|
+
: {}),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
async function runtimeClientResponseToStringStream(
|
|
50
|
+
responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,
|
|
51
|
+
) {
|
|
52
|
+
const messagesStream = runtimeClient.asStream(responsePromise);
|
|
53
|
+
|
|
54
|
+
return new ReadableStream({
|
|
55
|
+
async start(controller) {
|
|
56
|
+
const reader = messagesStream.getReader();
|
|
57
|
+
let sentContent = "";
|
|
58
|
+
|
|
59
|
+
while (true) {
|
|
60
|
+
const { done, value } = await reader.read();
|
|
61
|
+
if (done) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);
|
|
66
|
+
|
|
67
|
+
let newContent = "";
|
|
68
|
+
|
|
69
|
+
for (const message of messages) {
|
|
70
|
+
if (message.isTextMessage()) {
|
|
71
|
+
newContent += message.content;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (newContent) {
|
|
75
|
+
const contentToSend = newContent.slice(sentContent.length);
|
|
76
|
+
controller.enqueue(contentToSend);
|
|
77
|
+
sentContent += contentToSend;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
controller.close();
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const insertionFunction = useCallback(
|
|
86
|
+
async (
|
|
87
|
+
editorState: EditingEditorState,
|
|
88
|
+
insertionPrompt: string,
|
|
89
|
+
documents: DocumentPointer[],
|
|
90
|
+
abortSignal: AbortSignal,
|
|
91
|
+
) => {
|
|
92
|
+
const res = await retry(async () => {
|
|
93
|
+
const messages: Message[] = [
|
|
94
|
+
new TextMessage({
|
|
95
|
+
role: Role.System,
|
|
96
|
+
content: insertionApiConfig.makeSystemPrompt(
|
|
97
|
+
textareaPurpose,
|
|
98
|
+
getContextString(documents, contextCategories),
|
|
99
|
+
),
|
|
100
|
+
}),
|
|
101
|
+
...insertionApiConfig.fewShotMessages,
|
|
102
|
+
new TextMessage({
|
|
103
|
+
role: Role.User,
|
|
104
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
|
|
105
|
+
}),
|
|
106
|
+
new TextMessage({
|
|
107
|
+
role: Role.User,
|
|
108
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
|
|
109
|
+
}),
|
|
110
|
+
new TextMessage({
|
|
111
|
+
role: Role.User,
|
|
112
|
+
content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`,
|
|
113
|
+
}),
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
return runtimeClientResponseToStringStream(
|
|
117
|
+
runtimeClient.generateCopilotResponse({
|
|
118
|
+
data: {
|
|
119
|
+
frontend: {
|
|
120
|
+
actions: [],
|
|
121
|
+
url: window.location.href,
|
|
122
|
+
},
|
|
123
|
+
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
124
|
+
metadata: {
|
|
125
|
+
requestType: CopilotRequestType.TextareaCompletion,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
properties: copilotApiConfig.properties,
|
|
129
|
+
signal: abortSignal,
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return res;
|
|
135
|
+
},
|
|
136
|
+
[insertionApiConfig, getContextString, contextCategories, textareaPurpose],
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const editingFunction = useCallback(
|
|
140
|
+
async (
|
|
141
|
+
editorState: EditingEditorState,
|
|
142
|
+
editingPrompt: string,
|
|
143
|
+
documents: DocumentPointer[],
|
|
144
|
+
abortSignal: AbortSignal,
|
|
145
|
+
) => {
|
|
146
|
+
const res = await retry(async () => {
|
|
147
|
+
const messages: Message[] = [
|
|
148
|
+
new TextMessage({
|
|
149
|
+
role: Role.System,
|
|
150
|
+
content: editingApiConfig.makeSystemPrompt(
|
|
151
|
+
textareaPurpose,
|
|
152
|
+
getContextString(documents, contextCategories),
|
|
153
|
+
),
|
|
154
|
+
}),
|
|
155
|
+
...editingApiConfig.fewShotMessages,
|
|
156
|
+
new TextMessage({
|
|
157
|
+
role: Role.User,
|
|
158
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
|
|
159
|
+
}),
|
|
160
|
+
new TextMessage({
|
|
161
|
+
role: Role.User,
|
|
162
|
+
content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`,
|
|
163
|
+
}),
|
|
164
|
+
new TextMessage({
|
|
165
|
+
role: Role.User,
|
|
166
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
|
|
167
|
+
}),
|
|
168
|
+
new TextMessage({
|
|
169
|
+
role: Role.User,
|
|
170
|
+
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`,
|
|
171
|
+
}),
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
return runtimeClientResponseToStringStream(
|
|
175
|
+
runtimeClient.generateCopilotResponse({
|
|
176
|
+
data: {
|
|
177
|
+
frontend: {
|
|
178
|
+
actions: [],
|
|
179
|
+
url: window.location.href,
|
|
180
|
+
},
|
|
181
|
+
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
182
|
+
metadata: {
|
|
183
|
+
requestType: CopilotRequestType.TextareaCompletion,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
properties: copilotApiConfig.properties,
|
|
187
|
+
signal: abortSignal,
|
|
188
|
+
}),
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
return res;
|
|
193
|
+
},
|
|
194
|
+
[editingApiConfig, getContextString, contextCategories, textareaPurpose],
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const insertionOrEditingFunction = useCallback(
|
|
198
|
+
async (
|
|
199
|
+
editorState: EditingEditorState,
|
|
200
|
+
insertionPrompt: string,
|
|
201
|
+
documents: DocumentPointer[],
|
|
202
|
+
abortSignal: AbortSignal,
|
|
203
|
+
) => {
|
|
204
|
+
if (editorState.selectedText === "") {
|
|
205
|
+
return await insertionFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
206
|
+
} else {
|
|
207
|
+
return await editingFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
[insertionFunction, editingFunction],
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
return insertionOrEditingFunction;
|
|
214
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Ref, RefObject, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
// Updates the height of a <textarea> when the value changes.
|
|
4
|
+
const useAutosizeTextArea = (textAreaRef: RefObject<HTMLTextAreaElement>, value: string) => {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (textAreaRef.current !== null) {
|
|
7
|
+
// We need to reset the height momentarily to get the correct scrollHeight for the textarea
|
|
8
|
+
textAreaRef.current.style.height = "0px";
|
|
9
|
+
const scrollHeight = textAreaRef.current.scrollHeight;
|
|
10
|
+
|
|
11
|
+
// We then set the height directly, outside of the render loop
|
|
12
|
+
// Trying to set this with state or a ref will product an incorrect value.
|
|
13
|
+
textAreaRef.current.style.height = scrollHeight + "px";
|
|
14
|
+
}
|
|
15
|
+
}, [textAreaRef, value]);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default useAutosizeTextArea;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type AsyncFunction<T extends any[]> = (...args: [...T, AbortSignal]) => Promise<void>;
|
|
2
|
+
|
|
3
|
+
export class Debouncer<T extends any[]> {
|
|
4
|
+
private timeoutId?: ReturnType<typeof setTimeout>;
|
|
5
|
+
private activeAbortController?: AbortController;
|
|
6
|
+
|
|
7
|
+
constructor(private wait: number) {}
|
|
8
|
+
|
|
9
|
+
debounce = async (func: AsyncFunction<T>, ...args: T) => {
|
|
10
|
+
// Abort the previous promise immediately
|
|
11
|
+
this.cancel();
|
|
12
|
+
|
|
13
|
+
this.timeoutId = setTimeout(async () => {
|
|
14
|
+
try {
|
|
15
|
+
this.activeAbortController = new AbortController();
|
|
16
|
+
|
|
17
|
+
// Pass the signal to the async function, assuming it supports it
|
|
18
|
+
await func(...args, this.activeAbortController.signal);
|
|
19
|
+
|
|
20
|
+
this.activeAbortController = undefined;
|
|
21
|
+
} catch (error) {}
|
|
22
|
+
}, this.wait);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
cancel = () => {
|
|
26
|
+
if (this.activeAbortController) {
|
|
27
|
+
this.activeAbortController.abort();
|
|
28
|
+
this.activeAbortController = undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.timeoutId !== undefined) {
|
|
32
|
+
clearTimeout(this.timeoutId);
|
|
33
|
+
this.timeoutId = undefined;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BaseEditor, Descendant, Element } from "slate";
|
|
2
|
+
import { HistoryEditor } from "slate-history";
|
|
3
|
+
import { ReactEditor } from "slate-react";
|
|
4
|
+
import { SuggestionAwareText } from "../types/base/custom-editor";
|
|
5
|
+
|
|
6
|
+
function nodeChildrenToTextComponents(
|
|
7
|
+
editor: BaseEditor & ReactEditor & HistoryEditor,
|
|
8
|
+
nodes: Descendant[],
|
|
9
|
+
): SuggestionAwareText[] {
|
|
10
|
+
// find inlineable elements
|
|
11
|
+
const indeciesOfInlineElements = new Set(
|
|
12
|
+
nodes
|
|
13
|
+
.map((node, index) => {
|
|
14
|
+
if (Element.isElement(node) && editor.isInline(node)) {
|
|
15
|
+
return index;
|
|
16
|
+
}
|
|
17
|
+
return -1;
|
|
18
|
+
})
|
|
19
|
+
.filter((index) => index !== -1),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// ignorable elements = inline elements,
|
|
23
|
+
// or neighbors of inline elements that are {text: ""}
|
|
24
|
+
const nonIgnorableItems = nodes.filter((node, index) => {
|
|
25
|
+
const isInline = indeciesOfInlineElements.has(index);
|
|
26
|
+
if (isInline) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isNeighbourOfInline =
|
|
31
|
+
indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
|
|
32
|
+
if (isNeighbourOfInline) {
|
|
33
|
+
return (node as any).text !== "";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return nonIgnorableItems
|
|
40
|
+
.map((node) => {
|
|
41
|
+
if (Element.isElement(node)) {
|
|
42
|
+
switch (node.type) {
|
|
43
|
+
case "paragraph":
|
|
44
|
+
return nodeChildrenToTextComponents(editor, node.children);
|
|
45
|
+
case "suggestion":
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
return [node];
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.reduce((acc, val) => acc.concat(val), []);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const editorToText = (editor: BaseEditor & ReactEditor & HistoryEditor) => {
|
|
56
|
+
const flattened = nodeChildrenToTextComponents(editor, editor.children);
|
|
57
|
+
|
|
58
|
+
const text = flattened.map((textComponent) => textComponent.text).join("\n");
|
|
59
|
+
|
|
60
|
+
return text;
|
|
61
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from "slate";
|
|
2
|
+
import { EditorAutocompleteState } from "../types/base/editor-autocomplete-state";
|
|
3
|
+
|
|
4
|
+
export interface EditorTextState {
|
|
5
|
+
selection: BaseRange;
|
|
6
|
+
|
|
7
|
+
textBeforeCursor: string;
|
|
8
|
+
selectedText: string;
|
|
9
|
+
textAfterCursor: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {
|
|
13
|
+
const { selection } = editor;
|
|
14
|
+
if (!selection || !Range.isCollapsed(selection)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const cursorPoint = selection.anchor;
|
|
19
|
+
|
|
20
|
+
// Create two ranges: one before the anchor and one after
|
|
21
|
+
const beforeRange: Range = {
|
|
22
|
+
anchor: Editor.start(editor, []),
|
|
23
|
+
focus: cursorPoint,
|
|
24
|
+
};
|
|
25
|
+
const afterRange: Range = {
|
|
26
|
+
anchor: cursorPoint,
|
|
27
|
+
focus: Editor.end(editor, []),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Extract text for these ranges
|
|
31
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
32
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
cursorPoint: cursorPoint,
|
|
36
|
+
textBeforeCursor: before,
|
|
37
|
+
textAfterCursor: after,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getTextAroundSelection(editor: Editor): EditorTextState | null {
|
|
42
|
+
const { selection } = editor;
|
|
43
|
+
if (!selection) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const wellOrderedSelection = wellOrderedRange(selection);
|
|
48
|
+
|
|
49
|
+
// Create two ranges: one before the anchor and one after
|
|
50
|
+
const beforeRange: Range = {
|
|
51
|
+
anchor: Editor.start(editor, []),
|
|
52
|
+
focus: wellOrderedSelection.anchor,
|
|
53
|
+
};
|
|
54
|
+
const afterRange: Range = {
|
|
55
|
+
anchor: wellOrderedSelection.focus,
|
|
56
|
+
focus: Editor.end(editor, []),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Extract text for these ranges
|
|
60
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
61
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
62
|
+
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
selection: wellOrderedSelection,
|
|
66
|
+
textBeforeCursor: before,
|
|
67
|
+
selectedText,
|
|
68
|
+
textAfterCursor: after,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function getFullEditorTextWithNewlines(editor: Editor): string {
|
|
73
|
+
const fullDocumentRange: Range = {
|
|
74
|
+
anchor: Editor.start(editor, []),
|
|
75
|
+
focus: Editor.end(editor, []),
|
|
76
|
+
};
|
|
77
|
+
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Helper function to extract text with newlines
|
|
81
|
+
export function extractTextWithNewlines(editor: Editor, range: Range): string {
|
|
82
|
+
const voids = false;
|
|
83
|
+
const [start, end] = Range.edges(range);
|
|
84
|
+
let text = "";
|
|
85
|
+
let lastBlock: Node | null = null;
|
|
86
|
+
|
|
87
|
+
for (const [node, path] of Editor.nodes(editor, {
|
|
88
|
+
at: range,
|
|
89
|
+
match: Text.isText,
|
|
90
|
+
voids,
|
|
91
|
+
})) {
|
|
92
|
+
let t = node.text;
|
|
93
|
+
|
|
94
|
+
// Determine the parent block of the current text node
|
|
95
|
+
const [block] = Editor.above(editor, {
|
|
96
|
+
at: path,
|
|
97
|
+
match: (n) => Element.isElement(n) && n.type === "paragraph",
|
|
98
|
+
}) || [null];
|
|
99
|
+
|
|
100
|
+
// If we encounter a new block, prepend a newline
|
|
101
|
+
if (lastBlock !== block && block) {
|
|
102
|
+
// check that lastBlock is not null to avoid adding a newline at the beginning
|
|
103
|
+
if (lastBlock) {
|
|
104
|
+
text += "\n";
|
|
105
|
+
}
|
|
106
|
+
lastBlock = block;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Path.equals(path, end.path)) {
|
|
110
|
+
t = t.slice(0, end.offset);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (Path.equals(path, start.path)) {
|
|
114
|
+
t = t.slice(start.offset);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
text += t;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return text;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function wellOrderedRange(range: BaseRange): BaseRange {
|
|
124
|
+
const { anchor, focus } = range;
|
|
125
|
+
// if anchor is before focus, return range as is
|
|
126
|
+
if (Point.isBefore(anchor, focus)) {
|
|
127
|
+
return range;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// if focus is before anchor, return range with anchor and focus swapped
|
|
131
|
+
return {
|
|
132
|
+
anchor: focus,
|
|
133
|
+
focus: anchor,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function retry<T>(
|
|
2
|
+
fn: () => Promise<T>,
|
|
3
|
+
retriesLeft: number = 2,
|
|
4
|
+
interval: number = 200,
|
|
5
|
+
backoff: number = 1.5,
|
|
6
|
+
): Promise<T> {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
fn()
|
|
9
|
+
.then(resolve)
|
|
10
|
+
.catch((error) => {
|
|
11
|
+
if (retriesLeft === 1) {
|
|
12
|
+
reject(error);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff)
|
|
18
|
+
.then(resolve)
|
|
19
|
+
.catch(reject);
|
|
20
|
+
}, interval);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BasePoint, Transforms } from "slate";
|
|
2
|
+
import { CustomEditor } from "../../types/base/custom-editor";
|
|
3
|
+
|
|
4
|
+
export function addAutocompletionsToEditor(
|
|
5
|
+
editor: CustomEditor,
|
|
6
|
+
newSuggestion: string,
|
|
7
|
+
point: BasePoint,
|
|
8
|
+
) {
|
|
9
|
+
const editorPosition = editor.selection;
|
|
10
|
+
|
|
11
|
+
Transforms.insertNodes(
|
|
12
|
+
editor,
|
|
13
|
+
[
|
|
14
|
+
{
|
|
15
|
+
type: "suggestion",
|
|
16
|
+
inline: true,
|
|
17
|
+
content: newSuggestion,
|
|
18
|
+
children: [{ text: "" }],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
{
|
|
22
|
+
at: point,
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// restore cursor position
|
|
27
|
+
if (editorPosition) {
|
|
28
|
+
editor.selection = editorPosition;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Element, Node, Path, Transforms } from "slate";
|
|
2
|
+
import { CustomEditor } from "../../types/base/custom-editor";
|
|
3
|
+
|
|
4
|
+
export function clearAutocompletionsFromEditor(editor: CustomEditor) {
|
|
5
|
+
// clear previous suggestion
|
|
6
|
+
const paths: Path[] = [];
|
|
7
|
+
for (const [node, path] of Node.nodes(editor)) {
|
|
8
|
+
if (Element.isElement(node) && node.type === "suggestion") {
|
|
9
|
+
paths.push(path);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (const path of paths) {
|
|
13
|
+
try {
|
|
14
|
+
Transforms.removeNodes(editor, { at: path });
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Editor, Transforms } from "slate";
|
|
2
|
+
|
|
3
|
+
export function replaceEditorText(editor: Editor, newText: string) {
|
|
4
|
+
// clear all previous text
|
|
5
|
+
Transforms.delete(editor, {
|
|
6
|
+
at: {
|
|
7
|
+
anchor: Editor.start(editor, []),
|
|
8
|
+
focus: Editor.end(editor, []),
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// insert new text
|
|
13
|
+
if (newText && newText !== "") {
|
|
14
|
+
// don't insert empty text - results in strange visual behavior
|
|
15
|
+
Transforms.insertNodes(
|
|
16
|
+
editor,
|
|
17
|
+
[
|
|
18
|
+
{
|
|
19
|
+
type: "paragraph",
|
|
20
|
+
children: [{ text: newText }],
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
{
|
|
24
|
+
at: [0],
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|