@copilotkit/react-textarea 1.71.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/react-textarea",
3
- "version": "1.71.1",
3
+ "version": "1.72.0",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -59,9 +59,9 @@
59
59
  "slate-history": "^0.93.0",
60
60
  "slate-react": "^0.98.1",
61
61
  "tailwind-merge": "^1.13.2",
62
- "@copilotkit/react-core": "1.71.1",
63
- "@copilotkit/shared": "1.71.1",
64
- "@copilotkit/runtime-client-gql": "1.71.1"
62
+ "@copilotkit/react-core": "1.72.0",
63
+ "@copilotkit/shared": "1.72.0",
64
+ "@copilotkit/runtime-client-gql": "1.72.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/lodash.merge": "^4.6.7",
@@ -1,24 +1,23 @@
1
- import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
2
- import { useCopilotContext } from "@copilotkit/react-core";
3
1
  import { useCallback } from "react";
4
- import {
5
- CopilotRuntimeClient,
6
- Message,
7
- Role,
8
- TextMessage,
9
- convertGqlOutputToMessages,
10
- convertMessagesToGqlInput,
11
- filterAgentStateMessages,
12
- CopilotRequestType,
13
- } from "@copilotkit/runtime-client-gql";
14
- import { retry } from "../../lib/retry";
15
- import {
2
+ import type {
16
3
  EditingEditorState,
17
4
  Generator_InsertionOrEditingSuggestion,
18
5
  } from "../../types/base/autosuggestions-bare-function";
19
- import { InsertionsApiConfig } from "../../types/autosuggestions-config/insertions-api-config";
20
- import { EditingApiConfig } from "../../types/autosuggestions-config/editing-api-config";
21
- import { DocumentPointer } from "@copilotkit/react-core";
6
+ import type { InsertionsApiConfig } from "../../types/autosuggestions-config/insertions-api-config";
7
+ import type { EditingApiConfig } from "../../types/autosuggestions-config/editing-api-config";
8
+ import type { DocumentPointer } from "@copilotkit/react-core";
9
+
10
+ let warnedDeprecated = false;
11
+
12
+ function warnDeprecatedOnce() {
13
+ if (warnedDeprecated) return;
14
+ warnedDeprecated = true;
15
+ console.warn(
16
+ "[CopilotKit] CopilotTextarea insertion and editing are no longer functional. " +
17
+ "@copilotkit/react-textarea is a deprecated v1 package and the backend it called was " +
18
+ "removed in v1.50.0. There is no 1:1 v2 replacement; start from @copilotkit/react-core/v2.",
19
+ );
20
+ }
22
21
 
23
22
  /**
24
23
  * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
@@ -39,51 +38,20 @@ export function useMakeStandardInsertionOrEditingFunction(
39
38
  insertionApiConfig: InsertionsApiConfig,
40
39
  editingApiConfig: EditingApiConfig,
41
40
  ): Generator_InsertionOrEditingSuggestion {
42
- const runtimeClient: any = {
43
- generateCopilotResponse: (...args: any[]) => {},
44
- };
45
- const { getContextString, copilotApiConfig } = useCopilotContext();
46
- const headers = copilotApiConfig.publicApiKey
47
- ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }
48
- : {};
49
-
50
- async function runtimeClientResponseToStringStream(
51
- responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,
52
- ) {
53
- const messagesStream = runtimeClient.asStream(responsePromise);
54
-
55
- return new ReadableStream({
56
- async start(controller) {
57
- const reader = messagesStream.getReader();
58
- let sentContent = "";
59
-
60
- while (true) {
61
- const { done, value } = await reader.read();
62
- if (done) {
63
- break;
64
- }
65
-
66
- const messages = convertGqlOutputToMessages(
67
- value.generateCopilotResponse.messages,
68
- );
69
-
70
- let newContent = "";
71
-
72
- for (const message of messages) {
73
- if (message.isTextMessage()) {
74
- newContent += message.content;
75
- }
76
- }
77
- if (newContent) {
78
- const contentToSend = newContent.slice(sentContent.length);
79
- controller.enqueue(contentToSend);
80
- sentContent += contentToSend;
81
- }
82
- }
41
+ // The GraphQL transport this hook used to call was removed in v1.50.0, and
42
+ // the request was stubbed out at the same time. The stub left behind had no
43
+ // `asStream`, so reaching this path raised
44
+ // `TypeError: runtimeClient.asStream is not a function` the first time a user
45
+ // triggered an insertion or an edit. Return an empty stream instead, matching
46
+ // the sibling autosuggestions hook, and say once why nothing happened.
47
+ const emptySuggestionStream = () => {
48
+ warnDeprecatedOnce();
49
+ return new ReadableStream<string>({
50
+ start(controller) {
83
51
  controller.close();
84
52
  },
85
53
  });
86
- }
54
+ };
87
55
 
88
56
  const insertionFunction = useCallback(
89
57
  async (
@@ -92,53 +60,9 @@ export function useMakeStandardInsertionOrEditingFunction(
92
60
  documents: DocumentPointer[],
93
61
  abortSignal: AbortSignal,
94
62
  ) => {
95
- const res = await retry(async () => {
96
- const messages: Message[] = [
97
- new TextMessage({
98
- role: Role.System,
99
- content: insertionApiConfig.makeSystemPrompt(
100
- textareaPurpose,
101
- getContextString(documents, contextCategories),
102
- ),
103
- }),
104
- ...insertionApiConfig.fewShotMessages,
105
- new TextMessage({
106
- role: Role.User,
107
- content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
108
- }),
109
- new TextMessage({
110
- role: Role.User,
111
- content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
112
- }),
113
- new TextMessage({
114
- role: Role.User,
115
- content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`,
116
- }),
117
- ];
118
-
119
- return runtimeClientResponseToStringStream(
120
- runtimeClient.generateCopilotResponse({
121
- data: {
122
- frontend: {
123
- actions: [],
124
- url: window.location.href,
125
- },
126
- messages: convertMessagesToGqlInput(
127
- filterAgentStateMessages(messages),
128
- ),
129
- metadata: {
130
- requestType: CopilotRequestType.TextareaCompletion,
131
- },
132
- },
133
- properties: copilotApiConfig.properties,
134
- signal: abortSignal,
135
- }),
136
- );
137
- });
138
-
139
- return res;
63
+ return emptySuggestionStream();
140
64
  },
141
- [insertionApiConfig, getContextString, contextCategories, textareaPurpose],
65
+ [insertionApiConfig, contextCategories, textareaPurpose],
142
66
  );
143
67
 
144
68
  const editingFunction = useCallback(
@@ -148,57 +72,9 @@ export function useMakeStandardInsertionOrEditingFunction(
148
72
  documents: DocumentPointer[],
149
73
  abortSignal: AbortSignal,
150
74
  ) => {
151
- const res = await retry(async () => {
152
- const messages: Message[] = [
153
- new TextMessage({
154
- role: Role.System,
155
- content: editingApiConfig.makeSystemPrompt(
156
- textareaPurpose,
157
- getContextString(documents, contextCategories),
158
- ),
159
- }),
160
- ...editingApiConfig.fewShotMessages,
161
- new TextMessage({
162
- role: Role.User,
163
- content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
164
- }),
165
- new TextMessage({
166
- role: Role.User,
167
- content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`,
168
- }),
169
- new TextMessage({
170
- role: Role.User,
171
- content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
172
- }),
173
- new TextMessage({
174
- role: Role.User,
175
- content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`,
176
- }),
177
- ];
178
-
179
- return runtimeClientResponseToStringStream(
180
- runtimeClient.generateCopilotResponse({
181
- data: {
182
- frontend: {
183
- actions: [],
184
- url: window.location.href,
185
- },
186
- messages: convertMessagesToGqlInput(
187
- filterAgentStateMessages(messages),
188
- ),
189
- metadata: {
190
- requestType: CopilotRequestType.TextareaCompletion,
191
- },
192
- },
193
- properties: copilotApiConfig.properties,
194
- signal: abortSignal,
195
- }),
196
- );
197
- });
198
-
199
- return res;
75
+ return emptySuggestionStream();
200
76
  },
201
- [editingApiConfig, getContextString, contextCategories, textareaPurpose],
77
+ [editingApiConfig, contextCategories, textareaPurpose],
202
78
  );
203
79
 
204
80
  const insertionOrEditingFunction = useCallback(