@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 CHANGED
@@ -1693,6 +1693,12 @@ const defaultAutosuggestionsConfig = {
1693
1693
 
1694
1694
  //#endregion
1695
1695
  //#region src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
1696
+ let warnedDeprecated = false;
1697
+ function warnDeprecatedOnce() {
1698
+ if (warnedDeprecated) return;
1699
+ warnedDeprecated = true;
1700
+ 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.");
1701
+ }
1696
1702
  /**
1697
1703
  * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
1698
1704
  * The function takes in the text before and after the cursor, and an abort signal.
@@ -1707,110 +1713,23 @@ const defaultAutosuggestionsConfig = {
1707
1713
  * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
1708
1714
  */
1709
1715
  function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
1710
- const runtimeClient = { generateCopilotResponse: (...args) => {} };
1711
- const { getContextString, copilotApiConfig } = (0, _copilotkit_react_core.useCopilotContext)();
1712
- copilotApiConfig.publicApiKey && copilotApiConfig.publicApiKey;
1713
- async function runtimeClientResponseToStringStream(responsePromise) {
1714
- const messagesStream = runtimeClient.asStream(responsePromise);
1715
- return new ReadableStream({ async start(controller) {
1716
- const reader = messagesStream.getReader();
1717
- let sentContent = "";
1718
- while (true) {
1719
- const { done, value } = await reader.read();
1720
- if (done) break;
1721
- const messages = (0, _copilotkit_runtime_client_gql.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
1722
- let newContent = "";
1723
- for (const message of messages) if (message.isTextMessage()) newContent += message.content;
1724
- if (newContent) {
1725
- const contentToSend = newContent.slice(sentContent.length);
1726
- controller.enqueue(contentToSend);
1727
- sentContent += contentToSend;
1728
- }
1729
- }
1716
+ const emptySuggestionStream = () => {
1717
+ warnDeprecatedOnce();
1718
+ return new ReadableStream({ start(controller) {
1730
1719
  controller.close();
1731
1720
  } });
1732
- }
1721
+ };
1733
1722
  const insertionFunction = (0, react.useCallback)(async (editorState, insertionPrompt, documents, abortSignal) => {
1734
- return await retry(async () => {
1735
- const messages = [
1736
- new _copilotkit_runtime_client_gql.TextMessage({
1737
- role: _copilotkit_runtime_client_gql.Role.System,
1738
- content: insertionApiConfig.makeSystemPrompt(textareaPurpose, getContextString(documents, contextCategories))
1739
- }),
1740
- ...insertionApiConfig.fewShotMessages,
1741
- new _copilotkit_runtime_client_gql.TextMessage({
1742
- role: _copilotkit_runtime_client_gql.Role.User,
1743
- content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
1744
- }),
1745
- new _copilotkit_runtime_client_gql.TextMessage({
1746
- role: _copilotkit_runtime_client_gql.Role.User,
1747
- content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
1748
- }),
1749
- new _copilotkit_runtime_client_gql.TextMessage({
1750
- role: _copilotkit_runtime_client_gql.Role.User,
1751
- content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
1752
- })
1753
- ];
1754
- return runtimeClientResponseToStringStream(runtimeClient.generateCopilotResponse({
1755
- data: {
1756
- frontend: {
1757
- actions: [],
1758
- url: window.location.href
1759
- },
1760
- messages: (0, _copilotkit_runtime_client_gql.convertMessagesToGqlInput)((0, _copilotkit_runtime_client_gql.filterAgentStateMessages)(messages)),
1761
- metadata: { requestType: _copilotkit_runtime_client_gql.CopilotRequestType.TextareaCompletion }
1762
- },
1763
- properties: copilotApiConfig.properties,
1764
- signal: abortSignal
1765
- }));
1766
- });
1723
+ return emptySuggestionStream();
1767
1724
  }, [
1768
1725
  insertionApiConfig,
1769
- getContextString,
1770
1726
  contextCategories,
1771
1727
  textareaPurpose
1772
1728
  ]);
1773
1729
  const editingFunction = (0, react.useCallback)(async (editorState, editingPrompt, documents, abortSignal) => {
1774
- return await retry(async () => {
1775
- const messages = [
1776
- new _copilotkit_runtime_client_gql.TextMessage({
1777
- role: _copilotkit_runtime_client_gql.Role.System,
1778
- content: editingApiConfig.makeSystemPrompt(textareaPurpose, getContextString(documents, contextCategories))
1779
- }),
1780
- ...editingApiConfig.fewShotMessages,
1781
- new _copilotkit_runtime_client_gql.TextMessage({
1782
- role: _copilotkit_runtime_client_gql.Role.User,
1783
- content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`
1784
- }),
1785
- new _copilotkit_runtime_client_gql.TextMessage({
1786
- role: _copilotkit_runtime_client_gql.Role.User,
1787
- content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`
1788
- }),
1789
- new _copilotkit_runtime_client_gql.TextMessage({
1790
- role: _copilotkit_runtime_client_gql.Role.User,
1791
- content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`
1792
- }),
1793
- new _copilotkit_runtime_client_gql.TextMessage({
1794
- role: _copilotkit_runtime_client_gql.Role.User,
1795
- content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
1796
- })
1797
- ];
1798
- return runtimeClientResponseToStringStream(runtimeClient.generateCopilotResponse({
1799
- data: {
1800
- frontend: {
1801
- actions: [],
1802
- url: window.location.href
1803
- },
1804
- messages: (0, _copilotkit_runtime_client_gql.convertMessagesToGqlInput)((0, _copilotkit_runtime_client_gql.filterAgentStateMessages)(messages)),
1805
- metadata: { requestType: _copilotkit_runtime_client_gql.CopilotRequestType.TextareaCompletion }
1806
- },
1807
- properties: copilotApiConfig.properties,
1808
- signal: abortSignal
1809
- }));
1810
- });
1730
+ return emptySuggestionStream();
1811
1731
  }, [
1812
1732
  editingApiConfig,
1813
- getContextString,
1814
1733
  contextCategories,
1815
1734
  textareaPurpose
1816
1735
  ]);