@copilotkit/react-textarea 1.3.0 → 1.3.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/CHANGELOG.md +10 -0
- package/dist/chunk-224UKA7C.mjs +38 -0
- package/dist/chunk-224UKA7C.mjs.map +1 -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-2XDYLKPH.mjs +181 -0
- package/dist/chunk-2XDYLKPH.mjs.map +1 -0
- package/dist/chunk-3PQ7GSFE.mjs +17 -0
- package/dist/chunk-3PQ7GSFE.mjs.map +1 -0
- package/dist/chunk-4AMCUMC7.mjs +124 -0
- package/dist/chunk-4AMCUMC7.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-5UNJXFUO.mjs +29 -0
- package/dist/chunk-5UNJXFUO.mjs.map +1 -0
- package/dist/chunk-7LSRNPNI.mjs +59 -0
- package/dist/chunk-7LSRNPNI.mjs.map +1 -0
- package/dist/chunk-AJ5OMEXM.mjs +13 -0
- package/dist/chunk-AJ5OMEXM.mjs.map +1 -0
- package/dist/chunk-CF5GISTC.mjs +113 -0
- package/dist/chunk-CF5GISTC.mjs.map +1 -0
- package/dist/chunk-D2SUDM2O.mjs +99 -0
- package/dist/chunk-D2SUDM2O.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-FYCQE57K.mjs +60 -0
- package/dist/chunk-FYCQE57K.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-HL7EF7KA.mjs +32 -0
- package/dist/chunk-HL7EF7KA.mjs.map +1 -0
- package/dist/chunk-I3SPIGAI.mjs +31 -0
- package/dist/chunk-I3SPIGAI.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-J62KUPFZ.mjs +264 -0
- package/dist/chunk-J62KUPFZ.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-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-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-SDHH6DI6.mjs +63 -0
- package/dist/chunk-SDHH6DI6.mjs.map +1 -0
- package/dist/chunk-T6MTDQZ7.mjs +45 -0
- package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
- package/dist/chunk-UGEKMSRR.mjs +225 -0
- package/dist/chunk-UGEKMSRR.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 +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +114 -49
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +36 -1687
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-element.d.ts +1 -1
- package/dist/components/base-copilot-textarea/render-element.mjs +4 -48
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.d.ts +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +4 -46
- package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +4 -2
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +5 -81
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +4 -54
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
- 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 +9 -3
- package/dist/components/copilot-textarea/copilot-textarea.js +116 -51
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +44 -2212
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +1 -1
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +5 -13
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +2 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js +21 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +9 -111
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.js +94 -31
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +19 -808
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +65 -21
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +14 -520
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +68 -24
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +15 -543
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
- 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.js +68 -24
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +16 -543
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
- package/dist/components/index.css +9 -0
- package/dist/components/index.css.map +1 -0
- package/dist/components/index.js +116 -51
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +46 -2211
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/manual-ui/chip-with-icon.d.ts +1 -1
- package/dist/components/manual-ui/chip-with-icon.mjs +2 -0
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.d.ts +1 -1
- package/dist/components/source-search-box/source-search-box.js +4 -2
- package/dist/components/source-search-box/source-search-box.js.map +1 -1
- package/dist/components/source-search-box/source-search-box.mjs +8 -200
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/button.mjs +6 -76
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/command.mjs +14 -233
- package/dist/components/ui/command.mjs.map +1 -1
- package/dist/components/ui/dialog.mjs +11 -135
- package/dist/components/ui/dialog.mjs.map +1 -1
- package/dist/components/ui/label.mjs +5 -51
- package/dist/components/ui/label.mjs.map +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.mjs +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +7 -152
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +5 -165
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +6 -141
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.mjs +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +4 -139
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +4 -221
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
- package/dist/hooks/misc/use-autosize-textarea.mjs +4 -12
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
- package/dist/index.css +644 -1
- package/dist/index.css.map +1 -0
- package/dist/index.js +116 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -2218
- package/dist/index.mjs.map +1 -1
- package/dist/lib/debouncer.d.ts +1 -1
- package/dist/lib/debouncer.js.map +1 -1
- package/dist/lib/debouncer.mjs +4 -48
- package/dist/lib/debouncer.mjs.map +1 -1
- package/dist/lib/editor-to-text.mjs +4 -40
- package/dist/lib/editor-to-text.mjs.map +1 -1
- package/dist/lib/get-text-around-cursor.d.ts +1 -1
- package/dist/lib/get-text-around-cursor.mjs +7 -96
- package/dist/lib/get-text-around-cursor.mjs.map +1 -1
- package/dist/lib/retry.mjs +4 -14
- package/dist/lib/retry.mjs.map +1 -1
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +4 -22
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -1
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +4 -17
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/replace-text.mjs +4 -24
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
- package/dist/lib/slatejs-edits/with-partial-history.d.ts +1 -1
- package/dist/lib/slatejs-edits/with-partial-history.mjs +5 -102
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
- package/dist/lib/stream-promise-flatten.js.map +1 -1
- package/dist/lib/stream-promise-flatten.mjs +4 -44
- package/dist/lib/stream-promise-flatten.mjs.map +1 -1
- package/dist/lib/utils.mjs +8 -58
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/lib/utils.test.d.ts +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +9 -258
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.d.ts +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +6 -75
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/index.js.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +10 -258
- package/dist/types/autosuggestions-config/index.mjs.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.d.ts +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +6 -68
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +6 -56
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
- package/dist/types/base/autosuggestion-state.d.ts +1 -1
- package/dist/types/base/autosuggestions-bare-function.d.ts +1 -1
- package/dist/types/base/base-autosuggestions-config.d.ts +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +4 -25
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
- package/dist/types/base/custom-editor.d.ts +1 -1
- package/dist/types/base/editor-autocomplete-state.d.ts +1 -1
- package/dist/types/base/editor-autocomplete-state.mjs +5 -9
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
- package/dist/types/base/index.d.ts +1 -1
- package/dist/types/base/index.mjs +5 -25
- package/dist/types/base/index.mjs.map +1 -1
- package/dist/types/html-copilot-textarea-element.d.ts +1 -1
- package/dist/types/html-copilot-textarea-element.mjs +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +14 -258
- package/dist/types/index.mjs.map +1 -1
- package/package.json +11 -17
- package/src/components/base-copilot-textarea/base-copilot-textarea.css +9 -0
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +1 -0
- package/src/components/copilot-textarea/copilot-textarea.tsx +8 -2
- package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +17 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +7 -4
- package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +55 -0
- package/src/styles.css +2 -9
- package/tsup.config.ts +15 -63
- package/dist/components/base-copilot-textarea/base-copilot-textarea.d.mts +0 -43
- package/dist/components/base-copilot-textarea/render-element.d.mts +0 -6
- package/dist/components/base-copilot-textarea/render-placeholder.d.mts +0 -6
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.mts +0 -8
- package/dist/components/base-copilot-textarea/use-add-branding-css.d.mts +0 -3
- package/dist/components/copilot-textarea/copilot-textarea.d.mts +0 -165
- package/dist/components/hovering-toolbar/hovering-editor-provider.d.mts +0 -18
- package/dist/components/hovering-toolbar/hovering-toolbar-components.d.mts +0 -17
- package/dist/components/hovering-toolbar/hovering-toolbar.d.mts +0 -12
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.mts +0 -16
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.mts +0 -14
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.mts +0 -4
- package/dist/components/index.d.mts +0 -15
- package/dist/components/manual-ui/chip-with-icon.d.mts +0 -10
- package/dist/components/source-search-box/source-search-box.d.mts +0 -16
- package/dist/components/ui/button.d.mts +0 -14
- package/dist/components/ui/command.d.mts +0 -53
- package/dist/components/ui/dialog.d.mts +0 -19
- package/dist/components/ui/label.d.mts +0 -8
- package/dist/context/index.d.mts +0 -2
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.mts +0 -15
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.d.mts +0 -8
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.mts +0 -7
- package/dist/hooks/index.d.mts +0 -2
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.mts +0 -22
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.mts +0 -23
- package/dist/hooks/misc/use-autosize-textarea.d.mts +0 -5
- package/dist/index.d.mts +0 -15
- package/dist/lib/debouncer.d.mts +0 -11
- package/dist/lib/editor-to-text.d.mts +0 -7
- package/dist/lib/get-text-around-cursor.d.mts +0 -15
- package/dist/lib/retry.d.mts +0 -3
- package/dist/lib/slatejs-edits/add-autocompletions.d.mts +0 -8
- package/dist/lib/slatejs-edits/clear-autocompletions.d.mts +0 -8
- package/dist/lib/slatejs-edits/replace-text.d.mts +0 -5
- package/dist/lib/slatejs-edits/with-partial-history.d.mts +0 -8
- package/dist/lib/stream-promise-flatten.d.mts +0 -12
- package/dist/lib/utils.d.mts +0 -9
- package/dist/lib/utils.test.d.mts +0 -2
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.mts +0 -23
- package/dist/types/autosuggestions-config/autosuggestions-config.d.mts +0 -20
- package/dist/types/autosuggestions-config/editing-api-config.d.mts +0 -15
- package/dist/types/autosuggestions-config/index.d.mts +0 -10
- package/dist/types/autosuggestions-config/insertions-api-config.d.mts +0 -15
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.mts +0 -3
- package/dist/types/autosuggestions-config/suggestions-api-config.d.mts +0 -14
- package/dist/types/base/autosuggestion-state.d.mts +0 -8
- package/dist/types/base/autosuggestions-bare-function.d.mts +0 -19
- package/dist/types/base/base-autosuggestions-config.d.mts +0 -83
- package/dist/types/base/base-copilot-textarea-props.d.mts +0 -5
- package/dist/types/base/custom-editor.d.mts +0 -29
- package/dist/types/base/editor-autocomplete-state.d.mts +0 -10
- package/dist/types/base/index.d.mts +0 -54
- package/dist/types/html-copilot-textarea-element.d.mts +0 -7
- package/dist/types/index.d.mts +0 -13
|
@@ -1,168 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
// src/lib/slatejs-edits/with-partial-history.ts
|
|
7
|
-
import { Editor, Operation, Path, Transforms } from "slate";
|
|
8
|
-
import { HistoryEditor } from "slate-history";
|
|
9
|
-
var withPartialHistory = (editor, shouldSave2) => {
|
|
10
|
-
const e = editor;
|
|
11
|
-
const { apply } = e;
|
|
12
|
-
e.history = { undos: [], redos: [] };
|
|
13
|
-
e.redo = () => {
|
|
14
|
-
const { history } = e;
|
|
15
|
-
const { redos } = history;
|
|
16
|
-
if (redos.length > 0) {
|
|
17
|
-
const batch = redos[redos.length - 1];
|
|
18
|
-
if (batch.selectionBefore) {
|
|
19
|
-
Transforms.setSelection(e, batch.selectionBefore);
|
|
20
|
-
}
|
|
21
|
-
HistoryEditor.withoutSaving(e, () => {
|
|
22
|
-
Editor.withoutNormalizing(e, () => {
|
|
23
|
-
for (const op of batch.operations) {
|
|
24
|
-
e.apply(op);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
history.redos.pop();
|
|
29
|
-
e.writeHistory("undos", batch);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
e.undo = () => {
|
|
33
|
-
const { history } = e;
|
|
34
|
-
const { undos } = history;
|
|
35
|
-
if (undos.length > 0) {
|
|
36
|
-
const batch = undos[undos.length - 1];
|
|
37
|
-
HistoryEditor.withoutSaving(e, () => {
|
|
38
|
-
Editor.withoutNormalizing(e, () => {
|
|
39
|
-
const inverseOps = batch.operations.map(Operation.inverse).reverse();
|
|
40
|
-
for (const op of inverseOps) {
|
|
41
|
-
e.apply(op);
|
|
42
|
-
}
|
|
43
|
-
if (batch.selectionBefore) {
|
|
44
|
-
Transforms.setSelection(e, batch.selectionBefore);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
e.writeHistory("redos", batch);
|
|
49
|
-
history.undos.pop();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
e.apply = (op) => {
|
|
53
|
-
const { operations, history } = e;
|
|
54
|
-
const { undos } = history;
|
|
55
|
-
const lastBatch = undos[undos.length - 1];
|
|
56
|
-
const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
|
57
|
-
let save = HistoryEditor.isSaving(e);
|
|
58
|
-
let merge = HistoryEditor.isMerging(e);
|
|
59
|
-
if (save == null) {
|
|
60
|
-
save = shouldSave2(op, lastOp);
|
|
61
|
-
}
|
|
62
|
-
if (save) {
|
|
63
|
-
if (merge == null) {
|
|
64
|
-
if (lastBatch == null) {
|
|
65
|
-
merge = false;
|
|
66
|
-
} else if (operations.length !== 0) {
|
|
67
|
-
merge = true;
|
|
68
|
-
} else {
|
|
69
|
-
merge = shouldMerge(op, lastOp);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (lastBatch && merge) {
|
|
73
|
-
lastBatch.operations.push(op);
|
|
74
|
-
} else {
|
|
75
|
-
const batch = {
|
|
76
|
-
operations: [op],
|
|
77
|
-
selectionBefore: e.selection
|
|
78
|
-
};
|
|
79
|
-
e.writeHistory("undos", batch);
|
|
80
|
-
}
|
|
81
|
-
while (undos.length > 100) {
|
|
82
|
-
undos.shift();
|
|
83
|
-
}
|
|
84
|
-
history.redos = [];
|
|
85
|
-
}
|
|
86
|
-
apply(op);
|
|
87
|
-
};
|
|
88
|
-
e.writeHistory = (stack, batch) => {
|
|
89
|
-
e.history[stack].push(batch);
|
|
90
|
-
};
|
|
91
|
-
return e;
|
|
92
|
-
};
|
|
93
|
-
var shouldMerge = (op, prev) => {
|
|
94
|
-
if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
};
|
|
102
|
-
var defaultShouldSave = (op, prev) => {
|
|
103
|
-
if (op.type === "set_selection") {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
return true;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
|
|
110
|
-
var shouldSave = (op, prev) => {
|
|
111
|
-
const excludedNodeType = "suggestion";
|
|
112
|
-
if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
return defaultShouldSave(op, prev);
|
|
131
|
-
};
|
|
132
|
-
function useCopilotTextareaEditor() {
|
|
133
|
-
const editor = useMemo(() => {
|
|
134
|
-
const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
|
|
135
|
-
const { isVoid } = editor2;
|
|
136
|
-
editor2.isVoid = (element) => {
|
|
137
|
-
switch (element.type) {
|
|
138
|
-
case "suggestion":
|
|
139
|
-
return true;
|
|
140
|
-
default:
|
|
141
|
-
return isVoid(element);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
const { markableVoid } = editor2;
|
|
145
|
-
editor2.markableVoid = (element) => {
|
|
146
|
-
switch (element.type) {
|
|
147
|
-
case "suggestion":
|
|
148
|
-
return true;
|
|
149
|
-
default:
|
|
150
|
-
return markableVoid(element);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const { isInline } = editor2;
|
|
154
|
-
editor2.isInline = (element) => {
|
|
155
|
-
switch (element.type) {
|
|
156
|
-
case "suggestion":
|
|
157
|
-
return element.inline;
|
|
158
|
-
default:
|
|
159
|
-
return isInline(element);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
return editor2;
|
|
163
|
-
}, []);
|
|
164
|
-
return editor;
|
|
165
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
useCopilotTextareaEditor
|
|
3
|
+
} from "../../chunk-DRV2FOHZ.mjs";
|
|
4
|
+
import "../../chunk-4NHVQZ67.mjs";
|
|
5
|
+
import "../../chunk-MRXNTQOX.mjs";
|
|
166
6
|
export {
|
|
167
7
|
useCopilotTextareaEditor
|
|
168
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx","../../../src/lib/slatejs-edits/with-partial-history.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { createEditor, Element } from \"slate\";\nimport { withReact } from \"slate-react\";\nimport {\n defaultShouldSave,\n ShouldSaveToHistory,\n withPartialHistory,\n} from \"../../lib/slatejs-edits/with-partial-history\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nconst shouldSave: ShouldSaveToHistory = (op, prev) => {\n const excludedNodeType = \"suggestion\";\n // Check if the operation involves the suggestion inline node type\n if (\n op.type === \"insert_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"remove_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"set_node\" &&\n \"type\" in op.newProperties &&\n op.newProperties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (op.type == \"set_node\" && \"type\" in op.properties && op.properties.type === excludedNodeType) {\n return false;\n }\n\n if (\n op.type === \"merge_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"split_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n // Otherwise, save the operation to history\n return defaultShouldSave(op, prev);\n};\n\nexport function useCopilotTextareaEditor(): CustomEditor {\n const editor = useMemo(() => {\n const editor = withPartialHistory(withReact(createEditor()), shouldSave);\n\n const { isVoid } = editor;\n editor.isVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return isVoid(element);\n }\n };\n\n const { markableVoid } = editor;\n editor.markableVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return markableVoid(element);\n }\n };\n\n const { isInline } = editor;\n editor.isInline = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return element.inline;\n default:\n return isInline(element);\n }\n };\n\n return editor;\n }, []);\n\n return editor;\n}\n","import { Editor, Operation, Path, Range, Transforms } from \"slate\";\nimport { HistoryEditor } from \"slate-history\";\n\n// Copy-pasted from `https://github.com/ianstormtaylor/slate/blob/main/packages/slate-history/src/with-history.ts`\n// With one exception: the `shouldSave` function is passed in as an argument to `withPartialHistory` instead of being hardcoded\nexport type ShouldSaveToHistory = (op: Operation, prev: Operation | undefined) => boolean;\n\nexport const withPartialHistory = <T extends Editor>(\n editor: T,\n shouldSave: ShouldSaveToHistory,\n) => {\n const e = editor as T & HistoryEditor;\n const { apply } = e;\n e.history = { undos: [], redos: [] };\n\n e.redo = () => {\n const { history } = e;\n const { redos } = history;\n\n if (redos.length > 0) {\n const batch = redos[redos.length - 1];\n\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n for (const op of batch.operations) {\n e.apply(op);\n }\n });\n });\n\n history.redos.pop();\n e.writeHistory(\"undos\", batch);\n }\n };\n\n e.undo = () => {\n const { history } = e;\n const { undos } = history;\n\n if (undos.length > 0) {\n const batch = undos[undos.length - 1];\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n const inverseOps = batch.operations.map(Operation.inverse).reverse();\n\n for (const op of inverseOps) {\n e.apply(op);\n }\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n });\n });\n\n e.writeHistory(\"redos\", batch);\n history.undos.pop();\n }\n };\n\n e.apply = (op: Operation) => {\n const { operations, history } = e;\n const { undos } = history;\n const lastBatch = undos[undos.length - 1];\n const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];\n let save = HistoryEditor.isSaving(e);\n let merge = HistoryEditor.isMerging(e);\n\n if (save == null) {\n save = shouldSave(op, lastOp);\n }\n\n if (save) {\n if (merge == null) {\n if (lastBatch == null) {\n merge = false;\n } else if (operations.length !== 0) {\n merge = true;\n } else {\n merge = shouldMerge(op, lastOp);\n }\n }\n\n if (lastBatch && merge) {\n lastBatch.operations.push(op);\n } else {\n const batch = {\n operations: [op],\n selectionBefore: e.selection,\n };\n e.writeHistory(\"undos\", batch);\n }\n\n while (undos.length > 100) {\n undos.shift();\n }\n\n history.redos = [];\n }\n\n apply(op);\n };\n\n e.writeHistory = (stack: \"undos\" | \"redos\", batch: any) => {\n e.history[stack].push(batch);\n };\n\n return e;\n};\n\n/**\n * Check whether to merge an operation into the previous operation.\n */\n\nconst shouldMerge = (op: Operation, prev: Operation | undefined): boolean => {\n if (\n prev &&\n op.type === \"insert_text\" &&\n prev.type === \"insert_text\" &&\n op.offset === prev.offset + prev.text.length &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n if (\n prev &&\n op.type === \"remove_text\" &&\n prev.type === \"remove_text\" &&\n op.offset + op.text.length === prev.offset &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n return false;\n};\n\nexport const defaultShouldSave = (op: Operation, prev: Operation | undefined): boolean => {\n if (op.type === \"set_selection\") {\n return false;\n }\n\n return true;\n};\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,cAAc,eAAe;AACtC,SAAS,iBAAiB;;;ACF1B,SAAS,QAAQ,WAAW,MAAa,kBAAkB;AAC3D,SAAS,qBAAqB;AAMvB,IAAM,qBAAqB,CAChC,QACAA,gBACG;AACH,QAAM,IAAI;AACV,QAAM,EAAE,MAAM,IAAI;AAClB,IAAE,UAAU,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,EAAE;AAEnC,IAAE,OAAO,MAAM;AACb,UAAM,EAAE,QAAQ,IAAI;AACpB,UAAM,EAAE,MAAM,IAAI;AAElB,QAAI,MAAM,SAAS,GAAG;AACpB,YAAM,QAAQ,MAAM,MAAM,S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MAC3B;AAAA,IACF;AAEA,WAAOA;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":["shouldSave","editor"]}
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts","../../../src/lib/get-text-around-cursor.ts","../../../src/lib/slatejs-edits/replace-text.ts"],"sourcesContent":["import React from \"react\";\nimport { Editor } from \"slate\";\nimport { ReactEditor } from \"slate-react\";\nimport { getFullEditorTextWithNewlines } from \"../../lib/get-text-around-cursor\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function usePopulateCopilotTextareaRef(\n editor: Editor,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n) {\n React.useImperativeHandle(ref, () => {\n class Combined {\n constructor(\n private customMethods: CustomMethods,\n private editorHtmlElement: HTMLElement,\n ) {}\n\n [key: string]: any;\n\n get(target: any, propKey: string): any {\n if (this.isKeyOfCustomMethods(propKey)) {\n const value = this.customMethods[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.customMethods);\n }\n return value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n const value = this.editorHtmlElement[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.editorHtmlElement);\n }\n return value;\n }\n }\n\n set(target: any, propKey: string, value: any): boolean {\n if (this.isKeyOfCustomMethods(propKey)) {\n (this.customMethods as any)[propKey] = value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n (this.editorHtmlElement as any)[propKey] = value;\n } else {\n // Default behavior (optional)\n target[propKey] = value;\n }\n return true;\n }\n\n private isKeyOfCustomMethods(key: string): key is keyof CustomMethods {\n return key in this.customMethods;\n }\n\n private isKeyOfHTMLElement(key: string): key is keyof HTMLElement {\n return key in this.editorHtmlElement;\n }\n }\n\n const handler = {\n get(target: any, propKey: keyof CustomMethods | keyof HTMLElement) {\n return target.get(target, propKey);\n },\n set(target: any, propKey: keyof CustomMethods | keyof HTMLElement, value: any) {\n return target.set(target, propKey, value);\n },\n };\n\n class CustomMethods {\n constructor(private editor: CustomEditor) {}\n\n focus() {\n ReactEditor.focus(this.editor);\n }\n\n blur() {\n ReactEditor.blur(this.editor);\n }\n\n get value() {\n return getFullEditorTextWithNewlines(this.editor);\n }\n set value(value: string) {\n replaceEditorText(this.editor, value);\n }\n }\n\n const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);\n const customMethods = new CustomMethods(editor);\n\n const combined = new Combined(customMethods, editorHtmlElement);\n return new Proxy(combined, handler);\n }, [editor]);\n}\n","import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n","import { Editor, Transforms } from \"slate\";\n\nexport function replaceEditorText(editor: Editor, newText: string) {\n // clear all previous text\n Transforms.delete(editor, {\n at: {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n },\n });\n\n // insert new text\n if (newText && newText !== \"\") {\n // don't insert empty text - results in strange visual behavior\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"paragraph\",\n children: [{ text: newText }],\n },\n ],\n {\n at: [0],\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,yBAA4B;;;ACF5B,mBAAsF;AAuE/E,SAAS,8BAA8B,QAAwB;AACpE,QAAM,oBAA2B;AAAA,IAC/B,QAAQ,oBAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,oBAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AACA,SAAO,wBAAwB,QAAQ,iBAAiB;AAC1D;AAGO,SAAS,wBAAwB,QAAgB,OAAsB;AAC5E,QAAM,QAAQ;AACd,QAAM,CAAC,OAAO,GAAG,IAAI,mBAAM,MAAM,KAAK;AACtC,MAAI,OAAO;AACX,MAAI,YAAyB;AAE7B,aAAW,CAAC,MAAM,IAAI,KAAK,oBAAO,MAAM,QAAQ;AAAA,IAC9C,IAAI;AAAA,IACJ,OAAO,kBAAK;AAAA,IACZ;AAAA,EACF,CAAC,GAAG;AACF,QAAI,IAAI,KAAK;AAGb,UAAM,CAAC,KAAK,IAAI,oBAAO,MAAM,QAAQ;AAAA,MACnC,IAAI;AAAA,MACJ,OAAO,CAAC,MAAM,qBAAQ,UAAU,CAAC,KAAK,EAAE,SAAS;AAAA,IACnD,CAAC,KAAK,CAAC,IAAI;AAGX,QAAI,cAAc,SAAS,OAAO;AAEhC,UAAI,WAAW;AACb,gBAAQ;AAAA,MACV;AACA,kBAAY;AAAA,IACd;AAEA,QAAI,kBAAK,OAAO,MAAM,IAAI,IAAI,GAAG;AAC/B,UAAI,EAAE,MAAM,GAAG,IAAI,MAAM;AAAA,IAC3B;AAEA,QAAI,kBAAK,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AqB,OAAO,GAAG;AACtC,UAAC,KAAK,cAAsB,OAAO,IAAI;AAAA,QACzC,WAAW,KAAK,mBAAmB,OAAO,GAAG;AAC3C,UAAC,KAAK,kBAA0B,OAAO,IAAI;AAAA,QAC7C,OAAO;AAEL,iBAAO,OAAO,IAAI;AAAA,QACpB;AACA,eAAO;AAAA,MACT;AAAA,MAEQ,qBAAqB,KAAyC;AACpE,eAAO,OAAO,KAAK;AAAA,MACrB;AAAA,MAEQ,mBAAmB,KAAuC;AAChE,eAAO,OAAO,KAAK;AAAA,MACrB;AAAA,IACF;AAEA,UAAM,UAAU;AAAA,MACd,IAAI,QAAa,SAAkD;AACjE,eAAO,OAAO,IAAI,QAAQ,OAAO;AAAA,MACnC;AAAA,MACA,IAAI,QAAa,SAAkD,OAAY;AAC7E,eAAO,OAAO,IAAI,QAAQ,SAAS,KAAK;AAAA,MAC1C;AAAA,IACF;AAAA,IAEA,MAAM,cAAc;AAAA,MAClB,YAAoBC,SAAsB;AAAtB,sBAAAA;AAAA,MAAuB;AAAA,MAE3C,QAAQ;AACN,uCAAY,MAAM,KAAK,MAAM;AAAA,MAC/B;AAAA,MAEA,OAAO;AACL,uCAAY,KAAK,KAAK,MAAM;AAAA,MAC9B;AAAA,MAEA,IAAI,QAAQ;AACV,eAAO,8BAA8B,KAAK,MAAM;AAAA,MAClD;AAAA,MACA,IAAI,MAAM,OAAe;AACvB,0BAAkB,KAAK,QAAQ,KAAK;AAAA,MACtC;AAAA,IACF;AAEA,UAAM,oBAAoB,+BAAY,UAAU,QAAQ,MAAM;AAC9D,UAAM,gBAAgB,IAAI,cAAc,MAAM;AAE9C,UAAM,WAAW,IAAI,SAAS,eAAe,iBAAiB;AAC9D,WAAO,IAAI,MAAM,UAAU,OAAO;AAAA,EACpC,GAAG,CAAC,MAAM,CAAC;AACb;","names":["import_slate","React","customMethods","editorHtmlElement","editor"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts","../../../src/lib/get-text-around-cursor.ts","../../../src/lib/slatejs-edits/replace-text.ts"],"sourcesContent":["import React from \"react\";\nimport { Editor } from \"slate\";\nimport { ReactEditor } from \"slate-react\";\nimport { getFullEditorTextWithNewlines } from \"../../lib/get-text-around-cursor\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function usePopulateCopilotTextareaRef(\n editor: Editor,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n) {\n React.useImperativeHandle(ref, () => {\n class Combined {\n constructor(\n private customMethods: CustomMethods,\n private editorHtmlElement: HTMLElement,\n ) {}\n\n [key: string]: any;\n\n get(target: any, propKey: string): any {\n if (this.isKeyOfCustomMethods(propKey)) {\n const value = this.customMethods[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.customMethods);\n }\n return value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n const value = this.editorHtmlElement[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.editorHtmlElement);\n }\n return value;\n }\n }\n\n set(target: any, propKey: string, value: any): boolean {\n if (this.isKeyOfCustomMethods(propKey)) {\n (this.customMethods as any)[propKey] = value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n (this.editorHtmlElement as any)[propKey] = value;\n } else {\n // Default behavior (optional)\n target[propKey] = value;\n }\n return true;\n }\n\n private isKeyOfCustomMethods(key: string): key is keyof CustomMethods {\n return key in this.customMethods;\n }\n\n private isKeyOfHTMLElement(key: string): key is keyof HTMLElement {\n return key in this.editorHtmlElement;\n }\n }\n\n const handler = {\n get(target: any, propKey: keyof CustomMethods | keyof HTMLElement) {\n return target.get(target, propKey);\n },\n set(target: any, propKey: keyof CustomMethods | keyof HTMLElement, value: any) {\n return target.set(target, propKey, value);\n },\n };\n\n class CustomMethods {\n constructor(private editor: CustomEditor) {}\n\n focus() {\n ReactEditor.focus(this.editor);\n }\n\n blur() {\n ReactEditor.blur(this.editor);\n }\n\n get value() {\n return getFullEditorTextWithNewlines(this.editor);\n }\n set value(value: string) {\n replaceEditorText(this.editor, value);\n }\n }\n\n const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);\n const customMethods = new CustomMethods(editor);\n\n const combined = new Combined(customMethods, editorHtmlElement);\n return new Proxy(combined, handler);\n }, [editor]);\n}\n","import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n","import { Editor, Transforms } from \"slate\";\n\nexport function replaceEditorText(editor: Editor, newText: string) {\n // clear all previous text\n Transforms.delete(editor, {\n at: {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n },\n });\n\n // insert new text\n if (newText && newText !== \"\") {\n // don't insert empty text - results in strange visual behavior\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"paragraph\",\n children: [{ text: newText }],\n },\n ],\n {\n at: [0],\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,y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,KAAuC;AAChE,eAAO,OAAO,KAAK;AAAA,MACrB;AAAA,IACF;AAEA,UAAM,UAAU;AAAA,MACd,IAAI,QAAa,SAAkD;AACjE,eAAO,OAAO,IAAI,QAAQ,OAAO;AAAA,MACnC;AAAA,MACA,IAAI,QAAa,SAAkD,OAAY;AAC7E,eAAO,OAAO,IAAI,QAAQ,SAAS,KAAK;AAAA,MAC1C;AAAA,IACF;AAEA,UAAM,cAAc;AAAA,MAClB,YAAoBC,SAAsB;AAAtB,sBAAAA;AAAA,MAAuB;AAAA,MAE3C,QAAQ;AACN,uCAAY,MAAM,KAAK,MAAM;AAAA,MAC/B;AAAA,MAEA,OAAO;AACL,uCAAY,KAAK,KAAK,MAAM;AAAA,MAC9B;AAAA,MAEA,IAAI,QAAQ;AACV,eAAO,8BAA8B,KAAK,MAAM;AAAA,MAClD;AAAA,MACA,IAAI,MAAM,OAAe;AACvB,0BAAkB,KAAK,QAAQ,KAAK;AAAA,MACtC;AAAA,IACF;AAEA,UAAM,oBAAoB,+BAAY,UAAU,QAAQ,MAAM;AAC9D,UAAM,gBAAgB,IAAI,cAAc,MAAM;AAE9C,UAAM,WAAW,IAAI,SAAS,eAAe,iBAAiB;AAC9D,WAAO,IAAI,MAAM,UAAU,OAAO;AAAA,EACpC,GAAG,CAAC,MAAM,CAAC;AACb;","names":["import_slate","React","customMethods","editorHtmlElement","editor"]}
|
package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs
CHANGED
|
@@ -1,144 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
function getFullEditorTextWithNewlines(editor) {
|
|
8
|
-
const fullDocumentRange = {
|
|
9
|
-
anchor: Editor.start(editor, []),
|
|
10
|
-
focus: Editor.end(editor, [])
|
|
11
|
-
};
|
|
12
|
-
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
13
|
-
}
|
|
14
|
-
function extractTextWithNewlines(editor, range) {
|
|
15
|
-
const voids = false;
|
|
16
|
-
const [start, end] = Range.edges(range);
|
|
17
|
-
let text = "";
|
|
18
|
-
let lastBlock = null;
|
|
19
|
-
for (const [node, path] of Editor.nodes(editor, {
|
|
20
|
-
at: range,
|
|
21
|
-
match: Text.isText,
|
|
22
|
-
voids
|
|
23
|
-
})) {
|
|
24
|
-
let t = node.text;
|
|
25
|
-
const [block] = Editor.above(editor, {
|
|
26
|
-
at: path,
|
|
27
|
-
match: (n) => Element.isElement(n) && n.type === "paragraph"
|
|
28
|
-
}) || [null];
|
|
29
|
-
if (lastBlock !== block && block) {
|
|
30
|
-
if (lastBlock) {
|
|
31
|
-
text += "\n";
|
|
32
|
-
}
|
|
33
|
-
lastBlock = block;
|
|
34
|
-
}
|
|
35
|
-
if (Path.equals(path, end.path)) {
|
|
36
|
-
t = t.slice(0, end.offset);
|
|
37
|
-
}
|
|
38
|
-
if (Path.equals(path, start.path)) {
|
|
39
|
-
t = t.slice(start.offset);
|
|
40
|
-
}
|
|
41
|
-
text += t;
|
|
42
|
-
}
|
|
43
|
-
return text;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/lib/slatejs-edits/replace-text.ts
|
|
47
|
-
import { Editor as Editor2, Transforms } from "slate";
|
|
48
|
-
function replaceEditorText(editor, newText) {
|
|
49
|
-
Transforms.delete(editor, {
|
|
50
|
-
at: {
|
|
51
|
-
anchor: Editor2.start(editor, []),
|
|
52
|
-
focus: Editor2.end(editor, [])
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
if (newText && newText !== "") {
|
|
56
|
-
Transforms.insertNodes(
|
|
57
|
-
editor,
|
|
58
|
-
[
|
|
59
|
-
{
|
|
60
|
-
type: "paragraph",
|
|
61
|
-
children: [{ text: newText }]
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
{
|
|
65
|
-
at: [0]
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
|
|
72
|
-
function usePopulateCopilotTextareaRef(editor, ref) {
|
|
73
|
-
React.useImperativeHandle(ref, () => {
|
|
74
|
-
class Combined {
|
|
75
|
-
constructor(customMethods2, editorHtmlElement2) {
|
|
76
|
-
this.customMethods = customMethods2;
|
|
77
|
-
this.editorHtmlElement = editorHtmlElement2;
|
|
78
|
-
}
|
|
79
|
-
get(target, propKey) {
|
|
80
|
-
if (this.isKeyOfCustomMethods(propKey)) {
|
|
81
|
-
const value = this.customMethods[propKey];
|
|
82
|
-
if (typeof value === "function") {
|
|
83
|
-
return value.bind(this.customMethods);
|
|
84
|
-
}
|
|
85
|
-
return value;
|
|
86
|
-
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
87
|
-
const value = this.editorHtmlElement[propKey];
|
|
88
|
-
if (typeof value === "function") {
|
|
89
|
-
return value.bind(this.editorHtmlElement);
|
|
90
|
-
}
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
set(target, propKey, value) {
|
|
95
|
-
if (this.isKeyOfCustomMethods(propKey)) {
|
|
96
|
-
this.customMethods[propKey] = value;
|
|
97
|
-
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
98
|
-
this.editorHtmlElement[propKey] = value;
|
|
99
|
-
} else {
|
|
100
|
-
target[propKey] = value;
|
|
101
|
-
}
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
isKeyOfCustomMethods(key) {
|
|
105
|
-
return key in this.customMethods;
|
|
106
|
-
}
|
|
107
|
-
isKeyOfHTMLElement(key) {
|
|
108
|
-
return key in this.editorHtmlElement;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const handler = {
|
|
112
|
-
get(target, propKey) {
|
|
113
|
-
return target.get(target, propKey);
|
|
114
|
-
},
|
|
115
|
-
set(target, propKey, value) {
|
|
116
|
-
return target.set(target, propKey, value);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
class CustomMethods {
|
|
120
|
-
constructor(editor2) {
|
|
121
|
-
this.editor = editor2;
|
|
122
|
-
}
|
|
123
|
-
focus() {
|
|
124
|
-
ReactEditor.focus(this.editor);
|
|
125
|
-
}
|
|
126
|
-
blur() {
|
|
127
|
-
ReactEditor.blur(this.editor);
|
|
128
|
-
}
|
|
129
|
-
get value() {
|
|
130
|
-
return getFullEditorTextWithNewlines(this.editor);
|
|
131
|
-
}
|
|
132
|
-
set value(value) {
|
|
133
|
-
replaceEditorText(this.editor, value);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);
|
|
137
|
-
const customMethods = new CustomMethods(editor);
|
|
138
|
-
const combined = new Combined(customMethods, editorHtmlElement);
|
|
139
|
-
return new Proxy(combined, handler);
|
|
140
|
-
}, [editor]);
|
|
141
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
usePopulateCopilotTextareaRef
|
|
3
|
+
} from "../../chunk-QJNFNPWH.mjs";
|
|
4
|
+
import "../../chunk-5UNJXFUO.mjs";
|
|
5
|
+
import "../../chunk-ECR45NSD.mjs";
|
|
6
|
+
import "../../chunk-MRXNTQOX.mjs";
|
|
142
7
|
export {
|
|
143
8
|
usePopulateCopilotTextareaRef
|
|
144
9
|
};
|
package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts","../../../src/lib/get-text-around-cursor.ts","../../../src/lib/slatejs-edits/replace-text.ts"],"sourcesContent":["import React from \"react\";\nimport { Editor } from \"slate\";\nimport { ReactEditor } from \"slate-react\";\nimport { getFullEditorTextWithNewlines } from \"../../lib/get-text-around-cursor\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function usePopulateCopilotTextareaRef(\n editor: Editor,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n) {\n React.useImperativeHandle(ref, () => {\n class Combined {\n constructor(\n private customMethods: CustomMethods,\n private editorHtmlElement: HTMLElement,\n ) {}\n\n [key: string]: any;\n\n get(target: any, propKey: string): any {\n if (this.isKeyOfCustomMethods(propKey)) {\n const value = this.customMethods[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.customMethods);\n }\n return value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n const value = this.editorHtmlElement[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.editorHtmlElement);\n }\n return value;\n }\n }\n\n set(target: any, propKey: string, value: any): boolean {\n if (this.isKeyOfCustomMethods(propKey)) {\n (this.customMethods as any)[propKey] = value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n (this.editorHtmlElement as any)[propKey] = value;\n } else {\n // Default behavior (optional)\n target[propKey] = value;\n }\n return true;\n }\n\n private isKeyOfCustomMethods(key: string): key is keyof CustomMethods {\n return key in this.customMethods;\n }\n\n private isKeyOfHTMLElement(key: string): key is keyof HTMLElement {\n return key in this.editorHtmlElement;\n }\n }\n\n const handler = {\n get(target: any, propKey: keyof CustomMethods | keyof HTMLElement) {\n return target.get(target, propKey);\n },\n set(target: any, propKey: keyof CustomMethods | keyof HTMLElement, value: any) {\n return target.set(target, propKey, value);\n },\n };\n\n class CustomMethods {\n constructor(private editor: CustomEditor) {}\n\n focus() {\n ReactEditor.focus(this.editor);\n }\n\n blur() {\n ReactEditor.blur(this.editor);\n }\n\n get value() {\n return getFullEditorTextWithNewlines(this.editor);\n }\n set value(value: string) {\n replaceEditorText(this.editor, value);\n }\n }\n\n const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);\n const customMethods = new CustomMethods(editor);\n\n const combined = new Combined(customMethods, editorHtmlElement);\n return new Proxy(combined, handler);\n }, [editor]);\n}\n","import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n","import { Editor, Transforms } from \"slate\";\n\nexport function replaceEditorText(editor: Editor, newText: string) {\n // clear all previous text\n Transforms.delete(editor, {\n at: {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n },\n });\n\n // insert new text\n if (newText && newText !== \"\") {\n // don't insert empty text - results in strange visual behavior\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"paragraph\",\n children: [{ text: newText }],\n },\n ],\n {\n at: [0],\n },\n );\n }\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAElB,SAAS,mBAAmB;;;ACF5B,SAAS,QAAc,MAAM,OAAO,MAAM,SAA+B,aAAa;AAuE/E,SAAS,8BAA8B,QAAwB;AACpE,QAAM,oBAA2B;AAAA,IAC/B,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AACA,SAAO,wBAAwB,QAAQ,iBAAiB;AAC1D;AAGO,SAAS,wBAAwB,QAAgB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,IAEA,MAAM,cAAc;AAAA,MAClB,YAAoBC,SAAsB;AAAtB,sBAAAA;AAAA,MAAuB;AAAA,MAE3C,QAAQ;AACN,oBAAY,MAAM,KAAK,MAAM;AAAA,MAC/B;AAAA,MAEA,OAAO;AACL,oBAAY,KAAK,KAAK,MAAM;AAAA,MAC9B;AAAA,MAEA,IAAI,QAAQ;AACV,eAAO,8BAA8B,KAAK,MAAM;AAAA,MAClD;AAAA,MACA,IAAI,MAAM,OAAe;AACvB,0BAAkB,KAAK,QAAQ,KAAK;AAAA,MACtC;AAAA,IACF;AAEA,UAAM,oBAAoB,YAAY,UAAU,QAAQ,MAAM;AAC9D,UAAM,gBAAgB,IAAI,cAAc,MAAM;AAE9C,UAAM,WAAW,IAAI,SAAS,eAAe,iBAAiB;AAC9D,WAAO,IAAI,MAAM,UAAU,OAAO;AAAA,EACpC,GAAG,CAAC,MAAM,CAAC;AACb;","names":["Editor","customMethods","editorHtmlElement","editor"]}
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
export {
|
|
2
|
+
export { }
|
package/dist/hooks/index.mjs
CHANGED
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx","../../../src/lib/retry.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from \"@copilotkit/shared\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback } from \"react\";\nimport { AutosuggestionsBareFunction } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\nimport {\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n CopilotRequestType,\n} from \"@copilotkit/runtime-client-gql\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[],\n apiConfig: SuggestionsApiConfig,\n): AutosuggestionsBareFunction {\n const { getContextString, copilotApiConfig } = useCopilotContext();\n const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;\n const headers = {\n ...copilotApiConfig.headers,\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n const { maxTokens, stop } = apiConfig;\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString([], contextCategories),\n ),\n }),\n ...apiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: editorState.textAfterCursor,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n ];\n\n const runtimeClient = new CopilotRuntimeClient({\n url,\n publicApiKey,\n headers,\n credentials,\n });\n\n const response = await runtimeClient\n .generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n forwardedParameters: {\n maxTokens,\n stop,\n },\n },\n properties,\n signal: abortSignal,\n })\n .toPromise();\n\n let result = \"\";\n for (const message of convertGqlOutputToMessages(\n response.data?.generateCopilotResponse?.messages ?? [],\n )) {\n if (abortSignal.aborted) {\n break;\n }\n if (message instanceof TextMessage) {\n result += message.content;\n }\n }\n\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose],\n );\n}\n","export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoD;AACpD,wBAAkC;AAClC,mBAA4B;;;ACFrB,SAAS,MACd,IACA,cAAsB,GACtB,WAAmB,KACnB,UAAkB,KACN;AACZ,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,OAAG,EACA,KAAK,OAAO,EACZ,MAAM,CAAC,UAAU;AAChB,UAAI,gBAAgB,GAAG;AACrB,eAAO,KAAK;AACZ;AAAA,MACF;AAEA,iBAAW,MAAM;AACf,cAAM,IAAI,cAAc,GAAG,WAAW,SAAS,OAAO,EACnD,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,MACjB,GAAG,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH;;;ADfA,gCASO;AAeA,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,kBAAkB,iBAAiB,QAAI,qCAAkB;AACjE,QAAM,EAAE,iBAAiB,KAAK,cAAc,aAAa,WAAW,IAAI;AACxE,QAAM,UAAU,kCACX,iBAAiB,UAChB,eAAe,EAAE,CAAC,iDAAmC,GAAG,aAAa,IAAI,CAAC;AAEhF,QAAM,EAAE,WAAW,KAAK,IAAI;AAE5B,aAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AA9C1C;AA+CQ,cAAM,WAAsB;AAAA,UAC1B,IAAI,sCAAY;AAAA,YACd,MAAM,+BAAK;AAAA,YACX,SAAS,UAAU;AAAA,cACjB;AAAA,cACA,iBAAiB,CAAC,GAAG,iBAAiB;AAAA,YACxC;AAAA,UACF,CAAC;AAAA,UACD,GAAG,UAAU;AAAA,UACb,IAAI,sCAAY;AAAA,YACd,MAAM,+BAAK;AAAA,YACX,SAAS,YAAY;AAAA,UACvB,CAAC;AAAA,UACD,IAAI,sCAAY;AAAA,YACd,MAAM,+BAAK;AAAA,YACX,SAAS,oBAAoB,YAAY
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx","../../../src/lib/retry.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from \"@copilotkit/shared\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback } from \"react\";\nimport { AutosuggestionsBareFunction } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\nimport {\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n CopilotRequestType,\n} from \"@copilotkit/runtime-client-gql\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[],\n apiConfig: SuggestionsApiConfig,\n): AutosuggestionsBareFunction {\n const { getContextString, copilotApiConfig } = useCopilotContext();\n const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;\n const headers = {\n ...copilotApiConfig.headers,\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n const { maxTokens, stop } = apiConfig;\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString([], contextCategories),\n ),\n }),\n ...apiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: editorState.textAfterCursor,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n ];\n\n const runtimeClient = new CopilotRuntimeClient({\n url,\n publicApiKey,\n headers,\n credentials,\n });\n\n const response = await runtimeClient\n .generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n forwardedParameters: {\n maxTokens,\n stop,\n },\n },\n properties,\n signal: abortSignal,\n })\n .toPromise();\n\n let result = \"\";\n for (const message of convertGqlOutputToMessages(\n response.data?.generateCopilotResponse?.messages ?? [],\n )) {\n if (abortSignal.aborted) {\n break;\n }\n if (message instanceof TextMessage) {\n result += message.content;\n }\n }\n\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose],\n );\n}\n","export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoD;AACpD,wBAAkC;AAClC,mBAA4B;;;ACFrB,SAAS,MACd,IACA,cAAsB,GACtB,WAAmB,KACnB,UAAkB,KACN;AACZ,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,OAAG,EACA,KAAK,OAAO,EACZ,MAAM,CAAC,UAAU;AAChB,UAAI,gBAAgB,GAAG;AACrB,eAAO,KAAK;AACZ;AAAA,MACF;AAEA,iBAAW,MAAM;AACf,cAAM,IAAI,cAAc,GAAG,WAAW,SAAS,OAAO,EACnD,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,MACjB,GAAG,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH;;;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nB;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,UACA;AAAA,UACA,QAAQ;AAAA,QACV,CAAC,EACA,UAAU;AAEb,YAAI,SAAS;AACb,mBAAW,eAAW;AAAA,WACpB,0BAAS,SAAT,mBAAe,4BAAf,mBAAwC,aAAxC,YAAoD,CAAC;AAAA,QACvD,GAAG;AACD,cAAI,YAAY,SAAS;AACvB;AAAA,UACF;AACA,cAAI,mBAAmB,uCAAa;AAClC,sBAAU,QAAQ;AAAA,UACpB;AAAA,QACF;AAEA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF;","names":[]}
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs
CHANGED
|
@@ -1,143 +1,8 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __async = (__this, __arguments, generator) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
var fulfilled = (value) => {
|
|
20
|
-
try {
|
|
21
|
-
step(generator.next(value));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var rejected = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
step(generator.throw(value));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
reject(e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
39
|
-
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
40
|
-
import { useCopilotContext } from "@copilotkit/react-core";
|
|
41
|
-
import { useCallback } from "react";
|
|
42
|
-
|
|
43
|
-
// src/lib/retry.tsx
|
|
44
|
-
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
fn().then(resolve).catch((error) => {
|
|
47
|
-
if (retriesLeft === 1) {
|
|
48
|
-
reject(error);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
setTimeout(() => {
|
|
52
|
-
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
53
|
-
}, interval);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
59
1
|
import {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
convertMessagesToGqlInput,
|
|
65
|
-
filterAgentStateMessages,
|
|
66
|
-
CopilotRequestType
|
|
67
|
-
} from "@copilotkit/runtime-client-gql";
|
|
68
|
-
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
69
|
-
const { getContextString, copilotApiConfig } = useCopilotContext();
|
|
70
|
-
const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
|
|
71
|
-
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
72
|
-
const { maxTokens, stop } = apiConfig;
|
|
73
|
-
return useCallback(
|
|
74
|
-
(editorState, abortSignal) => __async(this, null, function* () {
|
|
75
|
-
const res = yield retry(() => __async(this, null, function* () {
|
|
76
|
-
var _a, _b, _c;
|
|
77
|
-
const messages = [
|
|
78
|
-
new TextMessage({
|
|
79
|
-
role: Role.System,
|
|
80
|
-
content: apiConfig.makeSystemPrompt(
|
|
81
|
-
textareaPurpose,
|
|
82
|
-
getContextString([], contextCategories)
|
|
83
|
-
)
|
|
84
|
-
}),
|
|
85
|
-
...apiConfig.fewShotMessages,
|
|
86
|
-
new TextMessage({
|
|
87
|
-
role: Role.User,
|
|
88
|
-
content: editorState.textAfterCursor
|
|
89
|
-
}),
|
|
90
|
-
new TextMessage({
|
|
91
|
-
role: Role.User,
|
|
92
|
-
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
|
|
93
|
-
}),
|
|
94
|
-
new TextMessage({
|
|
95
|
-
role: Role.User,
|
|
96
|
-
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
97
|
-
})
|
|
98
|
-
];
|
|
99
|
-
const runtimeClient = new CopilotRuntimeClient({
|
|
100
|
-
url,
|
|
101
|
-
publicApiKey,
|
|
102
|
-
headers,
|
|
103
|
-
credentials
|
|
104
|
-
});
|
|
105
|
-
const response = yield runtimeClient.generateCopilotResponse({
|
|
106
|
-
data: {
|
|
107
|
-
frontend: {
|
|
108
|
-
actions: [],
|
|
109
|
-
url: window.location.href
|
|
110
|
-
},
|
|
111
|
-
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
112
|
-
metadata: {
|
|
113
|
-
requestType: CopilotRequestType.TextareaCompletion
|
|
114
|
-
},
|
|
115
|
-
forwardedParameters: {
|
|
116
|
-
maxTokens,
|
|
117
|
-
stop
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
properties,
|
|
121
|
-
signal: abortSignal
|
|
122
|
-
}).toPromise();
|
|
123
|
-
let result = "";
|
|
124
|
-
for (const message of convertGqlOutputToMessages(
|
|
125
|
-
(_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
|
|
126
|
-
)) {
|
|
127
|
-
if (abortSignal.aborted) {
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
if (message instanceof TextMessage) {
|
|
131
|
-
result += message.content;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return result;
|
|
135
|
-
}));
|
|
136
|
-
return res;
|
|
137
|
-
}),
|
|
138
|
-
[apiConfig, getContextString, contextCategories, textareaPurpose]
|
|
139
|
-
);
|
|
140
|
-
}
|
|
2
|
+
useMakeStandardAutosuggestionFunction
|
|
3
|
+
} from "../../chunk-D2SUDM2O.mjs";
|
|
4
|
+
import "../../chunk-KNQIEOFP.mjs";
|
|
5
|
+
import "../../chunk-MRXNTQOX.mjs";
|
|
141
6
|
export {
|
|
142
7
|
useMakeStandardAutosuggestionFunction
|
|
143
8
|
};
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|