@copilotkit/react-textarea 0.19.0 → 0.20.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 (94) hide show
  1. package/.turbo/turbo-build.log +79 -74
  2. package/CHANGELOG.md +18 -0
  3. package/dist/{chunk-3TK2VELX.mjs → chunk-34D4UIYX.mjs} +2 -2
  4. package/dist/{chunk-L6DZHWEL.mjs → chunk-463BFNUP.mjs} +10 -9
  5. package/dist/chunk-463BFNUP.mjs.map +1 -0
  6. package/dist/{chunk-QNJ6MXJ2.mjs → chunk-7JO276KU.mjs} +3 -3
  7. package/dist/{chunk-QNJ6MXJ2.mjs.map → chunk-7JO276KU.mjs.map} +1 -1
  8. package/dist/{chunk-HRTFMM7P.mjs → chunk-AXN37AHC.mjs} +6 -8
  9. package/dist/chunk-AXN37AHC.mjs.map +1 -0
  10. package/dist/{chunk-BBKDE7YT.mjs → chunk-F2TIBXML.mjs} +3 -3
  11. package/dist/{chunk-47JRPWI3.mjs → chunk-F4WZCQG6.mjs} +20 -53
  12. package/dist/chunk-F4WZCQG6.mjs.map +1 -0
  13. package/dist/{chunk-FN7GDKKG.mjs → chunk-GCMQHIRF.mjs} +1 -1
  14. package/dist/chunk-GCMQHIRF.mjs.map +1 -0
  15. package/dist/{chunk-OXPXFYUG.mjs → chunk-IBSJOQI7.mjs} +13 -7
  16. package/dist/chunk-IBSJOQI7.mjs.map +1 -0
  17. package/dist/{chunk-7QWJ3OV7.mjs → chunk-LRXRD5KU.mjs} +2 -2
  18. package/dist/{chunk-RDHPSSHJ.mjs → chunk-OM3Z4S4Y.mjs} +5 -5
  19. package/dist/{chunk-K2AVA67P.mjs → chunk-PPWNZF3T.mjs} +2 -2
  20. package/dist/chunk-PPWNZF3T.mjs.map +1 -0
  21. package/dist/{chunk-66BDXIX4.mjs → chunk-RR6OQGTI.mjs} +7 -9
  22. package/dist/chunk-RR6OQGTI.mjs.map +1 -0
  23. package/dist/chunk-TIBMW3DC.mjs +48 -0
  24. package/dist/chunk-TIBMW3DC.mjs.map +1 -0
  25. package/dist/{chunk-XA7M72ZO.mjs → chunk-WLPYYGES.mjs} +5 -2
  26. package/dist/chunk-WLPYYGES.mjs.map +1 -0
  27. package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +1 -0
  28. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +8 -7
  29. package/dist/components/copilot-textarea/copilot-textarea.d.ts +1 -0
  30. package/dist/components/copilot-textarea/copilot-textarea.mjs +14 -13
  31. package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +1 -0
  32. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +7 -6
  33. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +2 -12
  34. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +5 -4
  35. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +1 -0
  36. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +6 -5
  37. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +15 -0
  38. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +6 -0
  39. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -0
  40. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +1 -0
  41. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +6 -5
  42. package/dist/components/index.d.ts +1 -0
  43. package/dist/components/index.mjs +14 -13
  44. package/dist/components/source-search-box/source-search-box.d.ts +3 -2
  45. package/dist/components/source-search-box/source-search-box.mjs +2 -2
  46. package/dist/components/ui/command.mjs +1 -1
  47. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +1 -0
  48. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +1 -0
  49. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +4 -4
  50. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +1 -0
  51. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +4 -4
  52. package/dist/index.css +6 -7
  53. package/dist/index.css.map +1 -1
  54. package/dist/index.d.ts +1 -1
  55. package/dist/index.mjs +14 -13
  56. package/dist/lib/stream-promise-flatten.d.ts +9 -0
  57. package/dist/lib/stream-promise-flatten.mjs +1 -1
  58. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +1 -0
  59. package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +1 -0
  60. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +3 -3
  61. package/dist/types/autosuggestions-config/editing-api-config.mjs +1 -1
  62. package/dist/types/autosuggestions-config/index.d.ts +1 -1
  63. package/dist/types/autosuggestions-config/index.mjs +3 -3
  64. package/dist/types/autosuggestions-config/insertions-api-config.mjs +1 -1
  65. package/dist/types/base/autosuggestions-bare-function.d.ts +3 -1
  66. package/dist/types/base/base-autosuggestions-config.d.ts +1 -0
  67. package/dist/types/base/base-copilot-textarea-props.d.ts +1 -0
  68. package/dist/types/base/index.d.ts +1 -0
  69. package/dist/types/index.d.ts +1 -1
  70. package/dist/types/index.mjs +3 -3
  71. package/package.json +2 -2
  72. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +27 -62
  73. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +1 -1
  74. package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +54 -0
  75. package/src/components/source-search-box/source-search-box.tsx +9 -8
  76. package/src/components/ui/command.tsx +4 -1
  77. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +1 -1
  78. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +13 -3
  79. package/src/lib/stream-promise-flatten.ts +10 -0
  80. package/src/types/autosuggestions-config/editing-api-config.tsx +5 -7
  81. package/src/types/autosuggestions-config/insertions-api-config.tsx +6 -8
  82. package/src/types/base/autosuggestions-bare-function.ts +3 -0
  83. package/dist/chunk-47JRPWI3.mjs.map +0 -1
  84. package/dist/chunk-66BDXIX4.mjs.map +0 -1
  85. package/dist/chunk-FN7GDKKG.mjs.map +0 -1
  86. package/dist/chunk-HRTFMM7P.mjs.map +0 -1
  87. package/dist/chunk-K2AVA67P.mjs.map +0 -1
  88. package/dist/chunk-L6DZHWEL.mjs.map +0 -1
  89. package/dist/chunk-OXPXFYUG.mjs.map +0 -1
  90. package/dist/chunk-XA7M72ZO.mjs.map +0 -1
  91. /package/dist/{chunk-3TK2VELX.mjs.map → chunk-34D4UIYX.mjs.map} +0 -0
  92. /package/dist/{chunk-BBKDE7YT.mjs.map → chunk-F2TIBXML.mjs.map} +0 -0
  93. /package/dist/{chunk-7QWJ3OV7.mjs.map → chunk-LRXRD5KU.mjs.map} +0 -0
  94. /package/dist/{chunk-RDHPSSHJ.mjs.map → chunk-OM3Z4S4Y.mjs.map} +0 -0
@@ -1,6 +1,7 @@
1
1
  import { TextareaHTMLAttributes } from 'react';
2
2
  import { BaseAutosuggestionsConfig } from './base-autosuggestions-config.js';
3
3
  import { BaseCopilotTextareaApiConfig } from './autosuggestions-bare-function.js';
4
+ import '@copilotkit/react-core';
4
5
 
5
6
  /**
6
7
  * `BaseCopilotTextareaProps` defines the properties for the `BaseCopilotTextarea` component.
@@ -1,4 +1,5 @@
1
1
  export { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from './base-autosuggestions-config.js';
2
2
  export { AutosuggestionsBareFunction } from './autosuggestions-bare-function.js';
3
3
  export { BaseCopilotTextareaProps } from './base-copilot-textarea-props.js';
4
+ import '@copilotkit/react-core';
4
5
  import 'react';
@@ -7,8 +7,8 @@ export { MinimalChatGPTMessage } from './autosuggestions-config/subtypes/minimal
7
7
  export { MakeSystemPrompt } from './autosuggestions-config/subtypes/make-system-prompt.js';
8
8
  export { ChatlikeApiEndpoint, ChatlikeApiEndpointImpl } from './autosuggestions-config/subtypes/chatlike-api-endpoint.js';
9
9
  export { AutosuggestionsConfigUserSpecified, InsertionsApiConfigUserSpecified, SuggestionsApiConfigUserSpecified } from './autosuggestions-config/autosuggestions-config-user-specified.js';
10
+ import '@copilotkit/react-core';
10
11
  import 'react';
11
12
  import './autosuggestions-config/suggestions-api-config.js';
12
13
  import './autosuggestions-config/insertions-api-config.js';
13
14
  import './autosuggestions-config/editing-api-config.js';
14
- import '@copilotkit/react-core';
@@ -1,9 +1,9 @@
1
1
  import '../chunk-DE5K76I2.mjs';
2
2
  import '../chunk-5FO6ISW4.mjs';
3
3
  export { ChatlikeApiEndpoint } from '../chunk-KIRROE2K.mjs';
4
- export { defaultAutosuggestionsConfig } from '../chunk-BBKDE7YT.mjs';
5
- import '../chunk-HRTFMM7P.mjs';
6
- import '../chunk-66BDXIX4.mjs';
4
+ export { defaultAutosuggestionsConfig } from '../chunk-F2TIBXML.mjs';
5
+ import '../chunk-AXN37AHC.mjs';
6
+ import '../chunk-RR6OQGTI.mjs';
7
7
  import '../chunk-JHTAOLEW.mjs';
8
8
  import '../chunk-WADHCMPK.mjs';
9
9
  import '../chunk-WJHSY5T6.mjs';
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.19.0",
7
+ "version": "0.20.0",
8
8
  "sideEffects": [
9
9
  "**/*.css"
10
10
  ],
@@ -61,7 +61,7 @@
61
61
  "slate-history": "^0.93.0",
62
62
  "slate-react": "^0.98.1",
63
63
  "tailwind-merge": "^1.13.2",
64
- "@copilotkit/react-core": "0.8.0"
64
+ "@copilotkit/react-core": "0.10.0"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "tsup --treeshake",
@@ -8,12 +8,17 @@ import { SourceSearchBox } from "../../source-search-box/source-search-box";
8
8
  import { DocumentPointer } from "@copilotkit/react-core";
9
9
  import { Button } from "../../ui/button";
10
10
  import { Label } from "../../ui/label";
11
- import React, { useContext, useEffect, useRef, useState } from "react";
11
+ import React, {
12
+ useCallback,
13
+ useContext,
14
+ useEffect,
15
+ useRef,
16
+ useState,
17
+ } from "react";
12
18
 
13
- import Chip from "@mui/material/Chip";
14
- import Avatar from "@mui/material/Avatar";
15
19
  import { streamPromiseFlatten } from "../../../lib/stream-promise-flatten";
16
20
  import { CopilotContext } from "@copilotkit/react-core";
21
+ import { IncludedFilesPreview } from "./included-files-preview";
17
22
 
18
23
  export type SuggestionState = {
19
24
  editorState: EditingEditorState;
@@ -80,7 +85,6 @@ export const HoveringInsertionPromptBoxCore: React.FC<
80
85
 
81
86
  // read the generating suggestion stream and continuously update the edit suggestion
82
87
  const reader = generatingSuggestion.getReader();
83
-
84
88
  const read = async () => {
85
89
  setSuggestionIsLoading(true);
86
90
  while (true) {
@@ -105,6 +109,7 @@ export const HoveringInsertionPromptBoxCore: React.FC<
105
109
  read();
106
110
 
107
111
  return () => {
112
+ // release the lock if the reader is not closed on unmount
108
113
  const releaseLockIfNotClosed = async () => {
109
114
  try {
110
115
  await reader.closed;
@@ -117,22 +122,25 @@ export const HoveringInsertionPromptBoxCore: React.FC<
117
122
  };
118
123
  }, [generatingSuggestion]);
119
124
 
120
- // when the adjustment prompt changes, reset the edit suggestion
121
- const begingGeneratingAdjustment = async () => {
125
+ // generate an adjustment to the completed text, based on the adjustment prompt
126
+ const beginGeneratingAdjustment = useCallback(async () => {
122
127
  // don't generate text if the prompt is empty
123
128
  if (!adjustmentPrompt.trim()) {
124
129
  return;
125
130
  }
126
131
 
127
- // if the current edit suggestion is not empty, then use it as the selected text instead of the editor state's selected text
128
- let editorState = state.editorState;
132
+ // editor state includes the text being edited, and the text before/after the selection
133
+ // if the current edit suggestion is not empty, then use *it* as the "selected text" - instead of the editor state's selected text
134
+ let modificationState = state.editorState;
129
135
  if (editSuggestion !== "") {
130
- editorState.selectedText = editSuggestion;
136
+ modificationState.selectedText = editSuggestion;
131
137
  }
132
138
 
139
+ // generate the adjustment suggestion
133
140
  const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
134
- editorState,
141
+ modificationState,
135
142
  adjustmentPrompt,
143
+ filePointers,
136
144
  new AbortController().signal
137
145
  );
138
146
  const adjustmentSuggestionTextStream = streamPromiseFlatten(
@@ -140,7 +148,13 @@ export const HoveringInsertionPromptBoxCore: React.FC<
140
148
  );
141
149
 
142
150
  setGeneratingSuggestion(adjustmentSuggestionTextStream);
143
- };
151
+ }, [
152
+ adjustmentPrompt,
153
+ editSuggestion,
154
+ state.editorState,
155
+ insertionOrEditingFunction,
156
+ filePointers,
157
+ ]);
144
158
 
145
159
  const isLoading = suggestionIsLoading;
146
160
 
@@ -169,7 +183,7 @@ export const HoveringInsertionPromptBoxCore: React.FC<
169
183
  setAdjustmentPrompt(adjustmentPrompt + "\n");
170
184
  } else if (e.key === "Enter") {
171
185
  e.preventDefault();
172
- begingGeneratingAdjustment();
186
+ beginGeneratingAdjustment();
173
187
  }
174
188
  }}
175
189
  placeholder={placeholder}
@@ -178,7 +192,7 @@ export const HoveringInsertionPromptBoxCore: React.FC<
178
192
  rows={1}
179
193
  />
180
194
  <button
181
- onClick={begingGeneratingAdjustment}
195
+ onClick={beginGeneratingAdjustment}
182
196
  className="absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center"
183
197
  >
184
198
  <i className="material-icons">arrow_forward</i>
@@ -266,52 +280,3 @@ export const HoveringInsertionPromptBoxCore: React.FC<
266
280
  </div>
267
281
  );
268
282
  };
269
-
270
- interface IncludedFilesPreviewProps {
271
- includedFiles: DocumentPointer[];
272
- setIncludedFiles: React.Dispatch<React.SetStateAction<DocumentPointer[]>>;
273
- }
274
-
275
- export const IncludedFilesPreview: React.FC<IncludedFilesPreviewProps> = ({
276
- includedFiles,
277
- setIncludedFiles,
278
- }) => {
279
- return (
280
- <div className="flex flex-col gap-2 mt-2">
281
- <Label className="">Included context:</Label>
282
- <div className="flex flex-wrap gap-2">
283
- {includedFiles.map((filePointer, index) => {
284
- return (
285
- <FileChipPreview
286
- key={`file-${filePointer.sourceApplication}.${filePointer.name}`}
287
- filePointer={filePointer}
288
- onDelete={() => {
289
- setIncludedFiles((prev) =>
290
- prev.filter((fp) => fp !== filePointer)
291
- );
292
- }}
293
- />
294
- );
295
- })}
296
- </div>
297
- </div>
298
- );
299
- };
300
-
301
- export interface FileChipPreviewProp {
302
- filePointer: DocumentPointer;
303
- onDelete: () => void;
304
- }
305
-
306
- export const FileChipPreview: React.FC<FileChipPreviewProp> = ({
307
- filePointer,
308
- onDelete,
309
- }) => {
310
- return (
311
- <Chip
312
- label={filePointer.name}
313
- onDelete={onDelete}
314
- avatar={<Avatar sx={{ backgroundColor: "transparent" }}></Avatar>}
315
- />
316
- );
317
- };
@@ -23,8 +23,8 @@ export const HoveringInsertionPromptBox: React.FC<Props> = (props) => {
23
23
  state={{
24
24
  editorState: props.editorState,
25
25
  }}
26
- performInsertion={props.performInsertion}
27
26
  insertionOrEditingFunction={props.apiConfig.insertionOrEditingFunction}
27
+ performInsertion={props.performInsertion}
28
28
  contextCategories={props.contextCategories}
29
29
  />
30
30
  </div>
@@ -0,0 +1,54 @@
1
+ import { DocumentPointer } from "@copilotkit/react-core";
2
+ import { Label } from "../../ui/label";
3
+ import React from "react";
4
+ import Chip from "@mui/material/Chip";
5
+ import Avatar from "@mui/material/Avatar";
6
+
7
+ export interface IncludedFilesPreviewProps {
8
+ includedFiles: DocumentPointer[];
9
+ setIncludedFiles: React.Dispatch<React.SetStateAction<DocumentPointer[]>>;
10
+ }
11
+
12
+ export const IncludedFilesPreview: React.FC<IncludedFilesPreviewProps> = ({
13
+ includedFiles,
14
+ setIncludedFiles,
15
+ }) => {
16
+ return (
17
+ <div className="flex flex-col gap-2 mt-2">
18
+ <Label className="">Included context:</Label>
19
+ <div className="flex flex-wrap gap-2">
20
+ {includedFiles.map((filePointer, index) => {
21
+ return (
22
+ <FileChipPreview
23
+ key={`file-${filePointer.sourceApplication}.${filePointer.name}`}
24
+ filePointer={filePointer}
25
+ onDelete={() => {
26
+ setIncludedFiles((prev) =>
27
+ prev.filter((fp) => fp !== filePointer)
28
+ );
29
+ }}
30
+ />
31
+ );
32
+ })}
33
+ </div>
34
+ </div>
35
+ );
36
+ };
37
+
38
+ export interface FileChipPreviewProp {
39
+ filePointer: DocumentPointer;
40
+ onDelete: () => void;
41
+ }
42
+
43
+ export const FileChipPreview: React.FC<FileChipPreviewProp> = ({
44
+ filePointer,
45
+ onDelete,
46
+ }) => {
47
+ return (
48
+ <Chip
49
+ label={filePointer.name}
50
+ onDelete={onDelete}
51
+ avatar={<Avatar sx={{ backgroundColor: "transparent" }}></Avatar>}
52
+ />
53
+ );
54
+ };
@@ -67,13 +67,12 @@ export function SourceSearchBox(props: SourceSearchBoxProps) {
67
67
  props.onSelectedFile(filePointer);
68
68
  }}
69
69
  >
70
- <div className="flex flex-row gap-3 items-center">
71
- <Logo size="30px">
70
+ <div className=" px-3 flex flex-row gap-1 items-center">
71
+ <Logo width="20px" height="20px">
72
72
  <img
73
73
  src={filePointer.iconImageUri}
74
74
  alt={filePointer.sourceApplication}
75
- width={30}
76
- height={30}
75
+ className="w-full h-full"
77
76
  />
78
77
  </Logo>
79
78
  {filePointer.name}
@@ -110,15 +109,17 @@ export function SourceSearchBox(props: SourceSearchBoxProps) {
110
109
 
111
110
  export function Logo({
112
111
  children,
113
- size = "30px",
112
+ width,
113
+ height,
114
114
  }: {
115
115
  children: React.ReactNode;
116
- size?: string;
116
+ width: string;
117
+ height: string;
117
118
  }) {
118
119
  return (
119
120
  <div
120
- className="flex items-center justify-center bg-black"
121
- style={{ width: size, height: size }}
121
+ className="flex items-center justify-center"
122
+ style={{ width: width, height: height }}
122
123
  >
123
124
  {children}
124
125
  </div>
@@ -62,7 +62,10 @@ const CommandList = React.forwardRef<
62
62
  >(({ className, ...props }, ref) => (
63
63
  <CommandPrimitive.List
64
64
  ref={ref}
65
- className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
65
+ className={cn(
66
+ "max-h-[300px] overflow-y-auto overflow-x-hidden pb-2",
67
+ className
68
+ )}
66
69
  {...props}
67
70
  />
68
71
  ));
@@ -36,7 +36,7 @@ export function useMakeStandardAutosuggestionFunction(
36
36
  role: "system",
37
37
  content: apiConfig.makeSystemPrompt(
38
38
  textareaPurpose,
39
- getContextString(contextCategories)
39
+ getContextString([], contextCategories)
40
40
  ),
41
41
  },
42
42
  ...apiConfig.fewShotMessages,
@@ -10,6 +10,7 @@ import {
10
10
  } from "../../types/base/autosuggestions-bare-function";
11
11
  import { InsertionsApiConfig } from "../../types/autosuggestions-config/insertions-api-config";
12
12
  import { EditingApiConfig } from "../../types/autosuggestions-config/editing-api-config";
13
+ import { DocumentPointer } from "@copilotkit/react-core";
13
14
 
14
15
  /**
15
16
  * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
@@ -36,6 +37,7 @@ export function useMakeStandardInsertionOrEditingFunction(
36
37
  async (
37
38
  editorState: EditingEditorState,
38
39
  insertionPrompt: string,
40
+ documents: DocumentPointer[],
39
41
  abortSignal: AbortSignal
40
42
  ) => {
41
43
  const res = await retry(async () => {
@@ -44,7 +46,7 @@ export function useMakeStandardInsertionOrEditingFunction(
44
46
  role: "system",
45
47
  content: insertionApiConfig.makeSystemPrompt(
46
48
  textareaPurpose,
47
- getContextString(contextCategories)
49
+ getContextString(documents, contextCategories)
48
50
  ),
49
51
  },
50
52
  ...insertionApiConfig.fewShotMessages,
@@ -83,6 +85,7 @@ export function useMakeStandardInsertionOrEditingFunction(
83
85
  async (
84
86
  editorState: EditingEditorState,
85
87
  editingPrompt: string,
88
+ documents: DocumentPointer[],
86
89
  abortSignal: AbortSignal
87
90
  ) => {
88
91
  const res = await retry(async () => {
@@ -91,7 +94,7 @@ export function useMakeStandardInsertionOrEditingFunction(
91
94
  role: "system",
92
95
  content: editingApiConfig.makeSystemPrompt(
93
96
  textareaPurpose,
94
- getContextString(contextCategories)
97
+ getContextString(documents, contextCategories)
95
98
  ),
96
99
  },
97
100
  ...editingApiConfig.fewShotMessages,
@@ -135,16 +138,23 @@ export function useMakeStandardInsertionOrEditingFunction(
135
138
  async (
136
139
  editorState: EditingEditorState,
137
140
  insertionPrompt: string,
141
+ documents: DocumentPointer[],
138
142
  abortSignal: AbortSignal
139
143
  ) => {
140
144
  if (editorState.selectedText === "") {
141
145
  return await insertionFunction(
142
146
  editorState,
143
147
  insertionPrompt,
148
+ documents,
144
149
  abortSignal
145
150
  );
146
151
  } else {
147
- return await editingFunction(editorState, insertionPrompt, abortSignal);
152
+ return await editingFunction(
153
+ editorState,
154
+ insertionPrompt,
155
+ documents,
156
+ abortSignal
157
+ );
148
158
  }
149
159
  },
150
160
  [insertionFunction, editingFunction]
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Flatten a promise of a stream, into a stream.
3
+ *
4
+ * Useful because a stream already includes the notion of async value delivery,
5
+ * so it often makes sense to simply await the values rather than the generator of the values.
6
+ *
7
+ * @param {Promise<ReadableStream<A>>} promise - The promise to flatten.
8
+ * @returns {ReadableStream<A>} - The flattened stream.
9
+ */
10
+
1
11
  export function streamPromiseFlatten<A>(
2
12
  promise: Promise<ReadableStream<A>>
3
13
  ): ReadableStream<A> {
@@ -16,6 +16,11 @@ export const defaultEditingMakeSystemPrompt: MakeSystemPrompt = (
16
16
  The user is writing some text.
17
17
  The purpose is: \"${textareaPurpose}\"
18
18
 
19
+ The following external context is also provided. Use it to help you make better suggestions!!!
20
+ \`\`\`
21
+ ${contextString}
22
+ \`\`\`
23
+
19
24
  The user also provides you with a prompt for EDITING some text they are writing.
20
25
  Your job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.
21
26
 
@@ -28,13 +33,6 @@ The user will provide the following information; use this to infer the best rele
28
33
  <EditingPrompt>
29
34
 
30
35
  <YourEditSuggestion>
31
-
32
- If we need to add a whitespace character to the suggested edit text, make sure to explicitly add it in.
33
-
34
- The following external context is also provided. Use it to help you make better suggestions!!!
35
- \`\`\`
36
- ${contextString}
37
- \`\`\`
38
36
  `;
39
37
  };
40
38
 
@@ -16,9 +16,14 @@ export const defaultInsertionsMakeSystemPrompt: MakeSystemPrompt = (
16
16
  The user is writing some text.
17
17
  The purpose is: \"${textareaPurpose}\"
18
18
 
19
+ The following external context is also provided. Use it to help you make better suggestions!!!
20
+ \`\`\`
21
+ ${contextString}
22
+ \`\`\`
23
+
19
24
  The user also provides you with a prompt for INSERTIONS into the text they are writing.
20
25
  Your job is to come up with an INSERTION into the text that the user would like AS BEST YOU CAN.
21
- Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
26
+ Only insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.
22
27
 
23
28
  Adjust yourself to the user's style and implied intent.
24
29
 
@@ -27,13 +32,6 @@ The user will provide the text before and after the cursor, as well as the inser
27
32
  <TextBeforeCursor>
28
33
  <InsertionPrompt>
29
34
  <YourSuggestion>
30
-
31
- If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
32
-
33
- The following external context is also provided. Use it to help you make better suggestions!!!
34
- \`\`\`
35
- ${contextString}
36
- \`\`\`
37
35
  `;
38
36
  };
39
37
 
@@ -1,3 +1,5 @@
1
+ import { DocumentPointer } from "@copilotkit/react-core";
2
+
1
3
  export interface InsertionEditorState {
2
4
  textBeforeCursor: string;
3
5
  textAfterCursor: string;
@@ -15,6 +17,7 @@ export type AutosuggestionsBareFunction = (
15
17
  export type Generator_InsertionOrEditingSuggestion = (
16
18
  editorState: EditingEditorState,
17
19
  prompt: string,
20
+ documents: DocumentPointer[],
18
21
  abortSignal: AbortSignal
19
22
  ) => Promise<ReadableStream<string>>;
20
23
 
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAUA,SAAgB,YAAY,WAAW,QAA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AAQ,oBAAC;AAAA,MAAO,IAAI,EAAE,iBAAiB,cAAc;AAAA,KAAG;AAAA,GAC1D;AAEJ","sourcesContent":["import useAutosizeTextArea from \"../../../hooks/misc/use-autosize-textarea\";\nimport { MinimalChatGPTMessage } from \"../../../types\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n} from \"../../../types/base/autosuggestions-bare-function\";\nimport { SourceSearchBox } from \"../../source-search-box/source-search-box\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\nimport { Button } from \"../../ui/button\";\nimport { Label } from \"../../ui/label\";\nimport React, { useContext, useEffect, useRef, useState } from \"react\";\n\nimport Chip from \"@mui/material/Chip\";\nimport Avatar from \"@mui/material/Avatar\";\nimport { streamPromiseFlatten } from \"../../../lib/stream-promise-flatten\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\n\nexport type SuggestionState = {\n editorState: EditingEditorState;\n};\n\nexport interface HoveringInsertionPromptBoxCoreProps {\n state: SuggestionState;\n performInsertion: (insertedText: string) => void;\n insertionOrEditingFunction: Generator_InsertionOrEditingSuggestion;\n contextCategories: string[];\n}\n\nexport const HoveringInsertionPromptBoxCore: React.FC<\n HoveringInsertionPromptBoxCoreProps\n> = ({\n performInsertion,\n state,\n insertionOrEditingFunction,\n contextCategories,\n}) => {\n const { getDocumentsContext } = useContext(CopilotContext);\n\n const [editSuggestion, setEditSuggestion] = useState<string>(\"\");\n const [suggestionIsLoading, setSuggestionIsLoading] =\n useState<boolean>(false);\n\n const [adjustmentPrompt, setAdjustmentPrompt] = useState<string>(\"\");\n\n const [generatingSuggestion, setGeneratingSuggestion] =\n useState<ReadableStream<string> | null>(null);\n\n const adjustmentTextAreaRef = useRef<HTMLTextAreaElement>(null);\n const suggestionTextAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [filePointers, setFilePointers] = useState<DocumentPointer[]>([]);\n\n const [suggestedFiles, setSuggestedFiles] = useState<DocumentPointer[]>([]);\n useEffect(() => {\n setSuggestedFiles(getDocumentsContext(contextCategories));\n }, [contextCategories, getDocumentsContext]);\n\n useAutosizeTextArea(suggestionTextAreaRef, editSuggestion || \"\");\n useAutosizeTextArea(adjustmentTextAreaRef, adjustmentPrompt || \"\");\n\n // initially focus on the adjustment prompt text area\n useEffect(() => {\n adjustmentTextAreaRef.current?.focus();\n }, []);\n\n // continuously read the generating suggestion stream and update the edit suggestion\n useEffect(() => {\n // if no generating suggestion, do nothing\n if (!generatingSuggestion) {\n return;\n }\n\n // Check if the stream is already locked (i.e. already reading from it)\n if (generatingSuggestion.locked) {\n return;\n }\n\n // reset the edit suggestion\n setEditSuggestion(\"\");\n\n // read the generating suggestion stream and continuously update the edit suggestion\n const reader = generatingSuggestion.getReader();\n\n const read = async () => {\n setSuggestionIsLoading(true);\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n setEditSuggestion((prev) => {\n const newSuggestion = prev + value;\n\n // Scroll to the bottom of the textarea. We call this here to make sure scroll-to-bottom is synchronous with the state update.\n if (suggestionTextAreaRef.current) {\n suggestionTextAreaRef.current.scrollTop =\n suggestionTextAreaRef.current.scrollHeight;\n }\n return newSuggestion;\n });\n }\n\n setSuggestionIsLoading(false);\n };\n read();\n\n return () => {\n const releaseLockIfNotClosed = async () => {\n try {\n await reader.closed;\n } catch {\n reader.releaseLock();\n }\n };\n\n releaseLockIfNotClosed();\n };\n }, [generatingSuggestion]);\n\n // when the adjustment prompt changes, reset the edit suggestion\n const begingGeneratingAdjustment = async () => {\n // don't generate text if the prompt is empty\n if (!adjustmentPrompt.trim()) {\n return;\n }\n\n // if the current edit suggestion is not empty, then use it as the selected text instead of the editor state's selected text\n let editorState = state.editorState;\n if (editSuggestion !== \"\") {\n editorState.selectedText = editSuggestion;\n }\n\n const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(\n editorState,\n adjustmentPrompt,\n new AbortController().signal\n );\n const adjustmentSuggestionTextStream = streamPromiseFlatten(\n adjustmentSuggestionTextStreamPromise\n );\n\n setGeneratingSuggestion(adjustmentSuggestionTextStream);\n };\n\n const isLoading = suggestionIsLoading;\n\n const textToEdit = editSuggestion || state.editorState.selectedText;\n const adjustmentLabel =\n textToEdit === \"\"\n ? \"Describe the text you want to insert\"\n : \"Describe adjustments to the suggested text\";\n const placeholder =\n textToEdit === \"\"\n ? \"e.g. 'summarize the client's top 3 pain-points from @CallTranscript'\"\n : \"e.g. 'make it more formal', 'be more specific', ...\";\n\n const AdjustmentPromptComponent = (\n <>\n <Label className=\"\">{adjustmentLabel}</Label>\n <div className=\"relative w-full flex items-center\">\n <textarea\n disabled={suggestionIsLoading}\n ref={adjustmentTextAreaRef}\n value={adjustmentPrompt}\n onChange={(e) => setAdjustmentPrompt(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && e.shiftKey) {\n e.preventDefault();\n setAdjustmentPrompt(adjustmentPrompt + \"\\n\");\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n begingGeneratingAdjustment();\n }\n }}\n placeholder={placeholder}\n style={{ minHeight: \"3rem\" }}\n 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]\"\n rows={1}\n />\n <button\n onClick={begingGeneratingAdjustment}\n className=\"absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center\"\n >\n <i className=\"material-icons\">arrow_forward</i>\n </button>\n </div>\n </>\n );\n\n const SuggestionComponent = (\n <>\n <div className=\"flex justify-between items-end w-full\">\n <Label className=\"mt-4\">Suggested:</Label>\n <div className=\"ml-auto\">\n {isLoading && (\n <div className=\"flex justify-center items-center\">\n <div\n 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]\"\n role=\"status\"\n >\n <span className=\"!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]\">\n Loading...\n </span>\n </div>\n </div>\n )}\n </div>\n </div>\n <textarea\n ref={suggestionTextAreaRef}\n value={editSuggestion}\n disabled={suggestionIsLoading}\n onChange={(e) => setEditSuggestion(e.target.value)}\n className=\"w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50\"\n style={{ overflow: \"auto\", maxHeight: \"10em\" }}\n />\n </>\n );\n\n const SubmitComponent = (\n <div className=\"flex w-full gap-4 justify-start\">\n <Button\n className=\" bg-green-700 text-white\"\n onClick={() => {\n performInsertion(editSuggestion);\n }}\n >\n Insert <i className=\"material-icons\">check</i>\n </Button>\n </div>\n );\n\n // show source search if the last word in the adjustment prompt BEGINS with an @\n const sourceSearchCandidate = adjustmentPrompt.split(\" \").pop();\n // if the candidate is @someCandidate, then 'someCandidate', otherwise undefined\n const sourceSearchWord = sourceSearchCandidate?.startsWith(\"@\")\n ? sourceSearchCandidate.slice(1)\n : undefined;\n\n return (\n <div className=\"w-full flex flex-col items-start relative gap-2\">\n {AdjustmentPromptComponent}\n {filePointers.length > 0 && (\n <IncludedFilesPreview\n includedFiles={filePointers}\n setIncludedFiles={setFilePointers}\n />\n )}\n {sourceSearchWord !== undefined && (\n <SourceSearchBox\n searchTerm={sourceSearchWord}\n suggestedFiles={suggestedFiles}\n onSelectedFile={(filePointer) => {\n setAdjustmentPrompt(\n adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), \"\")\n );\n setFilePointers((prev) => [...prev, filePointer]);\n\n // focus back on the adjustment prompt, and move the cursor to the end\n adjustmentTextAreaRef.current?.focus();\n }}\n />\n )}\n {generatingSuggestion ? SuggestionComponent : null}\n {generatingSuggestion ? SubmitComponent : null}\n </div>\n );\n};\n\ninterface IncludedFilesPreviewProps {\n includedFiles: DocumentPointer[];\n setIncludedFiles: React.Dispatch<React.SetStateAction<DocumentPointer[]>>;\n}\n\nexport const IncludedFilesPreview: React.FC<IncludedFilesPreviewProps> = ({\n includedFiles,\n setIncludedFiles,\n}) => {\n return (\n <div className=\"flex flex-col gap-2 mt-2\">\n <Label className=\"\">Included context:</Label>\n <div className=\"flex flex-wrap gap-2\">\n {includedFiles.map((filePointer, index) => {\n return (\n <FileChipPreview\n key={`file-${filePointer.sourceApplication}.${filePointer.name}`}\n filePointer={filePointer}\n onDelete={() => {\n setIncludedFiles((prev) =>\n prev.filter((fp) => fp !== filePointer)\n );\n }}\n />\n );\n })}\n </div>\n </div>\n );\n};\n\nexport interface FileChipPreviewProp {\n filePointer: DocumentPointer;\n onDelete: () => void;\n}\n\nexport const FileChipPreview: React.FC<FileChipPreviewProp> = ({\n filePointer,\n onDelete,\n}) => {\n return (\n <Chip\n label={filePointer.name}\n onDelete={onDelete}\n avatar={<Avatar sx={{ backgroundColor: \"transparent\" }}></Avatar>}\n />\n );\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types/autosuggestions-config/insertions-api-config.tsx"],"names":[],"mappings":";AASO,IAAM,oCAAsD,CACjE,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBlB;AAAA;AAAA;AAGF;AAEO,IAAM,mCAA4D;AAAA,EACvE;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,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,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AAEO,IAAM,6BAAkD;AAAA,EAC7D,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB","sourcesContent":["import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface InsertionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultInsertionsMakeSystemPrompt: 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\nThe user also provides you with a prompt for INSERTIONS into the text they are writing. \nYour job is to come up with an INSERTION into the text that the user would like 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 the text before and after the cursor, as well as the insertion prompt. You should use this to infer the best relevant insertion.\n<TextAfterCursor>\n<TextBeforeCursor>\n<InsertionPrompt>\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 defaultInsertionsFewShotMessages: 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: \"user\",\n name: \"InsertionPrompt\",\n content: \"I bought a big watermelon\",\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: \"user\",\n name: \"InsertionPrompt\",\n content: \"add section about the optionholder's pro rata share\",\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 defaultInsertionsApiConfig: InsertionsApiConfig = {\n makeSystemPrompt: defaultInsertionsMakeSystemPrompt,\n fewShotMessages: defaultInsertionsFewShotMessages,\n forwardedParams: undefined,\n};\n"]}
@@ -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 +0,0 @@
1
- {"version":3,"sources":["../src/types/autosuggestions-config/editing-api-config.tsx"],"names":[],"mappings":";AASO,IAAM,iCAAmD,CAC9D,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBlB;AAAA;AAAA;AAGF;AAEO,IAAM,gCAAyD;AAAA,EACpE;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;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,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,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AAEO,IAAM,0BAA4C;AAAA,EACvD,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB","sourcesContent":["import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface EditingApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultEditingMakeSystemPrompt: 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\nThe user also provides you with a prompt for EDITING some text they are writing. \nYour job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide the following information; use this to infer the best relevant EDIT:\n<TextBeforeCursor>\n<TextToEdit>\n<TextAfterCursor>\n<EditingPrompt>\n\n<YourEditSuggestion>\n\nIf we need to add a whitespace character to the suggested edit 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 defaultEditingFewShotMessages: MinimalChatGPTMessage[] = [\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: \"user\",\n name: \"TextToEdit\",\n content:\n \"While I was there I also picked up some apples, oranges, and bananas. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"The grocery store was having a sale on fruit, so I decided to stock up.\",\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: \"I bought a big watermelon\",\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: \"user\",\n name: \"InsertionPrompt\",\n content: \"add section about the optionholder's pro rata share\",\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 defaultEditingApiConfig: EditingApiConfig = {\n makeSystemPrompt: defaultEditingMakeSystemPrompt,\n fewShotMessages: defaultEditingFewShotMessages,\n forwardedParams: undefined,\n};\n"]}
@@ -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;AAsBjC,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,WAAW,cAAc;AAExE,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,cACJ,oBAAoB,qBAAqB,gBAAgB;AAC3D,cAAM,SAAS,MAAM,YAAY;AAAA,UAC/B;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 ChatlikeApiEndpoint,\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, copilotApiConfig } = 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 apiEndpoint =\n ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);\n const stream = await 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 +0,0 @@
1
- {"version":3,"sources":["../src/components/source-search-box/source-search-box.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,SAAS,gBAAgB;AAmDnB,cAkBU,YAlBV;AArBC,SAAS,gBAAgB,OAA6B;AAC3D,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAiB,EAAE;AAE7D,SACE,qBAAC;AAAA,IACC,WAAU;AAAA,IACV,OAAO;AAAA,IACP,eAAe,CAAC,UAAU;AACxB,uBAAiB,KAAK;AAAA,IACxB;AAAA,IACA,QAAQ,CAAC,OAAO,WAAW;AAEzB,UAAI,MAAM,eAAe;AAAI,eAAO;AAGpC,UAAI,MAAM,WAAW,MAAM,UAAU;AAAG,eAAO;AAG/C,aAAO;AAAA,IACT;AAAA,IAEA;AAAA,0BAAC;AAAA,QACC,OAAO,MAAM;AAAA,QACb,WAAU;AAAA,QACV,aAAY;AAAA,OACd;AAAA,MACA,qBAAC;AAAA,QACC;AAAA,8BAAC;AAAA,YAAa;AAAA,WAAiB;AAAA,UAE/B,oBAAC;AAAA,YAAa,SAAQ;AAAA,YACnB,gBAAM,eAAe,IAAI,CAAC,gBAAgB;AACzC,qBACE,oBAAC;AAAA,gBAEC,OAAO,YAAY;AAAA,gBACnB,UAAU,CAAC,UAAU;AACnB,wBAAM,eAAe,WAAW;AAAA,gBAClC;AAAA,gBAEA,+BAAC;AAAA,kBAAI,WAAU;AAAA,kBACb;AAAA,wCAAC;AAAA,sBAAK,MAAK;AAAA,sBACT,8BAAC;AAAA,wBACC,KAAK,YAAY;AAAA,wBACjB,KAAK,YAAY;AAAA,wBACjB,OAAO;AAAA,wBACP,QAAQ;AAAA,uBACV;AAAA,qBACF;AAAA,oBACC,YAAY;AAAA;AAAA,iBACf;AAAA,iBAhBK,QAAQ,YAAY,qBAAqB,YAAY,MAiB5D;AAAA,YAEJ,CAAC;AAAA,WACH;AAAA,UAqBA,oBAAC,oBAAiB;AAAA;AAAA,OACpB;AAAA;AAAA,GACF;AAEJ;AAEO,SAAS,KAAK;AAAA,EACnB;AAAA,EACA,OAAO;AACT,GAGG;AACD,SACE,oBAAC;AAAA,IACC,WAAU;AAAA,IACV,OAAO,EAAE,OAAO,MAAM,QAAQ,KAAK;AAAA,IAElC;AAAA,GACH;AAEJ","sourcesContent":["import { useState } from \"react\";\nimport {\n Command,\n CommandDialog,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n CommandSeparator,\n CommandShortcut,\n} from \"../ui/command\";\n\nimport {\n Calculator,\n Calendar,\n CreditCard,\n Settings,\n Smile,\n User,\n} from \"lucide-react\";\n\nimport { DocumentPointer } from \"@copilotkit/react-core\";\n\nexport interface SourceSearchBoxProps {\n searchTerm: string;\n suggestedFiles: DocumentPointer[];\n onSelectedFile: (filePointer: DocumentPointer) => void;\n}\n\nexport function SourceSearchBox(props: SourceSearchBoxProps) {\n const [selectedValue, setSelectedValue] = useState<string>(\"\");\n\n return (\n <Command\n className=\"rounded-lg border shadow-md\"\n value={selectedValue}\n onValueChange={(value) => {\n setSelectedValue(value);\n }}\n filter={(value, search) => {\n // if the search term is empty, show all commands\n if (props.searchTerm === \"\") return 1;\n\n // if the search term is a prefix of the command, show it\n if (value.startsWith(props.searchTerm)) return 1;\n\n // otherwise, don't show it\n return 0;\n }}\n >\n <CommandInput\n value={props.searchTerm}\n className=\"rounded-t-lg hidden\"\n placeholder=\"Search for a command...\"\n />\n <CommandList>\n <CommandEmpty>No results found.</CommandEmpty>\n\n <CommandGroup heading=\"Available resources\">\n {props.suggestedFiles.map((filePointer) => {\n return (\n <CommandItem\n key={`word-${filePointer.sourceApplication}.${filePointer.name}`}\n value={filePointer.name}\n onSelect={(value) => {\n props.onSelectedFile(filePointer);\n }}\n >\n <div className=\"flex flex-row gap-3 items-center\">\n <Logo size=\"30px\">\n <img\n src={filePointer.iconImageUri}\n alt={filePointer.sourceApplication}\n width={30}\n height={30}\n />\n </Logo>\n {filePointer.name}\n </div>\n </CommandItem>\n );\n })}\n </CommandGroup>\n\n {/* <CommandGroup heading=\"Suggestions\">\n <CommandItem\n onSelect={(value) => {\n console.log(value);\n console.log(value);\n }}\n >\n <Calendar className=\"mr-2 h-4 w-4\" />\n <span>Calendar</span>\n </CommandItem>\n <CommandItem>\n <Smile className=\"mr-2 h-4 w-4\" />\n <span>Search Emoji</span>\n </CommandItem>\n <CommandItem>\n <Calculator className=\"mr-2 h-4 w-4\" />\n <span>Calculator</span>\n </CommandItem>\n </CommandGroup> */}\n <CommandSeparator />\n </CommandList>\n </Command>\n );\n}\n\nexport function Logo({\n children,\n size = \"30px\",\n}: {\n children: React.ReactNode;\n size?: string;\n}) {\n return (\n <div\n className=\"flex items-center justify-center bg-black\"\n style={{ width: size, height: size }}\n >\n {children}\n </div>\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AAyBjC,SAAS,0CACd,iBACA,mBACA,oBACA,kBACwC;AACxC,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,WAAW,cAAc;AAExE,QAAM,oBAAoB;AAAA,IACxB,CACE,aACA,iBACA,g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A,QACF;AAEA,cAAM,cACJ,oBAAoB,qBAAqB,gBAAgB;AAC3D,eAAO,MAAM,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,UACA,iBAAiB;AAAA,QACnB;AAAA,MACF,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,kBAAkB,kBAAkB,mBAAmB,eAAe;AAAA,EACzE;AAEA,QAAM,6BAA6B;AAAA,IACjC,CACE,aACA,iBACA,gBACG;AACH,UAAI,YAAY,iBAAiB,IAAI;AACnC,eAAO,MAAM;AAAA,UACX;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,OAAO;AACL,eAAO,MAAM,gBAAgB,aAAa,iBAAiB,WAAW;AAAA,MACxE;AAAA,IACF;AAAA,IACA,CAAC,mBAAmB,eAAe;AAAA,EACrC;AAEA,SAAO;AACT","sourcesContent":["import { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { ChatlikeApiEndpoint, MinimalChatGPTMessage } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n InsertionEditorApiConfig,\n InsertionEditorState,\n} from \"../../types/base/autosuggestions-bare-function\";\nimport { InsertionsApiConfig } from \"../../types/autosuggestions-config/insertions-api-config\";\nimport { EditingApiConfig } from \"../../types/autosuggestions-config/editing-api-config\";\n\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 useMakeStandardInsertionOrEditingFunction(\n textareaPurpose: string,\n contextCategories: string[] | undefined,\n insertionApiConfig: InsertionsApiConfig,\n editingApiConfig: EditingApiConfig\n): Generator_InsertionOrEditingSuggestion {\n const { getContextString, copilotApiConfig } = useContext(CopilotContext);\n\n const insertionFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n abortSignal: AbortSignal\n ) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: insertionApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(contextCategories)\n ),\n },\n ...insertionApiConfig.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 role: \"user\",\n name: \"InsertionPrompt\",\n content: insertionPrompt,\n },\n ];\n\n const apiEndpoint =\n ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);\n return await apiEndpoint.run(\n abortSignal,\n messages,\n insertionApiConfig.forwardedParams\n );\n });\n\n return res;\n },\n [insertionApiConfig, getContextString, contextCategories, textareaPurpose]\n );\n\n const editingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n editingPrompt: string,\n abortSignal: AbortSignal\n ) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: editingApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(contextCategories)\n ),\n },\n ...editingApiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: editorState.selectedText,\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: editingPrompt,\n },\n ];\n\n const apiEndpoint =\n ChatlikeApiEndpoint.fromCopilotApiConfig(copilotApiConfig);\n return await apiEndpoint.run(\n abortSignal,\n messages,\n editingApiConfig.forwardedParams\n );\n });\n\n return res;\n },\n [editingApiConfig, getContextString, contextCategories, textareaPurpose]\n );\n\n const insertionOrEditingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n abortSignal: AbortSignal\n ) => {\n if (editorState.selectedText === \"\") {\n return await insertionFunction(\n editorState,\n insertionPrompt,\n abortSignal\n );\n } else {\n return await editingFunction(editorState, insertionPrompt, abortSignal);\n }\n },\n [insertionFunction, editingFunction]\n );\n\n return insertionOrEditingFunction;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/ui/command.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,YAAY,WAAW;AAEvB,SAAS,WAAW,wBAAwB;AAU1C;AAdF;AAUA,IAAM,UAAgB,iBAGpB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YAbL,IAaG,IAAgB,kBAAhB,IAAgB,CAAd;AACH,6BAAC;AAAA,IACC;AAAA,IACA,WAAW;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,KACI,MACN;AAAA,CACD;AACD,QAAQ,cAAc,iBAAiB;AAIvC,IAAM,gBAAgB,CAAC,OAA+C;AAA/C,eAAE,WA3BzB,IA2BuB,IAAe,kBAAf,IAAe,CAAb;AACvB,SACE,oBAAC,yCAAW,QAAX;AAAA,IACC,8BAAC;AAAA,MAAc,WAAU;AAAA,MACvB,8BAAC;AAAA,QAAQ,WAAU;AAAA,QAChB;AAAA,OACH;AAAA,KACF;AAAA,IACF;AAEJ;AAEA,IAAM,eAAqB,iBAGzB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YA1CL,IA0CG,IAAgB,kBAAhB,IAAgB,CAAd;AACH,6BAAC;AAAA,IAAI,WAAU;AAAA,IAAkC,sBAAmB;AAAA,IAElE,8BAAC,iBAAiB,OAAjB;AAAA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cAAc,iBAAiB,KAAK;AAEhD,IAAM,kBAAkB,CAAC,OAGoB;AAHpB,eACvB;AAAA;AAAA,EAjIF,IAgIyB,IAEpB,kBAFoB,IAEpB;AAAA,IADH;AAAA;AAGA,SACE,oBAAC;AAAA,IACC,WAAW;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,KACI,MACN;AAEJ;AACA,gBAAgB,cAAc","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { DialogProps } from \"@radix-ui/react-dialog\";\nimport { Command as CommandPrimitive } from \"cmdk\";\nimport { Search } from \"lucide-react\";\n\nimport { cn } from \"../../lib/utils\";\nimport { Dialog, DialogContent } from \"./dialog\";\n\nconst Command = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive\n ref={ref}\n className={cn(\n \"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground\",\n className\n )}\n {...props}\n />\n));\nCommand.displayName = CommandPrimitive.displayName;\n\ninterface CommandDialogProps extends DialogProps {}\n\nconst CommandDialog = ({ children, ...props }: CommandDialogProps) => {\n return (\n <Dialog {...props}>\n <DialogContent className=\"overflow-hidden p-0 shadow-lg\">\n <Command className=\"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5\">\n {children}\n </Command>\n </DialogContent>\n </Dialog>\n );\n};\n\nconst CommandInput = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Input>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>\n>(({ className, ...props }, ref) => (\n <div className=\"flex items-center border-b px-3\" cmdk-input-wrapper=\"\">\n {/* <Search className=\"mr-2 h-4 w-4 shrink-0 opacity-50\" /> */}\n <CommandPrimitive.Input\n ref={ref}\n className={cn(\n \"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\",\n className\n )}\n {...props}\n />\n </div>\n));\n\nCommandInput.displayName = CommandPrimitive.Input.displayName;\n\nconst CommandList = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.List>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.List\n ref={ref}\n className={cn(\"max-h-[300px] overflow-y-auto overflow-x-hidden\", className)}\n {...props}\n />\n));\n\nCommandList.displayName = CommandPrimitive.List.displayName;\n\nconst CommandEmpty = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Empty>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>\n>((props, ref) => (\n <CommandPrimitive.Empty\n ref={ref}\n className=\"py-6 text-center text-sm\"\n {...props}\n />\n));\n\nCommandEmpty.displayName = CommandPrimitive.Empty.displayName;\n\nconst CommandGroup = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Group>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Group\n ref={ref}\n className={cn(\n \"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\",\n className\n )}\n {...props}\n />\n));\n\nCommandGroup.displayName = CommandPrimitive.Group.displayName;\n\nconst CommandSeparator = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Separator\n ref={ref}\n className={cn(\"-mx-1 h-px bg-border\", className)}\n {...props}\n />\n));\nCommandSeparator.displayName = CommandPrimitive.Separator.displayName;\n\nconst CommandItem = React.forwardRef<\n React.ElementRef<typeof CommandPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>\n>(({ className, ...props }, ref) => (\n <CommandPrimitive.Item\n ref={ref}\n className={cn(\n \"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\",\n className\n )}\n {...props}\n />\n));\n\nCommandItem.displayName = CommandPrimitive.Item.displayName;\n\nconst CommandShortcut = ({\n className,\n ...props\n}: React.HTMLAttributes<HTMLSpanElement>) => {\n return (\n <span\n className={cn(\n \"ml-auto text-xs tracking-widest text-muted-foreground\",\n className\n )}\n {...props}\n />\n );\n};\nCommandShortcut.displayName = \"CommandShortcut\";\n\nexport {\n Command,\n CommandDialog,\n CommandInput,\n CommandList,\n CommandEmpty,\n CommandGroup,\n CommandItem,\n CommandShortcut,\n CommandSeparator,\n};\n"]}