@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,2216 +1,48 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
var __async = (__this, __arguments, generator) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/components/copilot-textarea/copilot-textarea.tsx
|
|
54
|
-
import React7 from "react";
|
|
55
|
-
|
|
56
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
57
|
-
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
58
|
-
import { useCopilotContext } from "@copilotkit/react-core";
|
|
59
|
-
import { useCallback } from "react";
|
|
60
|
-
|
|
61
|
-
// src/lib/retry.tsx
|
|
62
|
-
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
fn().then(resolve).catch((error) => {
|
|
65
|
-
if (retriesLeft === 1) {
|
|
66
|
-
reject(error);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
setTimeout(() => {
|
|
70
|
-
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
71
|
-
}, interval);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
77
1
|
import {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
123
|
-
const response = yield runtimeClient.generateCopilotResponse({
|
|
124
|
-
data: {
|
|
125
|
-
frontend: {
|
|
126
|
-
actions: [],
|
|
127
|
-
url: window.location.href
|
|
128
|
-
},
|
|
129
|
-
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
130
|
-
metadata: {
|
|
131
|
-
requestType: CopilotRequestType.TextareaCompletion
|
|
132
|
-
},
|
|
133
|
-
forwardedParameters: {
|
|
134
|
-
maxTokens,
|
|
135
|
-
stop
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
properties,
|
|
139
|
-
signal: abortSignal
|
|
140
|
-
}).toPromise();
|
|
141
|
-
let result = "";
|
|
142
|
-
for (const message of convertGqlOutputToMessages(
|
|
143
|
-
(_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
|
|
144
|
-
)) {
|
|
145
|
-
if (abortSignal.aborted) {
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
if (message instanceof TextMessage) {
|
|
149
|
-
result += message.content;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return result;
|
|
153
|
-
}));
|
|
154
|
-
return res;
|
|
155
|
-
}),
|
|
156
|
-
[apiConfig, getContextString, contextCategories, textareaPurpose]
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// src/types/base/base-autosuggestions-config.tsx
|
|
161
|
-
import { defaultCopilotContextCategories } from "@copilotkit/react-core";
|
|
162
|
-
var defaultShouldToggleHoveringEditorOnKeyPress = (event, shortcut) => {
|
|
163
|
-
if (event.key === shortcut && event.metaKey) {
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
return false;
|
|
167
|
-
};
|
|
168
|
-
var defaultShouldAcceptAutosuggestionOnKeyPress = (event) => {
|
|
169
|
-
if (event.key === "Tab") {
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
};
|
|
174
|
-
var defaultShouldAcceptAutosuggestionOnTouch = () => false;
|
|
175
|
-
var defaultBaseAutosuggestionsConfig = {
|
|
176
|
-
debounceTime: 250,
|
|
177
|
-
contextCategories: defaultCopilotContextCategories,
|
|
178
|
-
disableWhenEmpty: true,
|
|
179
|
-
disabled: false,
|
|
180
|
-
temporarilyDisableWhenMovingCursorWithoutChangingText: true,
|
|
181
|
-
shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
|
|
182
|
-
shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,
|
|
183
|
-
shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
// src/types/autosuggestions-config/suggestions-api-config.tsx
|
|
187
|
-
import { Role as Role2, TextMessage as TextMessage2 } from "@copilotkit/runtime-client-gql";
|
|
188
|
-
var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
189
|
-
return `You are a versatile writing assistant.
|
|
190
|
-
|
|
191
|
-
The user is writing some text.
|
|
192
|
-
The purpose is: "${textareaPurpose}"
|
|
193
|
-
|
|
194
|
-
Your job is to guess what the user will write next AS BEST YOU CAN.
|
|
195
|
-
Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
|
|
196
|
-
|
|
197
|
-
Adjust yourself to the user's style and implied intent.
|
|
198
|
-
|
|
199
|
-
The user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.
|
|
200
|
-
<TextAfterCursor>
|
|
201
|
-
<TextBeforeCursor>
|
|
202
|
-
<YourSuggestion>
|
|
203
|
-
|
|
204
|
-
If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
|
|
205
|
-
|
|
206
|
-
The following external context is also provided. Use it to help you make better suggestions!!!
|
|
207
|
-
\`\`\`
|
|
208
|
-
${contextString}
|
|
209
|
-
\`\`\`
|
|
210
|
-
`;
|
|
211
|
-
};
|
|
212
|
-
var defaultSuggestionsFewShotMessages = [
|
|
213
|
-
new TextMessage2({
|
|
214
|
-
role: Role2.User,
|
|
215
|
-
content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
|
|
216
|
-
}),
|
|
217
|
-
new TextMessage2({
|
|
218
|
-
role: Role2.User,
|
|
219
|
-
content: "This morning I woke up and went straight to the grocery store."
|
|
220
|
-
}),
|
|
221
|
-
new TextMessage2({
|
|
222
|
-
role: Role2.Assistant,
|
|
223
|
-
content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
|
|
224
|
-
}),
|
|
225
|
-
new TextMessage2({
|
|
226
|
-
role: Role2.User,
|
|
227
|
-
content: "<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>"
|
|
228
|
-
}),
|
|
229
|
-
new TextMessage2({
|
|
230
|
-
role: Role2.User,
|
|
231
|
-
content: `<TextBeforeCursor>The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;</TextBeforeCursor>`
|
|
232
|
-
}),
|
|
233
|
-
new TextMessage2({
|
|
234
|
-
role: Role2.Assistant,
|
|
235
|
-
content: ` (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder's "Pro Rata Share"; `
|
|
236
|
-
})
|
|
237
|
-
];
|
|
238
|
-
var defaultSuggestionsApiConfig = {
|
|
239
|
-
makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
|
|
240
|
-
fewShotMessages: defaultSuggestionsFewShotMessages
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// src/types/autosuggestions-config/insertions-api-config.tsx
|
|
244
|
-
import { Role as Role3, TextMessage as TextMessage3 } from "@copilotkit/runtime-client-gql";
|
|
245
|
-
var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
246
|
-
return `You are a versatile writing assistant helping the user insert new text into their existing work.
|
|
247
|
-
|
|
248
|
-
The user is writing some text.
|
|
249
|
-
The purpose is: "${textareaPurpose}"
|
|
250
|
-
|
|
251
|
-
The following external context is also provided. Use it to inform your suggestions when relevant!!!
|
|
252
|
-
\`\`\`
|
|
253
|
-
${contextString}
|
|
254
|
-
\`\`\`
|
|
255
|
-
|
|
256
|
-
The user will provide you with a prompt for an INSERTION into the text they are writing.
|
|
257
|
-
Your job is to come up with an INSERTION into the text that the user would like to use, AS BEST YOU CAN.
|
|
258
|
-
Only insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.
|
|
259
|
-
|
|
260
|
-
Adjust yourself to the user's style and implied intent.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
The user will provide the text before and after the cursor, as well as the INSERTION prompt. You should use this to infer the best relevant insertion.
|
|
264
|
-
The conversation will be structured as follows:
|
|
265
|
-
<TextAfterCursor>
|
|
266
|
-
<TextBeforeCursor>
|
|
267
|
-
<InsertionPrompt>
|
|
268
|
-
|
|
269
|
-
<YourInsertionSuggestion>
|
|
270
|
-
`;
|
|
271
|
-
};
|
|
272
|
-
var defaultInsertionsFewShotMessages = [
|
|
273
|
-
new TextMessage3({
|
|
274
|
-
role: Role3.User,
|
|
275
|
-
content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
|
|
276
|
-
}),
|
|
277
|
-
new TextMessage3({
|
|
278
|
-
role: Role3.User,
|
|
279
|
-
content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>"
|
|
280
|
-
}),
|
|
281
|
-
new TextMessage3({
|
|
282
|
-
role: Role3.User,
|
|
283
|
-
content: "<InsertionPrompt>I bought a big watermelon</InsertionPrompt>"
|
|
284
|
-
}),
|
|
285
|
-
new TextMessage3({
|
|
286
|
-
role: Role3.Assistant,
|
|
287
|
-
content: "When I arrived I went straight to the produce section and picked out a big watermelon."
|
|
288
|
-
}),
|
|
289
|
-
new TextMessage3({
|
|
290
|
-
role: Role3.User,
|
|
291
|
-
content: "<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>"
|
|
292
|
-
}),
|
|
293
|
-
new TextMessage3({
|
|
294
|
-
role: Role3.User,
|
|
295
|
-
content: `<TextBeforeCursor>The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;</TextBeforeCursor>`
|
|
296
|
-
}),
|
|
297
|
-
new TextMessage3({
|
|
298
|
-
role: Role3.User,
|
|
299
|
-
content: "<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>"
|
|
300
|
-
}),
|
|
301
|
-
new TextMessage3({
|
|
302
|
-
role: Role3.Assistant,
|
|
303
|
-
content: ` (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder's "Pro Rata Share"; `
|
|
304
|
-
})
|
|
305
|
-
];
|
|
306
|
-
var defaultInsertionsApiConfig = {
|
|
307
|
-
makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
|
|
308
|
-
fewShotMessages: defaultInsertionsFewShotMessages,
|
|
309
|
-
forwardedParams: void 0
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
// src/types/autosuggestions-config/editing-api-config.tsx
|
|
313
|
-
import { Role as Role4, TextMessage as TextMessage4 } from "@copilotkit/runtime-client-gql";
|
|
314
|
-
var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
315
|
-
return `You are a versatile writing assistant helping the user edit a portion of their text.
|
|
316
|
-
|
|
317
|
-
The user is writing some text.
|
|
318
|
-
The purpose is: "${textareaPurpose}"
|
|
319
|
-
|
|
320
|
-
The following external context is also provided. Use it when relevant.
|
|
321
|
-
\`\`\`
|
|
322
|
-
${contextString}
|
|
323
|
-
\`\`\`
|
|
324
|
-
|
|
325
|
-
The user has provided you with a PROMPT for EDITING a PORTION of the text.
|
|
326
|
-
Your job is to come up with a new EDITED version OF THE SEGMENT IN QUESTION - AS BEST YOU CAN.
|
|
327
|
-
Only rewrite the portion of the text that the user has marked as "TextToEdit"!!!
|
|
328
|
-
|
|
329
|
-
Adjust yourself to the user's style and implied intent.
|
|
330
|
-
|
|
331
|
-
The conversation will be structured as follows:
|
|
332
|
-
<TextBeforeCursor>
|
|
333
|
-
<TextToEdit>
|
|
334
|
-
<TextAfterCursor>
|
|
335
|
-
<EditingPrompt>
|
|
336
|
-
|
|
337
|
-
<YourEditSuggestion>
|
|
338
|
-
`;
|
|
339
|
-
};
|
|
340
|
-
var defaultEditingFewShotMessages = [
|
|
341
|
-
new TextMessage4({
|
|
342
|
-
role: Role4.User,
|
|
343
|
-
content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>"
|
|
344
|
-
}),
|
|
345
|
-
new TextMessage4({
|
|
346
|
-
role: Role4.User,
|
|
347
|
-
content: "<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>"
|
|
348
|
-
}),
|
|
349
|
-
new TextMessage4({
|
|
350
|
-
role: Role4.User,
|
|
351
|
-
content: "<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>"
|
|
352
|
-
}),
|
|
353
|
-
new TextMessage4({
|
|
354
|
-
role: Role4.User,
|
|
355
|
-
content: "<EditingPrompt>I also bought a big watermelon</EditingPrompt>"
|
|
356
|
-
}),
|
|
357
|
-
new TextMessage4({
|
|
358
|
-
role: Role4.Assistant,
|
|
359
|
-
content: "While I was there I picked up some apples, oranges, and bananas, and a big watermelon."
|
|
360
|
-
}),
|
|
361
|
-
new TextMessage4({
|
|
362
|
-
role: Role4.User,
|
|
363
|
-
content: "<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>"
|
|
364
|
-
}),
|
|
365
|
-
new TextMessage4({
|
|
366
|
-
role: Role4.User,
|
|
367
|
-
content: "<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>"
|
|
368
|
-
}),
|
|
369
|
-
new TextMessage4({
|
|
370
|
-
role: Role4.User,
|
|
371
|
-
content: "<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>"
|
|
372
|
-
}),
|
|
373
|
-
new TextMessage4({
|
|
374
|
-
role: Role4.User,
|
|
375
|
-
content: "<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>"
|
|
376
|
-
}),
|
|
377
|
-
new TextMessage4({
|
|
378
|
-
role: Role4.Assistant,
|
|
379
|
-
content: "It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project."
|
|
380
|
-
})
|
|
381
|
-
];
|
|
382
|
-
var defaultEditingApiConfig = {
|
|
383
|
-
makeSystemPrompt: defaultEditingMakeSystemPrompt,
|
|
384
|
-
fewShotMessages: defaultEditingFewShotMessages,
|
|
385
|
-
forwardedParams: void 0
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
// src/types/autosuggestions-config/autosuggestions-config.tsx
|
|
389
|
-
import { defaultCopilotContextCategories as defaultCopilotContextCategories2 } from "@copilotkit/react-core";
|
|
390
|
-
var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
|
|
391
|
-
contextCategories: defaultCopilotContextCategories2,
|
|
392
|
-
chatApiConfigs: {
|
|
393
|
-
suggestionsApiConfig: defaultSuggestionsApiConfig,
|
|
394
|
-
insertionApiConfig: defaultInsertionsApiConfig,
|
|
395
|
-
editingApiConfig: defaultEditingApiConfig
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
// src/components/base-copilot-textarea/base-copilot-textarea.tsx
|
|
400
|
-
import React6, { useCallback as useCallback4, useEffect as useEffect7, useMemo as useMemo3, useState as useState6 } from "react";
|
|
401
|
-
import { Editor as Editor5 } from "slate";
|
|
402
|
-
import { Editable, Slate } from "slate-react";
|
|
403
|
-
import { twMerge as twMerge2 } from "tailwind-merge";
|
|
404
|
-
|
|
405
|
-
// src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
|
|
406
|
-
import { useCallback as useCallback2, useEffect, useMemo, useState } from "react";
|
|
407
|
-
|
|
408
|
-
// src/lib/debouncer.ts
|
|
409
|
-
var Debouncer = class {
|
|
410
|
-
constructor(wait) {
|
|
411
|
-
this.wait = wait;
|
|
412
|
-
this.debounce = (func, ...args) => __async(this, null, function* () {
|
|
413
|
-
this.cancel();
|
|
414
|
-
this.timeoutId = setTimeout(() => __async(this, null, function* () {
|
|
415
|
-
try {
|
|
416
|
-
this.activeAbortController = new AbortController();
|
|
417
|
-
yield func(...args, this.activeAbortController.signal);
|
|
418
|
-
this.activeAbortController = void 0;
|
|
419
|
-
} catch (error) {
|
|
420
|
-
}
|
|
421
|
-
}), this.wait);
|
|
422
|
-
});
|
|
423
|
-
this.cancel = () => {
|
|
424
|
-
if (this.activeAbortController) {
|
|
425
|
-
this.activeAbortController.abort();
|
|
426
|
-
this.activeAbortController = void 0;
|
|
427
|
-
}
|
|
428
|
-
if (this.timeoutId !== void 0) {
|
|
429
|
-
clearTimeout(this.timeoutId);
|
|
430
|
-
this.timeoutId = void 0;
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
// src/lib/utils.ts
|
|
437
|
-
import { clsx } from "clsx";
|
|
438
|
-
import { twMerge } from "tailwind-merge";
|
|
439
|
-
function cn(...inputs) {
|
|
440
|
-
return twMerge(clsx(inputs));
|
|
441
|
-
}
|
|
442
|
-
var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
|
|
443
|
-
function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
|
|
444
|
-
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
445
|
-
return a === b;
|
|
446
|
-
}
|
|
447
|
-
return naiveEqualityCheck(a, b);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// src/types/base/editor-autocomplete-state.ts
|
|
451
|
-
function areEqual_autocompleteState(prev, next) {
|
|
452
|
-
return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
|
|
456
|
-
function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, shouldAcceptAutosuggestionOnTouch, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
|
|
457
|
-
const [previousAutocompleteState, setPreviousAutocompleteState] = useState(null);
|
|
458
|
-
const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = useState(null);
|
|
459
|
-
const awaitForAndAppendSuggestion = useCallback2(
|
|
460
|
-
(editorAutocompleteState, abortSignal) => __async(this, null, function* () {
|
|
461
|
-
if (disabled) {
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
if (disableWhenEmpty && editorAutocompleteState.textBeforeCursor === "" && editorAutocompleteState.textAfterCursor === "") {
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
const suggestion = yield autosuggestionFunction(editorAutocompleteState, abortSignal);
|
|
468
|
-
if (!suggestion || abortSignal.aborted) {
|
|
469
|
-
throw new DOMException("Aborted", "AbortError");
|
|
470
|
-
}
|
|
471
|
-
setCurrentAutocompleteSuggestion({
|
|
472
|
-
text: suggestion,
|
|
473
|
-
point: editorAutocompleteState.cursorPoint
|
|
474
|
-
});
|
|
475
|
-
}),
|
|
476
|
-
[autosuggestionFunction, setCurrentAutocompleteSuggestion, disableWhenEmpty, disabled]
|
|
477
|
-
);
|
|
478
|
-
const debouncedFunction = useMemo(
|
|
479
|
-
() => new Debouncer(debounceTime),
|
|
480
|
-
[debounceTime]
|
|
481
|
-
);
|
|
482
|
-
useEffect(() => {
|
|
483
|
-
return () => {
|
|
484
|
-
debouncedFunction.cancel();
|
|
485
|
-
setCurrentAutocompleteSuggestion(null);
|
|
486
|
-
};
|
|
487
|
-
}, [debouncedFunction, disabled]);
|
|
488
|
-
const onChange = useCallback2(
|
|
489
|
-
(newEditorState) => {
|
|
490
|
-
const editorStateHasChanged = !nullableCompatibleEqualityCheck(
|
|
491
|
-
areEqual_autocompleteState,
|
|
492
|
-
previousAutocompleteState,
|
|
493
|
-
newEditorState
|
|
494
|
-
);
|
|
495
|
-
setPreviousAutocompleteState(newEditorState);
|
|
496
|
-
if (!editorStateHasChanged) {
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
setCurrentAutocompleteSuggestion(null);
|
|
500
|
-
if (newEditorState) {
|
|
501
|
-
debouncedFunction.debounce(awaitForAndAppendSuggestion, newEditorState);
|
|
502
|
-
} else {
|
|
503
|
-
debouncedFunction.cancel();
|
|
504
|
-
}
|
|
505
|
-
},
|
|
506
|
-
[
|
|
507
|
-
previousAutocompleteState,
|
|
508
|
-
setPreviousAutocompleteState,
|
|
509
|
-
debouncedFunction,
|
|
510
|
-
awaitForAndAppendSuggestion,
|
|
511
|
-
setCurrentAutocompleteSuggestion
|
|
512
|
-
]
|
|
513
|
-
);
|
|
514
|
-
const keyDownOrTouchHandler = useCallback2(
|
|
515
|
-
(event) => {
|
|
516
|
-
if (currentAutocompleteSuggestion) {
|
|
517
|
-
const shouldAcceptSuggestion = event.type === "touchstart" ? shouldAcceptAutosuggestionOnTouch(event) : shouldAcceptAutosuggestionOnKeyPress(event);
|
|
518
|
-
if (shouldAcceptSuggestion) {
|
|
519
|
-
event.preventDefault();
|
|
520
|
-
insertAutocompleteSuggestion(currentAutocompleteSuggestion);
|
|
521
|
-
setCurrentAutocompleteSuggestion(null);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
[
|
|
526
|
-
currentAutocompleteSuggestion,
|
|
527
|
-
setCurrentAutocompleteSuggestion,
|
|
528
|
-
insertAutocompleteSuggestion,
|
|
529
|
-
shouldAcceptAutosuggestionOnKeyPress
|
|
530
|
-
]
|
|
531
|
-
);
|
|
532
|
-
return {
|
|
533
|
-
currentAutocompleteSuggestion,
|
|
534
|
-
onChangeHandler: onChange,
|
|
535
|
-
onKeyDownHandler: keyDownOrTouchHandler,
|
|
536
|
-
onTouchStartHandler: keyDownOrTouchHandler
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
// src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
|
|
541
|
-
import { useMemo as useMemo2 } from "react";
|
|
542
|
-
import { createEditor, Element } from "slate";
|
|
543
|
-
import { withReact } from "slate-react";
|
|
544
|
-
|
|
545
|
-
// src/lib/slatejs-edits/with-partial-history.ts
|
|
546
|
-
import { Editor, Operation, Path, Transforms } from "slate";
|
|
547
|
-
import { HistoryEditor } from "slate-history";
|
|
548
|
-
var withPartialHistory = (editor, shouldSave2) => {
|
|
549
|
-
const e = editor;
|
|
550
|
-
const { apply } = e;
|
|
551
|
-
e.history = { undos: [], redos: [] };
|
|
552
|
-
e.redo = () => {
|
|
553
|
-
const { history } = e;
|
|
554
|
-
const { redos } = history;
|
|
555
|
-
if (redos.length > 0) {
|
|
556
|
-
const batch = redos[redos.length - 1];
|
|
557
|
-
if (batch.selectionBefore) {
|
|
558
|
-
Transforms.setSelection(e, batch.selectionBefore);
|
|
559
|
-
}
|
|
560
|
-
HistoryEditor.withoutSaving(e, () => {
|
|
561
|
-
Editor.withoutNormalizing(e, () => {
|
|
562
|
-
for (const op of batch.operations) {
|
|
563
|
-
e.apply(op);
|
|
564
|
-
}
|
|
565
|
-
});
|
|
566
|
-
});
|
|
567
|
-
history.redos.pop();
|
|
568
|
-
e.writeHistory("undos", batch);
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
e.undo = () => {
|
|
572
|
-
const { history } = e;
|
|
573
|
-
const { undos } = history;
|
|
574
|
-
if (undos.length > 0) {
|
|
575
|
-
const batch = undos[undos.length - 1];
|
|
576
|
-
HistoryEditor.withoutSaving(e, () => {
|
|
577
|
-
Editor.withoutNormalizing(e, () => {
|
|
578
|
-
const inverseOps = batch.operations.map(Operation.inverse).reverse();
|
|
579
|
-
for (const op of inverseOps) {
|
|
580
|
-
e.apply(op);
|
|
581
|
-
}
|
|
582
|
-
if (batch.selectionBefore) {
|
|
583
|
-
Transforms.setSelection(e, batch.selectionBefore);
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
e.writeHistory("redos", batch);
|
|
588
|
-
history.undos.pop();
|
|
589
|
-
}
|
|
590
|
-
};
|
|
591
|
-
e.apply = (op) => {
|
|
592
|
-
const { operations, history } = e;
|
|
593
|
-
const { undos } = history;
|
|
594
|
-
const lastBatch = undos[undos.length - 1];
|
|
595
|
-
const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
|
596
|
-
let save = HistoryEditor.isSaving(e);
|
|
597
|
-
let merge2 = HistoryEditor.isMerging(e);
|
|
598
|
-
if (save == null) {
|
|
599
|
-
save = shouldSave2(op, lastOp);
|
|
600
|
-
}
|
|
601
|
-
if (save) {
|
|
602
|
-
if (merge2 == null) {
|
|
603
|
-
if (lastBatch == null) {
|
|
604
|
-
merge2 = false;
|
|
605
|
-
} else if (operations.length !== 0) {
|
|
606
|
-
merge2 = true;
|
|
607
|
-
} else {
|
|
608
|
-
merge2 = shouldMerge(op, lastOp);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
if (lastBatch && merge2) {
|
|
612
|
-
lastBatch.operations.push(op);
|
|
613
|
-
} else {
|
|
614
|
-
const batch = {
|
|
615
|
-
operations: [op],
|
|
616
|
-
selectionBefore: e.selection
|
|
617
|
-
};
|
|
618
|
-
e.writeHistory("undos", batch);
|
|
619
|
-
}
|
|
620
|
-
while (undos.length > 100) {
|
|
621
|
-
undos.shift();
|
|
622
|
-
}
|
|
623
|
-
history.redos = [];
|
|
624
|
-
}
|
|
625
|
-
apply(op);
|
|
626
|
-
};
|
|
627
|
-
e.writeHistory = (stack, batch) => {
|
|
628
|
-
e.history[stack].push(batch);
|
|
629
|
-
};
|
|
630
|
-
return e;
|
|
631
|
-
};
|
|
632
|
-
var shouldMerge = (op, prev) => {
|
|
633
|
-
if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
|
|
634
|
-
return true;
|
|
635
|
-
}
|
|
636
|
-
if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
|
|
637
|
-
return true;
|
|
638
|
-
}
|
|
639
|
-
return false;
|
|
640
|
-
};
|
|
641
|
-
var defaultShouldSave = (op, prev) => {
|
|
642
|
-
if (op.type === "set_selection") {
|
|
643
|
-
return false;
|
|
644
|
-
}
|
|
645
|
-
return true;
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
// src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
|
|
649
|
-
var shouldSave = (op, prev) => {
|
|
650
|
-
const excludedNodeType = "suggestion";
|
|
651
|
-
if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
652
|
-
return false;
|
|
653
|
-
}
|
|
654
|
-
if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
655
|
-
return false;
|
|
656
|
-
}
|
|
657
|
-
if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
|
|
658
|
-
return false;
|
|
659
|
-
}
|
|
660
|
-
if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
661
|
-
return false;
|
|
662
|
-
}
|
|
663
|
-
if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
return defaultShouldSave(op, prev);
|
|
670
|
-
};
|
|
671
|
-
function useCopilotTextareaEditor() {
|
|
672
|
-
const editor = useMemo2(() => {
|
|
673
|
-
const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
|
|
674
|
-
const { isVoid } = editor2;
|
|
675
|
-
editor2.isVoid = (element) => {
|
|
676
|
-
switch (element.type) {
|
|
677
|
-
case "suggestion":
|
|
678
|
-
return true;
|
|
679
|
-
default:
|
|
680
|
-
return isVoid(element);
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
const { markableVoid } = editor2;
|
|
684
|
-
editor2.markableVoid = (element) => {
|
|
685
|
-
switch (element.type) {
|
|
686
|
-
case "suggestion":
|
|
687
|
-
return true;
|
|
688
|
-
default:
|
|
689
|
-
return markableVoid(element);
|
|
690
|
-
}
|
|
691
|
-
};
|
|
692
|
-
const { isInline } = editor2;
|
|
693
|
-
editor2.isInline = (element) => {
|
|
694
|
-
switch (element.type) {
|
|
695
|
-
case "suggestion":
|
|
696
|
-
return element.inline;
|
|
697
|
-
default:
|
|
698
|
-
return isInline(element);
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
return editor2;
|
|
702
|
-
}, []);
|
|
703
|
-
return editor;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
// src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
|
|
707
|
-
import React from "react";
|
|
708
|
-
import { ReactEditor } from "slate-react";
|
|
709
|
-
|
|
710
|
-
// src/lib/get-text-around-cursor.ts
|
|
711
|
-
import { Editor as Editor2, Path as Path2, Range as Range2, Text, Element as Element2, Point } from "slate";
|
|
712
|
-
function getTextAroundCollapsedCursor(editor) {
|
|
713
|
-
const { selection } = editor;
|
|
714
|
-
if (!selection || !Range2.isCollapsed(selection)) {
|
|
715
|
-
return null;
|
|
716
|
-
}
|
|
717
|
-
const cursorPoint = selection.anchor;
|
|
718
|
-
const beforeRange = {
|
|
719
|
-
anchor: Editor2.start(editor, []),
|
|
720
|
-
focus: cursorPoint
|
|
721
|
-
};
|
|
722
|
-
const afterRange = {
|
|
723
|
-
anchor: cursorPoint,
|
|
724
|
-
focus: Editor2.end(editor, [])
|
|
725
|
-
};
|
|
726
|
-
const before = extractTextWithNewlines(editor, beforeRange);
|
|
727
|
-
const after = extractTextWithNewlines(editor, afterRange);
|
|
728
|
-
return {
|
|
729
|
-
cursorPoint,
|
|
730
|
-
textBeforeCursor: before,
|
|
731
|
-
textAfterCursor: after
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
function getTextAroundSelection(editor) {
|
|
735
|
-
const { selection } = editor;
|
|
736
|
-
if (!selection) {
|
|
737
|
-
return null;
|
|
738
|
-
}
|
|
739
|
-
const wellOrderedSelection = wellOrderedRange(selection);
|
|
740
|
-
const beforeRange = {
|
|
741
|
-
anchor: Editor2.start(editor, []),
|
|
742
|
-
focus: wellOrderedSelection.anchor
|
|
743
|
-
};
|
|
744
|
-
const afterRange = {
|
|
745
|
-
anchor: wellOrderedSelection.focus,
|
|
746
|
-
focus: Editor2.end(editor, [])
|
|
747
|
-
};
|
|
748
|
-
const before = extractTextWithNewlines(editor, beforeRange);
|
|
749
|
-
const after = extractTextWithNewlines(editor, afterRange);
|
|
750
|
-
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
751
|
-
return {
|
|
752
|
-
selection: wellOrderedSelection,
|
|
753
|
-
textBeforeCursor: before,
|
|
754
|
-
selectedText,
|
|
755
|
-
textAfterCursor: after
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
function getFullEditorTextWithNewlines(editor) {
|
|
759
|
-
const fullDocumentRange = {
|
|
760
|
-
anchor: Editor2.start(editor, []),
|
|
761
|
-
focus: Editor2.end(editor, [])
|
|
762
|
-
};
|
|
763
|
-
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
764
|
-
}
|
|
765
|
-
function extractTextWithNewlines(editor, range) {
|
|
766
|
-
const voids = false;
|
|
767
|
-
const [start, end] = Range2.edges(range);
|
|
768
|
-
let text = "";
|
|
769
|
-
let lastBlock = null;
|
|
770
|
-
for (const [node, path] of Editor2.nodes(editor, {
|
|
771
|
-
at: range,
|
|
772
|
-
match: Text.isText,
|
|
773
|
-
voids
|
|
774
|
-
})) {
|
|
775
|
-
let t = node.text;
|
|
776
|
-
const [block] = Editor2.above(editor, {
|
|
777
|
-
at: path,
|
|
778
|
-
match: (n) => Element2.isElement(n) && n.type === "paragraph"
|
|
779
|
-
}) || [null];
|
|
780
|
-
if (lastBlock !== block && block) {
|
|
781
|
-
if (lastBlock) {
|
|
782
|
-
text += "\n";
|
|
783
|
-
}
|
|
784
|
-
lastBlock = block;
|
|
785
|
-
}
|
|
786
|
-
if (Path2.equals(path, end.path)) {
|
|
787
|
-
t = t.slice(0, end.offset);
|
|
788
|
-
}
|
|
789
|
-
if (Path2.equals(path, start.path)) {
|
|
790
|
-
t = t.slice(start.offset);
|
|
791
|
-
}
|
|
792
|
-
text += t;
|
|
793
|
-
}
|
|
794
|
-
return text;
|
|
795
|
-
}
|
|
796
|
-
function wellOrderedRange(range) {
|
|
797
|
-
const { anchor, focus } = range;
|
|
798
|
-
if (Point.isBefore(anchor, focus)) {
|
|
799
|
-
return range;
|
|
800
|
-
}
|
|
801
|
-
return {
|
|
802
|
-
anchor: focus,
|
|
803
|
-
focus: anchor
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
// src/lib/slatejs-edits/replace-text.ts
|
|
808
|
-
import { Editor as Editor3, Transforms as Transforms2 } from "slate";
|
|
809
|
-
function replaceEditorText(editor, newText) {
|
|
810
|
-
Transforms2.delete(editor, {
|
|
811
|
-
at: {
|
|
812
|
-
anchor: Editor3.start(editor, []),
|
|
813
|
-
focus: Editor3.end(editor, [])
|
|
814
|
-
}
|
|
815
|
-
});
|
|
816
|
-
if (newText && newText !== "") {
|
|
817
|
-
Transforms2.insertNodes(
|
|
818
|
-
editor,
|
|
819
|
-
[
|
|
820
|
-
{
|
|
821
|
-
type: "paragraph",
|
|
822
|
-
children: [{ text: newText }]
|
|
823
|
-
}
|
|
824
|
-
],
|
|
825
|
-
{
|
|
826
|
-
at: [0]
|
|
827
|
-
}
|
|
828
|
-
);
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
|
|
833
|
-
function usePopulateCopilotTextareaRef(editor, ref) {
|
|
834
|
-
React.useImperativeHandle(ref, () => {
|
|
835
|
-
class Combined {
|
|
836
|
-
constructor(customMethods2, editorHtmlElement2) {
|
|
837
|
-
this.customMethods = customMethods2;
|
|
838
|
-
this.editorHtmlElement = editorHtmlElement2;
|
|
839
|
-
}
|
|
840
|
-
get(target, propKey) {
|
|
841
|
-
if (this.isKeyOfCustomMethods(propKey)) {
|
|
842
|
-
const value = this.customMethods[propKey];
|
|
843
|
-
if (typeof value === "function") {
|
|
844
|
-
return value.bind(this.customMethods);
|
|
845
|
-
}
|
|
846
|
-
return value;
|
|
847
|
-
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
848
|
-
const value = this.editorHtmlElement[propKey];
|
|
849
|
-
if (typeof value === "function") {
|
|
850
|
-
return value.bind(this.editorHtmlElement);
|
|
851
|
-
}
|
|
852
|
-
return value;
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
set(target, propKey, value) {
|
|
856
|
-
if (this.isKeyOfCustomMethods(propKey)) {
|
|
857
|
-
this.customMethods[propKey] = value;
|
|
858
|
-
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
859
|
-
this.editorHtmlElement[propKey] = value;
|
|
860
|
-
} else {
|
|
861
|
-
target[propKey] = value;
|
|
862
|
-
}
|
|
863
|
-
return true;
|
|
864
|
-
}
|
|
865
|
-
isKeyOfCustomMethods(key) {
|
|
866
|
-
return key in this.customMethods;
|
|
867
|
-
}
|
|
868
|
-
isKeyOfHTMLElement(key) {
|
|
869
|
-
return key in this.editorHtmlElement;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
const handler = {
|
|
873
|
-
get(target, propKey) {
|
|
874
|
-
return target.get(target, propKey);
|
|
875
|
-
},
|
|
876
|
-
set(target, propKey, value) {
|
|
877
|
-
return target.set(target, propKey, value);
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
class CustomMethods {
|
|
881
|
-
constructor(editor2) {
|
|
882
|
-
this.editor = editor2;
|
|
883
|
-
}
|
|
884
|
-
focus() {
|
|
885
|
-
ReactEditor.focus(this.editor);
|
|
886
|
-
}
|
|
887
|
-
blur() {
|
|
888
|
-
ReactEditor.blur(this.editor);
|
|
889
|
-
}
|
|
890
|
-
get value() {
|
|
891
|
-
return getFullEditorTextWithNewlines(this.editor);
|
|
892
|
-
}
|
|
893
|
-
set value(value) {
|
|
894
|
-
replaceEditorText(this.editor, value);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);
|
|
898
|
-
const customMethods = new CustomMethods(editor);
|
|
899
|
-
const combined = new Combined(customMethods, editorHtmlElement);
|
|
900
|
-
return new Proxy(combined, handler);
|
|
901
|
-
}, [editor]);
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
// src/lib/slatejs-edits/add-autocompletions.ts
|
|
905
|
-
import { Transforms as Transforms3 } from "slate";
|
|
906
|
-
function addAutocompletionsToEditor(editor, newSuggestion, point) {
|
|
907
|
-
const editorPosition = editor.selection;
|
|
908
|
-
Transforms3.insertNodes(
|
|
909
|
-
editor,
|
|
910
|
-
[
|
|
911
|
-
{
|
|
912
|
-
type: "suggestion",
|
|
913
|
-
inline: true,
|
|
914
|
-
content: newSuggestion,
|
|
915
|
-
children: [{ text: "" }]
|
|
916
|
-
}
|
|
917
|
-
],
|
|
918
|
-
{
|
|
919
|
-
at: point
|
|
920
|
-
}
|
|
921
|
-
);
|
|
922
|
-
if (editorPosition) {
|
|
923
|
-
editor.selection = editorPosition;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
// src/lib/slatejs-edits/clear-autocompletions.ts
|
|
928
|
-
import { Element as Element3, Node as Node2, Transforms as Transforms4 } from "slate";
|
|
929
|
-
function clearAutocompletionsFromEditor(editor) {
|
|
930
|
-
const paths = [];
|
|
931
|
-
for (const [node, path] of Node2.nodes(editor)) {
|
|
932
|
-
if (Element3.isElement(node) && node.type === "suggestion") {
|
|
933
|
-
paths.push(path);
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
for (const path of paths) {
|
|
937
|
-
try {
|
|
938
|
-
Transforms4.removeNodes(editor, { at: path });
|
|
939
|
-
} catch (e) {
|
|
940
|
-
console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
// src/components/hovering-toolbar/hovering-toolbar.tsx
|
|
946
|
-
import { useEffect as useEffect4, useRef as useRef2, useState as useState5 } from "react";
|
|
947
|
-
import { Transforms as Transforms5 } from "slate";
|
|
948
|
-
import { useSlate, useSlateSelection } from "slate-react";
|
|
949
|
-
|
|
950
|
-
// src/hooks/misc/use-autosize-textarea.tsx
|
|
951
|
-
import { useEffect as useEffect2 } from "react";
|
|
952
|
-
var useAutosizeTextArea = (textAreaRef, value) => {
|
|
953
|
-
useEffect2(() => {
|
|
954
|
-
if (textAreaRef.current !== null) {
|
|
955
|
-
textAreaRef.current.style.height = "0px";
|
|
956
|
-
const scrollHeight = textAreaRef.current.scrollHeight;
|
|
957
|
-
textAreaRef.current.style.height = scrollHeight + "px";
|
|
958
|
-
}
|
|
959
|
-
}, [textAreaRef, value]);
|
|
960
|
-
};
|
|
961
|
-
var use_autosize_textarea_default = useAutosizeTextArea;
|
|
962
|
-
|
|
963
|
-
// src/components/source-search-box/source-search-box.tsx
|
|
964
|
-
import { useState as useState2 } from "react";
|
|
965
|
-
|
|
966
|
-
// src/components/ui/command.tsx
|
|
967
|
-
import * as React2 from "react";
|
|
968
|
-
import { Command as CommandPrimitive } from "cmdk";
|
|
969
|
-
import { jsx } from "react/jsx-runtime";
|
|
970
|
-
var Command = React2.forwardRef((_a, ref) => {
|
|
971
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
972
|
-
return /* @__PURE__ */ jsx(
|
|
973
|
-
CommandPrimitive,
|
|
974
|
-
__spreadValues({
|
|
975
|
-
ref,
|
|
976
|
-
className: cn(
|
|
977
|
-
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
|
978
|
-
className
|
|
979
|
-
)
|
|
980
|
-
}, props)
|
|
981
|
-
);
|
|
982
|
-
});
|
|
983
|
-
Command.displayName = CommandPrimitive.displayName;
|
|
984
|
-
var CommandInput = React2.forwardRef((_a, ref) => {
|
|
985
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
986
|
-
return /* @__PURE__ */ jsx("div", { className: "flex items-center border-b px-3", "cmdk-input-wrapper": "", children: /* @__PURE__ */ jsx(
|
|
987
|
-
CommandPrimitive.Input,
|
|
988
|
-
__spreadValues({
|
|
989
|
-
ref,
|
|
990
|
-
className: cn(
|
|
991
|
-
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
992
|
-
className
|
|
993
|
-
)
|
|
994
|
-
}, props)
|
|
995
|
-
) });
|
|
996
|
-
});
|
|
997
|
-
CommandInput.displayName = CommandPrimitive.Input.displayName;
|
|
998
|
-
var CommandList = React2.forwardRef((_a, ref) => {
|
|
999
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1000
|
-
return /* @__PURE__ */ jsx(
|
|
1001
|
-
CommandPrimitive.List,
|
|
1002
|
-
__spreadValues({
|
|
1003
|
-
ref,
|
|
1004
|
-
className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden pb-2", className)
|
|
1005
|
-
}, props)
|
|
1006
|
-
);
|
|
1007
|
-
});
|
|
1008
|
-
CommandList.displayName = CommandPrimitive.List.displayName;
|
|
1009
|
-
var CommandEmpty = React2.forwardRef((props, ref) => /* @__PURE__ */ jsx(CommandPrimitive.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
|
|
1010
|
-
CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
|
|
1011
|
-
var CommandGroup = React2.forwardRef((_a, ref) => {
|
|
1012
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1013
|
-
return /* @__PURE__ */ jsx(
|
|
1014
|
-
CommandPrimitive.Group,
|
|
1015
|
-
__spreadValues({
|
|
1016
|
-
ref,
|
|
1017
|
-
className: cn(
|
|
1018
|
-
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
|
|
1019
|
-
className
|
|
1020
|
-
)
|
|
1021
|
-
}, props)
|
|
1022
|
-
);
|
|
1023
|
-
});
|
|
1024
|
-
CommandGroup.displayName = CommandPrimitive.Group.displayName;
|
|
1025
|
-
var CommandSeparator = React2.forwardRef((_a, ref) => {
|
|
1026
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1027
|
-
return /* @__PURE__ */ jsx(
|
|
1028
|
-
CommandPrimitive.Separator,
|
|
1029
|
-
__spreadValues({
|
|
1030
|
-
ref,
|
|
1031
|
-
className: cn("-mx-1 h-px bg-border", className)
|
|
1032
|
-
}, props)
|
|
1033
|
-
);
|
|
1034
|
-
});
|
|
1035
|
-
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
|
|
1036
|
-
var CommandItem = React2.forwardRef((_a, ref) => {
|
|
1037
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1038
|
-
return /* @__PURE__ */ jsx(
|
|
1039
|
-
CommandPrimitive.Item,
|
|
1040
|
-
__spreadValues({
|
|
1041
|
-
ref,
|
|
1042
|
-
className: cn(
|
|
1043
|
-
"relative flex cursor-default select-none items-center rounded-sm text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
1044
|
-
className
|
|
1045
|
-
)
|
|
1046
|
-
}, props)
|
|
1047
|
-
);
|
|
1048
|
-
});
|
|
1049
|
-
CommandItem.displayName = CommandPrimitive.Item.displayName;
|
|
1050
|
-
var CommandShortcut = (_a) => {
|
|
1051
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1052
|
-
return /* @__PURE__ */ jsx(
|
|
1053
|
-
"span",
|
|
1054
|
-
__spreadValues({
|
|
1055
|
-
className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className)
|
|
1056
|
-
}, props)
|
|
1057
|
-
);
|
|
1058
|
-
};
|
|
1059
|
-
CommandShortcut.displayName = "CommandShortcut";
|
|
1060
|
-
|
|
1061
|
-
// src/components/source-search-box/source-search-box.tsx
|
|
1062
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
1063
|
-
function SourceSearchBox(props) {
|
|
1064
|
-
const [selectedValue, setSelectedValue] = useState2("");
|
|
1065
|
-
return /* @__PURE__ */ jsxs(
|
|
1066
|
-
Command,
|
|
1067
|
-
{
|
|
1068
|
-
className: "rounded-lg border shadow-md",
|
|
1069
|
-
value: selectedValue,
|
|
1070
|
-
onValueChange: (value) => {
|
|
1071
|
-
setSelectedValue(value);
|
|
1072
|
-
},
|
|
1073
|
-
filter: (value, search) => {
|
|
1074
|
-
if (props.searchTerm === "") return 1;
|
|
1075
|
-
if (value.startsWith(props.searchTerm)) return 1;
|
|
1076
|
-
return 0;
|
|
1077
|
-
},
|
|
1078
|
-
children: [
|
|
1079
|
-
/* @__PURE__ */ jsx2(
|
|
1080
|
-
CommandInput,
|
|
1081
|
-
{
|
|
1082
|
-
value: props.searchTerm,
|
|
1083
|
-
className: "rounded-t-lg hidden",
|
|
1084
|
-
placeholder: "Search for a command..."
|
|
1085
|
-
}
|
|
1086
|
-
),
|
|
1087
|
-
/* @__PURE__ */ jsxs(CommandList, { children: [
|
|
1088
|
-
/* @__PURE__ */ jsx2(CommandEmpty, { children: "No results found." }),
|
|
1089
|
-
/* @__PURE__ */ jsx2(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
|
|
1090
|
-
return /* @__PURE__ */ jsx2(
|
|
1091
|
-
CommandItem,
|
|
1092
|
-
{
|
|
1093
|
-
value: filePointer.name,
|
|
1094
|
-
onSelect: (value) => {
|
|
1095
|
-
props.onSelectedFile(filePointer);
|
|
1096
|
-
},
|
|
1097
|
-
children: /* @__PURE__ */ jsxs("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
|
|
1098
|
-
/* @__PURE__ */ jsx2(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ jsx2(
|
|
1099
|
-
"img",
|
|
1100
|
-
{
|
|
1101
|
-
src: filePointer.iconImageUri,
|
|
1102
|
-
alt: filePointer.sourceApplication,
|
|
1103
|
-
className: "w-full h-full"
|
|
1104
|
-
}
|
|
1105
|
-
) }),
|
|
1106
|
-
filePointer.name
|
|
1107
|
-
] })
|
|
1108
|
-
},
|
|
1109
|
-
`word-${filePointer.sourceApplication}.${filePointer.name}`
|
|
1110
|
-
);
|
|
1111
|
-
}) }),
|
|
1112
|
-
/* @__PURE__ */ jsx2(CommandSeparator, {})
|
|
1113
|
-
] })
|
|
1114
|
-
]
|
|
1115
|
-
}
|
|
1116
|
-
);
|
|
1117
|
-
}
|
|
1118
|
-
function Logo({
|
|
1119
|
-
children,
|
|
1120
|
-
width,
|
|
1121
|
-
height
|
|
1122
|
-
}) {
|
|
1123
|
-
return /* @__PURE__ */ jsx2("div", { className: "flex items-center justify-center", style: { width, height }, children });
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
1127
|
-
import { useCopilotContext as useCopilotContext2 } from "@copilotkit/react-core";
|
|
1128
|
-
|
|
1129
|
-
// src/components/ui/button.tsx
|
|
1130
|
-
import * as React3 from "react";
|
|
1131
|
-
import { Slot } from "@radix-ui/react-slot";
|
|
1132
|
-
import { cva } from "class-variance-authority";
|
|
1133
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1134
|
-
var buttonVariants = cva(
|
|
1135
|
-
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
1136
|
-
{
|
|
1137
|
-
variants: {
|
|
1138
|
-
variant: {
|
|
1139
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
1140
|
-
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
1141
|
-
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
1142
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
1143
|
-
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
1144
|
-
link: "text-primary underline-offset-4 hover:underline"
|
|
1145
|
-
},
|
|
1146
|
-
size: {
|
|
1147
|
-
default: "h-10 px-4 py-2",
|
|
1148
|
-
sm: "h-9 rounded-md px-3",
|
|
1149
|
-
lg: "h-11 rounded-md px-8",
|
|
1150
|
-
icon: "h-10 w-10"
|
|
1151
|
-
}
|
|
1152
|
-
},
|
|
1153
|
-
defaultVariants: {
|
|
1154
|
-
variant: "default",
|
|
1155
|
-
size: "default"
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
);
|
|
1159
|
-
var Button = React3.forwardRef(
|
|
1160
|
-
(_a, ref) => {
|
|
1161
|
-
var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
|
|
1162
|
-
const Comp = asChild ? Slot : "button";
|
|
1163
|
-
return /* @__PURE__ */ jsx3(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
|
|
1164
|
-
}
|
|
1165
|
-
);
|
|
1166
|
-
Button.displayName = "Button";
|
|
1167
|
-
|
|
1168
|
-
// src/components/ui/label.tsx
|
|
1169
|
-
import * as React4 from "react";
|
|
1170
|
-
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
1171
|
-
import { cva as cva2 } from "class-variance-authority";
|
|
1172
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1173
|
-
var labelVariants = cva2(
|
|
1174
|
-
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
1175
|
-
);
|
|
1176
|
-
var Label = React4.forwardRef((_a, ref) => {
|
|
1177
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1178
|
-
return /* @__PURE__ */ jsx4(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
|
|
1179
|
-
});
|
|
1180
|
-
Label.displayName = LabelPrimitive.Root.displayName;
|
|
1181
|
-
|
|
1182
|
-
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
1183
|
-
import { useCallback as useCallback3, useEffect as useEffect3, useRef, useState as useState4 } from "react";
|
|
1184
|
-
|
|
1185
|
-
// src/lib/stream-promise-flatten.ts
|
|
1186
|
-
function streamPromiseFlatten(promise) {
|
|
1187
|
-
return new ReadableStream({
|
|
1188
|
-
start(controller) {
|
|
1189
|
-
return __async(this, null, function* () {
|
|
1190
|
-
try {
|
|
1191
|
-
const stream = yield promise;
|
|
1192
|
-
const reader = stream.getReader();
|
|
1193
|
-
while (true) {
|
|
1194
|
-
const { done, value } = yield reader.read();
|
|
1195
|
-
if (done) {
|
|
1196
|
-
controller.close();
|
|
1197
|
-
return;
|
|
1198
|
-
}
|
|
1199
|
-
controller.enqueue(value);
|
|
1200
|
-
}
|
|
1201
|
-
} catch (error) {
|
|
1202
|
-
controller.error(error);
|
|
1203
|
-
}
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
});
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
// src/components/hovering-toolbar/hovering-editor-provider.tsx
|
|
1210
|
-
import { createContext, useState as useState3, useContext } from "react";
|
|
1211
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1212
|
-
var HoveringEditorContext = createContext({
|
|
1213
|
-
isDisplayed: false,
|
|
1214
|
-
setIsDisplayed: () => {
|
|
1215
|
-
}
|
|
1216
|
-
});
|
|
1217
|
-
var HoveringEditorProvider = ({ children }) => {
|
|
1218
|
-
const [isDisplayed, setIsDisplayed] = useState3(false);
|
|
1219
|
-
return /* @__PURE__ */ jsx5(HoveringEditorContext.Provider, { value: { isDisplayed, setIsDisplayed }, children });
|
|
1220
|
-
};
|
|
1221
|
-
var useHoveringEditorContext = () => useContext(HoveringEditorContext);
|
|
1222
|
-
|
|
1223
|
-
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
1224
|
-
import { MdArrowForward, MdCheck } from "react-icons/md";
|
|
1225
|
-
import { Fragment, jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1226
|
-
var HoveringInsertionPromptBoxCore = ({
|
|
1227
|
-
performInsertion,
|
|
1228
|
-
state,
|
|
1229
|
-
insertionOrEditingFunction,
|
|
1230
|
-
contextCategories
|
|
1231
|
-
}) => {
|
|
1232
|
-
const { getDocumentsContext } = useCopilotContext2();
|
|
1233
|
-
const [editSuggestion, setEditSuggestion] = useState4("");
|
|
1234
|
-
const [suggestionIsLoading, setSuggestionIsLoading] = useState4(false);
|
|
1235
|
-
const [adjustmentPrompt, setAdjustmentPrompt] = useState4("");
|
|
1236
|
-
const [generatingSuggestion, setGeneratingSuggestion] = useState4(
|
|
1237
|
-
null
|
|
1238
|
-
);
|
|
1239
|
-
const adjustmentTextAreaRef = useRef(null);
|
|
1240
|
-
const suggestionTextAreaRef = useRef(null);
|
|
1241
|
-
const [filePointers, setFilePointers] = useState4([]);
|
|
1242
|
-
const [suggestedFiles, setSuggestedFiles] = useState4([]);
|
|
1243
|
-
useEffect3(() => {
|
|
1244
|
-
setSuggestedFiles(getDocumentsContext(contextCategories));
|
|
1245
|
-
}, [contextCategories, getDocumentsContext]);
|
|
1246
|
-
use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
|
|
1247
|
-
use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
|
|
1248
|
-
useEffect3(() => {
|
|
1249
|
-
var _a;
|
|
1250
|
-
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
1251
|
-
}, []);
|
|
1252
|
-
useEffect3(() => {
|
|
1253
|
-
if (!generatingSuggestion) {
|
|
1254
|
-
return;
|
|
1255
|
-
}
|
|
1256
|
-
if (generatingSuggestion.locked) {
|
|
1257
|
-
return;
|
|
1258
|
-
}
|
|
1259
|
-
setEditSuggestion("");
|
|
1260
|
-
const reader = generatingSuggestion.getReader();
|
|
1261
|
-
const read = () => __async(void 0, null, function* () {
|
|
1262
|
-
setSuggestionIsLoading(true);
|
|
1263
|
-
while (true) {
|
|
1264
|
-
const { done, value } = yield reader.read();
|
|
1265
|
-
if (done) {
|
|
1266
|
-
break;
|
|
1267
|
-
}
|
|
1268
|
-
setEditSuggestion((prev) => {
|
|
1269
|
-
const newSuggestion = prev + value;
|
|
1270
|
-
if (suggestionTextAreaRef.current) {
|
|
1271
|
-
suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
|
|
1272
|
-
}
|
|
1273
|
-
return newSuggestion;
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
setSuggestionIsLoading(false);
|
|
1277
|
-
});
|
|
1278
|
-
read();
|
|
1279
|
-
return () => {
|
|
1280
|
-
const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
|
|
1281
|
-
try {
|
|
1282
|
-
yield reader.closed;
|
|
1283
|
-
} catch (e) {
|
|
1284
|
-
reader.releaseLock();
|
|
1285
|
-
}
|
|
1286
|
-
});
|
|
1287
|
-
releaseLockIfNotClosed();
|
|
1288
|
-
};
|
|
1289
|
-
}, [generatingSuggestion]);
|
|
1290
|
-
const beginGeneratingAdjustment = useCallback3(() => __async(void 0, null, function* () {
|
|
1291
|
-
if (!adjustmentPrompt.trim()) {
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1294
|
-
let modificationState = state.editorState;
|
|
1295
|
-
if (editSuggestion !== "") {
|
|
1296
|
-
modificationState.selectedText = editSuggestion;
|
|
1297
|
-
}
|
|
1298
|
-
const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
|
|
1299
|
-
modificationState,
|
|
1300
|
-
adjustmentPrompt,
|
|
1301
|
-
filePointers,
|
|
1302
|
-
new AbortController().signal
|
|
1303
|
-
);
|
|
1304
|
-
const adjustmentSuggestionTextStream = streamPromiseFlatten(
|
|
1305
|
-
adjustmentSuggestionTextStreamPromise
|
|
1306
|
-
);
|
|
1307
|
-
setGeneratingSuggestion(adjustmentSuggestionTextStream);
|
|
1308
|
-
}), [
|
|
1309
|
-
adjustmentPrompt,
|
|
1310
|
-
editSuggestion,
|
|
1311
|
-
state.editorState,
|
|
1312
|
-
insertionOrEditingFunction,
|
|
1313
|
-
filePointers
|
|
1314
|
-
]);
|
|
1315
|
-
const isLoading = suggestionIsLoading;
|
|
1316
|
-
const textToEdit = editSuggestion || state.editorState.selectedText;
|
|
1317
|
-
const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
|
|
1318
|
-
const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
|
|
1319
|
-
const { setIsDisplayed } = useHoveringEditorContext();
|
|
1320
|
-
const AdjustmentPromptComponent = /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1321
|
-
/* @__PURE__ */ jsx6(Label, { className: "", children: adjustmentLabel }),
|
|
1322
|
-
/* @__PURE__ */ jsxs2("div", { className: "relative w-full flex items-center", children: [
|
|
1323
|
-
/* @__PURE__ */ jsx6(
|
|
1324
|
-
"textarea",
|
|
1325
|
-
{
|
|
1326
|
-
disabled: suggestionIsLoading,
|
|
1327
|
-
ref: adjustmentTextAreaRef,
|
|
1328
|
-
value: adjustmentPrompt,
|
|
1329
|
-
onChange: (e) => setAdjustmentPrompt(e.target.value),
|
|
1330
|
-
onKeyDown: (e) => {
|
|
1331
|
-
if (e.key === "Enter" && e.shiftKey) {
|
|
1332
|
-
e.preventDefault();
|
|
1333
|
-
setAdjustmentPrompt(adjustmentPrompt + "\n");
|
|
1334
|
-
} else if (e.key === "Enter") {
|
|
1335
|
-
e.preventDefault();
|
|
1336
|
-
beginGeneratingAdjustment();
|
|
1337
|
-
} else if (e.key == "Escape") {
|
|
1338
|
-
e.preventDefault();
|
|
1339
|
-
setIsDisplayed(false);
|
|
1340
|
-
}
|
|
1341
|
-
},
|
|
1342
|
-
placeholder,
|
|
1343
|
-
style: { minHeight: "3rem" },
|
|
1344
|
-
className: "w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]",
|
|
1345
|
-
rows: 1
|
|
1346
|
-
}
|
|
1347
|
-
),
|
|
1348
|
-
/* @__PURE__ */ jsx6(
|
|
1349
|
-
"button",
|
|
1350
|
-
{
|
|
1351
|
-
onClick: beginGeneratingAdjustment,
|
|
1352
|
-
className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
|
|
1353
|
-
children: /* @__PURE__ */ jsx6(MdArrowForward, { className: "text-2xl" })
|
|
1354
|
-
}
|
|
1355
|
-
)
|
|
1356
|
-
] })
|
|
1357
|
-
] });
|
|
1358
|
-
const SuggestionComponent = /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1359
|
-
/* @__PURE__ */ jsxs2("div", { className: "flex justify-between items-end w-full", children: [
|
|
1360
|
-
/* @__PURE__ */ jsx6(Label, { className: "mt-4", children: "Suggested:" }),
|
|
1361
|
-
/* @__PURE__ */ jsx6("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ jsx6("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ jsx6(
|
|
1362
|
-
"div",
|
|
1363
|
-
{
|
|
1364
|
-
className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
|
|
1365
|
-
role: "status",
|
|
1366
|
-
children: /* @__PURE__ */ jsx6("span", { className: "absolute -m-px h-px w-px overflow-hidden whitespace-nowrap border-0 p-0 [clip:rect(0,0,0,0)]", children: "Loading..." })
|
|
1367
|
-
}
|
|
1368
|
-
) }) })
|
|
1369
|
-
] }),
|
|
1370
|
-
/* @__PURE__ */ jsx6(
|
|
1371
|
-
"textarea",
|
|
1372
|
-
{
|
|
1373
|
-
ref: suggestionTextAreaRef,
|
|
1374
|
-
value: editSuggestion,
|
|
1375
|
-
disabled: suggestionIsLoading,
|
|
1376
|
-
onChange: (e) => setEditSuggestion(e.target.value),
|
|
1377
|
-
className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
|
|
1378
|
-
style: { overflow: "auto", maxHeight: "10em" }
|
|
1379
|
-
}
|
|
1380
|
-
)
|
|
1381
|
-
] });
|
|
1382
|
-
const SubmitComponent = /* @__PURE__ */ jsx6("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ jsxs2(
|
|
1383
|
-
Button,
|
|
1384
|
-
{
|
|
1385
|
-
className: " bg-green-700 text-white",
|
|
1386
|
-
onClick: () => {
|
|
1387
|
-
performInsertion(editSuggestion);
|
|
1388
|
-
},
|
|
1389
|
-
children: [
|
|
1390
|
-
"Insert ",
|
|
1391
|
-
/* @__PURE__ */ jsx6(MdCheck, { className: "text-2xl" })
|
|
1392
|
-
]
|
|
1393
|
-
}
|
|
1394
|
-
) });
|
|
1395
|
-
const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
|
|
1396
|
-
const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
|
|
1397
|
-
return /* @__PURE__ */ jsxs2("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
|
|
1398
|
-
AdjustmentPromptComponent,
|
|
1399
|
-
sourceSearchWord !== void 0 && /* @__PURE__ */ jsx6(
|
|
1400
|
-
SourceSearchBox,
|
|
1401
|
-
{
|
|
1402
|
-
searchTerm: sourceSearchWord,
|
|
1403
|
-
suggestedFiles,
|
|
1404
|
-
onSelectedFile: (filePointer) => {
|
|
1405
|
-
var _a;
|
|
1406
|
-
setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), ""));
|
|
1407
|
-
setFilePointers((prev) => [...prev, filePointer]);
|
|
1408
|
-
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
),
|
|
1412
|
-
generatingSuggestion ? SuggestionComponent : null,
|
|
1413
|
-
generatingSuggestion ? SubmitComponent : null
|
|
1414
|
-
] });
|
|
1415
|
-
};
|
|
1416
|
-
|
|
1417
|
-
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
|
|
1418
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1419
|
-
var HoveringInsertionPromptBox = (props) => {
|
|
1420
|
-
return /* @__PURE__ */ jsx7(
|
|
1421
|
-
"div",
|
|
1422
|
-
{
|
|
1423
|
-
className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
|
|
1424
|
-
style: { width: "35rem" },
|
|
1425
|
-
children: /* @__PURE__ */ jsx7(
|
|
1426
|
-
HoveringInsertionPromptBoxCore,
|
|
1427
|
-
{
|
|
1428
|
-
state: {
|
|
1429
|
-
editorState: props.editorState
|
|
1430
|
-
},
|
|
1431
|
-
insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction,
|
|
1432
|
-
performInsertion: props.performInsertion,
|
|
1433
|
-
contextCategories: props.contextCategories
|
|
1434
|
-
}
|
|
1435
|
-
)
|
|
1436
|
-
}
|
|
1437
|
-
);
|
|
1438
|
-
};
|
|
1439
|
-
|
|
1440
|
-
// src/components/hovering-toolbar/hovering-toolbar-components.tsx
|
|
1441
|
-
import { css, cx } from "@emotion/css";
|
|
1442
|
-
import React5 from "react";
|
|
1443
|
-
import ReactDOM from "react-dom";
|
|
1444
|
-
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1445
|
-
var Button2 = React5.forwardRef(
|
|
1446
|
-
(_a, ref) => {
|
|
1447
|
-
var _b = _a, {
|
|
1448
|
-
className,
|
|
1449
|
-
active,
|
|
1450
|
-
reversed
|
|
1451
|
-
} = _b, props = __objRest(_b, [
|
|
1452
|
-
"className",
|
|
1453
|
-
"active",
|
|
1454
|
-
"reversed"
|
|
1455
|
-
]);
|
|
1456
|
-
return /* @__PURE__ */ jsx8(
|
|
1457
|
-
"span",
|
|
1458
|
-
__spreadProps(__spreadValues({}, props), {
|
|
1459
|
-
ref,
|
|
1460
|
-
className: cx(
|
|
1461
|
-
className,
|
|
1462
|
-
css`
|
|
1463
|
-
cursor: pointer;
|
|
1464
|
-
color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
|
|
1465
|
-
`
|
|
1466
|
-
)
|
|
1467
|
-
})
|
|
1468
|
-
);
|
|
1469
|
-
}
|
|
1470
|
-
);
|
|
1471
|
-
var Menu = React5.forwardRef(
|
|
1472
|
-
(_a, ref) => {
|
|
1473
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1474
|
-
return /* @__PURE__ */ jsx8(
|
|
1475
|
-
"div",
|
|
1476
|
-
__spreadProps(__spreadValues({}, props), {
|
|
1477
|
-
"data-test-id": "menu",
|
|
1478
|
-
ref,
|
|
1479
|
-
className: cx(
|
|
1480
|
-
className,
|
|
1481
|
-
css`
|
|
1482
|
-
& > * {
|
|
1483
|
-
display: inline-block;
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
& > * + * {
|
|
1487
|
-
margin-left: 15px;
|
|
1488
|
-
}
|
|
1489
|
-
`
|
|
1490
|
-
)
|
|
1491
|
-
})
|
|
1492
|
-
);
|
|
1493
|
-
}
|
|
1494
|
-
);
|
|
1495
|
-
var Portal = ({ children }) => {
|
|
1496
|
-
return typeof document === "object" ? ReactDOM.createPortal(children, document.body) : null;
|
|
1497
|
-
};
|
|
1498
|
-
var Toolbar = React5.forwardRef(
|
|
1499
|
-
(_a, ref) => {
|
|
1500
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1501
|
-
return /* @__PURE__ */ jsx8(
|
|
1502
|
-
Menu,
|
|
1503
|
-
__spreadProps(__spreadValues({}, props), {
|
|
1504
|
-
ref,
|
|
1505
|
-
className: cx(
|
|
1506
|
-
className,
|
|
1507
|
-
css`
|
|
1508
|
-
position: relative;
|
|
1509
|
-
padding: 1px 18px 17px;
|
|
1510
|
-
margin: 0 -20px;
|
|
1511
|
-
border-bottom: 2px solid #eee;
|
|
1512
|
-
margin-bottom: 20px;
|
|
1513
|
-
`
|
|
1514
|
-
)
|
|
1515
|
-
})
|
|
1516
|
-
);
|
|
1517
|
-
}
|
|
1518
|
-
);
|
|
1519
|
-
|
|
1520
|
-
// src/components/hovering-toolbar/hovering-toolbar.tsx
|
|
1521
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1522
|
-
var HoveringToolbar = (props) => {
|
|
1523
|
-
const ref = useRef2(null);
|
|
1524
|
-
const editor = useSlate();
|
|
1525
|
-
const selection = useSlateSelection();
|
|
1526
|
-
const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
|
|
1527
|
-
const [isClient, setIsClient] = useState5(false);
|
|
1528
|
-
useEffect4(() => {
|
|
1529
|
-
setIsClient(true);
|
|
1530
|
-
}, []);
|
|
1531
|
-
useEffect4(() => {
|
|
1532
|
-
const el = ref.current;
|
|
1533
|
-
const { selection: selection2 } = editor;
|
|
1534
|
-
if (!el) {
|
|
1535
|
-
return;
|
|
1536
|
-
}
|
|
1537
|
-
if (!selection2) {
|
|
1538
|
-
el.removeAttribute("style");
|
|
1539
|
-
return;
|
|
1540
|
-
}
|
|
1541
|
-
const domSelection = window.getSelection();
|
|
1542
|
-
if (!domSelection || domSelection.rangeCount === 0) {
|
|
1543
|
-
return;
|
|
1544
|
-
}
|
|
1545
|
-
const domRange = domSelection.getRangeAt(0);
|
|
1546
|
-
const rect = domRange.getBoundingClientRect();
|
|
1547
|
-
if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
|
|
1548
|
-
return;
|
|
1549
|
-
}
|
|
1550
|
-
const minGapFromEdge = 60;
|
|
1551
|
-
const verticalOffsetFromCorner = 35;
|
|
1552
|
-
const horizontalOffsetFromCorner = 15;
|
|
1553
|
-
let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
|
|
1554
|
-
if (top < minGapFromEdge) {
|
|
1555
|
-
top = rect.bottom + window.scrollY + minGapFromEdge;
|
|
1556
|
-
} else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
|
|
1557
|
-
top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
|
|
1558
|
-
}
|
|
1559
|
-
let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
|
|
1560
|
-
if (left < minGapFromEdge) {
|
|
1561
|
-
left = minGapFromEdge;
|
|
1562
|
-
} else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
|
|
1563
|
-
left = window.innerWidth - el.offsetWidth - minGapFromEdge;
|
|
1564
|
-
}
|
|
1565
|
-
el.style.opacity = "1";
|
|
1566
|
-
el.style.position = "absolute";
|
|
1567
|
-
el.style.top = `${top}px`;
|
|
1568
|
-
el.style.left = `${left}px`;
|
|
1569
|
-
});
|
|
1570
|
-
useEffect4(() => {
|
|
1571
|
-
const handleClickOutside = (event) => {
|
|
1572
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
1573
|
-
setIsDisplayed(false);
|
|
1574
|
-
}
|
|
1575
|
-
};
|
|
1576
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
1577
|
-
return () => {
|
|
1578
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
1579
|
-
};
|
|
1580
|
-
}, [ref, setIsDisplayed]);
|
|
1581
|
-
if (!isClient) {
|
|
1582
|
-
return null;
|
|
1583
|
-
}
|
|
1584
|
-
return /* @__PURE__ */ jsx9(Portal, { children: /* @__PURE__ */ jsx9(
|
|
1585
|
-
Menu,
|
|
1586
|
-
{
|
|
1587
|
-
ref,
|
|
1588
|
-
className: "copilot-kit-textarea-css-scope " + (props.hoverMenuClassname || "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700"),
|
|
1589
|
-
children: isDisplayed && selection && /* @__PURE__ */ jsx9(
|
|
1590
|
-
HoveringInsertionPromptBox,
|
|
1591
|
-
{
|
|
1592
|
-
editorState: editorState(editor, selection),
|
|
1593
|
-
apiConfig: props.apiConfig,
|
|
1594
|
-
closeWindow: () => {
|
|
1595
|
-
setIsDisplayed(false);
|
|
1596
|
-
},
|
|
1597
|
-
performInsertion: (insertedText) => {
|
|
1598
|
-
Transforms5.delete(editor, { at: selection });
|
|
1599
|
-
Transforms5.insertText(editor, insertedText, {
|
|
1600
|
-
at: selection
|
|
1601
|
-
});
|
|
1602
|
-
setIsDisplayed(false);
|
|
1603
|
-
},
|
|
1604
|
-
contextCategories: props.contextCategories
|
|
1605
|
-
}
|
|
1606
|
-
)
|
|
1607
|
-
}
|
|
1608
|
-
) });
|
|
1609
|
-
};
|
|
1610
|
-
function editorState(editor, selection) {
|
|
1611
|
-
const textAroundCursor = getTextAroundSelection(editor);
|
|
1612
|
-
if (textAroundCursor) {
|
|
1613
|
-
return textAroundCursor;
|
|
1614
|
-
}
|
|
1615
|
-
return {
|
|
1616
|
-
textBeforeCursor: getFullEditorTextWithNewlines(editor),
|
|
1617
|
-
textAfterCursor: "",
|
|
1618
|
-
selectedText: ""
|
|
1619
|
-
};
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
// src/components/base-copilot-textarea/render-element.tsx
|
|
1623
|
-
import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1624
|
-
function makeRenderElementFunction(suggestionsStyle) {
|
|
1625
|
-
return (props) => {
|
|
1626
|
-
switch (props.element.type) {
|
|
1627
|
-
case "paragraph":
|
|
1628
|
-
return /* @__PURE__ */ jsx10(DefaultElement, __spreadValues({}, props));
|
|
1629
|
-
case "suggestion":
|
|
1630
|
-
return /* @__PURE__ */ jsx10(SuggestionElement, __spreadProps(__spreadValues({}, props), { suggestionsStyle }));
|
|
1631
|
-
}
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
var DefaultElement = (props) => {
|
|
1635
|
-
return /* @__PURE__ */ jsx10("div", __spreadProps(__spreadValues({}, props.attributes), { children: props.children }));
|
|
1636
|
-
};
|
|
1637
|
-
var SuggestionElement = (props) => {
|
|
1638
|
-
return /* @__PURE__ */ jsxs3(
|
|
1639
|
-
"span",
|
|
1640
|
-
__spreadProps(__spreadValues({}, props.attributes), {
|
|
1641
|
-
style: __spreadValues({}, props.suggestionsStyle),
|
|
1642
|
-
contentEditable: false,
|
|
1643
|
-
children: [
|
|
1644
|
-
props.children,
|
|
1645
|
-
props.element.type === "suggestion" && props.element.content
|
|
1646
|
-
]
|
|
1647
|
-
})
|
|
1648
|
-
);
|
|
1649
|
-
};
|
|
1650
|
-
|
|
1651
|
-
// src/components/base-copilot-textarea/render-placeholder.tsx
|
|
1652
|
-
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1653
|
-
function makeRenderPlaceholderFunction(placeholderStyle) {
|
|
1654
|
-
return (props) => {
|
|
1655
|
-
const _a = props.attributes, { style } = _a, restAttributes = __objRest(_a, ["style"]);
|
|
1656
|
-
return /* @__PURE__ */ jsx11(
|
|
1657
|
-
"div",
|
|
1658
|
-
__spreadProps(__spreadValues({}, restAttributes), {
|
|
1659
|
-
style: __spreadValues(__spreadValues({}, style), placeholderStyle),
|
|
1660
|
-
children: props.children
|
|
1661
|
-
})
|
|
1662
|
-
);
|
|
1663
|
-
};
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
// src/components/base-copilot-textarea/use-add-branding-css.tsx
|
|
1667
|
-
import { useEffect as useEffect5 } from "react";
|
|
1668
|
-
function useAddBrandingCss(suggestionStyleAugmented, disableBranding) {
|
|
1669
|
-
const cssSelector = ".copilot-textarea.with-branding";
|
|
1670
|
-
useEffect5(() => {
|
|
1671
|
-
if (disableBranding) {
|
|
1672
|
-
return;
|
|
1673
|
-
}
|
|
1674
|
-
const styleEl = document.createElement("style");
|
|
1675
|
-
styleEl.id = "dynamic-styles";
|
|
1676
|
-
let dynamicStyles = Object.entries(suggestionStyleAugmented).map(([key, value]) => {
|
|
1677
|
-
const kebabCaseKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
1678
|
-
return `${kebabCaseKey}: ${value};`;
|
|
1679
|
-
}).join(" ");
|
|
1680
|
-
dynamicStyles += `font-style: normal; font-size: x-small;`;
|
|
1681
|
-
dynamicStyles += `content: "CopilotKit";`;
|
|
1682
|
-
dynamicStyles += `bottom: 6px;`;
|
|
1683
|
-
dynamicStyles += `right: 6px;`;
|
|
1684
|
-
dynamicStyles += `pointer-events: none;`;
|
|
1685
|
-
dynamicStyles += `font-weight: 200;`;
|
|
1686
|
-
dynamicStyles += `padding: 0;`;
|
|
1687
|
-
dynamicStyles += `margin: 0;`;
|
|
1688
|
-
dynamicStyles += `border: 0;`;
|
|
1689
|
-
dynamicStyles += `line-height: 1;`;
|
|
1690
|
-
dynamicStyles += `position: absolute;`;
|
|
1691
|
-
styleEl.innerHTML = `
|
|
1692
|
-
${cssSelector}::after {
|
|
1693
|
-
${dynamicStyles}
|
|
1694
|
-
}
|
|
1695
|
-
`;
|
|
1696
|
-
document.head.appendChild(styleEl);
|
|
1697
|
-
const textarea = document.querySelector(cssSelector);
|
|
1698
|
-
const handleScroll = () => {
|
|
1699
|
-
const styleEl2 = document.getElementById("dynamic-styles");
|
|
1700
|
-
if (styleEl2 && textarea) {
|
|
1701
|
-
const offsetFromBottom = -textarea.scrollTop + 6;
|
|
1702
|
-
const offsetFromRight = -textarea.scrollLeft + 6;
|
|
1703
|
-
styleEl2.innerHTML = `
|
|
1704
|
-
${cssSelector}::after {
|
|
1705
|
-
${dynamicStyles}
|
|
1706
|
-
bottom: ${offsetFromBottom}px;
|
|
1707
|
-
right: ${offsetFromRight}px;
|
|
1708
|
-
}
|
|
1709
|
-
`;
|
|
1710
|
-
}
|
|
1711
|
-
};
|
|
1712
|
-
textarea == null ? void 0 : textarea.addEventListener("scroll", handleScroll);
|
|
1713
|
-
return () => {
|
|
1714
|
-
var _a;
|
|
1715
|
-
(_a = document.getElementById("dynamic-styles")) == null ? void 0 : _a.remove();
|
|
1716
|
-
textarea == null ? void 0 : textarea.removeEventListener("scroll", handleScroll);
|
|
1717
|
-
};
|
|
1718
|
-
}, [disableBranding, suggestionStyleAugmented]);
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
// src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
|
|
1722
|
-
import { useEffect as useEffect6, useRef as useRef3 } from "react";
|
|
1723
|
-
import { useSlateSelector } from "slate-react";
|
|
1724
|
-
import { Range as Range3 } from "slate";
|
|
1725
|
-
|
|
1726
|
-
// src/lib/editor-to-text.ts
|
|
1727
|
-
import { Element as Element4 } from "slate";
|
|
1728
|
-
function nodeChildrenToTextComponents(editor, nodes) {
|
|
1729
|
-
const indeciesOfInlineElements = new Set(
|
|
1730
|
-
nodes.map((node, index) => {
|
|
1731
|
-
if (Element4.isElement(node) && editor.isInline(node)) {
|
|
1732
|
-
return index;
|
|
1733
|
-
}
|
|
1734
|
-
return -1;
|
|
1735
|
-
}).filter((index) => index !== -1)
|
|
1736
|
-
);
|
|
1737
|
-
const nonIgnorableItems = nodes.filter((node, index) => {
|
|
1738
|
-
const isInline = indeciesOfInlineElements.has(index);
|
|
1739
|
-
if (isInline) {
|
|
1740
|
-
return false;
|
|
1741
|
-
}
|
|
1742
|
-
const isNeighbourOfInline = indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
|
|
1743
|
-
if (isNeighbourOfInline) {
|
|
1744
|
-
return node.text !== "";
|
|
1745
|
-
}
|
|
1746
|
-
return true;
|
|
1747
|
-
});
|
|
1748
|
-
return nonIgnorableItems.map((node) => {
|
|
1749
|
-
if (Element4.isElement(node)) {
|
|
1750
|
-
switch (node.type) {
|
|
1751
|
-
case "paragraph":
|
|
1752
|
-
return nodeChildrenToTextComponents(editor, node.children);
|
|
1753
|
-
case "suggestion":
|
|
1754
|
-
return [];
|
|
1755
|
-
}
|
|
1756
|
-
} else {
|
|
1757
|
-
return [node];
|
|
1758
|
-
}
|
|
1759
|
-
}).reduce((acc, val) => acc.concat(val), []);
|
|
1760
|
-
}
|
|
1761
|
-
var editorToText = (editor) => {
|
|
1762
|
-
const flattened = nodeChildrenToTextComponents(editor, editor.children);
|
|
1763
|
-
const text = flattened.map((textComponent) => textComponent.text).join("\n");
|
|
1764
|
-
return text;
|
|
1765
|
-
};
|
|
1766
|
-
|
|
1767
|
-
// src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
|
|
1768
|
-
import { Fragment as Fragment2, jsx as jsx12 } from "react/jsx-runtime";
|
|
1769
|
-
function TrackerTextEditedSinceLastCursorMovement(props) {
|
|
1770
|
-
const cursorState = useSlateSelector((state) => ({
|
|
1771
|
-
selection: state.selection,
|
|
1772
|
-
text: editorToText(state)
|
|
1773
|
-
}));
|
|
1774
|
-
const previousState = usePrevious(cursorState);
|
|
1775
|
-
useEffect6(() => {
|
|
1776
|
-
if (!previousState) {
|
|
1777
|
-
return;
|
|
1778
|
-
}
|
|
1779
|
-
if (cursorChangedWithoutTextChanged(previousState, cursorState)) {
|
|
1780
|
-
props.setCursorMovedSinceLastTextChange(true);
|
|
1781
|
-
}
|
|
1782
|
-
}, [props.setCursorMovedSinceLastTextChange, cursorState]);
|
|
1783
|
-
return /* @__PURE__ */ jsx12(Fragment2, {});
|
|
1784
|
-
}
|
|
1785
|
-
var cursorChangedWithoutTextChanged = (prev, next) => {
|
|
1786
|
-
const isSelectionChanged = !isSelectionEqual(prev.selection, next.selection);
|
|
1787
|
-
const isTextSame = prev.text === next.text;
|
|
1788
|
-
return isSelectionChanged && isTextSame;
|
|
1789
|
-
};
|
|
1790
|
-
var isSelectionEqual = (a, b) => {
|
|
1791
|
-
if (!a && !b) return true;
|
|
1792
|
-
if (!a || !b) return false;
|
|
1793
|
-
return Range3.equals(a, b);
|
|
1794
|
-
};
|
|
1795
|
-
function usePrevious(value) {
|
|
1796
|
-
const ref = useRef3();
|
|
1797
|
-
useEffect6(() => {
|
|
1798
|
-
ref.current = value;
|
|
1799
|
-
});
|
|
1800
|
-
return ref.current;
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
// src/components/base-copilot-textarea/base-copilot-textarea.tsx
|
|
1804
|
-
import { jsx as jsx13, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1805
|
-
var BaseCopilotTextarea = React6.forwardRef(
|
|
1806
|
-
(props, ref) => {
|
|
1807
|
-
return /* @__PURE__ */ jsx13(HoveringEditorProvider, { children: /* @__PURE__ */ jsx13(BaseCopilotTextareaWithHoveringContext, __spreadProps(__spreadValues({}, props), { ref })) });
|
|
1808
|
-
}
|
|
1809
|
-
);
|
|
1810
|
-
var BaseCopilotTextareaWithHoveringContext = React6.forwardRef(
|
|
1811
|
-
(props, ref) => {
|
|
1812
|
-
const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultBaseAutosuggestionsConfig), props.baseAutosuggestionsConfig);
|
|
1813
|
-
const valueOnInitialRender = useMemo3(() => {
|
|
1814
|
-
var _a2;
|
|
1815
|
-
return (_a2 = props.value) != null ? _a2 : "";
|
|
1816
|
-
}, []);
|
|
1817
|
-
const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState6(valueOnInitialRender);
|
|
1818
|
-
const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState6(false);
|
|
1819
|
-
const initialValue = useMemo3(() => {
|
|
1820
|
-
return [
|
|
1821
|
-
{
|
|
1822
|
-
type: "paragraph",
|
|
1823
|
-
children: [{ text: valueOnInitialRender }]
|
|
1824
|
-
}
|
|
1825
|
-
];
|
|
1826
|
-
}, [valueOnInitialRender]);
|
|
1827
|
-
const editor = useCopilotTextareaEditor();
|
|
1828
|
-
const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } = useHoveringEditorContext();
|
|
1829
|
-
const insertText = useCallback4(
|
|
1830
|
-
(autosuggestion) => {
|
|
1831
|
-
Editor5.insertText(editor, autosuggestion.text, {
|
|
1832
|
-
at: autosuggestion.point
|
|
1833
|
-
});
|
|
1834
|
-
},
|
|
1835
|
-
[editor]
|
|
1836
|
-
);
|
|
1837
|
-
const shouldDisableAutosuggestions = (
|
|
1838
|
-
// textarea is manually disabled:
|
|
1839
|
-
autosuggestionsConfig.disabled || // hovering editor is displayed:
|
|
1840
|
-
hoveringEditorIsDisplayed || // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:
|
|
1841
|
-
cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
|
|
1842
|
-
);
|
|
1843
|
-
const {
|
|
1844
|
-
currentAutocompleteSuggestion,
|
|
1845
|
-
onChangeHandler: onChangeHandlerForAutocomplete,
|
|
1846
|
-
onKeyDownHandler: onKeyDownHandlerForAutocomplete,
|
|
1847
|
-
onTouchStartHandler: onTouchStartHandlerForAutocomplete
|
|
1848
|
-
} = useAutosuggestions(
|
|
1849
|
-
autosuggestionsConfig.debounceTime,
|
|
1850
|
-
autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,
|
|
1851
|
-
autosuggestionsConfig.shouldAcceptAutosuggestionOnTouch,
|
|
1852
|
-
autosuggestionsConfig.apiConfig.autosuggestionsFunction,
|
|
1853
|
-
insertText,
|
|
1854
|
-
autosuggestionsConfig.disableWhenEmpty,
|
|
1855
|
-
shouldDisableAutosuggestions
|
|
1856
|
-
);
|
|
1857
|
-
const onKeyDownHandlerForHoveringEditor = useCallback4(
|
|
1858
|
-
(event) => {
|
|
1859
|
-
var _a2;
|
|
1860
|
-
if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event, (_a2 = props.shortcut) != null ? _a2 : "k")) {
|
|
1861
|
-
event.preventDefault();
|
|
1862
|
-
setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
|
|
1863
|
-
}
|
|
1864
|
-
},
|
|
1865
|
-
[
|
|
1866
|
-
hoveringEditorIsDisplayed,
|
|
1867
|
-
setHoveringEditorIsDisplayed,
|
|
1868
|
-
autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress
|
|
1869
|
-
]
|
|
1870
|
-
);
|
|
1871
|
-
useEffect7(() => {
|
|
1872
|
-
clearAutocompletionsFromEditor(editor);
|
|
1873
|
-
if (currentAutocompleteSuggestion) {
|
|
1874
|
-
addAutocompletionsToEditor(
|
|
1875
|
-
editor,
|
|
1876
|
-
currentAutocompleteSuggestion.text,
|
|
1877
|
-
currentAutocompleteSuggestion.point
|
|
1878
|
-
);
|
|
1879
|
-
}
|
|
1880
|
-
}, [currentAutocompleteSuggestion]);
|
|
1881
|
-
const suggestionStyleAugmented = useMemo3(() => {
|
|
1882
|
-
return __spreadValues({
|
|
1883
|
-
fontStyle: "italic",
|
|
1884
|
-
color: "gray"
|
|
1885
|
-
}, props.suggestionsStyle);
|
|
1886
|
-
}, [props.suggestionsStyle]);
|
|
1887
|
-
const renderElementMemoized = useMemo3(() => {
|
|
1888
|
-
return makeRenderElementFunction(suggestionStyleAugmented);
|
|
1889
|
-
}, [suggestionStyleAugmented]);
|
|
1890
|
-
const renderPlaceholderMemoized = useMemo3(() => {
|
|
1891
|
-
const placeholderStyleSlatejsOverrides = {
|
|
1892
|
-
top: void 0
|
|
1893
|
-
};
|
|
1894
|
-
const placeholderStyleAugmented = __spreadValues(__spreadValues({}, placeholderStyleSlatejsOverrides), props.placeholderStyle);
|
|
1895
|
-
return makeRenderPlaceholderFunction(placeholderStyleAugmented);
|
|
1896
|
-
}, [props.placeholderStyle]);
|
|
1897
|
-
useEffect7(() => {
|
|
1898
|
-
var _a2, _b;
|
|
1899
|
-
if (props.value === lastKnownFullEditorText) {
|
|
1900
|
-
return;
|
|
1901
|
-
}
|
|
1902
|
-
setLastKnownFullEditorText((_a2 = props.value) != null ? _a2 : "");
|
|
1903
|
-
replaceEditorText(editor, (_b = props.value) != null ? _b : "");
|
|
1904
|
-
}, [props.value]);
|
|
1905
|
-
const _a = props, {
|
|
1906
|
-
placeholderStyle,
|
|
1907
|
-
value,
|
|
1908
|
-
hoverMenuClassname,
|
|
1909
|
-
onValueChange,
|
|
1910
|
-
baseAutosuggestionsConfig: autosuggestionsConfigFromProps,
|
|
1911
|
-
className,
|
|
1912
|
-
onChange,
|
|
1913
|
-
onKeyDown,
|
|
1914
|
-
disableBranding
|
|
1915
|
-
} = _a, propsToForward = __objRest(_a, [
|
|
1916
|
-
"placeholderStyle",
|
|
1917
|
-
"value",
|
|
1918
|
-
"hoverMenuClassname",
|
|
1919
|
-
"onValueChange",
|
|
1920
|
-
"baseAutosuggestionsConfig",
|
|
1921
|
-
"className",
|
|
1922
|
-
"onChange",
|
|
1923
|
-
"onKeyDown",
|
|
1924
|
-
"disableBranding"
|
|
1925
|
-
]);
|
|
1926
|
-
useAddBrandingCss(suggestionStyleAugmented, disableBranding);
|
|
1927
|
-
usePopulateCopilotTextareaRef(editor, ref);
|
|
1928
|
-
const moddedClassName = (() => {
|
|
1929
|
-
const baseClassName = "copilot-textarea";
|
|
1930
|
-
const brandingClass = disableBranding ? "no-branding" : "with-branding";
|
|
1931
|
-
const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
|
|
1932
|
-
const mergedClassName = twMerge2(defaultTailwindClassName, className != null ? className : "");
|
|
1933
|
-
return `${baseClassName} ${brandingClass} ${mergedClassName}`;
|
|
1934
|
-
})();
|
|
1935
|
-
return /* @__PURE__ */ jsxs4(
|
|
1936
|
-
Slate,
|
|
1937
|
-
{
|
|
1938
|
-
editor,
|
|
1939
|
-
initialValue,
|
|
1940
|
-
onChange: (value2) => {
|
|
1941
|
-
var _a2, _b;
|
|
1942
|
-
const newEditorState = getTextAroundCollapsedCursor(editor);
|
|
1943
|
-
const fullEditorText = newEditorState ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor : getFullEditorTextWithNewlines(editor);
|
|
1944
|
-
setLastKnownFullEditorText((prev) => {
|
|
1945
|
-
if (prev !== fullEditorText) {
|
|
1946
|
-
setCursorMovedSinceLastTextChange(false);
|
|
1947
|
-
}
|
|
1948
|
-
return fullEditorText;
|
|
1949
|
-
});
|
|
1950
|
-
onChangeHandlerForAutocomplete(newEditorState);
|
|
1951
|
-
(_a2 = props.onValueChange) == null ? void 0 : _a2.call(props, fullEditorText);
|
|
1952
|
-
(_b = props.onChange) == null ? void 0 : _b.call(props, makeSemiFakeReactTextAreaEvent(fullEditorText));
|
|
1953
|
-
},
|
|
1954
|
-
children: [
|
|
1955
|
-
/* @__PURE__ */ jsx13(
|
|
1956
|
-
TrackerTextEditedSinceLastCursorMovement,
|
|
1957
|
-
{
|
|
1958
|
-
setCursorMovedSinceLastTextChange
|
|
1959
|
-
}
|
|
1960
|
-
),
|
|
1961
|
-
/* @__PURE__ */ jsx13(
|
|
1962
|
-
HoveringToolbar,
|
|
1963
|
-
{
|
|
1964
|
-
apiConfig: autosuggestionsConfig.apiConfig,
|
|
1965
|
-
contextCategories: autosuggestionsConfig.contextCategories,
|
|
1966
|
-
hoverMenuClassname
|
|
1967
|
-
}
|
|
1968
|
-
),
|
|
1969
|
-
/* @__PURE__ */ jsx13(
|
|
1970
|
-
Editable,
|
|
1971
|
-
__spreadValues({
|
|
1972
|
-
renderElement: renderElementMemoized,
|
|
1973
|
-
renderPlaceholder: renderPlaceholderMemoized,
|
|
1974
|
-
onKeyDown: (event) => {
|
|
1975
|
-
var _a2;
|
|
1976
|
-
onKeyDownHandlerForHoveringEditor(event);
|
|
1977
|
-
onKeyDownHandlerForAutocomplete(event);
|
|
1978
|
-
(_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
|
|
1979
|
-
},
|
|
1980
|
-
onTouchStart: (event) => {
|
|
1981
|
-
onTouchStartHandlerForAutocomplete(event);
|
|
1982
|
-
},
|
|
1983
|
-
className: moddedClassName,
|
|
1984
|
-
onBlur: (ev) => {
|
|
1985
|
-
var _a2;
|
|
1986
|
-
(_a2 = props.onBlur) == null ? void 0 : _a2.call(props, ev);
|
|
1987
|
-
clearAutocompletionsFromEditor(editor);
|
|
1988
|
-
}
|
|
1989
|
-
}, propsToForward)
|
|
1990
|
-
)
|
|
1991
|
-
]
|
|
1992
|
-
}
|
|
1993
|
-
);
|
|
1994
|
-
}
|
|
1995
|
-
);
|
|
1996
|
-
function makeSemiFakeReactTextAreaEvent(currentText) {
|
|
1997
|
-
return {
|
|
1998
|
-
target: {
|
|
1999
|
-
value: currentText,
|
|
2000
|
-
type: "copilot-textarea"
|
|
2001
|
-
},
|
|
2002
|
-
currentTarget: {
|
|
2003
|
-
value: currentText,
|
|
2004
|
-
type: "copilot-textarea"
|
|
2005
|
-
}
|
|
2006
|
-
};
|
|
2007
|
-
}
|
|
2008
|
-
|
|
2009
|
-
// src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
|
|
2010
|
-
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER as COPILOT_CLOUD_PUBLIC_API_KEY_HEADER2 } from "@copilotkit/shared";
|
|
2011
|
-
import { useCopilotContext as useCopilotContext3 } from "@copilotkit/react-core";
|
|
2012
|
-
import { useCallback as useCallback5 } from "react";
|
|
2013
|
-
import {
|
|
2014
|
-
CopilotRuntimeClient as CopilotRuntimeClient2,
|
|
2015
|
-
Role as Role5,
|
|
2016
|
-
TextMessage as TextMessage5,
|
|
2017
|
-
convertGqlOutputToMessages as convertGqlOutputToMessages2,
|
|
2018
|
-
convertMessagesToGqlInput as convertMessagesToGqlInput2,
|
|
2019
|
-
filterAgentStateMessages as filterAgentStateMessages2,
|
|
2020
|
-
CopilotRequestType as CopilotRequestType2
|
|
2021
|
-
} from "@copilotkit/runtime-client-gql";
|
|
2022
|
-
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
2023
|
-
const { getContextString, copilotApiConfig } = useCopilotContext3();
|
|
2024
|
-
const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER2]: copilotApiConfig.publicApiKey } : {});
|
|
2025
|
-
const runtimeClient = new CopilotRuntimeClient2({
|
|
2026
|
-
url: copilotApiConfig.chatApiEndpoint,
|
|
2027
|
-
publicApiKey: copilotApiConfig.publicApiKey,
|
|
2028
|
-
headers,
|
|
2029
|
-
credentials: copilotApiConfig.credentials
|
|
2030
|
-
});
|
|
2031
|
-
function runtimeClientResponseToStringStream(responsePromise) {
|
|
2032
|
-
return __async(this, null, function* () {
|
|
2033
|
-
const messagesStream = yield CopilotRuntimeClient2.asStream(responsePromise);
|
|
2034
|
-
return new ReadableStream({
|
|
2035
|
-
start(controller) {
|
|
2036
|
-
return __async(this, null, function* () {
|
|
2037
|
-
const reader = messagesStream.getReader();
|
|
2038
|
-
let sentContent = "";
|
|
2039
|
-
while (true) {
|
|
2040
|
-
const { done, value } = yield reader.read();
|
|
2041
|
-
if (done) {
|
|
2042
|
-
break;
|
|
2043
|
-
}
|
|
2044
|
-
const messages = convertGqlOutputToMessages2(value.generateCopilotResponse.messages);
|
|
2045
|
-
let newContent = "";
|
|
2046
|
-
for (const message of messages) {
|
|
2047
|
-
if (message instanceof TextMessage5) {
|
|
2048
|
-
newContent += message.content;
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
if (newContent) {
|
|
2052
|
-
const contentToSend = newContent.slice(sentContent.length);
|
|
2053
|
-
controller.enqueue(contentToSend);
|
|
2054
|
-
sentContent += contentToSend;
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
controller.close();
|
|
2058
|
-
});
|
|
2059
|
-
}
|
|
2060
|
-
});
|
|
2061
|
-
});
|
|
2062
|
-
}
|
|
2063
|
-
const insertionFunction = useCallback5(
|
|
2064
|
-
(editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
2065
|
-
const res = yield retry(() => __async(this, null, function* () {
|
|
2066
|
-
const messages = [
|
|
2067
|
-
new TextMessage5({
|
|
2068
|
-
role: Role5.System,
|
|
2069
|
-
content: insertionApiConfig.makeSystemPrompt(
|
|
2070
|
-
textareaPurpose,
|
|
2071
|
-
getContextString(documents, contextCategories)
|
|
2072
|
-
)
|
|
2073
|
-
}),
|
|
2074
|
-
...insertionApiConfig.fewShotMessages,
|
|
2075
|
-
new TextMessage5({
|
|
2076
|
-
role: Role5.User,
|
|
2077
|
-
content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
|
|
2078
|
-
}),
|
|
2079
|
-
new TextMessage5({
|
|
2080
|
-
role: Role5.User,
|
|
2081
|
-
content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
|
|
2082
|
-
}),
|
|
2083
|
-
new TextMessage5({
|
|
2084
|
-
role: Role5.User,
|
|
2085
|
-
content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
|
|
2086
|
-
})
|
|
2087
|
-
];
|
|
2088
|
-
return runtimeClientResponseToStringStream(
|
|
2089
|
-
runtimeClient.generateCopilotResponse({
|
|
2090
|
-
data: {
|
|
2091
|
-
frontend: {
|
|
2092
|
-
actions: [],
|
|
2093
|
-
url: window.location.href
|
|
2094
|
-
},
|
|
2095
|
-
messages: convertMessagesToGqlInput2(filterAgentStateMessages2(messages)),
|
|
2096
|
-
metadata: {
|
|
2097
|
-
requestType: CopilotRequestType2.TextareaCompletion
|
|
2098
|
-
}
|
|
2099
|
-
},
|
|
2100
|
-
properties: copilotApiConfig.properties,
|
|
2101
|
-
signal: abortSignal
|
|
2102
|
-
})
|
|
2103
|
-
);
|
|
2104
|
-
}));
|
|
2105
|
-
return res;
|
|
2106
|
-
}),
|
|
2107
|
-
[insertionApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
2108
|
-
);
|
|
2109
|
-
const editingFunction = useCallback5(
|
|
2110
|
-
(editorState2, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
2111
|
-
const res = yield retry(() => __async(this, null, function* () {
|
|
2112
|
-
const messages = [
|
|
2113
|
-
new TextMessage5({
|
|
2114
|
-
role: Role5.System,
|
|
2115
|
-
content: editingApiConfig.makeSystemPrompt(
|
|
2116
|
-
textareaPurpose,
|
|
2117
|
-
getContextString(documents, contextCategories)
|
|
2118
|
-
)
|
|
2119
|
-
}),
|
|
2120
|
-
...editingApiConfig.fewShotMessages,
|
|
2121
|
-
new TextMessage5({
|
|
2122
|
-
role: Role5.User,
|
|
2123
|
-
content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
|
|
2124
|
-
}),
|
|
2125
|
-
new TextMessage5({
|
|
2126
|
-
role: Role5.User,
|
|
2127
|
-
content: `<TextToEdit>${editorState2.selectedText}</TextToEdit>`
|
|
2128
|
-
}),
|
|
2129
|
-
new TextMessage5({
|
|
2130
|
-
role: Role5.User,
|
|
2131
|
-
content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
|
|
2132
|
-
}),
|
|
2133
|
-
new TextMessage5({
|
|
2134
|
-
role: Role5.User,
|
|
2135
|
-
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
|
|
2136
|
-
})
|
|
2137
|
-
];
|
|
2138
|
-
const runtimeClient2 = new CopilotRuntimeClient2({
|
|
2139
|
-
url: copilotApiConfig.chatApiEndpoint,
|
|
2140
|
-
publicApiKey: copilotApiConfig.publicApiKey,
|
|
2141
|
-
headers,
|
|
2142
|
-
credentials: copilotApiConfig.credentials
|
|
2143
|
-
});
|
|
2144
|
-
return runtimeClientResponseToStringStream(
|
|
2145
|
-
runtimeClient2.generateCopilotResponse({
|
|
2146
|
-
data: {
|
|
2147
|
-
frontend: {
|
|
2148
|
-
actions: [],
|
|
2149
|
-
url: window.location.href
|
|
2150
|
-
},
|
|
2151
|
-
messages: convertMessagesToGqlInput2(filterAgentStateMessages2(messages)),
|
|
2152
|
-
metadata: {
|
|
2153
|
-
requestType: CopilotRequestType2.TextareaCompletion
|
|
2154
|
-
}
|
|
2155
|
-
},
|
|
2156
|
-
properties: copilotApiConfig.properties,
|
|
2157
|
-
signal: abortSignal
|
|
2158
|
-
})
|
|
2159
|
-
);
|
|
2160
|
-
}));
|
|
2161
|
-
return res;
|
|
2162
|
-
}),
|
|
2163
|
-
[editingApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
2164
|
-
);
|
|
2165
|
-
const insertionOrEditingFunction = useCallback5(
|
|
2166
|
-
(editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
2167
|
-
if (editorState2.selectedText === "") {
|
|
2168
|
-
return yield insertionFunction(editorState2, insertionPrompt, documents, abortSignal);
|
|
2169
|
-
} else {
|
|
2170
|
-
return yield editingFunction(editorState2, insertionPrompt, documents, abortSignal);
|
|
2171
|
-
}
|
|
2172
|
-
}),
|
|
2173
|
-
[insertionFunction, editingFunction]
|
|
2174
|
-
);
|
|
2175
|
-
return insertionOrEditingFunction;
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
// src/components/copilot-textarea/copilot-textarea.tsx
|
|
2179
|
-
import merge from "lodash.merge";
|
|
2180
|
-
import { Fragment as Fragment3, jsx as jsx14 } from "react/jsx-runtime";
|
|
2181
|
-
var CopilotTextarea = React7.forwardRef(
|
|
2182
|
-
(props, ref) => {
|
|
2183
|
-
const _a = props, { autosuggestionsConfig: autosuggestionsConfigUserSpecified } = _a, forwardedProps = __objRest(_a, ["autosuggestionsConfig"]);
|
|
2184
|
-
const autosuggestionsConfig = merge(
|
|
2185
|
-
defaultAutosuggestionsConfig,
|
|
2186
|
-
autosuggestionsConfigUserSpecified
|
|
2187
|
-
);
|
|
2188
|
-
const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(
|
|
2189
|
-
autosuggestionsConfig.textareaPurpose,
|
|
2190
|
-
autosuggestionsConfig.contextCategories,
|
|
2191
|
-
autosuggestionsConfig.chatApiConfigs.suggestionsApiConfig
|
|
2192
|
-
);
|
|
2193
|
-
const insertionOrEditingFunction = useMakeStandardInsertionOrEditingFunction(
|
|
2194
|
-
autosuggestionsConfig.textareaPurpose,
|
|
2195
|
-
autosuggestionsConfig.contextCategories,
|
|
2196
|
-
autosuggestionsConfig.chatApiConfigs.insertionApiConfig,
|
|
2197
|
-
autosuggestionsConfig.chatApiConfigs.editingApiConfig
|
|
2198
|
-
);
|
|
2199
|
-
return /* @__PURE__ */ jsx14(Fragment3, { children: /* @__PURE__ */ jsx14(
|
|
2200
|
-
BaseCopilotTextarea,
|
|
2201
|
-
__spreadProps(__spreadValues({
|
|
2202
|
-
ref
|
|
2203
|
-
}, forwardedProps), {
|
|
2204
|
-
baseAutosuggestionsConfig: __spreadProps(__spreadValues({}, autosuggestionsConfig), {
|
|
2205
|
-
apiConfig: {
|
|
2206
|
-
insertionOrEditingFunction,
|
|
2207
|
-
autosuggestionsFunction
|
|
2208
|
-
}
|
|
2209
|
-
})
|
|
2210
|
-
})
|
|
2211
|
-
) });
|
|
2212
|
-
}
|
|
2213
|
-
);
|
|
2
|
+
CopilotTextarea
|
|
3
|
+
} from "../../chunk-FYCQE57K.mjs";
|
|
4
|
+
import "../../chunk-2XDYLKPH.mjs";
|
|
5
|
+
import "../../chunk-D2SUDM2O.mjs";
|
|
6
|
+
import "../../chunk-RUV6NBIF.mjs";
|
|
7
|
+
import "../../chunk-HL7EF7KA.mjs";
|
|
8
|
+
import "../../chunk-EJGGLWWR.mjs";
|
|
9
|
+
import "../../chunk-MCNXIA4Q.mjs";
|
|
10
|
+
import "../../chunk-SDHH6DI6.mjs";
|
|
11
|
+
import "../../chunk-J62KUPFZ.mjs";
|
|
12
|
+
import "../../chunk-2C7O2EVM.mjs";
|
|
13
|
+
import "../../chunk-GQN2HYFJ.mjs";
|
|
14
|
+
import "../../chunk-23Q6A46J.mjs";
|
|
15
|
+
import "../../chunk-AJ5OMEXM.mjs";
|
|
16
|
+
import "../../chunk-DRV2FOHZ.mjs";
|
|
17
|
+
import "../../chunk-4NHVQZ67.mjs";
|
|
18
|
+
import "../../chunk-QJNFNPWH.mjs";
|
|
19
|
+
import "../../chunk-5UNJXFUO.mjs";
|
|
20
|
+
import "../../chunk-LQ2OWQU7.mjs";
|
|
21
|
+
import "../../chunk-7LSRNPNI.mjs";
|
|
22
|
+
import "../../chunk-4AMCUMC7.mjs";
|
|
23
|
+
import "../../chunk-L7VVZH4Q.mjs";
|
|
24
|
+
import "../../chunk-I3SPIGAI.mjs";
|
|
25
|
+
import "../../chunk-UGEKMSRR.mjs";
|
|
26
|
+
import "../../chunk-KMVGEY7Q.mjs";
|
|
27
|
+
import "../../chunk-3PQ7GSFE.mjs";
|
|
28
|
+
import "../../chunk-4PDYALMP.mjs";
|
|
29
|
+
import "../../chunk-D47EKHIF.mjs";
|
|
30
|
+
import "../../chunk-LYB4B6MK.mjs";
|
|
31
|
+
import "../../chunk-CF5GISTC.mjs";
|
|
32
|
+
import "../../chunk-WGWQRALG.mjs";
|
|
33
|
+
import "../../chunk-VSVQZUPW.mjs";
|
|
34
|
+
import "../../chunk-I72DKFHD.mjs";
|
|
35
|
+
import "../../chunk-2QDCE7PD.mjs";
|
|
36
|
+
import "../../chunk-YLFAIYRY.mjs";
|
|
37
|
+
import "../../chunk-WJHSY5T6.mjs";
|
|
38
|
+
import "../../chunk-4CVSOOJY.mjs";
|
|
39
|
+
import "../../chunk-224UKA7C.mjs";
|
|
40
|
+
import "../../chunk-XW3ICO4S.mjs";
|
|
41
|
+
import "../../chunk-DFTV4TST.mjs";
|
|
42
|
+
import "../../chunk-T6MTDQZ7.mjs";
|
|
43
|
+
import "../../chunk-ECR45NSD.mjs";
|
|
44
|
+
import "../../chunk-KNQIEOFP.mjs";
|
|
45
|
+
import "../../chunk-MRXNTQOX.mjs";
|
|
2214
46
|
export {
|
|
2215
47
|
CopilotTextarea
|
|
2216
48
|
};
|