@copilotkit/react-textarea 1.10.7-next.0 → 1.50.0-beta.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.
- package/CHANGELOG.md +0 -8
- package/dist/{chunk-HDBI2WN5.mjs → chunk-2IWVZ4PP.mjs} +17 -27
- package/dist/chunk-2IWVZ4PP.mjs.map +1 -0
- package/dist/{chunk-XW3ICO4S.mjs → chunk-3QJOFG3V.mjs} +1 -1
- package/dist/chunk-3QJOFG3V.mjs.map +1 -0
- package/dist/{chunk-HBWBHJ64.mjs → chunk-4VCJHANC.mjs} +9 -9
- package/dist/{chunk-7WVURIB7.mjs → chunk-5NZNJCP2.mjs} +21 -21
- package/dist/{chunk-2DF2AVDU.mjs → chunk-66KFI242.mjs} +2 -2
- package/dist/{chunk-C3PMJNQA.mjs → chunk-7VADGLV2.mjs} +6 -6
- package/dist/{chunk-RXV67GJN.mjs → chunk-DL3JWL2E.mjs} +4 -2
- package/dist/chunk-DL3JWL2E.mjs.map +1 -0
- package/dist/{chunk-7L6GIHDM.mjs → chunk-F2ULK22F.mjs} +1 -1
- package/dist/chunk-F2ULK22F.mjs.map +1 -0
- package/dist/{chunk-6SGWO63I.mjs → chunk-ISKK3RIW.mjs} +4 -4
- package/dist/chunk-JD7BAH7U.mjs +1 -0
- package/dist/{chunk-LQ2OWQU7.mjs → chunk-JLOABKLH.mjs} +2 -2
- package/dist/{chunk-LQ2OWQU7.mjs.map → chunk-JLOABKLH.mjs.map} +1 -1
- package/dist/{chunk-3PQ7GSFE.mjs → chunk-NAFNY4FL.mjs} +1 -1
- package/dist/chunk-NAFNY4FL.mjs.map +1 -0
- package/dist/{chunk-F6GMWOLE.mjs → chunk-ZQSEYPNN.mjs} +6 -25
- package/dist/chunk-ZQSEYPNN.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +17 -27
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +21 -21
- package/dist/components/base-copilot-textarea/render-element.d.ts +3 -2
- package/dist/components/base-copilot-textarea/render-element.js.map +1 -1
- package/dist/components/base-copilot-textarea/render-element.mjs +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.d.ts +3 -2
- package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.js +24 -48
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +75 -28
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js +16 -26
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.js +16 -26
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +8 -8
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +5 -5
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +6 -6
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +6 -6
- package/dist/components/index.d.ts +2 -11
- package/dist/components/index.js +25 -531
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +23 -35
- package/dist/components/ui/command.d.ts +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +4 -20
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +3 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
- package/dist/hooks/misc/use-autosize-textarea.d.ts +1 -1
- package/dist/hooks/misc/use-autosize-textarea.js.map +1 -1
- package/dist/hooks/misc/use-autosize-textarea.mjs +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +76 -368
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -34
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +2 -2
- package/dist/types/autosuggestions-config/index.mjs +2 -2
- package/dist/types/index.mjs +3 -3
- package/package.json +22 -22
- package/src/components/base-copilot-textarea/render-element.tsx +2 -1
- package/src/components/base-copilot-textarea/render-placeholder.tsx +2 -1
- package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +1 -1
- package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +28 -40
- package/src/components/index.ts +0 -3
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +24 -22
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +2 -1
- package/src/hooks/misc/use-autosize-textarea.tsx +1 -1
- package/dist/chunk-3PQ7GSFE.mjs.map +0 -1
- package/dist/chunk-7L6GIHDM.mjs.map +0 -1
- package/dist/chunk-F6GMWOLE.mjs.map +0 -1
- package/dist/chunk-HDBI2WN5.mjs.map +0 -1
- package/dist/chunk-MMVDU6DF.mjs +0 -1
- package/dist/chunk-NZIHZWRU.mjs +0 -60
- package/dist/chunk-NZIHZWRU.mjs.map +0 -1
- package/dist/chunk-RXV67GJN.mjs.map +0 -1
- package/dist/chunk-XW3ICO4S.mjs.map +0 -1
- /package/dist/{chunk-HBWBHJ64.mjs.map → chunk-4VCJHANC.mjs.map} +0 -0
- /package/dist/{chunk-7WVURIB7.mjs.map → chunk-5NZNJCP2.mjs.map} +0 -0
- /package/dist/{chunk-2DF2AVDU.mjs.map → chunk-66KFI242.mjs.map} +0 -0
- /package/dist/{chunk-C3PMJNQA.mjs.map → chunk-7VADGLV2.mjs.map} +0 -0
- /package/dist/{chunk-6SGWO63I.mjs.map → chunk-ISKK3RIW.mjs.map} +0 -0
- /package/dist/{chunk-MMVDU6DF.mjs.map → chunk-JD7BAH7U.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,32 +9,22 @@ import { css, cx } from "@emotion/css";
|
|
|
9
9
|
import React from "react";
|
|
10
10
|
import ReactDOM from "react-dom";
|
|
11
11
|
import { jsx } from "react/jsx-runtime";
|
|
12
|
-
var Button = React.forwardRef(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
className,
|
|
29
|
-
css`
|
|
30
|
-
cursor: pointer;
|
|
31
|
-
color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
|
|
32
|
-
`
|
|
33
|
-
)
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
);
|
|
12
|
+
var Button = React.forwardRef((_a, ref) => {
|
|
13
|
+
var _b = _a, { className, active, reversed } = _b, props = __objRest(_b, ["className", "active", "reversed"]);
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
"span",
|
|
16
|
+
__spreadProps(__spreadValues({}, props), {
|
|
17
|
+
ref,
|
|
18
|
+
className: cx(
|
|
19
|
+
className,
|
|
20
|
+
css`
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
|
|
23
|
+
`
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
});
|
|
38
28
|
var Icon = React.forwardRef(
|
|
39
29
|
(_a, ref) => {
|
|
40
30
|
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
@@ -110,4 +100,4 @@ export {
|
|
|
110
100
|
Portal,
|
|
111
101
|
Toolbar
|
|
112
102
|
};
|
|
113
|
-
//# sourceMappingURL=chunk-
|
|
103
|
+
//# sourceMappingURL=chunk-2IWVZ4PP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/hovering-toolbar/hovering-toolbar-components.tsx"],"sourcesContent":["import { css, cx } from \"@emotion/css\";\nimport React, { PropsWithChildren, Ref } from \"react\";\nimport ReactDOM from \"react-dom\";\n\ninterface BaseProps {\n className?: string;\n [key: string]: unknown;\n}\n\nexport const Button = React.forwardRef<\n HTMLSpanElement,\n PropsWithChildren<{ active: boolean; reversed: boolean } & BaseProps>\n>(({ className, active, reversed, ...props }, ref) => (\n <span\n {...props}\n ref={ref}\n className={cx(\n className as string,\n css`\n cursor: pointer;\n color: ${reversed ? (active ? \"white\" : \"#aaa\") : active ? \"black\" : \"#ccc\"};\n `,\n )}\n />\n));\n\nexport const Icon = React.forwardRef<HTMLSpanElement, PropsWithChildren<BaseProps>>(\n ({ className, ...props }, ref) => (\n <span\n {...props}\n ref={ref}\n className={cx(\n \"material-icons\",\n className as string,\n css`\n font-size: 18px;\n vertical-align: text-bottom;\n `,\n )}\n />\n ),\n);\n\nexport const Menu = React.forwardRef<HTMLDivElement, PropsWithChildren<BaseProps>>(\n ({ className, ...props }, ref) => {\n return (\n <div\n {...props}\n data-testid=\"menu\"\n ref={ref}\n className={cx(\n className as string,\n css`\n & > * {\n display: inline-block;\n }\n\n & > * + * {\n margin-left: 15px;\n }\n `,\n )}\n />\n );\n },\n);\nexport const Portal = ({ children }: { children: React.ReactNode }) => {\n return typeof document === \"object\" ? ReactDOM.createPortal(children, document.body) : null;\n};\n\nexport const Toolbar = React.forwardRef<HTMLDivElement, PropsWithChildren<BaseProps>>(\n ({ className, ...props }, ref) => (\n <Menu\n {...props}\n ref={ref}\n className={cx(\n className as string,\n css`\n position: relative;\n padding: 1px 18px 17px;\n margin: 0 -20px;\n border-bottom: 2px solid #eee;\n margin-bottom: 20px;\n `,\n )}\n />\n ),\n);\n"],"mappings":";;;;;;;AAAA,SAAS,KAAK,UAAU;AACxB,OAAO,WAAuC;AAC9C,OAAO,cAAc;AAWnB;AAJK,IAAM,SAAS,MAAM,WAG1B,CAAC,IAA2C,QAAK;AAAhD,eAAE,aAAW,QAAQ,SAZxB,IAYG,IAAkC,kBAAlC,IAAkC,CAAhC,aAAW,UAAQ;AACtB;AAAA,IAAC;AAAA,qCACK,QADL;AAAA,MAEC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA;AAAA,iBAEW,WAAY,SAAS,UAAU,SAAU,SAAS,UAAU;AAAA;AAAA,MAEzE;AAAA;AAAA,EACF;AAAA,CACD;AAEM,IAAM,OAAO,MAAM;AAAA,EACxB,CAAC,IAAyB,QAAK;AAA9B,iBAAE,YA3BL,IA2BG,IAAgB,kBAAhB,IAAgB,CAAd;AACD;AAAA,MAAC;AAAA,uCACK,QADL;AAAA,QAEC;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA;AAAA;AAAA;AAAA,QAIF;AAAA;AAAA,IACF;AAAA;AAEJ;AAEO,IAAM,OAAO,MAAM;AAAA,EACxB,CAAC,IAAyB,QAAQ;AAAjC,iBAAE,YA5CL,IA4CG,IAAgB,kBAAhB,IAAgB,CAAd;AACD,WACE;AAAA,MAAC;AAAA,uCACK,QADL;AAAA,QAEC,eAAY;AAAA,QACZ;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QASF;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AACO,IAAM,SAAS,CAAC,EAAE,SAAS,MAAqC;AACrE,SAAO,OAAO,aAAa,WAAW,SAAS,aAAa,UAAU,SAAS,IAAI,IAAI;AACzF;AAEO,IAAM,UAAU,MAAM;AAAA,EAC3B,CAAC,IAAyB,QAAK;AAA9B,iBAAE,YAvEL,IAuEG,IAAgB,kBAAhB,IAAgB,CAAd;AACD;AAAA,MAAC;AAAA,uCACK,QADL;AAAA,QAEC;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOF;AAAA;AAAA,IACF;AAAA;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/base-copilot-textarea/render-placeholder.tsx"],"sourcesContent":["import { RenderPlaceholderProps } from \"slate-react\";\nimport React from \"react\";\n\nexport type RenderPlaceholderFunction = (props: RenderPlaceholderProps) => React.JSX.Element;\n\nexport function makeRenderPlaceholderFunction(\n placeholderStyle?: React.CSSProperties,\n): RenderPlaceholderFunction {\n return (props: RenderPlaceholderProps) => {\n const { style, ...restAttributes } = props.attributes;\n\n return (\n <div\n {...restAttributes}\n style={{\n ...style,\n ...placeholderStyle,\n }}\n >\n {props.children}\n </div>\n );\n };\n}\n"],"mappings":";;;;;;;AAYM;AAPC,SAAS,8BACd,kBAC2B;AAC3B,SAAO,CAAC,UAAkC;AACxC,UAAqC,WAAM,YAAnC,QATZ,IASyC,IAAnB,2BAAmB,IAAnB,CAAV;AAER,WACE;AAAA,MAAC;AAAA,uCACK,iBADL;AAAA,QAEC,OAAO,kCACF,QACA;AAAA,QAGJ,gBAAM;AAAA;AAAA,IACT;AAAA,EAEJ;AACF;","names":[]}
|
|
@@ -2,20 +2,20 @@ import {
|
|
|
2
2
|
IncludedFilesPreview
|
|
3
3
|
} from "./chunk-KMVGEY7Q.mjs";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
SourceSearchBox
|
|
6
|
+
} from "./chunk-WGWQRALG.mjs";
|
|
7
|
+
import {
|
|
8
|
+
Button
|
|
9
|
+
} from "./chunk-4PDYALMP.mjs";
|
|
7
10
|
import {
|
|
8
11
|
Label
|
|
9
12
|
} from "./chunk-D47EKHIF.mjs";
|
|
13
|
+
import {
|
|
14
|
+
use_autosize_textarea_default
|
|
15
|
+
} from "./chunk-NAFNY4FL.mjs";
|
|
10
16
|
import {
|
|
11
17
|
useHoveringEditorContext
|
|
12
18
|
} from "./chunk-LYB4B6MK.mjs";
|
|
13
|
-
import {
|
|
14
|
-
SourceSearchBox
|
|
15
|
-
} from "./chunk-WGWQRALG.mjs";
|
|
16
|
-
import {
|
|
17
|
-
Button
|
|
18
|
-
} from "./chunk-4PDYALMP.mjs";
|
|
19
19
|
import {
|
|
20
20
|
streamPromiseFlatten
|
|
21
21
|
} from "./chunk-2QDCE7PD.mjs";
|
|
@@ -223,4 +223,4 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
223
223
|
export {
|
|
224
224
|
HoveringInsertionPromptBoxCore
|
|
225
225
|
};
|
|
226
|
-
//# sourceMappingURL=chunk-
|
|
226
|
+
//# sourceMappingURL=chunk-4VCJHANC.mjs.map
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAutocompletionsToEditor
|
|
3
|
-
} from "./chunk-2C7O2EVM.mjs";
|
|
4
1
|
import {
|
|
5
2
|
clearAutocompletionsFromEditor
|
|
6
3
|
} from "./chunk-GQN2HYFJ.mjs";
|
|
7
4
|
import {
|
|
8
|
-
|
|
9
|
-
} from "./chunk-
|
|
5
|
+
HoveringToolbar
|
|
6
|
+
} from "./chunk-7VADGLV2.mjs";
|
|
10
7
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
8
|
+
addAutocompletionsToEditor
|
|
9
|
+
} from "./chunk-2C7O2EVM.mjs";
|
|
13
10
|
import {
|
|
14
|
-
|
|
15
|
-
} from "./chunk-
|
|
11
|
+
makeRenderElementFunction
|
|
12
|
+
} from "./chunk-F2ULK22F.mjs";
|
|
16
13
|
import {
|
|
17
|
-
|
|
18
|
-
} from "./chunk-
|
|
14
|
+
makeRenderPlaceholderFunction
|
|
15
|
+
} from "./chunk-3QJOFG3V.mjs";
|
|
16
|
+
import {
|
|
17
|
+
TrackerTextEditedSinceLastCursorMovement
|
|
18
|
+
} from "./chunk-JLOABKLH.mjs";
|
|
19
19
|
import {
|
|
20
20
|
useAddBrandingCss
|
|
21
21
|
} from "./chunk-7LSRNPNI.mjs";
|
|
22
|
-
import {
|
|
23
|
-
HoveringToolbar
|
|
24
|
-
} from "./chunk-C3PMJNQA.mjs";
|
|
25
22
|
import {
|
|
26
23
|
HoveringEditorProvider,
|
|
27
24
|
useHoveringEditorContext
|
|
@@ -30,14 +27,17 @@ import {
|
|
|
30
27
|
defaultBaseAutosuggestionsConfig
|
|
31
28
|
} from "./chunk-F6RLSVG3.mjs";
|
|
32
29
|
import {
|
|
33
|
-
|
|
34
|
-
} from "./chunk-
|
|
30
|
+
useAutosuggestions
|
|
31
|
+
} from "./chunk-23Q6A46J.mjs";
|
|
35
32
|
import {
|
|
36
|
-
|
|
37
|
-
} from "./chunk-
|
|
33
|
+
useCopilotTextareaEditor
|
|
34
|
+
} from "./chunk-DRV2FOHZ.mjs";
|
|
38
35
|
import {
|
|
39
|
-
|
|
40
|
-
} from "./chunk-
|
|
36
|
+
usePopulateCopilotTextareaRef
|
|
37
|
+
} from "./chunk-QJNFNPWH.mjs";
|
|
38
|
+
import {
|
|
39
|
+
replaceEditorText
|
|
40
|
+
} from "./chunk-5UNJXFUO.mjs";
|
|
41
41
|
import {
|
|
42
42
|
getFullEditorTextWithNewlines,
|
|
43
43
|
getTextAroundCollapsedCursor
|
|
@@ -266,4 +266,4 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
|
|
|
266
266
|
export {
|
|
267
267
|
BaseCopilotTextarea
|
|
268
268
|
};
|
|
269
|
-
//# sourceMappingURL=chunk-
|
|
269
|
+
//# sourceMappingURL=chunk-5NZNJCP2.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HoveringInsertionPromptBoxCore
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4VCJHANC.mjs";
|
|
4
4
|
|
|
5
5
|
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -28,4 +28,4 @@ var HoveringInsertionPromptBox = (props) => {
|
|
|
28
28
|
export {
|
|
29
29
|
HoveringInsertionPromptBox
|
|
30
30
|
};
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
31
|
+
//# sourceMappingURL=chunk-66KFI242.mjs.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HoveringInsertionPromptBox
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
useHoveringEditorContext
|
|
6
|
-
} from "./chunk-LYB4B6MK.mjs";
|
|
3
|
+
} from "./chunk-66KFI242.mjs";
|
|
7
4
|
import {
|
|
8
5
|
Menu,
|
|
9
6
|
Portal
|
|
10
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-2IWVZ4PP.mjs";
|
|
8
|
+
import {
|
|
9
|
+
useHoveringEditorContext
|
|
10
|
+
} from "./chunk-LYB4B6MK.mjs";
|
|
11
11
|
import {
|
|
12
12
|
getFullEditorTextWithNewlines,
|
|
13
13
|
getTextAroundSelection
|
|
@@ -117,4 +117,4 @@ function editorState(editor, selection) {
|
|
|
117
117
|
export {
|
|
118
118
|
HoveringToolbar
|
|
119
119
|
};
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
120
|
+
//# sourceMappingURL=chunk-7VADGLV2.mjs.map
|
|
@@ -19,7 +19,9 @@ import {
|
|
|
19
19
|
CopilotRequestType
|
|
20
20
|
} from "@copilotkit/runtime-client-gql";
|
|
21
21
|
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
22
|
-
const
|
|
22
|
+
const runtimeClient = { generateCopilotResponse: (...args) => {
|
|
23
|
+
} };
|
|
24
|
+
const { getContextString, copilotApiConfig } = useCopilotContext();
|
|
23
25
|
const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
24
26
|
function runtimeClientResponseToStringStream(responsePromise) {
|
|
25
27
|
return __async(this, null, function* () {
|
|
@@ -165,4 +167,4 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
|
|
|
165
167
|
export {
|
|
166
168
|
useMakeStandardInsertionOrEditingFunction
|
|
167
169
|
};
|
|
168
|
-
//# sourceMappingURL=chunk-
|
|
170
|
+
//# sourceMappingURL=chunk-DL3JWL2E.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from \"@copilotkit/shared\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback } from \"react\";\nimport {\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n CopilotRequestType,\n} from \"@copilotkit/runtime-client-gql\";\nimport { retry } from \"../../lib/retry\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\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\";\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 runtimeClient: any = { generateCopilotResponse: (...args: any[]) => {} };\n const { getContextString, copilotApiConfig } = useCopilotContext();\n const headers = {\n ...(copilotApiConfig.publicApiKey\n ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }\n : {}),\n };\n\n async function runtimeClientResponseToStringStream(\n responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,\n ) {\n const messagesStream = runtimeClient.asStream(responsePromise);\n\n return new ReadableStream({\n async start(controller) {\n const reader = messagesStream.getReader();\n let sentContent = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);\n\n let newContent = \"\";\n\n for (const message of messages) {\n if (message.isTextMessage()) {\n newContent += message.content;\n }\n }\n if (newContent) {\n const contentToSend = newContent.slice(sentContent.length);\n controller.enqueue(contentToSend);\n sentContent += contentToSend;\n }\n }\n controller.close();\n },\n });\n }\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: Message[] = [\n new TextMessage({\n role: Role.System,\n content: insertionApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n }),\n ...insertionApiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`,\n }),\n ];\n\n return runtimeClientResponseToStringStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n },\n properties: copilotApiConfig.properties,\n signal: abortSignal,\n }),\n );\n });\n\n return res;\n },\n [insertionApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const editingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n editingPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: editingApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n }),\n ...editingApiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`,\n }),\n ];\n\n return runtimeClientResponseToStringStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n },\n properties: copilotApiConfig.properties,\n signal: abortSignal,\n }),\n );\n });\n\n return res;\n },\n [editingApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const insertionOrEditingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n 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":"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","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/base-copilot-textarea/render-element.tsx"],"sourcesContent":["import { RenderElementProps } from \"slate-react\";\nimport React from \"react\";\n\nexport type RenderElementFunction = (props: RenderElementProps) => React.JSX.Element;\n\nexport function makeRenderElementFunction(\n suggestionsStyle: React.CSSProperties,\n): RenderElementFunction {\n return (props: RenderElementProps) => {\n switch (props.element.type) {\n case \"paragraph\":\n return <DefaultElement {...props} />;\n case \"suggestion\":\n return <SuggestionElement {...props} suggestionsStyle={suggestionsStyle} />;\n }\n };\n}\n\nconst DefaultElement = (props: RenderElementProps) => {\n return <div {...props.attributes}>{props.children}</div>;\n};\nconst SuggestionElement = (\n props: RenderElementProps & {\n suggestionsStyle: React.CSSProperties;\n },\n) => {\n return (\n <span\n {...props.attributes}\n style={{\n ...props.suggestionsStyle,\n }}\n data-testid=\"suggestion\"\n contentEditable={false}\n >\n {props.children /* https://github.com/ianstormtaylor/slate/issues/3930 */}\n {props.element.type === \"suggestion\" && props.element.content}\n </span>\n );\n};\n"],"mappings":";;;;;;AAWe,cAgBX,YAhBW;AANR,SAAS,0BACd,kBACuB;AACvB,SAAO,CAAC,UAA8B;AACpC,YAAQ,MAAM,QAAQ,MAAM;AAAA,MAC1B,KAAK;AACH,eAAO,oBAAC,mCAAmB,MAAO;AAAA,MACpC,KAAK;AACH,eAAO,oBAAC,oDAAsB,QAAtB,EAA6B,mBAAoC;AAAA,IAC7E;AAAA,EACF;AACF;AAEA,IAAM,iBAAiB,CAAC,UAA8B;AACpD,SAAO,oBAAC,wCAAQ,MAAM,aAAd,EAA2B,gBAAM,WAAS;AACpD;AACA,IAAM,oBAAoB,CACxB,UAGG;AACH,SACE;AAAA,IAAC;AAAA,qCACK,MAAM,aADX;AAAA,MAEC,OAAO,mBACF,MAAM;AAAA,MAEX,eAAY;AAAA,MACZ,iBAAiB;AAAA,MAEhB;AAAA,cAAM;AAAA,QACN,MAAM,QAAQ,SAAS,gBAAgB,MAAM,QAAQ;AAAA;AAAA;AAAA,EACxD;AAEJ;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defaultInsertionsApiConfig
|
|
3
|
-
} from "./chunk-MCNXIA4Q.mjs";
|
|
4
1
|
import {
|
|
5
2
|
defaultSuggestionsApiConfig
|
|
6
3
|
} from "./chunk-QFXR6DOA.mjs";
|
|
7
4
|
import {
|
|
8
5
|
defaultEditingApiConfig
|
|
9
6
|
} from "./chunk-EJGGLWWR.mjs";
|
|
7
|
+
import {
|
|
8
|
+
defaultInsertionsApiConfig
|
|
9
|
+
} from "./chunk-MCNXIA4Q.mjs";
|
|
10
10
|
import {
|
|
11
11
|
defaultBaseAutosuggestionsConfig
|
|
12
12
|
} from "./chunk-F6RLSVG3.mjs";
|
|
@@ -29,4 +29,4 @@ var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseA
|
|
|
29
29
|
export {
|
|
30
30
|
defaultAutosuggestionsConfig
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-ISKK3RIW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-JD7BAH7U.mjs.map
|
|
@@ -36,7 +36,7 @@ var isSelectionEqual = (a, b) => {
|
|
|
36
36
|
return Range.equals(a, b);
|
|
37
37
|
};
|
|
38
38
|
function usePrevious(value) {
|
|
39
|
-
const ref = useRef();
|
|
39
|
+
const ref = useRef(void 0);
|
|
40
40
|
useEffect(() => {
|
|
41
41
|
ref.current = value;
|
|
42
42
|
});
|
|
@@ -46,4 +46,4 @@ function usePrevious(value) {
|
|
|
46
46
|
export {
|
|
47
47
|
TrackerTextEditedSinceLastCursorMovement
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-JLOABKLH.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { BaseSelection } from \"slate\";\nimport { useSlateSelector } from \"slate-react\";\nimport { Range } from \"slate\";\nimport { editorToText } from \"../../lib/editor-to-text\";\n\ninterface TrackerTextEditedSinceLastCursorMovementProps {\n setCursorMovedSinceLastTextChange: (value: boolean) => void;\n}\nexport function TrackerTextEditedSinceLastCursorMovement(\n props: TrackerTextEditedSinceLastCursorMovementProps,\n) {\n const cursorState: RelevantEditorState = useSlateSelector((state) => ({\n selection: state.selection,\n text: editorToText(state),\n }));\n\n const previousState = usePrevious(cursorState);\n\n useEffect(() => {\n if (!previousState) {\n return;\n }\n\n if (cursorChangedWithoutTextChanged(previousState, cursorState)) {\n props.setCursorMovedSinceLastTextChange(true);\n }\n }, [props.setCursorMovedSinceLastTextChange, cursorState]);\n\n return <></>;\n}\n\ntype RelevantEditorState = {\n selection: BaseSelection;\n text: string;\n};\n\nconst cursorChangedWithoutTextChanged = (\n prev: RelevantEditorState,\n next: RelevantEditorState,\n): boolean => {\n // Check if the selection has changed\n const isSelectionChanged = !isSelectionEqual(prev.selection, next.selection);\n\n // Check if the text content remains the same\n const isTextSame = prev.text === next.text;\n\n return isSelectionChanged && isTextSame;\n};\n\nconst isSelectionEqual = (a: BaseSelection, b: BaseSelection) => {\n if (!a && !b) return true;\n if (!a || !b) return false;\n return Range.equals(a, b);\n};\n\n/**\n * Easily keep track of the *previous* value of a variable.\n *\n * Example:\n * ```\n * const [count, setCount] = useState(0);\n * const prevCount = usePrevious(count);\n *\n * useEffect(() => {\n * if (count > prevCount) {\n * console.log('Now I know that count is bigger than before');\n * }\n * }, [count, prevCount]);\n * ```\n */\nfunction usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n });\n\n return ref.current;\n}\n"],"mappings":";;;;;AAAA,SAAS,WAAW,cAAc;AAElC,SAAS,wBAAwB;AACjC,SAAS,aAAa;AA0Bb;AApBF,SAAS,yCACd,OACA;AACA,QAAM,cAAmC,iBAAiB,CAAC,WAAW;AAAA,IACpE,WAAW,MAAM;AAAA,IACjB,MAAM,aAAa,KAAK;AAAA,EAC1B,EAAE;AAEF,QAAM,gBAAgB,YAAY,WAAW;AAE7C,YAAU,MAAM;AACd,QAAI,CAAC,eAAe;AAClB;AAAA,IACF;AAEA,QAAI,gCAAgC,eAAe,WAAW,GAAG;AAC/D,YAAM,kCAAkC,IAAI;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,MAAM,mCAAmC,WAAW,CAAC;AAEzD,SAAO,gCAAE;AACX;AAOA,IAAM,kCAAkC,CACtC,MACA,SACY;AAEZ,QAAM,qBAAqB,CAAC,iBAAiB,KAAK,WAAW,KAAK,SAAS;AAG3E,QAAM,aAAa,KAAK,SAAS,KAAK;AAEtC,SAAO,sBAAsB;AAC/B;AAEA,IAAM,mBAAmB,CAAC,GAAkB,MAAqB;AAC/D,MAAI,CAAC,KAAK,CAAC;AAAG,WAAO;AACrB,MAAI,CAAC,KAAK,CAAC;AAAG,WAAO;AACrB,SAAO,MAAM,OAAO,GAAG,CAAC;AAC1B;AAiBA,SAAS,YAAe,OAAyB;AAC/C,QAAM,MAAM,OAAU;
|
|
1
|
+
{"version":3,"sources":["../src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { BaseSelection } from \"slate\";\nimport { useSlateSelector } from \"slate-react\";\nimport { Range } from \"slate\";\nimport { editorToText } from \"../../lib/editor-to-text\";\n\ninterface TrackerTextEditedSinceLastCursorMovementProps {\n setCursorMovedSinceLastTextChange: (value: boolean) => void;\n}\nexport function TrackerTextEditedSinceLastCursorMovement(\n props: TrackerTextEditedSinceLastCursorMovementProps,\n) {\n const cursorState: RelevantEditorState = useSlateSelector((state) => ({\n selection: state.selection,\n text: editorToText(state),\n }));\n\n const previousState = usePrevious(cursorState);\n\n useEffect(() => {\n if (!previousState) {\n return;\n }\n\n if (cursorChangedWithoutTextChanged(previousState, cursorState)) {\n props.setCursorMovedSinceLastTextChange(true);\n }\n }, [props.setCursorMovedSinceLastTextChange, cursorState]);\n\n return <></>;\n}\n\ntype RelevantEditorState = {\n selection: BaseSelection;\n text: string;\n};\n\nconst cursorChangedWithoutTextChanged = (\n prev: RelevantEditorState,\n next: RelevantEditorState,\n): boolean => {\n // Check if the selection has changed\n const isSelectionChanged = !isSelectionEqual(prev.selection, next.selection);\n\n // Check if the text content remains the same\n const isTextSame = prev.text === next.text;\n\n return isSelectionChanged && isTextSame;\n};\n\nconst isSelectionEqual = (a: BaseSelection, b: BaseSelection) => {\n if (!a && !b) return true;\n if (!a || !b) return false;\n return Range.equals(a, b);\n};\n\n/**\n * Easily keep track of the *previous* value of a variable.\n *\n * Example:\n * ```\n * const [count, setCount] = useState(0);\n * const prevCount = usePrevious(count);\n *\n * useEffect(() => {\n * if (count > prevCount) {\n * console.log('Now I know that count is bigger than before');\n * }\n * }, [count, prevCount]);\n * ```\n */\nfunction usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T>(undefined!);\n\n useEffect(() => {\n ref.current = value;\n });\n\n return ref.current;\n}\n"],"mappings":";;;;;AAAA,SAAS,WAAW,cAAc;AAElC,SAAS,wBAAwB;AACjC,SAAS,aAAa;AA0Bb;AApBF,SAAS,yCACd,OACA;AACA,QAAM,cAAmC,iBAAiB,CAAC,WAAW;AAAA,IACpE,WAAW,MAAM;AAAA,IACjB,MAAM,aAAa,KAAK;AAAA,EAC1B,EAAE;AAEF,QAAM,gBAAgB,YAAY,WAAW;AAE7C,YAAU,MAAM;AACd,QAAI,CAAC,eAAe;AAClB;AAAA,IACF;AAEA,QAAI,gCAAgC,eAAe,WAAW,GAAG;AAC/D,YAAM,kCAAkC,IAAI;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,MAAM,mCAAmC,WAAW,CAAC;AAEzD,SAAO,gCAAE;AACX;AAOA,IAAM,kCAAkC,CACtC,MACA,SACY;AAEZ,QAAM,qBAAqB,CAAC,iBAAiB,KAAK,WAAW,KAAK,SAAS;AAG3E,QAAM,aAAa,KAAK,SAAS,KAAK;AAEtC,SAAO,sBAAsB;AAC/B;AAEA,IAAM,mBAAmB,CAAC,GAAkB,MAAqB;AAC/D,MAAI,CAAC,KAAK,CAAC;AAAG,WAAO;AACrB,MAAI,CAAC,KAAK,CAAC;AAAG,WAAO;AACrB,SAAO,MAAM,OAAO,GAAG,CAAC;AAC1B;AAiBA,SAAS,YAAe,OAAyB;AAC/C,QAAM,MAAM,OAAU,MAAU;AAEhC,YAAU,MAAM;AACd,QAAI,UAAU;AAAA,EAChB,CAAC;AAED,SAAO,IAAI;AACb;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/misc/use-autosize-textarea.tsx"],"sourcesContent":["import { Ref, RefObject, useEffect } from \"react\";\n\n// Updates the height of a <textarea> when the value changes.\nconst useAutosizeTextArea = (textAreaRef: RefObject<HTMLTextAreaElement | null>, value: string) => {\n useEffect(() => {\n if (textAreaRef.current !== null) {\n // We need to reset the height momentarily to get the correct scrollHeight for the textarea\n textAreaRef.current.style.height = \"0px\";\n const scrollHeight = textAreaRef.current.scrollHeight;\n\n // We then set the height directly, outside of the render loop\n // Trying to set this with state or a ref will product an incorrect value.\n textAreaRef.current.style.height = scrollHeight + \"px\";\n }\n }, [textAreaRef, value]);\n};\n\nexport default useAutosizeTextArea;\n"],"mappings":";AAAA,SAAyB,iBAAiB;AAG1C,IAAM,sBAAsB,CAAC,aAAoD,UAAkB;AACjG,YAAU,MAAM;AACd,QAAI,YAAY,YAAY,MAAM;AAEhC,kBAAY,QAAQ,MAAM,SAAS;AACnC,YAAM,eAAe,YAAY,QAAQ;AAIzC,kBAAY,QAAQ,MAAM,SAAS,eAAe;AAAA,IACpD;AAAA,EACF,GAAG,CAAC,aAAa,KAAK,CAAC;AACzB;AAEA,IAAO,gCAAQ;","names":[]}
|
|
@@ -13,13 +13,12 @@ import { useCallback } from "react";
|
|
|
13
13
|
import {
|
|
14
14
|
Role,
|
|
15
15
|
TextMessage,
|
|
16
|
-
convertGqlOutputToMessages
|
|
17
|
-
convertMessagesToGqlInput,
|
|
18
|
-
filterAgentStateMessages,
|
|
19
|
-
CopilotRequestType
|
|
16
|
+
convertGqlOutputToMessages
|
|
20
17
|
} from "@copilotkit/runtime-client-gql";
|
|
21
18
|
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
22
|
-
const
|
|
19
|
+
const runtimeClient = { generateCopilotResponse: (...args) => {
|
|
20
|
+
} };
|
|
21
|
+
const { getContextString, copilotApiConfig } = useCopilotContext();
|
|
23
22
|
const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
|
|
24
23
|
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
25
24
|
const { maxTokens, stop, temperature = 0 } = apiConfig;
|
|
@@ -49,25 +48,7 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
49
48
|
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
50
49
|
})
|
|
51
50
|
].filter(Boolean);
|
|
52
|
-
const response =
|
|
53
|
-
data: {
|
|
54
|
-
frontend: {
|
|
55
|
-
actions: [],
|
|
56
|
-
url: window.location.href
|
|
57
|
-
},
|
|
58
|
-
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
59
|
-
metadata: {
|
|
60
|
-
requestType: CopilotRequestType.TextareaCompletion
|
|
61
|
-
},
|
|
62
|
-
forwardedParameters: {
|
|
63
|
-
maxTokens,
|
|
64
|
-
stop,
|
|
65
|
-
temperature
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
properties,
|
|
69
|
-
signal: abortSignal
|
|
70
|
-
}).toPromise();
|
|
51
|
+
const response = {};
|
|
71
52
|
let result = "";
|
|
72
53
|
for (const message of convertGqlOutputToMessages(
|
|
73
54
|
(_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
|
|
@@ -90,4 +71,4 @@ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategorie
|
|
|
90
71
|
export {
|
|
91
72
|
useMakeStandardAutosuggestionFunction
|
|
92
73
|
};
|
|
93
|
-
//# sourceMappingURL=chunk-
|
|
74
|
+
//# sourceMappingURL=chunk-ZQSEYPNN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from \"@copilotkit/shared\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback } from \"react\";\nimport { AutosuggestionsBareFunction } 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 {\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n CopilotRequestType,\n} from \"@copilotkit/runtime-client-gql\";\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 runtimeClient = { generateCopilotResponse: (...args: any[]) => {} };\n const { getContextString, copilotApiConfig } = useCopilotContext();\n const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;\n const headers = {\n ...copilotApiConfig.headers,\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n const { maxTokens, stop, temperature = 0 } = apiConfig;\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n // @ts-expect-error -- Passing null is forbidden, but we're filtering it later\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString([], contextCategories),\n ),\n }),\n ...apiConfig.fewShotMessages,\n editorState.textAfterCursor != \"\"\n ? new TextMessage({\n role: Role.User,\n content: editorState.textAfterCursor,\n })\n : null,\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n ].filter(Boolean);\n\n // const response = await runtimeClient\n // .generateCopilotResponse({\n // data: {\n // frontend: {\n // actions: [],\n // url: window.location.href,\n // },\n // messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n // metadata: {\n // requestType: CopilotRequestType.TextareaCompletion,\n // },\n // forwardedParameters: {\n // maxTokens,\n // stop,\n // temperature,\n // },\n // },\n // properties,\n // signal: abortSignal,\n // })\n // .toPromise();\n const response: any = {};\n\n let result = \"\";\n for (const message of convertGqlOutputToMessages(\n response.data?.generateCopilotResponse?.messages ?? [],\n )) {\n if (abortSignal.aborted) {\n break;\n }\n if (message.isTextMessage()) {\n result += message.content;\n }\n }\n\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose],\n );\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,2CAA2C;AACpD,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAK5B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAeA,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,gBAAgB,EAAE,yBAAyB,IAAI,SAAgB;AAAA,EAAC,EAAE;AACxE,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,kBAAkB;AACjE,QAAM,EAAE,iBAAiB,KAAK,cAAc,aAAa,WAAW,IAAI;AACxE,QAAM,UAAU,kCACX,iBAAiB,UAChB,eAAe,EAAE,CAAC,mCAAmC,GAAG,aAAa,IAAI,CAAC;AAEhF,QAAM,EAAE,WAAW,MAAM,cAAc,EAAE,IAAI;AAE7C,SAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AA9C1C;AAgDQ,cAAM,WAAsB;AAAA,UAC1B,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,UAAU;AAAA,cACjB;AAAA,cACA,iBAAiB,CAAC,GAAG,iBAAiB;AAAA,YACxC;AAAA,UACF,CAAC;AAAA,UACD,GAAG,UAAU;AAAA,UACb,YAAY,mBAAmB,KAC3B,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,YAAY;AAAA,UACvB,CAAC,IACD;AAAA,UACJ,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,oBAAoB,YAAY;AAAA,UAC3C,CAAC;AAAA,UACD,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,qBAAqB,YAAY;AAAA,UAC5C,CAAC;AAAA,QACH,EAAE,OAAO,OAAO;AAuBhB,cAAM,WAAgB,CAAC;AAEvB,YAAI,SAAS;AACb,mBAAW,WAAW;AAAA,WACpB,0BAAS,SAAT,mBAAe,4BAAf,mBAAwC,aAAxC,YAAoD,CAAC;AAAA,QACvD,GAAG;AACD,cAAI,YAAY,SAAS;AACvB;AAAA,UACF;AACA,cAAI,QAAQ,cAAc,GAAG;AAC3B,sBAAU,QAAQ;AAAA,UACpB;AAAA,QACF;AAEA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF;","names":[]}
|
|
@@ -677,32 +677,22 @@ var import_css = require("@emotion/css");
|
|
|
677
677
|
var import_react5 = __toESM(require("react"));
|
|
678
678
|
var import_react_dom = __toESM(require("react-dom"));
|
|
679
679
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
680
|
-
var Button = import_react5.default.forwardRef(
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
className,
|
|
697
|
-
import_css.css`
|
|
698
|
-
cursor: pointer;
|
|
699
|
-
color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
|
|
700
|
-
`
|
|
701
|
-
)
|
|
702
|
-
})
|
|
703
|
-
);
|
|
704
|
-
}
|
|
705
|
-
);
|
|
680
|
+
var Button = import_react5.default.forwardRef((_a, ref) => {
|
|
681
|
+
var _b = _a, { className, active, reversed } = _b, props = __objRest(_b, ["className", "active", "reversed"]);
|
|
682
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
683
|
+
"span",
|
|
684
|
+
__spreadProps(__spreadValues({}, props), {
|
|
685
|
+
ref,
|
|
686
|
+
className: (0, import_css.cx)(
|
|
687
|
+
className,
|
|
688
|
+
import_css.css`
|
|
689
|
+
cursor: pointer;
|
|
690
|
+
color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
|
|
691
|
+
`
|
|
692
|
+
)
|
|
693
|
+
})
|
|
694
|
+
);
|
|
695
|
+
});
|
|
706
696
|
var Icon = import_react5.default.forwardRef(
|
|
707
697
|
(_a, ref) => {
|
|
708
698
|
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
@@ -1567,7 +1557,7 @@ var isSelectionEqual = (a, b) => {
|
|
|
1567
1557
|
return import_slate9.Range.equals(a, b);
|
|
1568
1558
|
};
|
|
1569
1559
|
function usePrevious(value) {
|
|
1570
|
-
const ref = (0, import_react11.useRef)();
|
|
1560
|
+
const ref = (0, import_react11.useRef)(void 0);
|
|
1571
1561
|
(0, import_react11.useEffect)(() => {
|
|
1572
1562
|
ref.current = value;
|
|
1573
1563
|
});
|