@copilotkit/react-textarea 0.37.0 → 0.38.0-beta.0

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 (114) hide show
  1. package/.turbo/turbo-build.log +216 -224
  2. package/CHANGELOG.md +13 -0
  3. package/dist/chunk-3SVQJA5A.mjs +169 -0
  4. package/dist/chunk-3SVQJA5A.mjs.map +1 -0
  5. package/dist/chunk-5KLAWLCD.mjs +88 -0
  6. package/dist/chunk-5KLAWLCD.mjs.map +1 -0
  7. package/dist/{chunk-QKS2IOUH.mjs → chunk-7QFH4E7C.mjs} +7 -5
  8. package/dist/chunk-7QFH4E7C.mjs.map +1 -0
  9. package/dist/chunk-CVO5T3PA.mjs +82 -0
  10. package/dist/chunk-CVO5T3PA.mjs.map +1 -0
  11. package/dist/{chunk-DKE57EAC.mjs → chunk-H3PGQHLG.mjs} +5 -5
  12. package/dist/{chunk-RKQ6RTZM.mjs → chunk-I6DJQ7D7.mjs} +33 -38
  13. package/dist/chunk-I6DJQ7D7.mjs.map +1 -0
  14. package/dist/{chunk-VAJHETSN.mjs → chunk-IF7CDWEH.mjs} +5 -5
  15. package/dist/{chunk-VAJHETSN.mjs.map → chunk-IF7CDWEH.mjs.map} +1 -1
  16. package/dist/{chunk-LCDTIJSD.mjs → chunk-OJXLHIYQ.mjs} +4 -2
  17. package/dist/chunk-OJXLHIYQ.mjs.map +1 -0
  18. package/dist/{chunk-ZRKQLLC7.mjs → chunk-R77MK6QS.mjs} +10 -5
  19. package/dist/{chunk-ZRKQLLC7.mjs.map → chunk-R77MK6QS.mjs.map} +1 -1
  20. package/dist/{chunk-O4LDWYJB.mjs → chunk-TNGDQV3I.mjs} +1 -2
  21. package/dist/{chunk-O4LDWYJB.mjs.map → chunk-TNGDQV3I.mjs.map} +1 -1
  22. package/dist/{chunk-KDVMG3XF.mjs → chunk-WMHVBGPR.mjs} +23 -25
  23. package/dist/chunk-WMHVBGPR.mjs.map +1 -0
  24. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +15 -7
  25. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
  26. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +4 -4
  27. package/dist/components/copilot-textarea/copilot-textarea.d.ts +2 -2
  28. package/dist/components/copilot-textarea/copilot-textarea.js +255 -207
  29. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  30. package/dist/components/copilot-textarea/copilot-textarea.mjs +11 -11
  31. package/dist/components/hovering-toolbar/hovering-toolbar.js +0 -1
  32. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
  33. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +1 -1
  34. package/dist/components/index.d.ts +1 -1
  35. package/dist/components/index.js +251 -203
  36. package/dist/components/index.js.map +1 -1
  37. package/dist/components/index.mjs +11 -11
  38. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +2 -1
  39. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +6 -4
  40. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -1
  41. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +1 -1
  42. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +1 -1
  43. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +39 -31
  44. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
  45. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
  46. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +1 -1
  47. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +100 -60
  48. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
  49. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
  50. package/dist/index.d.ts +1 -1
  51. package/dist/index.js +251 -203
  52. package/dist/index.js.map +1 -1
  53. package/dist/index.mjs +11 -11
  54. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +1 -1
  55. package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +1 -1
  56. package/dist/types/autosuggestions-config/autosuggestions-config.js +96 -108
  57. package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
  58. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +5 -5
  59. package/dist/types/autosuggestions-config/editing-api-config.d.ts +3 -3
  60. package/dist/types/autosuggestions-config/editing-api-config.js +39 -46
  61. package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -1
  62. package/dist/types/autosuggestions-config/editing-api-config.mjs +1 -1
  63. package/dist/types/autosuggestions-config/index.d.ts +1 -1
  64. package/dist/types/autosuggestions-config/index.js +96 -108
  65. package/dist/types/autosuggestions-config/index.js.map +1 -1
  66. package/dist/types/autosuggestions-config/index.mjs +5 -5
  67. package/dist/types/autosuggestions-config/insertions-api-config.d.ts +3 -3
  68. package/dist/types/autosuggestions-config/insertions-api-config.js +32 -37
  69. package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -1
  70. package/dist/types/autosuggestions-config/insertions-api-config.mjs +1 -1
  71. package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +3 -3
  72. package/dist/types/autosuggestions-config/suggestions-api-config.js +22 -24
  73. package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -1
  74. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +1 -1
  75. package/dist/types/base/base-autosuggestions-config.d.ts +14 -0
  76. package/dist/types/base/base-autosuggestions-config.js +3 -1
  77. package/dist/types/base/base-autosuggestions-config.js.map +1 -1
  78. package/dist/types/base/base-autosuggestions-config.mjs +1 -1
  79. package/dist/types/base/index.js +3 -1
  80. package/dist/types/base/index.js.map +1 -1
  81. package/dist/types/base/index.mjs +1 -1
  82. package/dist/types/index.d.ts +1 -1
  83. package/dist/types/index.js +96 -108
  84. package/dist/types/index.js.map +1 -1
  85. package/dist/types/index.mjs +5 -5
  86. package/package.json +7 -6
  87. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +5 -0
  88. package/src/components/copilot-textarea/copilot-textarea.tsx +1 -1
  89. package/src/components/hovering-toolbar/hovering-toolbar.tsx +0 -1
  90. package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +11 -4
  91. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +51 -31
  92. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +116 -62
  93. package/src/types/autosuggestions-config/editing-api-config.tsx +48 -49
  94. package/src/types/autosuggestions-config/index.ts +0 -1
  95. package/src/types/autosuggestions-config/insertions-api-config.tsx +38 -40
  96. package/src/types/autosuggestions-config/suggestions-api-config.tsx +26 -27
  97. package/src/types/base/base-autosuggestions-config.tsx +17 -0
  98. package/dist/chunk-4OJ3H65F.mjs +0 -89
  99. package/dist/chunk-4OJ3H65F.mjs.map +0 -1
  100. package/dist/chunk-HE4GMS2P.mjs +0 -121
  101. package/dist/chunk-HE4GMS2P.mjs.map +0 -1
  102. package/dist/chunk-KDVMG3XF.mjs.map +0 -1
  103. package/dist/chunk-LCDTIJSD.mjs.map +0 -1
  104. package/dist/chunk-QKS2IOUH.mjs.map +0 -1
  105. package/dist/chunk-RKQ6RTZM.mjs.map +0 -1
  106. package/dist/chunk-SJ2TM5GA.mjs +0 -72
  107. package/dist/chunk-SJ2TM5GA.mjs.map +0 -1
  108. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.d.ts +0 -7
  109. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js +0 -19
  110. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +0 -1
  111. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +0 -1
  112. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +0 -1
  113. package/src/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.tsx +0 -5
  114. /package/dist/{chunk-DKE57EAC.mjs.map → chunk-H3PGQHLG.mjs.map} +0 -0
@@ -105,7 +105,7 @@ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
105
105
  }
106
106
 
107
107
  // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
108
- var import_react_core2 = require("@copilotkit/react-core");
108
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
109
109
  function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
110
110
  const { getContextString, copilotApiConfig } = (0, import_react.useContext)(import_react_core.CopilotContext);
111
111
  const publicApiKey = copilotApiConfig.publicApiKey;
@@ -113,44 +113,55 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
113
113
  return (0, import_react.useCallback)(
114
114
  (editorState2, abortSignal) => __async(this, null, function* () {
115
115
  const res = yield retry(() => __async(this, null, function* () {
116
+ var _a, _b, _c;
116
117
  const messages = [
117
- {
118
- role: "system",
118
+ new import_runtime_client_gql.TextMessage({
119
+ role: import_runtime_client_gql.Role.System,
119
120
  content: apiConfig.makeSystemPrompt(
120
121
  textareaPurpose,
121
122
  getContextString([], contextCategories)
122
123
  )
123
- },
124
+ }),
124
125
  ...apiConfig.fewShotMessages,
125
- {
126
- role: "user",
127
- name: "TextAfterCursor",
126
+ new import_runtime_client_gql.TextMessage({
127
+ role: import_runtime_client_gql.Role.User,
128
128
  content: editorState2.textAfterCursor
129
- },
130
- {
131
- role: "user",
132
- name: "TextBeforeCursor",
133
- content: editorState2.textBeforeCursor
134
- }
129
+ }),
130
+ new import_runtime_client_gql.TextMessage({
131
+ role: import_runtime_client_gql.Role.User,
132
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
133
+ }),
134
+ new import_runtime_client_gql.TextMessage({
135
+ role: import_runtime_client_gql.Role.User,
136
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
137
+ })
135
138
  ];
136
- const response = yield (0, import_react_core2.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
137
- messages
138
- }, apiConfig.forwardedParams), {
139
- copilotConfig: copilotApiConfig,
140
- signal: abortSignal,
141
- headers
142
- }));
143
- if (!response.events) {
144
- throw new Error("Failed to fetch chat completion");
145
- }
146
- const reader = response.events.getReader();
139
+ const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
140
+ url: copilotApiConfig.chatApiEndpoint,
141
+ publicApiKey: copilotApiConfig.publicApiKey,
142
+ headers: copilotApiConfig.headers
143
+ });
144
+ const response = yield runtimeClient.generateCopilotResponse(
145
+ {
146
+ frontend: {
147
+ actions: []
148
+ },
149
+ messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messages)
150
+ },
151
+ copilotApiConfig.properties,
152
+ abortSignal
153
+ ).toPromise();
147
154
  let result = "";
148
- while (!abortSignal.aborted) {
149
- const { done, value } = yield reader.read();
150
- if (done) {
155
+ for (const message of (0, import_runtime_client_gql.convertGqlOutputToMessages)(
156
+ (_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
157
+ )) {
158
+ if (abortSignal.aborted) {
151
159
  break;
152
160
  }
153
- result += value;
161
+ if (message instanceof import_runtime_client_gql.TextMessage) {
162
+ result += message.content;
163
+ console.log(message.content);
164
+ }
154
165
  }
155
166
  return result;
156
167
  }));
@@ -161,7 +172,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
161
172
  }
162
173
 
163
174
  // src/types/base/base-autosuggestions-config.tsx
164
- var import_react_core3 = require("@copilotkit/react-core");
175
+ var import_react_core2 = require("@copilotkit/react-core");
165
176
  var defaultShouldToggleHoveringEditorOnKeyPress = (event, shortcut) => {
166
177
  if (event.key === shortcut && event.metaKey) {
167
178
  return true;
@@ -174,17 +185,20 @@ var defaultShouldAcceptAutosuggestionOnKeyPress = (event) => {
174
185
  }
175
186
  return false;
176
187
  };
188
+ var defaultShouldAcceptAutosuggestionOnTouch = () => true;
177
189
  var defaultBaseAutosuggestionsConfig = {
178
190
  debounceTime: 250,
179
- contextCategories: import_react_core3.defaultCopilotContextCategories,
191
+ contextCategories: import_react_core2.defaultCopilotContextCategories,
180
192
  disableWhenEmpty: true,
181
193
  disabled: false,
182
194
  temporarilyDisableWhenMovingCursorWithoutChangingText: true,
183
195
  shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
184
- shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress
196
+ shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,
197
+ shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch
185
198
  };
186
199
 
187
200
  // src/types/autosuggestions-config/suggestions-api-config.tsx
201
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
188
202
  var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
189
203
  return `You are a versatile writing assistant.
190
204
 
@@ -210,33 +224,30 @@ ${contextString}
210
224
  `;
211
225
  };
212
226
  var defaultSuggestionsFewShotMessages = [
213
- {
214
- role: "user",
215
- name: "TextAfterCursor",
216
- content: "While I was there I also picked up some apples, oranges, and bananas."
217
- },
218
- {
219
- role: "user",
227
+ new import_runtime_client_gql2.TextMessage({
228
+ role: import_runtime_client_gql2.Role.User,
229
+ content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
230
+ }),
231
+ new import_runtime_client_gql2.TextMessage({
232
+ role: import_runtime_client_gql2.Role.User,
220
233
  content: "This morning I woke up and went straight to the grocery store."
221
- },
222
- {
223
- role: "assistant",
234
+ }),
235
+ new import_runtime_client_gql2.TextMessage({
236
+ role: import_runtime_client_gql2.Role.Assistant,
224
237
  content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
225
- },
226
- {
227
- role: "user",
228
- name: "TextAfterCursor",
229
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
230
- },
231
- {
232
- role: "user",
233
- name: "TextBeforeCursor",
234
- 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;`
235
- },
236
- {
237
- role: "assistant",
238
+ }),
239
+ new import_runtime_client_gql2.TextMessage({
240
+ role: import_runtime_client_gql2.Role.User,
241
+ content: "<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>"
242
+ }),
243
+ new import_runtime_client_gql2.TextMessage({
244
+ role: import_runtime_client_gql2.Role.User,
245
+ content: `<TextBeforeCursor>The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;</TextBeforeCursor>`
246
+ }),
247
+ new import_runtime_client_gql2.TextMessage({
248
+ role: import_runtime_client_gql2.Role.Assistant,
238
249
  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"; `
239
- }
250
+ })
240
251
  ];
241
252
  var defaultSuggestionsApiConfig = {
242
253
  makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
@@ -245,6 +256,7 @@ var defaultSuggestionsApiConfig = {
245
256
  };
246
257
 
247
258
  // src/types/autosuggestions-config/insertions-api-config.tsx
259
+ var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
248
260
  var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
249
261
  return `You are a versatile writing assistant helping the user insert new text into their existing work.
250
262
 
@@ -273,44 +285,38 @@ The conversation will be structured as follows:
273
285
  `;
274
286
  };
275
287
  var defaultInsertionsFewShotMessages = [
276
- {
277
- role: "user",
278
- name: "TextAfterCursor",
279
- content: "While I was there I also picked up some apples, oranges, and bananas."
280
- },
281
- {
282
- role: "user",
283
- name: "TextBeforeCursor",
284
- content: "This morning I woke up and went straight to the grocery store."
285
- },
286
- {
287
- role: "user",
288
- name: "InsertionPrompt",
289
- content: "I bought a big watermelon"
290
- },
291
- {
292
- role: "assistant",
293
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
294
- },
295
- {
296
- role: "user",
297
- name: "TextAfterCursor",
298
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
299
- },
300
- {
301
- role: "user",
302
- name: "TextBeforeCursor",
303
- 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;`
304
- },
305
- {
306
- role: "user",
307
- name: "InsertionPrompt",
308
- content: "add section about the optionholder's pro rata share"
309
- },
310
- {
311
- role: "assistant",
288
+ new import_runtime_client_gql3.TextMessage({
289
+ role: import_runtime_client_gql3.Role.User,
290
+ content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
291
+ }),
292
+ new import_runtime_client_gql3.TextMessage({
293
+ role: import_runtime_client_gql3.Role.User,
294
+ content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>"
295
+ }),
296
+ new import_runtime_client_gql3.TextMessage({
297
+ role: import_runtime_client_gql3.Role.User,
298
+ content: "<InsertionPrompt>I bought a big watermelon</InsertionPrompt>"
299
+ }),
300
+ new import_runtime_client_gql3.TextMessage({
301
+ role: import_runtime_client_gql3.Role.Assistant,
302
+ content: "When I arrived I went straight to the produce section and picked out a big watermelon."
303
+ }),
304
+ new import_runtime_client_gql3.TextMessage({
305
+ role: import_runtime_client_gql3.Role.User,
306
+ content: "<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>"
307
+ }),
308
+ new import_runtime_client_gql3.TextMessage({
309
+ role: import_runtime_client_gql3.Role.User,
310
+ content: `<TextBeforeCursor>The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;</TextBeforeCursor>`
311
+ }),
312
+ new import_runtime_client_gql3.TextMessage({
313
+ role: import_runtime_client_gql3.Role.User,
314
+ content: "<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>"
315
+ }),
316
+ new import_runtime_client_gql3.TextMessage({
317
+ role: import_runtime_client_gql3.Role.Assistant,
312
318
  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"; `
313
- }
319
+ })
314
320
  ];
315
321
  var defaultInsertionsApiConfig = {
316
322
  makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
@@ -319,6 +325,7 @@ var defaultInsertionsApiConfig = {
319
325
  };
320
326
 
321
327
  // src/types/autosuggestions-config/editing-api-config.tsx
328
+ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
322
329
  var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
323
330
  return `You are a versatile writing assistant helping the user edit a portion of their text.
324
331
 
@@ -346,54 +353,46 @@ The conversation will be structured as follows:
346
353
  `;
347
354
  };
348
355
  var defaultEditingFewShotMessages = [
349
- {
350
- role: "user",
351
- name: "TextBeforeCursor",
352
- content: "This morning I woke up and went straight to the grocery store. "
353
- },
354
- {
355
- role: "user",
356
- name: "TextToEdit",
357
- content: "While I was there I picked up some apples, oranges, and bananas. "
358
- },
359
- {
360
- role: "user",
361
- name: "TextAfterCursor",
362
- content: "The grocery store was having a sale on fruit, so I decided to stock up."
363
- },
364
- {
365
- role: "user",
366
- name: "EditingPrompt",
367
- content: "I also bought a big watermelon"
368
- },
369
- {
370
- role: "assistant",
356
+ new import_runtime_client_gql4.TextMessage({
357
+ role: import_runtime_client_gql4.Role.User,
358
+ content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>"
359
+ }),
360
+ new import_runtime_client_gql4.TextMessage({
361
+ role: import_runtime_client_gql4.Role.User,
362
+ content: "<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>"
363
+ }),
364
+ new import_runtime_client_gql4.TextMessage({
365
+ role: import_runtime_client_gql4.Role.User,
366
+ content: "<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>"
367
+ }),
368
+ new import_runtime_client_gql4.TextMessage({
369
+ role: import_runtime_client_gql4.Role.User,
370
+ content: "<EditingPrompt>I also bought a big watermelon</EditingPrompt>"
371
+ }),
372
+ new import_runtime_client_gql4.TextMessage({
373
+ role: import_runtime_client_gql4.Role.Assistant,
371
374
  content: "While I was there I picked up some apples, oranges, and bananas, and a big watermelon."
372
- },
373
- {
374
- role: "user",
375
- name: "TextBeforeCursor",
376
- content: "Yesterday, I spent the afternoon working on my new project. "
377
- },
378
- {
379
- role: "user",
380
- name: "TextToEdit",
381
- content: "It's quite challenging and requires a lot of focus. "
382
- },
383
- {
384
- role: "user",
385
- name: "TextAfterCursor",
386
- content: "I'm really excited about the potential outcomes of this project."
387
- },
388
- {
389
- role: "user",
390
- name: "EditingPrompt",
391
- content: "emphasize the complexity and my enthusiasm for the project"
392
- },
393
- {
394
- role: "assistant",
375
+ }),
376
+ new import_runtime_client_gql4.TextMessage({
377
+ role: import_runtime_client_gql4.Role.User,
378
+ content: "<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>"
379
+ }),
380
+ new import_runtime_client_gql4.TextMessage({
381
+ role: import_runtime_client_gql4.Role.User,
382
+ content: "<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>"
383
+ }),
384
+ new import_runtime_client_gql4.TextMessage({
385
+ role: import_runtime_client_gql4.Role.User,
386
+ content: "<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>"
387
+ }),
388
+ new import_runtime_client_gql4.TextMessage({
389
+ role: import_runtime_client_gql4.Role.User,
390
+ content: "<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>"
391
+ }),
392
+ new import_runtime_client_gql4.TextMessage({
393
+ role: import_runtime_client_gql4.Role.Assistant,
395
394
  content: "It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project."
396
- }
395
+ })
397
396
  ];
398
397
  var defaultEditingApiConfig = {
399
398
  makeSystemPrompt: defaultEditingMakeSystemPrompt,
@@ -402,9 +401,9 @@ var defaultEditingApiConfig = {
402
401
  };
403
402
 
404
403
  // src/types/autosuggestions-config/autosuggestions-config.tsx
405
- var import_react_core4 = require("@copilotkit/react-core");
404
+ var import_react_core3 = require("@copilotkit/react-core");
406
405
  var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
407
- contextCategories: import_react_core4.defaultCopilotContextCategories,
406
+ contextCategories: import_react_core3.defaultCopilotContextCategories,
408
407
  chatApiConfigs: {
409
408
  suggestionsApiConfig: defaultSuggestionsApiConfig,
410
409
  insertionApiConfig: defaultInsertionsApiConfig,
@@ -474,7 +473,7 @@ function areEqual_autocompleteState(prev, next) {
474
473
  }
475
474
 
476
475
  // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
477
- function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
476
+ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, shouldAcceptAutosuggestionOnTouch, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
478
477
  const [previousAutocompleteState, setPreviousAutocompleteState] = (0, import_react2.useState)(null);
479
478
  const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = (0, import_react2.useState)(null);
480
479
  const awaitForAndAppendSuggestion = (0, import_react2.useCallback)(
@@ -532,10 +531,11 @@ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress,
532
531
  setCurrentAutocompleteSuggestion
533
532
  ]
534
533
  );
535
- const keyDownHandler = (0, import_react2.useCallback)(
534
+ const keyDownOrTouchHandler = (0, import_react2.useCallback)(
536
535
  (event) => {
537
536
  if (currentAutocompleteSuggestion) {
538
- if (shouldAcceptAutosuggestionOnKeyPress(event)) {
537
+ const shouldAcceptSuggestion = event instanceof KeyboardEvent ? shouldAcceptAutosuggestionOnKeyPress(event) : shouldAcceptAutosuggestionOnTouch(event);
538
+ if (shouldAcceptSuggestion) {
539
539
  event.preventDefault();
540
540
  insertAutocompleteSuggestion(currentAutocompleteSuggestion);
541
541
  setCurrentAutocompleteSuggestion(null);
@@ -552,7 +552,8 @@ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress,
552
552
  return {
553
553
  currentAutocompleteSuggestion,
554
554
  onChangeHandler: onChange,
555
- onKeyDownHandler: keyDownHandler
555
+ onKeyDownHandler: keyDownOrTouchHandler,
556
+ onTouchStartHandler: keyDownOrTouchHandler
556
557
  };
557
558
  }
558
559
 
@@ -1229,7 +1230,7 @@ function streamPromiseFlatten(promise) {
1229
1230
  }
1230
1231
 
1231
1232
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
1232
- var import_react_core5 = require("@copilotkit/react-core");
1233
+ var import_react_core4 = require("@copilotkit/react-core");
1233
1234
 
1234
1235
  // src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx
1235
1236
  var import_Chip = __toESM(require("@mui/material/Chip/Chip.js"));
@@ -1295,7 +1296,7 @@ var HoveringInsertionPromptBoxCore = ({
1295
1296
  insertionOrEditingFunction,
1296
1297
  contextCategories
1297
1298
  }) => {
1298
- const { getDocumentsContext } = (0, import_react8.useContext)(import_react_core5.CopilotContext);
1299
+ const { getDocumentsContext } = (0, import_react8.useContext)(import_react_core4.CopilotContext);
1299
1300
  const [editSuggestion, setEditSuggestion] = (0, import_react8.useState)("");
1300
1301
  const [suggestionIsLoading, setSuggestionIsLoading] = (0, import_react8.useState)(false);
1301
1302
  const [adjustmentPrompt, setAdjustmentPrompt] = (0, import_react8.useState)("");
@@ -1680,7 +1681,6 @@ var HoveringToolbar = (props) => {
1680
1681
  setIsDisplayed(false);
1681
1682
  },
1682
1683
  performInsertion: (insertedText) => {
1683
- console.log("inserted text", insertedText);
1684
1684
  import_slate7.Transforms.delete(editor, { at: selection });
1685
1685
  import_slate7.Transforms.insertText(editor, insertedText, {
1686
1686
  at: selection
@@ -1931,10 +1931,12 @@ var BaseCopilotTextareaWithHoveringContext = import_react13.default.forwardRef(
1931
1931
  const {
1932
1932
  currentAutocompleteSuggestion,
1933
1933
  onChangeHandler: onChangeHandlerForAutocomplete,
1934
- onKeyDownHandler: onKeyDownHandlerForAutocomplete
1934
+ onKeyDownHandler: onKeyDownHandlerForAutocomplete,
1935
+ onTouchStartHandler: onTouchStartHandlerForAutocomplete
1935
1936
  } = useAutosuggestions(
1936
1937
  autosuggestionsConfig.debounceTime,
1937
1938
  autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,
1939
+ autosuggestionsConfig.shouldAcceptAutosuggestionOnTouch,
1938
1940
  autosuggestionsConfig.apiConfig.autosuggestionsFunction,
1939
1941
  insertText,
1940
1942
  autosuggestionsConfig.disableWhenEmpty,
@@ -2063,6 +2065,9 @@ var BaseCopilotTextareaWithHoveringContext = import_react13.default.forwardRef(
2063
2065
  onKeyDownHandlerForAutocomplete(event);
2064
2066
  (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
2065
2067
  },
2068
+ onTouchStart: (event) => {
2069
+ onTouchStartHandlerForAutocomplete(event);
2070
+ },
2066
2071
  className: moddedClassName,
2067
2072
  onBlur: (ev) => {
2068
2073
  var _a2;
@@ -2091,48 +2096,86 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
2091
2096
 
2092
2097
  // src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
2093
2098
  var import_shared2 = require("@copilotkit/shared");
2094
- var import_react_core6 = require("@copilotkit/react-core");
2099
+ var import_react_core5 = require("@copilotkit/react-core");
2095
2100
  var import_react14 = require("react");
2096
- var import_react_core7 = require("@copilotkit/react-core");
2101
+ var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
2097
2102
  function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
2098
- const { getContextString, copilotApiConfig } = (0, import_react14.useContext)(import_react_core6.CopilotContext);
2103
+ const { getContextString, copilotApiConfig } = (0, import_react14.useContext)(import_react_core5.CopilotContext);
2099
2104
  const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
2105
+ const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
2106
+ url: copilotApiConfig.chatApiEndpoint,
2107
+ publicApiKey: copilotApiConfig.publicApiKey,
2108
+ headers
2109
+ });
2110
+ function runtimeClientResponseToStringStream(responsePromise) {
2111
+ return __async(this, null, function* () {
2112
+ const messagesStream = yield import_runtime_client_gql5.CopilotRuntimeClient.asStream(responsePromise);
2113
+ return new ReadableStream({
2114
+ start(controller) {
2115
+ return __async(this, null, function* () {
2116
+ const reader = messagesStream.getReader();
2117
+ let sentContent = "";
2118
+ while (true) {
2119
+ const { done, value } = yield reader.read();
2120
+ if (done) {
2121
+ break;
2122
+ }
2123
+ const messages = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
2124
+ let newContent = "";
2125
+ for (const message of messages) {
2126
+ if (message instanceof import_runtime_client_gql5.TextMessage) {
2127
+ newContent += message.content;
2128
+ }
2129
+ }
2130
+ if (newContent) {
2131
+ const contentToSend = newContent.slice(sentContent.length);
2132
+ controller.enqueue(contentToSend);
2133
+ sentContent += contentToSend;
2134
+ }
2135
+ }
2136
+ controller.close();
2137
+ });
2138
+ }
2139
+ });
2140
+ });
2141
+ }
2100
2142
  const insertionFunction = (0, import_react14.useCallback)(
2101
2143
  (editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
2102
2144
  const res = yield retry(() => __async(this, null, function* () {
2103
2145
  const messages = [
2104
- {
2105
- role: "system",
2146
+ new import_runtime_client_gql5.TextMessage({
2147
+ role: import_runtime_client_gql5.Role.System,
2106
2148
  content: insertionApiConfig.makeSystemPrompt(
2107
2149
  textareaPurpose,
2108
2150
  getContextString(documents, contextCategories)
2109
2151
  )
2110
- },
2152
+ }),
2111
2153
  ...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
- }
2154
+ new import_runtime_client_gql5.TextMessage({
2155
+ role: import_runtime_client_gql5.Role.User,
2156
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
2157
+ }),
2158
+ new import_runtime_client_gql5.TextMessage({
2159
+ role: import_runtime_client_gql5.Role.User,
2160
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
2161
+ }),
2162
+ new import_runtime_client_gql5.TextMessage({
2163
+ role: import_runtime_client_gql5.Role.User,
2164
+ content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
2165
+ })
2127
2166
  ];
2128
- const stream = yield (0, import_react_core7.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
2129
- messages
2130
- }, insertionApiConfig.forwardedParams), {
2131
- copilotConfig: copilotApiConfig,
2132
- signal: abortSignal,
2133
- headers
2134
- }));
2135
- return stream.events;
2167
+ return runtimeClientResponseToStringStream(
2168
+ runtimeClient.generateCopilotResponse(
2169
+ {
2170
+ frontend: {
2171
+ actions: []
2172
+ },
2173
+ messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(messages)
2174
+ },
2175
+ copilotApiConfig.properties,
2176
+ abortSignal
2177
+ )
2178
+ );
2136
2179
  }));
2137
2180
  return res;
2138
2181
  }),
@@ -2142,43 +2185,48 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
2142
2185
  (editorState2, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
2143
2186
  const res = yield retry(() => __async(this, null, function* () {
2144
2187
  const messages = [
2145
- {
2146
- role: "system",
2188
+ new import_runtime_client_gql5.TextMessage({
2189
+ role: import_runtime_client_gql5.Role.System,
2147
2190
  content: editingApiConfig.makeSystemPrompt(
2148
2191
  textareaPurpose,
2149
2192
  getContextString(documents, contextCategories)
2150
2193
  )
2151
- },
2194
+ }),
2152
2195
  ...editingApiConfig.fewShotMessages,
2153
- {
2154
- role: "user",
2155
- name: "TextBeforeCursor",
2156
- content: editorState2.textBeforeCursor
2157
- },
2158
- {
2159
- role: "user",
2160
- name: "TextToEdit",
2161
- content: editorState2.selectedText
2162
- },
2163
- {
2164
- role: "user",
2165
- name: "TextAfterCursor",
2166
- content: editorState2.textAfterCursor
2167
- },
2168
- {
2169
- role: "user",
2170
- name: "EditingPrompt",
2171
- content: editingPrompt
2172
- }
2196
+ new import_runtime_client_gql5.TextMessage({
2197
+ role: import_runtime_client_gql5.Role.User,
2198
+ content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
2199
+ }),
2200
+ new import_runtime_client_gql5.TextMessage({
2201
+ role: import_runtime_client_gql5.Role.User,
2202
+ content: `<TextToEdit>${editorState2.selectedText}</TextToEdit>`
2203
+ }),
2204
+ new import_runtime_client_gql5.TextMessage({
2205
+ role: import_runtime_client_gql5.Role.User,
2206
+ content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
2207
+ }),
2208
+ new import_runtime_client_gql5.TextMessage({
2209
+ role: import_runtime_client_gql5.Role.User,
2210
+ content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
2211
+ })
2173
2212
  ];
2174
- const stream = yield (0, import_react_core7.fetchAndDecodeChatCompletionAsText)(__spreadProps(__spreadValues({
2175
- messages
2176
- }, editingApiConfig.forwardedParams), {
2177
- copilotConfig: copilotApiConfig,
2178
- signal: abortSignal,
2213
+ const runtimeClient2 = new import_runtime_client_gql5.CopilotRuntimeClient({
2214
+ url: copilotApiConfig.chatApiEndpoint,
2215
+ publicApiKey: copilotApiConfig.publicApiKey,
2179
2216
  headers
2180
- }));
2181
- return stream.events;
2217
+ });
2218
+ return runtimeClientResponseToStringStream(
2219
+ runtimeClient2.generateCopilotResponse(
2220
+ {
2221
+ frontend: {
2222
+ actions: []
2223
+ },
2224
+ messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(messages)
2225
+ },
2226
+ copilotApiConfig.properties,
2227
+ abortSignal
2228
+ )
2229
+ );
2182
2230
  }));
2183
2231
  return res;
2184
2232
  }),