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