@copilotkit/react-textarea 0.37.0 → 0.38.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/.turbo/turbo-build.log +216 -224
- package/CHANGELOG.md +13 -0
- package/dist/chunk-3SVQJA5A.mjs +169 -0
- package/dist/chunk-3SVQJA5A.mjs.map +1 -0
- package/dist/chunk-5KLAWLCD.mjs +88 -0
- package/dist/chunk-5KLAWLCD.mjs.map +1 -0
- package/dist/{chunk-QKS2IOUH.mjs → chunk-7QFH4E7C.mjs} +7 -5
- package/dist/chunk-7QFH4E7C.mjs.map +1 -0
- package/dist/chunk-CVO5T3PA.mjs +82 -0
- package/dist/chunk-CVO5T3PA.mjs.map +1 -0
- package/dist/{chunk-DKE57EAC.mjs → chunk-H3PGQHLG.mjs} +5 -5
- package/dist/{chunk-RKQ6RTZM.mjs → chunk-I6DJQ7D7.mjs} +33 -38
- package/dist/chunk-I6DJQ7D7.mjs.map +1 -0
- package/dist/{chunk-VAJHETSN.mjs → chunk-IF7CDWEH.mjs} +5 -5
- package/dist/{chunk-VAJHETSN.mjs.map → chunk-IF7CDWEH.mjs.map} +1 -1
- package/dist/{chunk-LCDTIJSD.mjs → chunk-OJXLHIYQ.mjs} +4 -2
- package/dist/chunk-OJXLHIYQ.mjs.map +1 -0
- package/dist/{chunk-ZRKQLLC7.mjs → chunk-R77MK6QS.mjs} +10 -5
- package/dist/{chunk-ZRKQLLC7.mjs.map → chunk-R77MK6QS.mjs.map} +1 -1
- package/dist/{chunk-O4LDWYJB.mjs → chunk-TNGDQV3I.mjs} +1 -2
- package/dist/{chunk-O4LDWYJB.mjs.map → chunk-TNGDQV3I.mjs.map} +1 -1
- package/dist/{chunk-KDVMG3XF.mjs → chunk-WMHVBGPR.mjs} +23 -25
- package/dist/chunk-WMHVBGPR.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +15 -7
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +4 -4
- package/dist/components/copilot-textarea/copilot-textarea.d.ts +2 -2
- package/dist/components/copilot-textarea/copilot-textarea.js +255 -207
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +11 -11
- package/dist/components/hovering-toolbar/hovering-toolbar.js +0 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +251 -203
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +11 -11
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +2 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +6 -4
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +39 -31
- 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.d.ts +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +100 -60
- 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/index.d.ts +1 -1
- package/dist/index.js +251 -203
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.js +96 -108
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +5 -5
- package/dist/types/autosuggestions-config/editing-api-config.d.ts +3 -3
- package/dist/types/autosuggestions-config/editing-api-config.js +39 -46
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +1 -1
- package/dist/types/autosuggestions-config/index.d.ts +1 -1
- package/dist/types/autosuggestions-config/index.js +96 -108
- package/dist/types/autosuggestions-config/index.js.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +5 -5
- package/dist/types/autosuggestions-config/insertions-api-config.d.ts +3 -3
- package/dist/types/autosuggestions-config/insertions-api-config.js +32 -37
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +3 -3
- package/dist/types/autosuggestions-config/suggestions-api-config.js +22 -24
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +1 -1
- package/dist/types/base/base-autosuggestions-config.d.ts +14 -0
- package/dist/types/base/base-autosuggestions-config.js +3 -1
- package/dist/types/base/base-autosuggestions-config.js.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +1 -1
- package/dist/types/base/index.js +3 -1
- package/dist/types/base/index.js.map +1 -1
- package/dist/types/base/index.mjs +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +96 -108
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +5 -5
- package/package.json +7 -6
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +5 -0
- package/src/components/copilot-textarea/copilot-textarea.tsx +1 -1
- package/src/components/hovering-toolbar/hovering-toolbar.tsx +0 -1
- package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +11 -4
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +51 -31
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +116 -62
- package/src/types/autosuggestions-config/editing-api-config.tsx +48 -49
- package/src/types/autosuggestions-config/index.ts +0 -1
- package/src/types/autosuggestions-config/insertions-api-config.tsx +38 -40
- package/src/types/autosuggestions-config/suggestions-api-config.tsx +26 -27
- package/src/types/base/base-autosuggestions-config.tsx +17 -0
- package/dist/chunk-4OJ3H65F.mjs +0 -89
- package/dist/chunk-4OJ3H65F.mjs.map +0 -1
- package/dist/chunk-HE4GMS2P.mjs +0 -121
- package/dist/chunk-HE4GMS2P.mjs.map +0 -1
- package/dist/chunk-KDVMG3XF.mjs.map +0 -1
- package/dist/chunk-LCDTIJSD.mjs.map +0 -1
- package/dist/chunk-QKS2IOUH.mjs.map +0 -1
- package/dist/chunk-RKQ6RTZM.mjs.map +0 -1
- package/dist/chunk-SJ2TM5GA.mjs +0 -72
- package/dist/chunk-SJ2TM5GA.mjs.map +0 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.d.ts +0 -7
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js +0 -19
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +0 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +0 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +0 -1
- package/src/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.tsx +0 -5
- /package/dist/{chunk-DKE57EAC.mjs.map → chunk-H3PGQHLG.mjs.map} +0 -0
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.38.0-beta.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"**/*.css"
|
|
10
10
|
],
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"ts-jest": "^29.1.1",
|
|
39
39
|
"tsup": "^6.7.0",
|
|
40
40
|
"typescript": "^5.2.3",
|
|
41
|
-
"eslint-config-custom": "0.
|
|
42
|
-
"tailwind-config": "0.
|
|
43
|
-
"tsconfig": "0.
|
|
41
|
+
"eslint-config-custom": "0.13.0-beta.0",
|
|
42
|
+
"tailwind-config": "0.12.0-beta.0",
|
|
43
|
+
"tsconfig": "0.17.0-beta.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@emotion/css": "^11.11.2",
|
|
@@ -63,8 +63,9 @@
|
|
|
63
63
|
"slate-history": "^0.93.0",
|
|
64
64
|
"slate-react": "^0.98.1",
|
|
65
65
|
"tailwind-merge": "^1.13.2",
|
|
66
|
-
"@copilotkit/react-core": "0.
|
|
67
|
-
"@copilotkit/
|
|
66
|
+
"@copilotkit/react-core": "0.38.0-beta.0",
|
|
67
|
+
"@copilotkit/runtime-client-gql": "0.38.0-beta.0",
|
|
68
|
+
"@copilotkit/shared": "0.38.0-beta.0"
|
|
68
69
|
},
|
|
69
70
|
"scripts": {
|
|
70
71
|
"build": "tsup --clean",
|
|
@@ -134,9 +134,11 @@ const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
|
|
|
134
134
|
currentAutocompleteSuggestion,
|
|
135
135
|
onChangeHandler: onChangeHandlerForAutocomplete,
|
|
136
136
|
onKeyDownHandler: onKeyDownHandlerForAutocomplete,
|
|
137
|
+
onTouchStartHandler: onTouchStartHandlerForAutocomplete,
|
|
137
138
|
} = useAutosuggestions(
|
|
138
139
|
autosuggestionsConfig.debounceTime,
|
|
139
140
|
autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,
|
|
141
|
+
autosuggestionsConfig.shouldAcceptAutosuggestionOnTouch,
|
|
140
142
|
autosuggestionsConfig.apiConfig.autosuggestionsFunction,
|
|
141
143
|
insertText,
|
|
142
144
|
autosuggestionsConfig.disableWhenEmpty,
|
|
@@ -271,6 +273,9 @@ const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
|
|
|
271
273
|
onKeyDownHandlerForAutocomplete(event); // forward the event for internal use
|
|
272
274
|
props.onKeyDown?.(event); // forward the event for external use
|
|
273
275
|
}}
|
|
276
|
+
onTouchStart={(event) => {
|
|
277
|
+
onTouchStartHandlerForAutocomplete(event); // forward the event for internal use
|
|
278
|
+
}}
|
|
274
279
|
className={moddedClassName}
|
|
275
280
|
onBlur={(ev) => {
|
|
276
281
|
// clear autocompletion on blur
|
|
@@ -107,7 +107,7 @@ export interface CopilotTextareaProps
|
|
|
107
107
|
* // use this to provide a custom system prompt
|
|
108
108
|
* makeSystemPrompt: (textareaPurpose: string, contextString: string) => string;
|
|
109
109
|
* // custom few shot messages
|
|
110
|
-
* fewShotMessages:
|
|
110
|
+
* fewShotMessages: Message[];
|
|
111
111
|
* forwardedParams: {
|
|
112
112
|
* // max number of tokens to generate
|
|
113
113
|
* max_tokens: number,
|
|
@@ -120,7 +120,6 @@ export const HoveringToolbar = (props: HoveringToolbarProps) => {
|
|
|
120
120
|
setIsDisplayed(false);
|
|
121
121
|
}}
|
|
122
122
|
performInsertion={(insertedText) => {
|
|
123
|
-
console.log("inserted text", insertedText);
|
|
124
123
|
// replace the selection with the inserted text
|
|
125
124
|
Transforms.delete(editor, { at: selection });
|
|
126
125
|
Transforms.insertText(editor, insertedText, {
|
|
@@ -12,11 +12,13 @@ export interface UseAutosuggestionsResult {
|
|
|
12
12
|
currentAutocompleteSuggestion: AutosuggestionState | null;
|
|
13
13
|
onChangeHandler: (newEditorState: EditorAutocompleteState | null) => void;
|
|
14
14
|
onKeyDownHandler: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
15
|
+
onTouchStartHandler: (event: React.TouchEvent<HTMLDivElement>) => void;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export function useAutosuggestions(
|
|
18
19
|
debounceTime: number,
|
|
19
20
|
shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean,
|
|
21
|
+
shouldAcceptAutosuggestionOnTouch: (event: React.TouchEvent<HTMLDivElement>) => boolean,
|
|
20
22
|
autosuggestionFunction: AutosuggestionsBareFunction,
|
|
21
23
|
insertAutocompleteSuggestion: (suggestion: AutosuggestionState) => void,
|
|
22
24
|
disableWhenEmpty: boolean,
|
|
@@ -108,10 +110,14 @@ export function useAutosuggestions(
|
|
|
108
110
|
],
|
|
109
111
|
);
|
|
110
112
|
|
|
111
|
-
const
|
|
112
|
-
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
113
|
+
const keyDownOrTouchHandler = useCallback(
|
|
114
|
+
(event: React.KeyboardEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement>) => {
|
|
113
115
|
if (currentAutocompleteSuggestion) {
|
|
114
|
-
|
|
116
|
+
const shouldAcceptSuggestion =
|
|
117
|
+
event instanceof KeyboardEvent
|
|
118
|
+
? shouldAcceptAutosuggestionOnKeyPress(event as React.KeyboardEvent<HTMLDivElement>)
|
|
119
|
+
: shouldAcceptAutosuggestionOnTouch(event as React.TouchEvent<HTMLDivElement>);
|
|
120
|
+
if (shouldAcceptSuggestion) {
|
|
115
121
|
event.preventDefault();
|
|
116
122
|
insertAutocompleteSuggestion(currentAutocompleteSuggestion);
|
|
117
123
|
setCurrentAutocompleteSuggestion(null);
|
|
@@ -129,6 +135,7 @@ export function useAutosuggestions(
|
|
|
129
135
|
return {
|
|
130
136
|
currentAutocompleteSuggestion,
|
|
131
137
|
onChangeHandler: onChange,
|
|
132
|
-
onKeyDownHandler:
|
|
138
|
+
onKeyDownHandler: keyDownOrTouchHandler,
|
|
139
|
+
onTouchStartHandler: keyDownOrTouchHandler,
|
|
133
140
|
};
|
|
134
141
|
}
|
package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER
|
|
1
|
+
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
2
2
|
import { CopilotContext } from "@copilotkit/react-core";
|
|
3
3
|
import { useCallback, useContext } from "react";
|
|
4
|
-
import { AutosuggestionsBareFunction
|
|
4
|
+
import { AutosuggestionsBareFunction } from "../../types";
|
|
5
5
|
import { retry } from "../../lib/retry";
|
|
6
6
|
import { InsertionEditorState } from "../../types/base/autosuggestions-bare-function";
|
|
7
7
|
import { SuggestionsApiConfig } from "../../types/autosuggestions-config/suggestions-api-config";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
CopilotRuntimeClient,
|
|
10
|
+
Message,
|
|
11
|
+
Role,
|
|
12
|
+
TextMessage,
|
|
13
|
+
convertGqlOutputToMessages,
|
|
14
|
+
convertMessagesToGqlInput,
|
|
15
|
+
} from "@copilotkit/runtime-client-gql";
|
|
16
|
+
import { nanoid } from "nanoid";
|
|
9
17
|
|
|
10
18
|
/**
|
|
11
19
|
* Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
@@ -34,49 +42,61 @@ export function useMakeStandardAutosuggestionFunction(
|
|
|
34
42
|
return useCallback(
|
|
35
43
|
async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {
|
|
36
44
|
const res = await retry(async () => {
|
|
37
|
-
const messages:
|
|
38
|
-
{
|
|
39
|
-
role:
|
|
45
|
+
const messages: Message[] = [
|
|
46
|
+
new TextMessage({
|
|
47
|
+
role: Role.System,
|
|
40
48
|
content: apiConfig.makeSystemPrompt(
|
|
41
49
|
textareaPurpose,
|
|
42
50
|
getContextString([], contextCategories),
|
|
43
51
|
),
|
|
44
|
-
},
|
|
52
|
+
}),
|
|
45
53
|
...apiConfig.fewShotMessages,
|
|
46
|
-
{
|
|
47
|
-
role:
|
|
48
|
-
name: "TextAfterCursor",
|
|
54
|
+
new TextMessage({
|
|
55
|
+
role: Role.User,
|
|
49
56
|
content: editorState.textAfterCursor,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
role:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
}),
|
|
58
|
+
new TextMessage({
|
|
59
|
+
role: Role.User,
|
|
60
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
|
|
61
|
+
}),
|
|
62
|
+
new TextMessage({
|
|
63
|
+
role: Role.User,
|
|
64
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
|
|
65
|
+
}),
|
|
56
66
|
];
|
|
57
67
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
signal: abortSignal,
|
|
63
|
-
headers: headers,
|
|
68
|
+
const runtimeClient = new CopilotRuntimeClient({
|
|
69
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
70
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
71
|
+
headers: copilotApiConfig.headers,
|
|
64
72
|
});
|
|
65
73
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
const response = await runtimeClient
|
|
75
|
+
.generateCopilotResponse(
|
|
76
|
+
{
|
|
77
|
+
frontend: {
|
|
78
|
+
actions: [],
|
|
79
|
+
},
|
|
80
|
+
messages: convertMessagesToGqlInput(messages),
|
|
81
|
+
},
|
|
82
|
+
copilotApiConfig.properties,
|
|
83
|
+
abortSignal,
|
|
84
|
+
)
|
|
85
|
+
.toPromise();
|
|
71
86
|
|
|
72
87
|
let result = "";
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
for (const message of convertGqlOutputToMessages(
|
|
89
|
+
response.data?.generateCopilotResponse?.messages ?? [],
|
|
90
|
+
)) {
|
|
91
|
+
if (abortSignal.aborted) {
|
|
76
92
|
break;
|
|
77
93
|
}
|
|
78
|
-
|
|
94
|
+
if (message instanceof TextMessage) {
|
|
95
|
+
result += message.content;
|
|
96
|
+
console.log(message.content);
|
|
97
|
+
}
|
|
79
98
|
}
|
|
99
|
+
|
|
80
100
|
return result;
|
|
81
101
|
});
|
|
82
102
|
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER
|
|
1
|
+
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
2
2
|
import { CopilotContext } from "@copilotkit/react-core";
|
|
3
3
|
import { useCallback, useContext } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CopilotRuntimeClient,
|
|
6
|
+
Message,
|
|
7
|
+
Role,
|
|
8
|
+
TextMessage,
|
|
9
|
+
convertGqlOutputToMessages,
|
|
10
|
+
convertMessagesToGqlInput,
|
|
11
|
+
} from "@copilotkit/runtime-client-gql";
|
|
5
12
|
import { retry } from "../../lib/retry";
|
|
6
13
|
import {
|
|
7
14
|
EditingEditorState,
|
|
8
15
|
Generator_InsertionOrEditingSuggestion,
|
|
9
|
-
InsertionEditorApiConfig,
|
|
10
|
-
InsertionEditorState,
|
|
11
16
|
} from "../../types/base/autosuggestions-bare-function";
|
|
12
17
|
import { InsertionsApiConfig } from "../../types/autosuggestions-config/insertions-api-config";
|
|
13
18
|
import { EditingApiConfig } from "../../types/autosuggestions-config/editing-api-config";
|
|
14
19
|
import { DocumentPointer } from "@copilotkit/react-core";
|
|
15
|
-
import {
|
|
20
|
+
import { nanoid } from "nanoid";
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
23
|
* Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
@@ -40,6 +45,48 @@ export function useMakeStandardInsertionOrEditingFunction(
|
|
|
40
45
|
: {}),
|
|
41
46
|
};
|
|
42
47
|
|
|
48
|
+
const runtimeClient = new CopilotRuntimeClient({
|
|
49
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
50
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
51
|
+
headers,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
async function runtimeClientResponseToStringStream(
|
|
55
|
+
responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,
|
|
56
|
+
) {
|
|
57
|
+
const messagesStream = await CopilotRuntimeClient.asStream(responsePromise);
|
|
58
|
+
|
|
59
|
+
return new ReadableStream({
|
|
60
|
+
async start(controller) {
|
|
61
|
+
const reader = messagesStream.getReader();
|
|
62
|
+
let sentContent = "";
|
|
63
|
+
|
|
64
|
+
while (true) {
|
|
65
|
+
const { done, value } = await reader.read();
|
|
66
|
+
if (done) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);
|
|
71
|
+
|
|
72
|
+
let newContent = "";
|
|
73
|
+
|
|
74
|
+
for (const message of messages) {
|
|
75
|
+
if (message instanceof TextMessage) {
|
|
76
|
+
newContent += message.content;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (newContent) {
|
|
80
|
+
const contentToSend = newContent.slice(sentContent.length);
|
|
81
|
+
controller.enqueue(contentToSend);
|
|
82
|
+
sentContent += contentToSend;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
controller.close();
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
43
90
|
const insertionFunction = useCallback(
|
|
44
91
|
async (
|
|
45
92
|
editorState: EditingEditorState,
|
|
@@ -48,40 +95,41 @@ export function useMakeStandardInsertionOrEditingFunction(
|
|
|
48
95
|
abortSignal: AbortSignal,
|
|
49
96
|
) => {
|
|
50
97
|
const res = await retry(async () => {
|
|
51
|
-
const messages:
|
|
52
|
-
{
|
|
53
|
-
role:
|
|
98
|
+
const messages: Message[] = [
|
|
99
|
+
new TextMessage({
|
|
100
|
+
role: Role.System,
|
|
54
101
|
content: insertionApiConfig.makeSystemPrompt(
|
|
55
102
|
textareaPurpose,
|
|
56
103
|
getContextString(documents, contextCategories),
|
|
57
104
|
),
|
|
58
|
-
},
|
|
105
|
+
}),
|
|
59
106
|
...insertionApiConfig.fewShotMessages,
|
|
60
|
-
{
|
|
61
|
-
role:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
name: "InsertionPrompt",
|
|
73
|
-
content: insertionPrompt,
|
|
74
|
-
},
|
|
107
|
+
new TextMessage({
|
|
108
|
+
role: Role.User,
|
|
109
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
|
|
110
|
+
}),
|
|
111
|
+
new TextMessage({
|
|
112
|
+
role: Role.User,
|
|
113
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
|
|
114
|
+
}),
|
|
115
|
+
new TextMessage({
|
|
116
|
+
role: Role.User,
|
|
117
|
+
content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`,
|
|
118
|
+
}),
|
|
75
119
|
];
|
|
76
120
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
121
|
+
return runtimeClientResponseToStringStream(
|
|
122
|
+
runtimeClient.generateCopilotResponse(
|
|
123
|
+
{
|
|
124
|
+
frontend: {
|
|
125
|
+
actions: [],
|
|
126
|
+
},
|
|
127
|
+
messages: convertMessagesToGqlInput(messages),
|
|
128
|
+
},
|
|
129
|
+
copilotApiConfig.properties,
|
|
130
|
+
abortSignal,
|
|
131
|
+
),
|
|
132
|
+
);
|
|
85
133
|
});
|
|
86
134
|
|
|
87
135
|
return res;
|
|
@@ -97,45 +145,51 @@ export function useMakeStandardInsertionOrEditingFunction(
|
|
|
97
145
|
abortSignal: AbortSignal,
|
|
98
146
|
) => {
|
|
99
147
|
const res = await retry(async () => {
|
|
100
|
-
const messages:
|
|
101
|
-
{
|
|
102
|
-
role:
|
|
148
|
+
const messages: Message[] = [
|
|
149
|
+
new TextMessage({
|
|
150
|
+
role: Role.System,
|
|
103
151
|
content: editingApiConfig.makeSystemPrompt(
|
|
104
152
|
textareaPurpose,
|
|
105
153
|
getContextString(documents, contextCategories),
|
|
106
154
|
),
|
|
107
|
-
},
|
|
155
|
+
}),
|
|
108
156
|
...editingApiConfig.fewShotMessages,
|
|
109
|
-
{
|
|
110
|
-
role:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
role: "user",
|
|
126
|
-
name: "EditingPrompt",
|
|
127
|
-
content: editingPrompt,
|
|
128
|
-
},
|
|
157
|
+
new TextMessage({
|
|
158
|
+
role: Role.User,
|
|
159
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
|
|
160
|
+
}),
|
|
161
|
+
new TextMessage({
|
|
162
|
+
role: Role.User,
|
|
163
|
+
content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`,
|
|
164
|
+
}),
|
|
165
|
+
new TextMessage({
|
|
166
|
+
role: Role.User,
|
|
167
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
|
|
168
|
+
}),
|
|
169
|
+
new TextMessage({
|
|
170
|
+
role: Role.User,
|
|
171
|
+
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`,
|
|
172
|
+
}),
|
|
129
173
|
];
|
|
130
174
|
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
copilotConfig: copilotApiConfig,
|
|
135
|
-
signal: abortSignal,
|
|
175
|
+
const runtimeClient = new CopilotRuntimeClient({
|
|
176
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
177
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
136
178
|
headers,
|
|
137
179
|
});
|
|
138
|
-
|
|
180
|
+
|
|
181
|
+
return runtimeClientResponseToStringStream(
|
|
182
|
+
runtimeClient.generateCopilotResponse(
|
|
183
|
+
{
|
|
184
|
+
frontend: {
|
|
185
|
+
actions: [],
|
|
186
|
+
},
|
|
187
|
+
messages: convertMessagesToGqlInput(messages),
|
|
188
|
+
},
|
|
189
|
+
copilotApiConfig.properties,
|
|
190
|
+
abortSignal,
|
|
191
|
+
),
|
|
192
|
+
);
|
|
139
193
|
});
|
|
140
194
|
|
|
141
195
|
return res;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Message, Role, TextMessage } from "@copilotkit/runtime-client-gql";
|
|
1
2
|
import { MakeSystemPrompt } from "./subtypes/make-system-prompt";
|
|
2
|
-
import {
|
|
3
|
+
import { nanoid } from "nanoid";
|
|
3
4
|
|
|
4
5
|
export interface EditingApiConfig {
|
|
5
6
|
makeSystemPrompt: MakeSystemPrompt;
|
|
6
|
-
fewShotMessages:
|
|
7
|
+
fewShotMessages: Message[];
|
|
7
8
|
forwardedParams: { [key: string]: any } | undefined;
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -37,58 +38,56 @@ The conversation will be structured as follows:
|
|
|
37
38
|
`;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
export const defaultEditingFewShotMessages:
|
|
41
|
-
{
|
|
42
|
-
role:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
role:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
role:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
role:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
role: "assistant",
|
|
41
|
+
export const defaultEditingFewShotMessages: Message[] = [
|
|
42
|
+
new TextMessage({
|
|
43
|
+
role: Role.User,
|
|
44
|
+
content:
|
|
45
|
+
"<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>",
|
|
46
|
+
}),
|
|
47
|
+
new TextMessage({
|
|
48
|
+
role: Role.User,
|
|
49
|
+
content:
|
|
50
|
+
"<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>",
|
|
51
|
+
}),
|
|
52
|
+
new TextMessage({
|
|
53
|
+
role: Role.User,
|
|
54
|
+
content:
|
|
55
|
+
"<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>",
|
|
56
|
+
}),
|
|
57
|
+
new TextMessage({
|
|
58
|
+
role: Role.User,
|
|
59
|
+
content: "<EditingPrompt>I also bought a big watermelon</EditingPrompt>",
|
|
60
|
+
}),
|
|
61
|
+
new TextMessage({
|
|
62
|
+
role: Role.Assistant,
|
|
63
63
|
content:
|
|
64
64
|
"While I was there I picked up some apples, oranges, and bananas, and a big watermelon.",
|
|
65
|
-
},
|
|
65
|
+
}),
|
|
66
66
|
|
|
67
|
-
{
|
|
68
|
-
role:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
role:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
role: "assistant",
|
|
67
|
+
new TextMessage({
|
|
68
|
+
role: Role.User,
|
|
69
|
+
content:
|
|
70
|
+
"<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>",
|
|
71
|
+
}),
|
|
72
|
+
new TextMessage({
|
|
73
|
+
role: Role.User,
|
|
74
|
+
content: "<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>",
|
|
75
|
+
}),
|
|
76
|
+
new TextMessage({
|
|
77
|
+
role: Role.User,
|
|
78
|
+
content:
|
|
79
|
+
"<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>",
|
|
80
|
+
}),
|
|
81
|
+
new TextMessage({
|
|
82
|
+
role: Role.User,
|
|
83
|
+
content:
|
|
84
|
+
"<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>",
|
|
85
|
+
}),
|
|
86
|
+
new TextMessage({
|
|
87
|
+
role: Role.Assistant,
|
|
89
88
|
content:
|
|
90
89
|
"It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project.",
|
|
91
|
-
},
|
|
90
|
+
}),
|
|
92
91
|
];
|
|
93
92
|
|
|
94
93
|
export const defaultEditingApiConfig: EditingApiConfig = {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { defaultAutosuggestionsConfig } from "./autosuggestions-config";
|
|
2
2
|
export type { AutosuggestionsConfig } from "./autosuggestions-config";
|
|
3
3
|
|
|
4
|
-
export type { MinimalChatGPTMessage } from "./subtypes/minimal-chat-gpt-message";
|
|
5
4
|
export type { MakeSystemPrompt } from "./subtypes/make-system-prompt";
|
|
6
5
|
|
|
7
6
|
export type { AutosuggestionsConfigUserSpecified } from "./autosuggestions-config-user-specified";
|