@copilotkit/react-core 0.18.0-alpha.0 → 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.
Files changed (165) hide show
  1. package/.turbo/turbo-build.log +179 -117
  2. package/CHANGELOG.md +25 -1
  3. package/dist/{chunk-6A4PCNMZ.mjs → chunk-4CFJ6A6A.mjs} +4 -10
  4. package/dist/chunk-4CFJ6A6A.mjs.map +1 -0
  5. package/dist/{chunk-SFQOMKM2.mjs → chunk-5GS7FQPW.mjs} +13 -9
  6. package/dist/chunk-5GS7FQPW.mjs.map +1 -0
  7. package/dist/{chunk-FP4EXCGS.mjs → chunk-DGUVNY3V.mjs} +2 -2
  8. package/dist/chunk-DGUVNY3V.mjs.map +1 -0
  9. package/dist/{chunk-QTET3FBV.mjs → chunk-GBZZPQ5X.mjs} +11 -38
  10. package/dist/chunk-GBZZPQ5X.mjs.map +1 -0
  11. package/dist/chunk-IQEWY7P4.mjs +102 -0
  12. package/dist/chunk-IQEWY7P4.mjs.map +1 -0
  13. package/dist/{chunk-7P4OYNP3.mjs → chunk-IQH5AQQC.mjs} +2 -2
  14. package/dist/chunk-UAKLDQMP.mjs +61 -0
  15. package/dist/chunk-UAKLDQMP.mjs.map +1 -0
  16. package/dist/{chunk-TU4DNDO7.mjs → chunk-VP2EU4US.mjs} +3 -3
  17. package/dist/{chunk-HW5IH6PV.mjs → chunk-YOXWT7I6.mjs} +2 -2
  18. package/dist/components/copilot-provider/copilotkit-props.d.ts +39 -0
  19. package/dist/components/copilot-provider/copilotkit-props.js +4 -0
  20. package/dist/components/copilot-provider/copilotkit-props.mjs +3 -0
  21. package/dist/components/copilot-provider/{copilot-provider.d.ts → copilotkit.d.ts} +9 -15
  22. package/dist/components/copilot-provider/copilotkit.js +426 -0
  23. package/dist/components/copilot-provider/copilotkit.js.map +1 -0
  24. package/dist/components/copilot-provider/copilotkit.mjs +8 -0
  25. package/dist/components/copilot-provider/index.d.ts +2 -8
  26. package/dist/components/copilot-provider/index.js +426 -0
  27. package/dist/components/copilot-provider/index.js.map +1 -0
  28. package/dist/components/copilot-provider/index.mjs +2 -2
  29. package/dist/components/copilot-provider/standard-copilot-api-config.d.ts +2 -4
  30. package/dist/components/copilot-provider/standard-copilot-api-config.js +15 -0
  31. package/dist/components/copilot-provider/standard-copilot-api-config.js.map +1 -0
  32. package/dist/components/index.d.ts +2 -8
  33. package/dist/components/index.js +426 -0
  34. package/dist/components/index.js.map +1 -0
  35. package/dist/components/index.mjs +2 -2
  36. package/dist/context/copilot-context.d.ts +3 -5
  37. package/dist/context/copilot-context.js +47 -0
  38. package/dist/context/copilot-context.js.map +1 -0
  39. package/dist/context/copilot-context.mjs +1 -1
  40. package/dist/context/index.d.ts +2 -4
  41. package/dist/context/index.js +47 -0
  42. package/dist/context/index.js.map +1 -0
  43. package/dist/context/index.mjs +1 -1
  44. package/dist/hooks/index.d.ts +3 -4
  45. package/dist/hooks/index.js +358 -0
  46. package/dist/hooks/index.js.map +1 -0
  47. package/dist/hooks/index.mjs +8 -9
  48. package/dist/hooks/use-chat.d.ts +2 -4
  49. package/dist/hooks/use-chat.js +186 -0
  50. package/dist/hooks/use-chat.js.map +1 -0
  51. package/dist/hooks/use-chat.mjs +2 -3
  52. package/dist/hooks/use-copilot-chat.d.ts +7 -7
  53. package/dist/hooks/use-copilot-chat.js +313 -0
  54. package/dist/hooks/use-copilot-chat.js.map +1 -0
  55. package/dist/hooks/use-copilot-chat.mjs +5 -6
  56. package/dist/hooks/use-flat-category-store.js +72 -0
  57. package/dist/hooks/use-flat-category-store.js.map +1 -0
  58. package/dist/hooks/use-make-copilot-actionable.d.ts +1 -1
  59. package/dist/hooks/use-make-copilot-actionable.js +67 -0
  60. package/dist/hooks/use-make-copilot-actionable.js.map +1 -0
  61. package/dist/hooks/use-make-copilot-actionable.mjs +2 -2
  62. package/dist/hooks/use-make-copilot-document-readable.js +61 -0
  63. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
  64. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  65. package/dist/hooks/use-make-copilot-readable.js +61 -0
  66. package/dist/hooks/use-make-copilot-readable.js.map +1 -0
  67. package/dist/hooks/use-make-copilot-readable.mjs +2 -2
  68. package/dist/hooks/use-tree.js +155 -0
  69. package/dist/hooks/use-tree.js.map +1 -0
  70. package/dist/index.d.ts +5 -9
  71. package/dist/index.js +838 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/index.mjs +9 -12
  74. package/dist/openai-assistants/hooks/index.js +225 -0
  75. package/dist/openai-assistants/hooks/index.js.map +1 -0
  76. package/dist/openai-assistants/hooks/index.mjs +3 -3
  77. package/dist/openai-assistants/hooks/use-assistants.js +129 -0
  78. package/dist/openai-assistants/hooks/use-assistants.js.map +1 -0
  79. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +226 -0
  80. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -0
  81. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +3 -3
  82. package/dist/openai-assistants/index.js +226 -0
  83. package/dist/openai-assistants/index.js.map +1 -0
  84. package/dist/openai-assistants/index.mjs +3 -3
  85. package/dist/openai-assistants/utils/index.js +49 -0
  86. package/dist/openai-assistants/utils/index.js.map +1 -0
  87. package/dist/openai-assistants/utils/process-message-stream.js +49 -0
  88. package/dist/openai-assistants/utils/process-message-stream.js.map +1 -0
  89. package/dist/types/document-pointer.js +4 -0
  90. package/dist/types/index.d.ts +1 -2
  91. package/dist/types/index.js +4 -0
  92. package/dist/types/system-message.d.ts +3 -0
  93. package/dist/types/system-message.js +4 -0
  94. package/dist/types/system-message.mjs +3 -0
  95. package/dist/utils/fetch-chat-completion.d.ts +28 -0
  96. package/dist/utils/fetch-chat-completion.js +103 -0
  97. package/dist/utils/fetch-chat-completion.js.map +1 -0
  98. package/dist/utils/fetch-chat-completion.mjs +4 -0
  99. package/dist/utils/utils.js +4 -0
  100. package/dist/utils/utils.test.js +10 -0
  101. package/dist/utils/utils.test.js.map +1 -0
  102. package/package.json +8 -8
  103. package/src/components/copilot-provider/copilotkit-props.tsx +42 -0
  104. package/src/components/copilot-provider/{copilot-provider.tsx → copilotkit.tsx} +22 -57
  105. package/src/components/copilot-provider/index.ts +2 -6
  106. package/src/context/copilot-context.tsx +5 -13
  107. package/src/hooks/use-chat.ts +54 -72
  108. package/src/hooks/use-copilot-chat.ts +16 -9
  109. package/src/hooks/use-make-copilot-actionable.ts +1 -1
  110. package/src/index.tsx +6 -1
  111. package/src/types/index.ts +1 -3
  112. package/src/types/system-message.ts +4 -0
  113. package/src/utils/fetch-chat-completion.ts +95 -0
  114. package/tsup.config.ts +1 -2
  115. package/dist/chunk-6A4PCNMZ.mjs.map +0 -1
  116. package/dist/chunk-6SOQYBNX.mjs +0 -44
  117. package/dist/chunk-6SOQYBNX.mjs.map +0 -1
  118. package/dist/chunk-FP4EXCGS.mjs.map +0 -1
  119. package/dist/chunk-LMZN4NSM.mjs +0 -113
  120. package/dist/chunk-LMZN4NSM.mjs.map +0 -1
  121. package/dist/chunk-PUFR5OAI.mjs +0 -3
  122. package/dist/chunk-QTET3FBV.mjs.map +0 -1
  123. package/dist/chunk-SFQOMKM2.mjs.map +0 -1
  124. package/dist/chunk-TKXPMMND.mjs +0 -177
  125. package/dist/chunk-TKXPMMND.mjs.map +0 -1
  126. package/dist/chunk-VK25FIML.mjs +0 -144
  127. package/dist/chunk-VK25FIML.mjs.map +0 -1
  128. package/dist/components/copilot-provider/copilot-provider-props.d.ts +0 -50
  129. package/dist/components/copilot-provider/copilot-provider-props.mjs +0 -3
  130. package/dist/components/copilot-provider/copilot-provider.mjs +0 -8
  131. package/dist/openai/chat-completion-client.d.ts +0 -52
  132. package/dist/openai/chat-completion-client.mjs +0 -5
  133. package/dist/openai/chat-completion-stream.d.ts +0 -21
  134. package/dist/openai/chat-completion-stream.mjs +0 -5
  135. package/dist/openai/chat-completion-transport.d.ts +0 -38
  136. package/dist/openai/chat-completion-transport.mjs +0 -4
  137. package/dist/openai/index.d.ts +0 -10
  138. package/dist/openai/index.mjs +0 -6
  139. package/dist/types/annotated-function.d.ts +0 -24
  140. package/dist/types/annotated-function.mjs +0 -3
  141. package/dist/types/base.d.ts +0 -56
  142. package/dist/types/base.mjs +0 -3
  143. package/dist/types/message.d.ts +0 -2
  144. package/dist/types/message.mjs +0 -3
  145. package/dist/types/message.mjs.map +0 -1
  146. package/src/components/copilot-provider/copilot-provider-props.tsx +0 -50
  147. package/src/openai/chat-completion-client.ts +0 -229
  148. package/src/openai/chat-completion-stream.ts +0 -54
  149. package/src/openai/chat-completion-transport.ts +0 -186
  150. package/src/openai/index.tsx +0 -5
  151. package/src/types/annotated-function.ts +0 -27
  152. package/src/types/base.ts +0 -61
  153. package/src/types/message.ts +0 -0
  154. /package/dist/{chunk-7P4OYNP3.mjs.map → chunk-IQH5AQQC.mjs.map} +0 -0
  155. /package/dist/{chunk-TU4DNDO7.mjs.map → chunk-VP2EU4US.mjs.map} +0 -0
  156. /package/dist/{chunk-HW5IH6PV.mjs.map → chunk-YOXWT7I6.mjs.map} +0 -0
  157. /package/dist/{chunk-PUFR5OAI.mjs.map → components/copilot-provider/copilotkit-props.js.map} +0 -0
  158. /package/dist/components/copilot-provider/{copilot-provider-props.mjs.map → copilotkit-props.mjs.map} +0 -0
  159. /package/dist/components/copilot-provider/{copilot-provider.mjs.map → copilotkit.mjs.map} +0 -0
  160. /package/dist/{openai/chat-completion-client.mjs.map → types/document-pointer.js.map} +0 -0
  161. /package/dist/{openai/chat-completion-stream.mjs.map → types/index.js.map} +0 -0
  162. /package/dist/{openai/chat-completion-transport.mjs.map → types/system-message.js.map} +0 -0
  163. /package/dist/{openai/index.mjs.map → types/system-message.mjs.map} +0 -0
  164. /package/dist/{types/annotated-function.mjs.map → utils/fetch-chat-completion.mjs.map} +0 -0
  165. /package/dist/{types/base.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"]}
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ //# sourceMappingURL=out.js.map
4
+ //# sourceMappingURL=document-pointer.js.map
@@ -1,3 +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';
2
+ export { SystemMessageFunction } from './system-message.js';
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ //# sourceMappingURL=out.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ type SystemMessageFunction = (contextString: string, additionalInstructions?: string) => string;
2
+
3
+ export { SystemMessageFunction };
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ //# sourceMappingURL=out.js.map
4
+ //# sourceMappingURL=system-message.js.map
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=system-message.mjs.map
@@ -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,4 @@
1
+ export { fetchAndDecodeChatCompletion, fetchAndDecodeChatCompletionAsText, fetchChatCompletion } from '../chunk-UAKLDQMP.mjs';
2
+ import '../chunk-MRXNTQOX.mjs';
3
+ //# sourceMappingURL=out.js.map
4
+ //# sourceMappingURL=fetch-chat-completion.mjs.map
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ //# sourceMappingURL=out.js.map
4
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ // src/utils/utils.test.ts
4
+ describe("emptyTest", () => {
5
+ it("should be truthy", () => {
6
+ expect(true).toBeTruthy();
7
+ });
8
+ });
9
+ //# sourceMappingURL=out.js.map
10
+ //# sourceMappingURL=utils.test.js.map
@@ -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.0",
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": "./dist/index.mjs",
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
- "eslint-config-custom": "0.2.0",
27
- "tsconfig": "0.6.0"
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
- "openai": "^4.6.0",
33
- "@copilotkit/shared": "0.1.1"
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 { AnnotatedFunction } from "../../types/annotated-function";
7
- import { ChatCompletionCreateParams } from "openai/resources/chat";
8
- import { DocumentPointer, FunctionCallHandler } from "../../types";
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 { CopilotProviderProps } from "./copilot-provider-props";
15
+ import { CopilotKitProps } from "./copilotkit-props";
12
16
 
13
17
  /**
14
- * The CopilotProvider component.
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
- * <CopilotProvider chatApiEndpoint="https://your.copilotkit.api">
29
+ * <CopilotKit url="https://your.copilotkit.api">
26
30
  * <App />
27
- * </CopilotProvider>
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
- * <CopilotProvider chatApiConfig={copilotApiConfig}>
46
+ * <CopilotKit chatApiConfig={copilotApiConfig}>
43
47
  * <App />
44
- * </CopilotProvider>
48
+ * </CopilotKit>
45
49
  * ```
46
50
  *
47
51
  * @param props - The props for the component.
48
- * @returns The CopilotProvider component.
52
+ * @returns The CopilotKit component.
49
53
  */
50
- export function CopilotProvider({ children, ...props }: CopilotProviderProps): JSX.Element {
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
- let copilotApiConfig: CopilotApiConfig;
145
- if ("chatApiEndpoint" in props) {
146
- copilotApiConfig = new StandardCopilotApiConfig(
147
- props.chatApiEndpoint,
148
- props.chatApiEndpointV2 || `${props.chatApiEndpoint}/v2`,
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 { CopilotProvider, defaultCopilotContextCategories } from "./copilot-provider";
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 "../types";
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: () => ChatCompletionCreateParams.Function[];
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
  }