@copilotkit/react-core 0.15.0-alpha.3 → 0.15.0-alpha.5
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 +76 -76
- package/CHANGELOG.md +22 -0
- package/dist/chunk-3MAIWZNZ.mjs +58 -0
- package/dist/chunk-3MAIWZNZ.mjs.map +1 -0
- package/dist/chunk-45PUEKTG.mjs +19 -0
- package/dist/chunk-45PUEKTG.mjs.map +1 -0
- package/dist/chunk-6LKBKYRJ.mjs +165 -0
- package/dist/chunk-6LKBKYRJ.mjs.map +1 -0
- package/dist/chunk-6LNDDH6K.mjs +19 -0
- package/dist/chunk-6LNDDH6K.mjs.map +1 -0
- package/dist/chunk-6N6X7K7T.mjs +13 -0
- package/dist/chunk-6N6X7K7T.mjs.map +1 -0
- package/dist/chunk-7GFKOIO7.mjs +3 -0
- package/dist/chunk-7GFKOIO7.mjs.map +1 -0
- package/dist/chunk-BABVSMJR.mjs +3 -0
- package/dist/chunk-BABVSMJR.mjs.map +1 -0
- package/dist/chunk-E3P5YZO2.mjs +27 -0
- package/dist/chunk-E3P5YZO2.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +3 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-FRAKUJWH.mjs +3 -0
- package/dist/chunk-FRAKUJWH.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +3 -0
- package/dist/chunk-JD7BAH7U.mjs.map +1 -0
- package/dist/chunk-JHJ7LUTD.mjs +125 -0
- package/dist/chunk-JHJ7LUTD.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +55 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-MZ5UN3BY.mjs +28 -0
- package/dist/chunk-MZ5UN3BY.mjs.map +1 -0
- package/dist/chunk-OFRZZ5OF.mjs +79 -0
- package/dist/chunk-OFRZZ5OF.mjs.map +1 -0
- package/dist/chunk-QACD2U6P.mjs +3 -0
- package/dist/chunk-QACD2U6P.mjs.map +1 -0
- package/dist/chunk-SPCZTZCY.mjs +3 -0
- package/dist/chunk-SPCZTZCY.mjs.map +1 -0
- package/dist/chunk-VUY2K2DI.mjs +135 -0
- package/dist/chunk-VUY2K2DI.mjs.map +1 -0
- package/dist/chunk-YPSGKPDA.mjs +3 -0
- package/dist/chunk-YPSGKPDA.mjs.map +1 -0
- package/dist/chunk-YULKJPY3.mjs +70 -0
- package/dist/chunk-YULKJPY3.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-provider-props.mjs +2 -1
- package/dist/components/copilot-provider/copilot-provider-props.mjs.map +1 -1
- package/dist/components/copilot-provider/copilot-provider.mjs +7 -468
- package/dist/components/copilot-provider/copilot-provider.mjs.map +1 -1
- package/dist/components/copilot-provider/index.mjs +8 -467
- package/dist/components/copilot-provider/index.mjs.map +1 -1
- package/dist/components/copilot-provider/standard-cpilot-api-config.mjs +3 -12
- package/dist/components/copilot-provider/standard-cpilot-api-config.mjs.map +1 -1
- package/dist/components/index.mjs +9 -467
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.mjs +3 -81
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.mjs +4 -80
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.mjs +14 -249
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +10 -194
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +3 -68
- package/dist/hooks/use-flat-category-store.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +4 -95
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +4 -87
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +4 -87
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
- package/dist/hooks/use-tree.mjs +3 -153
- package/dist/hooks/use-tree.mjs.map +1 -1
- package/dist/index.mjs +21 -755
- package/dist/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +14 -245
- package/dist/openai-assistants/hooks/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/use-assistants.mjs +8 -52
- package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +13 -246
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -1
- package/dist/openai-assistants/index.mjs +15 -246
- package/dist/openai-assistants/index.mjs.map +1 -1
- package/dist/openai-assistants/utils/index.mjs +4 -46
- package/dist/openai-assistants/utils/index.mjs.map +1 -1
- package/dist/openai-assistants/utils/process-message-stream.mjs +3 -46
- package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -1
- package/dist/types/annotated-function.mjs +2 -0
- package/dist/types/annotated-function.mjs.map +1 -1
- package/dist/types/document-pointer.mjs +2 -0
- package/dist/types/document-pointer.mjs.map +1 -1
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/utils.mjs +2 -0
- package/dist/utils/utils.mjs.map +1 -1
- package/dist/utils/utils.test.mjs +1 -0
- package/dist/utils/utils.test.mjs.map +1 -1
- package/package.json +3 -3
- package/src/hooks/use-copilot-chat.ts +1 -4
- package/src/openai-assistants/hooks/use-copilot-chat-v2.ts +4 -1
package/dist/context/index.mjs
CHANGED
|
@@ -1,81 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/context/copilot-context.tsx
|
|
23
|
-
import React from "react";
|
|
24
|
-
function copilotApiConfigExtrapolator(config) {
|
|
25
|
-
return {
|
|
26
|
-
get chatApiEndpoint() {
|
|
27
|
-
return `${config.chatApiEndpoint}`;
|
|
28
|
-
},
|
|
29
|
-
get chatApiEndpointV2() {
|
|
30
|
-
return `${config.chatApiEndpointV2}`;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
var emptyCopilotContext = {
|
|
35
|
-
entryPoints: {},
|
|
36
|
-
setEntryPoint: () => {
|
|
37
|
-
},
|
|
38
|
-
removeEntryPoint: () => {
|
|
39
|
-
},
|
|
40
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
41
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
42
|
-
})),
|
|
43
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
44
|
-
addContext: () => "",
|
|
45
|
-
removeContext: () => {
|
|
46
|
-
},
|
|
47
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
48
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
49
|
-
removeDocumentContext: () => {
|
|
50
|
-
},
|
|
51
|
-
copilotApiConfig: new class {
|
|
52
|
-
get chatApiEndpoint() {
|
|
53
|
-
throw new Error(
|
|
54
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
get chatApiEndpointV2() {
|
|
58
|
-
throw new Error(
|
|
59
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
get headers() {
|
|
63
|
-
return {};
|
|
64
|
-
}
|
|
65
|
-
get body() {
|
|
66
|
-
return {};
|
|
67
|
-
}
|
|
68
|
-
}()
|
|
69
|
-
};
|
|
70
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
71
|
-
function returnAndThrowInDebug(value) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
74
|
-
);
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
export {
|
|
78
|
-
CopilotContext,
|
|
79
|
-
copilotApiConfigExtrapolator
|
|
80
|
-
};
|
|
1
|
+
import '../chunk-YPSGKPDA.mjs';
|
|
2
|
+
export { CopilotContext, copilotApiConfigExtrapolator } from '../chunk-3MAIWZNZ.mjs';
|
|
3
|
+
import '../chunk-MRXNTQOX.mjs';
|
|
4
|
+
//# sourceMappingURL=out.js.map
|
|
81
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,250 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
var __async = (__this, __arguments, generator) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/hooks/use-copilot-chat.ts
|
|
54
|
-
import { useMemo, useContext } from "react";
|
|
55
|
-
|
|
56
|
-
// src/context/copilot-context.tsx
|
|
57
|
-
import React from "react";
|
|
58
|
-
function copilotApiConfigExtrapolator(config) {
|
|
59
|
-
return {
|
|
60
|
-
get chatApiEndpoint() {
|
|
61
|
-
return `${config.chatApiEndpoint}`;
|
|
62
|
-
},
|
|
63
|
-
get chatApiEndpointV2() {
|
|
64
|
-
return `${config.chatApiEndpointV2}`;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
var emptyCopilotContext = {
|
|
69
|
-
entryPoints: {},
|
|
70
|
-
setEntryPoint: () => {
|
|
71
|
-
},
|
|
72
|
-
removeEntryPoint: () => {
|
|
73
|
-
},
|
|
74
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
75
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
76
|
-
})),
|
|
77
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
78
|
-
addContext: () => "",
|
|
79
|
-
removeContext: () => {
|
|
80
|
-
},
|
|
81
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
82
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
83
|
-
removeDocumentContext: () => {
|
|
84
|
-
},
|
|
85
|
-
copilotApiConfig: new class {
|
|
86
|
-
get chatApiEndpoint() {
|
|
87
|
-
throw new Error(
|
|
88
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
get chatApiEndpointV2() {
|
|
92
|
-
throw new Error(
|
|
93
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
get headers() {
|
|
97
|
-
return {};
|
|
98
|
-
}
|
|
99
|
-
get body() {
|
|
100
|
-
return {};
|
|
101
|
-
}
|
|
102
|
-
}()
|
|
103
|
-
};
|
|
104
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
105
|
-
function returnAndThrowInDebug(value) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
108
|
-
);
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/hooks/use-copilot-chat.ts
|
|
113
|
-
import { useChat } from "ai/react";
|
|
114
|
-
|
|
115
|
-
// src/components/copilot-provider/copilot-provider.tsx
|
|
116
|
-
import { useCallback, useState } from "react";
|
|
117
|
-
import { jsx } from "react/jsx-runtime";
|
|
118
|
-
var defaultCopilotContextCategories = ["global"];
|
|
119
|
-
|
|
120
|
-
// src/hooks/use-copilot-chat.ts
|
|
121
|
-
function useCopilotChat(_a) {
|
|
122
|
-
var _b = _a, {
|
|
123
|
-
makeSystemMessage
|
|
124
|
-
} = _b, options = __objRest(_b, [
|
|
125
|
-
"makeSystemMessage"
|
|
126
|
-
]);
|
|
127
|
-
const {
|
|
128
|
-
getContextString,
|
|
129
|
-
getChatCompletionFunctionDescriptions,
|
|
130
|
-
getFunctionCallHandler,
|
|
131
|
-
copilotApiConfig
|
|
132
|
-
} = useContext(CopilotContext);
|
|
133
|
-
const systemMessage = useMemo(() => {
|
|
134
|
-
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
135
|
-
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
136
|
-
return {
|
|
137
|
-
id: "system",
|
|
138
|
-
content: systemMessageMaker(contextString),
|
|
139
|
-
role: "system"
|
|
140
|
-
};
|
|
141
|
-
}, [getContextString, makeSystemMessage]);
|
|
142
|
-
const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);
|
|
143
|
-
const functionDescriptions = useMemo(() => {
|
|
144
|
-
return getChatCompletionFunctionDescriptions();
|
|
145
|
-
}, [getChatCompletionFunctionDescriptions]);
|
|
146
|
-
const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
147
|
-
api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
|
|
148
|
-
id: options.id,
|
|
149
|
-
initialMessages: initialMessagesWithContext,
|
|
150
|
-
experimental_onFunctionCall: getFunctionCallHandler(),
|
|
151
|
-
headers: __spreadValues(__spreadValues({}, copilotApiConfig.headers), options.headers),
|
|
152
|
-
body: __spreadValues(__spreadValues({
|
|
153
|
-
id: options.id,
|
|
154
|
-
functions: functionDescriptions
|
|
155
|
-
}, copilotApiConfig.body), options.body)
|
|
156
|
-
}));
|
|
157
|
-
const visibleMessages = messages.filter(
|
|
158
|
-
(message) => message.role === "user" || message.role === "assistant"
|
|
159
|
-
);
|
|
160
|
-
return {
|
|
161
|
-
visibleMessages,
|
|
162
|
-
append,
|
|
163
|
-
reload,
|
|
164
|
-
stop,
|
|
165
|
-
isLoading,
|
|
166
|
-
input,
|
|
167
|
-
setInput
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function defaultSystemMessage(contextString) {
|
|
171
|
-
return `
|
|
172
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
173
|
-
|
|
174
|
-
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
175
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
176
|
-
|
|
177
|
-
The user has provided you with the following context:
|
|
178
|
-
\`\`\`
|
|
179
|
-
${contextString}
|
|
180
|
-
\`\`\`
|
|
181
|
-
|
|
182
|
-
They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
|
|
183
|
-
|
|
184
|
-
Please assist them as best you can.
|
|
185
|
-
|
|
186
|
-
You can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.
|
|
187
|
-
|
|
188
|
-
If you would like to call a function, call it without saying anything else.
|
|
189
|
-
`;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// src/hooks/use-make-copilot-actionable.ts
|
|
193
|
-
import { useRef, useContext as useContext2, useEffect, useMemo as useMemo2 } from "react";
|
|
194
|
-
import { nanoid } from "nanoid";
|
|
195
|
-
function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
196
|
-
const idRef = useRef(nanoid());
|
|
197
|
-
const { setEntryPoint, removeEntryPoint } = useContext2(CopilotContext);
|
|
198
|
-
const memoizedAnnotatedFunction = useMemo2(
|
|
199
|
-
() => ({
|
|
200
|
-
name: annotatedFunction.name,
|
|
201
|
-
description: annotatedFunction.description,
|
|
202
|
-
argumentAnnotations: annotatedFunction.argumentAnnotations,
|
|
203
|
-
implementation: annotatedFunction.implementation
|
|
204
|
-
}),
|
|
205
|
-
dependencies
|
|
206
|
-
);
|
|
207
|
-
useEffect(() => {
|
|
208
|
-
setEntryPoint(idRef.current, memoizedAnnotatedFunction);
|
|
209
|
-
return () => {
|
|
210
|
-
removeEntryPoint(idRef.current);
|
|
211
|
-
};
|
|
212
|
-
}, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// src/hooks/use-make-copilot-readable.ts
|
|
216
|
-
import { useContext as useContext3, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
217
|
-
function useMakeCopilotReadable(information, parentId, categories) {
|
|
218
|
-
const { addContext, removeContext } = useContext3(CopilotContext);
|
|
219
|
-
const idRef = useRef2();
|
|
220
|
-
useEffect2(() => {
|
|
221
|
-
const id = addContext(information, parentId, categories);
|
|
222
|
-
idRef.current = id;
|
|
223
|
-
return () => {
|
|
224
|
-
removeContext(id);
|
|
225
|
-
};
|
|
226
|
-
}, [information, parentId, addContext, removeContext]);
|
|
227
|
-
return idRef.current;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/hooks/use-make-copilot-document-readable.ts
|
|
231
|
-
import { useContext as useContext4, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
232
|
-
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
233
|
-
const { addDocumentContext, removeDocumentContext } = useContext4(CopilotContext);
|
|
234
|
-
const idRef = useRef3();
|
|
235
|
-
useEffect3(() => {
|
|
236
|
-
const id = addDocumentContext(document, categories);
|
|
237
|
-
idRef.current = id;
|
|
238
|
-
return () => {
|
|
239
|
-
removeDocumentContext(id);
|
|
240
|
-
};
|
|
241
|
-
}, [addDocumentContext, removeDocumentContext, ...dependencies]);
|
|
242
|
-
return idRef.current;
|
|
243
|
-
}
|
|
244
|
-
export {
|
|
245
|
-
useCopilotChat,
|
|
246
|
-
useMakeCopilotActionable,
|
|
247
|
-
useMakeCopilotDocumentReadable,
|
|
248
|
-
useMakeCopilotReadable
|
|
249
|
-
};
|
|
1
|
+
import '../chunk-QACD2U6P.mjs';
|
|
2
|
+
export { useMakeCopilotDocumentReadable } from '../chunk-6LNDDH6K.mjs';
|
|
3
|
+
export { useMakeCopilotReadable } from '../chunk-45PUEKTG.mjs';
|
|
4
|
+
export { useCopilotChat } from '../chunk-OFRZZ5OF.mjs';
|
|
5
|
+
import '../chunk-JD7BAH7U.mjs';
|
|
6
|
+
import '../chunk-SPCZTZCY.mjs';
|
|
7
|
+
import '../chunk-6LKBKYRJ.mjs';
|
|
8
|
+
import '../chunk-6N6X7K7T.mjs';
|
|
9
|
+
import '../chunk-VUY2K2DI.mjs';
|
|
10
|
+
import '../chunk-YULKJPY3.mjs';
|
|
11
|
+
export { useMakeCopilotActionable } from '../chunk-E3P5YZO2.mjs';
|
|
12
|
+
import '../chunk-3MAIWZNZ.mjs';
|
|
13
|
+
import '../chunk-MRXNTQOX.mjs';
|
|
14
|
+
//# sourceMappingURL=out.js.map
|
|
250
15
|
//# sourceMappingURL=index.mjs.map
|
package/dist/hooks/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-copilot-chat.ts","../../src/context/copilot-context.tsx","../../src/components/copilot-provider/copilot-provider.tsx","../../src/hooks/use-make-copilot-actionable.ts","../../src/hooks/use-make-copilot-readable.ts","../../src/hooks/use-make-copilot-document-readable.ts"],"sourcesContent":["import { useMemo, useContext } from \"react\";\nimport {\n CopilotContext,\n CopilotContextParams,\n copilotApiConfigExtrapolator,\n} from \"../context/copilot-context\";\nimport { useChat } from \"ai/react\";\nimport { ChatRequestOptions, CreateMessage, Message } from \"ai\";\nimport { UseChatOptions } from \"ai\";\nimport { defaultCopilotContextCategories } from \"../components\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: (contextString: string) => string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (\n message: Message | CreateMessage,\n chatRequestOptions?: ChatRequestOptions,\n ) => Promise<string | null | undefined>;\n reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;\n stop: () => void;\n isLoading: boolean;\n input: string;\n setInput: React.Dispatch<React.SetStateAction<string>>;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions): UseCopilotChatReturn {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, makeSystemMessage]);\n\n const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);\n\n const functionDescriptions = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } = useChat({\n ...options,\n api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,\n id: options.id,\n initialMessages: initialMessagesWithContext,\n experimental_onFunctionCall: getFunctionCallHandler(),\n headers: { ...copilotApiConfig.headers, ...options.headers },\n body: {\n id: options.id,\n functions: functionDescriptions,\n ...copilotApiConfig.body,\n ...options.body,\n },\n });\n\n const visibleMessages = messages.filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n );\n\n return {\n visibleMessages,\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\n };\n}\n\nexport function defaultSystemMessage(contextString: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n`;\n}\n","\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n}\n\nexport function copilotApiConfigExtrapolator(config: CopilotApiConfig) {\n return {\n get chatApiEndpoint(): string {\n return `${config.chatApiEndpoint}`;\n },\n get chatApiEndpointV2(): string {\n return `${config.chatApiEndpointV2}`;\n },\n };\n}\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: () => ChatCompletionCreateParams.Function[];\n getFunctionCallHandler: () => FunctionCallHandler;\n\n // text context\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\",\n );\n }\n get chatApiEndpointV2(): string {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\",\n );\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\",\n );\n return value;\n}\n","\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\nimport { useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../../types\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { StandardCopilotApiConfig } from \"./standard-cpilot-api-config\";\nimport { CopilotProviderProps } from \"./copilot-provider-props\";\n\n/**\n * The CopilotProvider component.\n * This component provides the Copilot context to its children.\n * It can be configured either with a chat API endpoint or a CopilotApiConfig.\n *\n * Example usage:\n * ```\n * <CopilotProvider chatApiEndpoint=\"https://api.copilot.chat\">\n * <App />\n * </CopilotProvider>\n * ```\n *\n * or\n *\n * ```\n * const copilotApiConfig = new StandardCopilotApiConfig(\n * \"https://api.copilot.chat\",\n * \"https://api.copilot.chat/v2\",\n * {},\n * {}\n * );\n *\n * // ...\n *\n * <CopilotProvider chatApiConfig={copilotApiConfig}>\n * <App />\n * </CopilotProvider>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotProvider component.\n */\nexport function CopilotProvider({ children, ...props }: CopilotProviderProps): JSX.Element {\n // Compute all the functions and properties that we need to pass\n // to the CopilotContext.\n\n const [entryPoints, setEntryPoints] = useState<Record<string, AnnotatedFunction<any[]>>>({});\n\n const { addElement, removeElement, printTree } = useTree();\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback((id: string, entryPoint: AnnotatedFunction<any[]>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n }, []);\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (documents: DocumentPointer[], categories: string[]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${document.sourceApplication}):\\n${document.getContents()}`;\n })\n .join(\"\\n\\n\");\n\n const nonDocumentStrings = printTree(categories);\n\n return `${documentsString}\\n\\n${nonDocumentStrings}`;\n },\n [printTree],\n );\n\n const addContext = useCallback(\n (\n context: string,\n parentId?: string,\n categories: string[] = defaultCopilotContextCategories,\n ) => {\n return addElement(context, categories, parentId);\n },\n [addElement],\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement],\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(() => {\n return entryPointsToChatCompletionFunctions(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getFunctionCallHandler = useCallback(() => {\n return entryPointsToFunctionCallHandler(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getDocumentsContext = useCallback(\n (categories: string[]) => {\n return allDocuments(categories);\n },\n [allDocuments],\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument],\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument],\n );\n\n // get the appropriate CopilotApiConfig from the props\n let copilotApiConfig: CopilotApiConfig;\n if (\"chatApiEndpoint\" in props) {\n copilotApiConfig = new StandardCopilotApiConfig(\n props.chatApiEndpoint,\n props.chatApiEndpointV2 || `${props.chatApiEndpoint}/v2`,\n {},\n {},\n );\n } else {\n copilotApiConfig = props.chatApiConfig;\n }\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: copilotApiConfig,\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[],\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<string, AnnotatedFunction<any[]>> = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction = entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let parsedFunctionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n parsedFunctionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n parsedFunctionCallArguments[arg.name as keyof typeof parsedFunctionCallArguments],\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[],\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n","\"use client\";\n\nimport { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { nanoid } from \"nanoid\";\n\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[],\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies,\n );\n\n useEffect(() => {\n setEntryPoint(idRef.current, memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n","\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n * @param information - The information to be added to the Copilot context.\n * @param parentId - The ID of the parent context, if any.\n * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n * @returns The ID of the added context.\n */\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string,\n categories?: string[],\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n","\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, remove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A,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAAIC,YAAW,cAAc;AAC/E,QAAM,QAAQC,QAAe;AAE7B,EAAAC,WAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,GAAG,YAAY,CAAC;AAE/D,SAAO,MAAM;AACf;","names":["useContext","useMemo","useContext","useMemo","useContext","useEffect","useRef","useContext","useRef","useEffect","useContext","useEffect","useRef","useContext","useRef","useEffect"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -1,195 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
var __async = (__this, __arguments, generator) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/hooks/use-copilot-chat.ts
|
|
54
|
-
import { useMemo, useContext } from "react";
|
|
55
|
-
|
|
56
|
-
// src/context/copilot-context.tsx
|
|
57
|
-
import React from "react";
|
|
58
|
-
function copilotApiConfigExtrapolator(config) {
|
|
59
|
-
return {
|
|
60
|
-
get chatApiEndpoint() {
|
|
61
|
-
return `${config.chatApiEndpoint}`;
|
|
62
|
-
},
|
|
63
|
-
get chatApiEndpointV2() {
|
|
64
|
-
return `${config.chatApiEndpointV2}`;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
var emptyCopilotContext = {
|
|
69
|
-
entryPoints: {},
|
|
70
|
-
setEntryPoint: () => {
|
|
71
|
-
},
|
|
72
|
-
removeEntryPoint: () => {
|
|
73
|
-
},
|
|
74
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
75
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
76
|
-
})),
|
|
77
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
78
|
-
addContext: () => "",
|
|
79
|
-
removeContext: () => {
|
|
80
|
-
},
|
|
81
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
82
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
83
|
-
removeDocumentContext: () => {
|
|
84
|
-
},
|
|
85
|
-
copilotApiConfig: new class {
|
|
86
|
-
get chatApiEndpoint() {
|
|
87
|
-
throw new Error(
|
|
88
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
get chatApiEndpointV2() {
|
|
92
|
-
throw new Error(
|
|
93
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
get headers() {
|
|
97
|
-
return {};
|
|
98
|
-
}
|
|
99
|
-
get body() {
|
|
100
|
-
return {};
|
|
101
|
-
}
|
|
102
|
-
}()
|
|
103
|
-
};
|
|
104
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
105
|
-
function returnAndThrowInDebug(value) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
108
|
-
);
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/hooks/use-copilot-chat.ts
|
|
113
|
-
import { useChat } from "ai/react";
|
|
114
|
-
|
|
115
|
-
// src/components/copilot-provider/copilot-provider.tsx
|
|
116
|
-
import { useCallback, useState } from "react";
|
|
117
|
-
import { jsx } from "react/jsx-runtime";
|
|
118
|
-
var defaultCopilotContextCategories = ["global"];
|
|
119
|
-
|
|
120
|
-
// src/hooks/use-copilot-chat.ts
|
|
121
|
-
function useCopilotChat(_a) {
|
|
122
|
-
var _b = _a, {
|
|
123
|
-
makeSystemMessage
|
|
124
|
-
} = _b, options = __objRest(_b, [
|
|
125
|
-
"makeSystemMessage"
|
|
126
|
-
]);
|
|
127
|
-
const {
|
|
128
|
-
getContextString,
|
|
129
|
-
getChatCompletionFunctionDescriptions,
|
|
130
|
-
getFunctionCallHandler,
|
|
131
|
-
copilotApiConfig
|
|
132
|
-
} = useContext(CopilotContext);
|
|
133
|
-
const systemMessage = useMemo(() => {
|
|
134
|
-
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
135
|
-
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
136
|
-
return {
|
|
137
|
-
id: "system",
|
|
138
|
-
content: systemMessageMaker(contextString),
|
|
139
|
-
role: "system"
|
|
140
|
-
};
|
|
141
|
-
}, [getContextString, makeSystemMessage]);
|
|
142
|
-
const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);
|
|
143
|
-
const functionDescriptions = useMemo(() => {
|
|
144
|
-
return getChatCompletionFunctionDescriptions();
|
|
145
|
-
}, [getChatCompletionFunctionDescriptions]);
|
|
146
|
-
const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
147
|
-
api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
|
|
148
|
-
id: options.id,
|
|
149
|
-
initialMessages: initialMessagesWithContext,
|
|
150
|
-
experimental_onFunctionCall: getFunctionCallHandler(),
|
|
151
|
-
headers: __spreadValues(__spreadValues({}, copilotApiConfig.headers), options.headers),
|
|
152
|
-
body: __spreadValues(__spreadValues({
|
|
153
|
-
id: options.id,
|
|
154
|
-
functions: functionDescriptions
|
|
155
|
-
}, copilotApiConfig.body), options.body)
|
|
156
|
-
}));
|
|
157
|
-
const visibleMessages = messages.filter(
|
|
158
|
-
(message) => message.role === "user" || message.role === "assistant"
|
|
159
|
-
);
|
|
160
|
-
return {
|
|
161
|
-
visibleMessages,
|
|
162
|
-
append,
|
|
163
|
-
reload,
|
|
164
|
-
stop,
|
|
165
|
-
isLoading,
|
|
166
|
-
input,
|
|
167
|
-
setInput
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function defaultSystemMessage(contextString) {
|
|
171
|
-
return `
|
|
172
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
173
|
-
|
|
174
|
-
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
175
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
176
|
-
|
|
177
|
-
The user has provided you with the following context:
|
|
178
|
-
\`\`\`
|
|
179
|
-
${contextString}
|
|
180
|
-
\`\`\`
|
|
181
|
-
|
|
182
|
-
They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
|
|
183
|
-
|
|
184
|
-
Please assist them as best you can.
|
|
185
|
-
|
|
186
|
-
You can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.
|
|
187
|
-
|
|
188
|
-
If you would like to call a function, call it without saying anything else.
|
|
189
|
-
`;
|
|
190
|
-
}
|
|
191
|
-
export {
|
|
192
|
-
defaultSystemMessage,
|
|
193
|
-
useCopilotChat
|
|
194
|
-
};
|
|
1
|
+
export { defaultSystemMessage, useCopilotChat } from '../chunk-OFRZZ5OF.mjs';
|
|
2
|
+
import '../chunk-JD7BAH7U.mjs';
|
|
3
|
+
import '../chunk-SPCZTZCY.mjs';
|
|
4
|
+
import '../chunk-6LKBKYRJ.mjs';
|
|
5
|
+
import '../chunk-6N6X7K7T.mjs';
|
|
6
|
+
import '../chunk-VUY2K2DI.mjs';
|
|
7
|
+
import '../chunk-YULKJPY3.mjs';
|
|
8
|
+
import '../chunk-3MAIWZNZ.mjs';
|
|
9
|
+
import '../chunk-MRXNTQOX.mjs';
|
|
10
|
+
//# sourceMappingURL=out.js.map
|
|
195
11
|
//# sourceMappingURL=use-copilot-chat.mjs.map
|