@copilotkit/react-textarea 0.35.0-function-calling-fixes.1 → 0.35.0-function-calling-fixes.2

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 (104) hide show
  1. package/.turbo/turbo-build.log +308 -304
  2. package/CHANGELOG.md +12 -0
  3. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +1752 -36
  4. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  5. package/dist/components/base-copilot-textarea/render-element.mjs +48 -4
  6. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  7. package/dist/components/base-copilot-textarea/render-placeholder.mjs +46 -4
  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 +83 -5
  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 +54 -4
  12. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  13. package/dist/components/copilot-textarea/copilot-textarea.mjs +2196 -45
  14. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  15. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +13 -5
  16. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  17. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +130 -8
  18. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  19. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +876 -19
  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 +569 -14
  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 +592 -15
  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/included-files-preview.mjs +98 -7
  26. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -1
  27. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +592 -16
  28. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  29. package/dist/components/index.mjs +2196 -48
  30. package/dist/components/index.mjs.map +1 -1
  31. package/dist/components/manual-ui/chip-with-icon.mjs +0 -2
  32. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  33. package/dist/components/source-search-box/source-search-box.mjs +207 -8
  34. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  35. package/dist/components/ui/button.mjs +81 -6
  36. package/dist/components/ui/button.mjs.map +1 -1
  37. package/dist/components/ui/card.mjs +42 -7
  38. package/dist/components/ui/card.mjs.map +1 -1
  39. package/dist/components/ui/command.mjs +232 -14
  40. package/dist/components/ui/command.mjs.map +1 -1
  41. package/dist/components/ui/dialog.mjs +134 -11
  42. package/dist/components/ui/dialog.mjs.map +1 -1
  43. package/dist/components/ui/label.mjs +56 -5
  44. package/dist/components/ui/label.mjs.map +1 -1
  45. package/dist/components/ui/separator.mjs +42 -7
  46. package/dist/components/ui/separator.mjs.map +1 -1
  47. package/dist/components/ui/textarea.mjs +42 -7
  48. package/dist/components/ui/textarea.mjs.map +1 -1
  49. package/dist/context/index.mjs +0 -1
  50. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +155 -7
  51. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  52. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +165 -5
  53. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  54. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +145 -6
  55. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  56. package/dist/hooks/index.mjs +0 -1
  57. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +111 -5
  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 +160 -5
  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 +12 -4
  62. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  63. package/dist/index.mjs +2196 -56
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/lib/debouncer.mjs +48 -4
  66. package/dist/lib/debouncer.mjs.map +1 -1
  67. package/dist/lib/editor-to-text.mjs +40 -4
  68. package/dist/lib/editor-to-text.mjs.map +1 -1
  69. package/dist/lib/get-text-around-cursor.mjs +96 -7
  70. package/dist/lib/get-text-around-cursor.mjs.map +1 -1
  71. package/dist/lib/retry.mjs +14 -4
  72. package/dist/lib/retry.mjs.map +1 -1
  73. package/dist/lib/slatejs-edits/add-autocompletions.mjs +22 -4
  74. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
  75. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +17 -4
  76. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
  77. package/dist/lib/slatejs-edits/replace-text.mjs +24 -4
  78. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
  79. package/dist/lib/slatejs-edits/with-partial-history.mjs +102 -5
  80. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
  81. package/dist/lib/stream-promise-flatten.mjs +44 -4
  82. package/dist/lib/stream-promise-flatten.mjs.map +1 -1
  83. package/dist/lib/utils.mjs +63 -9
  84. package/dist/lib/utils.mjs.map +1 -1
  85. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +271 -9
  86. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  87. package/dist/types/autosuggestions-config/editing-api-config.mjs +82 -6
  88. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  89. package/dist/types/autosuggestions-config/index.mjs +271 -10
  90. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  91. package/dist/types/autosuggestions-config/insertions-api-config.mjs +73 -6
  92. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
  93. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +59 -6
  94. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
  95. package/dist/types/base/base-autosuggestions-config.mjs +23 -4
  96. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
  97. package/dist/types/base/editor-autocomplete-state.mjs +14 -5
  98. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
  99. package/dist/types/base/index.mjs +23 -5
  100. package/dist/types/base/index.mjs.map +1 -1
  101. package/dist/types/html-copilot-textarea-element.mjs +0 -1
  102. package/dist/types/index.mjs +271 -14
  103. package/dist/types/index.mjs.map +1 -1
  104. package/package.json +6 -6
@@ -1,22 +1,879 @@
1
- import {
2
- HoveringToolbar
3
- } from "../../chunk-DMLXXOXD.mjs";
4
- import "../../chunk-L7VVZH4Q.mjs";
5
- import "../../chunk-COQISBP2.mjs";
6
- import "../../chunk-OGLVRSCO.mjs";
7
- import "../../chunk-YNXNMCDX.mjs";
8
- import "../../chunk-3PQ7GSFE.mjs";
9
- import "../../chunk-WFTAAA7R.mjs";
10
- import "../../chunk-YFK5BFEI.mjs";
11
- import "../../chunk-LYB4B6MK.mjs";
12
- import "../../chunk-CF5GISTC.mjs";
13
- import "../../chunk-4OZR65UB.mjs";
14
- import "../../chunk-FFSICDS5.mjs";
15
- import "../../chunk-4HBKWUCT.mjs";
16
- import "../../chunk-2QDCE7PD.mjs";
17
- import "../../chunk-7SUZ6CXM.mjs";
18
- import "../../chunk-ECR45NSD.mjs";
19
- import "../../chunk-MRXNTQOX.mjs";
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
52
+
53
+ // src/components/hovering-toolbar/hovering-toolbar.tsx
54
+ import { useEffect as useEffect3, useRef as useRef2, useState as useState4 } from "react";
55
+ import { Transforms } from "slate";
56
+ import { useSlate, useSlateSelection } from "slate-react";
57
+
58
+ // src/hooks/misc/use-autosize-textarea.tsx
59
+ import { useEffect } from "react";
60
+ var useAutosizeTextArea = (textAreaRef, value) => {
61
+ useEffect(() => {
62
+ if (textAreaRef.current !== null) {
63
+ textAreaRef.current.style.height = "0px";
64
+ const scrollHeight = textAreaRef.current.scrollHeight;
65
+ textAreaRef.current.style.height = scrollHeight + "px";
66
+ }
67
+ }, [textAreaRef, value]);
68
+ };
69
+ var use_autosize_textarea_default = useAutosizeTextArea;
70
+
71
+ // src/components/source-search-box/source-search-box.tsx
72
+ import { useState } from "react";
73
+
74
+ // src/components/ui/command.tsx
75
+ import * as React from "react";
76
+ import { Command as CommandPrimitive } from "cmdk";
77
+
78
+ // src/lib/utils.ts
79
+ import { clsx } from "clsx";
80
+ import { customAlphabet } from "nanoid";
81
+ import { twMerge } from "tailwind-merge";
82
+ function cn(...inputs) {
83
+ return twMerge(clsx(inputs));
84
+ }
85
+ var nanoid = customAlphabet(
86
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
87
+ 7
88
+ );
89
+
90
+ // src/components/ui/command.tsx
91
+ import { jsx } from "react/jsx-runtime";
92
+ var Command = React.forwardRef((_a, ref) => {
93
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
94
+ return /* @__PURE__ */ jsx(
95
+ CommandPrimitive,
96
+ __spreadValues({
97
+ ref,
98
+ className: cn(
99
+ "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
100
+ className
101
+ )
102
+ }, props)
103
+ );
104
+ });
105
+ Command.displayName = CommandPrimitive.displayName;
106
+ var CommandInput = React.forwardRef((_a, ref) => {
107
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
108
+ return /* @__PURE__ */ jsx("div", { className: "flex items-center border-b px-3", "cmdk-input-wrapper": "", children: /* @__PURE__ */ jsx(
109
+ CommandPrimitive.Input,
110
+ __spreadValues({
111
+ ref,
112
+ className: cn(
113
+ "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
114
+ className
115
+ )
116
+ }, props)
117
+ ) });
118
+ });
119
+ CommandInput.displayName = CommandPrimitive.Input.displayName;
120
+ var CommandList = React.forwardRef((_a, ref) => {
121
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
122
+ return /* @__PURE__ */ jsx(
123
+ CommandPrimitive.List,
124
+ __spreadValues({
125
+ ref,
126
+ className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden pb-2", className)
127
+ }, props)
128
+ );
129
+ });
130
+ CommandList.displayName = CommandPrimitive.List.displayName;
131
+ var CommandEmpty = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(CommandPrimitive.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
132
+ CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
133
+ var CommandGroup = React.forwardRef((_a, ref) => {
134
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
135
+ return /* @__PURE__ */ jsx(
136
+ CommandPrimitive.Group,
137
+ __spreadValues({
138
+ ref,
139
+ className: cn(
140
+ "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
141
+ className
142
+ )
143
+ }, props)
144
+ );
145
+ });
146
+ CommandGroup.displayName = CommandPrimitive.Group.displayName;
147
+ var CommandSeparator = React.forwardRef((_a, ref) => {
148
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
149
+ return /* @__PURE__ */ jsx(
150
+ CommandPrimitive.Separator,
151
+ __spreadValues({
152
+ ref,
153
+ className: cn("-mx-1 h-px bg-border", className)
154
+ }, props)
155
+ );
156
+ });
157
+ CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
158
+ var CommandItem = React.forwardRef((_a, ref) => {
159
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
160
+ return /* @__PURE__ */ jsx(
161
+ CommandPrimitive.Item,
162
+ __spreadValues({
163
+ ref,
164
+ className: cn(
165
+ "relative flex cursor-default select-none items-center rounded-sm text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
166
+ className
167
+ )
168
+ }, props)
169
+ );
170
+ });
171
+ CommandItem.displayName = CommandPrimitive.Item.displayName;
172
+ var CommandShortcut = (_a) => {
173
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
174
+ return /* @__PURE__ */ jsx(
175
+ "span",
176
+ __spreadValues({
177
+ className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className)
178
+ }, props)
179
+ );
180
+ };
181
+ CommandShortcut.displayName = "CommandShortcut";
182
+
183
+ // src/components/source-search-box/source-search-box.tsx
184
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
185
+ function SourceSearchBox(props) {
186
+ const [selectedValue, setSelectedValue] = useState("");
187
+ return /* @__PURE__ */ jsxs(
188
+ Command,
189
+ {
190
+ className: "rounded-lg border shadow-md",
191
+ value: selectedValue,
192
+ onValueChange: (value) => {
193
+ setSelectedValue(value);
194
+ },
195
+ filter: (value, search) => {
196
+ if (props.searchTerm === "")
197
+ return 1;
198
+ if (value.startsWith(props.searchTerm))
199
+ return 1;
200
+ return 0;
201
+ },
202
+ children: [
203
+ /* @__PURE__ */ jsx2(
204
+ CommandInput,
205
+ {
206
+ value: props.searchTerm,
207
+ className: "rounded-t-lg hidden",
208
+ placeholder: "Search for a command..."
209
+ }
210
+ ),
211
+ /* @__PURE__ */ jsxs(CommandList, { children: [
212
+ /* @__PURE__ */ jsx2(CommandEmpty, { children: "No results found." }),
213
+ /* @__PURE__ */ jsx2(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
214
+ return /* @__PURE__ */ jsx2(
215
+ CommandItem,
216
+ {
217
+ value: filePointer.name,
218
+ onSelect: (value) => {
219
+ props.onSelectedFile(filePointer);
220
+ },
221
+ children: /* @__PURE__ */ jsxs("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
222
+ /* @__PURE__ */ jsx2(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ jsx2(
223
+ "img",
224
+ {
225
+ src: filePointer.iconImageUri,
226
+ alt: filePointer.sourceApplication,
227
+ className: "w-full h-full"
228
+ }
229
+ ) }),
230
+ filePointer.name
231
+ ] })
232
+ },
233
+ `word-${filePointer.sourceApplication}.${filePointer.name}`
234
+ );
235
+ }) }),
236
+ /* @__PURE__ */ jsx2(CommandSeparator, {})
237
+ ] })
238
+ ]
239
+ }
240
+ );
241
+ }
242
+ function Logo({
243
+ children,
244
+ width,
245
+ height
246
+ }) {
247
+ return /* @__PURE__ */ jsx2("div", { className: "flex items-center justify-center", style: { width, height }, children });
248
+ }
249
+
250
+ // src/components/ui/button.tsx
251
+ import * as React2 from "react";
252
+ import { Slot } from "@radix-ui/react-slot";
253
+ import { cva } from "class-variance-authority";
254
+ import { jsx as jsx3 } from "react/jsx-runtime";
255
+ var buttonVariants = cva(
256
+ "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
257
+ {
258
+ variants: {
259
+ variant: {
260
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
261
+ destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
262
+ outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
263
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
264
+ ghost: "hover:bg-accent hover:text-accent-foreground",
265
+ link: "text-primary underline-offset-4 hover:underline"
266
+ },
267
+ size: {
268
+ default: "h-10 px-4 py-2",
269
+ sm: "h-9 rounded-md px-3",
270
+ lg: "h-11 rounded-md px-8",
271
+ icon: "h-10 w-10"
272
+ }
273
+ },
274
+ defaultVariants: {
275
+ variant: "default",
276
+ size: "default"
277
+ }
278
+ }
279
+ );
280
+ var Button = React2.forwardRef(
281
+ (_a, ref) => {
282
+ var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
283
+ const Comp = asChild ? Slot : "button";
284
+ return /* @__PURE__ */ jsx3(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
285
+ }
286
+ );
287
+ Button.displayName = "Button";
288
+
289
+ // src/components/ui/label.tsx
290
+ import * as React3 from "react";
291
+ import * as LabelPrimitive from "@radix-ui/react-label";
292
+ import { cva as cva2 } from "class-variance-authority";
293
+ import { jsx as jsx4 } from "react/jsx-runtime";
294
+ var labelVariants = cva2(
295
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
296
+ );
297
+ var Label = React3.forwardRef((_a, ref) => {
298
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
299
+ return /* @__PURE__ */ jsx4(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
300
+ });
301
+ Label.displayName = LabelPrimitive.Root.displayName;
302
+
303
+ // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
304
+ import { useCallback, useContext as useContext2, useEffect as useEffect2, useRef, useState as useState3 } from "react";
305
+
306
+ // src/lib/stream-promise-flatten.ts
307
+ function streamPromiseFlatten(promise) {
308
+ return new ReadableStream({
309
+ start(controller) {
310
+ return __async(this, null, function* () {
311
+ try {
312
+ const stream = yield promise;
313
+ const reader = stream.getReader();
314
+ while (true) {
315
+ const { done, value } = yield reader.read();
316
+ if (done) {
317
+ controller.close();
318
+ return;
319
+ }
320
+ controller.enqueue(value);
321
+ }
322
+ } catch (error) {
323
+ controller.error(error);
324
+ }
325
+ });
326
+ }
327
+ });
328
+ }
329
+
330
+ // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
331
+ import { CopilotContext } from "@copilotkit/react-core";
332
+
333
+ // src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx
334
+ import Chip from "@mui/material/Chip/Chip.js";
335
+ import Avatar from "@mui/material/Avatar/Avatar.js";
336
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
337
+ var IncludedFilesPreview = ({
338
+ includedFiles,
339
+ setIncludedFiles
340
+ }) => {
341
+ return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col gap-2 mt-2", children: [
342
+ /* @__PURE__ */ jsx5(Label, { className: "", children: "Included context:" }),
343
+ /* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
344
+ return /* @__PURE__ */ jsx5(
345
+ FileChipPreview,
346
+ {
347
+ filePointer,
348
+ onDelete: () => {
349
+ setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));
350
+ }
351
+ },
352
+ `file-${filePointer.sourceApplication}.${filePointer.name}`
353
+ );
354
+ }) })
355
+ ] });
356
+ };
357
+ var FileChipPreview = ({ filePointer, onDelete }) => {
358
+ return /* @__PURE__ */ jsx5(
359
+ Chip,
360
+ {
361
+ label: filePointer.name,
362
+ onDelete,
363
+ avatar: /* @__PURE__ */ jsx5(
364
+ Avatar,
365
+ {
366
+ src: filePointer.iconImageUri,
367
+ alt: filePointer.sourceApplication,
368
+ sx: { backgroundColor: "transparent" }
369
+ }
370
+ )
371
+ }
372
+ );
373
+ };
374
+
375
+ // src/components/hovering-toolbar/hovering-editor-provider.tsx
376
+ import { createContext, useState as useState2, useContext } from "react";
377
+ import { jsx as jsx6 } from "react/jsx-runtime";
378
+ var HoveringEditorContext = createContext({
379
+ isDisplayed: false,
380
+ setIsDisplayed: () => {
381
+ }
382
+ });
383
+ var useHoveringEditorContext = () => useContext(HoveringEditorContext);
384
+
385
+ // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
386
+ import { Fragment, jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
387
+ var HoveringInsertionPromptBoxCore = ({
388
+ performInsertion,
389
+ state,
390
+ insertionOrEditingFunction,
391
+ contextCategories
392
+ }) => {
393
+ const { getDocumentsContext } = useContext2(CopilotContext);
394
+ const [editSuggestion, setEditSuggestion] = useState3("");
395
+ const [suggestionIsLoading, setSuggestionIsLoading] = useState3(false);
396
+ const [adjustmentPrompt, setAdjustmentPrompt] = useState3("");
397
+ const [generatingSuggestion, setGeneratingSuggestion] = useState3(
398
+ null
399
+ );
400
+ const adjustmentTextAreaRef = useRef(null);
401
+ const suggestionTextAreaRef = useRef(null);
402
+ const [filePointers, setFilePointers] = useState3([]);
403
+ const [suggestedFiles, setSuggestedFiles] = useState3([]);
404
+ useEffect2(() => {
405
+ setSuggestedFiles(getDocumentsContext(contextCategories));
406
+ }, [contextCategories, getDocumentsContext]);
407
+ use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
408
+ use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
409
+ useEffect2(() => {
410
+ var _a;
411
+ (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
412
+ }, []);
413
+ useEffect2(() => {
414
+ if (!generatingSuggestion) {
415
+ return;
416
+ }
417
+ if (generatingSuggestion.locked) {
418
+ return;
419
+ }
420
+ setEditSuggestion("");
421
+ const reader = generatingSuggestion.getReader();
422
+ const read = () => __async(void 0, null, function* () {
423
+ setSuggestionIsLoading(true);
424
+ while (true) {
425
+ const { done, value } = yield reader.read();
426
+ if (done) {
427
+ break;
428
+ }
429
+ setEditSuggestion((prev) => {
430
+ const newSuggestion = prev + value;
431
+ if (suggestionTextAreaRef.current) {
432
+ suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
433
+ }
434
+ return newSuggestion;
435
+ });
436
+ }
437
+ setSuggestionIsLoading(false);
438
+ });
439
+ read();
440
+ return () => {
441
+ const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
442
+ try {
443
+ yield reader.closed;
444
+ } catch (e) {
445
+ reader.releaseLock();
446
+ }
447
+ });
448
+ releaseLockIfNotClosed();
449
+ };
450
+ }, [generatingSuggestion]);
451
+ const beginGeneratingAdjustment = useCallback(() => __async(void 0, null, function* () {
452
+ if (!adjustmentPrompt.trim()) {
453
+ return;
454
+ }
455
+ let modificationState = state.editorState;
456
+ if (editSuggestion !== "") {
457
+ modificationState.selectedText = editSuggestion;
458
+ }
459
+ const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
460
+ modificationState,
461
+ adjustmentPrompt,
462
+ filePointers,
463
+ new AbortController().signal
464
+ );
465
+ const adjustmentSuggestionTextStream = streamPromiseFlatten(
466
+ adjustmentSuggestionTextStreamPromise
467
+ );
468
+ setGeneratingSuggestion(adjustmentSuggestionTextStream);
469
+ }), [
470
+ adjustmentPrompt,
471
+ editSuggestion,
472
+ state.editorState,
473
+ insertionOrEditingFunction,
474
+ filePointers
475
+ ]);
476
+ const isLoading = suggestionIsLoading;
477
+ const textToEdit = editSuggestion || state.editorState.selectedText;
478
+ const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
479
+ const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
480
+ const { setIsDisplayed } = useHoveringEditorContext();
481
+ const AdjustmentPromptComponent = /* @__PURE__ */ jsxs3(Fragment, { children: [
482
+ /* @__PURE__ */ jsx7(Label, { className: "", children: adjustmentLabel }),
483
+ /* @__PURE__ */ jsxs3("div", { className: "relative w-full flex items-center", children: [
484
+ /* @__PURE__ */ jsx7(
485
+ "textarea",
486
+ {
487
+ disabled: suggestionIsLoading,
488
+ ref: adjustmentTextAreaRef,
489
+ value: adjustmentPrompt,
490
+ onChange: (e) => setAdjustmentPrompt(e.target.value),
491
+ onKeyDown: (e) => {
492
+ if (e.key === "Enter" && e.shiftKey) {
493
+ e.preventDefault();
494
+ setAdjustmentPrompt(adjustmentPrompt + "\n");
495
+ } else if (e.key === "Enter") {
496
+ e.preventDefault();
497
+ beginGeneratingAdjustment();
498
+ } else if (e.key == "Escape") {
499
+ e.preventDefault();
500
+ setIsDisplayed(false);
501
+ }
502
+ },
503
+ placeholder,
504
+ style: { minHeight: "3rem" },
505
+ className: "w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]",
506
+ rows: 1
507
+ }
508
+ ),
509
+ /* @__PURE__ */ jsx7(
510
+ "button",
511
+ {
512
+ onClick: beginGeneratingAdjustment,
513
+ className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
514
+ children: /* @__PURE__ */ jsx7("i", { className: "material-icons", children: "arrow_forward" })
515
+ }
516
+ )
517
+ ] })
518
+ ] });
519
+ const SuggestionComponent = /* @__PURE__ */ jsxs3(Fragment, { children: [
520
+ /* @__PURE__ */ jsxs3("div", { className: "flex justify-between items-end w-full", children: [
521
+ /* @__PURE__ */ jsx7(Label, { className: "mt-4", children: "Suggested:" }),
522
+ /* @__PURE__ */ jsx7("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ jsx7("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ jsx7(
523
+ "div",
524
+ {
525
+ className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
526
+ role: "status",
527
+ children: /* @__PURE__ */ jsx7("span", { className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]", children: "Loading..." })
528
+ }
529
+ ) }) })
530
+ ] }),
531
+ /* @__PURE__ */ jsx7(
532
+ "textarea",
533
+ {
534
+ ref: suggestionTextAreaRef,
535
+ value: editSuggestion,
536
+ disabled: suggestionIsLoading,
537
+ onChange: (e) => setEditSuggestion(e.target.value),
538
+ className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
539
+ style: { overflow: "auto", maxHeight: "10em" }
540
+ }
541
+ )
542
+ ] });
543
+ const SubmitComponent = /* @__PURE__ */ jsx7("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ jsxs3(
544
+ Button,
545
+ {
546
+ className: " bg-green-700 text-white",
547
+ onClick: () => {
548
+ performInsertion(editSuggestion);
549
+ },
550
+ children: [
551
+ "Insert ",
552
+ /* @__PURE__ */ jsx7("i", { className: "material-icons", children: "check" })
553
+ ]
554
+ }
555
+ ) });
556
+ const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
557
+ const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
558
+ return /* @__PURE__ */ jsxs3("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
559
+ AdjustmentPromptComponent,
560
+ filePointers.length > 0 && /* @__PURE__ */ jsx7(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
561
+ sourceSearchWord !== void 0 && /* @__PURE__ */ jsx7(
562
+ SourceSearchBox,
563
+ {
564
+ searchTerm: sourceSearchWord,
565
+ suggestedFiles,
566
+ onSelectedFile: (filePointer) => {
567
+ var _a;
568
+ setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), ""));
569
+ setFilePointers((prev) => [...prev, filePointer]);
570
+ (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
571
+ }
572
+ }
573
+ ),
574
+ generatingSuggestion ? SuggestionComponent : null,
575
+ generatingSuggestion ? SubmitComponent : null
576
+ ] });
577
+ };
578
+
579
+ // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
580
+ import { jsx as jsx8 } from "react/jsx-runtime";
581
+ var HoveringInsertionPromptBox = (props) => {
582
+ return /* @__PURE__ */ jsx8(
583
+ "div",
584
+ {
585
+ className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
586
+ style: { width: "35rem" },
587
+ children: /* @__PURE__ */ jsx8(
588
+ HoveringInsertionPromptBoxCore,
589
+ {
590
+ state: {
591
+ editorState: props.editorState
592
+ },
593
+ insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction,
594
+ performInsertion: props.performInsertion,
595
+ contextCategories: props.contextCategories
596
+ }
597
+ )
598
+ }
599
+ );
600
+ };
601
+
602
+ // src/components/hovering-toolbar/hovering-toolbar-components.tsx
603
+ import { css, cx } from "@emotion/css";
604
+ import React4 from "react";
605
+ import ReactDOM from "react-dom";
606
+ import { jsx as jsx9 } from "react/jsx-runtime";
607
+ var Button2 = React4.forwardRef(
608
+ (_a, ref) => {
609
+ var _b = _a, {
610
+ className,
611
+ active,
612
+ reversed
613
+ } = _b, props = __objRest(_b, [
614
+ "className",
615
+ "active",
616
+ "reversed"
617
+ ]);
618
+ return /* @__PURE__ */ jsx9(
619
+ "span",
620
+ __spreadProps(__spreadValues({}, props), {
621
+ ref,
622
+ className: cx(
623
+ className,
624
+ css`
625
+ cursor: pointer;
626
+ color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
627
+ `
628
+ )
629
+ })
630
+ );
631
+ }
632
+ );
633
+ var Icon = React4.forwardRef(
634
+ (_a, ref) => {
635
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
636
+ return /* @__PURE__ */ jsx9(
637
+ "span",
638
+ __spreadProps(__spreadValues({}, props), {
639
+ ref,
640
+ className: cx(
641
+ "material-icons",
642
+ className,
643
+ css`
644
+ font-size: 18px;
645
+ vertical-align: text-bottom;
646
+ `
647
+ )
648
+ })
649
+ );
650
+ }
651
+ );
652
+ var Menu = React4.forwardRef(
653
+ (_a, ref) => {
654
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
655
+ return /* @__PURE__ */ jsx9(
656
+ "div",
657
+ __spreadProps(__spreadValues({}, props), {
658
+ "data-test-id": "menu",
659
+ ref,
660
+ className: cx(
661
+ className,
662
+ css`
663
+ & > * {
664
+ display: inline-block;
665
+ }
666
+
667
+ & > * + * {
668
+ margin-left: 15px;
669
+ }
670
+ `
671
+ )
672
+ })
673
+ );
674
+ }
675
+ );
676
+ var Portal = ({ children }) => {
677
+ return typeof document === "object" ? ReactDOM.createPortal(children, document.body) : null;
678
+ };
679
+ var Toolbar = React4.forwardRef(
680
+ (_a, ref) => {
681
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
682
+ return /* @__PURE__ */ jsx9(
683
+ Menu,
684
+ __spreadProps(__spreadValues({}, props), {
685
+ ref,
686
+ className: cx(
687
+ className,
688
+ css`
689
+ position: relative;
690
+ padding: 1px 18px 17px;
691
+ margin: 0 -20px;
692
+ border-bottom: 2px solid #eee;
693
+ margin-bottom: 20px;
694
+ `
695
+ )
696
+ })
697
+ );
698
+ }
699
+ );
700
+
701
+ // src/lib/get-text-around-cursor.ts
702
+ import { Editor, Path, Range, Text, Element, Point } from "slate";
703
+ function getTextAroundSelection(editor) {
704
+ const { selection } = editor;
705
+ if (!selection) {
706
+ return null;
707
+ }
708
+ const wellOrderedSelection = wellOrderedRange(selection);
709
+ const beforeRange = {
710
+ anchor: Editor.start(editor, []),
711
+ focus: wellOrderedSelection.anchor
712
+ };
713
+ const afterRange = {
714
+ anchor: wellOrderedSelection.focus,
715
+ focus: Editor.end(editor, [])
716
+ };
717
+ const before = extractTextWithNewlines(editor, beforeRange);
718
+ const after = extractTextWithNewlines(editor, afterRange);
719
+ const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
720
+ return {
721
+ selection: wellOrderedSelection,
722
+ textBeforeCursor: before,
723
+ selectedText,
724
+ textAfterCursor: after
725
+ };
726
+ }
727
+ function getFullEditorTextWithNewlines(editor) {
728
+ const fullDocumentRange = {
729
+ anchor: Editor.start(editor, []),
730
+ focus: Editor.end(editor, [])
731
+ };
732
+ return extractTextWithNewlines(editor, fullDocumentRange);
733
+ }
734
+ function extractTextWithNewlines(editor, range) {
735
+ const voids = false;
736
+ const [start, end] = Range.edges(range);
737
+ let text = "";
738
+ let lastBlock = null;
739
+ for (const [node, path] of Editor.nodes(editor, {
740
+ at: range,
741
+ match: Text.isText,
742
+ voids
743
+ })) {
744
+ let t = node.text;
745
+ const [block] = Editor.above(editor, {
746
+ at: path,
747
+ match: (n) => Element.isElement(n) && n.type === "paragraph"
748
+ }) || [null];
749
+ if (lastBlock !== block && block) {
750
+ if (lastBlock) {
751
+ text += "\n";
752
+ }
753
+ lastBlock = block;
754
+ }
755
+ if (Path.equals(path, end.path)) {
756
+ t = t.slice(0, end.offset);
757
+ }
758
+ if (Path.equals(path, start.path)) {
759
+ t = t.slice(start.offset);
760
+ }
761
+ text += t;
762
+ }
763
+ return text;
764
+ }
765
+ function wellOrderedRange(range) {
766
+ const { anchor, focus } = range;
767
+ if (Point.isBefore(anchor, focus)) {
768
+ return range;
769
+ }
770
+ return {
771
+ anchor: focus,
772
+ focus: anchor
773
+ };
774
+ }
775
+
776
+ // src/components/hovering-toolbar/hovering-toolbar.tsx
777
+ import { jsx as jsx10 } from "react/jsx-runtime";
778
+ var HoveringToolbar = (props) => {
779
+ const ref = useRef2(null);
780
+ const editor = useSlate();
781
+ const selection = useSlateSelection();
782
+ const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
783
+ const [isClient, setIsClient] = useState4(false);
784
+ useEffect3(() => {
785
+ setIsClient(true);
786
+ }, []);
787
+ useEffect3(() => {
788
+ const el = ref.current;
789
+ const { selection: selection2 } = editor;
790
+ if (!el) {
791
+ return;
792
+ }
793
+ if (!selection2) {
794
+ el.removeAttribute("style");
795
+ return;
796
+ }
797
+ const domSelection = window.getSelection();
798
+ if (!domSelection || domSelection.rangeCount === 0) {
799
+ return;
800
+ }
801
+ const domRange = domSelection.getRangeAt(0);
802
+ const rect = domRange.getBoundingClientRect();
803
+ if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
804
+ return;
805
+ }
806
+ const minGapFromEdge = 60;
807
+ const verticalOffsetFromCorner = 35;
808
+ const horizontalOffsetFromCorner = 15;
809
+ let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
810
+ if (top < minGapFromEdge) {
811
+ top = rect.bottom + window.scrollY + minGapFromEdge;
812
+ } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
813
+ top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
814
+ }
815
+ let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
816
+ if (left < minGapFromEdge) {
817
+ left = minGapFromEdge;
818
+ } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
819
+ left = window.innerWidth - el.offsetWidth - minGapFromEdge;
820
+ }
821
+ el.style.opacity = "1";
822
+ el.style.top = `${top}px`;
823
+ el.style.left = `${left}px`;
824
+ });
825
+ useEffect3(() => {
826
+ const handleClickOutside = (event) => {
827
+ if (ref.current && !ref.current.contains(event.target)) {
828
+ setIsDisplayed(false);
829
+ }
830
+ };
831
+ document.addEventListener("mousedown", handleClickOutside);
832
+ return () => {
833
+ document.removeEventListener("mousedown", handleClickOutside);
834
+ };
835
+ }, [ref, setIsDisplayed]);
836
+ if (!isClient) {
837
+ return null;
838
+ }
839
+ return /* @__PURE__ */ jsx10(Portal, { children: /* @__PURE__ */ jsx10(
840
+ Menu,
841
+ {
842
+ ref,
843
+ className: props.hoverMenuClassname || "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700",
844
+ children: isDisplayed && selection && /* @__PURE__ */ jsx10(
845
+ HoveringInsertionPromptBox,
846
+ {
847
+ editorState: editorState(editor, selection),
848
+ apiConfig: props.apiConfig,
849
+ closeWindow: () => {
850
+ setIsDisplayed(false);
851
+ },
852
+ performInsertion: (insertedText) => {
853
+ console.log("inserted text", insertedText);
854
+ Transforms.delete(editor, { at: selection });
855
+ Transforms.insertText(editor, insertedText, {
856
+ at: selection
857
+ });
858
+ setIsDisplayed(false);
859
+ },
860
+ contextCategories: props.contextCategories
861
+ }
862
+ )
863
+ }
864
+ ) });
865
+ };
866
+ function editorState(editor, selection) {
867
+ const textAroundCursor = getTextAroundSelection(editor);
868
+ if (textAroundCursor) {
869
+ return textAroundCursor;
870
+ }
871
+ return {
872
+ textBeforeCursor: getFullEditorTextWithNewlines(editor),
873
+ textAfterCursor: "",
874
+ selectedText: ""
875
+ };
876
+ }
20
877
  export {
21
878
  HoveringToolbar
22
879
  };