@copilotkit/react-textarea 0.35.0-multi-feature-usecopilotreadable.4 → 0.35.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 (41) hide show
  1. package/.turbo/turbo-build.log +428 -428
  2. package/CHANGELOG.md +92 -8
  3. package/dist/{chunk-3B3LGEDJ.mjs → chunk-COQISBP2.mjs} +2 -2
  4. package/dist/{chunk-FWZ23PN7.mjs → chunk-DMLXXOXD.mjs} +2 -2
  5. package/dist/{chunk-VPEH6V7T.mjs → chunk-FMQG2ZM3.mjs} +1 -1
  6. package/dist/chunk-FMQG2ZM3.mjs.map +1 -0
  7. package/dist/{chunk-Y5LVLSUK.mjs → chunk-OGLVRSCO.mjs} +7 -7
  8. package/dist/{chunk-HXEH4QQL.mjs → chunk-PQIOU3E5.mjs} +5 -5
  9. package/dist/{chunk-RT4UTBH3.mjs → chunk-SJ2TM5GA.mjs} +6 -2
  10. package/dist/chunk-SJ2TM5GA.mjs.map +1 -0
  11. package/dist/{chunk-QFG55HEW.mjs → chunk-XU5Z5BWV.mjs} +20 -20
  12. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
  13. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +16 -16
  14. package/dist/components/copilot-textarea/copilot-textarea.js +5 -1
  15. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  16. package/dist/components/copilot-textarea/copilot-textarea.mjs +23 -23
  17. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +5 -5
  18. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +3 -3
  19. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +4 -4
  20. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +4 -4
  21. package/dist/components/index.js +5 -1
  22. package/dist/components/index.js.map +1 -1
  23. package/dist/components/index.mjs +23 -23
  24. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -1
  25. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +1 -1
  26. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +5 -1
  27. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
  28. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
  29. package/dist/index.js +5 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +27 -27
  32. package/package.json +6 -6
  33. package/src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts +4 -1
  34. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +6 -1
  35. package/dist/chunk-RT4UTBH3.mjs.map +0 -1
  36. package/dist/chunk-VPEH6V7T.mjs.map +0 -1
  37. /package/dist/{chunk-3B3LGEDJ.mjs.map → chunk-COQISBP2.mjs.map} +0 -0
  38. /package/dist/{chunk-FWZ23PN7.mjs.map → chunk-DMLXXOXD.mjs.map} +0 -0
  39. /package/dist/{chunk-Y5LVLSUK.mjs.map → chunk-OGLVRSCO.mjs.map} +0 -0
  40. /package/dist/{chunk-HXEH4QQL.mjs.map → chunk-PQIOU3E5.mjs.map} +0 -0
  41. /package/dist/{chunk-QFG55HEW.mjs.map → chunk-XU5Z5BWV.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,55 +1,55 @@
1
1
  "use client";
2
2
  import "./chunk-DE5K76I2.mjs";
3
3
  import "./chunk-WADHCMPK.mjs";
4
- import "./chunk-IU3WTXLQ.mjs";
5
- import "./chunk-H4VKQGVU.mjs";
6
4
  import "./chunk-MMVDU6DF.mjs";
7
5
  import {
8
6
  CopilotTextarea
9
- } from "./chunk-HXEH4QQL.mjs";
10
- import "./chunk-RT4UTBH3.mjs";
7
+ } from "./chunk-PQIOU3E5.mjs";
8
+ import "./chunk-SJ2TM5GA.mjs";
11
9
  import "./chunk-QCPS6IYI.mjs";
10
+ import "./chunk-RUV6NBIF.mjs";
11
+ import {
12
+ defaultAutosuggestionsConfig
13
+ } from "./chunk-DKE57EAC.mjs";
14
+ import "./chunk-4OJ3H65F.mjs";
15
+ import "./chunk-RKQ6RTZM.mjs";
16
+ import "./chunk-KDVMG3XF.mjs";
12
17
  import {
13
18
  BaseCopilotTextarea
14
- } from "./chunk-QFG55HEW.mjs";
19
+ } from "./chunk-XU5Z5BWV.mjs";
20
+ import "./chunk-DRV2FOHZ.mjs";
21
+ import "./chunk-4NHVQZ67.mjs";
22
+ import "./chunk-FMQG2ZM3.mjs";
15
23
  import "./chunk-2C7O2EVM.mjs";
16
24
  import "./chunk-GQN2HYFJ.mjs";
25
+ import "./chunk-5UNJXFUO.mjs";
26
+ import "./chunk-QKS2IOUH.mjs";
27
+ import "./chunk-JJLQVT7S.mjs";
28
+ import "./chunk-LQ2OWQU7.mjs";
17
29
  import "./chunk-7LSRNPNI.mjs";
18
- import "./chunk-FWZ23PN7.mjs";
30
+ import "./chunk-DMLXXOXD.mjs";
19
31
  import "./chunk-L7VVZH4Q.mjs";
20
- import "./chunk-3B3LGEDJ.mjs";
21
- import "./chunk-Y5LVLSUK.mjs";
32
+ import "./chunk-COQISBP2.mjs";
33
+ import "./chunk-OGLVRSCO.mjs";
22
34
  import "./chunk-YNXNMCDX.mjs";
35
+ import "./chunk-3PQ7GSFE.mjs";
36
+ import "./chunk-WFTAAA7R.mjs";
23
37
  import "./chunk-YFK5BFEI.mjs";
24
38
  import "./chunk-LYB4B6MK.mjs";
25
39
  import "./chunk-CF5GISTC.mjs";
26
40
  import "./chunk-4OZR65UB.mjs";
27
41
  import "./chunk-FFSICDS5.mjs";
28
42
  import "./chunk-4HBKWUCT.mjs";
29
- import "./chunk-WFTAAA7R.mjs";
30
- import "./chunk-3PQ7GSFE.mjs";
31
- import "./chunk-224UKA7C.mjs";
32
- import "./chunk-XW3ICO4S.mjs";
33
- import "./chunk-LQ2OWQU7.mjs";
34
43
  import "./chunk-2QDCE7PD.mjs";
35
- import "./chunk-RUV6NBIF.mjs";
36
- import {
37
- defaultAutosuggestionsConfig
38
- } from "./chunk-DKE57EAC.mjs";
39
- import "./chunk-4OJ3H65F.mjs";
40
- import "./chunk-RKQ6RTZM.mjs";
41
- import "./chunk-KDVMG3XF.mjs";
44
+ import "./chunk-7SUZ6CXM.mjs";
42
45
  import "./chunk-WJHSY5T6.mjs";
43
46
  import {
44
47
  defaultBaseAutosuggestionsConfig
45
48
  } from "./chunk-LCDTIJSD.mjs";
46
- import "./chunk-QKS2IOUH.mjs";
47
- import "./chunk-JJLQVT7S.mjs";
48
- import "./chunk-7SUZ6CXM.mjs";
49
- import "./chunk-DRV2FOHZ.mjs";
50
- import "./chunk-4NHVQZ67.mjs";
51
- import "./chunk-VPEH6V7T.mjs";
52
- import "./chunk-5UNJXFUO.mjs";
49
+ import "./chunk-224UKA7C.mjs";
50
+ import "./chunk-XW3ICO4S.mjs";
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";
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.35.0-multi-feature-usecopilotreadable.4",
7
+ "version": "0.35.0",
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
- "tsconfig": "0.14.0-multi-feature-usecopilotreadable.4",
41
- "tailwind-config": "0.9.0-multi-feature-usecopilotreadable.4",
42
- "eslint-config-custom": "0.10.0-multi-feature-usecopilotreadable.4"
40
+ "eslint-config-custom": "0.10.0",
41
+ "tailwind-config": "0.9.0",
42
+ "tsconfig": "0.14.0"
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.25.0-multi-feature-usecopilotreadable.4",
66
- "@copilotkit/shared": "0.9.0-multi-feature-usecopilotreadable.4"
65
+ "@copilotkit/react-core": "0.25.0",
66
+ "@copilotkit/shared": "0.9.0"
67
67
  },
68
68
  "scripts": {
69
69
  "build": "tsup --clean",
@@ -14,7 +14,10 @@ export function usePopulateCopilotTextareaRef(
14
14
  ref,
15
15
  () => {
16
16
  class Combined {
17
- constructor(private customMethods: CustomMethods, private editorHtmlElement: HTMLElement) {}
17
+ constructor(
18
+ private customMethods: CustomMethods,
19
+ private editorHtmlElement: HTMLElement,
20
+ ) {}
18
21
 
19
22
  [key: string]: any;
20
23
 
@@ -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 { AutosuggestionsBareFunction, MinimalChatGPTMessage } from "../../types";
@@ -26,6 +26,10 @@ export function useMakeStandardAutosuggestionFunction(
26
26
  apiConfig: SuggestionsApiConfig,
27
27
  ): AutosuggestionsBareFunction {
28
28
  const { getContextString, copilotApiConfig } = useContext(CopilotContext);
29
+ const publicApiKey = copilotApiConfig.publicApiKey;
30
+ const headers = {
31
+ ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),
32
+ };
29
33
 
30
34
  return useCallback(
31
35
  async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {
@@ -56,6 +60,7 @@ export function useMakeStandardAutosuggestionFunction(
56
60
  ...apiConfig.forwardedParams,
57
61
  copilotConfig: copilotApiConfig,
58
62
  signal: abortSignal,
63
+ headers: headers,
59
64
  });
60
65
 
61
66
  if (!response.events) {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx"],"sourcesContent":["import { Message } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { AutosuggestionsBareFunction, MinimalChatGPTMessage } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\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 useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[],\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 response = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...apiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n });\n\n if (!response.events) {\n throw new Error(\"Failed to fetch chat completion\");\n }\n\n const reader = response.events.getReader();\n\n let result = \"\";\n while (!abortSignal.aborted) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n result += value;\n }\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose],\n );\n}\n"],"mappings":";;;;;;;;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AAKxC,SAAS,0CAA0C;AAe5C,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,CAAC,GAAG,iBAAiB;AAAA,YACxC;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,WAAW,MAAM,mCAAmC;AAAA,UACxD;AAAA,WACG,UAAU,kBAF2C;AAAA,UAGxD,eAAe;AAAA,UACf,QAAQ;AAAA,QACV,EAAC;AAED,YAAI,CAAC,SAAS,QAAQ;AACpB,gBAAM,IAAI,MAAM,iCAAiC;AAAA,QACnD;AAEA,cAAM,SAAS,SAAS,OAAO,UAAU;AAEzC,YAAI,SAAS;AACb,eAAO,CAAC,YAAY,SAAS;AAC3B,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR;AAAA,UACF;AACA,oBAAU;AAAA,QACZ;AACA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts"],"sourcesContent":["import React from \"react\";\nimport { Editor } from \"slate\";\nimport { ReactEditor } from \"slate-react\";\nimport { getFullEditorTextWithNewlines } from \"../../lib/get-text-around-cursor\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function usePopulateCopilotTextareaRef(\n editor: Editor,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n) {\n React.useImperativeHandle(\n ref,\n () => {\n class Combined {\n constructor(private customMethods: CustomMethods, private editorHtmlElement: HTMLElement) {}\n\n [key: string]: any;\n\n get(target: any, propKey: string): any {\n if (this.isKeyOfCustomMethods(propKey)) {\n const value = this.customMethods[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.customMethods);\n }\n return value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n const value = this.editorHtmlElement[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.editorHtmlElement);\n }\n return value;\n }\n }\n\n set(target: any, propKey: string, value: any): boolean {\n if (this.isKeyOfCustomMethods(propKey)) {\n (this.customMethods as any)[propKey] = value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n (this.editorHtmlElement as any)[propKey] = value;\n } else {\n // Default behavior (optional)\n target[propKey] = value;\n }\n return true;\n }\n\n private isKeyOfCustomMethods(key: string): key is keyof CustomMethods {\n return key in this.customMethods;\n }\n\n private isKeyOfHTMLElement(key: string): key is keyof HTMLElement {\n return key in this.editorHtmlElement;\n }\n }\n\n const handler = {\n get(target: any, propKey: keyof CustomMethods | keyof HTMLElement) {\n return target.get(target, propKey);\n },\n set(target: any, propKey: keyof CustomMethods | keyof HTMLElement, value: any) {\n return target.set(target, propKey, value);\n },\n };\n\n class CustomMethods {\n constructor(private editor: CustomEditor) {}\n\n focus() {\n ReactEditor.focus(this.editor);\n }\n\n blur() {\n ReactEditor.blur(this.editor);\n }\n\n get value() {\n return getFullEditorTextWithNewlines(this.editor);\n }\n set value(value: string) {\n replaceEditorText(this.editor, value);\n }\n }\n\n const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);\n const customMethods = new CustomMethods(editor);\n\n const combined = new Combined(customMethods, editorHtmlElement);\n return new Proxy(combined, handler);\n },\n [editor],\n );\n}\n"],"mappings":";;;;;;;;AAAA,OAAO,WAAW;AAElB,SAAS,mBAAmB;AAMrB,SAAS,8BACd,QACA,KACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA,MAAM;AACJ,YAAM,SAAS;AAAA,QACb,YAAoBA,gBAAsCC,oBAAgC;AAAtE,+BAAAD;AAAsC,mCAAAC;AAAA,QAAiC;AAAA,QAI3F,IAAI,QAAa,SAAsB;AACrC,cAAI,KAAK,qBAAqB,OAAO,GAAG;AACtC,kBAAM,QAAQ,KAAK,cAAc,OAAO;AACxC,gBAAI,OAAO,UAAU,YAAY;AAC/B,qBAAO,MAAM,KAAK,KAAK,aAAa;AAAA,YACtC;AACA,mBAAO;AAAA,UACT,WAAW,KAAK,mBAAmB,OAAO,GAAG;AAC3C,kBAAM,QAAQ,KAAK,kBAAkB,OAAO;AAC5C,gBAAI,OAAO,UAAU,YAAY;AAC/B,qBAAO,MAAM,KAAK,KAAK,iBAAiB;AAAA,YAC1C;AACA,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,QAEA,IAAI,QAAa,SAAiB,OAAqB;AACrD,cAAI,KAAK,qBAAqB,OAAO,GAAG;AACtC,YAAC,KAAK,cAAsB,OAAO,IAAI;AAAA,UACzC,WAAW,KAAK,mBAAmB,OAAO,GAAG;AAC3C,YAAC,KAAK,kBAA0B,OAAO,IAAI;AAAA,UAC7C,OAAO;AAEL,mBAAO,OAAO,IAAI;AAAA,UACpB;AACA,iBAAO;AAAA,QACT;AAAA,QAEQ,qBAAqB,KAAyC;AACpE,iBAAO,OAAO,KAAK;AAAA,QACrB;AAAA,QAEQ,mBAAmB,KAAuC;AAChE,iBAAO,OAAO,KAAK;AAAA,QACrB;AAAA,MACF;AAEA,YAAM,UAAU;AAAA,QACd,IAAI,QAAa,SAAkD;AACjE,iBAAO,OAAO,IAAI,QAAQ,OAAO;AAAA,QACnC;AAAA,QACA,IAAI,QAAa,SAAkD,OAAY;AAC7E,iBAAO,OAAO,IAAI,QAAQ,SAAS,KAAK;AAAA,QAC1C;AAAA,MACF;AAEA,YAAM,cAAc;AAAA,QAClB,YAAoBC,SAAsB;AAAtB,wBAAAA;AAAA,QAAuB;AAAA,QAE3C,QAAQ;AACN,sBAAY,MAAM,KAAK,MAAM;AAAA,QAC/B;AAAA,QAEA,OAAO;AACL,sBAAY,KAAK,KAAK,MAAM;AAAA,QAC9B;AAAA,QAEA,IAAI,QAAQ;AACV,iBAAO,8BAA8B,KAAK,MAAM;AAAA,QAClD;AAAA,QACA,IAAI,MAAM,OAAe;AACvB,4BAAkB,KAAK,QAAQ,KAAK;AAAA,QACtC;AAAA,MACF;AAEA,YAAM,oBAAoB,YAAY,UAAU,QAAQ,MAAM;AAC9D,YAAM,gBAAgB,IAAI,cAAc,MAAM;AAE9C,YAAM,WAAW,IAAI,SAAS,eAAe,iBAAiB;AAC9D,aAAO,IAAI,MAAM,UAAU,OAAO;AAAA,IACpC;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACF;","names":["customMethods","editorHtmlElement","editor"]}