@copilotkit/react-core 0.18.0-alpha.8 → 0.18.0

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 (159) hide show
  1. package/.turbo/turbo-build.log +198 -245
  2. package/CHANGELOG.md +43 -0
  3. package/dist/chunk-4CFJ6A6A.mjs +15 -9
  4. package/dist/chunk-4CFJ6A6A.mjs.map +1 -1
  5. package/dist/chunk-5GS7FQPW.mjs +20 -7
  6. package/dist/chunk-5GS7FQPW.mjs.map +1 -1
  7. package/dist/chunk-5UGLWBZJ.mjs +0 -2
  8. package/dist/chunk-5UGLWBZJ.mjs.map +1 -1
  9. package/dist/chunk-7GFKOIO7.mjs +0 -2
  10. package/dist/chunk-7GFKOIO7.mjs.map +1 -1
  11. package/dist/chunk-BABVSMJR.mjs +0 -2
  12. package/dist/chunk-BABVSMJR.mjs.map +1 -1
  13. package/dist/chunk-DGUVNY3V.mjs +9 -5
  14. package/dist/chunk-DGUVNY3V.mjs.map +1 -1
  15. package/dist/chunk-EFZPSZWO.mjs +0 -2
  16. package/dist/chunk-EFZPSZWO.mjs.map +1 -1
  17. package/dist/chunk-F2JIAPZQ.mjs +3 -2
  18. package/dist/chunk-F2JIAPZQ.mjs.map +1 -1
  19. package/dist/chunk-FRAKUJWH.mjs +0 -2
  20. package/dist/chunk-FRAKUJWH.mjs.map +1 -1
  21. package/dist/chunk-GBZZPQ5X.mjs +28 -10
  22. package/dist/chunk-GBZZPQ5X.mjs.map +1 -1
  23. package/dist/chunk-IQEWY7P4.mjs +13 -6
  24. package/dist/chunk-IQEWY7P4.mjs.map +1 -1
  25. package/dist/chunk-IQH5AQQC.mjs +8 -4
  26. package/dist/chunk-IQH5AQQC.mjs.map +1 -1
  27. package/dist/chunk-JD7BAH7U.mjs +0 -2
  28. package/dist/chunk-JD7BAH7U.mjs.map +1 -1
  29. package/dist/chunk-MRXNTQOX.mjs +6 -2
  30. package/dist/chunk-MRXNTQOX.mjs.map +1 -1
  31. package/dist/chunk-MZ5UN3BY.mjs +6 -3
  32. package/dist/chunk-MZ5UN3BY.mjs.map +1 -1
  33. package/dist/chunk-SPCZTZCY.mjs +0 -2
  34. package/dist/chunk-SPCZTZCY.mjs.map +1 -1
  35. package/dist/chunk-UAKLDQMP.mjs +16 -4
  36. package/dist/chunk-UAKLDQMP.mjs.map +1 -1
  37. package/dist/chunk-VNRDQJXW.mjs +0 -2
  38. package/dist/chunk-VNRDQJXW.mjs.map +1 -1
  39. package/dist/chunk-VP2EU4US.mjs +21 -9
  40. package/dist/chunk-VP2EU4US.mjs.map +1 -1
  41. package/dist/chunk-VUY2K2DI.mjs +10 -5
  42. package/dist/chunk-VUY2K2DI.mjs.map +1 -1
  43. package/dist/chunk-YOXWT7I6.mjs +8 -4
  44. package/dist/chunk-YOXWT7I6.mjs.map +1 -1
  45. package/dist/chunk-YULKJPY3.mjs +5 -5
  46. package/dist/chunk-YULKJPY3.mjs.map +1 -1
  47. package/dist/components/copilot-provider/copilotkit-props.js +18 -2
  48. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  49. package/dist/components/copilot-provider/copilotkit-props.mjs +1 -2
  50. package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -1
  51. package/dist/components/copilot-provider/copilotkit.js +89 -44
  52. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  53. package/dist/components/copilot-provider/copilotkit.mjs +14 -7
  54. package/dist/components/copilot-provider/copilotkit.mjs.map +1 -1
  55. package/dist/components/copilot-provider/index.js +90 -44
  56. package/dist/components/copilot-provider/index.js.map +1 -1
  57. package/dist/components/copilot-provider/index.mjs +14 -8
  58. package/dist/components/copilot-provider/index.mjs.map +1 -1
  59. package/dist/components/copilot-provider/standard-copilot-api-config.js +27 -4
  60. package/dist/components/copilot-provider/standard-copilot-api-config.js.map +1 -1
  61. package/dist/components/copilot-provider/standard-copilot-api-config.mjs +7 -3
  62. package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +1 -1
  63. package/dist/components/index.js +90 -44
  64. package/dist/components/index.js.map +1 -1
  65. package/dist/components/index.mjs +15 -9
  66. package/dist/components/index.mjs.map +1 -1
  67. package/dist/context/copilot-context.js +68 -16
  68. package/dist/context/copilot-context.js.map +1 -1
  69. package/dist/context/copilot-context.mjs +8 -3
  70. package/dist/context/copilot-context.mjs.map +1 -1
  71. package/dist/context/index.js +68 -15
  72. package/dist/context/index.js.map +1 -1
  73. package/dist/context/index.mjs +8 -4
  74. package/dist/context/index.mjs.map +1 -1
  75. package/dist/hooks/index.js +98 -42
  76. package/dist/hooks/index.js.map +1 -1
  77. package/dist/hooks/index.mjs +29 -16
  78. package/dist/hooks/index.mjs.map +1 -1
  79. package/dist/hooks/use-chat.js +38 -15
  80. package/dist/hooks/use-chat.js.map +1 -1
  81. package/dist/hooks/use-chat.mjs +8 -4
  82. package/dist/hooks/use-chat.mjs.map +1 -1
  83. package/dist/hooks/use-copilot-chat.js +72 -30
  84. package/dist/hooks/use-copilot-chat.js.map +1 -1
  85. package/dist/hooks/use-copilot-chat.mjs +18 -12
  86. package/dist/hooks/use-copilot-chat.mjs.map +1 -1
  87. package/dist/hooks/use-flat-category-store.js +30 -12
  88. package/dist/hooks/use-flat-category-store.js.map +1 -1
  89. package/dist/hooks/use-flat-category-store.mjs +7 -3
  90. package/dist/hooks/use-flat-category-store.mjs.map +1 -1
  91. package/dist/hooks/use-make-copilot-actionable.js +77 -20
  92. package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
  93. package/dist/hooks/use-make-copilot-actionable.mjs +9 -4
  94. package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
  95. package/dist/hooks/use-make-copilot-document-readable.js +73 -18
  96. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  97. package/dist/hooks/use-make-copilot-document-readable.mjs +9 -4
  98. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
  99. package/dist/hooks/use-make-copilot-readable.js +73 -18
  100. package/dist/hooks/use-make-copilot-readable.js.map +1 -1
  101. package/dist/hooks/use-make-copilot-readable.mjs +9 -4
  102. package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
  103. package/dist/hooks/use-tree.js +30 -13
  104. package/dist/hooks/use-tree.js.map +1 -1
  105. package/dist/hooks/use-tree.mjs +7 -3
  106. package/dist/hooks/use-tree.mjs.map +1 -1
  107. package/dist/index.js +165 -83
  108. package/dist/index.js.map +1 -1
  109. package/dist/index.mjs +57 -23
  110. package/dist/index.mjs.map +1 -1
  111. package/dist/openai-assistants/hooks/index.js +67 -27
  112. package/dist/openai-assistants/hooks/index.js.map +1 -1
  113. package/dist/openai-assistants/hooks/index.mjs +18 -14
  114. package/dist/openai-assistants/hooks/index.mjs.map +1 -1
  115. package/dist/openai-assistants/hooks/use-assistants.js +40 -14
  116. package/dist/openai-assistants/hooks/use-assistants.js.map +1 -1
  117. package/dist/openai-assistants/hooks/use-assistants.mjs +14 -8
  118. package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -1
  119. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +67 -28
  120. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
  121. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +19 -13
  122. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -1
  123. package/dist/openai-assistants/index.js +69 -28
  124. package/dist/openai-assistants/index.js.map +1 -1
  125. package/dist/openai-assistants/index.mjs +22 -15
  126. package/dist/openai-assistants/index.mjs.map +1 -1
  127. package/dist/openai-assistants/utils/index.js +29 -5
  128. package/dist/openai-assistants/utils/index.js.map +1 -1
  129. package/dist/openai-assistants/utils/index.mjs +8 -4
  130. package/dist/openai-assistants/utils/index.mjs.map +1 -1
  131. package/dist/openai-assistants/utils/process-message-stream.js +27 -5
  132. package/dist/openai-assistants/utils/process-message-stream.js.map +1 -1
  133. package/dist/openai-assistants/utils/process-message-stream.mjs +7 -3
  134. package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -1
  135. package/dist/types/document-pointer.js +17 -2
  136. package/dist/types/document-pointer.js.map +1 -1
  137. package/dist/types/document-pointer.mjs +0 -2
  138. package/dist/types/document-pointer.mjs.map +1 -1
  139. package/dist/types/index.js +17 -2
  140. package/dist/types/index.js.map +1 -1
  141. package/dist/types/index.mjs +1 -2
  142. package/dist/types/index.mjs.map +1 -1
  143. package/dist/types/system-message.js +17 -2
  144. package/dist/types/system-message.js.map +1 -1
  145. package/dist/types/system-message.mjs +0 -2
  146. package/dist/types/system-message.mjs.map +1 -1
  147. package/dist/utils/fetch-chat-completion.js +35 -12
  148. package/dist/utils/fetch-chat-completion.js.map +1 -1
  149. package/dist/utils/fetch-chat-completion.mjs +11 -3
  150. package/dist/utils/fetch-chat-completion.mjs.map +1 -1
  151. package/dist/utils/utils.js +17 -2
  152. package/dist/utils/utils.js.map +1 -1
  153. package/dist/utils/utils.mjs +0 -2
  154. package/dist/utils/utils.mjs.map +1 -1
  155. package/dist/utils/utils.test.js +1 -2
  156. package/dist/utils/utils.test.js.map +1 -1
  157. package/dist/utils/utils.test.mjs +0 -1
  158. package/dist/utils/utils.test.mjs.map +1 -1
  159. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,15 +1,10 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
- var shared = require('@copilotkit/shared');
5
- require('react/jsx-runtime');
6
-
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
-
9
- var React__default = /*#__PURE__*/_interopDefault(React);
10
-
1
+ "use strict";
2
+ var __create = Object.create;
11
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
13
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
14
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
15
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -24,6 +19,27 @@ var __spreadValues = (a, b) => {
24
19
  }
25
20
  return a;
26
21
  };
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
+ // If the importer is in node compatibility mode or this is not an ESM
36
+ // file that has been converted to a CommonJS file using a Babel-
37
+ // compatible transform (i.e. "__esModule" has not been set), then set
38
+ // "default" to the CommonJS "module.exports" for node compatibility.
39
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ mod
41
+ ));
42
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
43
  var __async = (__this, __arguments, generator) => {
28
44
  return new Promise((resolve, reject) => {
29
45
  var fulfilled = (value) => {
@@ -45,6 +61,17 @@ var __async = (__this, __arguments, generator) => {
45
61
  });
46
62
  };
47
63
 
64
+ // src/openai-assistants/index.ts
65
+ var openai_assistants_exports = {};
66
+ __export(openai_assistants_exports, {
67
+ processMessageStream: () => processMessageStream,
68
+ useCopilotChatV2: () => useCopilotChatV2
69
+ });
70
+ module.exports = __toCommonJS(openai_assistants_exports);
71
+
72
+ // src/openai-assistants/hooks/use-copilot-chat-v2.ts
73
+ var import_react3 = require("react");
74
+
48
75
  // src/openai-assistants/utils/process-message-stream.ts
49
76
  function processMessageStream(reader, processMessage) {
50
77
  return __async(this, null, function* () {
@@ -67,20 +94,27 @@ function processMessageStream(reader, processMessage) {
67
94
  }
68
95
  });
69
96
  }
97
+
98
+ // src/openai-assistants/hooks/use-copilot-chat-v2.ts
99
+ var import_shared2 = require("@copilotkit/shared");
100
+
101
+ // src/context/copilot-context.tsx
102
+ var import_react = __toESM(require("react"));
70
103
  var emptyCopilotContext = {
71
104
  entryPoints: {},
72
105
  setEntryPoint: () => {
73
106
  },
74
107
  removeEntryPoint: () => {
75
108
  },
76
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
77
- getFunctionCallHandler: () => returnAndThrowInDebug(),
78
- getContextString: (documents, categories) => returnAndThrowInDebug(),
109
+ getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
110
+ getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
111
+ })),
112
+ getContextString: (documents, categories) => returnAndThrowInDebug(""),
79
113
  addContext: () => "",
80
114
  removeContext: () => {
81
115
  },
82
- getDocumentsContext: (categories) => returnAndThrowInDebug(),
83
- addDocumentContext: () => returnAndThrowInDebug(),
116
+ getDocumentsContext: (categories) => returnAndThrowInDebug([]),
117
+ addDocumentContext: () => returnAndThrowInDebug(""),
84
118
  removeDocumentContext: () => {
85
119
  },
86
120
  copilotApiConfig: new class {
@@ -98,10 +132,16 @@ var emptyCopilotContext = {
98
132
  }
99
133
  }()
100
134
  };
101
- var CopilotContext = React__default.default.createContext(emptyCopilotContext);
135
+ var CopilotContext = import_react.default.createContext(emptyCopilotContext);
102
136
  function returnAndThrowInDebug(value) {
103
137
  throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
138
+ return value;
104
139
  }
140
+
141
+ // src/components/copilot-provider/copilotkit.tsx
142
+ var import_react2 = require("react");
143
+ var import_shared = require("@copilotkit/shared");
144
+ var import_jsx_runtime = require("react/jsx-runtime");
105
145
  var defaultCopilotContextCategories = ["global"];
106
146
 
107
147
  // src/openai-assistants/hooks/use-copilot-chat-v2.ts
@@ -111,13 +151,13 @@ function useCopilotChatV2(options) {
111
151
  getChatCompletionFunctionDescriptions,
112
152
  getFunctionCallHandler,
113
153
  copilotApiConfig
114
- } = React.useContext(CopilotContext);
115
- const [messages, setMessages] = React.useState([]);
116
- const [input, setInput] = React.useState("");
117
- const [threadId, setThreadId] = React.useState(void 0);
118
- const [status, setStatus] = React.useState("awaiting_message");
119
- const [error, setError] = React.useState(void 0);
120
- React.useMemo(() => {
154
+ } = (0, import_react3.useContext)(CopilotContext);
155
+ const [messages, setMessages] = (0, import_react3.useState)([]);
156
+ const [input, setInput] = (0, import_react3.useState)("");
157
+ const [threadId, setThreadId] = (0, import_react3.useState)(void 0);
158
+ const [status, setStatus] = (0, import_react3.useState)("awaiting_message");
159
+ const [error, setError] = (0, import_react3.useState)(void 0);
160
+ const systemMessage = (0, import_react3.useMemo)(() => {
121
161
  const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage;
122
162
  const contextString = getContextString([], defaultCopilotContextCategories);
123
163
  return {
@@ -156,7 +196,7 @@ function useCopilotChatV2(options) {
156
196
  }
157
197
  yield processMessageStream(result.body.getReader(), (message) => {
158
198
  try {
159
- const { type, value } = shared.parseStreamPart(message);
199
+ const { type, value } = (0, import_shared2.parseStreamPart)(message);
160
200
  switch (type) {
161
201
  case "assistant_message": {
162
202
  setMessages((messages2) => [
@@ -219,8 +259,9 @@ You can ask them for clarifying questions if needed, but don't be annoying about
219
259
  If you would like to call a function, call it without saying anything else.
220
260
  `;
221
261
  }
222
-
223
- exports.processMessageStream = processMessageStream;
224
- exports.useCopilotChatV2 = useCopilotChatV2;
225
- //# sourceMappingURL=out.js.map
262
+ // Annotate the CommonJS export names for ESM import in node:
263
+ 0 && (module.exports = {
264
+ processMessageStream,
265
+ useCopilotChatV2
266
+ });
226
267
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/openai-assistants/hooks/use-copilot-chat-v2.ts","../../src/openai-assistants/utils/process-message-stream.ts","../../src/context/copilot-context.tsx","../../src/components/copilot-provider/copilotkit.tsx"],"names":["useState","messages","error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,SAAS,YAAAA,iBAAgB;;;ACA9C,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;;;ADtBA,SAAkB,uBAAuB;;;AECzC,OAAO,WAAW;AAiElB,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;A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,KAAK,MAAM;AACvB,qBAAO,CAAC,GAAGA,UAAS,MAAM,GAAGA,UAAS,SAAS,CAAC,GAAG,WAAW;AAAA,YAChE,CAAC;AAED;AAAA,UACF;AAAA,UAEA,KAAK,SAAS;AACZ,qBAAS,KAAK;AACd;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAASC,QAAP;AACA,iBAASA,MAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAED,cAAU,kBAAkB;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;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 { useContext, useMemo, useState } from \"react\";\nimport { processMessageStream } from \"../utils\";\nimport { Message, parseStreamPart } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"../../context\";\nimport { defaultCopilotContextCategories } from \"../../components\";\n\nexport type AssistantStatus = \"in_progress\" | \"awaiting_message\";\n\nexport interface RequestForwardingOptions {\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * Extra body object to be sent with the API request.\n * @example\n * Send a `sessionId` to the API along with the messages.\n * ```js\n * useChat({\n * body: {\n * sessionId: '123',\n * }\n * })\n * ```\n */\n body?: object;\n}\nexport interface UseCopilotChatOptionsV2 extends RequestForwardingOptions {\n makeSystemMessage?: (contextString: string) => string;\n threadId?: string | undefined;\n}\n\nexport interface UseCopilotChatV2Result {\n messages: Message[];\n input: string;\n handleInputChange: (e: any) => void;\n submitMessage: (e: any) => Promise<void>;\n status: AssistantStatus;\n error: unknown;\n}\n\nexport function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotChatV2Result {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const [messages, setMessages] = useState<Message[]>([]);\n const [input, setInput] = useState(\"\");\n const [threadId, setThreadId] = useState<string | undefined>(undefined);\n const [status, setStatus] = useState<AssistantStatus>(\"awaiting_message\");\n const [error, setError] = useState<unknown | undefined>(undefined);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = options.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, options.makeSystemMessage]);\n\n const handleInputChange = (e: any) => {\n setInput(e.target.value);\n };\n\n const submitMessage = async (e: any) => {\n e.preventDefault();\n\n if (input === \"\") {\n return;\n }\n\n setStatus(\"in_progress\");\n\n setMessages((messages) => [...messages, { id: \"\", role: \"user\", content: input }]);\n\n setInput(\"\");\n\n const apiUrl = copilotApiConfig.chatApiEndpointV2;\n\n const functions = getChatCompletionFunctionDescriptions();\n\n const result = await fetch(apiUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotApiConfig.headers,\n ...options.headers,\n },\n body: JSON.stringify({\n // always use user-provided threadId when available:\n threadId: options.threadId ?? threadId ?? null,\n message: input,\n ...(functions.length > 0 && { functions: functions }),\n ...copilotApiConfig.body,\n ...options.body,\n }),\n });\n\n if (result.body == null) {\n throw new Error(\"The response body is empty.\");\n }\n\n await processMessageStream(result.body.getReader(), (message: string) => {\n try {\n const { type, value } = parseStreamPart(message);\n\n switch (type) {\n case \"assistant_message\": {\n // append message:\n setMessages((messages) => [\n ...messages,\n {\n id: value.id,\n role: value.role,\n content: value.content[0].text.value,\n },\n ]);\n break;\n }\n\n case \"assistant_control_data\": {\n setThreadId(value.threadId);\n\n // set id of last message:\n setMessages((messages) => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.id = value.messageId;\n return [...messages.slice(0, messages.length - 1), lastMessage];\n });\n\n break;\n }\n\n case \"error\": {\n setError(value);\n break;\n }\n }\n } catch (error) {\n setError(error);\n }\n });\n\n setStatus(\"awaiting_message\");\n };\n\n return {\n messages,\n input,\n handleInputChange,\n submitMessage,\n status,\n error,\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","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","\"use client\";\n\nimport { FunctionCallHandler, AnnotatedFunction, Function } from \"@copilotkit/shared\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\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: () => 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(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\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(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n","\"use client\";\n\nimport { Function } from \"@copilotkit/shared\";\nimport { useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { DocumentPointer } from \"../../types\";\nimport {\n FunctionCallHandler,\n AnnotatedFunction,\n annotatedFunctionToChatCompletionFunction,\n} from \"@copilotkit/shared\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { StandardCopilotApiConfig } from \"./standard-copilot-api-config\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\n\n/**\n * The CopilotKit 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 * <CopilotKit url=\"https://your.copilotkit.api\">\n * <App />\n * </CopilotKit>\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 * <CopilotKit chatApiConfig={copilotApiConfig}>\n * <App />\n * </CopilotKit>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotKit component.\n */\nexport function CopilotKit({ children, ...props }: CopilotKitProps) {\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 const copilotApiConfig: CopilotApiConfig = new StandardCopilotApiConfig(\n props.url,\n `${props.url}/v2`,\n props.headers || {},\n props.body || {},\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(entryPoints: AnnotatedFunction<any[]>[]): Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n"]}
1
+ {"version":3,"sources":["../../src/openai-assistants/index.ts","../../src/openai-assistants/hooks/use-copilot-chat-v2.ts","../../src/openai-assistants/utils/process-message-stream.ts","../../src/context/copilot-context.tsx","../../src/components/copilot-provider/copilotkit.tsx"],"sourcesContent":["export * from \"./hooks\";\nexport * from \"./utils\";\n","import { useContext, useMemo, useState } from \"react\";\nimport { processMessageStream } from \"../utils\";\nimport { Message, parseStreamPart } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"../../context\";\nimport { defaultCopilotContextCategories } from \"../../components\";\n\nexport type AssistantStatus = \"in_progress\" | \"awaiting_message\";\n\nexport interface RequestForwardingOptions {\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * Extra body object to be sent with the API request.\n * @example\n * Send a `sessionId` to the API along with the messages.\n * ```js\n * useChat({\n * body: {\n * sessionId: '123',\n * }\n * })\n * ```\n */\n body?: object;\n}\nexport interface UseCopilotChatOptionsV2 extends RequestForwardingOptions {\n makeSystemMessage?: (contextString: string) => string;\n threadId?: string | undefined;\n}\n\nexport interface UseCopilotChatV2Result {\n messages: Message[];\n input: string;\n handleInputChange: (e: any) => void;\n submitMessage: (e: any) => Promise<void>;\n status: AssistantStatus;\n error: unknown;\n}\n\nexport function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotChatV2Result {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const [messages, setMessages] = useState<Message[]>([]);\n const [input, setInput] = useState(\"\");\n const [threadId, setThreadId] = useState<string | undefined>(undefined);\n const [status, setStatus] = useState<AssistantStatus>(\"awaiting_message\");\n const [error, setError] = useState<unknown | undefined>(undefined);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = options.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, options.makeSystemMessage]);\n\n const handleInputChange = (e: any) => {\n setInput(e.target.value);\n };\n\n const submitMessage = async (e: any) => {\n e.preventDefault();\n\n if (input === \"\") {\n return;\n }\n\n setStatus(\"in_progress\");\n\n setMessages((messages) => [...messages, { id: \"\", role: \"user\", content: input }]);\n\n setInput(\"\");\n\n const apiUrl = copilotApiConfig.chatApiEndpointV2;\n\n const functions = getChatCompletionFunctionDescriptions();\n\n const result = await fetch(apiUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotApiConfig.headers,\n ...options.headers,\n },\n body: JSON.stringify({\n // always use user-provided threadId when available:\n threadId: options.threadId ?? threadId ?? null,\n message: input,\n ...(functions.length > 0 && { functions: functions }),\n ...copilotApiConfig.body,\n ...options.body,\n }),\n });\n\n if (result.body == null) {\n throw new Error(\"The response body is empty.\");\n }\n\n await processMessageStream(result.body.getReader(), (message: string) => {\n try {\n const { type, value } = parseStreamPart(message);\n\n switch (type) {\n case \"assistant_message\": {\n // append message:\n setMessages((messages) => [\n ...messages,\n {\n id: value.id,\n role: value.role,\n content: value.content[0].text.value,\n },\n ]);\n break;\n }\n\n case \"assistant_control_data\": {\n setThreadId(value.threadId);\n\n // set id of last message:\n setMessages((messages) => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.id = value.messageId;\n return [...messages.slice(0, messages.length - 1), lastMessage];\n });\n\n break;\n }\n\n case \"error\": {\n setError(value);\n break;\n }\n }\n } catch (error) {\n setError(error);\n }\n });\n\n setStatus(\"awaiting_message\");\n };\n\n return {\n messages,\n input,\n handleInputChange,\n submitMessage,\n status,\n error,\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","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","\"use client\";\n\nimport { FunctionCallHandler, AnnotatedFunction, Function } from \"@copilotkit/shared\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\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: () => 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(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\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(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n","\"use client\";\n\nimport { Function } from \"@copilotkit/shared\";\nimport { useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { DocumentPointer } from \"../../types\";\nimport {\n FunctionCallHandler,\n AnnotatedFunction,\n annotatedFunctionToChatCompletionFunction,\n} from \"@copilotkit/shared\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { StandardCopilotApiConfig } from \"./standard-copilot-api-config\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\n\n/**\n * The CopilotKit 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 * <CopilotKit url=\"https://your.copilotkit.api\">\n * <App />\n * </CopilotKit>\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 * <CopilotKit chatApiConfig={copilotApiConfig}>\n * <App />\n * </CopilotKit>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotKit component.\n */\nexport function CopilotKit({ children, ...props }: CopilotKitProps) {\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 const copilotApiConfig: CopilotApiConfig = new StandardCopilotApiConfig(\n props.url,\n `${props.url}/v2`,\n props.headers || {},\n props.body || {},\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(entryPoints: AnnotatedFunction<any[]>[]): Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA8C;;;ACA9C,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/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ChD,iBAAiB,OACjB,QAAQ,KACZ;AAAA,IACH,CAAC;AAED,QAAI,OAAO,QAAQ,MAAM;AACvB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AAEA,UAAM,qBAAqB,OAAO,KAAK,UAAU,GAAG,CAAC,YAAoB;AACvE,UAAI;AACF,cAAM,EAAE,MAAM,MAAM,QAAI,gCAAgB,OAAO;AAE/C,gBAAQ,MAAM;AAAA,UACZ,KAAK,qBAAqB;AAExB,wBAAY,CAACA,cAAa;AAAA,cACxB,GAAGA;AAAA,cACH;AAAA,gBACE,IAAI,MAAM;AAAA,gBACV,MAAM,MAAM;AAAA,gBACZ,SAAS,MAAM,QAAQ,CAAC,EAAE,KAAK;AAAA,cACjC;AAAA,YACF,CAAC;AACD;AAAA,UACF;AAAA,UAEA,KAAK,0BAA0B;AAC7B,wBAAY,MAAM,QAAQ;AAG1B,wBAAY,CAACA,cAAa;AACxB,oBAAM,cAAcA,UAASA,UAAS,SAAS,CAAC;AAChD,0BAAY,KAAK,MAAM;AACvB,qBAAO,CAAC,GAAGA,UAAS,MAAM,GAAGA,UAAS,SAAS,CAAC,GAAG,WAAW;AAAA,YAChE,CAAC;AAED;AAAA,UACF;AAAA,UAEA,KAAK,SAAS;AACZ,qBAAS,KAAK;AACd;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAASC,QAAP;AACA,iBAASA,MAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAED,cAAU,kBAAkB;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;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;","names":["import_react","import_shared","React","import_react","messages","error"]}
@@ -1,16 +1,23 @@
1
- import '../chunk-7GFKOIO7.mjs';
2
- import '../chunk-BABVSMJR.mjs';
3
- export { useCopilotChatV2 } from '../chunk-VP2EU4US.mjs';
4
- import '../chunk-FRAKUJWH.mjs';
5
- export { processMessageStream } from '../chunk-MZ5UN3BY.mjs';
6
- import '../chunk-VNRDQJXW.mjs';
7
- import '../chunk-JD7BAH7U.mjs';
8
- import '../chunk-SPCZTZCY.mjs';
9
- import '../chunk-GBZZPQ5X.mjs';
10
- import '../chunk-F2JIAPZQ.mjs';
11
- import '../chunk-VUY2K2DI.mjs';
12
- import '../chunk-4CFJ6A6A.mjs';
13
- import '../chunk-YULKJPY3.mjs';
14
- import '../chunk-MRXNTQOX.mjs';
15
- //# sourceMappingURL=out.js.map
1
+ import "../chunk-7GFKOIO7.mjs";
2
+ import "../chunk-BABVSMJR.mjs";
3
+ import {
4
+ useCopilotChatV2
5
+ } from "../chunk-VP2EU4US.mjs";
6
+ import "../chunk-FRAKUJWH.mjs";
7
+ import {
8
+ processMessageStream
9
+ } from "../chunk-MZ5UN3BY.mjs";
10
+ import "../chunk-VNRDQJXW.mjs";
11
+ import "../chunk-JD7BAH7U.mjs";
12
+ import "../chunk-SPCZTZCY.mjs";
13
+ import "../chunk-GBZZPQ5X.mjs";
14
+ import "../chunk-F2JIAPZQ.mjs";
15
+ import "../chunk-VUY2K2DI.mjs";
16
+ import "../chunk-4CFJ6A6A.mjs";
17
+ import "../chunk-YULKJPY3.mjs";
18
+ import "../chunk-MRXNTQOX.mjs";
19
+ export {
20
+ processMessageStream,
21
+ useCopilotChatV2
22
+ };
16
23
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,5 +1,21 @@
1
- 'use strict';
2
-
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
3
19
  var __async = (__this, __arguments, generator) => {
4
20
  return new Promise((resolve, reject) => {
5
21
  var fulfilled = (value) => {
@@ -21,6 +37,13 @@ var __async = (__this, __arguments, generator) => {
21
37
  });
22
38
  };
23
39
 
40
+ // src/openai-assistants/utils/index.ts
41
+ var utils_exports = {};
42
+ __export(utils_exports, {
43
+ processMessageStream: () => processMessageStream
44
+ });
45
+ module.exports = __toCommonJS(utils_exports);
46
+
24
47
  // src/openai-assistants/utils/process-message-stream.ts
25
48
  function processMessageStream(reader, processMessage) {
26
49
  return __async(this, null, function* () {
@@ -43,7 +66,8 @@ function processMessageStream(reader, processMessage) {
43
66
  }
44
67
  });
45
68
  }
46
-
47
- exports.processMessageStream = processMessageStream;
48
- //# sourceMappingURL=out.js.map
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ processMessageStream
72
+ });
49
73
  //# sourceMappingURL=index.js.map
@@ -1 +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"]}
1
+ {"version":3,"sources":["../../../src/openai-assistants/utils/index.ts","../../../src/openai-assistants/utils/process-message-stream.ts"],"sourcesContent":["export { processMessageStream } from \"./process-message-stream\";\n","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;AAAA;AAAA;AAAA;AAAA;;;ACAA,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,5 +1,9 @@
1
- import '../../chunk-FRAKUJWH.mjs';
2
- export { processMessageStream } from '../../chunk-MZ5UN3BY.mjs';
3
- import '../../chunk-MRXNTQOX.mjs';
4
- //# sourceMappingURL=out.js.map
1
+ import "../../chunk-FRAKUJWH.mjs";
2
+ import {
3
+ processMessageStream
4
+ } from "../../chunk-MZ5UN3BY.mjs";
5
+ import "../../chunk-MRXNTQOX.mjs";
6
+ export {
7
+ processMessageStream
8
+ };
5
9
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,5 +1,21 @@
1
- 'use strict';
2
-
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
3
19
  var __async = (__this, __arguments, generator) => {
4
20
  return new Promise((resolve, reject) => {
5
21
  var fulfilled = (value) => {
@@ -22,6 +38,11 @@ var __async = (__this, __arguments, generator) => {
22
38
  };
23
39
 
24
40
  // src/openai-assistants/utils/process-message-stream.ts
41
+ var process_message_stream_exports = {};
42
+ __export(process_message_stream_exports, {
43
+ processMessageStream: () => processMessageStream
44
+ });
45
+ module.exports = __toCommonJS(process_message_stream_exports);
25
46
  function processMessageStream(reader, processMessage) {
26
47
  return __async(this, null, function* () {
27
48
  const decoder = new TextDecoder();
@@ -43,7 +64,8 @@ function processMessageStream(reader, processMessage) {
43
64
  }
44
65
  });
45
66
  }
46
-
47
- exports.processMessageStream = processMessageStream;
48
- //# sourceMappingURL=out.js.map
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ processMessageStream
70
+ });
49
71
  //# sourceMappingURL=process-message-stream.js.map
@@ -1 +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"]}
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;AAAA;AAAA;AAAA;AAAA;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,8 @@
1
- export { processMessageStream } from '../../chunk-MZ5UN3BY.mjs';
2
- import '../../chunk-MRXNTQOX.mjs';
3
- //# sourceMappingURL=out.js.map
1
+ import {
2
+ processMessageStream
3
+ } from "../../chunk-MZ5UN3BY.mjs";
4
+ import "../../chunk-MRXNTQOX.mjs";
5
+ export {
6
+ processMessageStream
7
+ };
4
8
  //# sourceMappingURL=process-message-stream.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,19 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
15
 
3
- //# sourceMappingURL=out.js.map
16
+ // src/types/document-pointer.ts
17
+ var document_pointer_exports = {};
18
+ module.exports = __toCommonJS(document_pointer_exports);
4
19
  //# sourceMappingURL=document-pointer.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../../src/types/document-pointer.ts"],"sourcesContent":["export interface DocumentPointer {\n id: string;\n name: string;\n sourceApplication: string;\n iconImageUri: string;\n getContents: () => string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","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,4 +1,19 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
15
 
3
- //# sourceMappingURL=out.js.map
16
+ // src/types/index.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
4
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export type { DocumentPointer } from \"./document-pointer\";\nexport type { SystemMessageFunction } from \"./system-message\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,3 +1,2 @@
1
- import '../chunk-EFZPSZWO.mjs';
2
- //# sourceMappingURL=out.js.map
1
+ import "../chunk-EFZPSZWO.mjs";
3
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,19 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
15
 
3
- //# sourceMappingURL=out.js.map
16
+ // src/types/system-message.ts
17
+ var system_message_exports = {};
18
+ module.exports = __toCommonJS(system_message_exports);
4
19
  //# sourceMappingURL=system-message.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../../src/types/system-message.ts"],"sourcesContent":["export type SystemMessageFunction = (\n contextString: string,\n additionalInstructions?: string,\n) => string;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
1
  //# sourceMappingURL=system-message.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}