@copilotkit/react-core 0.17.0-alpha.4 → 0.17.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/.turbo/turbo-build.log +101 -105
  2. package/CHANGELOG.md +6 -0
  3. package/dist/components/copilot-provider/copilot-provider-props.mjs +1 -2
  4. package/dist/components/copilot-provider/copilot-provider-props.mjs.map +1 -1
  5. package/dist/components/copilot-provider/copilot-provider.mjs +468 -7
  6. package/dist/components/copilot-provider/copilot-provider.mjs.map +1 -1
  7. package/dist/components/copilot-provider/index.mjs +467 -8
  8. package/dist/components/copilot-provider/index.mjs.map +1 -1
  9. package/dist/components/copilot-provider/standard-copilot-api-config.mjs +12 -3
  10. package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +1 -1
  11. package/dist/components/index.mjs +467 -9
  12. package/dist/components/index.mjs.map +1 -1
  13. package/dist/context/copilot-context.mjs +70 -3
  14. package/dist/context/copilot-context.mjs.map +1 -1
  15. package/dist/context/index.mjs +69 -4
  16. package/dist/context/index.mjs.map +1 -1
  17. package/dist/hooks/index.mjs +646 -17
  18. package/dist/hooks/index.mjs.map +1 -1
  19. package/dist/hooks/use-chat.mjs +452 -5
  20. package/dist/hooks/use-chat.mjs.map +1 -1
  21. package/dist/hooks/use-copilot-chat.mjs +591 -13
  22. package/dist/hooks/use-copilot-chat.mjs.map +1 -1
  23. package/dist/hooks/use-flat-category-store.mjs +68 -3
  24. package/dist/hooks/use-flat-category-store.mjs.map +1 -1
  25. package/dist/hooks/use-make-copilot-actionable.mjs +95 -4
  26. package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
  27. package/dist/hooks/use-make-copilot-document-readable.mjs +87 -4
  28. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
  29. package/dist/hooks/use-make-copilot-readable.mjs +87 -4
  30. package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
  31. package/dist/hooks/use-tree.mjs +153 -3
  32. package/dist/hooks/use-tree.mjs.map +1 -1
  33. package/dist/index.mjs +1194 -26
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/openai/chat-completion-client.mjs +353 -4
  36. package/dist/openai/chat-completion-client.mjs.map +1 -1
  37. package/dist/openai/chat-completion-stream.mjs +217 -4
  38. package/dist/openai/chat-completion-stream.mjs.map +1 -1
  39. package/dist/openai/chat-completion-transport.mjs +179 -3
  40. package/dist/openai/chat-completion-transport.mjs.map +1 -1
  41. package/dist/openai/index.mjs +217 -5
  42. package/dist/openai/index.mjs.map +1 -1
  43. package/dist/openai-assistants/hooks/index.mjs +235 -14
  44. package/dist/openai-assistants/hooks/index.mjs.map +1 -1
  45. package/dist/openai-assistants/hooks/use-assistants.mjs +52 -8
  46. package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -1
  47. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +236 -13
  48. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -1
  49. package/dist/openai-assistants/index.mjs +236 -15
  50. package/dist/openai-assistants/index.mjs.map +1 -1
  51. package/dist/openai-assistants/utils/index.mjs +46 -4
  52. package/dist/openai-assistants/utils/index.mjs.map +1 -1
  53. package/dist/openai-assistants/utils/process-message-stream.mjs +46 -3
  54. package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -1
  55. package/dist/types/annotated-function.mjs +0 -2
  56. package/dist/types/annotated-function.mjs.map +1 -1
  57. package/dist/types/base.mjs +0 -2
  58. package/dist/types/base.mjs.map +1 -1
  59. package/dist/types/document-pointer.mjs +0 -2
  60. package/dist/types/document-pointer.mjs.map +1 -1
  61. package/dist/types/index.mjs +0 -2
  62. package/dist/types/index.mjs.map +1 -1
  63. package/dist/types/message.mjs +0 -2
  64. package/dist/types/message.mjs.map +1 -1
  65. package/dist/utils/utils.mjs +0 -2
  66. package/dist/utils/utils.mjs.map +1 -1
  67. package/dist/utils/utils.test.mjs +0 -1
  68. package/dist/utils/utils.test.mjs.map +1 -1
  69. package/package.json +1 -1
  70. package/dist/chunk-56GURLWX.mjs +0 -165
  71. package/dist/chunk-56GURLWX.mjs.map +0 -1
  72. package/dist/chunk-5UGLWBZJ.mjs +0 -3
  73. package/dist/chunk-5UGLWBZJ.mjs.map +0 -1
  74. package/dist/chunk-6A4PCNMZ.mjs +0 -48
  75. package/dist/chunk-6A4PCNMZ.mjs.map +0 -1
  76. package/dist/chunk-6SOQYBNX.mjs +0 -44
  77. package/dist/chunk-6SOQYBNX.mjs.map +0 -1
  78. package/dist/chunk-7GFKOIO7.mjs +0 -3
  79. package/dist/chunk-7GFKOIO7.mjs.map +0 -1
  80. package/dist/chunk-7P4OYNP3.mjs +0 -19
  81. package/dist/chunk-7P4OYNP3.mjs.map +0 -1
  82. package/dist/chunk-BABVSMJR.mjs +0 -3
  83. package/dist/chunk-BABVSMJR.mjs.map +0 -1
  84. package/dist/chunk-EFZPSZWO.mjs +0 -3
  85. package/dist/chunk-EFZPSZWO.mjs.map +0 -1
  86. package/dist/chunk-ELXZFAYR.mjs +0 -77
  87. package/dist/chunk-ELXZFAYR.mjs.map +0 -1
  88. package/dist/chunk-F2JIAPZQ.mjs +0 -13
  89. package/dist/chunk-F2JIAPZQ.mjs.map +0 -1
  90. package/dist/chunk-FP4EXCGS.mjs +0 -27
  91. package/dist/chunk-FP4EXCGS.mjs.map +0 -1
  92. package/dist/chunk-FRAKUJWH.mjs +0 -3
  93. package/dist/chunk-FRAKUJWH.mjs.map +0 -1
  94. package/dist/chunk-HW5IH6PV.mjs +0 -19
  95. package/dist/chunk-HW5IH6PV.mjs.map +0 -1
  96. package/dist/chunk-JD7BAH7U.mjs +0 -3
  97. package/dist/chunk-JD7BAH7U.mjs.map +0 -1
  98. package/dist/chunk-LV3MQPZL.mjs +0 -125
  99. package/dist/chunk-LV3MQPZL.mjs.map +0 -1
  100. package/dist/chunk-MRXNTQOX.mjs +0 -55
  101. package/dist/chunk-MRXNTQOX.mjs.map +0 -1
  102. package/dist/chunk-MZ5UN3BY.mjs +0 -28
  103. package/dist/chunk-MZ5UN3BY.mjs.map +0 -1
  104. package/dist/chunk-PUFR5OAI.mjs +0 -3
  105. package/dist/chunk-PUFR5OAI.mjs.map +0 -1
  106. package/dist/chunk-SPCZTZCY.mjs +0 -3
  107. package/dist/chunk-SPCZTZCY.mjs.map +0 -1
  108. package/dist/chunk-TKXPMMND.mjs +0 -177
  109. package/dist/chunk-TKXPMMND.mjs.map +0 -1
  110. package/dist/chunk-VK25FIML.mjs +0 -144
  111. package/dist/chunk-VK25FIML.mjs.map +0 -1
  112. package/dist/chunk-VNRDQJXW.mjs +0 -3
  113. package/dist/chunk-VNRDQJXW.mjs.map +0 -1
  114. package/dist/chunk-VUY2K2DI.mjs +0 -135
  115. package/dist/chunk-VUY2K2DI.mjs.map +0 -1
  116. package/dist/chunk-WMXA2TIX.mjs +0 -102
  117. package/dist/chunk-WMXA2TIX.mjs.map +0 -1
  118. package/dist/chunk-YULKJPY3.mjs +0 -70
  119. package/dist/chunk-YULKJPY3.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../../../src/openai-assistants/utils/process-message-stream.ts"],"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"],"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;","names":[]}
@@ -1,4 +1,47 @@
1
- export { processMessageStream } from '../../chunk-MZ5UN3BY.mjs';
2
- import '../../chunk-MRXNTQOX.mjs';
3
- //# sourceMappingURL=out.js.map
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/openai-assistants/utils/process-message-stream.ts
23
+ function processMessageStream(reader, processMessage) {
24
+ return __async(this, null, function* () {
25
+ const decoder = new TextDecoder();
26
+ let buffer = "";
27
+ while (true) {
28
+ const { done, value } = yield reader.read();
29
+ if (done) {
30
+ if (buffer.length > 0) {
31
+ processMessage(buffer);
32
+ }
33
+ break;
34
+ }
35
+ buffer += decoder.decode(value, { stream: true });
36
+ let endIndex;
37
+ while ((endIndex = buffer.indexOf("\n")) !== -1) {
38
+ processMessage(buffer.substring(0, endIndex).trim());
39
+ buffer = buffer.substring(endIndex + 1);
40
+ }
41
+ }
42
+ });
43
+ }
44
+ export {
45
+ processMessageStream
46
+ };
4
47
  //# sourceMappingURL=process-message-stream.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../../../src/openai-assistants/utils/process-message-stream.ts"],"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"],"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;","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=annotated-function.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=base.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=document-pointer.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1 @@
1
- import '../chunk-EFZPSZWO.mjs';
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=message.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -4,5 +4,4 @@ describe("emptyTest", () => {
4
4
  expect(true).toBeTruthy();
5
5
  });
6
6
  });
7
- //# sourceMappingURL=out.js.map
8
7
  //# sourceMappingURL=utils.test.mjs.map
@@ -1 +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"]}
1
+ {"version":3,"sources":["../../src/utils/utils.test.ts"],"sourcesContent":["import * as utils from \"./utils\";\n\ndescribe(\"emptyTest\", () => {\n it(\"should be truthy\", () => {\n expect(true).toBeTruthy();\n });\n});\n"],"mappings":";AAEA,SAAS,aAAa,MAAM;AAC1B,KAAG,oBAAoB,MAAM;AAC3B,WAAO,IAAI,EAAE,WAAW;AAAA,EAC1B,CAAC;AACH,CAAC;","names":[]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.0-alpha.4",
7
+ "version": "0.17.0-alpha.5",
8
8
  "sideEffects": false,
9
9
  "main": "./dist/index.js",
10
10
  "module": "./dist/index.mjs",
@@ -1,165 +0,0 @@
1
- import { StandardCopilotApiConfig } from './chunk-F2JIAPZQ.mjs';
2
- import { use_flat_category_store_default } from './chunk-YULKJPY3.mjs';
3
- import { use_tree_default } from './chunk-VUY2K2DI.mjs';
4
- import { CopilotContext } from './chunk-6A4PCNMZ.mjs';
5
- import { __objRest, __spreadProps, __spreadValues, __async } from './chunk-MRXNTQOX.mjs';
6
- import { useState, useCallback } from 'react';
7
- import { jsx } from 'react/jsx-runtime';
8
-
9
- function CopilotProvider(_a) {
10
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
11
- const [entryPoints, setEntryPoints] = useState({});
12
- const { addElement, removeElement, printTree } = use_tree_default();
13
- const {
14
- addElement: addDocument,
15
- removeElement: removeDocument,
16
- allElements: allDocuments
17
- } = use_flat_category_store_default();
18
- const setEntryPoint = useCallback((id, entryPoint) => {
19
- setEntryPoints((prevPoints) => {
20
- return __spreadProps(__spreadValues({}, prevPoints), {
21
- [id]: entryPoint
22
- });
23
- });
24
- }, []);
25
- const removeEntryPoint = useCallback((id) => {
26
- setEntryPoints((prevPoints) => {
27
- const newPoints = __spreadValues({}, prevPoints);
28
- delete newPoints[id];
29
- return newPoints;
30
- });
31
- }, []);
32
- const getContextString = useCallback(
33
- (documents, categories) => {
34
- const documentsString = documents.map((document) => {
35
- return `${document.name} (${document.sourceApplication}):
36
- ${document.getContents()}`;
37
- }).join("\n\n");
38
- const nonDocumentStrings = printTree(categories);
39
- return `${documentsString}
40
-
41
- ${nonDocumentStrings}`;
42
- },
43
- [printTree]
44
- );
45
- const addContext = useCallback(
46
- (context, parentId, categories = defaultCopilotContextCategories) => {
47
- return addElement(context, categories, parentId);
48
- },
49
- [addElement]
50
- );
51
- const removeContext = useCallback(
52
- (id) => {
53
- removeElement(id);
54
- },
55
- [removeElement]
56
- );
57
- const getChatCompletionFunctionDescriptions = useCallback(() => {
58
- return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
59
- }, [entryPoints]);
60
- const getFunctionCallHandler = useCallback(() => {
61
- return entryPointsToFunctionCallHandler(Object.values(entryPoints));
62
- }, [entryPoints]);
63
- const getDocumentsContext = useCallback(
64
- (categories) => {
65
- return allDocuments(categories);
66
- },
67
- [allDocuments]
68
- );
69
- const addDocumentContext = useCallback(
70
- (documentPointer, categories = defaultCopilotContextCategories) => {
71
- return addDocument(documentPointer, categories);
72
- },
73
- [addDocument]
74
- );
75
- const removeDocumentContext = useCallback(
76
- (documentId) => {
77
- removeDocument(documentId);
78
- },
79
- [removeDocument]
80
- );
81
- let copilotApiConfig;
82
- if ("chatApiEndpoint" in props) {
83
- copilotApiConfig = new StandardCopilotApiConfig(
84
- props.chatApiEndpoint,
85
- props.chatApiEndpointV2 || `${props.chatApiEndpoint}/v2`,
86
- {},
87
- {}
88
- );
89
- } else {
90
- copilotApiConfig = props.chatApiConfig;
91
- }
92
- return /* @__PURE__ */ jsx(
93
- CopilotContext.Provider,
94
- {
95
- value: {
96
- entryPoints,
97
- getChatCompletionFunctionDescriptions,
98
- getFunctionCallHandler,
99
- setEntryPoint,
100
- removeEntryPoint,
101
- getContextString,
102
- addContext,
103
- removeContext,
104
- getDocumentsContext,
105
- addDocumentContext,
106
- removeDocumentContext,
107
- copilotApiConfig
108
- },
109
- children
110
- }
111
- );
112
- }
113
- var defaultCopilotContextCategories = ["global"];
114
- function entryPointsToFunctionCallHandler(entryPoints) {
115
- return (chatMessages, functionCall) => __async(this, null, function* () {
116
- let entrypointsByFunctionName = {};
117
- for (let entryPoint of entryPoints) {
118
- entrypointsByFunctionName[entryPoint.name] = entryPoint;
119
- }
120
- const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""];
121
- if (entryPointFunction) {
122
- let functionCallArguments = [];
123
- if (functionCall.arguments) {
124
- functionCallArguments = JSON.parse(functionCall.arguments);
125
- }
126
- const paramsInCorrectOrder = [];
127
- for (let arg of entryPointFunction.argumentAnnotations) {
128
- paramsInCorrectOrder.push(
129
- functionCallArguments[arg.name]
130
- );
131
- }
132
- yield entryPointFunction.implementation(...paramsInCorrectOrder);
133
- }
134
- });
135
- }
136
- function entryPointsToChatCompletionFunctions(entryPoints) {
137
- return entryPoints.map(annotatedFunctionToChatCompletionFunction);
138
- }
139
- function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
140
- let parameters = {};
141
- for (let arg of annotatedFunction.argumentAnnotations) {
142
- let _a = arg, forwardedArgs = __objRest(_a, ["name", "required"]);
143
- parameters[arg.name] = forwardedArgs;
144
- }
145
- let requiredParameterNames = [];
146
- for (let arg of annotatedFunction.argumentAnnotations) {
147
- if (arg.required) {
148
- requiredParameterNames.push(arg.name);
149
- }
150
- }
151
- let chatCompletionFunction = {
152
- name: annotatedFunction.name,
153
- description: annotatedFunction.description,
154
- parameters: {
155
- type: "object",
156
- properties: parameters,
157
- required: requiredParameterNames
158
- }
159
- };
160
- return chatCompletionFunction;
161
- }
162
-
163
- export { CopilotProvider, defaultCopilotContextCategories };
164
- //# sourceMappingURL=out.js.map
165
- //# sourceMappingURL=chunk-56GURLWX.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/copilot-provider/copilot-provider.tsx"],"names":[],"mappings":"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","sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer, FunctionCallHandler } from \"../../types\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { StandardCopilotApiConfig } from \"./standard-copilot-api-config\";\nimport { CopilotProviderProps } from \"./copilot-provider-props\";\n\n/**\n * The CopilotProvider component.\n * This component provides the Copilot context to its children.\n * It can be configured either with a chat API endpoint or a CopilotApiConfig.\n *\n * NOTE: The backend can use OpenAI, or you can bring your own LLM.\n * For examples of the backend api implementation, see `examples/next-openai` usage (under `src/api/copilotkit`),\n * or read the documentation at https://docs.copilotkit.ai\n * In particular, Getting-Started > Quickstart-Backend: https://docs.copilotkit.ai/getting-started/quickstart-backend\n *\n * Example usage:\n * ```\n * <CopilotProvider chatApiEndpoint=\"https://your.copilotkit.api\">\n * <App />\n * </CopilotProvider>\n * ```\n *\n * or\n *\n * ```\n * const copilotApiConfig = new StandardCopilotApiConfig(\n * \"https://your.copilotkit.api/v1\",\n * \"https://your.copilotkit.api/v2\",\n * {},\n * {}\n * );\n *\n * // ...\n *\n * <CopilotProvider chatApiConfig={copilotApiConfig}>\n * <App />\n * </CopilotProvider>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotProvider component.\n */\nexport function CopilotProvider({ children, ...props }: CopilotProviderProps): JSX.Element {\n // Compute all the functions and properties that we need to pass\n // to the CopilotContext.\n\n const [entryPoints, setEntryPoints] = useState<Record<string, AnnotatedFunction<any[]>>>({});\n\n const { addElement, removeElement, printTree } = useTree();\n\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback((id: string, entryPoint: AnnotatedFunction<any[]>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n }, []);\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (documents: DocumentPointer[], categories: string[]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${document.sourceApplication}):\\n${document.getContents()}`;\n })\n .join(\"\\n\\n\");\n\n const nonDocumentStrings = printTree(categories);\n\n return `${documentsString}\\n\\n${nonDocumentStrings}`;\n },\n [printTree],\n );\n\n const addContext = useCallback(\n (\n context: string,\n parentId?: string,\n categories: string[] = defaultCopilotContextCategories,\n ) => {\n return addElement(context, categories, parentId);\n },\n [addElement],\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement],\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(() => {\n return entryPointsToChatCompletionFunctions(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getFunctionCallHandler = useCallback(() => {\n return entryPointsToFunctionCallHandler(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getDocumentsContext = useCallback(\n (categories: string[]) => {\n return allDocuments(categories);\n },\n [allDocuments],\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument],\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument],\n );\n\n // get the appropriate CopilotApiConfig from the props\n let copilotApiConfig: CopilotApiConfig;\n if (\"chatApiEndpoint\" in props) {\n copilotApiConfig = new StandardCopilotApiConfig(\n props.chatApiEndpoint,\n props.chatApiEndpointV2 || `${props.chatApiEndpoint}/v2`,\n {},\n {},\n );\n } else {\n copilotApiConfig = props.chatApiConfig;\n }\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: copilotApiConfig,\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[],\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<string, AnnotatedFunction<any[]>> = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction = entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let functionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n functionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n functionCallArguments[arg.name as keyof typeof functionCallArguments],\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[],\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-5UGLWBZJ.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,48 +0,0 @@
1
- import './chunk-MRXNTQOX.mjs';
2
- import React from 'react';
3
-
4
- var emptyCopilotContext = {
5
- entryPoints: {},
6
- setEntryPoint: () => {
7
- },
8
- removeEntryPoint: () => {
9
- },
10
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
11
- getFunctionCallHandler: () => returnAndThrowInDebug(),
12
- getContextString: (documents, categories) => returnAndThrowInDebug(),
13
- addContext: () => "",
14
- removeContext: () => {
15
- },
16
- getDocumentsContext: (categories) => returnAndThrowInDebug(),
17
- addDocumentContext: () => returnAndThrowInDebug(),
18
- removeDocumentContext: () => {
19
- },
20
- copilotApiConfig: new class {
21
- get chatApiEndpoint() {
22
- throw new Error(
23
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
24
- );
25
- }
26
- get chatApiEndpointV2() {
27
- throw new Error(
28
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
29
- );
30
- }
31
- get headers() {
32
- return {};
33
- }
34
- get body() {
35
- return {};
36
- }
37
- }()
38
- };
39
- var CopilotContext = React.createContext(emptyCopilotContext);
40
- function returnAndThrowInDebug(value) {
41
- throw new Error(
42
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
43
- );
44
- }
45
-
46
- export { CopilotContext };
47
- //# sourceMappingURL=out.js.map
48
- //# sourceMappingURL=chunk-6A4PCNMZ.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/context/copilot-context.tsx"],"names":[],"mappings":";;;;;AAGA,OAAO,WAAW;AAmElB,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,MAAM,cAAoC,mBAAmB;AAE3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACA,SAAO;AACT","sourcesContent":["\"use client\";\n\nimport { FunctionCallHandler } from \"../types\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n}\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: () => ChatCompletionCreateParams.Function[];\n getFunctionCallHandler: () => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\",\n );\n }\n get chatApiEndpointV2(): string {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\",\n );\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\",\n );\n return value;\n}\n"]}
@@ -1,44 +0,0 @@
1
- import { ChatCompletionTransport } from './chunk-VK25FIML.mjs';
2
- import { __async, __spreadValues } from './chunk-MRXNTQOX.mjs';
3
-
4
- // src/openai/chat-completion-stream.ts
5
- var ChatCompletionStream = class {
6
- constructor(params) {
7
- this.url = params.url;
8
- }
9
- fetch(params) {
10
- return __async(this, null, function* () {
11
- params = __spreadValues({}, params);
12
- params.functions = void 0;
13
- const transport = new ChatCompletionTransport({});
14
- const cleanup = () => {
15
- transport.off("data");
16
- transport.off("end");
17
- transport.off("error");
18
- };
19
- const stream = new ReadableStream({
20
- start: (controller) => {
21
- transport.on("data", (data) => {
22
- if (data.choices[0].delta.content) {
23
- controller.enqueue(data.choices[0].delta.content);
24
- }
25
- });
26
- transport.on("error", (error) => {
27
- controller.error(error);
28
- cleanup();
29
- });
30
- transport.on("end", () => {
31
- controller.close();
32
- cleanup();
33
- });
34
- }
35
- });
36
- transport.fetch(params);
37
- return stream;
38
- });
39
- }
40
- };
41
-
42
- export { ChatCompletionStream };
43
- //# sourceMappingURL=out.js.map
44
- //# sourceMappingURL=chunk-6SOQYBNX.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/openai/chat-completion-stream.ts"],"names":[],"mappings":";;;;;;;;;AAUO,IAAM,uBAAN,MAA2B;AAAA,EAGhC,YAAY,QAA2C;AACrD,SAAK,MAAM,OAAO;AAAA,EACpB;AAAA,EAEa,MAAM,QAA6E;AAAA;AAC9F,eAAS,mBAAK;AACd,aAAO,YAAY;AAEnB,YAAM,YAAY,IAAI,wBAAwB,CAAC,CAAC;AAEhD,YAAM,UAAU,MAAM;AACpB,kBAAU,IAAI,MAAM;AACpB,kBAAU,IAAI,KAAK;AACnB,kBAAU,IAAI,OAAO;AAAA,MACvB;AAEA,YAAM,SAAS,IAAI,eAAuB;AAAA,QACxC,OAAO,CAAC,eAAe;AACrB,oBAAU,GAAG,QAAQ,CAAC,SAAS;AAC7B,gBAAI,KAAK,QAAQ,CAAC,EAAE,MAAM,SAAS;AACjC,yBAAW,QAAQ,KAAK,QAAQ,CAAC,EAAE,MAAM,OAAO;AAAA,YAClD;AAAA,UACF,CAAC;AAED,oBAAU,GAAG,SAAS,CAAC,UAAU;AAC/B,uBAAW,MAAM,KAAK;AACtB,oBAAQ;AAAA,UACV,CAAC;AAED,oBAAU,GAAG,OAAO,MAAM;AACxB,uBAAW,MAAM;AACjB,oBAAQ;AAAA,UACV,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAED,gBAAU,MAAM,MAAM;AAEtB,aAAO;AAAA,IACT;AAAA;AACF","sourcesContent":["import {\n ChatCompletionTransport,\n ChatCompletionTransportFetchParams,\n} from \"./chat-completion-transport\";\n\nexport interface ChatCompletionStreamConfiguration {\n url: string;\n model?: string;\n}\n\nexport class ChatCompletionStream {\n private url: string;\n\n constructor(params: ChatCompletionStreamConfiguration) {\n this.url = params.url;\n }\n\n public async fetch(params: ChatCompletionTransportFetchParams): Promise<ReadableStream<string>> {\n params = { ...params };\n params.functions = undefined;\n\n const transport = new ChatCompletionTransport({});\n\n const cleanup = () => {\n transport.off(\"data\");\n transport.off(\"end\");\n transport.off(\"error\");\n };\n\n const stream = new ReadableStream<string>({\n start: (controller) => {\n transport.on(\"data\", (data) => {\n if (data.choices[0].delta.content) {\n controller.enqueue(data.choices[0].delta.content);\n }\n });\n\n transport.on(\"error\", (error) => {\n controller.error(error);\n cleanup();\n });\n\n transport.on(\"end\", () => {\n controller.close();\n cleanup();\n });\n },\n });\n\n transport.fetch(params);\n\n return stream;\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-7GFKOIO7.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,19 +0,0 @@
1
- import { CopilotContext } from './chunk-6A4PCNMZ.mjs';
2
- import { useContext, useRef, useEffect } from 'react';
3
-
4
- function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
5
- const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);
6
- const idRef = useRef();
7
- useEffect(() => {
8
- const id = addDocumentContext(document, categories);
9
- idRef.current = id;
10
- return () => {
11
- removeDocumentContext(id);
12
- };
13
- }, [addDocumentContext, removeDocumentContext, ...dependencies]);
14
- return idRef.current;
15
- }
16
-
17
- export { useMakeCopilotDocumentReadable };
18
- //# sourceMappingURL=out.js.map
19
- //# sourceMappingURL=chunk-7P4OYNP3.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-make-copilot-document-readable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,YAAY,WAAW,cAAc;AAWvC,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAAI,WAAW,cAAc;AAC/E,QAAM,QAAQ,OAAe;AAE7B,YAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,GAAG,YAAY,CAAC;AAE/D,SAAO,MAAM;AACf","sourcesContent":["\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-BABVSMJR.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-EFZPSZWO.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,77 +0,0 @@
1
- import { useChat } from './chunk-WMXA2TIX.mjs';
2
- import { defaultCopilotContextCategories } from './chunk-56GURLWX.mjs';
3
- import { CopilotContext } from './chunk-6A4PCNMZ.mjs';
4
- import { __objRest, __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
5
- import { useContext, useMemo } from 'react';
6
-
7
- function useCopilotChat(_a) {
8
- var _b = _a, {
9
- makeSystemMessage
10
- } = _b, options = __objRest(_b, [
11
- "makeSystemMessage"
12
- ]);
13
- const {
14
- getContextString,
15
- getChatCompletionFunctionDescriptions,
16
- getFunctionCallHandler,
17
- copilotApiConfig
18
- } = useContext(CopilotContext);
19
- const systemMessage = useMemo(() => {
20
- const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
21
- const contextString = getContextString([], defaultCopilotContextCategories);
22
- return {
23
- id: "system",
24
- content: systemMessageMaker(contextString),
25
- role: "system"
26
- };
27
- }, [getContextString, makeSystemMessage]);
28
- const functionDescriptions = useMemo(() => {
29
- return getChatCompletionFunctionDescriptions();
30
- }, [getChatCompletionFunctionDescriptions]);
31
- const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
32
- copilotConfig: copilotApiConfig,
33
- id: options.id,
34
- initialMessages: [systemMessage].concat(options.initialMessages || []),
35
- functions: functionDescriptions,
36
- onFunctionCall: getFunctionCallHandler(),
37
- headers: __spreadValues({}, options.headers),
38
- body: __spreadValues({}, options.body)
39
- }));
40
- const visibleMessages = messages.filter(
41
- (message) => message.role === "user" || message.role === "assistant"
42
- );
43
- return {
44
- visibleMessages,
45
- append,
46
- reload,
47
- stop,
48
- isLoading,
49
- input,
50
- setInput
51
- };
52
- }
53
- function defaultSystemMessage(contextString) {
54
- return `
55
- Please act as an efficient, competent, conscientious, and industrious professional assistant.
56
-
57
- Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
58
- Always be polite and respectful, and prefer brevity over verbosity.
59
-
60
- The user has provided you with the following context:
61
- \`\`\`
62
- ${contextString}
63
- \`\`\`
64
-
65
- They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
66
-
67
- Please assist them as best you can.
68
-
69
- You can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.
70
-
71
- If you would like to call a function, call it without saying anything else.
72
- `;
73
- }
74
-
75
- export { defaultSystemMessage, useCopilotChat };
76
- //# sourceMappingURL=out.js.map
77
- //# sourceMappingURL=chunk-ELXZFAYR.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;AAqB7B,SAAS,eAAe,IAGiB;AAHjB,eAC7B;AAAA;AAAA,EAtBF,IAqB+B,IAE1B,oBAF0B,IAE1B;AAAA,IADH;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,qBAAqB;AAChD,UAAM,gBAAgB,iBAAiB,CAAC,GAAG,+BAA+B;AAE1E,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,mBAAmB,aAAa;AAAA,MACzC,MAAM;AAAA,IACR;AAAA,EACF,GAAG,CAAC,kBAAkB,iBAAiB,CAAC;AAExC,QAAM,uBAA8D,QAAQ,MAAM;AAChF,WAAO,sCAAsC;AAAA,EAC/C,GAAG,CAAC,qCAAqC,CAAC;AAE1C,QAAM,EAAE,UAAU,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,IAAI,QAAQ,iCAC1E,UAD0E;AAAA,IAE7E,eAAe;AAAA,IACf,IAAI,QAAQ;AAAA,IACZ,iBAAiB,CAAC,aAAa,EAAE,OAAO,QAAQ,mBAAmB,CAAC,CAAC;AAAA,IACrE,WAAW;AAAA,IACX,gBAAgB,uBAAuB;AAAA,IACvC,SAAS,mBAAK,QAAQ;AAAA,IACtB,MAAM,mBACD,QAAQ;AAAA,EAEf,EAAC;AAED,QAAM,kBAAkB,SAAS;AAAA,IAC/B,CAAC,YAAY,QAAQ,SAAS,UAAU,QAAQ,SAAS;AAAA,EAC3D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,eAA+B;AAClE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWF","sourcesContent":["import { useMemo, useContext } from \"react\";\nimport { CopilotContext, CopilotContextParams } from \"../context/copilot-context\";\nimport { Message } from \"../types\";\nimport { UseChatOptions, useChat } from \"./use-chat\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: (contextString: string) => string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (message: Message) => Promise<void>;\n reload: () => Promise<void>;\n stop: () => void;\n isLoading: boolean;\n input: string;\n setInput: React.Dispatch<React.SetStateAction<string>>;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions): UseCopilotChatReturn {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, makeSystemMessage]);\n\n const functionDescriptions: ChatCompletionCreateParams.Function[] = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } = useChat({\n ...options,\n copilotConfig: copilotApiConfig,\n id: options.id,\n initialMessages: [systemMessage].concat(options.initialMessages || []),\n functions: functionDescriptions,\n onFunctionCall: getFunctionCallHandler(),\n headers: { ...options.headers },\n body: {\n ...options.body,\n },\n });\n\n const visibleMessages = messages.filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n );\n\n return {\n visibleMessages,\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\n };\n}\n\nexport function defaultSystemMessage(contextString: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n`;\n}\n"]}
@@ -1,13 +0,0 @@
1
- // src/components/copilot-provider/standard-copilot-api-config.tsx
2
- var StandardCopilotApiConfig = class {
3
- constructor(chatApiEndpoint, chatApiEndpointV2, headers, body) {
4
- this.chatApiEndpoint = chatApiEndpoint;
5
- this.chatApiEndpointV2 = chatApiEndpointV2;
6
- this.headers = headers;
7
- this.body = body;
8
- }
9
- };
10
-
11
- export { StandardCopilotApiConfig };
12
- //# sourceMappingURL=out.js.map
13
- //# sourceMappingURL=chunk-F2JIAPZQ.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/copilot-provider/standard-copilot-api-config.tsx"],"names":[],"mappings":";AAUO,IAAM,2BAAN,MAA2D;AAAA,EAMhE,YACE,iBACA,mBACA,SACA,MACA;AACA,SAAK,kBAAkB;AACvB,SAAK,oBAAoB;AACzB,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AACF","sourcesContent":["import { CopilotApiConfig } from \"../../context/copilot-context\";\n\n/**\n * A standard implementation of the CopilotApiConfig interface.\n *\n * Pass in the base URL of the chat API, the headers to be sent with each request, and the body to be sent with each request.\n * The rest of the CopilotApiConfig interface is implemented by default.\n *\n */\n\nexport class StandardCopilotApiConfig implements CopilotApiConfig {\n chatApiEndpoint: string;\n chatApiEndpointV2: string;\n headers: Record<string, string>;\n body: Record<string, any>;\n\n constructor(\n chatApiEndpoint: string,\n chatApiEndpointV2: string,\n headers: Record<string, string>,\n body: Record<string, any>,\n ) {\n this.chatApiEndpoint = chatApiEndpoint;\n this.chatApiEndpointV2 = chatApiEndpointV2;\n this.headers = headers;\n this.body = body;\n }\n}\n"]}