@copilotkit/react-ui 0.6.0 → 0.8.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 (79) hide show
  1. package/.turbo/turbo-build.log +190 -206
  2. package/.turbo/turbo-check-types.log +4 -0
  3. package/CHANGELOG.md +17 -0
  4. package/dist/{chunk-YYTSYGAK.mjs → chunk-5IXZ2JCW.mjs} +4 -4
  5. package/dist/{chunk-D5X3GP4X.mjs → chunk-6UJWRTL6.mjs} +3 -3
  6. package/dist/chunk-7NSRDJ5C.mjs +3 -0
  7. package/dist/{chunk-YFUU7ZSS.mjs → chunk-CDAL5LKV.mjs} +2 -2
  8. package/dist/{chunk-NQOAC4FX.mjs → chunk-G6R4HFOE.mjs} +3 -3
  9. package/dist/{chunk-UFPPHGR2.mjs → chunk-JUPNM7ZR.mjs} +3 -3
  10. package/dist/{chunk-LWCPZL5R.mjs → chunk-KU35CEEC.mjs} +3 -3
  11. package/dist/{chunk-LBR74SDK.mjs → chunk-RVWZKSLL.mjs} +2 -2
  12. package/dist/chunk-U6NJWGTV.mjs +3 -0
  13. package/dist/{chunk-LED2SG5O.mjs → chunk-VQNV2DHJ.mjs} +2 -2
  14. package/dist/{chunk-M5HEMJBX.mjs → chunk-VSNDSL6W.mjs} +2 -2
  15. package/dist/{chunk-OXVWERJ3.mjs → chunk-XYAE5ALV.mjs} +2 -2
  16. package/dist/components/chat-components/chat-list.mjs +6 -6
  17. package/dist/components/chat-components/chat-message-actions.mjs +3 -3
  18. package/dist/components/chat-components/chat-message.mjs +5 -5
  19. package/dist/components/chat-components/chat-panel.mjs +4 -4
  20. package/dist/components/chat-components/clear-history.mjs +1 -1
  21. package/dist/components/chat-components/copilot-chat.mjs +11 -11
  22. package/dist/components/chat-components/default-empty-screen.mjs +2 -2
  23. package/dist/components/chat-components/prompt-form.mjs +3 -3
  24. package/dist/components/chat-components/theme-toggle.mjs +1 -1
  25. package/dist/components/chat-components/ui/codeblock.mjs +3 -3
  26. package/dist/components/index.d.ts +0 -4
  27. package/dist/components/index.mjs +14 -17
  28. package/dist/components/sidebar/copilot-sidebar-ui-provider.mjs +13 -13
  29. package/dist/components/sidebar/copilot-sidebar.mjs +12 -12
  30. package/dist/index.d.ts +0 -4
  31. package/dist/index.mjs +15 -18
  32. package/dist/lib/utils.test.d.ts +1 -0
  33. package/dist/lib/utils.test.mjs +8 -0
  34. package/dist/lib/utils.test.mjs.map +1 -0
  35. package/dist/types/index.d.ts +1 -3
  36. package/dist/types/index.mjs +1 -3
  37. package/jest.config.js +5 -0
  38. package/package.json +8 -5
  39. package/src/components/index.ts +0 -3
  40. package/src/lib/utils.test.ts +7 -0
  41. package/src/types/index.ts +1 -10
  42. package/tsconfig.json +8 -1
  43. package/tsup.config.ts +5 -0
  44. package/dist/chunk-3PTUDEHX.mjs +0 -67
  45. package/dist/chunk-3PTUDEHX.mjs.map +0 -1
  46. package/dist/chunk-CNTO7ZIR.mjs +0 -25
  47. package/dist/chunk-CNTO7ZIR.mjs.map +0 -1
  48. package/dist/chunk-E2RQC2ZD.mjs +0 -68
  49. package/dist/chunk-E2RQC2ZD.mjs.map +0 -1
  50. package/dist/chunk-FZRTAML3.mjs +0 -3
  51. package/dist/chunk-YPBKY4KY.mjs +0 -3
  52. package/dist/components/copilot-textarea/copilot-textarea.d.ts +0 -12
  53. package/dist/components/copilot-textarea/copilot-textarea.mjs +0 -6
  54. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +0 -1
  55. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +0 -22
  56. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +0 -4
  57. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +0 -1
  58. package/dist/types/autosuggestions-config.d.ts +0 -18
  59. package/dist/types/autosuggestions-config.mjs +0 -4
  60. package/dist/types/autosuggestions-config.mjs.map +0 -1
  61. package/dist/types/minimal-chatgpt-message.d.ts +0 -7
  62. package/dist/types/minimal-chatgpt-message.mjs +0 -3
  63. package/dist/types/minimal-chatgpt-message.mjs.map +0 -1
  64. package/src/components/copilot-textarea/copilot-textarea.tsx +0 -40
  65. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +0 -100
  66. package/src/types/autosuggestions-config.tsx +0 -94
  67. package/src/types/minimal-chatgpt-message.tsx +0 -5
  68. /package/dist/{chunk-YYTSYGAK.mjs.map → chunk-5IXZ2JCW.mjs.map} +0 -0
  69. /package/dist/{chunk-D5X3GP4X.mjs.map → chunk-6UJWRTL6.mjs.map} +0 -0
  70. /package/dist/{chunk-FZRTAML3.mjs.map → chunk-7NSRDJ5C.mjs.map} +0 -0
  71. /package/dist/{chunk-YFUU7ZSS.mjs.map → chunk-CDAL5LKV.mjs.map} +0 -0
  72. /package/dist/{chunk-NQOAC4FX.mjs.map → chunk-G6R4HFOE.mjs.map} +0 -0
  73. /package/dist/{chunk-UFPPHGR2.mjs.map → chunk-JUPNM7ZR.mjs.map} +0 -0
  74. /package/dist/{chunk-LWCPZL5R.mjs.map → chunk-KU35CEEC.mjs.map} +0 -0
  75. /package/dist/{chunk-LBR74SDK.mjs.map → chunk-RVWZKSLL.mjs.map} +0 -0
  76. /package/dist/{chunk-YPBKY4KY.mjs.map → chunk-U6NJWGTV.mjs.map} +0 -0
  77. /package/dist/{chunk-LED2SG5O.mjs.map → chunk-VQNV2DHJ.mjs.map} +0 -0
  78. /package/dist/{chunk-M5HEMJBX.mjs.map → chunk-VSNDSL6W.mjs.map} +0 -0
  79. /package/dist/{chunk-OXVWERJ3.mjs.map → chunk-XYAE5ALV.mjs.map} +0 -0
@@ -1,25 +0,0 @@
1
- import { useMakeStandardAutosuggestionFunction } from './chunk-3PTUDEHX.mjs';
2
- import { defaultAutosuggestionsConfig } from './chunk-E2RQC2ZD.mjs';
3
- import { __spreadValues, __spreadProps } from './chunk-MRXNTQOX.mjs';
4
- import { BaseCopilotTextarea } from '@copilotkit/react-textarea';
5
- import { jsx } from 'react/jsx-runtime';
6
-
7
- function CopilotTextarea(props) {
8
- const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultAutosuggestionsConfig), props.autosuggestionsConfig);
9
- const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(
10
- autosuggestionsConfig.purposePrompt,
11
- autosuggestionsConfig.apiEndpoint,
12
- autosuggestionsConfig.makeSystemPrompt,
13
- autosuggestionsConfig.fewShotMessages,
14
- autosuggestionsConfig.externalContextCategories,
15
- autosuggestionsConfig.forwardedParams
16
- );
17
- return /* @__PURE__ */ jsx(BaseCopilotTextarea, __spreadProps(__spreadValues({}, props), {
18
- autosuggestionsConfig,
19
- autosuggestionsFunction
20
- }));
21
- }
22
-
23
- export { CopilotTextarea };
24
- //# sourceMappingURL=out.js.map
25
- //# sourceMappingURL=chunk-CNTO7ZIR.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/copilot-textarea/copilot-textarea.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAMA;AAAA,EACE;AAAA,OAEK;AAwBH;AAhBG,SAAS,gBAAgB,OAA0C;AACxE,QAAM,wBAA+C,kCAChD,+BACA,MAAM;AAGX,QAAM,0BAA0B;AAAA,IAC9B,sBAAsB;AAAA,IACtB,sBAAsB;AAAA,IACtB,sBAAsB;AAAA,IACtB,sBAAsB;AAAA,IACtB,sBAAsB;AAAA,IACtB,sBAAsB;AAAA,EACxB;AAEA,SACE,oBAAC,sDACK,QADL;AAAA,IAEC;AAAA,IACA;AAAA,IACF;AAEJ","sourcesContent":["// This example is for an Editor with `ReactEditor` and `HistoryEditor`\nimport { useMakeStandardAutosuggestionFunction } from \"../../hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function\";\nimport {\n AutosuggestionsConfig,\n defaultAutosuggestionsConfig,\n} from \"../../types/autosuggestions-config\";\nimport {\n BaseCopilotTextarea,\n BaseCopilotTextareaProps,\n} from \"@copilotkit/react-textarea\";\n\nexport interface CopilotTextareaProps extends BaseCopilotTextareaProps {\n autosuggestionsConfig: Partial<AutosuggestionsConfig> & {\n purposePrompt: string;\n };\n}\n\nexport function CopilotTextarea(props: CopilotTextareaProps): JSX.Element {\n const autosuggestionsConfig: AutosuggestionsConfig = {\n ...defaultAutosuggestionsConfig,\n ...props.autosuggestionsConfig,\n };\n\n const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(\n autosuggestionsConfig.purposePrompt,\n autosuggestionsConfig.apiEndpoint,\n autosuggestionsConfig.makeSystemPrompt,\n autosuggestionsConfig.fewShotMessages,\n autosuggestionsConfig.externalContextCategories,\n autosuggestionsConfig.forwardedParams\n );\n\n return (\n <BaseCopilotTextarea\n {...props}\n autosuggestionsConfig={autosuggestionsConfig}\n autosuggestionsFunction={autosuggestionsFunction}\n />\n );\n}\n"]}
@@ -1,68 +0,0 @@
1
- import { __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
2
- import { defaultBaseAutosuggestionsConfig } from '@copilotkit/react-textarea';
3
-
4
- var defaultMakeSystemPrompt = (purposePrompt, contextString) => {
5
- return `You are a versatile writing assistant.
6
-
7
- The user is writing some text.
8
- The purpose is: "${purposePrompt}"
9
-
10
- Your job is to guess what the user will write next AS BEST YOU CAN.
11
- Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
12
-
13
- Adjust yourself to the user's style and implied intent.
14
-
15
- The user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.
16
- <TextAfterCursor>
17
- <TextBeforeCursor>
18
- <YourSuggestion>
19
-
20
- If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
21
-
22
- The following external context is also provided. Use it to help you make better suggestions!!!
23
- \`\`\`
24
- ${contextString}
25
- \`\`\`
26
- `;
27
- };
28
- var defaultFewShotMessages = [
29
- {
30
- role: "user",
31
- name: "TextAfterCursor",
32
- content: "While I was there I also picked up some apples, oranges, and bananas."
33
- },
34
- {
35
- role: "user",
36
- name: "TextBeforeCursor",
37
- content: "This morning I woke up and went straight to the grocery store."
38
- },
39
- {
40
- role: "assistant",
41
- content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
42
- },
43
- {
44
- role: "user",
45
- name: "TextAfterCursor",
46
- content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
47
- },
48
- {
49
- role: "user",
50
- name: "TextBeforeCursor",
51
- content: `The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;`
52
- },
53
- {
54
- role: "assistant",
55
- content: ` (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder's "Pro Rata Share"; `
56
- }
57
- ];
58
- var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
59
- apiEndpoint: "api/autosuggestions",
60
- makeSystemPrompt: defaultMakeSystemPrompt,
61
- fewShotMessages: defaultFewShotMessages,
62
- externalContextCategories: void 0,
63
- forwardedParams: void 0
64
- });
65
-
66
- export { defaultAutosuggestionsConfig, defaultFewShotMessages, defaultMakeSystemPrompt };
67
- //# sourceMappingURL=out.js.map
68
- //# sourceMappingURL=chunk-E2RQC2ZD.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types/autosuggestions-config.tsx"],"names":[],"mappings":";;;;;;AAAA;AAAA,EAEE;AAAA,OACK;AAgBA,IAAM,0BAA4C,CACvD,eACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBlB;AAAA;AAAA;AAGF;AAEO,IAAM,yBAAkD;AAAA,EAC7D;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AACO,IAAM,+BAGT,iCACC,mCADD;AAAA,EAGF,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,2BAA2B;AAAA,EAC3B,iBAAiB;AACnB","sourcesContent":["import {\n BaseAutosuggestionsConfig,\n defaultBaseAutosuggestionsConfig,\n} from \"@copilotkit/react-textarea\";\nimport { MinimalChatGPTMessage } from \"./minimal-chatgpt-message\";\n\nexport type MakeSystemPrompt = (\n purposePrompt: string,\n contextString: string\n) => string;\n\nexport interface AutosuggestionsConfig extends BaseAutosuggestionsConfig {\n apiEndpoint: string;\n externalContextCategories: string[] | undefined;\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultMakeSystemPrompt: MakeSystemPrompt = (\n purposePrompt,\n contextString\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${purposePrompt}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\nexport const defaultAutosuggestionsConfig: Omit<\n AutosuggestionsConfig,\n \"purposePrompt\"\n> = {\n ...defaultBaseAutosuggestionsConfig,\n\n apiEndpoint: \"api/autosuggestions\",\n makeSystemPrompt: defaultMakeSystemPrompt,\n fewShotMessages: defaultFewShotMessages,\n externalContextCategories: undefined,\n forwardedParams: undefined,\n};\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-FZRTAML3.mjs.map
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-YPBKY4KY.mjs.map
@@ -1,12 +0,0 @@
1
- import { AutosuggestionsConfig } from '../../types/autosuggestions-config.js';
2
- import { BaseCopilotTextareaProps } from '@copilotkit/react-textarea';
3
- import '../../types/minimal-chatgpt-message.js';
4
-
5
- interface CopilotTextareaProps extends BaseCopilotTextareaProps {
6
- autosuggestionsConfig: Partial<AutosuggestionsConfig> & {
7
- purposePrompt: string;
8
- };
9
- }
10
- declare function CopilotTextarea(props: CopilotTextareaProps): JSX.Element;
11
-
12
- export { CopilotTextarea, CopilotTextareaProps };
@@ -1,6 +0,0 @@
1
- export { CopilotTextarea } from '../../chunk-CNTO7ZIR.mjs';
2
- import '../../chunk-3PTUDEHX.mjs';
3
- import '../../chunk-E2RQC2ZD.mjs';
4
- import '../../chunk-MRXNTQOX.mjs';
5
- //# sourceMappingURL=out.js.map
6
- //# sourceMappingURL=copilot-textarea.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- import { MinimalChatGPTMessage } from '../../types/minimal-chatgpt-message.js';
2
- import { MakeSystemPrompt } from '../../types/autosuggestions-config.js';
3
- import { AutosuggestionsBareFunction } from '@copilotkit/react-textarea';
4
-
5
- /**
6
- * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
7
- * The function takes in the text before and after the cursor, and an abort signal.
8
- * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.
9
- * The function returns the suggestion from the API response.
10
- *
11
- * @param purposePrompt - The purpose of the textarea. This is included in the system message.
12
- * @param apiEndpoint - The API endpoint to send the autosuggestion request to.
13
- * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.
14
- * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.
15
- * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) "global" context category.
16
- * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
17
- */
18
- declare function useMakeStandardAutosuggestionFunction(purposePrompt: string, apiEndpoint: string, makeSystemPrompt: MakeSystemPrompt, fewShotMessages: MinimalChatGPTMessage[], contextCategories: string[] | undefined, forwardedProps?: {
19
- [key: string]: any;
20
- }): AutosuggestionsBareFunction;
21
-
22
- export { useMakeStandardAutosuggestionFunction };
@@ -1,4 +0,0 @@
1
- export { useMakeStandardAutosuggestionFunction } from '../../chunk-3PTUDEHX.mjs';
2
- import '../../chunk-MRXNTQOX.mjs';
3
- //# sourceMappingURL=out.js.map
4
- //# sourceMappingURL=use-make-standard-autosuggestions-function.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,18 +0,0 @@
1
- import { BaseAutosuggestionsConfig } from '@copilotkit/react-textarea';
2
- import { MinimalChatGPTMessage } from './minimal-chatgpt-message.js';
3
-
4
- type MakeSystemPrompt = (purposePrompt: string, contextString: string) => string;
5
- interface AutosuggestionsConfig extends BaseAutosuggestionsConfig {
6
- apiEndpoint: string;
7
- externalContextCategories: string[] | undefined;
8
- makeSystemPrompt: MakeSystemPrompt;
9
- fewShotMessages: MinimalChatGPTMessage[];
10
- forwardedParams: {
11
- [key: string]: any;
12
- } | undefined;
13
- }
14
- declare const defaultMakeSystemPrompt: MakeSystemPrompt;
15
- declare const defaultFewShotMessages: MinimalChatGPTMessage[];
16
- declare const defaultAutosuggestionsConfig: Omit<AutosuggestionsConfig, "purposePrompt">;
17
-
18
- export { AutosuggestionsConfig, MakeSystemPrompt, defaultAutosuggestionsConfig, defaultFewShotMessages, defaultMakeSystemPrompt };
@@ -1,4 +0,0 @@
1
- export { defaultAutosuggestionsConfig, defaultFewShotMessages, defaultMakeSystemPrompt } from '../chunk-E2RQC2ZD.mjs';
2
- import '../chunk-MRXNTQOX.mjs';
3
- //# sourceMappingURL=out.js.map
4
- //# sourceMappingURL=autosuggestions-config.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- interface MinimalChatGPTMessage {
2
- role: string;
3
- content: string;
4
- name?: string;
5
- }
6
-
7
- export { MinimalChatGPTMessage };
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=minimal-chatgpt-message.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- // This example is for an Editor with `ReactEditor` and `HistoryEditor`
2
- import { useMakeStandardAutosuggestionFunction } from "../../hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function";
3
- import {
4
- AutosuggestionsConfig,
5
- defaultAutosuggestionsConfig,
6
- } from "../../types/autosuggestions-config";
7
- import {
8
- BaseCopilotTextarea,
9
- BaseCopilotTextareaProps,
10
- } from "@copilotkit/react-textarea";
11
-
12
- export interface CopilotTextareaProps extends BaseCopilotTextareaProps {
13
- autosuggestionsConfig: Partial<AutosuggestionsConfig> & {
14
- purposePrompt: string;
15
- };
16
- }
17
-
18
- export function CopilotTextarea(props: CopilotTextareaProps): JSX.Element {
19
- const autosuggestionsConfig: AutosuggestionsConfig = {
20
- ...defaultAutosuggestionsConfig,
21
- ...props.autosuggestionsConfig,
22
- };
23
-
24
- const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(
25
- autosuggestionsConfig.purposePrompt,
26
- autosuggestionsConfig.apiEndpoint,
27
- autosuggestionsConfig.makeSystemPrompt,
28
- autosuggestionsConfig.fewShotMessages,
29
- autosuggestionsConfig.externalContextCategories,
30
- autosuggestionsConfig.forwardedParams
31
- );
32
-
33
- return (
34
- <BaseCopilotTextarea
35
- {...props}
36
- autosuggestionsConfig={autosuggestionsConfig}
37
- autosuggestionsFunction={autosuggestionsFunction}
38
- />
39
- );
40
- }
@@ -1,100 +0,0 @@
1
- import { CopilotContext } from "@copilotkit/react-core";
2
- import { useCallback, useContext } from "react";
3
- import { MakeSystemPrompt } from "../../types";
4
- import { MinimalChatGPTMessage } from "../../types/minimal-chatgpt-message";
5
- import { AutosuggestionsBareFunction } from "@copilotkit/react-textarea";
6
-
7
- /**
8
- * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
9
- * The function takes in the text before and after the cursor, and an abort signal.
10
- * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.
11
- * The function returns the suggestion from the API response.
12
- *
13
- * @param purposePrompt - The purpose of the textarea. This is included in the system message.
14
- * @param apiEndpoint - The API endpoint to send the autosuggestion request to.
15
- * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.
16
- * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.
17
- * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) "global" context category.
18
- * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
19
- */
20
- export function useMakeStandardAutosuggestionFunction(
21
- purposePrompt: string,
22
- apiEndpoint: string,
23
- makeSystemPrompt: MakeSystemPrompt,
24
- fewShotMessages: MinimalChatGPTMessage[],
25
- contextCategories: string[] | undefined,
26
- forwardedProps?: { [key: string]: any }
27
- ): AutosuggestionsBareFunction {
28
- const { getContextString } = useContext(CopilotContext);
29
-
30
- return useCallback(
31
- async (beforeText: string, afterText: string, abortSignal: AbortSignal) => {
32
- const res = await retry(async () => {
33
- return await fetch(apiEndpoint, {
34
- method: "POST",
35
- body: JSON.stringify({
36
- ...forwardedProps,
37
- messages: [
38
- {
39
- role: "system",
40
- content: makeSystemPrompt(
41
- purposePrompt,
42
- getContextString(contextCategories)
43
- ),
44
- },
45
- ...fewShotMessages,
46
- {
47
- role: "user",
48
- name: "TextAfterCursor",
49
- content: afterText,
50
- },
51
- {
52
- role: "user",
53
- name: "TextBeforeCursor",
54
- content: beforeText,
55
- },
56
- ],
57
- }),
58
- signal: abortSignal,
59
- });
60
- });
61
-
62
- const json = await res.json();
63
- const suggestion = json.choices[0].message.content;
64
-
65
- return suggestion;
66
- },
67
- [
68
- apiEndpoint,
69
- makeSystemPrompt,
70
- fewShotMessages,
71
- getContextString,
72
- contextCategories,
73
- purposePrompt,
74
- ]
75
- );
76
- }
77
-
78
- function retry<T>(
79
- fn: () => Promise<T>,
80
- retriesLeft: number = 2,
81
- interval: number = 200,
82
- backoff: number = 1.5
83
- ): Promise<T> {
84
- return new Promise((resolve, reject) => {
85
- fn()
86
- .then(resolve)
87
- .catch((error) => {
88
- if (retriesLeft === 1) {
89
- reject(error);
90
- return;
91
- }
92
-
93
- setTimeout(() => {
94
- retry(fn, retriesLeft - 1, interval * backoff, backoff)
95
- .then(resolve)
96
- .catch(reject);
97
- }, interval);
98
- });
99
- });
100
- }
@@ -1,94 +0,0 @@
1
- import {
2
- BaseAutosuggestionsConfig,
3
- defaultBaseAutosuggestionsConfig,
4
- } from "@copilotkit/react-textarea";
5
- import { MinimalChatGPTMessage } from "./minimal-chatgpt-message";
6
-
7
- export type MakeSystemPrompt = (
8
- purposePrompt: string,
9
- contextString: string
10
- ) => string;
11
-
12
- export interface AutosuggestionsConfig extends BaseAutosuggestionsConfig {
13
- apiEndpoint: string;
14
- externalContextCategories: string[] | undefined;
15
- makeSystemPrompt: MakeSystemPrompt;
16
- fewShotMessages: MinimalChatGPTMessage[];
17
- forwardedParams: { [key: string]: any } | undefined;
18
- }
19
-
20
- export const defaultMakeSystemPrompt: MakeSystemPrompt = (
21
- purposePrompt,
22
- contextString
23
- ) => {
24
- return `You are a versatile writing assistant.
25
-
26
- The user is writing some text.
27
- The purpose is: \"${purposePrompt}\"
28
-
29
- Your job is to guess what the user will write next AS BEST YOU CAN.
30
- Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
31
-
32
- Adjust yourself to the user's style and implied intent.
33
-
34
- The user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.
35
- <TextAfterCursor>
36
- <TextBeforeCursor>
37
- <YourSuggestion>
38
-
39
- If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
40
-
41
- The following external context is also provided. Use it to help you make better suggestions!!!
42
- \`\`\`
43
- ${contextString}
44
- \`\`\`
45
- `;
46
- };
47
-
48
- export const defaultFewShotMessages: MinimalChatGPTMessage[] = [
49
- {
50
- role: "user",
51
- name: "TextAfterCursor",
52
- content:
53
- "While I was there I also picked up some apples, oranges, and bananas.",
54
- },
55
- {
56
- role: "user",
57
- name: "TextBeforeCursor",
58
- content: "This morning I woke up and went straight to the grocery store.",
59
- },
60
- {
61
- role: "assistant",
62
- content:
63
- " When I arrived I went straight to the produce section and picked out a big watermelon. ",
64
- },
65
- {
66
- role: "user",
67
- name: "TextAfterCursor",
68
- content:
69
- "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.",
70
- },
71
- {
72
- role: "user",
73
- name: "TextBeforeCursor",
74
- content:
75
- '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;',
76
- },
77
- {
78
- role: "assistant",
79
- content:
80
- ' (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"; ',
81
- },
82
- ];
83
- export const defaultAutosuggestionsConfig: Omit<
84
- AutosuggestionsConfig,
85
- "purposePrompt"
86
- > = {
87
- ...defaultBaseAutosuggestionsConfig,
88
-
89
- apiEndpoint: "api/autosuggestions",
90
- makeSystemPrompt: defaultMakeSystemPrompt,
91
- fewShotMessages: defaultFewShotMessages,
92
- externalContextCategories: undefined,
93
- forwardedParams: undefined,
94
- };
@@ -1,5 +0,0 @@
1
- export interface MinimalChatGPTMessage {
2
- role: string;
3
- content: string;
4
- name?: string;
5
- }