@copilotkit/react-textarea 1.50.0-beta.1 → 1.50.0-beta.10
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 +95 -0
- package/dist/{chunk-ISKK3RIW.mjs → chunk-4ECCCOFV.mjs} +4 -4
- package/dist/{chunk-5NZNJCP2.mjs → chunk-AT3INWD6.mjs} +25 -25
- package/dist/{chunk-4VCJHANC.mjs → chunk-JVCLCI7G.mjs} +4 -4
- package/dist/chunk-KAU7LAEQ.mjs +60 -0
- package/dist/chunk-KAU7LAEQ.mjs.map +1 -0
- package/dist/{chunk-66KFI242.mjs → chunk-L6JBC3MS.mjs} +2 -2
- package/dist/chunk-MMVDU6DF.mjs +1 -0
- package/dist/{chunk-7VADGLV2.mjs → chunk-PIMJDHZM.mjs} +5 -5
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +19 -19
- package/dist/components/copilot-textarea/copilot-textarea.mjs +30 -77
- package/dist/components/copilot-textarea/copilot-textarea.mjs.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.mjs +4 -4
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +5 -5
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +5 -5
- package/dist/components/index.d.ts +11 -2
- package/dist/components/index.js +490 -8
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +33 -21
- package/dist/components/ui/command.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +327 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -30
- 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 +6 -6
- package/src/components/index.ts +3 -0
- package/dist/chunk-JD7BAH7U.mjs +0 -1
- /package/dist/{chunk-ISKK3RIW.mjs.map → chunk-4ECCCOFV.mjs.map} +0 -0
- /package/dist/{chunk-5NZNJCP2.mjs.map → chunk-AT3INWD6.mjs.map} +0 -0
- /package/dist/{chunk-4VCJHANC.mjs.map → chunk-JVCLCI7G.mjs.map} +0 -0
- /package/dist/{chunk-66KFI242.mjs.map → chunk-L6JBC3MS.mjs.map} +0 -0
- /package/dist/{chunk-JD7BAH7U.mjs.map → chunk-MMVDU6DF.mjs.map} +0 -0
- /package/dist/{chunk-7VADGLV2.mjs.map → chunk-PIMJDHZM.mjs.map} +0 -0
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
export { BaseCopilotTextarea } from './base-copilot-textarea/base-copilot-textarea.js';
|
|
2
|
-
|
|
3
|
-
import '../types/base/index.js';
|
|
2
|
+
export { CopilotTextarea, CopilotTextareaProps } from './copilot-textarea/copilot-textarea.js';
|
|
4
3
|
import '../types/base/base-autosuggestions-config.js';
|
|
5
4
|
import '../types/base/autosuggestions-bare-function.js';
|
|
5
|
+
import '../types/base/index.js';
|
|
6
|
+
import '../types/html-copilot-textarea-element.js';
|
|
7
|
+
import '../types/autosuggestions-config/autosuggestions-config.js';
|
|
8
|
+
import '../types/autosuggestions-config/subtypes/make-system-prompt.js';
|
|
9
|
+
import '../types/autosuggestions-config/autosuggestions-config-user-specified.js';
|
|
10
|
+
import 'react';
|
|
6
11
|
import '@copilotkit/react-core';
|
|
12
|
+
import '../types/autosuggestions-config/suggestions-api-config.js';
|
|
13
|
+
import '@copilotkit/runtime-client-gql';
|
|
14
|
+
import '../types/autosuggestions-config/insertions-api-config.js';
|
|
15
|
+
import '../types/autosuggestions-config/editing-api-config.js';
|
package/dist/components/index.js
CHANGED
|
@@ -79,7 +79,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
79
79
|
// src/components/index.ts
|
|
80
80
|
var components_exports = {};
|
|
81
81
|
__export(components_exports, {
|
|
82
|
-
BaseCopilotTextarea: () => BaseCopilotTextarea
|
|
82
|
+
BaseCopilotTextarea: () => BaseCopilotTextarea,
|
|
83
|
+
CopilotTextarea: () => CopilotTextarea
|
|
83
84
|
});
|
|
84
85
|
module.exports = __toCommonJS(components_exports);
|
|
85
86
|
|
|
@@ -281,21 +282,21 @@ var withPartialHistory = (editor, shouldSave2) => {
|
|
|
281
282
|
const lastBatch = undos[undos.length - 1];
|
|
282
283
|
const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
|
283
284
|
let save = import_slate_history.HistoryEditor.isSaving(e);
|
|
284
|
-
let
|
|
285
|
+
let merge2 = import_slate_history.HistoryEditor.isMerging(e);
|
|
285
286
|
if (save == null) {
|
|
286
287
|
save = shouldSave2(op, lastOp);
|
|
287
288
|
}
|
|
288
289
|
if (save) {
|
|
289
|
-
if (
|
|
290
|
+
if (merge2 == null) {
|
|
290
291
|
if (lastBatch == null) {
|
|
291
|
-
|
|
292
|
+
merge2 = false;
|
|
292
293
|
} else if (operations.length !== 0) {
|
|
293
|
-
|
|
294
|
+
merge2 = true;
|
|
294
295
|
} else {
|
|
295
|
-
|
|
296
|
+
merge2 = shouldMerge(op, lastOp);
|
|
296
297
|
}
|
|
297
298
|
}
|
|
298
|
-
if (lastBatch &&
|
|
299
|
+
if (lastBatch && merge2) {
|
|
299
300
|
lastBatch.operations.push(op);
|
|
300
301
|
} else {
|
|
301
302
|
const batch = {
|
|
@@ -1776,8 +1777,489 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
|
|
|
1776
1777
|
}
|
|
1777
1778
|
};
|
|
1778
1779
|
}
|
|
1780
|
+
|
|
1781
|
+
// src/components/copilot-textarea/copilot-textarea.tsx
|
|
1782
|
+
var import_react15 = __toESM(require("react"));
|
|
1783
|
+
|
|
1784
|
+
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
1785
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
1786
|
+
var import_react_core3 = require("@copilotkit/react-core");
|
|
1787
|
+
var import_react13 = require("react");
|
|
1788
|
+
|
|
1789
|
+
// src/lib/retry.tsx
|
|
1790
|
+
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
1791
|
+
return new Promise((resolve, reject) => {
|
|
1792
|
+
fn().then(resolve).catch((error) => {
|
|
1793
|
+
if (retriesLeft === 1) {
|
|
1794
|
+
reject(error);
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
setTimeout(() => {
|
|
1798
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
1799
|
+
}, interval);
|
|
1800
|
+
});
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
// src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
|
|
1805
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
1806
|
+
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
1807
|
+
const runtimeClient = { generateCopilotResponse: (...args) => {
|
|
1808
|
+
} };
|
|
1809
|
+
const { getContextString, copilotApiConfig } = (0, import_react_core3.useCopilotContext)();
|
|
1810
|
+
const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
|
|
1811
|
+
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1812
|
+
const { maxTokens, stop, temperature = 0 } = apiConfig;
|
|
1813
|
+
return (0, import_react13.useCallback)(
|
|
1814
|
+
(editorState2, abortSignal) => __async(this, null, function* () {
|
|
1815
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
1816
|
+
var _a, _b, _c;
|
|
1817
|
+
const messages = [
|
|
1818
|
+
new import_runtime_client_gql.TextMessage({
|
|
1819
|
+
role: import_runtime_client_gql.Role.System,
|
|
1820
|
+
content: apiConfig.makeSystemPrompt(
|
|
1821
|
+
textareaPurpose,
|
|
1822
|
+
getContextString([], contextCategories)
|
|
1823
|
+
)
|
|
1824
|
+
}),
|
|
1825
|
+
...apiConfig.fewShotMessages,
|
|
1826
|
+
editorState2.textAfterCursor != "" ? new import_runtime_client_gql.TextMessage({
|
|
1827
|
+
role: import_runtime_client_gql.Role.User,
|
|
1828
|
+
content: editorState2.textAfterCursor
|
|
1829
|
+
}) : null,
|
|
1830
|
+
new import_runtime_client_gql.TextMessage({
|
|
1831
|
+
role: import_runtime_client_gql.Role.User,
|
|
1832
|
+
content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
|
|
1833
|
+
}),
|
|
1834
|
+
new import_runtime_client_gql.TextMessage({
|
|
1835
|
+
role: import_runtime_client_gql.Role.User,
|
|
1836
|
+
content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
|
|
1837
|
+
})
|
|
1838
|
+
].filter(Boolean);
|
|
1839
|
+
const response = {};
|
|
1840
|
+
let result = "";
|
|
1841
|
+
for (const message of (0, import_runtime_client_gql.convertGqlOutputToMessages)(
|
|
1842
|
+
(_c = (_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) != null ? _c : []
|
|
1843
|
+
)) {
|
|
1844
|
+
if (abortSignal.aborted) {
|
|
1845
|
+
break;
|
|
1846
|
+
}
|
|
1847
|
+
if (message.isTextMessage()) {
|
|
1848
|
+
result += message.content;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
return result;
|
|
1852
|
+
}));
|
|
1853
|
+
return res;
|
|
1854
|
+
}),
|
|
1855
|
+
[apiConfig, getContextString, contextCategories, textareaPurpose]
|
|
1856
|
+
);
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// src/types/autosuggestions-config/suggestions-api-config.tsx
|
|
1860
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
1861
|
+
var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
1862
|
+
return `You are a versatile writing assistant.
|
|
1863
|
+
|
|
1864
|
+
The user is writing some text.
|
|
1865
|
+
The purpose is: "${textareaPurpose}"
|
|
1866
|
+
|
|
1867
|
+
Your job is to guess what the user will write next AS BEST YOU CAN.
|
|
1868
|
+
Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
|
|
1869
|
+
|
|
1870
|
+
Adjust yourself to the user's style and implied intent.
|
|
1871
|
+
|
|
1872
|
+
The user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.
|
|
1873
|
+
<TextAfterCursor>
|
|
1874
|
+
<TextBeforeCursor>
|
|
1875
|
+
<YourSuggestion>
|
|
1876
|
+
|
|
1877
|
+
If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
|
|
1878
|
+
Refrain from adding <YourSuggestion> tags when responding
|
|
1879
|
+
|
|
1880
|
+
The following external context is also provided. Use it to help you make better suggestions!!!
|
|
1881
|
+
\`\`\`
|
|
1882
|
+
${contextString}
|
|
1883
|
+
\`\`\`
|
|
1884
|
+
`;
|
|
1885
|
+
};
|
|
1886
|
+
var defaultSuggestionsFewShotMessages = [
|
|
1887
|
+
new import_runtime_client_gql2.TextMessage({
|
|
1888
|
+
role: import_runtime_client_gql2.Role.User,
|
|
1889
|
+
content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
|
|
1890
|
+
}),
|
|
1891
|
+
new import_runtime_client_gql2.TextMessage({
|
|
1892
|
+
role: import_runtime_client_gql2.Role.User,
|
|
1893
|
+
content: "This morning I woke up and went straight to the grocery store."
|
|
1894
|
+
}),
|
|
1895
|
+
new import_runtime_client_gql2.TextMessage({
|
|
1896
|
+
role: import_runtime_client_gql2.Role.Assistant,
|
|
1897
|
+
content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
|
|
1898
|
+
}),
|
|
1899
|
+
new import_runtime_client_gql2.TextMessage({
|
|
1900
|
+
role: import_runtime_client_gql2.Role.User,
|
|
1901
|
+
content: "<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>"
|
|
1902
|
+
}),
|
|
1903
|
+
new import_runtime_client_gql2.TextMessage({
|
|
1904
|
+
role: import_runtime_client_gql2.Role.User,
|
|
1905
|
+
content: `<TextBeforeCursor>The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;</TextBeforeCursor>`
|
|
1906
|
+
}),
|
|
1907
|
+
new import_runtime_client_gql2.TextMessage({
|
|
1908
|
+
role: import_runtime_client_gql2.Role.Assistant,
|
|
1909
|
+
content: ` (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder's "Pro Rata Share"; `
|
|
1910
|
+
})
|
|
1911
|
+
];
|
|
1912
|
+
var defaultSuggestionsApiConfig = {
|
|
1913
|
+
makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
|
|
1914
|
+
fewShotMessages: defaultSuggestionsFewShotMessages
|
|
1915
|
+
};
|
|
1916
|
+
|
|
1917
|
+
// src/types/autosuggestions-config/insertions-api-config.tsx
|
|
1918
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
1919
|
+
var defaultInsertionsMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
1920
|
+
return `You are a versatile writing assistant helping the user insert new text into their existing work.
|
|
1921
|
+
|
|
1922
|
+
The user is writing some text.
|
|
1923
|
+
The purpose is: "${textareaPurpose}"
|
|
1924
|
+
|
|
1925
|
+
The following external context is also provided. Use it to inform your suggestions when relevant!!!
|
|
1926
|
+
\`\`\`
|
|
1927
|
+
${contextString}
|
|
1928
|
+
\`\`\`
|
|
1929
|
+
|
|
1930
|
+
The user will provide you with a prompt for an INSERTION into the text they are writing.
|
|
1931
|
+
Your job is to come up with an INSERTION into the text that the user would like to use, AS BEST YOU CAN.
|
|
1932
|
+
Only insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.
|
|
1933
|
+
|
|
1934
|
+
Adjust yourself to the user's style and implied intent.
|
|
1935
|
+
|
|
1936
|
+
|
|
1937
|
+
The user will provide the text before and after the cursor, as well as the INSERTION prompt. You should use this to infer the best relevant insertion.
|
|
1938
|
+
The conversation will be structured as follows:
|
|
1939
|
+
<TextAfterCursor>
|
|
1940
|
+
<TextBeforeCursor>
|
|
1941
|
+
<InsertionPrompt>
|
|
1942
|
+
|
|
1943
|
+
<YourInsertionSuggestion>
|
|
1944
|
+
`;
|
|
1945
|
+
};
|
|
1946
|
+
var defaultInsertionsFewShotMessages = [
|
|
1947
|
+
new import_runtime_client_gql3.TextMessage({
|
|
1948
|
+
role: import_runtime_client_gql3.Role.User,
|
|
1949
|
+
content: "<TextAfterCursor>While I was there I also picked up some apples, oranges, and bananas.</TextAfterCursor>"
|
|
1950
|
+
}),
|
|
1951
|
+
new import_runtime_client_gql3.TextMessage({
|
|
1952
|
+
role: import_runtime_client_gql3.Role.User,
|
|
1953
|
+
content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store.</TextBeforeCursor>"
|
|
1954
|
+
}),
|
|
1955
|
+
new import_runtime_client_gql3.TextMessage({
|
|
1956
|
+
role: import_runtime_client_gql3.Role.User,
|
|
1957
|
+
content: "<InsertionPrompt>I bought a big watermelon</InsertionPrompt>"
|
|
1958
|
+
}),
|
|
1959
|
+
new import_runtime_client_gql3.TextMessage({
|
|
1960
|
+
role: import_runtime_client_gql3.Role.Assistant,
|
|
1961
|
+
content: "When I arrived I went straight to the produce section and picked out a big watermelon."
|
|
1962
|
+
}),
|
|
1963
|
+
new import_runtime_client_gql3.TextMessage({
|
|
1964
|
+
role: import_runtime_client_gql3.Role.User,
|
|
1965
|
+
content: "<TextAfterCursor>and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.</TextAfterCursor>"
|
|
1966
|
+
}),
|
|
1967
|
+
new import_runtime_client_gql3.TextMessage({
|
|
1968
|
+
role: import_runtime_client_gql3.Role.User,
|
|
1969
|
+
content: `<TextBeforeCursor>The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;</TextBeforeCursor>`
|
|
1970
|
+
}),
|
|
1971
|
+
new import_runtime_client_gql3.TextMessage({
|
|
1972
|
+
role: import_runtime_client_gql3.Role.User,
|
|
1973
|
+
content: "<InsertionPrompt>add section about the optionholder's pro rata share</InsertionPrompt>"
|
|
1974
|
+
}),
|
|
1975
|
+
new import_runtime_client_gql3.TextMessage({
|
|
1976
|
+
role: import_runtime_client_gql3.Role.Assistant,
|
|
1977
|
+
content: ` (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder's "Pro Rata Share"; `
|
|
1978
|
+
})
|
|
1979
|
+
];
|
|
1980
|
+
var defaultInsertionsApiConfig = {
|
|
1981
|
+
makeSystemPrompt: defaultInsertionsMakeSystemPrompt,
|
|
1982
|
+
fewShotMessages: defaultInsertionsFewShotMessages,
|
|
1983
|
+
forwardedParams: void 0
|
|
1984
|
+
};
|
|
1985
|
+
|
|
1986
|
+
// src/types/autosuggestions-config/editing-api-config.tsx
|
|
1987
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1988
|
+
var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
|
|
1989
|
+
return `You are a versatile writing assistant helping the user edit a portion of their text.
|
|
1990
|
+
|
|
1991
|
+
The user is writing some text.
|
|
1992
|
+
The purpose is: "${textareaPurpose}"
|
|
1993
|
+
|
|
1994
|
+
The following external context is also provided. Use it when relevant.
|
|
1995
|
+
\`\`\`
|
|
1996
|
+
${contextString}
|
|
1997
|
+
\`\`\`
|
|
1998
|
+
|
|
1999
|
+
The user has provided you with a PROMPT for EDITING a PORTION of the text.
|
|
2000
|
+
Your job is to come up with a new EDITED version OF THE SEGMENT IN QUESTION - AS BEST YOU CAN.
|
|
2001
|
+
Only rewrite the portion of the text that the user has marked as "TextToEdit"!!!
|
|
2002
|
+
|
|
2003
|
+
Adjust yourself to the user's style and implied intent.
|
|
2004
|
+
|
|
2005
|
+
The conversation will be structured as follows:
|
|
2006
|
+
<TextBeforeCursor>
|
|
2007
|
+
<TextToEdit>
|
|
2008
|
+
<TextAfterCursor>
|
|
2009
|
+
<EditingPrompt>
|
|
2010
|
+
|
|
2011
|
+
<YourEditSuggestion>
|
|
2012
|
+
`;
|
|
2013
|
+
};
|
|
2014
|
+
var defaultEditingFewShotMessages = [
|
|
2015
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2016
|
+
role: import_runtime_client_gql4.Role.User,
|
|
2017
|
+
content: "<TextBeforeCursor>This morning I woke up and went straight to the grocery store. </TextBeforeCursor>"
|
|
2018
|
+
}),
|
|
2019
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2020
|
+
role: import_runtime_client_gql4.Role.User,
|
|
2021
|
+
content: "<TextToEdit>While I was there I picked up some apples, oranges, and bananas. </TextToEdit>"
|
|
2022
|
+
}),
|
|
2023
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2024
|
+
role: import_runtime_client_gql4.Role.User,
|
|
2025
|
+
content: "<TextAfterCursor>The grocery store was having a sale on fruit, so I decided to stock up.</TextAfterCursor>"
|
|
2026
|
+
}),
|
|
2027
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2028
|
+
role: import_runtime_client_gql4.Role.User,
|
|
2029
|
+
content: "<EditingPrompt>I also bought a big watermelon</EditingPrompt>"
|
|
2030
|
+
}),
|
|
2031
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2032
|
+
role: import_runtime_client_gql4.Role.Assistant,
|
|
2033
|
+
content: "While I was there I picked up some apples, oranges, and bananas, and a big watermelon."
|
|
2034
|
+
}),
|
|
2035
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2036
|
+
role: import_runtime_client_gql4.Role.User,
|
|
2037
|
+
content: "<TextBeforeCursor>Yesterday, I spent the afternoon working on my new project.</TextBeforeCursor>"
|
|
2038
|
+
}),
|
|
2039
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2040
|
+
role: import_runtime_client_gql4.Role.User,
|
|
2041
|
+
content: "<TextToEdit>It's quite challenging and requires a lot of focus.</TextToEdit>"
|
|
2042
|
+
}),
|
|
2043
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2044
|
+
role: import_runtime_client_gql4.Role.User,
|
|
2045
|
+
content: "<TextAfterCursor>I'm really excited about the potential outcomes of this project.</TextAfterCursor>"
|
|
2046
|
+
}),
|
|
2047
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2048
|
+
role: import_runtime_client_gql4.Role.User,
|
|
2049
|
+
content: "<EditingPrompt>emphasize the complexity and my enthusiasm for the project</EditingPrompt>"
|
|
2050
|
+
}),
|
|
2051
|
+
new import_runtime_client_gql4.TextMessage({
|
|
2052
|
+
role: import_runtime_client_gql4.Role.Assistant,
|
|
2053
|
+
content: "It's a highly complex task that demands intense concentration, but I'm incredibly enthusiastic about the promising prospects of this project."
|
|
2054
|
+
})
|
|
2055
|
+
];
|
|
2056
|
+
var defaultEditingApiConfig = {
|
|
2057
|
+
makeSystemPrompt: defaultEditingMakeSystemPrompt,
|
|
2058
|
+
fewShotMessages: defaultEditingFewShotMessages,
|
|
2059
|
+
forwardedParams: void 0
|
|
2060
|
+
};
|
|
2061
|
+
|
|
2062
|
+
// src/types/autosuggestions-config/autosuggestions-config.tsx
|
|
2063
|
+
var import_react_core4 = require("@copilotkit/react-core");
|
|
2064
|
+
var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseAutosuggestionsConfig), {
|
|
2065
|
+
contextCategories: import_react_core4.defaultCopilotContextCategories,
|
|
2066
|
+
chatApiConfigs: {
|
|
2067
|
+
suggestionsApiConfig: defaultSuggestionsApiConfig,
|
|
2068
|
+
insertionApiConfig: defaultInsertionsApiConfig,
|
|
2069
|
+
editingApiConfig: defaultEditingApiConfig
|
|
2070
|
+
}
|
|
2071
|
+
});
|
|
2072
|
+
|
|
2073
|
+
// src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
|
|
2074
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
2075
|
+
var import_react_core5 = require("@copilotkit/react-core");
|
|
2076
|
+
var import_react14 = require("react");
|
|
2077
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
2078
|
+
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
2079
|
+
const runtimeClient = { generateCopilotResponse: (...args) => {
|
|
2080
|
+
} };
|
|
2081
|
+
const { getContextString, copilotApiConfig } = (0, import_react_core5.useCopilotContext)();
|
|
2082
|
+
const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
2083
|
+
function runtimeClientResponseToStringStream(responsePromise) {
|
|
2084
|
+
return __async(this, null, function* () {
|
|
2085
|
+
const messagesStream = runtimeClient.asStream(responsePromise);
|
|
2086
|
+
return new ReadableStream({
|
|
2087
|
+
start(controller) {
|
|
2088
|
+
return __async(this, null, function* () {
|
|
2089
|
+
const reader = messagesStream.getReader();
|
|
2090
|
+
let sentContent = "";
|
|
2091
|
+
while (true) {
|
|
2092
|
+
const { done, value } = yield reader.read();
|
|
2093
|
+
if (done) {
|
|
2094
|
+
break;
|
|
2095
|
+
}
|
|
2096
|
+
const messages = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
|
|
2097
|
+
let newContent = "";
|
|
2098
|
+
for (const message of messages) {
|
|
2099
|
+
if (message.isTextMessage()) {
|
|
2100
|
+
newContent += message.content;
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
if (newContent) {
|
|
2104
|
+
const contentToSend = newContent.slice(sentContent.length);
|
|
2105
|
+
controller.enqueue(contentToSend);
|
|
2106
|
+
sentContent += contentToSend;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
controller.close();
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
});
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
const insertionFunction = (0, import_react14.useCallback)(
|
|
2116
|
+
(editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
2117
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
2118
|
+
const messages = [
|
|
2119
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2120
|
+
role: import_runtime_client_gql5.Role.System,
|
|
2121
|
+
content: insertionApiConfig.makeSystemPrompt(
|
|
2122
|
+
textareaPurpose,
|
|
2123
|
+
getContextString(documents, contextCategories)
|
|
2124
|
+
)
|
|
2125
|
+
}),
|
|
2126
|
+
...insertionApiConfig.fewShotMessages,
|
|
2127
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2128
|
+
role: import_runtime_client_gql5.Role.User,
|
|
2129
|
+
content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
|
|
2130
|
+
}),
|
|
2131
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2132
|
+
role: import_runtime_client_gql5.Role.User,
|
|
2133
|
+
content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
|
|
2134
|
+
}),
|
|
2135
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2136
|
+
role: import_runtime_client_gql5.Role.User,
|
|
2137
|
+
content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`
|
|
2138
|
+
})
|
|
2139
|
+
];
|
|
2140
|
+
return runtimeClientResponseToStringStream(
|
|
2141
|
+
runtimeClient.generateCopilotResponse({
|
|
2142
|
+
data: {
|
|
2143
|
+
frontend: {
|
|
2144
|
+
actions: [],
|
|
2145
|
+
url: window.location.href
|
|
2146
|
+
},
|
|
2147
|
+
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messages)),
|
|
2148
|
+
metadata: {
|
|
2149
|
+
requestType: import_runtime_client_gql5.CopilotRequestType.TextareaCompletion
|
|
2150
|
+
}
|
|
2151
|
+
},
|
|
2152
|
+
properties: copilotApiConfig.properties,
|
|
2153
|
+
signal: abortSignal
|
|
2154
|
+
})
|
|
2155
|
+
);
|
|
2156
|
+
}));
|
|
2157
|
+
return res;
|
|
2158
|
+
}),
|
|
2159
|
+
[insertionApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
2160
|
+
);
|
|
2161
|
+
const editingFunction = (0, import_react14.useCallback)(
|
|
2162
|
+
(editorState2, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
2163
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
2164
|
+
const messages = [
|
|
2165
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2166
|
+
role: import_runtime_client_gql5.Role.System,
|
|
2167
|
+
content: editingApiConfig.makeSystemPrompt(
|
|
2168
|
+
textareaPurpose,
|
|
2169
|
+
getContextString(documents, contextCategories)
|
|
2170
|
+
)
|
|
2171
|
+
}),
|
|
2172
|
+
...editingApiConfig.fewShotMessages,
|
|
2173
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2174
|
+
role: import_runtime_client_gql5.Role.User,
|
|
2175
|
+
content: `<TextBeforeCursor>${editorState2.textBeforeCursor}</TextBeforeCursor>`
|
|
2176
|
+
}),
|
|
2177
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2178
|
+
role: import_runtime_client_gql5.Role.User,
|
|
2179
|
+
content: `<TextToEdit>${editorState2.selectedText}</TextToEdit>`
|
|
2180
|
+
}),
|
|
2181
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2182
|
+
role: import_runtime_client_gql5.Role.User,
|
|
2183
|
+
content: `<TextAfterCursor>${editorState2.textAfterCursor}</TextAfterCursor>`
|
|
2184
|
+
}),
|
|
2185
|
+
new import_runtime_client_gql5.TextMessage({
|
|
2186
|
+
role: import_runtime_client_gql5.Role.User,
|
|
2187
|
+
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`
|
|
2188
|
+
})
|
|
2189
|
+
];
|
|
2190
|
+
return runtimeClientResponseToStringStream(
|
|
2191
|
+
runtimeClient.generateCopilotResponse({
|
|
2192
|
+
data: {
|
|
2193
|
+
frontend: {
|
|
2194
|
+
actions: [],
|
|
2195
|
+
url: window.location.href
|
|
2196
|
+
},
|
|
2197
|
+
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messages)),
|
|
2198
|
+
metadata: {
|
|
2199
|
+
requestType: import_runtime_client_gql5.CopilotRequestType.TextareaCompletion
|
|
2200
|
+
}
|
|
2201
|
+
},
|
|
2202
|
+
properties: copilotApiConfig.properties,
|
|
2203
|
+
signal: abortSignal
|
|
2204
|
+
})
|
|
2205
|
+
);
|
|
2206
|
+
}));
|
|
2207
|
+
return res;
|
|
2208
|
+
}),
|
|
2209
|
+
[editingApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
2210
|
+
);
|
|
2211
|
+
const insertionOrEditingFunction = (0, import_react14.useCallback)(
|
|
2212
|
+
(editorState2, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
2213
|
+
if (editorState2.selectedText === "") {
|
|
2214
|
+
return yield insertionFunction(editorState2, insertionPrompt, documents, abortSignal);
|
|
2215
|
+
} else {
|
|
2216
|
+
return yield editingFunction(editorState2, insertionPrompt, documents, abortSignal);
|
|
2217
|
+
}
|
|
2218
|
+
}),
|
|
2219
|
+
[insertionFunction, editingFunction]
|
|
2220
|
+
);
|
|
2221
|
+
return insertionOrEditingFunction;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
// src/components/copilot-textarea/copilot-textarea.tsx
|
|
2225
|
+
var import_lodash = __toESM(require("lodash.merge"));
|
|
2226
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2227
|
+
var CopilotTextarea = import_react15.default.forwardRef(
|
|
2228
|
+
(props, ref) => {
|
|
2229
|
+
const _a = props, { autosuggestionsConfig: autosuggestionsConfigUserSpecified } = _a, forwardedProps = __objRest(_a, ["autosuggestionsConfig"]);
|
|
2230
|
+
const autosuggestionsConfig = (0, import_lodash.default)(
|
|
2231
|
+
defaultAutosuggestionsConfig,
|
|
2232
|
+
autosuggestionsConfigUserSpecified
|
|
2233
|
+
);
|
|
2234
|
+
const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(
|
|
2235
|
+
autosuggestionsConfig.textareaPurpose,
|
|
2236
|
+
autosuggestionsConfig.contextCategories,
|
|
2237
|
+
autosuggestionsConfig.chatApiConfigs.suggestionsApiConfig
|
|
2238
|
+
);
|
|
2239
|
+
const insertionOrEditingFunction = useMakeStandardInsertionOrEditingFunction(
|
|
2240
|
+
autosuggestionsConfig.textareaPurpose,
|
|
2241
|
+
autosuggestionsConfig.contextCategories,
|
|
2242
|
+
autosuggestionsConfig.chatApiConfigs.insertionApiConfig,
|
|
2243
|
+
autosuggestionsConfig.chatApiConfigs.editingApiConfig
|
|
2244
|
+
);
|
|
2245
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
2246
|
+
BaseCopilotTextarea,
|
|
2247
|
+
__spreadProps(__spreadValues({
|
|
2248
|
+
ref
|
|
2249
|
+
}, forwardedProps), {
|
|
2250
|
+
baseAutosuggestionsConfig: __spreadProps(__spreadValues({}, autosuggestionsConfig), {
|
|
2251
|
+
apiConfig: {
|
|
2252
|
+
insertionOrEditingFunction,
|
|
2253
|
+
autosuggestionsFunction
|
|
2254
|
+
}
|
|
2255
|
+
})
|
|
2256
|
+
})
|
|
2257
|
+
) });
|
|
2258
|
+
}
|
|
2259
|
+
);
|
|
1779
2260
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1780
2261
|
0 && (module.exports = {
|
|
1781
|
-
BaseCopilotTextarea
|
|
2262
|
+
BaseCopilotTextarea,
|
|
2263
|
+
CopilotTextarea
|
|
1782
2264
|
});
|
|
1783
2265
|
//# sourceMappingURL=index.js.map
|