@copilotkit/react-textarea 0.28.0-alpha.1 → 0.28.0-alpha.2
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 +301 -152
- package/CHANGELOG.md +16 -1
- package/dist/{chunk-LQZBI6XD.mjs → chunk-5J3UZV77.mjs} +3 -3
- package/dist/chunk-5J3UZV77.mjs.map +1 -0
- package/dist/{chunk-YLXEQDMS.mjs → chunk-B6TKVDDY.mjs} +5 -5
- package/dist/chunk-B6TKVDDY.mjs.map +1 -0
- package/dist/{chunk-HSCZA5TS.mjs → chunk-BBZ7AWOB.mjs} +2 -2
- package/dist/chunk-BBZ7AWOB.mjs.map +1 -0
- package/dist/{chunk-47L4PLG4.mjs → chunk-LQ2OWQU7.mjs} +1 -1
- package/dist/chunk-LQ2OWQU7.mjs.map +1 -0
- package/dist/{chunk-XV7MLLXQ.mjs → chunk-LYB4B6MK.mjs} +1 -1
- package/dist/chunk-LYB4B6MK.mjs.map +1 -0
- package/dist/{chunk-KJNSWCJC.mjs → chunk-QCPS6IYI.mjs} +6 -10
- package/dist/chunk-QCPS6IYI.mjs.map +1 -0
- package/dist/{chunk-NT3GWKWK.mjs → chunk-RT4UTBH3.mjs} +7 -7
- package/dist/chunk-RT4UTBH3.mjs.map +1 -0
- package/dist/{chunk-JYWINDWZ.mjs → chunk-SNQEBH5I.mjs} +4 -4
- package/dist/{chunk-JYWINDWZ.mjs.map → chunk-SNQEBH5I.mjs.map} +1 -1
- package/dist/{chunk-EPBVNDKE.mjs → chunk-SX6NY5FW.mjs} +1 -1
- package/dist/chunk-SX6NY5FW.mjs.map +1 -0
- package/dist/{chunk-KTTN5H7S.mjs → chunk-VB4VNCIQ.mjs} +6 -4
- package/dist/chunk-VB4VNCIQ.mjs.map +1 -0
- package/dist/{chunk-OHO4G6DR.mjs → chunk-XW3ICO4S.mjs} +1 -1
- package/dist/chunk-XW3ICO4S.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1658 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +8 -8
- package/dist/components/base-copilot-textarea/render-element.js +53 -0
- package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js +51 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +85 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.js +61 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.js +2082 -0
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.mjs +11 -11
- package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +2 -2
- package/dist/components/hovering-toolbar/hovering-editor-provider.js +21 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js +144 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js +842 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +5 -5
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +1 -2
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +544 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +2 -2
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +1 -2
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +564 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +3 -3
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +4 -4
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +122 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +0 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +564 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +3 -3
- package/dist/components/index.js +2083 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +11 -11
- package/dist/components/manual-ui/chip-with-icon.d.ts +1 -3
- package/dist/components/manual-ui/chip-with-icon.js +16 -0
- package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.js +213 -0
- package/dist/components/source-search-box/source-search-box.js.map +1 -0
- package/dist/components/ui/button.js +103 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/card.js +124 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/command.js +243 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/dialog.js +162 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/label.js +78 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/separator.js +86 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/textarea.js +83 -0
- package/dist/components/ui/textarea.js.map +1 -0
- package/dist/context/index.js +4 -0
- package/dist/context/index.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +158 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js +169 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js +151 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +113 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -0
- 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.js +162 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
- package/dist/hooks/misc/use-autosize-textarea.js +19 -0
- package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
- package/dist/index.js +2085 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +12 -12
- package/dist/lib/debouncer.js +54 -0
- package/dist/lib/debouncer.js.map +1 -0
- package/dist/lib/editor-to-text.js +47 -0
- package/dist/lib/editor-to-text.js.map +1 -0
- package/dist/lib/get-text-around-cursor.js +106 -0
- package/dist/lib/get-text-around-cursor.js.map +1 -0
- package/dist/lib/retry.js +20 -0
- package/dist/lib/retry.js.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js +29 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js +24 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.js +31 -0
- package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.js +110 -0
- package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
- package/dist/lib/stream-promise-flatten.js +50 -0
- package/dist/lib/stream-promise-flatten.js.map +1 -0
- package/dist/lib/utils.js +73 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.test.js +10 -0
- package/dist/lib/utils.test.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +4 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js +273 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.js +90 -0
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/index.js +273 -0
- package/dist/types/autosuggestions-config/index.js.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js +81 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +4 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js +4 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js +67 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
- package/dist/types/base/autosuggestion-state.js +4 -0
- package/dist/types/base/autosuggestion-state.js.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.js +4 -0
- package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
- package/dist/types/base/base-autosuggestions-config.js +30 -0
- package/dist/types/base/base-autosuggestions-config.js.map +1 -0
- package/dist/types/base/base-copilot-textarea-props.js +4 -0
- package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
- package/dist/types/base/custom-editor.js +4 -0
- package/dist/types/base/custom-editor.js.map +1 -0
- package/dist/types/base/editor-autocomplete-state.js +21 -0
- package/dist/types/base/editor-autocomplete-state.js.map +1 -0
- package/dist/types/base/index.js +30 -0
- package/dist/types/base/index.js.map +1 -0
- package/dist/types/html-copilot-textarea-element.js +4 -0
- package/dist/types/html-copilot-textarea-element.js.map +1 -0
- package/dist/types/index.js +274 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +8 -7
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +2 -3
- package/src/components/base-copilot-textarea/render-placeholder.tsx +1 -1
- package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +2 -2
- package/src/components/copilot-textarea/copilot-textarea.tsx +1 -1
- package/src/components/hovering-toolbar/hovering-editor-provider.tsx +2 -2
- package/src/components/hovering-toolbar/hovering-toolbar.tsx +4 -5
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +10 -5
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +1 -2
- package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +4 -4
- package/src/components/manual-ui/chip-with-icon.tsx +1 -3
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +10 -11
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +7 -11
- package/tsup.config.ts +1 -2
- package/dist/chunk-47L4PLG4.mjs.map +0 -1
- package/dist/chunk-EPBVNDKE.mjs.map +0 -1
- package/dist/chunk-HSCZA5TS.mjs.map +0 -1
- package/dist/chunk-KJNSWCJC.mjs.map +0 -1
- package/dist/chunk-KTTN5H7S.mjs.map +0 -1
- package/dist/chunk-LQZBI6XD.mjs.map +0 -1
- package/dist/chunk-NT3GWKWK.mjs.map +0 -1
- package/dist/chunk-OHO4G6DR.mjs.map +0 -1
- package/dist/chunk-XV7MLLXQ.mjs.map +0 -1
- package/dist/chunk-YLXEQDMS.mjs.map +0 -1
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactCore = require('@copilotkit/react-core');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defProps = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __async = (__this, __arguments, generator) => {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
var fulfilled = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.next(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var rejected = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.throw(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
42
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/lib/retry.tsx
|
|
47
|
+
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
fn().then(resolve).catch((error) => {
|
|
50
|
+
if (retriesLeft === 1) {
|
|
51
|
+
reject(error);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
56
|
+
}, interval);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
|
|
61
|
+
const { getContextString, copilotApiConfig } = react.useContext(reactCore.CopilotContext);
|
|
62
|
+
return react.useCallback(
|
|
63
|
+
(editorState, abortSignal) => __async(this, null, function* () {
|
|
64
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
65
|
+
const messages = [
|
|
66
|
+
{
|
|
67
|
+
role: "system",
|
|
68
|
+
content: apiConfig.makeSystemPrompt(
|
|
69
|
+
textareaPurpose,
|
|
70
|
+
getContextString([], contextCategories)
|
|
71
|
+
)
|
|
72
|
+
},
|
|
73
|
+
...apiConfig.fewShotMessages,
|
|
74
|
+
{
|
|
75
|
+
role: "user",
|
|
76
|
+
name: "TextAfterCursor",
|
|
77
|
+
content: editorState.textAfterCursor
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
role: "user",
|
|
81
|
+
name: "TextBeforeCursor",
|
|
82
|
+
content: editorState.textBeforeCursor
|
|
83
|
+
}
|
|
84
|
+
];
|
|
85
|
+
const response = yield reactCore.fetchAndDecodeChatCompletionAsText(__spreadProps(__spreadValues({
|
|
86
|
+
messages
|
|
87
|
+
}, apiConfig.forwardedParams), {
|
|
88
|
+
copilotConfig: copilotApiConfig,
|
|
89
|
+
signal: abortSignal
|
|
90
|
+
}));
|
|
91
|
+
if (!response.events) {
|
|
92
|
+
throw new Error("Failed to fetch chat completion");
|
|
93
|
+
}
|
|
94
|
+
const reader = response.events.getReader();
|
|
95
|
+
let result = "";
|
|
96
|
+
while (!abortSignal.aborted) {
|
|
97
|
+
const { done, value } = yield reader.read();
|
|
98
|
+
if (done) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
result += value;
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}));
|
|
105
|
+
return res;
|
|
106
|
+
}),
|
|
107
|
+
[apiConfig, getContextString, contextCategories, textareaPurpose]
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.useMakeStandardAutosuggestionFunction = useMakeStandardAutosuggestionFunction;
|
|
112
|
+
//# sourceMappingURL=out.js.map
|
|
113
|
+
//# sourceMappingURL=use-make-standard-autosuggestions-function.js.map
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx","../../../src/lib/retry.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;;;ACFjC,SAAS,MACd,IACA,cAAsB,GACtB,WAAmB,KACnB,UAAkB,KACN;AACZ,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,OAAG,EACA,KAAK,OAAO,EACZ,MAAM,CAAC,UAAU;AAChB,UAAI,gBAAgB,GAAG;AACrB,eAAO,KAAK;AACZ;AAAA,MACF;AAEA,iBAAW,MAAM;AACf,cAAM,IAAI,cAAc,GAAG,WAAW,SAAS,OAAO,EACnD,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,MACjB,GAAG,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH;;;ADfA,SAAS,0CAA0C;AAe5C,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,kBAAkB,iBAAiB,IAAI,WAAW,cAAc;AAExE,SAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,UAAU;AAAA,cACjB;AAAA,cACA,iBAAiB,CAAC,GAAG,iBAAiB;AAAA,YACxC;AAAA,UACF;AAAA,UACA,GAAG,UAAU;AAAA,UACb;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,QACF;AAEA,cAAM,WAAW,MAAM,mCAAmC;AAAA,UACxD;AAAA,WACG,UAAU,kBAF2C;AAAA,UAGxD,eAAe;AAAA,UACf,QAAQ;AAAA,QACV,EAAC;AAED,YAAI,CAAC,SAAS,QAAQ;AACpB,gBAAM,IAAI,MAAM,iCAAiC;AAAA,QACnD;AAEA,cAAM,SAAS,SAAS,OAAO,UAAU;AAEzC,YAAI,SAAS;AACb,eAAO,CAAC,YAAY,SAAS;AAC3B,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR;AAAA,UACF;AACA,oBAAU;AAAA,QACZ;AACA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF","sourcesContent":["import { Message } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { AutosuggestionsBareFunction, MinimalChatGPTMessage } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\nimport { fetchAndDecodeChatCompletionAsText } from \"@copilotkit/react-core\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[],\n apiConfig: SuggestionsApiConfig,\n): AutosuggestionsBareFunction {\n const { getContextString, copilotApiConfig } = useContext(CopilotContext);\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString([], contextCategories),\n ),\n },\n ...apiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n ];\n\n const response = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...apiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n });\n\n if (!response.events) {\n throw new Error(\"Failed to fetch chat completion\");\n }\n\n const reader = response.events.getReader();\n\n let result = \"\";\n while (!abortSignal.aborted) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n result += value;\n }\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose],\n );\n}\n","export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"]}
|
package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { useMakeStandardAutosuggestionFunction } from '../../chunk-
|
|
1
|
+
export { useMakeStandardAutosuggestionFunction } from '../../chunk-RT4UTBH3.mjs';
|
|
2
2
|
import '../../chunk-KNQIEOFP.mjs';
|
|
3
3
|
import '../../chunk-MRXNTQOX.mjs';
|
|
4
4
|
//# sourceMappingURL=out.js.map
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactCore = require('@copilotkit/react-core');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defProps = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __async = (__this, __arguments, generator) => {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
var fulfilled = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.next(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var rejected = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.throw(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
42
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/lib/retry.tsx
|
|
47
|
+
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
fn().then(resolve).catch((error) => {
|
|
50
|
+
if (retriesLeft === 1) {
|
|
51
|
+
reject(error);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
56
|
+
}, interval);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
|
|
61
|
+
const { getContextString, copilotApiConfig } = react.useContext(reactCore.CopilotContext);
|
|
62
|
+
const insertionFunction = react.useCallback(
|
|
63
|
+
(editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
64
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
65
|
+
const messages = [
|
|
66
|
+
{
|
|
67
|
+
role: "system",
|
|
68
|
+
content: insertionApiConfig.makeSystemPrompt(
|
|
69
|
+
textareaPurpose,
|
|
70
|
+
getContextString(documents, contextCategories)
|
|
71
|
+
)
|
|
72
|
+
},
|
|
73
|
+
...insertionApiConfig.fewShotMessages,
|
|
74
|
+
{
|
|
75
|
+
role: "user",
|
|
76
|
+
name: "TextAfterCursor",
|
|
77
|
+
content: editorState.textAfterCursor
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
role: "user",
|
|
81
|
+
name: "TextBeforeCursor",
|
|
82
|
+
content: editorState.textBeforeCursor
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
role: "user",
|
|
86
|
+
name: "InsertionPrompt",
|
|
87
|
+
content: insertionPrompt
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
const stream = yield reactCore.fetchAndDecodeChatCompletionAsText(__spreadProps(__spreadValues({
|
|
91
|
+
messages
|
|
92
|
+
}, insertionApiConfig.forwardedParams), {
|
|
93
|
+
copilotConfig: copilotApiConfig,
|
|
94
|
+
signal: abortSignal
|
|
95
|
+
}));
|
|
96
|
+
return stream.events;
|
|
97
|
+
}));
|
|
98
|
+
return res;
|
|
99
|
+
}),
|
|
100
|
+
[insertionApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
101
|
+
);
|
|
102
|
+
const editingFunction = react.useCallback(
|
|
103
|
+
(editorState, editingPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
104
|
+
const res = yield retry(() => __async(this, null, function* () {
|
|
105
|
+
const messages = [
|
|
106
|
+
{
|
|
107
|
+
role: "system",
|
|
108
|
+
content: editingApiConfig.makeSystemPrompt(
|
|
109
|
+
textareaPurpose,
|
|
110
|
+
getContextString(documents, contextCategories)
|
|
111
|
+
)
|
|
112
|
+
},
|
|
113
|
+
...editingApiConfig.fewShotMessages,
|
|
114
|
+
{
|
|
115
|
+
role: "user",
|
|
116
|
+
name: "TextBeforeCursor",
|
|
117
|
+
content: editorState.textBeforeCursor
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
role: "user",
|
|
121
|
+
name: "TextToEdit",
|
|
122
|
+
content: editorState.selectedText
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
role: "user",
|
|
126
|
+
name: "TextAfterCursor",
|
|
127
|
+
content: editorState.textAfterCursor
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
role: "user",
|
|
131
|
+
name: "EditingPrompt",
|
|
132
|
+
content: editingPrompt
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
const stream = yield reactCore.fetchAndDecodeChatCompletionAsText(__spreadProps(__spreadValues({
|
|
136
|
+
messages
|
|
137
|
+
}, editingApiConfig.forwardedParams), {
|
|
138
|
+
copilotConfig: copilotApiConfig,
|
|
139
|
+
signal: abortSignal
|
|
140
|
+
}));
|
|
141
|
+
return stream.events;
|
|
142
|
+
}));
|
|
143
|
+
return res;
|
|
144
|
+
}),
|
|
145
|
+
[editingApiConfig, getContextString, contextCategories, textareaPurpose]
|
|
146
|
+
);
|
|
147
|
+
const insertionOrEditingFunction = react.useCallback(
|
|
148
|
+
(editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
|
|
149
|
+
if (editorState.selectedText === "") {
|
|
150
|
+
return yield insertionFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
151
|
+
} else {
|
|
152
|
+
return yield editingFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
153
|
+
}
|
|
154
|
+
}),
|
|
155
|
+
[insertionFunction, editingFunction]
|
|
156
|
+
);
|
|
157
|
+
return insertionOrEditingFunction;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
exports.useMakeStandardInsertionOrEditingFunction = useMakeStandardInsertionOrEditingFunction;
|
|
161
|
+
//# sourceMappingURL=out.js.map
|
|
162
|
+
//# sourceMappingURL=use-make-standard-insertion-function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx","../../../src/lib/retry.tsx"],"names":[],"mappings":"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","sourcesContent":["import { Message } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport { MinimalChatGPTMessage } from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n InsertionEditorApiConfig,\n InsertionEditorState,\n} from \"../../types/base/autosuggestions-bare-function\";\nimport { InsertionsApiConfig } from \"../../types/autosuggestions-config/insertions-api-config\";\nimport { EditingApiConfig } from \"../../types/autosuggestions-config/editing-api-config\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\nimport { fetchAndDecodeChatCompletionAsText } from \"@copilotkit/react-core\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardInsertionOrEditingFunction(\n textareaPurpose: string,\n contextCategories: string[],\n insertionApiConfig: InsertionsApiConfig,\n editingApiConfig: EditingApiConfig,\n): Generator_InsertionOrEditingSuggestion {\n const { getContextString, copilotApiConfig } = useContext(CopilotContext);\n\n const insertionFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: insertionApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n },\n ...insertionApiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: insertionPrompt,\n },\n ];\n\n const stream = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...insertionApiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n });\n return stream.events!;\n });\n\n return res;\n },\n [insertionApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const editingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n editingPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: editingApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n },\n ...editingApiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: editorState.selectedText,\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: editingPrompt,\n },\n ];\n\n const stream = await fetchAndDecodeChatCompletionAsText({\n messages: messages as Message[],\n ...editingApiConfig.forwardedParams,\n copilotConfig: copilotApiConfig,\n signal: abortSignal,\n });\n return stream.events!;\n });\n\n return res;\n },\n [editingApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const insertionOrEditingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n if (editorState.selectedText === \"\") {\n return await insertionFunction(editorState, insertionPrompt, documents, abortSignal);\n } else {\n return await editingFunction(editorState, insertionPrompt, documents, abortSignal);\n }\n },\n [insertionFunction, editingFunction],\n );\n\n return insertionOrEditingFunction;\n}\n","export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { useMakeStandardInsertionOrEditingFunction } from '../../chunk-
|
|
1
|
+
export { useMakeStandardInsertionOrEditingFunction } from '../../chunk-QCPS6IYI.mjs';
|
|
2
2
|
import '../../chunk-KNQIEOFP.mjs';
|
|
3
3
|
import '../../chunk-MRXNTQOX.mjs';
|
|
4
4
|
//# sourceMappingURL=out.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
// src/hooks/misc/use-autosize-textarea.tsx
|
|
6
|
+
var useAutosizeTextArea = (textAreaRef, value) => {
|
|
7
|
+
react.useEffect(() => {
|
|
8
|
+
if (textAreaRef.current !== null) {
|
|
9
|
+
textAreaRef.current.style.height = "0px";
|
|
10
|
+
const scrollHeight = textAreaRef.current.scrollHeight;
|
|
11
|
+
textAreaRef.current.style.height = scrollHeight + "px";
|
|
12
|
+
}
|
|
13
|
+
}, [textAreaRef, value]);
|
|
14
|
+
};
|
|
15
|
+
var use_autosize_textarea_default = useAutosizeTextArea;
|
|
16
|
+
|
|
17
|
+
module.exports = use_autosize_textarea_default;
|
|
18
|
+
//# sourceMappingURL=out.js.map
|
|
19
|
+
//# sourceMappingURL=use-autosize-textarea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/misc/use-autosize-textarea.tsx"],"names":[],"mappings":";AAAA,SAAyB,iBAAiB;AAG1C,IAAM,sBAAsB,CAAC,aAA6C,UAAkB;AAC1F,YAAU,MAAM;AACd,QAAI,YAAY,YAAY,MAAM;AAEhC,kBAAY,QAAQ,MAAM,SAAS;AACnC,YAAM,eAAe,YAAY,QAAQ;AAIzC,kBAAY,QAAQ,MAAM,SAAS,eAAe;AAAA,IACpD;AAAA,EACF,GAAG,CAAC,aAAa,KAAK,CAAC;AACzB;AAEA,IAAO,gCAAQ","sourcesContent":["import { Ref, RefObject, useEffect } from \"react\";\n\n// Updates the height of a <textarea> when the value changes.\nconst useAutosizeTextArea = (textAreaRef: RefObject<HTMLTextAreaElement>, value: string) => {\n useEffect(() => {\n if (textAreaRef.current !== null) {\n // We need to reset the height momentarily to get the correct scrollHeight for the textarea\n textAreaRef.current.style.height = \"0px\";\n const scrollHeight = textAreaRef.current.scrollHeight;\n\n // We then set the height directly, outside of the render loop\n // Trying to set this with state or a ref will product an incorrect value.\n textAreaRef.current.style.height = scrollHeight + \"px\";\n }\n }, [textAreaRef, value]);\n};\n\nexport default useAutosizeTextArea;\n"]}
|