@copilotkit/react-core 0.8.0-alpha.6 → 0.9.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 (66) hide show
  1. package/.turbo/turbo-build.log +88 -88
  2. package/CHANGELOG.md +22 -0
  3. package/dist/chunk-3BOHSSKR.mjs +141 -0
  4. package/dist/chunk-3BOHSSKR.mjs.map +1 -0
  5. package/dist/chunk-3O374DDN.mjs +19 -0
  6. package/dist/chunk-3O374DDN.mjs.map +1 -0
  7. package/dist/chunk-63ILXW5V.mjs +76 -0
  8. package/dist/chunk-63ILXW5V.mjs.map +1 -0
  9. package/dist/chunk-6RRG7ME3.mjs +19 -0
  10. package/dist/chunk-6RRG7ME3.mjs.map +1 -0
  11. package/dist/chunk-EFZPSZWO.mjs +3 -0
  12. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  13. package/dist/chunk-JD7BAH7U.mjs +3 -0
  14. package/dist/chunk-JD7BAH7U.mjs.map +1 -0
  15. package/dist/chunk-K7TVQCXG.mjs +44 -0
  16. package/dist/chunk-K7TVQCXG.mjs.map +1 -0
  17. package/dist/chunk-MRXNTQOX.mjs +55 -0
  18. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  19. package/dist/chunk-Q6E6JSLL.mjs +149 -0
  20. package/dist/chunk-Q6E6JSLL.mjs.map +1 -0
  21. package/dist/chunk-QACD2U6P.mjs +3 -0
  22. package/dist/chunk-QACD2U6P.mjs.map +1 -0
  23. package/dist/chunk-UNFDVVCF.mjs +80 -0
  24. package/dist/chunk-UNFDVVCF.mjs.map +1 -0
  25. package/dist/chunk-YPSGKPDA.mjs +3 -0
  26. package/dist/chunk-YPSGKPDA.mjs.map +1 -0
  27. package/dist/chunk-YTIZQV7H.mjs +30 -0
  28. package/dist/chunk-YTIZQV7H.mjs.map +1 -0
  29. package/dist/components/copilot-provider.d.ts +2 -8
  30. package/dist/components/copilot-provider.mjs +6 -442
  31. package/dist/components/copilot-provider.mjs.map +1 -1
  32. package/dist/components/index.d.ts +0 -6
  33. package/dist/components/index.mjs +7 -442
  34. package/dist/components/index.mjs.map +1 -1
  35. package/dist/context/copilot-context.mjs +3 -67
  36. package/dist/context/copilot-context.mjs.map +1 -1
  37. package/dist/context/index.mjs +4 -67
  38. package/dist/context/index.mjs.map +1 -1
  39. package/dist/hooks/index.mjs +8 -220
  40. package/dist/hooks/index.mjs.map +1 -1
  41. package/dist/hooks/use-copilot-chat.mjs +4 -159
  42. package/dist/hooks/use-copilot-chat.mjs.map +1 -1
  43. package/dist/hooks/use-flat-category-store.mjs +3 -74
  44. package/dist/hooks/use-flat-category-store.mjs.map +1 -1
  45. package/dist/hooks/use-make-copilot-actionable.mjs +4 -88
  46. package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
  47. package/dist/hooks/use-make-copilot-document-readable.mjs +4 -77
  48. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
  49. package/dist/hooks/use-make-copilot-readable.mjs +4 -77
  50. package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
  51. package/dist/hooks/use-tree.mjs +3 -159
  52. package/dist/hooks/use-tree.mjs.map +1 -1
  53. package/dist/index.mjs +14 -589
  54. package/dist/index.mjs.map +1 -1
  55. package/dist/types/annotated-function.mjs +2 -0
  56. package/dist/types/annotated-function.mjs.map +1 -1
  57. package/dist/types/document-pointer.mjs +2 -0
  58. package/dist/types/document-pointer.mjs.map +1 -1
  59. package/dist/types/index.mjs +2 -0
  60. package/dist/types/index.mjs.map +1 -1
  61. package/dist/utils/utils.mjs +2 -0
  62. package/dist/utils/utils.mjs.map +1 -1
  63. package/dist/utils/utils.test.mjs +1 -0
  64. package/dist/utils/utils.test.mjs.map +1 -1
  65. package/package.json +2 -2
  66. package/src/components/copilot-provider.tsx +5 -3
@@ -1,221 +1,9 @@
1
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2
- var __hasOwnProp = Object.prototype.hasOwnProperty;
3
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
4
- var __objRest = (source, exclude) => {
5
- var target = {};
6
- for (var prop in source)
7
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
8
- target[prop] = source[prop];
9
- if (source != null && __getOwnPropSymbols)
10
- for (var prop of __getOwnPropSymbols(source)) {
11
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
12
- target[prop] = source[prop];
13
- }
14
- return target;
15
- };
16
- var __async = (__this, __arguments, generator) => {
17
- return new Promise((resolve, reject) => {
18
- var fulfilled = (value) => {
19
- try {
20
- step(generator.next(value));
21
- } catch (e) {
22
- reject(e);
23
- }
24
- };
25
- var rejected = (value) => {
26
- try {
27
- step(generator.throw(value));
28
- } catch (e) {
29
- reject(e);
30
- }
31
- };
32
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
33
- step((generator = generator.apply(__this, __arguments)).next());
34
- });
35
- };
36
-
37
- // src/hooks/use-copilot-chat.ts
38
- import { useMemo, useContext } from "react";
39
-
40
- // src/context/copilot-context.tsx
41
- import React from "react";
42
- "use client";
43
- function copilotApiConfigExtrapolator(config) {
44
- return {
45
- get chatApiEndpoint() {
46
- return `${config.chatApiEndpoint}`;
47
- }
48
- };
49
- }
50
- var emptyCopilotContext = {
51
- entryPoints: {},
52
- setEntryPoint: () => {
53
- },
54
- removeEntryPoint: () => {
55
- },
56
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
57
- getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
58
- })),
59
- getContextString: () => returnAndThrowInDebug(""),
60
- addContext: () => "",
61
- removeContext: () => {
62
- },
63
- getDocumentsContext: () => returnAndThrowInDebug([]),
64
- addDocumentContext: () => returnAndThrowInDebug(""),
65
- removeDocumentContext: () => {
66
- },
67
- copilotApiConfig: new class {
68
- get chatApiEndpoint() {
69
- throw new Error(
70
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
71
- );
72
- }
73
- }()
74
- };
75
- var CopilotContext = React.createContext(emptyCopilotContext);
76
- function returnAndThrowInDebug(value) {
77
- throw new Error(
78
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
79
- );
80
- return value;
81
- }
82
-
83
- // src/hooks/use-copilot-chat.ts
84
- import { useChat } from "ai/react";
85
- function useCopilotChat(_a) {
86
- var _b = _a, {
87
- makeSystemMessage
88
- } = _b, options = __objRest(_b, [
89
- "makeSystemMessage"
90
- ]);
91
- const {
92
- getContextString,
93
- getChatCompletionFunctionDescriptions,
94
- getFunctionCallHandler,
95
- copilotApiConfig
96
- } = useContext(CopilotContext);
97
- const systemMessage = useMemo(() => {
98
- const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
99
- const contextString = getContextString();
100
- return {
101
- id: "system",
102
- content: systemMessageMaker(contextString),
103
- role: "system"
104
- };
105
- }, [getContextString, makeSystemMessage]);
106
- const initialMessagesWithContext = [systemMessage].concat(
107
- options.initialMessages || []
108
- );
109
- const functionDescriptions = useMemo(() => {
110
- return getChatCompletionFunctionDescriptions();
111
- }, [getChatCompletionFunctionDescriptions]);
112
- const { messages, append, reload, stop, isLoading, input, setInput } = useChat({
113
- api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
114
- id: options.id,
115
- initialMessages: initialMessagesWithContext,
116
- experimental_onFunctionCall: getFunctionCallHandler(),
117
- body: {
118
- id: options.id,
119
- functions: functionDescriptions
120
- }
121
- });
122
- const visibleMessages = messages.filter(
123
- (message) => message.role === "user" || message.role === "assistant"
124
- );
125
- return {
126
- visibleMessages,
127
- append,
128
- reload,
129
- stop,
130
- isLoading,
131
- input,
132
- setInput
133
- };
134
- }
135
- function defaultSystemMessage(contextString) {
136
- return `
137
- Please act as an efficient, competent, conscientious, and industrious professional assistant.
138
-
139
- 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.
140
- Always be polite and respectful, and prefer brevity over verbosity.
141
-
142
- The user has provided you with the following context:
143
- \`\`\`
144
- ${contextString}
145
- \`\`\`
146
-
147
- 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.
148
-
149
- Please assist them as best you can.
150
-
151
- 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.
152
-
153
- If you would like to call a function, call it without saying anything else.
154
- `;
155
- }
156
-
157
- // src/hooks/use-make-copilot-actionable.ts
158
- import { useRef, useContext as useContext2, useEffect, useMemo as useMemo2 } from "react";
159
- import { nanoid } from "nanoid";
160
- "use client";
161
- function useMakeCopilotActionable(annotatedFunction, dependencies) {
162
- const idRef = useRef(nanoid());
163
- const { setEntryPoint, removeEntryPoint } = useContext2(CopilotContext);
164
- const memoizedAnnotatedFunction = useMemo2(
165
- () => ({
166
- name: annotatedFunction.name,
167
- description: annotatedFunction.description,
168
- argumentAnnotations: annotatedFunction.argumentAnnotations,
169
- implementation: annotatedFunction.implementation
170
- }),
171
- dependencies
172
- );
173
- useEffect(() => {
174
- setEntryPoint(
175
- idRef.current,
176
- memoizedAnnotatedFunction
177
- );
178
- return () => {
179
- removeEntryPoint(idRef.current);
180
- };
181
- }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
182
- }
183
-
184
- // src/hooks/use-make-copilot-readable.ts
185
- import { useContext as useContext3, useEffect as useEffect2, useRef as useRef2 } from "react";
186
- "use client";
187
- function useMakeCopilotReadable(information, parentId, categories) {
188
- const { addContext, removeContext } = useContext3(CopilotContext);
189
- const idRef = useRef2();
190
- useEffect2(() => {
191
- const id = addContext(information, parentId, categories);
192
- idRef.current = id;
193
- return () => {
194
- removeContext(id);
195
- };
196
- }, [information, parentId, addContext, removeContext]);
197
- return idRef.current;
198
- }
199
-
200
- // src/hooks/use-make-copilot-document-readable.ts
201
- import { useContext as useContext4, useEffect as useEffect3, useRef as useRef3 } from "react";
202
- "use client";
203
- function useMakeCopilotDocumentReadable(document, categories) {
204
- const { addDocumentContext, removeDocumentContext } = useContext4(CopilotContext);
205
- const idRef = useRef3();
206
- useEffect3(() => {
207
- const id = addDocumentContext(document, categories);
208
- idRef.current = id;
209
- return () => {
210
- removeDocumentContext(id);
211
- };
212
- }, [document, categories, addDocumentContext, removeDocumentContext]);
213
- return idRef.current;
214
- }
215
- export {
216
- useCopilotChat,
217
- useMakeCopilotActionable,
218
- useMakeCopilotDocumentReadable,
219
- useMakeCopilotReadable
220
- };
1
+ import '../chunk-QACD2U6P.mjs';
2
+ export { useMakeCopilotActionable } from '../chunk-YTIZQV7H.mjs';
3
+ export { useMakeCopilotDocumentReadable } from '../chunk-6RRG7ME3.mjs';
4
+ export { useMakeCopilotReadable } from '../chunk-3O374DDN.mjs';
5
+ export { useCopilotChat } from '../chunk-UNFDVVCF.mjs';
6
+ import '../chunk-K7TVQCXG.mjs';
7
+ import '../chunk-MRXNTQOX.mjs';
8
+ //# sourceMappingURL=out.js.map
221
9
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-copilot-chat.ts","../../src/context/copilot-context.tsx","../../src/hooks/use-make-copilot-actionable.ts","../../src/hooks/use-make-copilot-readable.ts","../../src/hooks/use-make-copilot-document-readable.ts"],"sourcesContent":["import { useMemo, useContext } from \"react\";\nimport {\n CopilotContext,\n CopilotContextParams,\n copilotApiConfigExtrapolator,\n} from \"../context/copilot-context\";\nimport { useChat } from \"ai/react\";\nimport { ChatRequestOptions, CreateMessage, Message } from \"ai\";\nimport { UseChatOptions } from \"ai\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: (contextString: string) => string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (\n message: Message | CreateMessage,\n chatRequestOptions?: ChatRequestOptions\n ) => Promise<string | null | undefined>;\n reload: (\n chatRequestOptions?: ChatRequestOptions\n ) => Promise<string | null | undefined>;\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();\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, makeSystemMessage]);\n\n const initialMessagesWithContext = [systemMessage].concat(\n options.initialMessages || []\n );\n\n const functionDescriptions = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } =\n useChat({\n api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,\n id: options.id,\n initialMessages: initialMessagesWithContext,\n experimental_onFunctionCall: getFunctionCallHandler(),\n body: {\n id: options.id,\n functions: functionDescriptions,\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","\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\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\nexport interface CopilotApiConfig {\n chatApiEndpoint: string;\n}\n\nexport function copilotApiConfigExtrapolator(config: CopilotApiConfig) {\n return {\n get chatApiEndpoint(): string {\n return `${config.chatApiEndpoint}`;\n },\n };\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 getContextString: (categories?: string[]) => string;\n addContext: (\n context: string,\n parentId?: string,\n categories?: string[]\n ) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories?: string[]) => DocumentPointer[];\n addDocumentContext: (\n documentPointer: DocumentPointer,\n categories?: string[]\n ) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\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: () => returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: () => 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 })(),\n};\n\nexport const CopilotContext =\n 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","\"use client\";\n\nimport { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { nanoid } from \"nanoid\";\n\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[]\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies\n );\n\n useEffect(() => {\n setEntryPoint(\n idRef.current,\n memoizedAnnotatedFunction as AnnotatedFunction<any[]>\n );\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n","\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n * @param information - The information to be added to the Copilot context.\n * @param parentId - The ID of the parent context, if any.\n * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n * @returns The ID of the added context.\n */\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string,\n categories?: string[]\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n","\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n * @param information - The information to be added to the Copilot context.\n * @param parentId - The ID of the parent context, if any.\n * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n * @returns The ID of the added context.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[]\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } =\n 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 }, [document, categories, addDocumentContext, removeDocumentContext]);\n\n return idRef.current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;;;ACGpC,OAAO,WAAW;AAHlB;AAaO,SAAS,6BAA6B,QAA0B;AACrE,SAAO;AAAA,IACL,IAAI,kBAA0B;AAC5B,aAAO,GAAG,OAAO;AAAA,IACnB;AAAA,EACF;AACF;AA+BA,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,MAAM,sBAAsB,EAAE;AAAA,EAChD,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACnD,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI;AAAA,QAC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oB;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAChDC,YAAW,cAAc;AAC3B,QAAM,QAAQC,QAAe;AAE7B,EAAAC,WAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,UAAU,YAAY,oBAAoB,qBAAqB,CAAC;AAEpE,SAAO,MAAM;AACf;","names":["useContext","useMemo","useContext","useMemo","useContext","useEffect","useRef","useContext","useRef","useEffect","useContext","useEffect","useRef","useContext","useRef","useEffect"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,160 +1,5 @@
1
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2
- var __hasOwnProp = Object.prototype.hasOwnProperty;
3
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
4
- var __objRest = (source, exclude) => {
5
- var target = {};
6
- for (var prop in source)
7
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
8
- target[prop] = source[prop];
9
- if (source != null && __getOwnPropSymbols)
10
- for (var prop of __getOwnPropSymbols(source)) {
11
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
12
- target[prop] = source[prop];
13
- }
14
- return target;
15
- };
16
- var __async = (__this, __arguments, generator) => {
17
- return new Promise((resolve, reject) => {
18
- var fulfilled = (value) => {
19
- try {
20
- step(generator.next(value));
21
- } catch (e) {
22
- reject(e);
23
- }
24
- };
25
- var rejected = (value) => {
26
- try {
27
- step(generator.throw(value));
28
- } catch (e) {
29
- reject(e);
30
- }
31
- };
32
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
33
- step((generator = generator.apply(__this, __arguments)).next());
34
- });
35
- };
36
-
37
- // src/hooks/use-copilot-chat.ts
38
- import { useMemo, useContext } from "react";
39
-
40
- // src/context/copilot-context.tsx
41
- import React from "react";
42
- "use client";
43
- function copilotApiConfigExtrapolator(config) {
44
- return {
45
- get chatApiEndpoint() {
46
- return `${config.chatApiEndpoint}`;
47
- }
48
- };
49
- }
50
- var emptyCopilotContext = {
51
- entryPoints: {},
52
- setEntryPoint: () => {
53
- },
54
- removeEntryPoint: () => {
55
- },
56
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
57
- getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
58
- })),
59
- getContextString: () => returnAndThrowInDebug(""),
60
- addContext: () => "",
61
- removeContext: () => {
62
- },
63
- getDocumentsContext: () => returnAndThrowInDebug([]),
64
- addDocumentContext: () => returnAndThrowInDebug(""),
65
- removeDocumentContext: () => {
66
- },
67
- copilotApiConfig: new class {
68
- get chatApiEndpoint() {
69
- throw new Error(
70
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
71
- );
72
- }
73
- }()
74
- };
75
- var CopilotContext = React.createContext(emptyCopilotContext);
76
- function returnAndThrowInDebug(value) {
77
- throw new Error(
78
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
79
- );
80
- return value;
81
- }
82
-
83
- // src/hooks/use-copilot-chat.ts
84
- import { useChat } from "ai/react";
85
- function useCopilotChat(_a) {
86
- var _b = _a, {
87
- makeSystemMessage
88
- } = _b, options = __objRest(_b, [
89
- "makeSystemMessage"
90
- ]);
91
- const {
92
- getContextString,
93
- getChatCompletionFunctionDescriptions,
94
- getFunctionCallHandler,
95
- copilotApiConfig
96
- } = useContext(CopilotContext);
97
- const systemMessage = useMemo(() => {
98
- const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
99
- const contextString = getContextString();
100
- return {
101
- id: "system",
102
- content: systemMessageMaker(contextString),
103
- role: "system"
104
- };
105
- }, [getContextString, makeSystemMessage]);
106
- const initialMessagesWithContext = [systemMessage].concat(
107
- options.initialMessages || []
108
- );
109
- const functionDescriptions = useMemo(() => {
110
- return getChatCompletionFunctionDescriptions();
111
- }, [getChatCompletionFunctionDescriptions]);
112
- const { messages, append, reload, stop, isLoading, input, setInput } = useChat({
113
- api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
114
- id: options.id,
115
- initialMessages: initialMessagesWithContext,
116
- experimental_onFunctionCall: getFunctionCallHandler(),
117
- body: {
118
- id: options.id,
119
- functions: functionDescriptions
120
- }
121
- });
122
- const visibleMessages = messages.filter(
123
- (message) => message.role === "user" || message.role === "assistant"
124
- );
125
- return {
126
- visibleMessages,
127
- append,
128
- reload,
129
- stop,
130
- isLoading,
131
- input,
132
- setInput
133
- };
134
- }
135
- function defaultSystemMessage(contextString) {
136
- return `
137
- Please act as an efficient, competent, conscientious, and industrious professional assistant.
138
-
139
- 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.
140
- Always be polite and respectful, and prefer brevity over verbosity.
141
-
142
- The user has provided you with the following context:
143
- \`\`\`
144
- ${contextString}
145
- \`\`\`
146
-
147
- 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.
148
-
149
- Please assist them as best you can.
150
-
151
- 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.
152
-
153
- If you would like to call a function, call it without saying anything else.
154
- `;
155
- }
156
- export {
157
- defaultSystemMessage,
158
- useCopilotChat
159
- };
1
+ export { defaultSystemMessage, useCopilotChat } from '../chunk-UNFDVVCF.mjs';
2
+ import '../chunk-K7TVQCXG.mjs';
3
+ import '../chunk-MRXNTQOX.mjs';
4
+ //# sourceMappingURL=out.js.map
160
5
  //# sourceMappingURL=use-copilot-chat.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-copilot-chat.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useMemo, useContext } from \"react\";\nimport {\n CopilotContext,\n CopilotContextParams,\n copilotApiConfigExtrapolator,\n} from \"../context/copilot-context\";\nimport { useChat } from \"ai/react\";\nimport { ChatRequestOptions, CreateMessage, Message } from \"ai\";\nimport { UseChatOptions } from \"ai\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: (contextString: string) => string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (\n message: Message | CreateMessage,\n chatRequestOptions?: ChatRequestOptions\n ) => Promise<string | null | undefined>;\n reload: (\n chatRequestOptions?: ChatRequestOptions\n ) => Promise<string | null | undefined>;\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();\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, makeSystemMessage]);\n\n const initialMessagesWithContext = [systemMessage].concat(\n options.initialMessages || []\n );\n\n const functionDescriptions = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } =\n useChat({\n api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,\n id: options.id,\n initialMessages: initialMessagesWithContext,\n experimental_onFunctionCall: getFunctionCallHandler(),\n body: {\n id: options.id,\n functions: functionDescriptions,\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","\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\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\nexport interface CopilotApiConfig {\n chatApiEndpoint: string;\n}\n\nexport function copilotApiConfigExtrapolator(config: CopilotApiConfig) {\n return {\n get chatApiEndpoint(): string {\n return `${config.chatApiEndpoint}`;\n },\n };\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 getContextString: (categories?: string[]) => string;\n addContext: (\n context: string,\n parentId?: string,\n categories?: string[]\n ) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories?: string[]) => DocumentPointer[];\n addDocumentContext: (\n documentPointer: DocumentPointer,\n categories?: string[]\n ) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\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: () => returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: () => 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 })(),\n};\n\nexport const CopilotContext =\n 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;;;ACGpC,OAAO,WAAW;AAHlB;AAaO,SAAS,6BAA6B,QAA0B;AACrE,SAAO;AAAA,IACL,IAAI,kBAA0B;AAC5B,aAAO,GAAG,OAAO;AAAA,IACnB;AAAA,EACF;AACF;AA+BA,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,MAAM,sBAAsB,EAAE;AAAA,EAChD,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACnD,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,EACF,EAAG;AACL;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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":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,75 +1,4 @@
1
- // src/hooks/use-flat-category-store.ts
2
- import { nanoid } from "nanoid";
3
- import { useCallback, useReducer } from "react";
4
- var useFlatCategoryStore = () => {
5
- const [elements, dispatch] = useReducer(
6
- flatCategoryStoreReducer,
7
- /* @__PURE__ */ new Map()
8
- );
9
- const addElement = useCallback(
10
- (value, categories) => {
11
- const newId = nanoid();
12
- dispatch({
13
- type: "ADD_ELEMENT",
14
- value,
15
- id: newId,
16
- categories
17
- });
18
- return newId;
19
- },
20
- []
21
- );
22
- const removeElement = useCallback((id) => {
23
- dispatch({ type: "REMOVE_ELEMENT", id });
24
- }, []);
25
- const allElements = useCallback(
26
- (categories) => {
27
- const categoriesSet = new Set(categories);
28
- const result = [];
29
- elements.forEach((element) => {
30
- if (setsHaveIntersection(categoriesSet, element.categories)) {
31
- result.push(element.value);
32
- }
33
- });
34
- return result;
35
- },
36
- [elements]
37
- );
38
- return { addElement, removeElement, allElements };
39
- };
40
- var use_flat_category_store_default = useFlatCategoryStore;
41
- function flatCategoryStoreReducer(state, action) {
42
- switch (action.type) {
43
- case "ADD_ELEMENT": {
44
- const { value, id, categories } = action;
45
- const newElement = {
46
- id,
47
- value,
48
- categories: new Set(categories)
49
- };
50
- const newState = new Map(state);
51
- newState.set(id, newElement);
52
- return newState;
53
- }
54
- case "REMOVE_ELEMENT": {
55
- const newState = new Map(state);
56
- newState.delete(action.id);
57
- return newState;
58
- }
59
- default:
60
- return state;
61
- }
62
- }
63
- function setsHaveIntersection(setA, setB) {
64
- const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
65
- for (let item of smallerSet) {
66
- if (largerSet.has(item)) {
67
- return true;
68
- }
69
- }
70
- return false;
71
- }
72
- export {
73
- use_flat_category_store_default as default
74
- };
1
+ export { use_flat_category_store_default as default } from '../chunk-63ILXW5V.mjs';
2
+ import '../chunk-MRXNTQOX.mjs';
3
+ //# sourceMappingURL=out.js.map
75
4
  //# sourceMappingURL=use-flat-category-store.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-flat-category-store.ts"],"sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type FlatCategoryStoreId = string;\n\nexport interface UseFlatCategoryStoreReturn<T> {\n addElement: (value: T, categories: string[]) => FlatCategoryStoreId;\n removeElement: (id: FlatCategoryStoreId) => void;\n allElements: (categories: string[]) => T[];\n}\n\ninterface FlatCategoryStoreElement<T> {\n id: FlatCategoryStoreId;\n value: T;\n categories: Set<string>;\n}\n\nconst useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {\n const [elements, dispatch] = useReducer<\n React.Reducer<\n Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n Action<T>\n >\n >(\n flatCategoryStoreReducer,\n new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>()\n );\n\n const addElement = useCallback(\n (value: T, categories: string[]): FlatCategoryStoreId => {\n const newId = nanoid();\n dispatch({\n type: \"ADD_ELEMENT\",\n value,\n id: newId,\n categories,\n });\n return newId;\n },\n []\n );\n\n const removeElement = useCallback((id: FlatCategoryStoreId): void => {\n dispatch({ type: \"REMOVE_ELEMENT\", id });\n }, []);\n\n const allElements = useCallback(\n (categories: string[]): T[] => {\n const categoriesSet = new Set(categories);\n const result: T[] = [];\n elements.forEach((element) => {\n if (setsHaveIntersection(categoriesSet, element.categories)) {\n result.push(element.value);\n }\n });\n return result;\n },\n [elements]\n );\n\n return { addElement, removeElement, allElements };\n};\n\nexport default useFlatCategoryStore;\n\n// Action types\ntype Action<T> =\n | {\n type: \"ADD_ELEMENT\";\n value: T;\n id: FlatCategoryStoreId;\n categories: string[];\n }\n | { type: \"REMOVE_ELEMENT\"; id: FlatCategoryStoreId };\n\n// Reducer\nfunction flatCategoryStoreReducer<T>(\n state: Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n action: Action<T>\n): Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>> {\n switch (action.type) {\n case \"ADD_ELEMENT\": {\n const { value, id, categories } = action;\n const newElement: FlatCategoryStoreElement<T> = {\n id,\n value,\n categories: new Set(categories),\n };\n const newState = new Map(state);\n newState.set(id, newElement);\n return newState;\n }\n case \"REMOVE_ELEMENT\": {\n const newState = new Map(state);\n newState.delete(action.id);\n return newState;\n }\n default:\n return state;\n }\n}\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAgBxC,IAAM,uBAAuB,MAAwC;AACnE,QAAM,CAAC,UAAU,QAAQ,IAAI;AAAA,IAM3B;AAAA,IACA,oBAAI,IAAsD;AAAA,EAC5D;AAEA,QAAM,aAAa;AAAA,IACjB,CAAC,OAAU,eAA8C;AACvD,YAAM,QAAQ,OAAO;AACrB,eAAS;AAAA,QACP,MAAM;AAAA,QACN;AAAA,QACA,IAAI;AAAA,QACJ;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,gBAAgB,YAAY,CAAC,OAAkC;AACnE,aAAS,EAAE,MAAM,kBAAkB,GAAG,CAAC;AAAA,EACzC,GAAG,CAAC,CAAC;AAEL,QAAM,cAAc;AAAA,IAClB,CAAC,eAA8B;AAC7B,YAAM,gBAAgB,IAAI,IAAI,UAAU;AACxC,YAAM,SAAc,CAAC;AACrB,eAAS,QAAQ,CAAC,YAAY;AAC5B,YAAI,qBAAqB,eAAe,QAAQ,UAAU,GAAG;AAC3D,iBAAO,KAAK,QAAQ,KAAK;AAAA,QAC3B;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,SAAO,EAAE,YAAY,eAAe,YAAY;AAClD;AAEA,IAAO,kCAAQ;AAaf,SAAS,yBACP,OACA,QACuD;AACvD,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,eAAe;AAClB,YAAM,EAAE,OAAO,IAAI,WAAW,IAAI;AAClC,YAAM,aAA0C;AAAA,QAC9C;AAAA,QACA;AAAA,QACA,YAAY,IAAI,IAAI,UAAU;AAAA,MAChC;AACA,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,IAAI,IAAI,UAAU;AAC3B,aAAO;AAAA,IACT;AAAA,IACA,KAAK,kBAAkB;AACrB,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,OAAO,OAAO,EAAE;AACzB,aAAO;AAAA,IACT;AAAA,IACA;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,qBAAwB,MAAc,MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAC1B,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAErD,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,89 +1,5 @@
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/hooks/use-make-copilot-actionable.ts
23
- import { useRef, useContext, useEffect, useMemo } from "react";
24
-
25
- // src/context/copilot-context.tsx
26
- import React from "react";
27
- "use client";
28
- var emptyCopilotContext = {
29
- entryPoints: {},
30
- setEntryPoint: () => {
31
- },
32
- removeEntryPoint: () => {
33
- },
34
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
35
- getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
36
- })),
37
- getContextString: () => returnAndThrowInDebug(""),
38
- addContext: () => "",
39
- removeContext: () => {
40
- },
41
- getDocumentsContext: () => returnAndThrowInDebug([]),
42
- addDocumentContext: () => returnAndThrowInDebug(""),
43
- removeDocumentContext: () => {
44
- },
45
- copilotApiConfig: new class {
46
- get chatApiEndpoint() {
47
- throw new Error(
48
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
49
- );
50
- }
51
- }()
52
- };
53
- var CopilotContext = React.createContext(emptyCopilotContext);
54
- function returnAndThrowInDebug(value) {
55
- throw new Error(
56
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
57
- );
58
- return value;
59
- }
60
-
61
- // src/hooks/use-make-copilot-actionable.ts
62
- import { nanoid } from "nanoid";
63
- "use client";
64
- function useMakeCopilotActionable(annotatedFunction, dependencies) {
65
- const idRef = useRef(nanoid());
66
- const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);
67
- const memoizedAnnotatedFunction = useMemo(
68
- () => ({
69
- name: annotatedFunction.name,
70
- description: annotatedFunction.description,
71
- argumentAnnotations: annotatedFunction.argumentAnnotations,
72
- implementation: annotatedFunction.implementation
73
- }),
74
- dependencies
75
- );
76
- useEffect(() => {
77
- setEntryPoint(
78
- idRef.current,
79
- memoizedAnnotatedFunction
80
- );
81
- return () => {
82
- removeEntryPoint(idRef.current);
83
- };
84
- }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
85
- }
86
- export {
87
- useMakeCopilotActionable
88
- };
1
+ export { useMakeCopilotActionable } from '../chunk-YTIZQV7H.mjs';
2
+ import '../chunk-K7TVQCXG.mjs';
3
+ import '../chunk-MRXNTQOX.mjs';
4
+ //# sourceMappingURL=out.js.map
89
5
  //# sourceMappingURL=use-make-copilot-actionable.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-make-copilot-actionable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["\"use client\";\n\nimport { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { nanoid } from \"nanoid\";\n\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[]\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies\n );\n\n useEffect(() => {\n setEntryPoint(\n idRef.current,\n memoizedAnnotatedFunction as AnnotatedFunction<any[]>\n );\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n","\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\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\nexport interface CopilotApiConfig {\n chatApiEndpoint: string;\n}\n\nexport function copilotApiConfigExtrapolator(config: CopilotApiConfig) {\n return {\n get chatApiEndpoint(): string {\n return `${config.chatApiEndpoint}`;\n },\n };\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 getContextString: (categories?: string[]) => string;\n addContext: (\n context: string,\n parentId?: string,\n categories?: string[]\n ) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories?: string[]) => DocumentPointer[];\n addDocumentContext: (\n documentPointer: DocumentPointer,\n categories?: string[]\n ) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\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: () => returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: () => 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 })(),\n};\n\nexport const CopilotContext =\n 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,QAAQ,YAAY,WAAW,eAAe;;;ACCvD,OAAO,WAAW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