@copilotkit/react-textarea 1.71.2 → 1.72.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/dist/index.cjs +12 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13 -94
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +13 -94
- package/dist/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +31 -155
package/dist/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import { cva } from "class-variance-authority";
|
|
|
18
18
|
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
19
19
|
import Chip from "@mui/material/Chip/Chip.js";
|
|
20
20
|
import Avatar from "@mui/material/Avatar/Avatar.js";
|
|
21
|
-
import {
|
|
21
|
+
import { Role, TextMessage, convertGqlOutputToMessages } from "@copilotkit/runtime-client-gql";
|
|
22
22
|
import merge from "lodash.merge";
|
|
23
23
|
|
|
24
24
|
//#region src/lib/debouncer.ts
|
|
@@ -1660,6 +1660,12 @@ const defaultAutosuggestionsConfig = {
|
|
|
1660
1660
|
|
|
1661
1661
|
//#endregion
|
|
1662
1662
|
//#region src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
|
|
1663
|
+
let warnedDeprecated = false;
|
|
1664
|
+
function warnDeprecatedOnce() {
|
|
1665
|
+
if (warnedDeprecated) return;
|
|
1666
|
+
warnedDeprecated = true;
|
|
1667
|
+
console.warn("[CopilotKit] CopilotTextarea insertion and editing are no longer functional. @copilotkit/react-textarea is a deprecated v1 package and the backend it called was removed in v1.50.0. There is no 1:1 v2 replacement; start from @copilotkit/react-core/v2.");
|
|
1668
|
+
}
|
|
1663
1669
|
/**
|
|
1664
1670
|
* Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
1665
1671
|
* The function takes in the text before and after the cursor, and an abort signal.
|
|
@@ -1674,110 +1680,23 @@ const defaultAutosuggestionsConfig = {
|
|
|
1674
1680
|
* @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
1675
1681
|
*/
|
|
1676
1682
|
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
async function runtimeClientResponseToStringStream(responsePromise) {
|
|
1681
|
-
const messagesStream = runtimeClient.asStream(responsePromise);
|
|
1682
|
-
return new ReadableStream({ async start(controller) {
|
|
1683
|
-
const reader = messagesStream.getReader();
|
|
1684
|
-
let sentContent = "";
|
|
1685
|
-
while (true) {
|
|
1686
|
-
const { done, value } = await reader.read();
|
|
1687
|
-
if (done) break;
|
|
1688
|
-
const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);
|
|
1689
|
-
let newContent = "";
|
|
1690
|
-
for (const message of messages) if (message.isTextMessage()) newContent += message.content;
|
|
1691
|
-
if (newContent) {
|
|
1692
|
-
const contentToSend = newContent.slice(sentContent.length);
|
|
1693
|
-
controller.enqueue(contentToSend);
|
|
1694
|
-
sentContent += contentToSend;
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1683
|
+
const emptySuggestionStream = () => {
|
|
1684
|
+
warnDeprecatedOnce();
|
|
1685
|
+
return new ReadableStream({ start(controller) {
|
|
1697
1686
|
controller.close();
|
|
1698
1687
|
} });
|
|
1699
|
-
}
|
|
1688
|
+
};
|
|
1700
1689
|
const insertionFunction = useCallback(async (editorState, insertionPrompt, documents, abortSignal) => {
|
|
1701
|
-
return
|
|
1702
|
-
const messages = [
|
|
1703
|
-
new TextMessage({
|
|
1704
|
-
role: Role.System,
|
|
1705
|
-
content: insertionApiConfig.makeSystemPrompt(textareaPurpose, getContextString(documents, contextCategories))
|
|
1706
|
-
}),
|
|
1707
|
-
...insertionApiConfig.fewShotMessages,
|
|
1708
|
-
new TextMessage({
|
|
1709
|
-
role: Role.User,
|
|
1710
|
-
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
|
|
1711
|
-
}),
|
|
1712
|
-
new TextMessage({
|
|
1713
|
-
role: Role.User,
|
|
1714
|
-
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
1715
|
-
}),
|
|
1716
|
-
new TextMessage({
|
|
1717
|
-
role: Role.User,
|
|
1718
|
-
content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
|
|
1719
|
-
})
|
|
1720
|
-
];
|
|
1721
|
-
return runtimeClientResponseToStringStream(runtimeClient.generateCopilotResponse({
|
|
1722
|
-
data: {
|
|
1723
|
-
frontend: {
|
|
1724
|
-
actions: [],
|
|
1725
|
-
url: window.location.href
|
|
1726
|
-
},
|
|
1727
|
-
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
1728
|
-
metadata: { requestType: CopilotRequestType.TextareaCompletion }
|
|
1729
|
-
},
|
|
1730
|
-
properties: copilotApiConfig.properties,
|
|
1731
|
-
signal: abortSignal
|
|
1732
|
-
}));
|
|
1733
|
-
});
|
|
1690
|
+
return emptySuggestionStream();
|
|
1734
1691
|
}, [
|
|
1735
1692
|
insertionApiConfig,
|
|
1736
|
-
getContextString,
|
|
1737
1693
|
contextCategories,
|
|
1738
1694
|
textareaPurpose
|
|
1739
1695
|
]);
|
|
1740
1696
|
const editingFunction = useCallback(async (editorState, editingPrompt, documents, abortSignal) => {
|
|
1741
|
-
return
|
|
1742
|
-
const messages = [
|
|
1743
|
-
new TextMessage({
|
|
1744
|
-
role: Role.System,
|
|
1745
|
-
content: editingApiConfig.makeSystemPrompt(textareaPurpose, getContextString(documents, contextCategories))
|
|
1746
|
-
}),
|
|
1747
|
-
...editingApiConfig.fewShotMessages,
|
|
1748
|
-
new TextMessage({
|
|
1749
|
-
role: Role.User,
|
|
1750
|
-
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
|
|
1751
|
-
}),
|
|
1752
|
-
new TextMessage({
|
|
1753
|
-
role: Role.User,
|
|
1754
|
-
content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`
|
|
1755
|
-
}),
|
|
1756
|
-
new TextMessage({
|
|
1757
|
-
role: Role.User,
|
|
1758
|
-
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
|
|
1759
|
-
}),
|
|
1760
|
-
new TextMessage({
|
|
1761
|
-
role: Role.User,
|
|
1762
|
-
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
|
|
1763
|
-
})
|
|
1764
|
-
];
|
|
1765
|
-
return runtimeClientResponseToStringStream(runtimeClient.generateCopilotResponse({
|
|
1766
|
-
data: {
|
|
1767
|
-
frontend: {
|
|
1768
|
-
actions: [],
|
|
1769
|
-
url: window.location.href
|
|
1770
|
-
},
|
|
1771
|
-
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
1772
|
-
metadata: { requestType: CopilotRequestType.TextareaCompletion }
|
|
1773
|
-
},
|
|
1774
|
-
properties: copilotApiConfig.properties,
|
|
1775
|
-
signal: abortSignal
|
|
1776
|
-
}));
|
|
1777
|
-
});
|
|
1697
|
+
return emptySuggestionStream();
|
|
1778
1698
|
}, [
|
|
1779
1699
|
editingApiConfig,
|
|
1780
|
-
getContextString,
|
|
1781
1700
|
contextCategories,
|
|
1782
1701
|
textareaPurpose
|
|
1783
1702
|
]);
|