@copilotkit/react-textarea 0.36.0-mme-push-to-talk.0 → 0.36.0-mme-pre.1

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 (27) hide show
  1. package/.turbo/turbo-build.log +62 -62
  2. package/CHANGELOG.md +12 -0
  3. package/dist/{chunk-PQIOU3E5.mjs → chunk-2OWOTL6X.mjs} +2 -2
  4. package/dist/chunk-2OWOTL6X.mjs.map +1 -0
  5. package/dist/{chunk-QCPS6IYI.mjs → chunk-HE4GMS2P.mjs} +7 -3
  6. package/dist/chunk-HE4GMS2P.mjs.map +1 -0
  7. package/dist/components/copilot-textarea/copilot-textarea.d.ts +106 -0
  8. package/dist/components/copilot-textarea/copilot-textarea.js +6 -2
  9. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  10. package/dist/components/copilot-textarea/copilot-textarea.mjs +2 -2
  11. package/dist/components/index.js +6 -2
  12. package/dist/components/index.js.map +1 -1
  13. package/dist/components/index.mjs +2 -2
  14. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +6 -2
  15. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
  16. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
  17. package/dist/index.js +6 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +3 -3
  20. package/dist/types/base/base-copilot-textarea-props.d.ts +28 -21
  21. package/dist/types/base/base-copilot-textarea-props.js.map +1 -1
  22. package/package.json +6 -6
  23. package/src/components/copilot-textarea/copilot-textarea.tsx +105 -1
  24. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +8 -1
  25. package/src/types/base/base-copilot-textarea-props.tsx +36 -21
  26. package/dist/chunk-PQIOU3E5.mjs.map +0 -1
  27. package/dist/chunk-QCPS6IYI.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -4,9 +4,9 @@ import "./chunk-WADHCMPK.mjs";
4
4
  import "./chunk-MMVDU6DF.mjs";
5
5
  import {
6
6
  CopilotTextarea
7
- } from "./chunk-PQIOU3E5.mjs";
7
+ } from "./chunk-2OWOTL6X.mjs";
8
8
  import "./chunk-SJ2TM5GA.mjs";
9
- import "./chunk-QCPS6IYI.mjs";
9
+ import "./chunk-HE4GMS2P.mjs";
10
10
  import "./chunk-RUV6NBIF.mjs";
11
11
  import {
12
12
  defaultAutosuggestionsConfig
@@ -48,8 +48,8 @@ import {
48
48
  } from "./chunk-LCDTIJSD.mjs";
49
49
  import "./chunk-224UKA7C.mjs";
50
50
  import "./chunk-XW3ICO4S.mjs";
51
- import "./chunk-H4VKQGVU.mjs";
52
51
  import "./chunk-IU3WTXLQ.mjs";
52
+ import "./chunk-H4VKQGVU.mjs";
53
53
  import "./chunk-DFTV4TST.mjs";
54
54
  import "./chunk-T6MTDQZ7.mjs";
55
55
  import "./chunk-ECR45NSD.mjs";
@@ -5,37 +5,44 @@ import '@copilotkit/react-core';
5
5
 
6
6
  /**
7
7
  * `BaseCopilotTextareaProps` defines the properties for the `BaseCopilotTextarea` component.
8
- *
9
- * @extends {Omit<TextareaHTMLAttributes<HTMLDivElement>, "onChange">}
10
- *
11
- * @property {boolean} [disableBranding=false] - Determines whether branding should be disabled. Default is `false`.
12
- *
13
- * @property {React.CSSProperties} [placeholderStyle] - Specifies the CSS styles to apply to the placeholder text.
14
- *
15
- * @property {React.CSSProperties} [suggestionsStyle] - Specifies the CSS styles to apply to the suggestions list.
16
- *
17
- * @property {string} [hoverMenuClassname] - a classname to applly to the editor popover window.
18
- *
19
- * @property {string} [value] - The initial value of the textarea. Can be controlled via `onValueChange`.
20
- *
21
- * @property {(value: string) => void} [onValueChange] - Callback invoked when the value of the textarea changes.
22
- *
23
- * @property {(event: React.ChangeEvent<HTMLTextAreaElement>) => void} [onChange] - Callback invoked when a `change` event is triggered on the textarea element. The event only actually includes the `event.target.value` and `event.currentTarget.value` properties (all that is required in 99% of cases).
24
- *
25
- * @property {Partial<BaseAutosuggestionsConfig> & {
26
- * textareaPurpose: string;
27
- * }} autosuggestionsConfig - Configuration settings for the autosuggestions feature.
28
- * Includes a mandatory `textareaPurpose` to guide the autosuggestions.
29
8
  */
30
9
  interface BaseCopilotTextareaProps extends Omit<TextareaHTMLAttributes<HTMLDivElement>, "onChange"> {
10
+ /**
11
+ * Determines whether the CopilotKit branding should be disabled. Default is `false`.
12
+ */
31
13
  disableBranding?: boolean;
14
+ /**
15
+ * Specifies the CSS styles to apply to the placeholder text.
16
+ */
32
17
  placeholderStyle?: React.CSSProperties;
18
+ /**
19
+ * Specifies the CSS styles to apply to the suggestions list.
20
+ */
33
21
  suggestionsStyle?: React.CSSProperties;
22
+ /**
23
+ * A class name to apply to the editor popover window.
24
+ */
34
25
  hoverMenuClassname?: string;
26
+ /**
27
+ * The initial value of the textarea. Can be controlled via `onValueChange`.
28
+ */
35
29
  value?: string;
30
+ /**
31
+ * Callback invoked when the value of the textarea changes.
32
+ */
36
33
  onValueChange?: (value: string) => void;
34
+ /**
35
+ * Callback invoked when a `change` event is triggered on the textarea element.
36
+ */
37
37
  onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
38
+ /**
39
+ * The shortcut to use to open the editor popover window. Default is `"Cmd-k"`.
40
+ */
38
41
  shortcut?: string;
42
+ /**
43
+ * Configuration settings for the autosuggestions feature.
44
+ * Includes a mandatory `textareaPurpose` to guide the autosuggestions.
45
+ */
39
46
  baseAutosuggestionsConfig: Partial<BaseAutosuggestionsConfig> & {
40
47
  textareaPurpose: string;
41
48
  apiConfig: BaseCopilotTextareaApiConfig;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/base/base-copilot-textarea-props.tsx"],"sourcesContent":["import { TextareaHTMLAttributes } from \"react\";\nimport { BaseAutosuggestionsConfig } from \".\";\nimport { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\n\n/**\n * `BaseCopilotTextareaProps` defines the properties for the `BaseCopilotTextarea` component.\n *\n * @extends {Omit<TextareaHTMLAttributes<HTMLDivElement>, \"onChange\">}\n *\n * @property {boolean} [disableBranding=false] - Determines whether branding should be disabled. Default is `false`.\n *\n * @property {React.CSSProperties} [placeholderStyle] - Specifies the CSS styles to apply to the placeholder text.\n *\n * @property {React.CSSProperties} [suggestionsStyle] - Specifies the CSS styles to apply to the suggestions list.\n *\n * @property {string} [hoverMenuClassname] - a classname to applly to the editor popover window.\n *\n * @property {string} [value] - The initial value of the textarea. Can be controlled via `onValueChange`.\n *\n * @property {(value: string) => void} [onValueChange] - Callback invoked when the value of the textarea changes.\n *\n * @property {(event: React.ChangeEvent<HTMLTextAreaElement>) => void} [onChange] - Callback invoked when a `change` event is triggered on the textarea element. The event only actually includes the `event.target.value` and `event.currentTarget.value` properties (all that is required in 99% of cases).\n *\n * @property {Partial<BaseAutosuggestionsConfig> & {\n * textareaPurpose: string;\n * }} autosuggestionsConfig - Configuration settings for the autosuggestions feature.\n * Includes a mandatory `textareaPurpose` to guide the autosuggestions.\n */\nexport interface BaseCopilotTextareaProps\n extends Omit<TextareaHTMLAttributes<HTMLDivElement>, \"onChange\"> {\n disableBranding?: boolean;\n placeholderStyle?: React.CSSProperties;\n suggestionsStyle?: React.CSSProperties;\n hoverMenuClassname?: string;\n value?: string;\n onValueChange?: (value: string) => void;\n onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n shortcut?: string;\n baseAutosuggestionsConfig: Partial<BaseAutosuggestionsConfig> & {\n textareaPurpose: string;\n apiConfig: BaseCopilotTextareaApiConfig;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/base/base-copilot-textarea-props.tsx"],"sourcesContent":["import { TextareaHTMLAttributes } from \"react\";\nimport { BaseAutosuggestionsConfig } from \".\";\nimport { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\n\n/**\n * `BaseCopilotTextareaProps` defines the properties for the `BaseCopilotTextarea` component.\n */\nexport interface BaseCopilotTextareaProps\n extends Omit<TextareaHTMLAttributes<HTMLDivElement>, \"onChange\"> {\n /**\n * Determines whether the CopilotKit branding should be disabled. Default is `false`.\n */\n disableBranding?: boolean;\n\n /**\n * Specifies the CSS styles to apply to the placeholder text.\n */\n placeholderStyle?: React.CSSProperties;\n\n /**\n * Specifies the CSS styles to apply to the suggestions list.\n */\n suggestionsStyle?: React.CSSProperties;\n\n /**\n * A class name to apply to the editor popover window.\n */\n hoverMenuClassname?: string;\n\n /**\n * The initial value of the textarea. Can be controlled via `onValueChange`.\n */\n value?: string;\n\n /**\n * Callback invoked when the value of the textarea changes.\n */\n onValueChange?: (value: string) => void;\n\n /**\n * Callback invoked when a `change` event is triggered on the textarea element.\n */\n onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n\n /**\n * The shortcut to use to open the editor popover window. Default is `\"Cmd-k\"`.\n */\n shortcut?: string;\n\n /**\n * Configuration settings for the autosuggestions feature.\n * Includes a mandatory `textareaPurpose` to guide the autosuggestions.\n */\n baseAutosuggestionsConfig: Partial<BaseAutosuggestionsConfig> & {\n textareaPurpose: string;\n apiConfig: BaseCopilotTextareaApiConfig;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.36.0-mme-push-to-talk.0",
7
+ "version": "0.36.0-mme-pre.1",
8
8
  "sideEffects": [
9
9
  "**/*.css"
10
10
  ],
@@ -37,9 +37,9 @@
37
37
  "ts-jest": "^29.1.1",
38
38
  "tsup": "^6.7.0",
39
39
  "typescript": "^5.2.3",
40
- "eslint-config-custom": "0.11.0-mme-push-to-talk.0",
41
- "tailwind-config": "0.10.0-mme-push-to-talk.0",
42
- "tsconfig": "0.15.0-mme-push-to-talk.0"
40
+ "eslint-config-custom": "0.11.0-mme-pre.1",
41
+ "tailwind-config": "0.10.0-mme-pre.1",
42
+ "tsconfig": "0.15.0-mme-pre.1"
43
43
  },
44
44
  "dependencies": {
45
45
  "@emotion/css": "^11.11.2",
@@ -62,8 +62,8 @@
62
62
  "slate-history": "^0.93.0",
63
63
  "slate-react": "^0.98.1",
64
64
  "tailwind-merge": "^1.13.2",
65
- "@copilotkit/react-core": "0.36.0-mme-push-to-talk.0",
66
- "@copilotkit/shared": "0.36.0-mme-push-to-talk.0"
65
+ "@copilotkit/react-core": "0.36.0-mme-pre.1",
66
+ "@copilotkit/shared": "0.36.0-mme-pre.1"
67
67
  },
68
68
  "scripts": {
69
69
  "build": "tsup --clean",
@@ -1,4 +1,79 @@
1
- // This example is for an Editor with `ReactEditor` and `HistoryEditor`
1
+ /**
2
+ * A context-aware, auto-completing textarea.
3
+ *
4
+ * <RequestExample>
5
+ * ```jsx CopilotTextarea Example
6
+ * <CopilotTextarea
7
+ * autosuggestionsConfig={{
8
+ * textareaPurpose:
9
+ * "the body of an email message",
10
+ * chatApiConfigs: {},
11
+ * }}
12
+ * />
13
+ * ```
14
+ * </RequestExample>
15
+ *
16
+ * `<CopilotTextarea>` is a React component that acts as a drop-in replacement for the standard `<textarea>`,
17
+ * offering enhanced autocomplete features powered by AI. It is context-aware, integrating seamlessly with the
18
+ * [useCopilotReadable()](./useCopilotReadable) hook to provide intelligent suggestions based on the application context.
19
+ *
20
+ * In addition, it provides a hovering editor window (available by default via `Cmd+k`) that allows the user to
21
+ * suggest changes to the text, for example providing a summary or rephrasing the text.
22
+ *
23
+ * <img src="/images/CopilotTextarea/CopilotTextarea.gif" width="500" />
24
+ *
25
+ * ## Integrating CopilotTextarea
26
+ *
27
+ * Install the CopilotTextarea frontend packagess:
28
+ *
29
+ * <CodeGroup>
30
+ * ```bash npm
31
+ * npm i @copilotkit/react-core @copilotkit/react-textarea
32
+ * ```
33
+ *
34
+ * ```bash yarn
35
+ * yarn add @copilotkit/react-core @copilotkit/react-textarea
36
+ * ```
37
+ *
38
+ * ```bash pnpm
39
+ * pnpm add @copilotkit/react-core @copilotkit/react-textarea
40
+ * ```
41
+ * </CodeGroup>
42
+ *
43
+ * Use the CopilotTextarea component in your React application similarly to a standard `<textarea />`,
44
+ * with additional configurations for AI-powered features.
45
+ *
46
+ * For example:
47
+ *
48
+ * ```tsx
49
+ * import { CopilotTextarea } from "@copilotkit/react-textarea";
50
+ * import { useState } from "react";
51
+ *
52
+ * export function ExampleComponent() {
53
+ * const [text, setText] = useState("");
54
+ *
55
+ * return (
56
+ * <CopilotTextarea
57
+ * className="custom-textarea-class"
58
+ * value={text}
59
+ * onValueChange={(value: string) => setText(value)}
60
+ * placeholder="Enter your text here..."
61
+ * autosuggestionsConfig={{
62
+ * textareaPurpose: "Provide context or purpose of the textarea.",
63
+ * chatApiConfigs: {
64
+ * suggestionsApiConfig: {
65
+ * forwardedParams: {
66
+ * max_tokens: 20,
67
+ * stop: [".", "?", "!"],
68
+ * },
69
+ * },
70
+ * },
71
+ * }}
72
+ * />
73
+ * );
74
+ * }
75
+ * ```
76
+ */
2
77
  import React from "react";
3
78
  import { useMakeStandardAutosuggestionFunction } from "../../hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function";
4
79
  import { HTMLCopilotTextAreaElement } from "../../types";
@@ -16,6 +91,35 @@ import { AutosuggestionsConfigUserSpecified } from "../../types/autosuggestions-
16
91
  // but with baseAutosuggestionsConfig replaced with autosuggestionsConfig.
17
92
  export interface CopilotTextareaProps
18
93
  extends Omit<BaseCopilotTextareaProps, "baseAutosuggestionsConfig"> {
94
+ /**
95
+ * Configuration settings for the autosuggestions feature.
96
+ * Includes a mandatory `textareaPurpose` to guide the autosuggestions.
97
+ *
98
+ * Autosuggestions can be configured as follows:
99
+ *
100
+ * ```ts
101
+ * {
102
+ * // the purpose of the textarea
103
+ * textareaPurpose: string,
104
+ * chatApiConfigs: {
105
+ * // the config for the suggestions api (optional)
106
+ * suggestionsApiConfig: {
107
+ * // use this to provide a custom system prompt
108
+ * makeSystemPrompt: (textareaPurpose: string, contextString: string) => string;
109
+ * // custom few shot messages
110
+ * fewShotMessages: MinimalChatGPTMessage[];
111
+ * forwardedParams: {
112
+ * // max number of tokens to generate
113
+ * max_tokens: number,
114
+ * // stop generating when these characters are encountered, e.g. [".", "?", "!"]
115
+ * stop: string[],
116
+ * },
117
+ * },
118
+ * insertionApiConfig: //... the same options as suggestionsApiConfig
119
+ * },
120
+ * }
121
+ * ```
122
+ */
19
123
  autosuggestionsConfig: AutosuggestionsConfigUserSpecified;
20
124
  }
21
125
 
@@ -1,4 +1,4 @@
1
- import { Message } from "@copilotkit/shared";
1
+ import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, Message } from "@copilotkit/shared";
2
2
  import { CopilotContext } from "@copilotkit/react-core";
3
3
  import { useCallback, useContext } from "react";
4
4
  import { MinimalChatGPTMessage } from "../../types";
@@ -34,6 +34,11 @@ export function useMakeStandardInsertionOrEditingFunction(
34
34
  editingApiConfig: EditingApiConfig,
35
35
  ): Generator_InsertionOrEditingSuggestion {
36
36
  const { getContextString, copilotApiConfig } = useContext(CopilotContext);
37
+ const headers = {
38
+ ...(copilotApiConfig.publicApiKey
39
+ ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }
40
+ : {}),
41
+ };
37
42
 
38
43
  const insertionFunction = useCallback(
39
44
  async (
@@ -74,6 +79,7 @@ export function useMakeStandardInsertionOrEditingFunction(
74
79
  ...insertionApiConfig.forwardedParams,
75
80
  copilotConfig: copilotApiConfig,
76
81
  signal: abortSignal,
82
+ headers,
77
83
  });
78
84
  return stream.events!;
79
85
  });
@@ -127,6 +133,7 @@ export function useMakeStandardInsertionOrEditingFunction(
127
133
  ...editingApiConfig.forwardedParams,
128
134
  copilotConfig: copilotApiConfig,
129
135
  signal: abortSignal,
136
+ headers,
130
137
  });
131
138
  return stream.events!;
132
139
  });
@@ -4,38 +4,53 @@ import { BaseCopilotTextareaApiConfig } from "./autosuggestions-bare-function";
4
4
 
5
5
  /**
6
6
  * `BaseCopilotTextareaProps` defines the properties for the `BaseCopilotTextarea` component.
7
- *
8
- * @extends {Omit<TextareaHTMLAttributes<HTMLDivElement>, "onChange">}
9
- *
10
- * @property {boolean} [disableBranding=false] - Determines whether branding should be disabled. Default is `false`.
11
- *
12
- * @property {React.CSSProperties} [placeholderStyle] - Specifies the CSS styles to apply to the placeholder text.
13
- *
14
- * @property {React.CSSProperties} [suggestionsStyle] - Specifies the CSS styles to apply to the suggestions list.
15
- *
16
- * @property {string} [hoverMenuClassname] - a classname to applly to the editor popover window.
17
- *
18
- * @property {string} [value] - The initial value of the textarea. Can be controlled via `onValueChange`.
19
- *
20
- * @property {(value: string) => void} [onValueChange] - Callback invoked when the value of the textarea changes.
21
- *
22
- * @property {(event: React.ChangeEvent<HTMLTextAreaElement>) => void} [onChange] - Callback invoked when a `change` event is triggered on the textarea element. The event only actually includes the `event.target.value` and `event.currentTarget.value` properties (all that is required in 99% of cases).
23
- *
24
- * @property {Partial<BaseAutosuggestionsConfig> & {
25
- * textareaPurpose: string;
26
- * }} autosuggestionsConfig - Configuration settings for the autosuggestions feature.
27
- * Includes a mandatory `textareaPurpose` to guide the autosuggestions.
28
7
  */
29
8
  export interface BaseCopilotTextareaProps
30
9
  extends Omit<TextareaHTMLAttributes<HTMLDivElement>, "onChange"> {
10
+ /**
11
+ * Determines whether the CopilotKit branding should be disabled. Default is `false`.
12
+ */
31
13
  disableBranding?: boolean;
14
+
15
+ /**
16
+ * Specifies the CSS styles to apply to the placeholder text.
17
+ */
32
18
  placeholderStyle?: React.CSSProperties;
19
+
20
+ /**
21
+ * Specifies the CSS styles to apply to the suggestions list.
22
+ */
33
23
  suggestionsStyle?: React.CSSProperties;
24
+
25
+ /**
26
+ * A class name to apply to the editor popover window.
27
+ */
34
28
  hoverMenuClassname?: string;
29
+
30
+ /**
31
+ * The initial value of the textarea. Can be controlled via `onValueChange`.
32
+ */
35
33
  value?: string;
34
+
35
+ /**
36
+ * Callback invoked when the value of the textarea changes.
37
+ */
36
38
  onValueChange?: (value: string) => void;
39
+
40
+ /**
41
+ * Callback invoked when a `change` event is triggered on the textarea element.
42
+ */
37
43
  onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
44
+
45
+ /**
46
+ * The shortcut to use to open the editor popover window. Default is `"Cmd-k"`.
47
+ */
38
48
  shortcut?: string;
49
+
50
+ /**
51
+ * Configuration settings for the autosuggestions feature.
52
+ * Includes a mandatory `textareaPurpose` to guide the autosuggestions.
53
+ */
39
54
  baseAutosuggestionsConfig: Partial<BaseAutosuggestionsConfig> & {
40
55
  textareaPurpose: string;
41
56
  apiConfig: BaseCopilotTextareaApiConfig;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/copilot-textarea/copilot-textarea.tsx"],"sourcesContent":["// This example is for an Editor with `ReactEditor` and `HistoryEditor`\nimport React from \"react\";\nimport { useMakeStandardAutosuggestionFunction } from \"../../hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { BaseCopilotTextareaProps } from \"../../types/base/base-copilot-textarea-props\";\nimport {\n AutosuggestionsConfig,\n defaultAutosuggestionsConfig,\n} from \"../../types/autosuggestions-config\";\nimport { BaseCopilotTextarea } from \"../base-copilot-textarea/base-copilot-textarea\";\nimport { useMakeStandardInsertionOrEditingFunction } from \"../../hooks/make-autosuggestions-function/use-make-standard-insertion-function\";\nimport merge from \"lodash.merge\";\nimport { AutosuggestionsConfigUserSpecified } from \"../../types/autosuggestions-config/autosuggestions-config-user-specified\";\n\n// Like the base copilot textarea props,\n// but with baseAutosuggestionsConfig replaced with autosuggestionsConfig.\nexport interface CopilotTextareaProps\n extends Omit<BaseCopilotTextareaProps, \"baseAutosuggestionsConfig\"> {\n autosuggestionsConfig: AutosuggestionsConfigUserSpecified;\n}\n\n/**\n * A copilot textarea that uses the standard autosuggestions function.\n */\nexport const CopilotTextarea = React.forwardRef(\n (props: CopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {\n // separate the AutosuggestionsConfigUserSpecified from the rest of the props\n const { autosuggestionsConfig: autosuggestionsConfigUserSpecified, ...forwardedProps } = props;\n\n const autosuggestionsConfig: AutosuggestionsConfig = merge(\n defaultAutosuggestionsConfig,\n autosuggestionsConfigUserSpecified,\n );\n\n const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(\n autosuggestionsConfig.textareaPurpose,\n autosuggestionsConfig.contextCategories,\n autosuggestionsConfig.chatApiConfigs.suggestionsApiConfig,\n );\n\n const insertionOrEditingFunction = useMakeStandardInsertionOrEditingFunction(\n autosuggestionsConfig.textareaPurpose,\n autosuggestionsConfig.contextCategories,\n autosuggestionsConfig.chatApiConfigs.insertionApiConfig,\n autosuggestionsConfig.chatApiConfigs.editingApiConfig,\n );\n\n return (\n <>\n <BaseCopilotTextarea\n ref={ref}\n {...forwardedProps}\n baseAutosuggestionsConfig={{\n ...autosuggestionsConfig,\n apiConfig: {\n insertionOrEditingFunction: insertionOrEditingFunction,\n autosuggestionsFunction: autosuggestionsFunction,\n },\n }}\n />\n </>\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AACA,OAAO,WAAW;AAUlB,OAAO,WAAW;AAqCZ,mBACE,WADF;AAxBC,IAAM,kBAAkB,MAAM;AAAA,EACnC,CAAC,OAA6B,QAA+C;AAE3E,UAAyF,YAAjF,yBAAuB,mCA3BnC,IA2B6F,IAAnB,2BAAmB,IAAnB,CAA9D;AAER,UAAM,wBAA+C;AAAA,MACnD;AAAA,MACA;AAAA,IACF;AAEA,UAAM,0BAA0B;AAAA,MAC9B,sBAAsB;AAAA,MACtB,sBAAsB;AAAA,MACtB,sBAAsB,eAAe;AAAA,IACvC;AAEA,UAAM,6BAA6B;AAAA,MACjC,sBAAsB;AAAA,MACtB,sBAAsB;AAAA,MACtB,sBAAsB,eAAe;AAAA,MACrC,sBAAsB,eAAe;AAAA,IACvC;AAEA,WACE,gCACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,SACI,iBAFL;AAAA,QAGC,2BAA2B,iCACtB,wBADsB;AAAA,UAEzB,WAAW;AAAA,YACT;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA;AAAA,IACF,GACF;AAAA,EAEJ;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx"],"sourcesContent":["import { Message } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { 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\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\nimport { fetchAndDecodeChatCompletionAsText } from \"@copilotkit/react-core\";\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[],\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 documents: DocumentPointer[],\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(documents, 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 stream = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...insertionApiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n });\n return stream.events!;\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 documents: DocumentPointer[],\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(documents, 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 stream = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...editingApiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n });\n return stream.events!;\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 documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n if (editorState.selectedText === \"\") {\n return await insertionFunction(editorState, insertionPrompt, documents, abortSignal);\n } else {\n return await editingFunction(editorState, insertionPrompt, documents, abortSignal);\n }\n },\n [insertionFunction, editingFunction],\n );\n\n return insertionOrEditingFunction;\n}\n"],"mappings":";;;;;;;;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AAYxC,SAAS,0CAA0C;AAe5C,SAAS,0CACd,iBACA,mBACA,oBACA,kBACwC;AACxC,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,WAAW,cAAc;AAExE,QAAM,oBAAoB;AAAA,IACxB,CACE,aACA,iBACA,WACA,gBACG;AACH,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,mBAAmB;AAAA,cAC1B;AAAA,cACA,iBAAiB,WAAW,iBAAiB;AAAA,YAC/C;AAAA,UACF;AAAA,UACA,GAAG,mBAAmB;AAAA,UACtB;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,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,UACX;AAAA,QACF;AAEA,cAAM,SAAS,MAAM,mCAAmC;AAAA,UACtD;AAAA,WACG,mBAAmB,kBAFgC;AAAA,UAGtD,eAAe;AAAA,UACf,QAAQ;AAAA,QACV,EAAC;AACD,eAAO,OAAO;AAAA,MAChB,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,oBAAoB,kBAAkB,mBAAmB,eAAe;AAAA,EAC3E;AAEA,QAAM,kBAAkB;AAAA,IACtB,CACE,aACA,eACA,WACA,gBACG;AACH,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,iBAAiB;AAAA,cACxB;AAAA,cACA,iBAAiB,WAAW,iBAAiB;AAAA,YAC/C;AAAA,UACF;AAAA,UACA,GAAG,iBAAiB;AAAA,UACpB;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,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,UACX;AAAA,QACF;AAEA,cAAM,SAAS,MAAM,mCAAmC;AAAA,UACtD;AAAA,WACG,iBAAiB,kBAFkC;AAAA,UAGtD,eAAe;AAAA,UACf,QAAQ;AAAA,QACV,EAAC;AACD,eAAO,OAAO;AAAA,MAChB,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,kBAAkB,kBAAkB,mBAAmB,eAAe;AAAA,EACzE;AAEA,QAAM,6BAA6B;AAAA,IACjC,CACE,aACA,iBACA,WACA,gBACG;AACH,UAAI,YAAY,iBAAiB,IAAI;AACnC,eAAO,MAAM,kBAAkB,aAAa,iBAAiB,WAAW,WAAW;AAAA,MACrF,OAAO;AACL,eAAO,MAAM,gBAAgB,aAAa,iBAAiB,WAAW,WAAW;AAAA,MACnF;AAAA,IACF;AAAA,IACA,CAAC,mBAAmB,eAAe;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}