@copilotkit/react-textarea 1.1.1-feat-runtime-remote-actions.0 → 1.1.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 (28) hide show
  1. package/CHANGELOG.md +8 -5
  2. package/dist/{chunk-5EDG5WL3.mjs → chunk-OLYQNYUN.mjs} +2 -2
  3. package/dist/{chunk-P774SJMD.mjs → chunk-T2HQH23F.mjs} +2 -2
  4. package/dist/chunk-T2HQH23F.mjs.map +1 -0
  5. package/dist/{chunk-6QIA4FWK.mjs → chunk-UUL4NSW5.mjs} +2 -1
  6. package/dist/chunk-UUL4NSW5.mjs.map +1 -0
  7. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1 -0
  8. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
  9. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +2 -2
  10. package/dist/components/copilot-textarea/copilot-textarea.d.ts +34 -23
  11. package/dist/components/copilot-textarea/copilot-textarea.js +1 -0
  12. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  13. package/dist/components/copilot-textarea/copilot-textarea.mjs +3 -3
  14. package/dist/components/hovering-toolbar/hovering-toolbar.js +1 -0
  15. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
  16. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +1 -1
  17. package/dist/components/index.js +1 -0
  18. package/dist/components/index.js.map +1 -1
  19. package/dist/components/index.mjs +3 -3
  20. package/dist/index.js +1 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +4 -4
  23. package/package.json +7 -7
  24. package/src/components/copilot-textarea/copilot-textarea.tsx +34 -23
  25. package/src/components/hovering-toolbar/hovering-toolbar.tsx +2 -1
  26. package/dist/chunk-6QIA4FWK.mjs.map +0 -1
  27. package/dist/chunk-P774SJMD.mjs.map +0 -1
  28. /package/dist/{chunk-5EDG5WL3.mjs.map → chunk-OLYQNYUN.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,14 +1,17 @@
1
1
  # ui
2
2
 
3
- ## 1.1.1-feat-runtime-remote-actions.0
3
+ ## 1.1.1
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Remote actions preview
7
+ - - improved documentation
8
+ - center textarea popup
9
+ - show/hide dev console
10
+ - forward maxTokens, stop and force function calling
8
11
  - Updated dependencies
9
- - @copilotkit/runtime-client-gql@1.1.1-feat-runtime-remote-actions.0
10
- - @copilotkit/react-core@1.1.1-feat-runtime-remote-actions.0
11
- - @copilotkit/shared@1.1.1-feat-runtime-remote-actions.0
12
+ - @copilotkit/react-core@1.1.1
13
+ - @copilotkit/runtime-client-gql@1.1.1
14
+ - @copilotkit/shared@1.1.1
12
15
 
13
16
  ## 1.1.0
14
17
 
@@ -24,7 +24,7 @@ import {
24
24
  } from "./chunk-7LSRNPNI.mjs";
25
25
  import {
26
26
  HoveringToolbar
27
- } from "./chunk-6QIA4FWK.mjs";
27
+ } from "./chunk-UUL4NSW5.mjs";
28
28
  import {
29
29
  HoveringEditorProvider,
30
30
  useHoveringEditorContext
@@ -261,4 +261,4 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
261
261
  export {
262
262
  BaseCopilotTextarea
263
263
  };
264
- //# sourceMappingURL=chunk-5EDG5WL3.mjs.map
264
+ //# sourceMappingURL=chunk-OLYQNYUN.mjs.map
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-HL7EF7KA.mjs";
10
10
  import {
11
11
  BaseCopilotTextarea
12
- } from "./chunk-5EDG5WL3.mjs";
12
+ } from "./chunk-OLYQNYUN.mjs";
13
13
  import {
14
14
  __objRest,
15
15
  __spreadProps,
@@ -57,4 +57,4 @@ var CopilotTextarea = React.forwardRef(
57
57
  export {
58
58
  CopilotTextarea
59
59
  };
60
- //# sourceMappingURL=chunk-P774SJMD.mjs.map
60
+ //# sourceMappingURL=chunk-T2HQH23F.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/copilot-textarea/copilot-textarea.tsx"],"sourcesContent":["/**\n * <br/>\n * <img src=\"/images/CopilotTextarea.gif\" width=\"500\" />\n *\n * `<CopilotTextarea>` is a React component that acts as a drop-in replacement for the standard `<textarea>`,\n * offering enhanced autocomplete features powered by AI. It is context-aware, integrating seamlessly with the\n * [`useCopilotReadable`](/reference/hooks/useCopilotReadable) hook to provide intelligent suggestions based on the application context.\n *\n * In addition, it provides a hovering editor window (available by default via `Cmd + K` on Mac and `Ctrl + K` on Windows) that allows the user to\n * suggest changes to the text, for example providing a summary or rephrasing the text.\n *\n * ## Example\n *\n * ```tsx\n * import { CopilotTextarea } from '@copilot/react-ui';\n *\n * <CopilotTextarea\n * autosuggestionsConfig={{\n * textareaPurpose:\n * \"the body of an email message\",\n * chatApiConfigs: {},\n * }}\n * />\n * ```\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Usage\n *\n * Use the CopilotTextarea component in your React application similarly to a standard `<textarea />`,\n * with additional configurations for AI-powered features.\n *\n * For example:\n *\n * ```tsx\n * import { CopilotTextarea } from \"@copilotkit/react-textarea\";\n * import { useState } from \"react\";\n *\n * export function ExampleComponent() {\n * const [text, setText] = useState(\"\");\n *\n * return (\n * <CopilotTextarea\n * className=\"custom-textarea-class\"\n * value={text}\n * onValueChange={(value: string) => setText(value)}\n * placeholder=\"Enter your text here...\"\n * autosuggestionsConfig={{\n * textareaPurpose: \"Provide context or purpose of the textarea.\",\n * chatApiConfigs: {\n * suggestionsApiConfig: {\n * maxTokens: 20,\n * stop: [\".\", \"?\", \"!\"],\n * },\n * },\n * }}\n * />\n * );\n * }\n * ```\n *\n * ### Look & Feel\n *\n * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:\n * ```tsx fileName=\"YourRootComponent.tsx\" {2}\n * ...\n * import \"@copilotkit/react-ui/styles.css\";\n *\n * export function YourRootComponent() {\n * return (\n * <CopilotKit>\n * ...\n * </CopilotKit>\n * );\n * }\n * ```\n * For more information about how to customize the styles, check out the [Customize Look & Feel](/concepts/customize-look-and-feel) guide.\n * */\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 /**\n * Configuration settings for the autosuggestions feature.\n * Includes a mandatory `textareaPurpose` to guide the autosuggestions.\n *\n * <PropertyReference name=\"textareaPurpose\" type=\"string\" >\n * The purpose of the text area in plain text.\n *\n * Example: *\"The body of the email response\"*\n * </PropertyReference>\n *\n * <PropertyReference name=\"chatApiConfigs\" type=\"ChatApiConfigs\" >\n * The chat API configurations.\n *\n * <strong>NOTE:</strong> You must provide specify at least one of `suggestionsApiConfig` or `insertionApiConfig`.\n *\n * <PropertyReference name=\"suggestionsApiConfig\" type=\"SuggestionsApiConfig\">\n * For full reference, please [click here](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-textarea/src/types/autosuggestions-config/suggestions-api-config.tsx#L4).\n * </PropertyReference>\n * <PropertyReference name=\"insertionApiConfig\" type=\"InsertionApiConfig\">\n * For full reference, please [click here](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-textarea/src/types/autosuggestions-config/insertions-api-config.tsx#L4).\n * </PropertyReference>\n * </PropertyReference>\n */\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":";;;;;;;;;;;;;;;;;;;AAsFA,OAAO,WAAW;AAUlB,OAAO,WAAW;AA4DZ,mBACE,WADF;AAxBC,IAAM,kBAAkB,MAAM;AAAA,EACnC,CAAC,OAA6B,QAA+C;AAE3E,UAAyF,YAAjF,yBAAuB,mCAvInC,IAuI6F,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":[]}
@@ -62,6 +62,7 @@ var HoveringToolbar = (props) => {
62
62
  left = window.innerWidth - el.offsetWidth - minGapFromEdge;
63
63
  }
64
64
  el.style.opacity = "1";
65
+ el.style.position = "absolute";
65
66
  el.style.top = `${top}px`;
66
67
  el.style.left = `${left}px`;
67
68
  });
@@ -120,4 +121,4 @@ function editorState(editor, selection) {
120
121
  export {
121
122
  HoveringToolbar
122
123
  };
123
- //# sourceMappingURL=chunk-6QIA4FWK.mjs.map
124
+ //# sourceMappingURL=chunk-UUL4NSW5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/hovering-toolbar/hovering-toolbar.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Editor, Location, Transforms } from \"slate\";\nimport { useSlate, useSlateSelection } from \"slate-react\";\nimport { HoveringInsertionPromptBox } from \"./text-insertion-prompt-box\";\nimport { Menu, Portal } from \"./hovering-toolbar-components\";\nimport { useHoveringEditorContext } from \"./hovering-editor-provider\";\nimport {\n getFullEditorTextWithNewlines,\n getTextAroundSelection,\n} from \"../../lib/get-text-around-cursor\";\nimport {\n EditingEditorState,\n InsertionEditorApiConfig,\n} from \"../../types/base/autosuggestions-bare-function\";\n\nexport interface HoveringToolbarProps {\n apiConfig: InsertionEditorApiConfig;\n contextCategories: string[];\n hoverMenuClassname: string | undefined;\n}\n\nexport const HoveringToolbar = (props: HoveringToolbarProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const editor = useSlate();\n const selection = useSlateSelection();\n const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();\n\n // only render on client\n const [isClient, setIsClient] = useState(false);\n useEffect(() => {\n setIsClient(true);\n }, []);\n\n useEffect(() => {\n const el = ref.current;\n const { selection } = editor;\n\n if (!el) {\n return;\n }\n\n if (!selection) {\n el.removeAttribute(\"style\");\n return;\n }\n\n const domSelection = window.getSelection();\n if (!domSelection || domSelection.rangeCount === 0) {\n return;\n }\n\n const domRange = domSelection.getRangeAt(0);\n const rect = domRange.getBoundingClientRect();\n\n // We use window = (0,0,0,0) as a signal that the selection is not in the original copilot-textarea,\n // but inside the hovering window.\n //\n // in such case, we simply do nothing.\n if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {\n return;\n }\n const minGapFromEdge = 60;\n const verticalOffsetFromCorner = 35;\n const horizontalOffsetFromCorner = 15;\n let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;\n // make sure top is in the viewport and not too close to the edge\n if (top < minGapFromEdge) {\n top = rect.bottom + window.scrollY + minGapFromEdge;\n } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {\n top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;\n }\n\n let left =\n rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;\n // make sure left is in the viewport and not too close to the edge\n if (left < minGapFromEdge) {\n left = minGapFromEdge;\n } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {\n left = window.innerWidth - el.offsetWidth - minGapFromEdge;\n }\n\n el.style.opacity = \"1\";\n el.style.position = \"absolute\";\n\n el.style.top = `${top}px`;\n el.style.left = `${left}px`;\n });\n\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (ref.current && !ref.current.contains(event.target as Node)) {\n setIsDisplayed(false);\n }\n };\n\n document.addEventListener(\"mousedown\", handleClickOutside);\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n }, [ref, setIsDisplayed]);\n\n if (!isClient) {\n return null;\n }\n\n return (\n <Portal>\n <Menu\n ref={ref}\n className={\n \"copilot-kit-textarea-css-scope \" +\n (props.hoverMenuClassname ||\n \"p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700\")\n }\n >\n {isDisplayed && selection && (\n <HoveringInsertionPromptBox\n editorState={editorState(editor, selection)}\n apiConfig={props.apiConfig}\n closeWindow={() => {\n setIsDisplayed(false);\n }}\n performInsertion={(insertedText) => {\n // replace the selection with the inserted text\n Transforms.delete(editor, { at: selection });\n Transforms.insertText(editor, insertedText, {\n at: selection,\n });\n setIsDisplayed(false);\n }}\n contextCategories={props.contextCategories}\n />\n )}\n </Menu>\n </Portal>\n );\n};\n\nfunction editorState(editor: Editor, selection: Location): EditingEditorState {\n const textAroundCursor = getTextAroundSelection(editor);\n if (textAroundCursor) {\n return textAroundCursor;\n }\n\n return {\n textBeforeCursor: getFullEditorTextWithNewlines(editor),\n textAfterCursor: \"\",\n selectedText: \"\",\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAA2B,kBAAkB;AAC7C,SAAS,UAAU,yBAAyB;AAkHlC;AA/FH,IAAM,kBAAkB,CAAC,UAAgC;AAC9D,QAAM,MAAM,OAAuB,IAAI;AACvC,QAAM,SAAS,SAAS;AACxB,QAAM,YAAY,kBAAkB;AACpC,QAAM,EAAE,aAAa,eAAe,IAAI,yBAAyB;AAGjE,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,YAAU,MAAM;AACd,gBAAY,IAAI;AAAA,EAClB,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,UAAM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aAAS,iBAAiB,aAAa,kBAAkB;AACzD,WAAO,MAAM;AACX,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAC9D;AAAA,EACF,GAAG,CAAC,KAAK,cAAc,CAAC;AAExB,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,SACE,oBAAC,UACC;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WACE,qCACC,MAAM,sBACL;AAAA,MAGH,yBAAe,aACd;AAAA,QAAC;AAAA;AAAA,UACC,aAAa,YAAY,QAAQ,SAAS;AAAA,UAC1C,WAAW,MAAM;AAAA,UACjB,aAAa,MAAM;AACjB,2BAAe,KAAK;AAAA,UACtB;AAAA,UACA,kBAAkB,CAAC,iBAAiB;AAElC,uBAAW,OAAO,QAAQ,EAAE,IAAI,UAAU,CAAC;AAC3C,uBAAW,WAAW,QAAQ,cAAc;AAAA,cAC1C,IAAI;AAAA,YACN,CAAC;AACD,2BAAe,KAAK;AAAA,UACtB;AAAA,UACA,mBAAmB,MAAM;AAAA;AAAA,MAC3B;AAAA;AAAA,EAEJ,GACF;AAEJ;AAEA,SAAS,YAAY,QAAgB,WAAyC;AAC5E,QAAM,mBAAmB,uBAAuB,MAAM;AACtD,MAAI,kBAAkB;AACpB,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,kBAAkB,8BAA8B,MAAM;AAAA,IACtD,iBAAiB;AAAA,IACjB,cAAc;AAAA,EAChB;AACF;","names":["selection"]}
@@ -1341,6 +1341,7 @@ var HoveringToolbar = (props) => {
1341
1341
  left = window.innerWidth - el.offsetWidth - minGapFromEdge;
1342
1342
  }
1343
1343
  el.style.opacity = "1";
1344
+ el.style.position = "absolute";
1344
1345
  el.style.top = `${top}px`;
1345
1346
  el.style.left = `${left}px`;
1346
1347
  });