@copilotkit/react-core 0.18.0-alpha.1 → 0.18.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 +184 -122
- package/CHANGELOG.md +14 -1
- package/dist/{chunk-6A4PCNMZ.mjs → chunk-4CFJ6A6A.mjs} +4 -10
- package/dist/chunk-4CFJ6A6A.mjs.map +1 -0
- package/dist/{chunk-FY7XNRJP.mjs → chunk-5GS7FQPW.mjs} +4 -4
- package/dist/chunk-5GS7FQPW.mjs.map +1 -0
- package/dist/{chunk-FP4EXCGS.mjs → chunk-DGUVNY3V.mjs} +2 -2
- package/dist/chunk-DGUVNY3V.mjs.map +1 -0
- package/dist/{chunk-D4NQCVHE.mjs → chunk-GBZZPQ5X.mjs} +11 -38
- package/dist/chunk-GBZZPQ5X.mjs.map +1 -0
- package/dist/chunk-IQEWY7P4.mjs +102 -0
- package/dist/chunk-IQEWY7P4.mjs.map +1 -0
- package/dist/{chunk-7P4OYNP3.mjs → chunk-IQH5AQQC.mjs} +2 -2
- package/dist/chunk-UAKLDQMP.mjs +61 -0
- package/dist/chunk-UAKLDQMP.mjs.map +1 -0
- package/dist/{chunk-P34OLW2N.mjs → chunk-VP2EU4US.mjs} +3 -3
- package/dist/{chunk-HW5IH6PV.mjs → chunk-YOXWT7I6.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +39 -0
- package/dist/components/copilot-provider/copilotkit-props.js +4 -0
- package/dist/components/copilot-provider/copilotkit-props.mjs +3 -0
- package/dist/components/copilot-provider/{copilot-provider.d.ts → copilotkit.d.ts} +9 -15
- package/dist/components/copilot-provider/copilotkit.js +426 -0
- package/dist/components/copilot-provider/copilotkit.js.map +1 -0
- package/dist/components/copilot-provider/copilotkit.mjs +8 -0
- package/dist/components/copilot-provider/index.d.ts +2 -8
- package/dist/components/copilot-provider/index.js +426 -0
- package/dist/components/copilot-provider/index.js.map +1 -0
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/copilot-provider/standard-copilot-api-config.d.ts +2 -4
- package/dist/components/copilot-provider/standard-copilot-api-config.js +15 -0
- package/dist/components/copilot-provider/standard-copilot-api-config.js.map +1 -0
- package/dist/components/index.d.ts +2 -8
- package/dist/components/index.js +426 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +3 -5
- package/dist/context/copilot-context.js +47 -0
- package/dist/context/copilot-context.js.map +1 -0
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +2 -4
- package/dist/context/index.js +47 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +2 -4
- package/dist/hooks/index.js +358 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +8 -9
- package/dist/hooks/use-chat.d.ts +2 -4
- package/dist/hooks/use-chat.js +186 -0
- package/dist/hooks/use-chat.js.map +1 -0
- package/dist/hooks/use-chat.mjs +2 -3
- package/dist/hooks/use-copilot-chat.d.ts +2 -4
- package/dist/hooks/use-copilot-chat.js +313 -0
- package/dist/hooks/use-copilot-chat.js.map +1 -0
- package/dist/hooks/use-copilot-chat.mjs +5 -6
- package/dist/hooks/use-flat-category-store.js +72 -0
- package/dist/hooks/use-flat-category-store.js.map +1 -0
- package/dist/hooks/use-make-copilot-actionable.d.ts +1 -1
- package/dist/hooks/use-make-copilot-actionable.js +67 -0
- package/dist/hooks/use-make-copilot-actionable.js.map +1 -0
- package/dist/hooks/use-make-copilot-actionable.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +61 -0
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-readable.js +61 -0
- package/dist/hooks/use-make-copilot-readable.js.map +1 -0
- package/dist/hooks/use-make-copilot-readable.mjs +2 -2
- package/dist/hooks/use-tree.js +155 -0
- package/dist/hooks/use-tree.js.map +1 -0
- package/dist/index.d.ts +4 -9
- package/dist/index.js +838 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +10 -13
- package/dist/openai-assistants/hooks/index.js +225 -0
- package/dist/openai-assistants/hooks/index.js.map +1 -0
- package/dist/openai-assistants/hooks/index.mjs +3 -3
- package/dist/openai-assistants/hooks/use-assistants.js +129 -0
- package/dist/openai-assistants/hooks/use-assistants.js.map +1 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +226 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +3 -3
- package/dist/openai-assistants/index.js +226 -0
- package/dist/openai-assistants/index.js.map +1 -0
- package/dist/openai-assistants/index.mjs +3 -3
- package/dist/openai-assistants/utils/index.js +49 -0
- package/dist/openai-assistants/utils/index.js.map +1 -0
- package/dist/openai-assistants/utils/process-message-stream.js +49 -0
- package/dist/openai-assistants/utils/process-message-stream.js.map +1 -0
- package/dist/types/document-pointer.js +4 -0
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.js +4 -0
- package/dist/types/system-message.js +4 -0
- package/dist/utils/fetch-chat-completion.d.ts +28 -0
- package/dist/utils/fetch-chat-completion.js +103 -0
- package/dist/utils/fetch-chat-completion.js.map +1 -0
- package/dist/utils/fetch-chat-completion.mjs +4 -0
- package/dist/utils/utils.js +4 -0
- package/dist/utils/utils.test.js +10 -0
- package/dist/utils/utils.test.js.map +1 -0
- package/package.json +8 -8
- package/src/components/copilot-provider/copilotkit-props.tsx +42 -0
- package/src/components/copilot-provider/{copilot-provider.tsx → copilotkit.tsx} +22 -57
- package/src/components/copilot-provider/index.ts +2 -6
- package/src/context/copilot-context.tsx +5 -13
- package/src/hooks/use-chat.ts +54 -72
- package/src/hooks/use-copilot-chat.ts +4 -4
- package/src/hooks/use-make-copilot-actionable.ts +1 -1
- package/src/index.tsx +6 -1
- package/src/types/index.ts +0 -3
- package/src/utils/fetch-chat-completion.ts +95 -0
- package/tsup.config.ts +1 -2
- package/dist/chunk-6A4PCNMZ.mjs.map +0 -1
- package/dist/chunk-6SOQYBNX.mjs +0 -44
- package/dist/chunk-6SOQYBNX.mjs.map +0 -1
- package/dist/chunk-D4NQCVHE.mjs.map +0 -1
- package/dist/chunk-FP4EXCGS.mjs.map +0 -1
- package/dist/chunk-FY7XNRJP.mjs.map +0 -1
- package/dist/chunk-LMZN4NSM.mjs +0 -113
- package/dist/chunk-LMZN4NSM.mjs.map +0 -1
- package/dist/chunk-PUFR5OAI.mjs +0 -3
- package/dist/chunk-TKXPMMND.mjs +0 -177
- package/dist/chunk-TKXPMMND.mjs.map +0 -1
- package/dist/chunk-VK25FIML.mjs +0 -144
- package/dist/chunk-VK25FIML.mjs.map +0 -1
- package/dist/components/copilot-provider/copilot-provider-props.d.ts +0 -50
- package/dist/components/copilot-provider/copilot-provider-props.mjs +0 -3
- package/dist/components/copilot-provider/copilot-provider.mjs +0 -8
- package/dist/openai/chat-completion-client.d.ts +0 -52
- package/dist/openai/chat-completion-client.mjs +0 -5
- package/dist/openai/chat-completion-stream.d.ts +0 -21
- package/dist/openai/chat-completion-stream.mjs +0 -5
- package/dist/openai/chat-completion-transport.d.ts +0 -38
- package/dist/openai/chat-completion-transport.mjs +0 -4
- package/dist/openai/index.d.ts +0 -10
- package/dist/openai/index.mjs +0 -6
- package/dist/types/annotated-function.d.ts +0 -24
- package/dist/types/annotated-function.mjs +0 -3
- package/dist/types/base.d.ts +0 -56
- package/dist/types/base.mjs +0 -3
- package/dist/types/base.mjs.map +0 -1
- package/src/components/copilot-provider/copilot-provider-props.tsx +0 -50
- package/src/openai/chat-completion-client.ts +0 -229
- package/src/openai/chat-completion-stream.ts +0 -54
- package/src/openai/chat-completion-transport.ts +0 -186
- package/src/openai/index.tsx +0 -5
- package/src/types/annotated-function.ts +0 -27
- package/src/types/base.ts +0 -61
- /package/dist/{chunk-7P4OYNP3.mjs.map → chunk-IQH5AQQC.mjs.map} +0 -0
- /package/dist/{chunk-P34OLW2N.mjs.map → chunk-VP2EU4US.mjs.map} +0 -0
- /package/dist/{chunk-HW5IH6PV.mjs.map → chunk-YOXWT7I6.mjs.map} +0 -0
- /package/dist/{chunk-PUFR5OAI.mjs.map → components/copilot-provider/copilotkit-props.js.map} +0 -0
- /package/dist/components/copilot-provider/{copilot-provider-props.mjs.map → copilotkit-props.mjs.map} +0 -0
- /package/dist/components/copilot-provider/{copilot-provider.mjs.map → copilotkit.mjs.map} +0 -0
- /package/dist/{openai/chat-completion-client.mjs.map → types/document-pointer.js.map} +0 -0
- /package/dist/{openai/chat-completion-stream.mjs.map → types/index.js.map} +0 -0
- /package/dist/{openai/chat-completion-transport.mjs.map → types/system-message.js.map} +0 -0
- /package/dist/{openai/index.mjs.map → utils/fetch-chat-completion.mjs.map} +0 -0
- /package/dist/{types/annotated-function.mjs.map → utils/utils.js.map} +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __async = (__this, __arguments, generator) => {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
var fulfilled = (value) => {
|
|
6
|
+
try {
|
|
7
|
+
step(generator.next(value));
|
|
8
|
+
} catch (e) {
|
|
9
|
+
reject(e);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var rejected = (value) => {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.throw(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
20
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/openai-assistants/utils/process-message-stream.ts
|
|
25
|
+
function processMessageStream(reader, processMessage) {
|
|
26
|
+
return __async(this, null, function* () {
|
|
27
|
+
const decoder = new TextDecoder();
|
|
28
|
+
let buffer = "";
|
|
29
|
+
while (true) {
|
|
30
|
+
const { done, value } = yield reader.read();
|
|
31
|
+
if (done) {
|
|
32
|
+
if (buffer.length > 0) {
|
|
33
|
+
processMessage(buffer);
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
buffer += decoder.decode(value, { stream: true });
|
|
38
|
+
let endIndex;
|
|
39
|
+
while ((endIndex = buffer.indexOf("\n")) !== -1) {
|
|
40
|
+
processMessage(buffer.substring(0, endIndex).trim());
|
|
41
|
+
buffer = buffer.substring(endIndex + 1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.processMessageStream = processMessageStream;
|
|
48
|
+
//# sourceMappingURL=out.js.map
|
|
49
|
+
//# sourceMappingURL=process-message-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/openai-assistants/utils/process-message-stream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAsB,qBACpB,QACA,gBACA;AAAA;AACA,UAAM,UAAU,IAAI,YAAY;AAChC,QAAI,SAAS;AACb,WAAO,MAAM;AACX,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,UAAI,MAAM;AACR,YAAI,OAAO,SAAS,GAAG;AACrB,yBAAe,MAAM;AAAA,QACvB;AACA;AAAA,MACF;AAEA,gBAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAEhD,UAAI;AACJ,cAAQ,WAAW,OAAO,QAAQ,IAAI,OAAO,IAAI;AAC/C,uBAAe,OAAO,UAAU,GAAG,QAAQ,EAAE,KAAK,CAAC;AACnD,iBAAS,OAAO,UAAU,WAAW,CAAC;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAAA","sourcesContent":["export async function processMessageStream(\n reader: ReadableStreamDefaultReader<Uint8Array>,\n processMessage: (message: string) => void | Promise<void>,\n) {\n const decoder = new TextDecoder();\n let buffer = \"\";\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n if (buffer.length > 0) {\n processMessage(buffer);\n }\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n let endIndex: number;\n while ((endIndex = buffer.indexOf(\"\\n\")) !== -1) {\n processMessage(buffer.substring(0, endIndex).trim());\n buffer = buffer.substring(endIndex + 1); // Remove the processed instruction + delimiter\n }\n }\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export { AnnotatedFunction, AnnotatedFunctionArgument } from './annotated-function.js';
|
|
2
1
|
export { DocumentPointer } from './document-pointer.js';
|
|
3
|
-
export { Function, FunctionCall, FunctionCallHandler, Message, Role } from './base.js';
|
|
4
2
|
export { SystemMessageFunction } from './system-message.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Message, Function, ChatCompletionEvent } from '@copilotkit/shared';
|
|
2
|
+
import { CopilotApiConfig } from '../context/copilot-context.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '../hooks/use-tree.js';
|
|
5
|
+
import '../types/document-pointer.js';
|
|
6
|
+
|
|
7
|
+
interface FetchChatCompletionParams {
|
|
8
|
+
copilotConfig: CopilotApiConfig;
|
|
9
|
+
model?: string;
|
|
10
|
+
messages: Message[];
|
|
11
|
+
functions?: Function[];
|
|
12
|
+
temperature?: number;
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
headers?: Record<string, string> | Headers;
|
|
15
|
+
body?: object;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
declare function fetchChatCompletion({ copilotConfig, model, messages, functions, temperature, headers, body, signal, }: FetchChatCompletionParams): Promise<Response>;
|
|
19
|
+
interface DecodedChatCompletionResponse extends Response {
|
|
20
|
+
events: ReadableStream<ChatCompletionEvent> | null;
|
|
21
|
+
}
|
|
22
|
+
declare function fetchAndDecodeChatCompletion(params: FetchChatCompletionParams): Promise<DecodedChatCompletionResponse>;
|
|
23
|
+
interface DecodedChatCompletionResponseAsText extends Response {
|
|
24
|
+
events: ReadableStream<string> | null;
|
|
25
|
+
}
|
|
26
|
+
declare function fetchAndDecodeChatCompletionAsText(params: FetchChatCompletionParams): Promise<DecodedChatCompletionResponseAsText>;
|
|
27
|
+
|
|
28
|
+
export { DecodedChatCompletionResponse, DecodedChatCompletionResponseAsText, FetchChatCompletionParams, fetchAndDecodeChatCompletion, fetchAndDecodeChatCompletionAsText, fetchChatCompletion };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var shared = require('@copilotkit/shared');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defProps = Object.defineProperties;
|
|
7
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var fulfilled = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.next(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rejected = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.throw(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
function fetchChatCompletion(_0) {
|
|
45
|
+
return __async(this, arguments, function* ({
|
|
46
|
+
copilotConfig,
|
|
47
|
+
model,
|
|
48
|
+
messages,
|
|
49
|
+
functions,
|
|
50
|
+
temperature,
|
|
51
|
+
headers,
|
|
52
|
+
body,
|
|
53
|
+
signal
|
|
54
|
+
}) {
|
|
55
|
+
temperature || (temperature = 0.5);
|
|
56
|
+
functions || (functions = []);
|
|
57
|
+
const cleanedMessages = messages.map((message) => {
|
|
58
|
+
const { content, role, name, function_call } = message;
|
|
59
|
+
return { content, role, name, function_call };
|
|
60
|
+
});
|
|
61
|
+
const response = yield fetch(copilotConfig.chatApiEndpoint, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: __spreadValues(__spreadValues({
|
|
64
|
+
"Content-Type": "application/json"
|
|
65
|
+
}, copilotConfig.headers), headers ? __spreadValues({}, headers) : {}),
|
|
66
|
+
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
67
|
+
model,
|
|
68
|
+
messages: cleanedMessages,
|
|
69
|
+
stream: true
|
|
70
|
+
}, functions.length ? { functions } : {}), temperature ? { temperature } : {}), functions.length != 0 ? { function_call: "auto" } : {}), copilotConfig.body), body ? __spreadValues({}, body) : {})),
|
|
71
|
+
signal
|
|
72
|
+
});
|
|
73
|
+
return response;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function fetchAndDecodeChatCompletion(params) {
|
|
77
|
+
return __async(this, null, function* () {
|
|
78
|
+
const response = yield fetchChatCompletion(params);
|
|
79
|
+
if (!response.ok || !response.body) {
|
|
80
|
+
return __spreadProps(__spreadValues({}, response), { events: null });
|
|
81
|
+
}
|
|
82
|
+
const events = yield shared.decodeChatCompletion(shared.parseChatCompletion(response.body));
|
|
83
|
+
return __spreadProps(__spreadValues({}, response), { events });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function fetchAndDecodeChatCompletionAsText(params) {
|
|
87
|
+
return __async(this, null, function* () {
|
|
88
|
+
const response = yield fetchChatCompletion(params);
|
|
89
|
+
if (!response.ok || !response.body) {
|
|
90
|
+
return __spreadProps(__spreadValues({}, response), { events: null });
|
|
91
|
+
}
|
|
92
|
+
const events = yield shared.decodeChatCompletionAsText(
|
|
93
|
+
shared.decodeChatCompletion(shared.parseChatCompletion(response.body))
|
|
94
|
+
);
|
|
95
|
+
return __spreadProps(__spreadValues({}, response), { events });
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
exports.fetchAndDecodeChatCompletion = fetchAndDecodeChatCompletion;
|
|
100
|
+
exports.fetchAndDecodeChatCompletionAsText = fetchAndDecodeChatCompletionAsText;
|
|
101
|
+
exports.fetchChatCompletion = fetchChatCompletion;
|
|
102
|
+
//# sourceMappingURL=out.js.map
|
|
103
|
+
//# sourceMappingURL=fetch-chat-completion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/fetch-chat-completion.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeP,SAAsB,oBAAoB,IASO;AAAA,6CATP;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAiD;AAC/C,kCAAgB;AAChB,8BAAc,CAAC;AAGf,UAAM,kBAAkB,SAAS,IAAI,CAAC,YAAY;AAChD,YAAM,EAAE,SAAS,MAAM,MAAM,cAAc,IAAI;AAC/C,aAAO,EAAE,SAAS,MAAM,MAAM,cAAc;AAAA,IAC9C,CAAC;AAED,UAAM,WAAW,MAAM,MAAM,cAAc,iBAAiB;AAAA,MAC1D,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,SACb,cAAc,UACb,UAAU,mBAAK,WAAY,CAAC;AAAA,MAElC,MAAM,KAAK,UAAU;AAAA,QACnB;AAAA,QACA,UAAU;AAAA,QACV,QAAQ;AAAA,SACJ,UAAU,SAAS,EAAE,UAAU,IAAI,CAAC,IACpC,cAAc,EAAE,YAAY,IAAI,CAAC,IACjC,UAAU,UAAU,IAAI,EAAE,eAAe,OAAO,IAAI,CAAC,IACtD,cAAc,OACb,OAAO,mBAAK,QAAS,CAAC,EAC3B;AAAA,MACD;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAMA,SAAsB,6BACpB,QACwC;AAAA;AACxC,UAAM,WAAW,MAAM,oBAAoB,MAAM;AACjD,QAAI,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM;AAClC,aAAO,iCAAK,WAAL,EAAe,QAAQ,KAAK;AAAA,IACrC;AACA,UAAM,SAAS,MAAM,qBAAqB,oBAAoB,SAAS,IAAI,CAAC;AAC5E,WAAO,iCAAK,WAAL,EAAe,OAAO;AAAA,EAC/B;AAAA;AAMA,SAAsB,mCACpB,QAC8C;AAAA;AAC9C,UAAM,WAAW,MAAM,oBAAoB,MAAM;AACjD,QAAI,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM;AAClC,aAAO,iCAAK,WAAL,EAAe,QAAQ,KAAK;AAAA,IACrC;AACA,UAAM,SAAS,MAAM;AAAA,MACnB,qBAAqB,oBAAoB,SAAS,IAAI,CAAC;AAAA,IACzD;AACA,WAAO,iCAAK,WAAL,EAAe,OAAO;AAAA,EAC/B;AAAA","sourcesContent":["import {\n Message,\n Function,\n ChatCompletionEvent,\n decodeChatCompletion,\n parseChatCompletion,\n decodeChatCompletionAsText,\n} from \"@copilotkit/shared\";\nimport { CopilotApiConfig } from \"../context\";\n\nexport interface FetchChatCompletionParams {\n copilotConfig: CopilotApiConfig;\n model?: string;\n messages: Message[];\n functions?: Function[];\n temperature?: number;\n maxTokens?: number;\n headers?: Record<string, string> | Headers;\n body?: object;\n signal?: AbortSignal;\n}\n\nexport async function fetchChatCompletion({\n copilotConfig,\n model,\n messages,\n functions,\n temperature,\n headers,\n body,\n signal,\n}: FetchChatCompletionParams): Promise<Response> {\n temperature ||= 0.5;\n functions ||= [];\n\n // clean up any extra properties from messages\n const cleanedMessages = messages.map((message) => {\n const { content, role, name, function_call } = message;\n return { content, role, name, function_call };\n });\n\n const response = await fetch(copilotConfig.chatApiEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotConfig.headers,\n ...(headers ? { ...headers } : {}),\n },\n body: JSON.stringify({\n model,\n messages: cleanedMessages,\n stream: true,\n ...(functions.length ? { functions } : {}),\n ...(temperature ? { temperature } : {}),\n ...(functions.length != 0 ? { function_call: \"auto\" } : {}),\n ...copilotConfig.body,\n ...(body ? { ...body } : {}),\n }),\n signal,\n });\n\n return response;\n}\n\nexport interface DecodedChatCompletionResponse extends Response {\n events: ReadableStream<ChatCompletionEvent> | null;\n}\n\nexport async function fetchAndDecodeChatCompletion(\n params: FetchChatCompletionParams,\n): Promise<DecodedChatCompletionResponse> {\n const response = await fetchChatCompletion(params);\n if (!response.ok || !response.body) {\n return { ...response, events: null };\n }\n const events = await decodeChatCompletion(parseChatCompletion(response.body));\n return { ...response, events };\n}\n\nexport interface DecodedChatCompletionResponseAsText extends Response {\n events: ReadableStream<string> | null;\n}\n\nexport async function fetchAndDecodeChatCompletionAsText(\n params: FetchChatCompletionParams,\n): Promise<DecodedChatCompletionResponseAsText> {\n const response = await fetchChatCompletion(params);\n if (!response.ok || !response.body) {\n return { ...response, events: null };\n }\n const events = await decodeChatCompletionAsText(\n decodeChatCompletion(parseChatCompletion(response.body)),\n );\n return { ...response, events };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/utils.test.ts"],"names":[],"mappings":";AAEA,SAAS,aAAa,MAAM;AAC1B,KAAG,oBAAoB,MAAM;AAC3B,WAAO,IAAI,EAAE,WAAW;AAAA,EAC1B,CAAC;AACH,CAAC","sourcesContent":["import * as utils from \"./utils\";\n\ndescribe(\"emptyTest\", () => {\n it(\"should be truthy\", () => {\n expect(true).toBeTruthy();\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.18.0-alpha.
|
|
7
|
+
"version": "0.18.0-alpha.2",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.mjs",
|
|
11
|
-
"exports":
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/index.js"
|
|
13
|
+
},
|
|
12
14
|
"types": "./dist/index.d.ts",
|
|
13
15
|
"license": "MIT",
|
|
14
16
|
"peerDependencies": {
|
|
@@ -23,17 +25,15 @@
|
|
|
23
25
|
"ts-jest": "^29.1.1",
|
|
24
26
|
"tsup": "^6.7.0",
|
|
25
27
|
"typescript": "^5.1.3",
|
|
26
|
-
"tsconfig": "0.7.0-alpha.
|
|
27
|
-
"eslint-config-custom": "0.3.0-alpha.
|
|
28
|
+
"tsconfig": "0.7.0-alpha.1",
|
|
29
|
+
"eslint-config-custom": "0.3.0-alpha.1"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"eventemitter3": "^5.0.1",
|
|
31
32
|
"nanoid": "^4.0.2",
|
|
32
|
-
"
|
|
33
|
-
"@copilotkit/shared": "0.2.0-alpha.0"
|
|
33
|
+
"@copilotkit/shared": "0.2.0-alpha.1"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "tsup --treeshake",
|
|
36
|
+
"build": "tsup --treeshake --clean",
|
|
37
37
|
"dev": "tsup --watch --no-splitting",
|
|
38
38
|
"test": "jest",
|
|
39
39
|
"check-types": "tsc --noEmit",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Props for CopilotKit.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface CopilotKitProps {
|
|
9
|
+
/**
|
|
10
|
+
* The endpoint for the chat API.
|
|
11
|
+
*/
|
|
12
|
+
url: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* additional headers to be sent with the request
|
|
16
|
+
* @default {}
|
|
17
|
+
* @example
|
|
18
|
+
* ```
|
|
19
|
+
* {
|
|
20
|
+
* 'Authorization': 'Bearer your_token_here'
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Additional body params to be sent with the request
|
|
28
|
+
* @default {}
|
|
29
|
+
* @example
|
|
30
|
+
* ```
|
|
31
|
+
* {
|
|
32
|
+
* 'message': 'Hello, world!'
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
body?: Record<string, any>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The children to be rendered within the CopilotKit.
|
|
40
|
+
*/
|
|
41
|
+
children: ReactNode;
|
|
42
|
+
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { Function } from "@copilotkit/shared";
|
|
3
4
|
import { useCallback, useState } from "react";
|
|
4
5
|
import { CopilotContext, CopilotApiConfig } from "../../context/copilot-context";
|
|
5
6
|
import useTree from "../../hooks/use-tree";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { DocumentPointer } from "../../types";
|
|
8
|
+
import {
|
|
9
|
+
FunctionCallHandler,
|
|
10
|
+
AnnotatedFunction,
|
|
11
|
+
annotatedFunctionToChatCompletionFunction,
|
|
12
|
+
} from "@copilotkit/shared";
|
|
9
13
|
import useFlatCategoryStore from "../../hooks/use-flat-category-store";
|
|
10
14
|
import { StandardCopilotApiConfig } from "./standard-copilot-api-config";
|
|
11
|
-
import {
|
|
15
|
+
import { CopilotKitProps } from "./copilotkit-props";
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
|
-
* The
|
|
18
|
+
* The CopilotKit component.
|
|
15
19
|
* This component provides the Copilot context to its children.
|
|
16
20
|
* It can be configured either with a chat API endpoint or a CopilotApiConfig.
|
|
17
21
|
*
|
|
@@ -22,9 +26,9 @@ import { CopilotProviderProps } from "./copilot-provider-props";
|
|
|
22
26
|
*
|
|
23
27
|
* Example usage:
|
|
24
28
|
* ```
|
|
25
|
-
* <
|
|
29
|
+
* <CopilotKit url="https://your.copilotkit.api">
|
|
26
30
|
* <App />
|
|
27
|
-
* </
|
|
31
|
+
* </CopilotKit>
|
|
28
32
|
* ```
|
|
29
33
|
*
|
|
30
34
|
* or
|
|
@@ -39,15 +43,15 @@ import { CopilotProviderProps } from "./copilot-provider-props";
|
|
|
39
43
|
*
|
|
40
44
|
* // ...
|
|
41
45
|
*
|
|
42
|
-
* <
|
|
46
|
+
* <CopilotKit chatApiConfig={copilotApiConfig}>
|
|
43
47
|
* <App />
|
|
44
|
-
* </
|
|
48
|
+
* </CopilotKit>
|
|
45
49
|
* ```
|
|
46
50
|
*
|
|
47
51
|
* @param props - The props for the component.
|
|
48
|
-
* @returns The
|
|
52
|
+
* @returns The CopilotKit component.
|
|
49
53
|
*/
|
|
50
|
-
export function
|
|
54
|
+
export function CopilotKit({ children, ...props }: CopilotKitProps) {
|
|
51
55
|
// Compute all the functions and properties that we need to pass
|
|
52
56
|
// to the CopilotContext.
|
|
53
57
|
|
|
@@ -141,17 +145,12 @@ export function CopilotProvider({ children, ...props }: CopilotProviderProps): J
|
|
|
141
145
|
);
|
|
142
146
|
|
|
143
147
|
// get the appropriate CopilotApiConfig from the props
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
{},
|
|
151
|
-
);
|
|
152
|
-
} else {
|
|
153
|
-
copilotApiConfig = props.chatApiConfig;
|
|
154
|
-
}
|
|
148
|
+
const copilotApiConfig: CopilotApiConfig = new StandardCopilotApiConfig(
|
|
149
|
+
props.url,
|
|
150
|
+
`${props.url}/v2`,
|
|
151
|
+
props.headers || {},
|
|
152
|
+
props.body || {},
|
|
153
|
+
);
|
|
155
154
|
|
|
156
155
|
return (
|
|
157
156
|
<CopilotContext.Provider
|
|
@@ -223,40 +222,6 @@ function entryPointsToFunctionCallHandler(
|
|
|
223
222
|
};
|
|
224
223
|
}
|
|
225
224
|
|
|
226
|
-
function entryPointsToChatCompletionFunctions(
|
|
227
|
-
entryPoints: AnnotatedFunction<any[]>[],
|
|
228
|
-
): ChatCompletionCreateParams.Function[] {
|
|
225
|
+
function entryPointsToChatCompletionFunctions(entryPoints: AnnotatedFunction<any[]>[]): Function[] {
|
|
229
226
|
return entryPoints.map(annotatedFunctionToChatCompletionFunction);
|
|
230
227
|
}
|
|
231
|
-
|
|
232
|
-
function annotatedFunctionToChatCompletionFunction(
|
|
233
|
-
annotatedFunction: AnnotatedFunction<any[]>,
|
|
234
|
-
): ChatCompletionCreateParams.Function {
|
|
235
|
-
// Create the parameters object based on the argumentAnnotations
|
|
236
|
-
let parameters: { [key: string]: any } = {};
|
|
237
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
238
|
-
// isolate the args we should forward inline
|
|
239
|
-
let { name, required, ...forwardedArgs } = arg;
|
|
240
|
-
parameters[arg.name] = forwardedArgs;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
let requiredParameterNames: string[] = [];
|
|
244
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
245
|
-
if (arg.required) {
|
|
246
|
-
requiredParameterNames.push(arg.name);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Create the ChatCompletionFunctions object
|
|
251
|
-
let chatCompletionFunction: ChatCompletionCreateParams.Function = {
|
|
252
|
-
name: annotatedFunction.name,
|
|
253
|
-
description: annotatedFunction.description,
|
|
254
|
-
parameters: {
|
|
255
|
-
type: "object",
|
|
256
|
-
properties: parameters,
|
|
257
|
-
required: requiredParameterNames,
|
|
258
|
-
},
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
return chatCompletionFunction;
|
|
262
|
-
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CopilotKit, defaultCopilotContextCategories } from "./copilotkit";
|
|
2
2
|
|
|
3
|
-
export type {
|
|
4
|
-
CopilotProviderApiEndpointProps,
|
|
5
|
-
CopilotProviderApiConfigProps,
|
|
6
|
-
CopilotProviderProps,
|
|
7
|
-
} from "./copilot-provider-props";
|
|
3
|
+
export type { CopilotKitProps } from "./copilotkit-props";
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { FunctionCallHandler } from "
|
|
3
|
+
import { FunctionCallHandler, AnnotatedFunction, Function } from "@copilotkit/shared";
|
|
4
4
|
import React from "react";
|
|
5
5
|
import { TreeNodeId } from "../hooks/use-tree";
|
|
6
|
-
import { AnnotatedFunction } from "../types/annotated-function";
|
|
7
|
-
import { ChatCompletionCreateParams } from "openai/resources/chat";
|
|
8
6
|
import { DocumentPointer } from "../types";
|
|
9
7
|
|
|
10
8
|
/**
|
|
@@ -51,7 +49,7 @@ export interface CopilotContextParams {
|
|
|
51
49
|
entryPoints: Record<string, AnnotatedFunction<any[]>>;
|
|
52
50
|
setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;
|
|
53
51
|
removeEntryPoint: (id: string) => void;
|
|
54
|
-
getChatCompletionFunctionDescriptions: () =>
|
|
52
|
+
getChatCompletionFunctionDescriptions: () => Function[];
|
|
55
53
|
getFunctionCallHandler: () => FunctionCallHandler;
|
|
56
54
|
|
|
57
55
|
// text context
|
|
@@ -86,14 +84,10 @@ const emptyCopilotContext: CopilotContextParams = {
|
|
|
86
84
|
|
|
87
85
|
copilotApiConfig: new (class implements CopilotApiConfig {
|
|
88
86
|
get chatApiEndpoint(): string {
|
|
89
|
-
throw new Error(
|
|
90
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!",
|
|
91
|
-
);
|
|
87
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
92
88
|
}
|
|
93
89
|
get chatApiEndpointV2(): string {
|
|
94
|
-
throw new Error(
|
|
95
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!",
|
|
96
|
-
);
|
|
90
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
97
91
|
}
|
|
98
92
|
get headers(): Record<string, string> {
|
|
99
93
|
return {};
|
|
@@ -107,8 +101,6 @@ const emptyCopilotContext: CopilotContextParams = {
|
|
|
107
101
|
export const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);
|
|
108
102
|
|
|
109
103
|
function returnAndThrowInDebug<T>(value: T): T {
|
|
110
|
-
throw new Error(
|
|
111
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!",
|
|
112
|
-
);
|
|
104
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
113
105
|
return value;
|
|
114
106
|
}
|
package/src/hooks/use-chat.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRef, useState } from "react";
|
|
2
|
-
import { Message, Function, FunctionCallHandler } from "
|
|
2
|
+
import { Message, Function, FunctionCallHandler, FunctionCall } from "@copilotkit/shared";
|
|
3
3
|
import { nanoid } from "nanoid";
|
|
4
|
-
import {
|
|
4
|
+
import { fetchAndDecodeChatCompletion } from "../utils/fetch-chat-completion";
|
|
5
5
|
import { CopilotApiConfig } from "../context";
|
|
6
6
|
|
|
7
7
|
export type UseChatOptions = {
|
|
@@ -87,84 +87,66 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
|
|
|
87
87
|
const abortControllerRef = useRef<AbortController>();
|
|
88
88
|
|
|
89
89
|
const runChatCompletion = async (messages: Message[]): Promise<Message> => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const cleanup = () => {
|
|
111
|
-
client.off("content");
|
|
112
|
-
client.off("end");
|
|
113
|
-
client.off("error");
|
|
114
|
-
client.off("function");
|
|
115
|
-
|
|
116
|
-
abortControllerRef.current = undefined;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
abortController.signal.addEventListener("abort", () => {
|
|
120
|
-
setIsLoading(false);
|
|
121
|
-
cleanup();
|
|
122
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
client.on("content", (content) => {
|
|
126
|
-
assistantMessage.content += content;
|
|
127
|
-
setMessages([...messages, { ...assistantMessage }]);
|
|
128
|
-
});
|
|
90
|
+
setIsLoading(true);
|
|
91
|
+
const assistantMessage: Message = {
|
|
92
|
+
id: nanoid(),
|
|
93
|
+
createdAt: new Date(),
|
|
94
|
+
content: "",
|
|
95
|
+
role: "assistant",
|
|
96
|
+
};
|
|
97
|
+
const abortController = new AbortController();
|
|
98
|
+
abortControllerRef.current = abortController;
|
|
99
|
+
|
|
100
|
+
setMessages([...messages, { ...assistantMessage }]);
|
|
101
|
+
|
|
102
|
+
const messagesWithContext = [...(options.initialMessages || []), ...messages];
|
|
103
|
+
const response = await fetchAndDecodeChatCompletion({
|
|
104
|
+
copilotConfig: options.copilotConfig,
|
|
105
|
+
messages: messagesWithContext,
|
|
106
|
+
functions: options.functions,
|
|
107
|
+
headers: options.headers,
|
|
108
|
+
signal: abortController.signal,
|
|
109
|
+
});
|
|
129
110
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
resolve({ ...assistantMessage });
|
|
134
|
-
});
|
|
111
|
+
if (!response.events) {
|
|
112
|
+
throw new Error("Failed to fetch chat completion");
|
|
113
|
+
}
|
|
135
114
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
115
|
+
const reader = response.events.getReader();
|
|
116
|
+
|
|
117
|
+
while (true) {
|
|
118
|
+
try {
|
|
119
|
+
const { done, value } = await reader.read();
|
|
120
|
+
|
|
121
|
+
if (done) {
|
|
122
|
+
setIsLoading(false);
|
|
123
|
+
return { ...assistantMessage };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (value.type === "content") {
|
|
127
|
+
assistantMessage.content += value.content;
|
|
128
|
+
setMessages([...messages, { ...assistantMessage }]);
|
|
129
|
+
} else if (value.type === "function") {
|
|
130
|
+
assistantMessage.function_call = {
|
|
131
|
+
name: value.name,
|
|
132
|
+
arguments: JSON.stringify(value.arguments),
|
|
133
|
+
};
|
|
134
|
+
setMessages([...messages, { ...assistantMessage }]);
|
|
135
|
+
// quit early if we get a function call
|
|
136
|
+
setIsLoading(false);
|
|
137
|
+
return { ...assistantMessage };
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
149
140
|
setIsLoading(false);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
client.fetch({
|
|
155
|
-
copilotConfig: options.copilotConfig,
|
|
156
|
-
messages: messagesWithContext,
|
|
157
|
-
functions: options.functions,
|
|
158
|
-
headers: options.headers,
|
|
159
|
-
signal: abortController.signal,
|
|
160
|
-
});
|
|
161
|
-
});
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
162
144
|
};
|
|
163
145
|
|
|
164
146
|
const runChatCompletionAndHandleFunctionCall = async (messages: Message[]): Promise<void> => {
|
|
165
147
|
const message = await runChatCompletion(messages);
|
|
166
148
|
if (message.function_call && options.onFunctionCall) {
|
|
167
|
-
await options.onFunctionCall(messages, message.function_call);
|
|
149
|
+
await options.onFunctionCall(messages, message.function_call as FunctionCall);
|
|
168
150
|
}
|
|
169
151
|
};
|
|
170
152
|
|