@copilotkit/react-textarea 0.19.0-alpha.3 → 0.19.0-alpha.4

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.
Files changed (222) hide show
  1. package/.turbo/turbo-build.log +147 -143
  2. package/CHANGELOG.md +6 -0
  3. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +1870 -33
  4. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  5. package/dist/components/base-copilot-textarea/render-element.mjs +52 -3
  6. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  7. package/dist/components/base-copilot-textarea/render-placeholder.mjs +46 -3
  8. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
  9. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +86 -4
  10. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
  11. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +57 -3
  12. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  13. package/dist/components/copilot-textarea/copilot-textarea.mjs +2339 -43
  14. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  15. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +22 -3
  16. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  17. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +125 -3
  18. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  19. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +1015 -16
  20. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
  21. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +721 -10
  22. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
  23. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +734 -11
  24. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
  25. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +734 -12
  26. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  27. package/dist/components/index.mjs +2340 -44
  28. package/dist/components/index.mjs.map +1 -1
  29. package/dist/components/manual-ui/chip-with-icon.mjs +5 -6
  30. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  31. package/dist/components/source-search-box/source-search-box.mjs +323 -10
  32. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  33. package/dist/components/ui/button.mjs +88 -4
  34. package/dist/components/ui/button.mjs.map +1 -1
  35. package/dist/components/ui/card.mjs +53 -7
  36. package/dist/components/ui/card.mjs.map +1 -1
  37. package/dist/components/ui/command.mjs +266 -5
  38. package/dist/components/ui/command.mjs.map +1 -1
  39. package/dist/components/ui/dialog.mjs +164 -4
  40. package/dist/components/ui/dialog.mjs.map +1 -1
  41. package/dist/components/ui/label.mjs +63 -4
  42. package/dist/components/ui/label.mjs.map +1 -1
  43. package/dist/components/ui/separator.mjs +50 -8
  44. package/dist/components/ui/separator.mjs.map +1 -1
  45. package/dist/components/ui/textarea.mjs +48 -7
  46. package/dist/components/ui/textarea.mjs.map +1 -1
  47. package/dist/context/index.mjs +0 -2
  48. package/dist/context/index.mjs.map +1 -1
  49. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +168 -6
  50. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  51. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +168 -4
  52. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  53. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +155 -5
  54. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  55. package/dist/hooks/index.mjs +0 -2
  56. package/dist/hooks/index.mjs.map +1 -1
  57. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +90 -4
  58. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
  59. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +143 -4
  60. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
  61. package/dist/hooks/misc/use-autosize-textarea.mjs +15 -3
  62. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  63. package/dist/index.css +3 -12
  64. package/dist/index.css.map +1 -1
  65. package/dist/index.mjs +2343 -48
  66. package/dist/index.mjs.map +1 -1
  67. package/dist/lib/debouncer.mjs +51 -3
  68. package/dist/lib/debouncer.mjs.map +1 -1
  69. package/dist/lib/editor-to-text.mjs +43 -3
  70. package/dist/lib/editor-to-text.mjs.map +1 -1
  71. package/dist/lib/get-text-around-cursor.mjs +109 -3
  72. package/dist/lib/get-text-around-cursor.mjs.map +1 -1
  73. package/dist/lib/retry.mjs +17 -3
  74. package/dist/lib/retry.mjs.map +1 -1
  75. package/dist/lib/slatejs-edits/add-autocompletions.mjs +25 -3
  76. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
  77. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +23 -3
  78. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
  79. package/dist/lib/slatejs-edits/replace-text.mjs +27 -3
  80. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
  81. package/dist/lib/slatejs-edits/with-partial-history.mjs +106 -3
  82. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
  83. package/dist/lib/stream-promise-flatten.mjs +47 -3
  84. package/dist/lib/stream-promise-flatten.mjs.map +1 -1
  85. package/dist/lib/utils.mjs +71 -3
  86. package/dist/lib/utils.mjs.map +1 -1
  87. package/dist/lib/utils.test.mjs +0 -1
  88. package/dist/lib/utils.test.mjs.map +1 -1
  89. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +0 -2
  90. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
  91. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +312 -9
  92. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  93. package/dist/types/autosuggestions-config/editing-api-config.mjs +155 -4
  94. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  95. package/dist/types/autosuggestions-config/index.mjs +313 -10
  96. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  97. package/dist/types/autosuggestions-config/insertions-api-config.mjs +149 -4
  98. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
  99. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +71 -3
  100. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
  101. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +0 -2
  102. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
  103. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +0 -2
  104. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
  105. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +137 -4
  106. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
  107. package/dist/types/base/autosuggestion-state.mjs +0 -2
  108. package/dist/types/base/autosuggestion-state.mjs.map +1 -1
  109. package/dist/types/base/autosuggestions-bare-function.mjs +0 -2
  110. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
  111. package/dist/types/base/base-autosuggestions-config.mjs +11 -3
  112. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
  113. package/dist/types/base/base-copilot-textarea-props.mjs +0 -2
  114. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
  115. package/dist/types/base/custom-editor.mjs +0 -2
  116. package/dist/types/base/custom-editor.mjs.map +1 -1
  117. package/dist/types/base/editor-autocomplete-state.mjs +17 -4
  118. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
  119. package/dist/types/base/index.mjs +11 -4
  120. package/dist/types/base/index.mjs.map +1 -1
  121. package/dist/types/html-copilot-textarea-element.mjs +0 -2
  122. package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
  123. package/dist/types/index.mjs +314 -12
  124. package/dist/types/index.mjs.map +1 -1
  125. package/package.json +3 -3
  126. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +2 -1
  127. package/src/components/source-search-box/source-search-box.tsx +6 -9
  128. package/src/components/ui/command.tsx +1 -1
  129. package/dist/chunk-23UHDUUY.mjs +0 -461
  130. package/dist/chunk-23UHDUUY.mjs.map +0 -1
  131. package/dist/chunk-2NURR2DX.mjs +0 -47
  132. package/dist/chunk-2NURR2DX.mjs.map +0 -1
  133. package/dist/chunk-3YJ63D5D.mjs +0 -106
  134. package/dist/chunk-3YJ63D5D.mjs.map +0 -1
  135. package/dist/chunk-4MDDCR32.mjs +0 -107
  136. package/dist/chunk-4MDDCR32.mjs.map +0 -1
  137. package/dist/chunk-4S5ZJH3I.mjs +0 -18
  138. package/dist/chunk-4S5ZJH3I.mjs.map +0 -1
  139. package/dist/chunk-55EGOC5T.mjs +0 -87
  140. package/dist/chunk-55EGOC5T.mjs.map +0 -1
  141. package/dist/chunk-5ARCOTW3.mjs +0 -34
  142. package/dist/chunk-5ARCOTW3.mjs.map +0 -1
  143. package/dist/chunk-5EJ5XOGP.mjs +0 -22
  144. package/dist/chunk-5EJ5XOGP.mjs.map +0 -1
  145. package/dist/chunk-5FO6ISW4.mjs +0 -3
  146. package/dist/chunk-5FO6ISW4.mjs.map +0 -1
  147. package/dist/chunk-A2RRLD23.mjs +0 -69
  148. package/dist/chunk-A2RRLD23.mjs.map +0 -1
  149. package/dist/chunk-CSGFJU3L.mjs +0 -65
  150. package/dist/chunk-CSGFJU3L.mjs.map +0 -1
  151. package/dist/chunk-CZMPLTHF.mjs +0 -20
  152. package/dist/chunk-CZMPLTHF.mjs.map +0 -1
  153. package/dist/chunk-D7SEV5PR.mjs +0 -12
  154. package/dist/chunk-D7SEV5PR.mjs.map +0 -1
  155. package/dist/chunk-DE5K76I2.mjs +0 -3
  156. package/dist/chunk-DE5K76I2.mjs.map +0 -1
  157. package/dist/chunk-F3MHL6ZY.mjs +0 -25
  158. package/dist/chunk-F3MHL6ZY.mjs.map +0 -1
  159. package/dist/chunk-FN7GDKKG.mjs +0 -29
  160. package/dist/chunk-FN7GDKKG.mjs.map +0 -1
  161. package/dist/chunk-H4VKQGVU.mjs +0 -3
  162. package/dist/chunk-H4VKQGVU.mjs.map +0 -1
  163. package/dist/chunk-HAFHLU4N.mjs +0 -55
  164. package/dist/chunk-HAFHLU4N.mjs.map +0 -1
  165. package/dist/chunk-IU3WTXLQ.mjs +0 -3
  166. package/dist/chunk-IU3WTXLQ.mjs.map +0 -1
  167. package/dist/chunk-IXJ2HCOA.mjs +0 -101
  168. package/dist/chunk-IXJ2HCOA.mjs.map +0 -1
  169. package/dist/chunk-JAFCXEPU.mjs +0 -10
  170. package/dist/chunk-JAFCXEPU.mjs.map +0 -1
  171. package/dist/chunk-KCHYD3EB.mjs +0 -107
  172. package/dist/chunk-KCHYD3EB.mjs.map +0 -1
  173. package/dist/chunk-KGKLUWKW.mjs +0 -47
  174. package/dist/chunk-KGKLUWKW.mjs.map +0 -1
  175. package/dist/chunk-L7VVZH4Q.mjs +0 -3
  176. package/dist/chunk-L7VVZH4Q.mjs.map +0 -1
  177. package/dist/chunk-LNAIMEB2.mjs +0 -34
  178. package/dist/chunk-LNAIMEB2.mjs.map +0 -1
  179. package/dist/chunk-MMVDU6DF.mjs +0 -3
  180. package/dist/chunk-MMVDU6DF.mjs.map +0 -1
  181. package/dist/chunk-MPME5BW2.mjs +0 -59
  182. package/dist/chunk-MPME5BW2.mjs.map +0 -1
  183. package/dist/chunk-MRXNTQOX.mjs +0 -55
  184. package/dist/chunk-MRXNTQOX.mjs.map +0 -1
  185. package/dist/chunk-ND5PXTAW.mjs +0 -17
  186. package/dist/chunk-ND5PXTAW.mjs.map +0 -1
  187. package/dist/chunk-NKW5OU2S.mjs +0 -33
  188. package/dist/chunk-NKW5OU2S.mjs.map +0 -1
  189. package/dist/chunk-O5OWT5GE.mjs +0 -114
  190. package/dist/chunk-O5OWT5GE.mjs.map +0 -1
  191. package/dist/chunk-OD7ZMOVE.mjs +0 -45
  192. package/dist/chunk-OD7ZMOVE.mjs.map +0 -1
  193. package/dist/chunk-OELUUJZY.mjs +0 -16
  194. package/dist/chunk-OELUUJZY.mjs.map +0 -1
  195. package/dist/chunk-OS2YW2UX.mjs +0 -201
  196. package/dist/chunk-OS2YW2UX.mjs.map +0 -1
  197. package/dist/chunk-QL2GYGG5.mjs +0 -19
  198. package/dist/chunk-QL2GYGG5.mjs.map +0 -1
  199. package/dist/chunk-RQHOUUXQ.mjs +0 -29
  200. package/dist/chunk-RQHOUUXQ.mjs.map +0 -1
  201. package/dist/chunk-U5GM2PRT.mjs +0 -44
  202. package/dist/chunk-U5GM2PRT.mjs.map +0 -1
  203. package/dist/chunk-UHD44NC5.mjs +0 -101
  204. package/dist/chunk-UHD44NC5.mjs.map +0 -1
  205. package/dist/chunk-VBIJPE3H.mjs +0 -108
  206. package/dist/chunk-VBIJPE3H.mjs.map +0 -1
  207. package/dist/chunk-WADHCMPK.mjs +0 -3
  208. package/dist/chunk-WADHCMPK.mjs.map +0 -1
  209. package/dist/chunk-WJHSY5T6.mjs +0 -3
  210. package/dist/chunk-WJHSY5T6.mjs.map +0 -1
  211. package/dist/chunk-WJYQWL4I.mjs +0 -27
  212. package/dist/chunk-WJYQWL4I.mjs.map +0 -1
  213. package/dist/chunk-XDT7BF3V.mjs +0 -81
  214. package/dist/chunk-XDT7BF3V.mjs.map +0 -1
  215. package/dist/chunk-XHUMROEY.mjs +0 -91
  216. package/dist/chunk-XHUMROEY.mjs.map +0 -1
  217. package/dist/chunk-YQU7WG7T.mjs +0 -83
  218. package/dist/chunk-YQU7WG7T.mjs.map +0 -1
  219. package/dist/chunk-YTOPHPSG.mjs +0 -45
  220. package/dist/chunk-YTOPHPSG.mjs.map +0 -1
  221. package/dist/chunk-YW3REYX6.mjs +0 -23
  222. package/dist/chunk-YW3REYX6.mjs.map +0 -1
@@ -1,69 +0,0 @@
1
- import { ChatlikeApiEndpoint } from './chunk-5ARCOTW3.mjs';
2
-
3
- // src/types/autosuggestions-config/suggestions-api-config.tsx
4
- var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
5
- return `You are a versatile writing assistant.
6
-
7
- The user is writing some text.
8
- The purpose is: "${textareaPurpose}"
9
-
10
- Your job is to guess what the user will write next AS BEST YOU CAN.
11
- Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
12
-
13
- Adjust yourself to the user's style and implied intent.
14
-
15
- 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.
16
- <TextAfterCursor>
17
- <TextBeforeCursor>
18
- <YourSuggestion>
19
-
20
- If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
21
-
22
- The following external context is also provided. Use it to help you make better suggestions!!!
23
- \`\`\`
24
- ${contextString}
25
- \`\`\`
26
- `;
27
- };
28
- var defaultSuggestionsFewShotMessages = [
29
- {
30
- role: "user",
31
- name: "TextAfterCursor",
32
- content: "While I was there I also picked up some apples, oranges, and bananas."
33
- },
34
- {
35
- role: "user",
36
- name: "TextBeforeCursor",
37
- content: "This morning I woke up and went straight to the grocery store."
38
- },
39
- {
40
- role: "assistant",
41
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
42
- },
43
- {
44
- role: "user",
45
- name: "TextAfterCursor",
46
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
47
- },
48
- {
49
- role: "user",
50
- name: "TextBeforeCursor",
51
- 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;`
52
- },
53
- {
54
- role: "assistant",
55
- 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"; `
56
- }
57
- ];
58
- var defaultSuggestionsApiConfig = {
59
- apiEndpoint: ChatlikeApiEndpoint.standardOpenAIEndpoint(
60
- "/api/copilotkit_chatlike"
61
- ),
62
- makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
63
- fewShotMessages: defaultSuggestionsFewShotMessages,
64
- forwardedParams: void 0
65
- };
66
-
67
- export { defaultSuggestionsApiConfig, defaultSuggestionsFewShotMessages, defaultSuggestionsMakeSystemPrompt };
68
- //# sourceMappingURL=out.js.map
69
- //# sourceMappingURL=chunk-A2RRLD23.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types/autosuggestions-config/suggestions-api-config.tsx"],"names":[],"mappings":";;;;;AAWO,IAAM,qCAAuD,CAClE,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBlB;AAAA;AAAA;AAGF;AAEO,IAAM,oCAA6D;AAAA,EACxE;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AAEO,IAAM,8BAAoD;AAAA,EAC/D,aAAa,oBAAoB;AAAA,IAC/B;AAAA,EACF;AAAA,EACA,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB","sourcesContent":["import { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { ChatlikeApiEndpoint } from \"./subtypes/chatlike-api-endpoint\";\n\nexport interface SuggestionsApiConfig {\n apiEndpoint: ChatlikeApiEndpoint;\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultSuggestionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe 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.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultSuggestionsFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n '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;',\n },\n {\n role: \"assistant\",\n content:\n ' (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\"; ',\n },\n];\n\nexport const defaultSuggestionsApiConfig: SuggestionsApiConfig = {\n apiEndpoint: ChatlikeApiEndpoint.standardOpenAIEndpoint(\n \"/api/copilotkit_chatlike\"\n ),\n makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,\n fewShotMessages: defaultSuggestionsFewShotMessages,\n forwardedParams: undefined,\n};\n"]}
@@ -1,65 +0,0 @@
1
- import { withPartialHistory, defaultShouldSave } from './chunk-KCHYD3EB.mjs';
2
- import { useMemo } from 'react';
3
- import { createEditor, Element } from 'slate';
4
- import { withReact } from 'slate-react';
5
-
6
- var shouldSave = (op, prev) => {
7
- const excludedNodeType = "suggestion";
8
- if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
9
- return false;
10
- }
11
- if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
12
- return false;
13
- }
14
- if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
15
- return false;
16
- }
17
- if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
18
- return false;
19
- }
20
- if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
21
- return false;
22
- }
23
- if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
24
- return false;
25
- }
26
- return defaultShouldSave(op, prev);
27
- };
28
- function useCopilotTextareaEditor() {
29
- const editor = useMemo(() => {
30
- const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
31
- const { isVoid } = editor2;
32
- editor2.isVoid = (element) => {
33
- switch (element.type) {
34
- case "suggestion":
35
- return true;
36
- default:
37
- return isVoid(element);
38
- }
39
- };
40
- const { markableVoid } = editor2;
41
- editor2.markableVoid = (element) => {
42
- switch (element.type) {
43
- case "suggestion":
44
- return true;
45
- default:
46
- return markableVoid(element);
47
- }
48
- };
49
- const { isInline } = editor2;
50
- editor2.isInline = (element) => {
51
- switch (element.type) {
52
- case "suggestion":
53
- return element.inline;
54
- default:
55
- return isInline(element);
56
- }
57
- };
58
- return editor2;
59
- }, []);
60
- return editor;
61
- }
62
-
63
- export { useCopilotTextareaEditor };
64
- //# sourceMappingURL=out.js.map
65
- //# sourceMappingURL=chunk-CSGFJU3L.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx"],"names":["editor"],"mappings":";;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,cAAc,eAAe;AACtC,SAAS,iBAAiB;AAQ1B,IAAM,aAAkC,CAAC,IAAI,SAAS;AACpD,QAAM,mBAAmB;AAEzB,MACE,GAAG,SAAS,iBACZ,QAAQ,UAAU,GAAG,IAAI,KACzB,GAAG,KAAK,SAAS,kBACjB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,iBACZ,QAAQ,UAAU,GAAG,IAAI,KACzB,GAAG,KAAK,SAAS,kBACjB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,cACZ,UAAU,GAAG,iBACb,GAAG,cAAc,SAAS,kBAC1B;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,QAAQ,cACX,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,gBACZ,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,gBACZ,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAGA,SAAO,kBAAkB,IAAI,IAAI;AACnC;AAEO,SAAS,2BAAyC;AACvD,QAAM,SAAS,QAAQ,MAAM;AAC3B,UAAMA,UAAS,mBAAmB,UAAU,aAAa,CAAC,GAAG,UAAU;AAEvE,UAAM,EAAE,OAAO,IAAIA;AACnB,IAAAA,QAAO,SAAS,CAAC,YAAY;AAC3B,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO;AAAA,QACT;AACE,iBAAO,OAAO,OAAO;AAAA,MACzB;AAAA,IACF;AAEA,UAAM,EAAE,aAAa,IAAIA;AACzB,IAAAA,QAAO,eAAe,CAAC,YAAY;AACjC,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO;AAAA,QACT;AACE,iBAAO,aAAa,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,EAAE,SAAS,IAAIA;AACrB,IAAAA,QAAO,WAAW,CAAC,YAAY;AAC7B,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO,QAAQ;AAAA,QACjB;AACE,iBAAO,SAAS,OAAO;AAAA,MAC3B;AAAA,IACF;AAEA,WAAOA;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT","sourcesContent":["import { useMemo } from \"react\";\nimport { createEditor, Element } from \"slate\";\nimport { withReact } from \"slate-react\";\nimport {\n defaultShouldSave,\n ShouldSaveToHistory,\n withPartialHistory,\n} from \"../../lib/slatejs-edits/with-partial-history\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nconst shouldSave: ShouldSaveToHistory = (op, prev) => {\n const excludedNodeType = \"suggestion\";\n // Check if the operation involves the suggestion inline node type\n if (\n op.type === \"insert_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"remove_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"set_node\" &&\n \"type\" in op.newProperties &&\n op.newProperties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type == \"set_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"merge_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"split_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n // Otherwise, save the operation to history\n return defaultShouldSave(op, prev);\n};\n\nexport function useCopilotTextareaEditor(): CustomEditor {\n const editor = useMemo(() => {\n const editor = withPartialHistory(withReact(createEditor()), shouldSave);\n\n const { isVoid } = editor;\n editor.isVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return isVoid(element);\n }\n };\n\n const { markableVoid } = editor;\n editor.markableVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return markableVoid(element);\n }\n };\n\n const { isInline } = editor;\n editor.isInline = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return element.inline;\n default:\n return isInline(element);\n }\n };\n\n return editor;\n }, []);\n\n return editor;\n}\n"]}
@@ -1,20 +0,0 @@
1
- import { HoveringInsertionPromptBoxCore } from './chunk-23UHDUUY.mjs';
2
- import { jsx } from 'react/jsx-runtime';
3
-
4
- var HoveringInsertionPromptBox = (props) => {
5
- return /* @__PURE__ */ jsx("div", {
6
- className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
7
- style: { width: "35rem" },
8
- children: /* @__PURE__ */ jsx(HoveringInsertionPromptBoxCore, {
9
- state: {
10
- editorState: props.editorState
11
- },
12
- performInsertion: props.performInsertion,
13
- insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction
14
- })
15
- });
16
- };
17
-
18
- export { HoveringInsertionPromptBox };
19
- //# sourceMappingURL=out.js.map
20
- //# sourceMappingURL=chunk-CZMPLTHF.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx"],"names":[],"mappings":";;;;;AAoBM;AANC,IAAM,6BAA8C,CAAC,UAAU;AACpE,SACE,oBAAC;AAAA,IACC,WAAU;AAAA,IACV,OAAO,EAAE,OAAO,QAAQ;AAAA,IAExB,8BAAC;AAAA,MACC,OAAO;AAAA,QACL,aAAa,MAAM;AAAA,MACrB;AAAA,MACA,kBAAkB,MAAM;AAAA,MACxB,4BAA4B,MAAM,UAAU;AAAA,KAC9C;AAAA,GACF;AAEJ","sourcesContent":["import React, { useCallback, useState } from \"react\";\nimport { HoveringInsertionPromptBoxCore } from \"./hovering-insertion-prompt-box-core\";\nimport {\n EditingEditorState,\n InsertionEditorApiConfig,\n} from \"../../../types/base/autosuggestions-bare-function\";\n\nexport interface Props {\n editorState: EditingEditorState;\n apiConfig: InsertionEditorApiConfig;\n performInsertion: (insertedText: string) => void;\n closeWindow: () => void;\n}\n\nexport const HoveringInsertionPromptBox: React.FC<Props> = (props) => {\n return (\n <div\n className=\"flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white\"\n style={{ width: \"35rem\" }}\n >\n <HoveringInsertionPromptBoxCore\n state={{\n editorState: props.editorState,\n }}\n performInsertion={props.performInsertion}\n insertionOrEditingFunction={props.apiConfig.insertionOrEditingFunction}\n />\n </div>\n );\n};\n"]}
@@ -1,12 +0,0 @@
1
- // src/types/base/base-autosuggestions-config.tsx
2
- var defaultBaseAutosuggestionsConfig = {
3
- debounceTime: 250,
4
- acceptAutosuggestionKey: "Tab",
5
- disableWhenEmpty: true,
6
- disabled: false,
7
- temporarilyDisableWhenMovingCursorWithoutChangingText: true
8
- };
9
-
10
- export { defaultBaseAutosuggestionsConfig };
11
- //# sourceMappingURL=out.js.map
12
- //# sourceMappingURL=chunk-D7SEV5PR.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types/base/base-autosuggestions-config.tsx"],"names":[],"mappings":";AAYO,IAAM,mCAGT;AAAA,EACF,cAAc;AAAA,EACd,yBAAyB;AAAA,EACzB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,uDAAuD;AACzD","sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\n\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n debounceTime: number;\n acceptAutosuggestionKey: string;\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n apiConfig: BaseCopilotTextareaApiConfig;\n}\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n acceptAutosuggestionKey: \"Tab\",\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n};\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-DE5K76I2.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- import { Node, Element, Transforms } from 'slate';
2
-
3
- // src/lib/slatejs-edits/clear-autocompletions.ts
4
- function clearAutocompletionsFromEditor(editor) {
5
- const paths = [];
6
- for (const [node, path] of Node.nodes(editor)) {
7
- if (Element.isElement(node) && node.type === "suggestion") {
8
- paths.push(path);
9
- }
10
- }
11
- for (const path of paths) {
12
- try {
13
- Transforms.removeNodes(editor, { at: path });
14
- } catch (e) {
15
- console.log(
16
- "CopilotTextarea.clearAutocompletionsFromEditor: error removing node",
17
- e
18
- );
19
- }
20
- }
21
- }
22
-
23
- export { clearAutocompletionsFromEditor };
24
- //# sourceMappingURL=out.js.map
25
- //# sourceMappingURL=chunk-F3MHL6ZY.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/slatejs-edits/clear-autocompletions.ts"],"names":[],"mappings":";AAAA,SAAS,SAAS,MAAY,kBAAkB;AAGzC,SAAS,+BAA+B,QAAsB;AAEnE,QAAM,QAAgB,CAAC;AACvB,aAAW,CAAC,MAAM,IAAI,KAAK,KAAK,MAAM,MAAM,GAAG;AAC7C,QAAI,QAAQ,UAAU,IAAI,KAAK,KAAK,SAAS,cAAc;AACzD,YAAM,KAAK,IAAI;AAAA,IACjB;AAAA,EACF;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,iBAAW,YAAY,QAAQ,EAAE,IAAI,KAAK,CAAC;AAAA,IAC7C,SAAS,GAAP;AACA,cAAQ;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import { Element, Node, Path, Transforms } from \"slate\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function clearAutocompletionsFromEditor(editor: CustomEditor) {\n // clear previous suggestion\n const paths: Path[] = [];\n for (const [node, path] of Node.nodes(editor)) {\n if (Element.isElement(node) && node.type === \"suggestion\") {\n paths.push(path);\n }\n }\n for (const path of paths) {\n try {\n Transforms.removeNodes(editor, { at: path });\n } catch (e) {\n console.log(\n \"CopilotTextarea.clearAutocompletionsFromEditor: error removing node\",\n e\n );\n }\n }\n}\n"]}
@@ -1,29 +0,0 @@
1
- import { __async } from './chunk-MRXNTQOX.mjs';
2
-
3
- // src/lib/stream-promise-flatten.ts
4
- function streamPromiseFlatten(promise) {
5
- return new ReadableStream({
6
- start(controller) {
7
- return __async(this, null, function* () {
8
- try {
9
- const stream = yield promise;
10
- const reader = stream.getReader();
11
- while (true) {
12
- const { done, value } = yield reader.read();
13
- if (done) {
14
- controller.close();
15
- return;
16
- }
17
- controller.enqueue(value);
18
- }
19
- } catch (error) {
20
- controller.error(error);
21
- }
22
- });
23
- }
24
- });
25
- }
26
-
27
- export { streamPromiseFlatten };
28
- //# sourceMappingURL=out.js.map
29
- //# sourceMappingURL=chunk-FN7GDKKG.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/stream-promise-flatten.ts"],"names":[],"mappings":";;;;;AAAO,SAAS,qBACd,SACmB;AACnB,SAAO,IAAI,eAAkB;AAAA,IACrB,MAAM,YAAY;AAAA;AACtB,YAAI;AACF,gBAAM,SAAS,MAAM;AACrB,gBAAM,SAAS,OAAO,UAAU;AAEhC,iBAAO,MAAM;AACX,kBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,gBAAI,MAAM;AACR,yBAAW,MAAM;AACjB;AAAA,YACF;AAEA,uBAAW,QAAQ,KAAK;AAAA,UAC1B;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AAAA,QACxB;AAAA,MACF;AAAA;AAAA,EACF,CAAC;AACH","sourcesContent":["export function streamPromiseFlatten<A>(\n promise: Promise<ReadableStream<A>>\n): ReadableStream<A> {\n return new ReadableStream<A>({\n async start(controller) {\n try {\n const stream = await promise;\n const reader = stream.getReader();\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n controller.close();\n return;\n }\n\n controller.enqueue(value);\n }\n } catch (error) {\n controller.error(error);\n }\n },\n });\n}\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-H4VKQGVU.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,55 +0,0 @@
1
- import { retry } from './chunk-4S5ZJH3I.mjs';
2
- import { __async } from './chunk-MRXNTQOX.mjs';
3
- import { CopilotContext } from '@copilotkit/react-core';
4
- import { useContext, useCallback } from 'react';
5
-
6
- function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
7
- const { getContextString } = useContext(CopilotContext);
8
- return useCallback(
9
- (editorState, abortSignal) => __async(this, null, function* () {
10
- const res = yield retry(() => __async(this, null, function* () {
11
- const messages = [
12
- {
13
- role: "system",
14
- content: apiConfig.makeSystemPrompt(
15
- textareaPurpose,
16
- getContextString(contextCategories)
17
- )
18
- },
19
- ...apiConfig.fewShotMessages,
20
- {
21
- role: "user",
22
- name: "TextAfterCursor",
23
- content: editorState.textAfterCursor
24
- },
25
- {
26
- role: "user",
27
- name: "TextBeforeCursor",
28
- content: editorState.textBeforeCursor
29
- }
30
- ];
31
- const stream = yield apiConfig.apiEndpoint.run(
32
- abortSignal,
33
- messages,
34
- apiConfig.forwardedParams
35
- );
36
- const reader = stream.getReader();
37
- let result = "";
38
- while (true) {
39
- const { done, value } = yield reader.read();
40
- if (done) {
41
- break;
42
- }
43
- result += value;
44
- }
45
- return result;
46
- }));
47
- return res;
48
- }),
49
- [apiConfig, getContextString, contextCategories, textareaPurpose]
50
- );
51
- }
52
-
53
- export { useMakeStandardAutosuggestionFunction };
54
- //# sourceMappingURL=out.js.map
55
- //# sourceMappingURL=chunk-HAFHLU4N.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AAqBjC,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,iBAAiB,IAAI,WAAW,cAAc;AAEtD,SAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,UAAU;AAAA,cACjB;AAAA,cACA,iBAAiB,iBAAiB;AAAA,YACpC;AAAA,UACF;AAAA,UACA,GAAG,UAAU;AAAA,UACb;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,QACF;AAEA,cAAM,SAAS,MAAM,UAAU,YAAY;AAAA,UACzC;AAAA,UACA;AAAA,UACA,UAAU;AAAA,QACZ;AAGA,cAAM,SAAS,OAAO,UAAU;AAChC,YAAI,SAAS;AAEb,eAAO,MAAM;AACX,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR;AAAA,UACF;AACA,oBAAU;AAAA,QACZ;AAEA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF","sourcesContent":["import { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport {\n AutosuggestionsBareFunction,\n MinimalChatGPTMessage,\n} from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[] | undefined,\n apiConfig: SuggestionsApiConfig\n): AutosuggestionsBareFunction {\n const { getContextString } = useContext(CopilotContext);\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(contextCategories)\n ),\n },\n ...apiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n ];\n\n const stream = await apiConfig.apiEndpoint.run(\n abortSignal,\n messages,\n apiConfig.forwardedParams\n );\n\n // read the stream:\n const reader = stream.getReader();\n let result = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n result += value;\n }\n\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose]\n );\n}\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-IU3WTXLQ.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,101 +0,0 @@
1
- import { Range, Editor, Text, Element, Path, Point } from 'slate';
2
-
3
- // src/lib/get-text-around-cursor.ts
4
- function getTextAroundCollapsedCursor(editor) {
5
- const { selection } = editor;
6
- if (!selection || !Range.isCollapsed(selection)) {
7
- return null;
8
- }
9
- const cursorPoint = selection.anchor;
10
- const beforeRange = {
11
- anchor: Editor.start(editor, []),
12
- focus: cursorPoint
13
- };
14
- const afterRange = {
15
- anchor: cursorPoint,
16
- focus: Editor.end(editor, [])
17
- };
18
- const before = extractTextWithNewlines(editor, beforeRange);
19
- const after = extractTextWithNewlines(editor, afterRange);
20
- return {
21
- cursorPoint,
22
- textBeforeCursor: before,
23
- textAfterCursor: after
24
- };
25
- }
26
- function getTextAroundSelection(editor) {
27
- const { selection } = editor;
28
- if (!selection) {
29
- return null;
30
- }
31
- const wellOrderedSelection = wellOrderedRange(selection);
32
- const beforeRange = {
33
- anchor: Editor.start(editor, []),
34
- focus: wellOrderedSelection.anchor
35
- };
36
- const afterRange = {
37
- anchor: wellOrderedSelection.focus,
38
- focus: Editor.end(editor, [])
39
- };
40
- const before = extractTextWithNewlines(editor, beforeRange);
41
- const after = extractTextWithNewlines(editor, afterRange);
42
- const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
43
- return {
44
- selection: wellOrderedSelection,
45
- textBeforeCursor: before,
46
- selectedText,
47
- textAfterCursor: after
48
- };
49
- }
50
- function getFullEditorTextWithNewlines(editor) {
51
- const fullDocumentRange = {
52
- anchor: Editor.start(editor, []),
53
- focus: Editor.end(editor, [])
54
- };
55
- return extractTextWithNewlines(editor, fullDocumentRange);
56
- }
57
- function extractTextWithNewlines(editor, range) {
58
- const voids = false;
59
- const [start, end] = Range.edges(range);
60
- let text = "";
61
- let lastBlock = null;
62
- for (const [node, path] of Editor.nodes(editor, {
63
- at: range,
64
- match: Text.isText,
65
- voids
66
- })) {
67
- let t = node.text;
68
- const [block] = Editor.above(editor, {
69
- at: path,
70
- match: (n) => Element.isElement(n) && n.type === "paragraph"
71
- }) || [null];
72
- if (lastBlock !== block && block) {
73
- if (lastBlock) {
74
- text += "\n";
75
- }
76
- lastBlock = block;
77
- }
78
- if (Path.equals(path, end.path)) {
79
- t = t.slice(0, end.offset);
80
- }
81
- if (Path.equals(path, start.path)) {
82
- t = t.slice(start.offset);
83
- }
84
- text += t;
85
- }
86
- return text;
87
- }
88
- function wellOrderedRange(range) {
89
- const { anchor, focus } = range;
90
- if (Point.isBefore(anchor, focus)) {
91
- return range;
92
- }
93
- return {
94
- anchor: focus,
95
- focus: anchor
96
- };
97
- }
98
-
99
- export { extractTextWithNewlines, getFullEditorTextWithNewlines, getTextAroundCollapsedCursor, getTextAroundSelection };
100
- //# sourceMappingURL=out.js.map
101
- //# sourceMappingURL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A,IACR,OAAO;AAAA,EACT;AACF","sourcesContent":["import {\n Editor,\n Node,\n Path,\n Range,\n Text,\n Element,\n BasePoint,\n BaseRange,\n Point,\n} from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(\n editor: Editor\n): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n"]}
@@ -1,10 +0,0 @@
1
- import { arraysAreEqual } from './chunk-KGKLUWKW.mjs';
2
-
3
- // src/types/base/editor-autocomplete-state.ts
4
- function areEqual_autocompleteState(prev, next) {
5
- return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
6
- }
7
-
8
- export { areEqual_autocompleteState };
9
- //# sourceMappingURL=out.js.map
10
- //# sourceMappingURL=chunk-JAFCXEPU.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types/base/editor-autocomplete-state.ts"],"names":[],"mappings":";;;;;AASO,SAAS,2BACd,MACA,MACA;AACA,SACE,KAAK,YAAY,WAAW,KAAK,YAAY,UAC7C,eAAe,KAAK,YAAY,MAAM,KAAK,YAAY,IAAI,KAC3D,KAAK,qBAAqB,KAAK,oBAC/B,KAAK,oBAAoB,KAAK;AAElC","sourcesContent":["import { BasePoint } from \"slate\";\nimport { arraysAreEqual } from \"../../lib/utils\";\n\nexport interface EditorAutocompleteState {\n cursorPoint: BasePoint;\n textBeforeCursor: string;\n textAfterCursor: string;\n}\n\nexport function areEqual_autocompleteState(\n prev: EditorAutocompleteState,\n next: EditorAutocompleteState\n) {\n return (\n prev.cursorPoint.offset === next.cursorPoint.offset &&\n arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) &&\n prev.textBeforeCursor === next.textBeforeCursor &&\n prev.textAfterCursor === next.textAfterCursor\n );\n}\n"]}
@@ -1,107 +0,0 @@
1
- import { Transforms, Editor, Operation, Path } from 'slate';
2
- import { HistoryEditor } from 'slate-history';
3
-
4
- // src/lib/slatejs-edits/with-partial-history.ts
5
- var withPartialHistory = (editor, shouldSave) => {
6
- const e = editor;
7
- const { apply } = e;
8
- e.history = { undos: [], redos: [] };
9
- e.redo = () => {
10
- const { history } = e;
11
- const { redos } = history;
12
- if (redos.length > 0) {
13
- const batch = redos[redos.length - 1];
14
- if (batch.selectionBefore) {
15
- Transforms.setSelection(e, batch.selectionBefore);
16
- }
17
- HistoryEditor.withoutSaving(e, () => {
18
- Editor.withoutNormalizing(e, () => {
19
- for (const op of batch.operations) {
20
- e.apply(op);
21
- }
22
- });
23
- });
24
- history.redos.pop();
25
- e.writeHistory("undos", batch);
26
- }
27
- };
28
- e.undo = () => {
29
- const { history } = e;
30
- const { undos } = history;
31
- if (undos.length > 0) {
32
- const batch = undos[undos.length - 1];
33
- HistoryEditor.withoutSaving(e, () => {
34
- Editor.withoutNormalizing(e, () => {
35
- const inverseOps = batch.operations.map(Operation.inverse).reverse();
36
- for (const op of inverseOps) {
37
- e.apply(op);
38
- }
39
- if (batch.selectionBefore) {
40
- Transforms.setSelection(e, batch.selectionBefore);
41
- }
42
- });
43
- });
44
- e.writeHistory("redos", batch);
45
- history.undos.pop();
46
- }
47
- };
48
- e.apply = (op) => {
49
- const { operations, history } = e;
50
- const { undos } = history;
51
- const lastBatch = undos[undos.length - 1];
52
- const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
53
- let save = HistoryEditor.isSaving(e);
54
- let merge = HistoryEditor.isMerging(e);
55
- if (save == null) {
56
- save = shouldSave(op, lastOp);
57
- }
58
- if (save) {
59
- if (merge == null) {
60
- if (lastBatch == null) {
61
- merge = false;
62
- } else if (operations.length !== 0) {
63
- merge = true;
64
- } else {
65
- merge = shouldMerge(op, lastOp);
66
- }
67
- }
68
- if (lastBatch && merge) {
69
- lastBatch.operations.push(op);
70
- } else {
71
- const batch = {
72
- operations: [op],
73
- selectionBefore: e.selection
74
- };
75
- e.writeHistory("undos", batch);
76
- }
77
- while (undos.length > 100) {
78
- undos.shift();
79
- }
80
- history.redos = [];
81
- }
82
- apply(op);
83
- };
84
- e.writeHistory = (stack, batch) => {
85
- e.history[stack].push(batch);
86
- };
87
- return e;
88
- };
89
- var shouldMerge = (op, prev) => {
90
- if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
91
- return true;
92
- }
93
- if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
94
- return true;
95
- }
96
- return false;
97
- };
98
- var defaultShouldSave = (op, prev) => {
99
- if (op.type === "set_selection") {
100
- return false;
101
- }
102
- return true;
103
- };
104
-
105
- export { defaultShouldSave, withPartialHistory };
106
- //# sourceMappingURL=out.js.map
107
- //# sourceMappingURL=chunk-KCHYD3EB.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/slatejs-edits/with-partial-history.ts"],"names":[],"mappings":";AAAA,SAAS,QAAQ,WAAW,MAAa,kBAAkB;AAC3D,SAAS,qBAAqB;AASvB,IAAM,qBAAqB,CAChC,QACA,eACG;AACH,QAAM,IAAI;AACV,QAAM,EAAE,MAAM,IAAI;AAClB,I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B;AAC/B,WAAO;AAAA,EACT;AAEA,SAAO;AACT","sourcesContent":["import { Editor, Operation, Path, Range, Transforms } from \"slate\";\nimport { HistoryEditor } from \"slate-history\";\n\n// Copy-pasted from `https://github.com/ianstormtaylor/slate/blob/main/packages/slate-history/src/with-history.ts`\n// With one exception: the `shouldSave` function is passed in as an argument to `withPartialHistory` instead of being hardcoded\nexport type ShouldSaveToHistory = (\n op: Operation,\n prev: Operation | undefined\n) => boolean;\n\nexport const withPartialHistory = <T extends Editor>(\n editor: T,\n shouldSave: ShouldSaveToHistory\n) => {\n const e = editor as T & HistoryEditor;\n const { apply } = e;\n e.history = { undos: [], redos: [] };\n\n e.redo = () => {\n const { history } = e;\n const { redos } = history;\n\n if (redos.length > 0) {\n const batch = redos[redos.length - 1];\n\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n for (const op of batch.operations) {\n e.apply(op);\n }\n });\n });\n\n history.redos.pop();\n e.writeHistory(\"undos\", batch);\n }\n };\n\n e.undo = () => {\n const { history } = e;\n const { undos } = history;\n\n if (undos.length > 0) {\n const batch = undos[undos.length - 1];\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n const inverseOps = batch.operations.map(Operation.inverse).reverse();\n\n for (const op of inverseOps) {\n e.apply(op);\n }\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n });\n });\n\n e.writeHistory(\"redos\", batch);\n history.undos.pop();\n }\n };\n\n e.apply = (op: Operation) => {\n const { operations, history } = e;\n const { undos } = history;\n const lastBatch = undos[undos.length - 1];\n const lastOp =\n lastBatch && lastBatch.operations[lastBatch.operations.length - 1];\n let save = HistoryEditor.isSaving(e);\n let merge = HistoryEditor.isMerging(e);\n\n if (save == null) {\n save = shouldSave(op, lastOp);\n }\n\n if (save) {\n if (merge == null) {\n if (lastBatch == null) {\n merge = false;\n } else if (operations.length !== 0) {\n merge = true;\n } else {\n merge = shouldMerge(op, lastOp);\n }\n }\n\n if (lastBatch && merge) {\n lastBatch.operations.push(op);\n } else {\n const batch = {\n operations: [op],\n selectionBefore: e.selection,\n };\n e.writeHistory(\"undos\", batch);\n }\n\n while (undos.length > 100) {\n undos.shift();\n }\n\n history.redos = [];\n }\n\n apply(op);\n };\n\n e.writeHistory = (stack: \"undos\" | \"redos\", batch: any) => {\n e.history[stack].push(batch);\n };\n\n return e;\n};\n\n/**\n * Check whether to merge an operation into the previous operation.\n */\n\nconst shouldMerge = (op: Operation, prev: Operation | undefined): boolean => {\n if (\n prev &&\n op.type === \"insert_text\" &&\n prev.type === \"insert_text\" &&\n op.offset === prev.offset + prev.text.length &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n if (\n prev &&\n op.type === \"remove_text\" &&\n prev.type === \"remove_text\" &&\n op.offset + op.text.length === prev.offset &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n return false;\n};\n\nexport const defaultShouldSave = (\n op: Operation,\n prev: Operation | undefined\n): boolean => {\n if (op.type === \"set_selection\") {\n return false;\n }\n\n return true;\n};\n"]}