@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
package/dist/chunk-VK25FIML.mjs
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { __async, __spreadValues } from './chunk-MRXNTQOX.mjs';
|
|
2
|
-
import EventEmitter from 'eventemitter3';
|
|
3
|
-
|
|
4
|
-
var DEFAULT_MODEL = "gpt-4-1106-preview";
|
|
5
|
-
var ChatCompletionTransport = class extends EventEmitter {
|
|
6
|
-
constructor(params) {
|
|
7
|
-
super();
|
|
8
|
-
this.buffer = new Uint8Array();
|
|
9
|
-
this.bodyReader = null;
|
|
10
|
-
}
|
|
11
|
-
cleanup() {
|
|
12
|
-
return __async(this, null, function* () {
|
|
13
|
-
if (this.bodyReader) {
|
|
14
|
-
try {
|
|
15
|
-
yield this.bodyReader.cancel();
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.warn("Failed to cancel body reader:", error);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
this.bodyReader = null;
|
|
21
|
-
this.buffer = new Uint8Array();
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
fetch(_0) {
|
|
25
|
-
return __async(this, arguments, function* ({
|
|
26
|
-
copilotConfig,
|
|
27
|
-
model,
|
|
28
|
-
messages,
|
|
29
|
-
functions,
|
|
30
|
-
temperature,
|
|
31
|
-
headers,
|
|
32
|
-
body,
|
|
33
|
-
signal
|
|
34
|
-
}) {
|
|
35
|
-
yield this.cleanup();
|
|
36
|
-
temperature || (temperature = 0.5);
|
|
37
|
-
functions || (functions = []);
|
|
38
|
-
model || (model = DEFAULT_MODEL);
|
|
39
|
-
const cleanedMessages = messages.map((message) => {
|
|
40
|
-
const { content, role, name, function_call } = message;
|
|
41
|
-
return { content, role, name, function_call };
|
|
42
|
-
});
|
|
43
|
-
try {
|
|
44
|
-
const response = yield fetch(copilotConfig.chatApiEndpoint, {
|
|
45
|
-
method: "POST",
|
|
46
|
-
headers: __spreadValues(__spreadValues({
|
|
47
|
-
"Content-Type": "application/json"
|
|
48
|
-
}, copilotConfig.headers), headers ? __spreadValues({}, headers) : {}),
|
|
49
|
-
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
50
|
-
model,
|
|
51
|
-
messages: cleanedMessages,
|
|
52
|
-
stream: true
|
|
53
|
-
}, functions.length ? { functions } : {}), temperature ? { temperature } : {}), functions.length != 0 ? { function_call: "auto" } : {}), copilotConfig.body), body ? __spreadValues({}, body) : {})),
|
|
54
|
-
signal
|
|
55
|
-
});
|
|
56
|
-
if (!response.ok) {
|
|
57
|
-
try {
|
|
58
|
-
const errorText = yield response.text();
|
|
59
|
-
yield this.cleanup();
|
|
60
|
-
const msg = `Error ${response.status}: ${errorText}`;
|
|
61
|
-
this.emit("error", new Error(msg));
|
|
62
|
-
} catch (_error) {
|
|
63
|
-
yield this.cleanup();
|
|
64
|
-
const msg = `Error ${response.status}: ${response.statusText}`;
|
|
65
|
-
this.emit("error", new Error(msg));
|
|
66
|
-
}
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (response.body == null) {
|
|
70
|
-
yield this.cleanup();
|
|
71
|
-
const msg = "Response body is null";
|
|
72
|
-
this.emit("error", new Error(msg));
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
this.bodyReader = response.body.getReader();
|
|
76
|
-
yield this.streamBody();
|
|
77
|
-
} catch (error) {
|
|
78
|
-
yield this.cleanup();
|
|
79
|
-
this.emit("error", error);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
streamBody() {
|
|
85
|
-
return __async(this, null, function* () {
|
|
86
|
-
while (true) {
|
|
87
|
-
try {
|
|
88
|
-
const { done, value } = yield this.bodyReader.read();
|
|
89
|
-
if (done) {
|
|
90
|
-
yield this.cleanup();
|
|
91
|
-
this.emit("end");
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const shouldContinue = yield this.processData(value);
|
|
95
|
-
if (!shouldContinue) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
} catch (error) {
|
|
99
|
-
yield this.cleanup();
|
|
100
|
-
this.emit("error", error);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
processData(data) {
|
|
107
|
-
return __async(this, null, function* () {
|
|
108
|
-
const newBuffer = new Uint8Array(this.buffer.length + data.length);
|
|
109
|
-
newBuffer.set(this.buffer);
|
|
110
|
-
newBuffer.set(data, this.buffer.length);
|
|
111
|
-
this.buffer = newBuffer;
|
|
112
|
-
const dataString = new TextDecoder("utf-8").decode(this.buffer);
|
|
113
|
-
let lines = dataString.split("\n").filter((line) => line.trim() !== "");
|
|
114
|
-
if (!dataString.endsWith("\n")) {
|
|
115
|
-
const lastLine = lines.pop() || "";
|
|
116
|
-
const remainingBytes = new TextEncoder().encode(lastLine);
|
|
117
|
-
this.buffer = new Uint8Array(remainingBytes);
|
|
118
|
-
} else {
|
|
119
|
-
this.buffer = new Uint8Array();
|
|
120
|
-
}
|
|
121
|
-
for (const line of lines) {
|
|
122
|
-
const cleanedLine = line.replace(/^data: /, "");
|
|
123
|
-
if (cleanedLine === "[DONE]") {
|
|
124
|
-
yield this.cleanup();
|
|
125
|
-
this.emit("end");
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
let json;
|
|
129
|
-
try {
|
|
130
|
-
json = JSON.parse(cleanedLine);
|
|
131
|
-
} catch (error) {
|
|
132
|
-
console.error("Failed to parse JSON:", error);
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
this.emit("data", json);
|
|
136
|
-
}
|
|
137
|
-
return true;
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export { ChatCompletionTransport };
|
|
143
|
-
//# sourceMappingURL=out.js.map
|
|
144
|
-
//# sourceMappingURL=chunk-VK25FIML.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openai/chat-completion-transport.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB;AAwBzB,IAAM,gBAAgB;AAEf,IAAM,0BAAN,cAAsC,aAA4C;AAAA,EAIvF,YAAY,QAA8C;AACxD,UAAM;AAJR,SAAQ,SAAS,IAAI,WAAW;AAChC,SAAQ,aAA6D;AAAA,EAIrE;AAAA,EAEc,UAAU;AAAA;AACtB,UAAI,KAAK,YAAY;AACnB,YAAI;AACF,gBAAM,KAAK,WAAW,OAAO;AAAA,QAC/B,SAAS,OAAP;AACA,kBAAQ,KAAK,iCAAiC,KAAK;AAAA,QACrD;AAAA,MACF;AACA,WAAK,aAAa;AAClB,WAAK,SAAS,IAAI,WAAW;AAAA,IAC/B;AAAA;AAAA,EAEa,MAAM,IASmC;AAAA,+CATnC;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,GAAsD;AACpD,YAAM,KAAK,QAAQ;AAEnB,oCAAgB;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AAI;AACJ,YAAI;AACF,iBAAO,KAAK,MAAM,WAAW;AAAA,QAC/B,SAAS,OAAP;AACA,kBAAQ,MAAM,yBAAyB,KAAK;AAC5C;AAAA,QACF;AAEA,aAAK,KAAK,QAAQ,IAAI;AAAA,MACxB;AACA,aAAO;AAAA,IACT;AAAA;AACF","sourcesContent":["import EventEmitter from \"eventemitter3\";\nimport { Message, Function } from \"../types\";\nimport { CopilotApiConfig } from \"../context\";\n\nexport interface ChatCompletionTransportConfiguration {}\n\ninterface ChatCompletionTransportEvents {\n end: void;\n data: any;\n error: any;\n}\n\nexport interface ChatCompletionTransportFetchParams {\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\nconst DEFAULT_MODEL = \"gpt-4-1106-preview\";\n\nexport class ChatCompletionTransport extends EventEmitter<ChatCompletionTransportEvents> {\n private buffer = new Uint8Array();\n private bodyReader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n\n constructor(params: ChatCompletionTransportConfiguration) {\n super();\n }\n\n private async cleanup() {\n if (this.bodyReader) {\n try {\n await this.bodyReader.cancel();\n } catch (error) {\n console.warn(\"Failed to cancel body reader:\", error);\n }\n }\n this.bodyReader = null;\n this.buffer = new Uint8Array();\n }\n\n public async fetch({\n copilotConfig,\n model,\n messages,\n functions,\n temperature,\n headers,\n body,\n signal,\n }: ChatCompletionTransportFetchParams): Promise<void> {\n await this.cleanup();\n\n temperature ||= 0.5;\n functions ||= [];\n model ||= DEFAULT_MODEL;\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 try {\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 if (!response.ok) {\n try {\n const errorText = await response.text();\n await this.cleanup();\n const msg = `Error ${response.status}: ${errorText}`;\n this.emit(\"error\", new Error(msg));\n } catch (_error) {\n await this.cleanup();\n const msg = `Error ${response.status}: ${response.statusText}`;\n this.emit(\"error\", new Error(msg));\n }\n return;\n }\n\n if (response.body == null) {\n await this.cleanup();\n const msg = \"Response body is null\";\n this.emit(\"error\", new Error(msg));\n return;\n }\n\n this.bodyReader = response.body.getReader();\n\n await this.streamBody();\n } catch (error) {\n await this.cleanup();\n this.emit(\"error\", error);\n return;\n }\n }\n\n private async streamBody() {\n while (true) {\n try {\n const { done, value } = await this.bodyReader!.read();\n\n if (done) {\n await this.cleanup();\n this.emit(\"end\");\n return;\n }\n\n const shouldContinue = await this.processData(value);\n\n if (!shouldContinue) {\n return;\n }\n } catch (error) {\n await this.cleanup();\n this.emit(\"error\", error);\n return;\n }\n }\n }\n\n private async processData(data: Uint8Array): Promise<boolean> {\n // Append new data to the temp buffer\n const newBuffer = new Uint8Array(this.buffer.length + data.length);\n newBuffer.set(this.buffer);\n newBuffer.set(data, this.buffer.length);\n this.buffer = newBuffer;\n\n const dataString = new TextDecoder(\"utf-8\").decode(this.buffer);\n\n let lines = dataString.split(\"\\n\").filter((line) => line.trim() !== \"\");\n\n // If the last line isn't complete, keep it in the buffer for next time\n if (!dataString.endsWith(\"\\n\")) {\n const lastLine = lines.pop() || \"\";\n const remainingBytes = new TextEncoder().encode(lastLine);\n this.buffer = new Uint8Array(remainingBytes);\n } else {\n this.buffer = new Uint8Array();\n }\n\n for (const line of lines) {\n const cleanedLine = line.replace(/^data: /, \"\");\n\n if (cleanedLine === \"[DONE]\") {\n await this.cleanup();\n this.emit(\"end\");\n return false;\n }\n\n let json;\n try {\n json = JSON.parse(cleanedLine);\n } catch (error) {\n console.error(\"Failed to parse JSON:\", error);\n continue;\n }\n\n this.emit(\"data\", json);\n }\n return true;\n }\n}\n"]}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { CopilotApiConfig } from '../../context/copilot-context.js';
|
|
3
|
-
import '../../types/annotated-function.js';
|
|
4
|
-
import '../../types/document-pointer.js';
|
|
5
|
-
import '../../types/base.js';
|
|
6
|
-
import '../../hooks/use-tree.js';
|
|
7
|
-
import 'openai/resources/chat';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Props for the CopilotProvider when using a chat API endpoint.
|
|
11
|
-
*/
|
|
12
|
-
interface CopilotProviderApiEndpointProps {
|
|
13
|
-
/**
|
|
14
|
-
* The endpoint for the chat API.
|
|
15
|
-
*/
|
|
16
|
-
chatApiEndpoint: string;
|
|
17
|
-
/**
|
|
18
|
-
* The endpoint for the chat API v2.
|
|
19
|
-
* If not provided, defaults to chatApiEndpoint + "/v2".
|
|
20
|
-
* This is used for the chat API v2.
|
|
21
|
-
* If you are not using the chat API v2, you can ignore this.
|
|
22
|
-
* @default chatApiEndpoint + "/v2"
|
|
23
|
-
* @optional
|
|
24
|
-
*/
|
|
25
|
-
chatApiEndpointV2?: string;
|
|
26
|
-
/**
|
|
27
|
-
* The children to be rendered within the CopilotProvider.
|
|
28
|
-
*/
|
|
29
|
-
children: ReactNode;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Props for the CopilotProvider when using a CopilotApiConfig.
|
|
33
|
-
*/
|
|
34
|
-
interface CopilotProviderApiConfigProps {
|
|
35
|
-
/**
|
|
36
|
-
* The configuration for the Copilot API.
|
|
37
|
-
*/
|
|
38
|
-
chatApiConfig: CopilotApiConfig;
|
|
39
|
-
/**
|
|
40
|
-
* The children to be rendered within the CopilotProvider.
|
|
41
|
-
*/
|
|
42
|
-
children: ReactNode;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Props for the CopilotProvider component.
|
|
46
|
-
* Can be either CopilotProviderApiEndpointProps or CopilotProviderApiConfigProps.
|
|
47
|
-
*/
|
|
48
|
-
type CopilotProviderProps = CopilotProviderApiEndpointProps | CopilotProviderApiConfigProps;
|
|
49
|
-
|
|
50
|
-
export { CopilotProviderApiConfigProps, CopilotProviderApiEndpointProps, CopilotProviderProps };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { CopilotProvider, defaultCopilotContextCategories } from '../../chunk-D4NQCVHE.mjs';
|
|
2
|
-
import '../../chunk-F2JIAPZQ.mjs';
|
|
3
|
-
import '../../chunk-VUY2K2DI.mjs';
|
|
4
|
-
import '../../chunk-YULKJPY3.mjs';
|
|
5
|
-
import '../../chunk-6A4PCNMZ.mjs';
|
|
6
|
-
import '../../chunk-MRXNTQOX.mjs';
|
|
7
|
-
//# sourceMappingURL=out.js.map
|
|
8
|
-
//# sourceMappingURL=copilot-provider.mjs.map
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3';
|
|
2
|
-
import { Role, Message } from '../types/base.js';
|
|
3
|
-
import { ChatCompletionTransportFetchParams } from './chat-completion-transport.js';
|
|
4
|
-
import '../context/copilot-context.js';
|
|
5
|
-
import '../types/annotated-function.js';
|
|
6
|
-
import '../types/document-pointer.js';
|
|
7
|
-
import 'react';
|
|
8
|
-
import '../hooks/use-tree.js';
|
|
9
|
-
import 'openai/resources/chat';
|
|
10
|
-
|
|
11
|
-
interface ChatCompletionClientConfiguration {
|
|
12
|
-
}
|
|
13
|
-
interface ChatCompletionClientEvents {
|
|
14
|
-
content: string;
|
|
15
|
-
partial: [string, string];
|
|
16
|
-
error: any;
|
|
17
|
-
function: {
|
|
18
|
-
name: string;
|
|
19
|
-
arguments: any;
|
|
20
|
-
};
|
|
21
|
-
end: void;
|
|
22
|
-
}
|
|
23
|
-
interface ChatCompletionChunk {
|
|
24
|
-
choices: {
|
|
25
|
-
delta: {
|
|
26
|
-
role: Role;
|
|
27
|
-
content?: string | null;
|
|
28
|
-
function_call?: {
|
|
29
|
-
name?: string;
|
|
30
|
-
arguments?: string;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
}[];
|
|
34
|
-
}
|
|
35
|
-
declare class ChatCompletionClient extends EventEmitter<ChatCompletionClientEvents> {
|
|
36
|
-
private chatCompletionTransport;
|
|
37
|
-
private mode;
|
|
38
|
-
private functionCallName;
|
|
39
|
-
private functionCallArguments;
|
|
40
|
-
constructor(params: ChatCompletionClientConfiguration);
|
|
41
|
-
fetch(params: ChatCompletionTransportFetchParams): Promise<void>;
|
|
42
|
-
private buildPrompt;
|
|
43
|
-
private runPrompt;
|
|
44
|
-
private onData;
|
|
45
|
-
private onError;
|
|
46
|
-
private onEnd;
|
|
47
|
-
private tryFlushFunctionCall;
|
|
48
|
-
private cleanup;
|
|
49
|
-
countTokens(message: Message): number;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { ChatCompletionChunk, ChatCompletionClient };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ChatCompletionTransportFetchParams } from './chat-completion-transport.js';
|
|
2
|
-
import 'eventemitter3';
|
|
3
|
-
import '../types/base.js';
|
|
4
|
-
import '../context/copilot-context.js';
|
|
5
|
-
import '../types/annotated-function.js';
|
|
6
|
-
import '../types/document-pointer.js';
|
|
7
|
-
import 'react';
|
|
8
|
-
import '../hooks/use-tree.js';
|
|
9
|
-
import 'openai/resources/chat';
|
|
10
|
-
|
|
11
|
-
interface ChatCompletionStreamConfiguration {
|
|
12
|
-
url: string;
|
|
13
|
-
model?: string;
|
|
14
|
-
}
|
|
15
|
-
declare class ChatCompletionStream {
|
|
16
|
-
private url;
|
|
17
|
-
constructor(params: ChatCompletionStreamConfiguration);
|
|
18
|
-
fetch(params: ChatCompletionTransportFetchParams): Promise<ReadableStream<string>>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { ChatCompletionStream, ChatCompletionStreamConfiguration };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3';
|
|
2
|
-
import { Message, Function } from '../types/base.js';
|
|
3
|
-
import { CopilotApiConfig } from '../context/copilot-context.js';
|
|
4
|
-
import '../types/annotated-function.js';
|
|
5
|
-
import '../types/document-pointer.js';
|
|
6
|
-
import 'react';
|
|
7
|
-
import '../hooks/use-tree.js';
|
|
8
|
-
import 'openai/resources/chat';
|
|
9
|
-
|
|
10
|
-
interface ChatCompletionTransportConfiguration {
|
|
11
|
-
}
|
|
12
|
-
interface ChatCompletionTransportEvents {
|
|
13
|
-
end: void;
|
|
14
|
-
data: any;
|
|
15
|
-
error: any;
|
|
16
|
-
}
|
|
17
|
-
interface ChatCompletionTransportFetchParams {
|
|
18
|
-
copilotConfig: CopilotApiConfig;
|
|
19
|
-
model?: string;
|
|
20
|
-
messages: Message[];
|
|
21
|
-
functions?: Function[];
|
|
22
|
-
temperature?: number;
|
|
23
|
-
maxTokens?: number;
|
|
24
|
-
headers?: Record<string, string> | Headers;
|
|
25
|
-
body?: object;
|
|
26
|
-
signal?: AbortSignal;
|
|
27
|
-
}
|
|
28
|
-
declare class ChatCompletionTransport extends EventEmitter<ChatCompletionTransportEvents> {
|
|
29
|
-
private buffer;
|
|
30
|
-
private bodyReader;
|
|
31
|
-
constructor(params: ChatCompletionTransportConfiguration);
|
|
32
|
-
private cleanup;
|
|
33
|
-
fetch({ copilotConfig, model, messages, functions, temperature, headers, body, signal, }: ChatCompletionTransportFetchParams): Promise<void>;
|
|
34
|
-
private streamBody;
|
|
35
|
-
private processData;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { ChatCompletionTransport, ChatCompletionTransportConfiguration, ChatCompletionTransportFetchParams };
|
package/dist/openai/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { ChatCompletionStream, ChatCompletionStreamConfiguration } from './chat-completion-stream.js';
|
|
2
|
-
export { ChatCompletionTransportFetchParams } from './chat-completion-transport.js';
|
|
3
|
-
import 'eventemitter3';
|
|
4
|
-
import '../types/base.js';
|
|
5
|
-
import '../context/copilot-context.js';
|
|
6
|
-
import '../types/annotated-function.js';
|
|
7
|
-
import '../types/document-pointer.js';
|
|
8
|
-
import 'react';
|
|
9
|
-
import '../hooks/use-tree.js';
|
|
10
|
-
import 'openai/resources/chat';
|
package/dist/openai/index.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
interface AnnotatedFunctionSimpleArgument {
|
|
2
|
-
name: string;
|
|
3
|
-
type: "string" | "number" | "boolean" | "object";
|
|
4
|
-
description: string;
|
|
5
|
-
required: boolean;
|
|
6
|
-
}
|
|
7
|
-
interface AnnotatedFunctionArrayArgument {
|
|
8
|
-
name: string;
|
|
9
|
-
type: "array";
|
|
10
|
-
items: {
|
|
11
|
-
type: string;
|
|
12
|
-
};
|
|
13
|
-
description: string;
|
|
14
|
-
required: boolean;
|
|
15
|
-
}
|
|
16
|
-
type AnnotatedFunctionArgument = AnnotatedFunctionSimpleArgument | AnnotatedFunctionArrayArgument;
|
|
17
|
-
interface AnnotatedFunction<Inputs extends any[]> {
|
|
18
|
-
name: string;
|
|
19
|
-
description: string;
|
|
20
|
-
argumentAnnotations: AnnotatedFunctionArgument[];
|
|
21
|
-
implementation: (...args: Inputs) => Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { AnnotatedFunction, AnnotatedFunctionArgument, AnnotatedFunctionArrayArgument, AnnotatedFunctionSimpleArgument };
|
package/dist/types/base.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
type Role = "system" | "user" | "assistant" | "function";
|
|
2
|
-
interface Message {
|
|
3
|
-
id: string;
|
|
4
|
-
createdAt?: Date;
|
|
5
|
-
content: string;
|
|
6
|
-
role: Role;
|
|
7
|
-
/**
|
|
8
|
-
* If the message has a role of `function`, the `name` field is the name of the function.
|
|
9
|
-
* Otherwise, the name field should not be set.
|
|
10
|
-
*/
|
|
11
|
-
name?: string;
|
|
12
|
-
/**
|
|
13
|
-
* If the assistant role makes a function call, the `function_call` field
|
|
14
|
-
* contains the function call name and arguments. Otherwise, the field should
|
|
15
|
-
* not be set.
|
|
16
|
-
*/
|
|
17
|
-
function_call?: FunctionCall;
|
|
18
|
-
}
|
|
19
|
-
interface FunctionCall {
|
|
20
|
-
/**
|
|
21
|
-
* The arguments to call the function with, as generated by the model in JSON
|
|
22
|
-
* format. Note that the model does not always generate valid JSON, and may
|
|
23
|
-
* hallucinate parameters not defined by your function schema. Validate the
|
|
24
|
-
* arguments in your code before calling your function.
|
|
25
|
-
*/
|
|
26
|
-
arguments?: string;
|
|
27
|
-
/**
|
|
28
|
-
* The name of the function to call.
|
|
29
|
-
*/
|
|
30
|
-
name?: string;
|
|
31
|
-
}
|
|
32
|
-
interface Function {
|
|
33
|
-
/**
|
|
34
|
-
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
|
|
35
|
-
* underscores and dashes, with a maximum length of 64.
|
|
36
|
-
*/
|
|
37
|
-
name: string;
|
|
38
|
-
/**
|
|
39
|
-
* The parameters the functions accepts, described as a JSON Schema object. See the
|
|
40
|
-
* [guide](/docs/guides/gpt/function-calling) for examples, and the
|
|
41
|
-
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
|
|
42
|
-
* documentation about the format.
|
|
43
|
-
*
|
|
44
|
-
* To describe a function that accepts no parameters, provide the value
|
|
45
|
-
* `{"type": "object", "properties": {}}`.
|
|
46
|
-
*/
|
|
47
|
-
parameters: Record<string, unknown>;
|
|
48
|
-
/**
|
|
49
|
-
* A description of what the function does, used by the model to choose when and
|
|
50
|
-
* how to call the function.
|
|
51
|
-
*/
|
|
52
|
-
description?: string;
|
|
53
|
-
}
|
|
54
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<void>;
|
|
55
|
-
|
|
56
|
-
export { Function, FunctionCall, FunctionCallHandler, Message, Role };
|
package/dist/types/base.mjs
DELETED
package/dist/types/base.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { ReactNode } from "react";
|
|
3
|
-
import { CopilotApiConfig } from "../../context/copilot-context";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Props for the CopilotProvider when using a chat API endpoint.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export interface CopilotProviderApiEndpointProps {
|
|
10
|
-
/**
|
|
11
|
-
* The endpoint for the chat API.
|
|
12
|
-
*/
|
|
13
|
-
chatApiEndpoint: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The endpoint for the chat API v2.
|
|
17
|
-
* If not provided, defaults to chatApiEndpoint + "/v2".
|
|
18
|
-
* This is used for the chat API v2.
|
|
19
|
-
* If you are not using the chat API v2, you can ignore this.
|
|
20
|
-
* @default chatApiEndpoint + "/v2"
|
|
21
|
-
* @optional
|
|
22
|
-
*/
|
|
23
|
-
chatApiEndpointV2?: string;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The children to be rendered within the CopilotProvider.
|
|
27
|
-
*/
|
|
28
|
-
children: ReactNode;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Props for the CopilotProvider when using a CopilotApiConfig.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
export interface CopilotProviderApiConfigProps {
|
|
35
|
-
/**
|
|
36
|
-
* The configuration for the Copilot API.
|
|
37
|
-
*/
|
|
38
|
-
chatApiConfig: CopilotApiConfig;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The children to be rendered within the CopilotProvider.
|
|
42
|
-
*/
|
|
43
|
-
children: ReactNode;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Props for the CopilotProvider component.
|
|
47
|
-
* Can be either CopilotProviderApiEndpointProps or CopilotProviderApiConfigProps.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
export type CopilotProviderProps = CopilotProviderApiEndpointProps | CopilotProviderApiConfigProps;
|