@copilotkit/react-core 0.14.0 → 0.15.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +141 -88
- package/CHANGELOG.md +22 -0
- package/dist/components/copilot-provider/copilot-provider-props.d.ts +50 -0
- package/dist/components/copilot-provider/copilot-provider-props.mjs +2 -0
- package/dist/components/copilot-provider/copilot-provider-props.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-provider.d.ts +45 -0
- package/dist/components/copilot-provider/copilot-provider.mjs +469 -0
- package/dist/components/copilot-provider/copilot-provider.mjs.map +1 -0
- package/dist/components/copilot-provider/index.d.ts +9 -0
- package/dist/components/copilot-provider/index.mjs +468 -0
- package/dist/components/copilot-provider/index.mjs.map +1 -0
- package/dist/components/copilot-provider/standard-cpilot-api-config.d.ts +24 -0
- package/dist/components/copilot-provider/standard-cpilot-api-config.mjs +13 -0
- package/dist/components/copilot-provider/standard-cpilot-api-config.mjs.map +1 -0
- package/dist/components/index.d.ts +8 -1
- package/dist/components/index.mjs +467 -7
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.d.ts +5 -0
- package/dist/context/copilot-context.mjs +81 -3
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.mjs +80 -4
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.mjs +249 -12
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +194 -8
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +68 -3
- package/dist/hooks/use-flat-category-store.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +95 -4
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +87 -4
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +87 -4
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
- package/dist/hooks/use-tree.mjs +153 -3
- package/dist/hooks/use-tree.mjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +755 -14
- package/dist/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/index.d.ts +2 -0
- package/dist/openai-assistants/hooks/index.mjs +246 -0
- package/dist/openai-assistants/hooks/index.mjs.map +1 -0
- package/dist/openai-assistants/hooks/use-assistants.d.ts +17 -0
- package/dist/openai-assistants/hooks/use-assistants.mjs +131 -0
- package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.d.ts +44 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +247 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -0
- package/dist/openai-assistants/index.d.ts +3 -0
- package/dist/openai-assistants/index.mjs +247 -0
- package/dist/openai-assistants/index.mjs.map +1 -0
- package/dist/openai-assistants/utils/index.d.ts +1 -0
- package/dist/openai-assistants/utils/index.mjs +47 -0
- package/dist/openai-assistants/utils/index.mjs.map +1 -0
- package/dist/openai-assistants/utils/process-message-stream.d.ts +3 -0
- package/dist/openai-assistants/utils/process-message-stream.mjs +47 -0
- package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -0
- package/dist/types/annotated-function.mjs +0 -2
- package/dist/types/annotated-function.mjs.map +1 -1
- package/dist/types/document-pointer.mjs +0 -2
- package/dist/types/document-pointer.mjs.map +1 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.mjs +0 -2
- package/dist/utils/utils.mjs.map +1 -1
- package/dist/utils/utils.test.d.ts +1 -0
- package/dist/utils/utils.test.mjs +0 -1
- package/dist/utils/utils.test.mjs.map +1 -1
- package/package.json +8 -7
- package/src/components/copilot-provider/copilot-provider-props.tsx +50 -0
- package/src/components/{copilot-provider.tsx → copilot-provider/copilot-provider.tsx} +60 -23
- package/src/components/copilot-provider/index.ts +7 -0
- package/src/components/copilot-provider/standard-cpilot-api-config.tsx +28 -0
- package/src/components/index.ts +1 -1
- package/src/context/copilot-context.tsx +13 -0
- package/src/hooks/use-copilot-chat.ts +1 -1
- package/src/index.tsx +1 -0
- package/src/openai-assistants/hooks/index.ts +9 -0
- package/src/openai-assistants/hooks/use-assistants.ts +114 -0
- package/src/openai-assistants/hooks/use-copilot-chat-v2.ts +186 -0
- package/src/openai-assistants/index.ts +2 -0
- package/src/openai-assistants/utils/index.ts +1 -0
- package/src/openai-assistants/utils/process-message-stream.ts +25 -0
- package/dist/chunk-C4KF43WB.mjs +0 -135
- package/dist/chunk-C4KF43WB.mjs.map +0 -1
- package/dist/chunk-EFZPSZWO.mjs +0 -3
- package/dist/chunk-EFZPSZWO.mjs.map +0 -1
- package/dist/chunk-FVU5RFVX.mjs +0 -80
- package/dist/chunk-FVU5RFVX.mjs.map +0 -1
- package/dist/chunk-HZDMKMAV.mjs +0 -50
- package/dist/chunk-HZDMKMAV.mjs.map +0 -1
- package/dist/chunk-JD7BAH7U.mjs +0 -3
- package/dist/chunk-JD7BAH7U.mjs.map +0 -1
- package/dist/chunk-MRXNTQOX.mjs +0 -55
- package/dist/chunk-MRXNTQOX.mjs.map +0 -1
- package/dist/chunk-QACD2U6P.mjs +0 -3
- package/dist/chunk-QACD2U6P.mjs.map +0 -1
- package/dist/chunk-RW25IF4S.mjs +0 -19
- package/dist/chunk-RW25IF4S.mjs.map +0 -1
- package/dist/chunk-UBLDQLZM.mjs +0 -19
- package/dist/chunk-UBLDQLZM.mjs.map +0 -1
- package/dist/chunk-XFSUVTIQ.mjs +0 -27
- package/dist/chunk-XFSUVTIQ.mjs.map +0 -1
- package/dist/chunk-YPSGKPDA.mjs +0 -3
- package/dist/chunk-YPSGKPDA.mjs.map +0 -1
- package/dist/chunk-YULKJPY3.mjs +0 -70
- package/dist/chunk-YULKJPY3.mjs.map +0 -1
- package/dist/chunk-ZIFCJ774.mjs +0 -158
- package/dist/chunk-ZIFCJ774.mjs.map +0 -1
- package/dist/components/copilot-provider.d.ts +0 -11
- package/dist/components/copilot-provider.mjs +0 -7
- package/dist/components/copilot-provider.mjs.map +0 -1
package/dist/chunk-XFSUVTIQ.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { CopilotContext } from './chunk-HZDMKMAV.mjs';
|
|
2
|
-
import { useRef, useContext, useMemo, useEffect } from 'react';
|
|
3
|
-
import { nanoid } from 'nanoid';
|
|
4
|
-
|
|
5
|
-
function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
6
|
-
const idRef = useRef(nanoid());
|
|
7
|
-
const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);
|
|
8
|
-
const memoizedAnnotatedFunction = useMemo(
|
|
9
|
-
() => ({
|
|
10
|
-
name: annotatedFunction.name,
|
|
11
|
-
description: annotatedFunction.description,
|
|
12
|
-
argumentAnnotations: annotatedFunction.argumentAnnotations,
|
|
13
|
-
implementation: annotatedFunction.implementation
|
|
14
|
-
}),
|
|
15
|
-
dependencies
|
|
16
|
-
);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
setEntryPoint(idRef.current, memoizedAnnotatedFunction);
|
|
19
|
-
return () => {
|
|
20
|
-
removeEntryPoint(idRef.current);
|
|
21
|
-
};
|
|
22
|
-
}, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { useMakeCopilotActionable };
|
|
26
|
-
//# sourceMappingURL=out.js.map
|
|
27
|
-
//# sourceMappingURL=chunk-XFSUVTIQ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-make-copilot-actionable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,QAAQ,YAAY,WAAW,eAAe;AAGvD,SAAS,cAAc;AALvB;AAOO,SAAS,yBACd,mBACA,cACA;AACA,QAAM,QAAQ,OAAO,OAAO,CAAC;AAC7B,QAAM,EAAE,eAAe,iBAAiB,IAAI,WAAW,cAAc;AAErE,QAAM,4BAA4D;AAAA,IAChE,OAAO;AAAA,MACL,MAAM,kBAAkB;AAAA,MACxB,aAAa,kBAAkB;AAAA,MAC/B,qBAAqB,kBAAkB;AAAA,MACvC,gBAAgB,kBAAkB;AAAA,IACpC;AAAA,IACA;AAAA,EACF;AAEA,YAAU,MAAM;AACd,kBAAc,MAAM,SAAS,yBAAqD;AAElF,WAAO,MAAM;AACX,uBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,2BAA2B,eAAe,gBAAgB,CAAC;AACjE","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(idRef.current, memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n"]}
|
package/dist/chunk-YPSGKPDA.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/chunk-YULKJPY3.mjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { nanoid } from 'nanoid';
|
|
2
|
-
import { useReducer, useCallback } from 'react';
|
|
3
|
-
|
|
4
|
-
// src/hooks/use-flat-category-store.ts
|
|
5
|
-
var useFlatCategoryStore = () => {
|
|
6
|
-
const [elements, dispatch] = useReducer(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
|
|
7
|
-
const addElement = useCallback((value, categories) => {
|
|
8
|
-
const newId = nanoid();
|
|
9
|
-
dispatch({
|
|
10
|
-
type: "ADD_ELEMENT",
|
|
11
|
-
value,
|
|
12
|
-
id: newId,
|
|
13
|
-
categories
|
|
14
|
-
});
|
|
15
|
-
return newId;
|
|
16
|
-
}, []);
|
|
17
|
-
const removeElement = useCallback((id) => {
|
|
18
|
-
dispatch({ type: "REMOVE_ELEMENT", id });
|
|
19
|
-
}, []);
|
|
20
|
-
const allElements = useCallback(
|
|
21
|
-
(categories) => {
|
|
22
|
-
const categoriesSet = new Set(categories);
|
|
23
|
-
const result = [];
|
|
24
|
-
elements.forEach((element) => {
|
|
25
|
-
if (setsHaveIntersection(categoriesSet, element.categories)) {
|
|
26
|
-
result.push(element.value);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return result;
|
|
30
|
-
},
|
|
31
|
-
[elements]
|
|
32
|
-
);
|
|
33
|
-
return { addElement, removeElement, allElements };
|
|
34
|
-
};
|
|
35
|
-
var use_flat_category_store_default = useFlatCategoryStore;
|
|
36
|
-
function flatCategoryStoreReducer(state, action) {
|
|
37
|
-
switch (action.type) {
|
|
38
|
-
case "ADD_ELEMENT": {
|
|
39
|
-
const { value, id, categories } = action;
|
|
40
|
-
const newElement = {
|
|
41
|
-
id,
|
|
42
|
-
value,
|
|
43
|
-
categories: new Set(categories)
|
|
44
|
-
};
|
|
45
|
-
const newState = new Map(state);
|
|
46
|
-
newState.set(id, newElement);
|
|
47
|
-
return newState;
|
|
48
|
-
}
|
|
49
|
-
case "REMOVE_ELEMENT": {
|
|
50
|
-
const newState = new Map(state);
|
|
51
|
-
newState.delete(action.id);
|
|
52
|
-
return newState;
|
|
53
|
-
}
|
|
54
|
-
default:
|
|
55
|
-
return state;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function setsHaveIntersection(setA, setB) {
|
|
59
|
-
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
60
|
-
for (let item of smallerSet) {
|
|
61
|
-
if (largerSet.has(item)) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export { use_flat_category_store_default };
|
|
69
|
-
//# sourceMappingURL=out.js.map
|
|
70
|
-
//# sourceMappingURL=chunk-YULKJPY3.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-flat-category-store.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAgBxC,IAAM,uBAAuB,MAAwC;AACnE,QAAM,CAAC,UAAU,QAAQ,IAAI,WAE3B,0BAA0B,oBAAI,IAAsD,CAAC;AAEvF,QAAM,aAAa,YAAY,CAAC,OAAU,eAA8C;AACtF,UAAM,QAAQ,OAAO;AACrB,aAAS;AAAA,MACP,MAAM;AAAA,MACN;AAAA,MACA,IAAI;AAAA,MACJ;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,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,IAAI,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAEnF,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT","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<Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>, Action<T>>\n >(flatCategoryStoreReducer, new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>());\n\n const addElement = useCallback((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 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] = 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"]}
|
package/dist/chunk-ZIFCJ774.mjs
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { use_tree_default } from './chunk-C4KF43WB.mjs';
|
|
2
|
-
import { CopilotContext } from './chunk-HZDMKMAV.mjs';
|
|
3
|
-
import { use_flat_category_store_default } from './chunk-YULKJPY3.mjs';
|
|
4
|
-
import { __spreadProps, __spreadValues, __async, __objRest } from './chunk-MRXNTQOX.mjs';
|
|
5
|
-
import { useState, useCallback } from 'react';
|
|
6
|
-
import { jsx } from 'react/jsx-runtime';
|
|
7
|
-
|
|
8
|
-
function CopilotProvider({
|
|
9
|
-
chatApiEndpoint,
|
|
10
|
-
headers,
|
|
11
|
-
body,
|
|
12
|
-
children
|
|
13
|
-
}) {
|
|
14
|
-
const [entryPoints, setEntryPoints] = useState({});
|
|
15
|
-
const { addElement, removeElement, printTree } = use_tree_default();
|
|
16
|
-
const {
|
|
17
|
-
addElement: addDocument,
|
|
18
|
-
removeElement: removeDocument,
|
|
19
|
-
allElements: allDocuments
|
|
20
|
-
} = use_flat_category_store_default();
|
|
21
|
-
const setEntryPoint = useCallback((id, entryPoint) => {
|
|
22
|
-
setEntryPoints((prevPoints) => {
|
|
23
|
-
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
24
|
-
[id]: entryPoint
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}, []);
|
|
28
|
-
const removeEntryPoint = useCallback((id) => {
|
|
29
|
-
setEntryPoints((prevPoints) => {
|
|
30
|
-
const newPoints = __spreadValues({}, prevPoints);
|
|
31
|
-
delete newPoints[id];
|
|
32
|
-
return newPoints;
|
|
33
|
-
});
|
|
34
|
-
}, []);
|
|
35
|
-
const getContextString = useCallback(
|
|
36
|
-
(documents, categories) => {
|
|
37
|
-
const documentsString = documents.map((document) => {
|
|
38
|
-
return `${document.name} (${document.sourceApplication}):
|
|
39
|
-
${document.getContents()}`;
|
|
40
|
-
}).join("\n\n");
|
|
41
|
-
const nonDocumentStrings = printTree(categories);
|
|
42
|
-
return `${documentsString}
|
|
43
|
-
|
|
44
|
-
${nonDocumentStrings}`;
|
|
45
|
-
},
|
|
46
|
-
[printTree]
|
|
47
|
-
);
|
|
48
|
-
const addContext = useCallback(
|
|
49
|
-
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
50
|
-
return addElement(context, categories, parentId);
|
|
51
|
-
},
|
|
52
|
-
[addElement]
|
|
53
|
-
);
|
|
54
|
-
const removeContext = useCallback(
|
|
55
|
-
(id) => {
|
|
56
|
-
removeElement(id);
|
|
57
|
-
},
|
|
58
|
-
[removeElement]
|
|
59
|
-
);
|
|
60
|
-
const getChatCompletionFunctionDescriptions = useCallback(() => {
|
|
61
|
-
return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
|
|
62
|
-
}, [entryPoints]);
|
|
63
|
-
const getFunctionCallHandler = useCallback(() => {
|
|
64
|
-
return entryPointsToFunctionCallHandler(Object.values(entryPoints));
|
|
65
|
-
}, [entryPoints]);
|
|
66
|
-
const getDocumentsContext = useCallback(
|
|
67
|
-
(categories) => {
|
|
68
|
-
return allDocuments(categories);
|
|
69
|
-
},
|
|
70
|
-
[allDocuments]
|
|
71
|
-
);
|
|
72
|
-
const addDocumentContext = useCallback(
|
|
73
|
-
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
74
|
-
return addDocument(documentPointer, categories);
|
|
75
|
-
},
|
|
76
|
-
[addDocument]
|
|
77
|
-
);
|
|
78
|
-
const removeDocumentContext = useCallback(
|
|
79
|
-
(documentId) => {
|
|
80
|
-
removeDocument(documentId);
|
|
81
|
-
},
|
|
82
|
-
[removeDocument]
|
|
83
|
-
);
|
|
84
|
-
return /* @__PURE__ */ jsx(CopilotContext.Provider, {
|
|
85
|
-
value: {
|
|
86
|
-
entryPoints,
|
|
87
|
-
getChatCompletionFunctionDescriptions,
|
|
88
|
-
getFunctionCallHandler,
|
|
89
|
-
setEntryPoint,
|
|
90
|
-
removeEntryPoint,
|
|
91
|
-
getContextString,
|
|
92
|
-
addContext,
|
|
93
|
-
removeContext,
|
|
94
|
-
getDocumentsContext,
|
|
95
|
-
addDocumentContext,
|
|
96
|
-
removeDocumentContext,
|
|
97
|
-
copilotApiConfig: {
|
|
98
|
-
chatApiEndpoint,
|
|
99
|
-
headers: headers || {},
|
|
100
|
-
body: body || {}
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
children
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
var defaultCopilotContextCategories = ["global"];
|
|
107
|
-
function entryPointsToFunctionCallHandler(entryPoints) {
|
|
108
|
-
return (chatMessages, functionCall) => __async(this, null, function* () {
|
|
109
|
-
let entrypointsByFunctionName = {};
|
|
110
|
-
for (let entryPoint of entryPoints) {
|
|
111
|
-
entrypointsByFunctionName[entryPoint.name] = entryPoint;
|
|
112
|
-
}
|
|
113
|
-
const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""];
|
|
114
|
-
if (entryPointFunction) {
|
|
115
|
-
let parsedFunctionCallArguments = [];
|
|
116
|
-
if (functionCall.arguments) {
|
|
117
|
-
parsedFunctionCallArguments = JSON.parse(functionCall.arguments);
|
|
118
|
-
}
|
|
119
|
-
const paramsInCorrectOrder = [];
|
|
120
|
-
for (let arg of entryPointFunction.argumentAnnotations) {
|
|
121
|
-
paramsInCorrectOrder.push(
|
|
122
|
-
parsedFunctionCallArguments[arg.name]
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
yield entryPointFunction.implementation(...paramsInCorrectOrder);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function entryPointsToChatCompletionFunctions(entryPoints) {
|
|
130
|
-
return entryPoints.map(annotatedFunctionToChatCompletionFunction);
|
|
131
|
-
}
|
|
132
|
-
function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
|
|
133
|
-
let parameters = {};
|
|
134
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
135
|
-
let _a = arg, forwardedArgs = __objRest(_a, ["name", "required"]);
|
|
136
|
-
parameters[arg.name] = forwardedArgs;
|
|
137
|
-
}
|
|
138
|
-
let requiredParameterNames = [];
|
|
139
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
140
|
-
if (arg.required) {
|
|
141
|
-
requiredParameterNames.push(arg.name);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
let chatCompletionFunction = {
|
|
145
|
-
name: annotatedFunction.name,
|
|
146
|
-
description: annotatedFunction.description,
|
|
147
|
-
parameters: {
|
|
148
|
-
type: "object",
|
|
149
|
-
properties: parameters,
|
|
150
|
-
required: requiredParameterNames
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
return chatCompletionFunction;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export { CopilotProvider, defaultCopilotContextCategories };
|
|
157
|
-
//# sourceMappingURL=out.js.map
|
|
158
|
-
//# sourceMappingURL=chunk-ZIFCJ774.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/copilot-provider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,SAAoB,aAAa,gBAAgB;AA4G7C;AA9GJ;AAUO,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKgB;AACd,QAAM,CAAC,aAAa,cAAc,IAAI,SAAmD,CAAC,CAAC;AAE3F,QAAM,EAAE,YAAY,eAAe,UAAU,IAAI,iBAAQ;AACzD,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,aAAa;AAAA,EACf,IAAI,gCAAsC;AAE1C,QAAM,gBAAgB,YAAY,CAAC,IAAY,eAAyC;AACtF,mBAAe,CAAC,eAAe;AAC7B,aAAO,iCACF,aADE;AAAA,QAEL,CAAC,KAAK;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,mBAAmB,YAAY,CAAC,OAAe;AACnD,mBAAe,CAAC,eAAe;AAC7B,YAAM,YAAY,mBAAK;AACvB,aAAO,UAAU;AACjB,aAAO;AAAA,IACT,CAAC;AAAA,EACH,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D;AAAA,IAChE,MAAM,kBAAkB;AAAA,IACxB,aAAa,kBAAkB;AAAA,IAC/B,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["\"use client\";\nimport { FunctionCallHandler } from \"ai\";\nimport { ReactNode, useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../context/copilot-context\";\nimport useTree from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\nimport useFlatCategoryStore from \"../hooks/use-flat-category-store\";\n\nexport function CopilotProvider({\n chatApiEndpoint,\n headers,\n body,\n children,\n}: {\n chatApiEndpoint: string;\n headers?: Record<string, string>;\n body?: Record<string, any>;\n children: ReactNode;\n}): JSX.Element {\n const [entryPoints, setEntryPoints] = useState<Record<string, AnnotatedFunction<any[]>>>({});\n\n const { addElement, removeElement, printTree } = useTree();\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 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: {\n chatApiEndpoint,\n headers: headers || {},\n body: body || {},\n },\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 parsedFunctionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n parsedFunctionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n parsedFunctionCallArguments[arg.name as keyof typeof parsedFunctionCallArguments],\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[],\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n"]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
declare function CopilotProvider({ chatApiEndpoint, headers, body, children, }: {
|
|
4
|
-
chatApiEndpoint: string;
|
|
5
|
-
headers?: Record<string, string>;
|
|
6
|
-
body?: Record<string, any>;
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
}): JSX.Element;
|
|
9
|
-
declare const defaultCopilotContextCategories: string[];
|
|
10
|
-
|
|
11
|
-
export { CopilotProvider, defaultCopilotContextCategories };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { CopilotProvider, defaultCopilotContextCategories } from '../chunk-ZIFCJ774.mjs';
|
|
2
|
-
import '../chunk-C4KF43WB.mjs';
|
|
3
|
-
import '../chunk-HZDMKMAV.mjs';
|
|
4
|
-
import '../chunk-YULKJPY3.mjs';
|
|
5
|
-
import '../chunk-MRXNTQOX.mjs';
|
|
6
|
-
//# sourceMappingURL=out.js.map
|
|
7
|
-
//# sourceMappingURL=copilot-provider.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|