@copilotkit/react-core 0.25.0 → 0.36.0-mme-pre.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 +184 -165
- package/CHANGELOG.md +22 -0
- package/dist/{chunk-72BJ3A3S.mjs → chunk-2C4UBKRR.mjs} +2 -2
- package/dist/{chunk-KTUNGBJF.mjs → chunk-2DKLSG5S.mjs} +2 -2
- package/dist/{chunk-4NNFSZOY.mjs → chunk-32T4S22Q.mjs} +3 -3
- package/dist/chunk-32T4S22Q.mjs.map +1 -0
- package/dist/{chunk-CGT3AVYT.mjs → chunk-7YTDTTX5.mjs} +6 -4
- package/dist/chunk-7YTDTTX5.mjs.map +1 -0
- package/dist/{chunk-ZIR7KCEA.mjs → chunk-B5CULQRZ.mjs} +2 -2
- package/dist/chunk-B5CULQRZ.mjs.map +1 -0
- package/dist/chunk-BTJD4QON.mjs +122 -0
- package/dist/chunk-BTJD4QON.mjs.map +1 -0
- package/dist/chunk-CYDWEPFL.mjs +1 -0
- package/dist/{chunk-6ARSX7BW.mjs → chunk-FHGMPFKO.mjs} +2 -2
- package/dist/{chunk-PC6FY3LD.mjs → chunk-GJGYNK46.mjs} +2 -2
- package/dist/{chunk-7LVVZQRG.mjs → chunk-JWANHQCM.mjs} +22 -6
- package/dist/chunk-JWANHQCM.mjs.map +1 -0
- package/dist/{chunk-M6WULIFO.mjs → chunk-L3LL6N7J.mjs} +5 -5
- package/dist/{chunk-6VF626RG.mjs → chunk-S2YA76YW.mjs} +5 -5
- package/dist/{chunk-MRXNTQOX.mjs → chunk-SKC7AJIV.mjs} +3 -1
- package/dist/chunk-SKC7AJIV.mjs.map +1 -0
- package/dist/{chunk-OWBDHSLH.mjs → chunk-T6UD6AJ2.mjs} +9 -4
- package/dist/chunk-T6UD6AJ2.mjs.map +1 -0
- package/dist/{chunk-O35YOIHC.mjs → chunk-TW5FS2QT.mjs} +8 -3
- package/dist/chunk-TW5FS2QT.mjs.map +1 -0
- package/dist/{chunk-VUY2K2DI.mjs → chunk-YWITCRBI.mjs} +2 -2
- package/dist/{chunk-MZ5UN3BY.mjs → chunk-ZFS5SQUT.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +18 -12
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +0 -20
- package/dist/components/copilot-provider/copilotkit.js +24 -3
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +4 -4
- package/dist/components/copilot-provider/index.js +24 -3
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +4 -4
- package/dist/components/index.js +24 -3
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -4
- package/dist/context/copilot-context.d.ts +14 -0
- package/dist/context/copilot-context.js +6 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +2 -2
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.js +6 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +2 -2
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +10 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +12 -12
- package/dist/hooks/use-chat.d.ts +1 -0
- package/dist/hooks/use-chat.js +4 -2
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +3 -3
- package/dist/hooks/use-copilot-action.js +6 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +1 -0
- package/dist/hooks/use-copilot-chat.js +10 -3
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +7 -7
- package/dist/hooks/use-copilot-readable.js +6 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +3 -3
- package/dist/hooks/use-flat-category-store.mjs +1 -1
- package/dist/hooks/use-make-copilot-actionable.js +6 -1
- package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +3 -3
- package/dist/hooks/use-make-copilot-document-readable.js +6 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +3 -3
- package/dist/hooks/use-make-copilot-readable.js +6 -1
- package/dist/hooks/use-make-copilot-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +3 -3
- package/dist/hooks/use-tree.mjs +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +143 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -15
- package/dist/lib/copilot-task.d.ts +98 -1
- package/dist/lib/copilot-task.js +9 -2
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +6 -6
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +9 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/openai-assistants/hooks/index.js +6 -1
- package/dist/openai-assistants/hooks/index.js.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +6 -6
- package/dist/openai-assistants/hooks/use-assistants.mjs +2 -2
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +6 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +6 -6
- package/dist/openai-assistants/index.js +6 -1
- package/dist/openai-assistants/index.js.map +1 -1
- package/dist/openai-assistants/index.mjs +6 -6
- package/dist/openai-assistants/utils/index.mjs +2 -2
- package/dist/openai-assistants/utils/process-message-stream.mjs +2 -2
- package/dist/types/chat-suggestion-configuration.d.ts +22 -0
- package/dist/types/chat-suggestion-configuration.js +19 -0
- package/dist/types/chat-suggestion-configuration.js.map +1 -0
- package/dist/types/chat-suggestion-configuration.mjs +1 -0
- package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/extract.d.ts +37 -0
- package/dist/utils/extract.js +245 -0
- package/dist/utils/extract.js.map +1 -0
- package/dist/utils/extract.mjs +15 -0
- package/dist/utils/extract.mjs.map +1 -0
- package/dist/utils/fetch-chat-completion.d.ts +8 -1
- package/dist/utils/fetch-chat-completion.js +4 -2
- package/dist/utils/fetch-chat-completion.js.map +1 -1
- package/dist/utils/fetch-chat-completion.mjs +2 -2
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.js +267 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +23 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +4 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +20 -12
- package/src/components/copilot-provider/copilotkit.tsx +62 -21
- package/src/context/copilot-context.tsx +24 -1
- package/src/hooks/use-chat.ts +2 -2
- package/src/hooks/use-copilot-readable.ts +94 -0
- package/src/index.tsx +1 -6
- package/src/lib/copilot-task.ts +97 -1
- package/src/types/chat-suggestion-configuration.ts +23 -0
- package/src/types/index.ts +1 -0
- package/src/utils/extract.ts +164 -0
- package/src/utils/fetch-chat-completion.ts +5 -1
- package/src/utils/index.ts +8 -0
- package/typedoc.json +4 -0
- package/dist/chunk-4NNFSZOY.mjs.map +0 -1
- package/dist/chunk-7LVVZQRG.mjs.map +0 -1
- package/dist/chunk-CGT3AVYT.mjs.map +0 -1
- package/dist/chunk-O35YOIHC.mjs.map +0 -1
- package/dist/chunk-OWBDHSLH.mjs.map +0 -1
- package/dist/chunk-ZIR7KCEA.mjs.map +0 -1
- /package/dist/{chunk-72BJ3A3S.mjs.map → chunk-2C4UBKRR.mjs.map} +0 -0
- /package/dist/{chunk-KTUNGBJF.mjs.map → chunk-2DKLSG5S.mjs.map} +0 -0
- /package/dist/{chunk-MRXNTQOX.mjs.map → chunk-CYDWEPFL.mjs.map} +0 -0
- /package/dist/{chunk-6ARSX7BW.mjs.map → chunk-FHGMPFKO.mjs.map} +0 -0
- /package/dist/{chunk-PC6FY3LD.mjs.map → chunk-GJGYNK46.mjs.map} +0 -0
- /package/dist/{chunk-M6WULIFO.mjs.map → chunk-L3LL6N7J.mjs.map} +0 -0
- /package/dist/{chunk-6VF626RG.mjs.map → chunk-S2YA76YW.mjs.map} +0 -0
- /package/dist/{chunk-VUY2K2DI.mjs.map → chunk-YWITCRBI.mjs.map} +0 -0
- /package/dist/{chunk-MZ5UN3BY.mjs.map → chunk-ZFS5SQUT.mjs.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__async,
|
|
3
3
|
__spreadValues
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
5
5
|
|
|
6
6
|
// src/utils/fetch-chat-completion.ts
|
|
7
7
|
import {
|
|
@@ -19,7 +19,8 @@ function fetchChatCompletion(_0) {
|
|
|
19
19
|
temperature,
|
|
20
20
|
headers,
|
|
21
21
|
body,
|
|
22
|
-
signal
|
|
22
|
+
signal,
|
|
23
|
+
toolChoice
|
|
23
24
|
}) {
|
|
24
25
|
temperature || (temperature = 0.5);
|
|
25
26
|
tools || (tools = []);
|
|
@@ -27,6 +28,7 @@ function fetchChatCompletion(_0) {
|
|
|
27
28
|
const { content, role, name, function_call } = message;
|
|
28
29
|
return { content, role, name, function_call };
|
|
29
30
|
});
|
|
31
|
+
toolChoice || (toolChoice = "auto");
|
|
30
32
|
const response = yield fetch(copilotConfig.chatApiEndpoint, {
|
|
31
33
|
method: "POST",
|
|
32
34
|
headers: __spreadValues(__spreadValues({
|
|
@@ -36,7 +38,7 @@ function fetchChatCompletion(_0) {
|
|
|
36
38
|
model,
|
|
37
39
|
messages: cleanedMessages,
|
|
38
40
|
stream: true
|
|
39
|
-
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice:
|
|
41
|
+
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: toolChoice } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {}), copilotConfig.cloud ? { cloud: copilotConfig.cloud } : {})),
|
|
40
42
|
signal
|
|
41
43
|
});
|
|
42
44
|
return response;
|
|
@@ -85,4 +87,4 @@ export {
|
|
|
85
87
|
fetchAndDecodeChatCompletion,
|
|
86
88
|
fetchAndDecodeChatCompletionAsText
|
|
87
89
|
};
|
|
88
|
-
//# sourceMappingURL=chunk-
|
|
90
|
+
//# sourceMappingURL=chunk-7YTDTTX5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/fetch-chat-completion.ts"],"sourcesContent":["import {\n Message,\n ToolDefinition,\n ChatCompletionEvent,\n decodeChatCompletion,\n parseChatCompletion,\n decodeChatCompletionAsText,\n EXCLUDE_FROM_FORWARD_PROPS_KEYS,\n} from \"@copilotkit/shared\";\nimport { CopilotApiConfig } from \"../context\";\n\nexport interface FetchChatCompletionParams {\n copilotConfig: CopilotApiConfig;\n model?: string;\n messages: Message[];\n tools?: ToolDefinition[];\n temperature?: number;\n maxTokens?: number;\n headers?: Record<string, string> | Headers;\n body?: object;\n signal?: AbortSignal;\n toolChoice?: string | { type: \"function\"; function: { name: string } };\n}\n\nexport async function fetchChatCompletion({\n copilotConfig,\n model,\n messages,\n tools,\n temperature,\n headers,\n body,\n signal,\n toolChoice,\n}: FetchChatCompletionParams): Promise<Response> {\n temperature ||= 0.5;\n tools ||= [];\n\n // clean up any extra properties from messages\n const cleanedMessages = messages.map((message) => {\n const { content, role, name, function_call } = message;\n return { content, role, name, function_call };\n });\n\n toolChoice ||= \"auto\";\n\n const response = await fetch(copilotConfig.chatApiEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotConfig.headers,\n ...(headers ? { ...headers } : {}),\n },\n body: JSON.stringify({\n model,\n messages: cleanedMessages,\n stream: true,\n ...(tools.length ? { tools } : {}),\n ...(temperature ? { temperature } : {}),\n ...(tools.length != 0 ? { tool_choice: toolChoice } : {}),\n ...copilotConfig.body,\n ...copilotConfig.backendOnlyProps,\n ...excludeBackendOnlyProps(copilotConfig),\n ...(body ? { ...body } : {}),\n ...(copilotConfig.cloud ? { cloud: copilotConfig.cloud } : {}),\n }),\n signal,\n });\n\n return response;\n}\n\nfunction excludeBackendOnlyProps(copilotConfig: any) {\n const backendOnlyProps = copilotConfig.backendOnlyProps ?? {};\n if (Object.keys(backendOnlyProps).length > 0) {\n return {\n [EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys(backendOnlyProps),\n };\n } else {\n return {};\n }\n}\n\nexport interface DecodedChatCompletionResponse extends Response {\n events: ReadableStream<ChatCompletionEvent> | null;\n}\n\nexport async function fetchAndDecodeChatCompletion(\n params: FetchChatCompletionParams,\n): Promise<DecodedChatCompletionResponse> {\n const response = await fetchChatCompletion(params);\n if (!response.ok || !response.body) {\n (response as any).events = null;\n } else {\n const events = await decodeChatCompletion(parseChatCompletion(response.body));\n (response as any).events = events;\n }\n return response as any;\n}\n\nexport interface DecodedChatCompletionResponseAsText extends Response {\n events: ReadableStream<string> | null;\n}\n\nexport async function fetchAndDecodeChatCompletionAsText(\n params: FetchChatCompletionParams,\n): Promise<DecodedChatCompletionResponseAsText> {\n const response = await fetchChatCompletion(params);\n if (!response.ok || !response.body) {\n (response as any).events = null;\n } else {\n const events = await decodeChatCompletionAsText(\n decodeChatCompletion(parseChatCompletion(response.body)),\n );\n (response as any).events = events;\n }\n\n return response as any;\n}\n"],"mappings":";;;;;;AAAA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgBP,SAAsB,oBAAoB,IAUO;AAAA,6CAVP;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA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;AAAA,IAC7B,OAAO;AACL,YAAM,SAAS,MAAM,qBAAqB,oBAAoB,SAAS,IAAI,CAAC;AAC5E,MAAC,SAAiB,SAAS;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA;AAMA,SAAsB,mCACpB,QAC8C;AAAA;AAC9C,UAAM,WAAW,MAAM,oBAAoB,MAAM;AACjD,QAAI,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM;AAClC,MAAC,SAAiB,SAAS;AAAA,IAC7B,OAAO;AACL,YAAM,SAAS,MAAM;AAAA,QACnB,qBAAqB,oBAAoB,SAAS,IAAI,CAAC;AAAA,MACzD;AACA,MAAC,SAAiB,SAAS;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AAAA;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TW5FS2QT.mjs";
|
|
4
4
|
|
|
5
5
|
// src/hooks/use-copilot-readable.ts
|
|
6
6
|
import { useContext, useEffect, useRef } from "react";
|
|
@@ -25,4 +25,4 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
25
25
|
export {
|
|
26
26
|
useCopilotReadable
|
|
27
27
|
};
|
|
28
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-B5CULQRZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-copilot-readable.ts"],"sourcesContent":["/**\n * A hook for providing app-state & other information to the Copilot.\n *\n * <img referrerPolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be\" />\n *\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * <RequestExample>\n * ```jsx useCopilotReadable Example\n * import { useCopilotReadable }\n * from \"@copilotkit/react-core\";\n *\n * const myAppState = ...;\n * useCopilotReadable({\n * description: \"The current state of the app\",\n * value: myAppState\n * });\n * ```\n * </RequestExample>\n *\n * In its most basic usage, useCopilotReadable accepts a single string argument\n * representing any piece of app state, making it available for the Copilot to use\n * as context when responding to user input.\n *\n * For example:\n *\n * ```jsx simple state example\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * const userName = \"Rust Cohle\";\n * useCopilotReadable({\n * description: \"The name of the user\",\n * value: userName\n * });\n * ```\n *\n * You can also pass in an object representing your app state,\n * for example:\n *\n * ```jsx using state\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * const myAppState = {\n * userName: \"Rust Cohle\",\n * userAddress: {\n * street: \"4500 Old Spanish Trail\",\n * city: \"New Orleans\",\n * state: \"LA\",\n * zip: \"70129\"\n * }\n * };\n * useCopilotReadable({\n * description: \"The current state of the app\",\n * value: myAppState\n * });\n * ```\n *\n * Optionally, you can maintain the hierarchical structure of information by passing\n * `parentId`:\n *\n * ```jsx parentId example\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n *\n * function Employee(props: EmployeeProps) {\n * const { employeeName, workProfile, metadata } = props;\n *\n * // propagate any information copilot\n * const employeeContextId = useCopilotReadable({\n * description: \"Employee name\",\n * value: employeeName\n * });\n *\n * // Pass a parentID to maintain a hierarchical structure.\n * // Especially useful with child React components, list elements, etc.\n * useCopilotReadable({\n * description: \"Work profile\",\n * value: workProfile.description(),\n * parentId: employeeContextId\n * });\n * useCopilotReadable({\n * description: \"Employee metadata\",\n * value: metadata.description(),\n * parentId: employeeContextId\n * });\n *\n * return (\n * // Render as usual...\n * );\n * }\n * ```\n */\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * Options for the useCopilotReadable hook.\n */\nexport interface UseCopilotReadableOptions {\n /**\n * The description of the information to be added to the Copilot context.\n */\n description: string;\n /**\n * The value to be added to the Copilot context.\n */\n value: any;\n /**\n * The ID of the parent context, if any.\n */\n parentId?: string;\n /**\n * An array of categories to control which context are visible where. Particularly useful\n * with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n */\n categories?: string[];\n\n /**\n * A custom conversion function to use to serialize the value to a string. If not provided, the value\n * will be serialized using `JSON.stringify`.\n */\n convert?: (description: string, value: any) => string;\n}\n\nfunction convertToJSON(description: string, value: any): string {\n return `${description}: ${typeof value === \"string\" ? value : JSON.stringify(value)}`;\n}\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n */\nexport function useCopilotReadable(\n { description, value, parentId, categories, convert }: UseCopilotReadableOptions,\n dependencies?: any[],\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n convert = convert || convertToJSON;\n\n const information = convert(description, value);\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, ...(dependencies || [])]);\n\n return idRef.current;\n}\n"],"mappings":";;;;;AA8FA,SAAS,YAAY,WAAW,cAAc;AAgC9C,SAAS,cAAc,aAAqB,OAAoB;AAC9D,SAAO,GAAG,gBAAgB,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;AACpF;AAKO,SAAS,mBACd,EAAE,aAAa,OAAO,UAAU,YAAY,QAAQ,GACpD,cACoB;AACpB,QAAM,EAAE,YAAY,cAAc,IAAI,WAAW,cAAc;AAC/D,QAAM,QAAQ,OAAe;AAC7B,YAAU,WAAW;AAErB,QAAM,cAAc,QAAQ,aAAa,KAAK;AAE9C,YAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,UAAU,UAAU;AACvD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,eAAe,GAAI,gBAAgB,CAAC,CAAE,CAAC;AAE9E,SAAO,MAAM;AACf;","names":[]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultCopilotContextCategories
|
|
3
|
+
} from "./chunk-JWANHQCM.mjs";
|
|
4
|
+
import {
|
|
5
|
+
fetchAndDecodeChatCompletion
|
|
6
|
+
} from "./chunk-7YTDTTX5.mjs";
|
|
7
|
+
import {
|
|
8
|
+
__async,
|
|
9
|
+
__spreadValues
|
|
10
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
11
|
+
|
|
12
|
+
// src/utils/extract.ts
|
|
13
|
+
import {
|
|
14
|
+
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER
|
|
15
|
+
} from "@copilotkit/shared";
|
|
16
|
+
import untruncateJson from "untruncate-json";
|
|
17
|
+
function extract(_0) {
|
|
18
|
+
return __async(this, arguments, function* ({
|
|
19
|
+
context,
|
|
20
|
+
instructions,
|
|
21
|
+
parameters,
|
|
22
|
+
include,
|
|
23
|
+
data,
|
|
24
|
+
abortSignal,
|
|
25
|
+
stream
|
|
26
|
+
}) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const { messages } = context;
|
|
29
|
+
const action = {
|
|
30
|
+
name: "extract",
|
|
31
|
+
parameters,
|
|
32
|
+
handler: (args) => {
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const includeReadable = (_a = include == null ? void 0 : include.readable) != null ? _a : false;
|
|
36
|
+
const includeMessages = (_b = include == null ? void 0 : include.messages) != null ? _b : false;
|
|
37
|
+
let contextString = "";
|
|
38
|
+
if (data) {
|
|
39
|
+
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
40
|
+
}
|
|
41
|
+
if (includeReadable) {
|
|
42
|
+
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
43
|
+
}
|
|
44
|
+
const systemMessage = {
|
|
45
|
+
id: "system",
|
|
46
|
+
content: makeSystemMessage(contextString, instructions),
|
|
47
|
+
role: "system"
|
|
48
|
+
};
|
|
49
|
+
const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey } : {});
|
|
50
|
+
const response = yield fetchAndDecodeChatCompletion({
|
|
51
|
+
copilotConfig: context.copilotApiConfig,
|
|
52
|
+
messages: includeMessages ? [systemMessage, ...messages] : [systemMessage],
|
|
53
|
+
tools: context.getChatCompletionFunctionDescriptions({ extract: action }),
|
|
54
|
+
headers,
|
|
55
|
+
body: context.copilotApiConfig.body,
|
|
56
|
+
toolChoice: { type: "function", function: { name: "extract" } },
|
|
57
|
+
signal: abortSignal
|
|
58
|
+
});
|
|
59
|
+
if (!response.events) {
|
|
60
|
+
throw new Error("extract() failed: Could not fetch chat completion");
|
|
61
|
+
}
|
|
62
|
+
const reader = response.events.getReader();
|
|
63
|
+
let isInitial = true;
|
|
64
|
+
while (true) {
|
|
65
|
+
const { done, value } = yield reader.read();
|
|
66
|
+
if (done) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (value.type === "partial") {
|
|
70
|
+
try {
|
|
71
|
+
let partialArguments = JSON.parse(untruncateJson(value.arguments));
|
|
72
|
+
stream == null ? void 0 : stream({
|
|
73
|
+
status: isInitial ? "initial" : "inProgress",
|
|
74
|
+
args: partialArguments
|
|
75
|
+
});
|
|
76
|
+
isInitial = false;
|
|
77
|
+
} catch (e) {
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (value.type === "function") {
|
|
81
|
+
stream == null ? void 0 : stream({
|
|
82
|
+
status: "complete",
|
|
83
|
+
args: value.arguments
|
|
84
|
+
});
|
|
85
|
+
return value.arguments;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
throw new Error("extract() failed: No function call occurred");
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function makeSystemMessage(contextString, instructions) {
|
|
92
|
+
return `
|
|
93
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
94
|
+
|
|
95
|
+
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.
|
|
96
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
97
|
+
|
|
98
|
+
The user has provided you with the following context:
|
|
99
|
+
\`\`\`
|
|
100
|
+
${contextString}
|
|
101
|
+
\`\`\`
|
|
102
|
+
|
|
103
|
+
They have also provided you with a function you MUST call to initiate actions on their behalf.
|
|
104
|
+
|
|
105
|
+
Please assist them as best you can.
|
|
106
|
+
|
|
107
|
+
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
108
|
+
|
|
109
|
+
The user has given you the following task to complete:
|
|
110
|
+
|
|
111
|
+
\`\`\`
|
|
112
|
+
${instructions}
|
|
113
|
+
\`\`\`
|
|
114
|
+
|
|
115
|
+
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
extract
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=chunk-BTJD4QON.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/extract.ts"],"sourcesContent":["import {\n Action,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n MappedParameterTypes,\n Message,\n Parameter,\n} from \"@copilotkit/shared\";\nimport { CopilotContextParams } from \"../context\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { fetchAndDecodeChatCompletion } from \"./fetch-chat-completion\";\nimport untruncateJson from \"untruncate-json\";\n\ninterface InitialState<T extends Parameter[] | [] = []> {\n status: \"initial\";\n args: Partial<MappedParameterTypes<T>>;\n}\n\ninterface InProgressState<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n}\n\ninterface CompleteState<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n}\n\ntype StreamHandlerArgs<T extends Parameter[] | [] = []> =\n | InitialState<T>\n | InProgressState<T>\n | CompleteState<T>;\n\ninterface ExtractOptions<T extends Parameter[]> {\n context: CopilotContextParams;\n instructions: string;\n parameters: T;\n include?: IncludeOptions;\n data?: any;\n abortSignal?: AbortSignal;\n stream?: (args: StreamHandlerArgs<T>) => void;\n}\n\ninterface IncludeOptions {\n readable?: boolean;\n messages?: boolean;\n}\n\nexport async function extract<const T extends Parameter[]>({\n context,\n instructions,\n parameters,\n include,\n data,\n abortSignal,\n stream,\n}: ExtractOptions<T>): Promise<MappedParameterTypes<T>> {\n const { messages } = context;\n\n const action: Action<any> = {\n name: \"extract\",\n parameters,\n handler: (args: any) => {},\n };\n\n const includeReadable = include?.readable ?? false;\n const includeMessages = include?.messages ?? false;\n\n let contextString = \"\";\n\n if (data) {\n contextString = (typeof data === \"string\" ? data : JSON.stringify(data)) + \"\\n\\n\";\n }\n\n if (includeReadable) {\n contextString += context.getContextString([], defaultCopilotContextCategories);\n }\n\n const systemMessage: Message = {\n id: \"system\",\n content: makeSystemMessage(contextString, instructions),\n role: \"system\",\n };\n\n const headers = {\n ...(context.copilotApiConfig.headers || {}),\n ...(context.copilotApiConfig.publicApiKey\n ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey }\n : {}),\n };\n\n const response = await fetchAndDecodeChatCompletion({\n copilotConfig: context.copilotApiConfig,\n messages: includeMessages ? [systemMessage, ...messages] : [systemMessage],\n tools: context.getChatCompletionFunctionDescriptions({ extract: action }),\n headers,\n body: context.copilotApiConfig.body,\n toolChoice: { type: \"function\", function: { name: \"extract\" } },\n signal: abortSignal,\n });\n\n if (!response.events) {\n throw new Error(\"extract() failed: Could not fetch chat completion\");\n }\n\n const reader = response.events.getReader();\n let isInitial = true;\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n break;\n }\n\n if (value.type === \"partial\") {\n try {\n let partialArguments = JSON.parse(untruncateJson(value.arguments));\n stream?.({\n status: isInitial ? \"initial\" : \"inProgress\",\n args: partialArguments as Partial<MappedParameterTypes<T>>,\n });\n isInitial = false;\n } catch (e) {}\n }\n\n if (value.type === \"function\") {\n stream?.({\n status: \"complete\",\n args: value.arguments as MappedParameterTypes<T>,\n });\n return value.arguments as MappedParameterTypes<T>;\n }\n }\n\n throw new Error(\"extract() failed: No function call occurred\");\n}\n\nfunction makeSystemMessage(contextString: string, instructions: 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 a function you MUST call to initiate actions on their behalf.\n\nPlease assist them as best you can.\n\nThis is not a conversation, so please do not ask questions. Just call the function without saying anything else.\n\nThe user has given you the following task to complete:\n\n\\`\\`\\`\n${instructions}\n\\`\\`\\`\n\nAny additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.\n`;\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA,EAEE;AAAA,OAIK;AAIP,OAAO,oBAAoB;AAqC3B,SAAsB,QAAqC,IAQH;AAAA,6CARG;AAAA,IACzD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAwD;AAvDxD;AAwDE,UAAM,EAAE,SAAS,IAAI;AAErB,UAAM,SAAsB;AAAA,MAC1B,MAAM;AAAA,MACN;AAAA,MACA,SAAS,CAAC,SAAc;AAAA,MAAC;AAAA,IAC3B;AAEA,UAAM,mBAAkB,wCAAS,aAAT,YAAqB;AAC7C,UAAM,mBAAkB,wCAAS,aAAT,YAAqB;AAE7C,QAAI,gBAAgB;AAEpB,QAAI,MAAM;AACR,uBAAiB,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,IAAI,KAAK;AAAA,IAC7E;AAEA,QAAI,iBAAiB;A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;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AAAA;AAEA,SAAS,kBAAkB,eAAuB,cAA8B;AAC9E,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AAAA;AAAA;AAAA;AAAA;AAKF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-CYDWEPFL.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TW5FS2QT.mjs";
|
|
4
4
|
|
|
5
5
|
// src/hooks/use-make-copilot-actionable.ts
|
|
6
6
|
import { useRef, useContext, useEffect, useMemo } from "react";
|
|
@@ -30,4 +30,4 @@ function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
|
30
30
|
export {
|
|
31
31
|
useMakeCopilotActionable
|
|
32
32
|
};
|
|
33
|
-
//# sourceMappingURL=chunk-
|
|
33
|
+
//# sourceMappingURL=chunk-FHGMPFKO.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TW5FS2QT.mjs";
|
|
4
4
|
|
|
5
5
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
6
6
|
import { useContext, useEffect, useRef } from "react";
|
|
@@ -20,4 +20,4 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
20
20
|
export {
|
|
21
21
|
useMakeCopilotDocumentReadable
|
|
22
22
|
};
|
|
23
|
-
//# sourceMappingURL=chunk-
|
|
23
|
+
//# sourceMappingURL=chunk-GJGYNK46.mjs.map
|
|
@@ -3,16 +3,17 @@ import {
|
|
|
3
3
|
} from "./chunk-YULKJPY3.mjs";
|
|
4
4
|
import {
|
|
5
5
|
use_tree_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YWITCRBI.mjs";
|
|
7
7
|
import {
|
|
8
8
|
CopilotContext
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TW5FS2QT.mjs";
|
|
10
10
|
import {
|
|
11
11
|
__async,
|
|
12
12
|
__objRest,
|
|
13
|
+
__restKey,
|
|
13
14
|
__spreadProps,
|
|
14
15
|
__spreadValues
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
16
17
|
|
|
17
18
|
// src/components/copilot-provider/copilotkit.tsx
|
|
18
19
|
import { useCallback, useRef, useState } from "react";
|
|
@@ -133,8 +134,20 @@ ${nonDocumentStrings}`;
|
|
|
133
134
|
chatApiEndpoint,
|
|
134
135
|
chatApiEndpointV2: `${props.url}/v2`,
|
|
135
136
|
headers: props.headers || {},
|
|
136
|
-
body: __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
|
|
137
|
+
body: __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps),
|
|
138
|
+
transcribeAudioUrl: props.transcribeAudioUrl,
|
|
139
|
+
textToSpeechUrl: props.textToSpeechUrl
|
|
137
140
|
});
|
|
141
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState({});
|
|
142
|
+
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
143
|
+
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
144
|
+
};
|
|
145
|
+
const removeChatSuggestionConfiguration = (id) => {
|
|
146
|
+
setChatSuggestionConfiguration((prev) => {
|
|
147
|
+
const _a3 = prev, { [id]: _ } = _a3, rest = __objRest(_a3, [__restKey(id)]);
|
|
148
|
+
return rest;
|
|
149
|
+
});
|
|
150
|
+
};
|
|
138
151
|
return /* @__PURE__ */ jsx(
|
|
139
152
|
CopilotContext.Provider,
|
|
140
153
|
{
|
|
@@ -153,7 +166,10 @@ ${nonDocumentStrings}`;
|
|
|
153
166
|
removeDocumentContext,
|
|
154
167
|
copilotApiConfig,
|
|
155
168
|
messages,
|
|
156
|
-
setMessages
|
|
169
|
+
setMessages,
|
|
170
|
+
chatSuggestionConfiguration,
|
|
171
|
+
addChatSuggestionConfiguration,
|
|
172
|
+
removeChatSuggestionConfiguration
|
|
157
173
|
},
|
|
158
174
|
children
|
|
159
175
|
}
|
|
@@ -184,4 +200,4 @@ export {
|
|
|
184
200
|
CopilotKit,
|
|
185
201
|
defaultCopilotContextCategories
|
|
186
202
|
};
|
|
187
|
-
//# sourceMappingURL=chunk-
|
|
203
|
+
//# sourceMappingURL=chunk-JWANHQCM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/copilot-provider/copilotkit.tsx"],"sourcesContent":["/**\n * Provides the Copilot context to its children.\n * \n * <img\n * referrerPolicy=\"no-referrer-when-downgrade\"\n * src=\"https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be\"\n * />\n * \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>\n * The backend can use OpenAI, or you can bring your own LLM. For examples of the\n * backend api implementation, see `examples/next-openai` or the [runtime\n * docs](https://docs.copilotkit.ai/getting-started/quickstart-runtime).\n * </Note>\n * \n * <RequestExample>\n * ```jsx CopilotKit Example\n * import { CopilotKit } from \"@copilotkit/react-core\";\n * \n * <CopilotKit \n * runtimeUrl=\"https://your.copilotkit.api\">\n * <YourApp/>\n * </CopilotKit>\n * ```\n * </RequestExample>\n * \n * ## Example usage\n * \n * ```jsx\n * <CopilotKit publicApiKey=\"the api key or self host (see below)\">\n * <App />\n * </CopilotKit>\n```\n */\nimport { Ref, useCallback, useRef, useState } from \"react\";\nimport {\n CopilotContext,\n CopilotApiConfig,\n InChatRenderFunction,\n} from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { CopilotChatSuggestionConfiguration, DocumentPointer } from \"../../types\";\n\nimport {\n COPILOT_CLOUD_CHAT_URL,\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n actionToChatCompletionFunction,\n} from \"@copilotkit/shared\";\n\nimport { FrontendAction } from \"../../types/frontend-action\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\nimport { ToolDefinition } from \"@copilotkit/shared\";\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 if (!props.runtimeUrl && !props.url && !props.publicApiKey) {\n throw new Error(\"Please provide either a url or a publicApiKey to the CopilotKit component.\");\n }\n\n const chatApiEndpoint = props.runtimeUrl || props.url || COPILOT_CLOUD_CHAT_URL;\n\n const [entryPoints, setEntryPoints] = useState<Record<string, FrontendAction<any>>>({});\n const chatComponentsCache = useRef<Record<string, InChatRenderFunction | string>>({});\n const { addElement, removeElement, printTree } = useTree();\n const [messages, setMessages] = useState<Message[]>([]);\n\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback((id: string, entryPoint: FrontendAction<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 (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToChatCompletionFunctions(Object.values(customEntryPoints || entryPoints));\n },\n [entryPoints],\n );\n\n const getFunctionCallHandler = useCallback(\n (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || entryPoints));\n },\n [entryPoints],\n );\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 if (!props.publicApiKey) {\n if (props.cloudRestrictToTopic) {\n throw new Error(\n \"To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey.\",\n );\n }\n }\n\n let cloud: CopilotCloudConfig | undefined = undefined;\n if (props.publicApiKey) {\n cloud = {\n guardrails: {\n input: {\n restrictToTopic: {\n enabled: props.cloudRestrictToTopic ? true : false,\n validTopics: props.cloudRestrictToTopic?.validTopics || [],\n invalidTopics: props.cloudRestrictToTopic?.invalidTopics || [],\n },\n },\n },\n };\n }\n\n // get the appropriate CopilotApiConfig from the props\n const copilotApiConfig: CopilotApiConfig = {\n publicApiKey: props.publicApiKey,\n ...(cloud ? { cloud } : {}),\n chatApiEndpoint: chatApiEndpoint,\n chatApiEndpointV2: `${props.url}/v2`,\n headers: props.headers || {},\n body: {\n ...props.body,\n ...props.backendOnlyProps,\n },\n transcribeAudioUrl: props.transcribeAudioUrl,\n textToSpeechUrl: props.textToSpeechUrl,\n };\n\n const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState<{\n [key: string]: CopilotChatSuggestionConfiguration;\n }>({});\n\n const addChatSuggestionConfiguration = (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => {\n setChatSuggestionConfiguration((prev) => ({ ...prev, [id]: suggestion }));\n };\n\n const removeChatSuggestionConfiguration = (id: string) => {\n setChatSuggestionConfiguration((prev) => {\n const { [id]: _, ...rest } = prev;\n return rest;\n });\n };\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n chatComponentsCache,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: copilotApiConfig,\n messages,\n setMessages,\n chatSuggestionConfiguration,\n addChatSuggestionConfiguration,\n removeChatSuggestionConfiguration,\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToChatCompletionFunctions(actions: FrontendAction<any>[]): ToolDefinition[] {\n return actions.map(actionToChatCompletionFunction);\n}\n\nfunction entryPointsToFunctionCallHandler(actions: FrontendAction<any>[]): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let actionsByFunctionName: Record<string, FrontendAction<any>> = {};\n for (let action of actions) {\n actionsByFunctionName[action.name] = action;\n }\n\n const action = actionsByFunctionName[functionCall.name || \"\"];\n if (action) {\n let functionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n functionCallArguments = JSON.parse(functionCall.arguments);\n }\n return await action.handler(functionCallArguments);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoCA,SAAc,aAAa,QAAQ,gBAAgB;AASnD;AAAA,EACE;AAAA,EAIA;AAAA,OACK;AA0KH;AAnKG,SAAS,WAAW,IAAyC;AAAzC,eAAE,WA1D7B,IA0D2B,IAAe,kB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AASE,WAAU,SAAS;AAC1B,4BAAsBA,QAAO,IAAI,IAAIA;AAAA,IACvC;AAEA,UAAM,SAAS,sBAAsB,aAAa,QAAQ,EAAE;AAC5D,QAAI,QAAQ;AACV,UAAI,wBAA+C,CAAC;AACpD,UAAI,aAAa,WAAW;AAC1B,gCAAwB,KAAK,MAAM,aAAa,SAAS;AAAA,MAC3D;AACA,aAAO,MAAM,OAAO,QAAQ,qBAAqB;AAAA,IACnD;AAAA,EACF;AACF;","names":["_a","_b","action"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
processMessageStream
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZFS5SQUT.mjs";
|
|
4
4
|
import {
|
|
5
5
|
defaultCopilotContextCategories
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-JWANHQCM.mjs";
|
|
7
7
|
import {
|
|
8
8
|
CopilotContext
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TW5FS2QT.mjs";
|
|
10
10
|
import {
|
|
11
11
|
__async,
|
|
12
12
|
__spreadValues
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
14
14
|
|
|
15
15
|
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
16
16
|
import { useContext, useMemo, useState } from "react";
|
|
@@ -134,4 +134,4 @@ export {
|
|
|
134
134
|
useCopilotChatV2,
|
|
135
135
|
defaultSystemMessage
|
|
136
136
|
};
|
|
137
|
-
//# sourceMappingURL=chunk-
|
|
137
|
+
//# sourceMappingURL=chunk-L3LL6N7J.mjs.map
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defaultCopilotContextCategories
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JWANHQCM.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useChat
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-32T4S22Q.mjs";
|
|
7
7
|
import {
|
|
8
8
|
CopilotContext
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TW5FS2QT.mjs";
|
|
10
10
|
import {
|
|
11
11
|
__objRest,
|
|
12
12
|
__spreadProps,
|
|
13
13
|
__spreadValues
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
15
15
|
|
|
16
16
|
// src/hooks/use-copilot-chat.ts
|
|
17
17
|
import { useMemo, useContext } from "react";
|
|
@@ -95,4 +95,4 @@ export {
|
|
|
95
95
|
useCopilotChat,
|
|
96
96
|
defaultSystemMessage
|
|
97
97
|
};
|
|
98
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# sourceMappingURL=chunk-S2YA76YW.mjs.map
|
|
@@ -17,6 +17,7 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|
20
21
|
var __objRest = (source, exclude) => {
|
|
21
22
|
var target = {};
|
|
22
23
|
for (var prop in source)
|
|
@@ -53,7 +54,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
53
54
|
export {
|
|
54
55
|
__spreadValues,
|
|
55
56
|
__spreadProps,
|
|
57
|
+
__restKey,
|
|
56
58
|
__objRest,
|
|
57
59
|
__async
|
|
58
60
|
};
|
|
59
|
-
//# sourceMappingURL=chunk-
|
|
61
|
+
//# sourceMappingURL=chunk-SKC7AJIV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defaultCopilotContextCategories
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JWANHQCM.mjs";
|
|
4
4
|
import {
|
|
5
5
|
fetchAndDecodeChatCompletion
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7YTDTTX5.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__async
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
10
10
|
|
|
11
11
|
// src/lib/copilot-task.ts
|
|
12
12
|
var CopilotTask = class {
|
|
@@ -16,6 +16,11 @@ var CopilotTask = class {
|
|
|
16
16
|
this.includeCopilotReadable = config.includeCopilotReadable !== false;
|
|
17
17
|
this.includeCopilotActions = config.includeCopilotActions !== false && config.includeCopilotActionable !== false;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Run the task.
|
|
21
|
+
* @param context The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.
|
|
22
|
+
* @param data The data to use for the task.
|
|
23
|
+
*/
|
|
19
24
|
run(context, data) {
|
|
20
25
|
return __async(this, null, function* () {
|
|
21
26
|
const entryPoints = this.includeCopilotActions ? Object.assign({}, context.entryPoints) : {};
|
|
@@ -99,4 +104,4 @@ ${instructions}
|
|
|
99
104
|
export {
|
|
100
105
|
CopilotTask
|
|
101
106
|
};
|
|
102
|
-
//# sourceMappingURL=chunk-
|
|
107
|
+
//# sourceMappingURL=chunk-T6UD6AJ2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/copilot-task.ts"],"sourcesContent":["/**\n * Execute one-off tasks using Copilot intelligence.\n *\n * <img referrerPolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be\" />\n *\n * This class is used to execute one-off tasks, for example on button press. It\n * can use the context available via [useCopilotReadable](../useCopilotReadable)\n * and the actions provided by [useCopilotAction](../useCopilotAction), or\n * you can provide your own context and actions.\n *\n * <RequestExample>\n * ```jsx CopilotTask Example\n * import {\n * CopilotTask,\n * useCopilotContext\n * } from \"@copilotkit/react-core\";\n *\n * const task = new CopilotTask({\n * instructions: \"Set a random message\",\n * actions: [\n * {\n * name: \"setMessage\",\n * description: \"Set the message.\",\n * argumentAnnotations: [\n * {\n * name: \"message\",\n * type: \"string\",\n * description:\n * \"A message to display.\",\n * required: true,\n * },\n * ],\n *\n * implementation: async (message) => {\n * // ...\n * },\n * }\n * ]\n * });\n * const context = useCopilotContext();\n * await task.run(context);\n * ```\n * </RequestExample>\n *\n * In the simplest case, use CopilotTask in the context of your app by giving it instructions on what to do.\n *\n * ```jsx\n * import {\n * CopilotTask,\n * useCopilotContext\n * } from \"@copilotkit/react-core\";\n *\n * const randomSlideTask = new CopilotTask({\n * instructions: \"Make a random slide\",\n * });\n *\n * const context = useCopilotContext();\n *\n * return (\n * <button onClick={() => randomSlideTask.run(context)}>\n * Make a random slide\n * </button>\n * );\n * ```\n *\n * Have a look at the [Presentation example](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/examples/next-openai/src/app/presentation/page.tsx)\n * for a more complete example.\n *\n * It's also possible to provide your own context and actions. In addition, you can specify to ignore\n * `useCopilotReadable` and `useCopilotAction`.\n *\n * ```jsx\n * import {\n * CopilotTask,\n * useCopilotContext\n * } from \"@copilotkit/react-core\";\n *\n * const standaloneTask = new CopilotTask({\n * instructions: \"Do something standalone\",\n * data: [...],\n * actions: [...],\n * includeCopilotReadable: false, // Don't use current context\n * includeCopilotActions: false, // Don't use current actions\n * });\n *\n * const context = useCopilotContext();\n *\n * standaloneTask.run(context);\n * ```\n */\n\nimport { FunctionCall, Message } from \"@copilotkit/shared\";\nimport { FrontendAction } from \"../types/frontend-action\";\nimport { CopilotContextParams } from \"../context\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { fetchAndDecodeChatCompletion } from \"../utils/fetch-chat-completion\";\n\nexport interface CopilotTaskConfig {\n /**\n * The instructions to be given to the assistant.\n */\n instructions: string;\n /**\n * An array of action definitions that can be called.\n */\n actions?: FrontendAction<any>[];\n /**\n * Whether to include the copilot readable context in the task.\n */\n includeCopilotReadable?: boolean;\n\n /**\n * Whether to include actions defined via useCopilotAction in the task.\n * @deprecated Use the `includeCopilotActions` property instead.\n */\n includeCopilotActionable?: boolean;\n\n /**\n * Whether to include actions defined via useCopilotAction in the task.\n */\n includeCopilotActions?: boolean;\n}\n\nexport class CopilotTask<T = any> {\n private instructions: string;\n private actions: FrontendAction<any>[];\n private includeCopilotReadable: boolean;\n private includeCopilotActions: boolean;\n\n constructor(config: CopilotTaskConfig) {\n this.instructions = config.instructions;\n this.actions = config.actions || [];\n this.includeCopilotReadable = config.includeCopilotReadable !== false;\n this.includeCopilotActions =\n config.includeCopilotActions !== false && config.includeCopilotActionable !== false;\n }\n\n /**\n * Run the task.\n * @param context The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.\n * @param data The data to use for the task.\n */\n async run(context: CopilotContextParams, data?: T): Promise<void> {\n const entryPoints = this.includeCopilotActions ? Object.assign({}, context.entryPoints) : {};\n\n // merge functions into entry points\n for (const fn of this.actions) {\n entryPoints[fn.name] = fn;\n }\n\n let contextString = \"\";\n\n if (data) {\n contextString = (typeof data === \"string\" ? data : JSON.stringify(data)) + \"\\n\\n\";\n }\n\n if (this.includeCopilotReadable) {\n contextString += context.getContextString([], defaultCopilotContextCategories);\n }\n\n const systemMessage: Message = {\n id: \"system\",\n content: taskSystemMessage(contextString, this.instructions),\n role: \"system\",\n };\n\n const messages = [systemMessage];\n\n const response = await fetchAndDecodeChatCompletion({\n copilotConfig: context.copilotApiConfig,\n messages: messages,\n tools: context.getChatCompletionFunctionDescriptions(entryPoints),\n headers: context.copilotApiConfig.headers,\n body: context.copilotApiConfig.body,\n });\n\n if (!response.events) {\n throw new Error(\"Failed to execute task\");\n }\n\n const reader = response.events.getReader();\n let functionCalls: FunctionCall[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n break;\n }\n\n if (value.type === \"function\") {\n functionCalls.push({\n name: value.name,\n arguments: JSON.stringify(value.arguments),\n });\n break;\n }\n }\n\n if (!functionCalls.length) {\n throw new Error(\"No function call occurred\");\n }\n\n const functionCallHandler = context.getFunctionCallHandler(entryPoints);\n for (const functionCall of functionCalls) {\n await functionCallHandler(messages, functionCall);\n }\n }\n}\n\nfunction taskSystemMessage(contextString: string, instructions: 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.\n\nPlease assist them as best you can.\n\nThis is not a conversation, so please do not ask questions. Just call a function without saying anything else.\n\nThe user has given you the following task to complete:\n\n\\`\\`\\`\n${instructions}\n\\`\\`\\`\n`;\n}\n"],"mappings":";;;;;;;;;;;AA2HO,IAAM,cAAN,MAA2B;AAAA,EAMhC,YAAY,QAA2B;AACrC,SAAK,eAAe,OAAO;AAC3B,SAAK,UAAU,OAAO,WAAW,CAAC;AAClC,SAAK,yBAAyB,OAAO,2BAA2B;AAChE,SAAK,wBACH,OAAO,0BAA0B,SAAS,OAAO,6BAA6B;AAAA,EAClF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOM,IAAI,SAA+B,MAAyB;AAAA;AAChE,YAAM,cAAc,KAAK,wBAAwB,OAAO,OAAO,CAAC,GAAG,QAAQ,WAAW,IAAI,CAAC;AAG3F,iBAAW,MAAM,KAAK,SAAS;AAC7B,oBAAY,GAAG,IAAI,IAAI;AAAA,MACzB;AAEA,UAAI,gBAAgB;AAEpB,UAAI,MAAM;AACR,yBAAiB,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,IAAI,KAAK;AAAA,MAC7E;AAEA,UAAI,KAAK,wBAAwB;AAC/B,yBAAiB,QAAQ,iBAAiB,CAAC,GAAG,+BAA+B;AAAA,MAC/E;AAEA,YAAM,gBAAyB;A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|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
4
4
|
|
|
5
5
|
// src/context/copilot-context.tsx
|
|
6
6
|
import React from "react";
|
|
@@ -37,7 +37,12 @@ var emptyCopilotContext = {
|
|
|
37
37
|
get body() {
|
|
38
38
|
return {};
|
|
39
39
|
}
|
|
40
|
-
}()
|
|
40
|
+
}(),
|
|
41
|
+
chatSuggestionConfiguration: {},
|
|
42
|
+
addChatSuggestionConfiguration: () => {
|
|
43
|
+
},
|
|
44
|
+
removeChatSuggestionConfiguration: () => {
|
|
45
|
+
}
|
|
41
46
|
};
|
|
42
47
|
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
43
48
|
function useCopilotContext() {
|
|
@@ -52,4 +57,4 @@ export {
|
|
|
52
57
|
CopilotContext,
|
|
53
58
|
useCopilotContext
|
|
54
59
|
};
|
|
55
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-TW5FS2QT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context/copilot-context.tsx"],"sourcesContent":["import {\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n ToolDefinition,\n} from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: 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 /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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 // suggestions configuration\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: 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 chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\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 chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\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"],"mappings":";;;;;AAOA,OAAO,WAAW;AAoHlB,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,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AAAA,EAEH,6BAA6B,CAAC;AAAA,EAC9B,gCAAgC,MAAM;AAAA,EAAC;AAAA,EACvC,mCAAmC,MAAM;AAAA,EAAC;AAC5C;AAEO,IAAM,iBAAiB,MAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,SAAO,MAAM,WAAW,cAAc;AACxC;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__spreadProps,
|
|
3
3
|
__spreadValues
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
5
5
|
|
|
6
6
|
// src/hooks/use-tree.ts
|
|
7
7
|
import { nanoid } from "nanoid";
|
|
@@ -137,4 +137,4 @@ function setsHaveIntersection(setA, setB) {
|
|
|
137
137
|
export {
|
|
138
138
|
use_tree_default
|
|
139
139
|
};
|
|
140
|
-
//# sourceMappingURL=chunk-
|
|
140
|
+
//# sourceMappingURL=chunk-YWITCRBI.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__async
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
4
4
|
|
|
5
5
|
// src/openai-assistants/utils/process-message-stream.ts
|
|
6
6
|
function processMessageStream(reader, processMessage) {
|
|
@@ -28,4 +28,4 @@ function processMessageStream(reader, processMessage) {
|
|
|
28
28
|
export {
|
|
29
29
|
processMessageStream
|
|
30
30
|
};
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
31
|
+
//# sourceMappingURL=chunk-ZFS5SQUT.mjs.map
|
|
@@ -5,11 +5,11 @@ import { ReactNode } from 'react';
|
|
|
5
5
|
*/
|
|
6
6
|
interface CopilotKitProps {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Your Copilot Cloud API key.
|
|
9
9
|
*/
|
|
10
10
|
publicApiKey?: string;
|
|
11
11
|
/**
|
|
12
|
-
* Cloud feature: Restrict to a specific topic.
|
|
12
|
+
* Cloud feature: Restrict input to a specific topic.
|
|
13
13
|
*/
|
|
14
14
|
cloudRestrictToTopic?: {
|
|
15
15
|
validTopics?: string[];
|
|
@@ -19,15 +19,23 @@ interface CopilotKitProps {
|
|
|
19
19
|
* the endpoint for the Copilot Runtime instance.
|
|
20
20
|
*/
|
|
21
21
|
runtimeUrl?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The endpoint for the Copilot transcribe audio service.
|
|
24
|
+
*/
|
|
25
|
+
transcribeAudioUrl?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The endpoint for the Copilot text to speech service.
|
|
28
|
+
*/
|
|
29
|
+
textToSpeechUrl?: string;
|
|
22
30
|
/**
|
|
23
31
|
* @deprecated use runtimeUrl instead
|
|
24
32
|
*/
|
|
25
33
|
url?: string;
|
|
26
34
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* ```
|
|
35
|
+
* Additional headers to be sent with the request.
|
|
36
|
+
*
|
|
37
|
+
* For example:
|
|
38
|
+
* ```js
|
|
31
39
|
* {
|
|
32
40
|
* 'Authorization': 'Bearer your_token_here'
|
|
33
41
|
* }
|
|
@@ -36,9 +44,8 @@ interface CopilotKitProps {
|
|
|
36
44
|
headers?: Record<string, string>;
|
|
37
45
|
/**
|
|
38
46
|
* Additional body params to be sent with the request
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* ```
|
|
47
|
+
* For example:
|
|
48
|
+
* ```js
|
|
42
49
|
* {
|
|
43
50
|
* 'message': 'Hello, world!'
|
|
44
51
|
* }
|
|
@@ -51,9 +58,8 @@ interface CopilotKitProps {
|
|
|
51
58
|
children: ReactNode;
|
|
52
59
|
/**
|
|
53
60
|
* Backend only props that will be combined to body params to be sent with the request
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* ```
|
|
61
|
+
* For example:
|
|
62
|
+
* ```js
|
|
57
63
|
* {
|
|
58
64
|
* 'user_id': 'users_id',
|
|
59
65
|
* }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/copilot-provider/copilotkit-props.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\n\n/**\n * Props for CopilotKit.\n */\n\nexport interface CopilotKitProps {\n /**\n *
|
|
1
|
+
{"version":3,"sources":["../../../src/components/copilot-provider/copilotkit-props.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\n\n/**\n * Props for CopilotKit.\n */\n\nexport interface CopilotKitProps {\n /**\n * Your Copilot Cloud API key.\n */\n publicApiKey?: string;\n\n /**\n * Cloud feature: Restrict input to a specific topic.\n */\n cloudRestrictToTopic?: {\n validTopics?: string[];\n invalidTopics?: string[];\n };\n\n /**\n * the endpoint for the Copilot Runtime instance.\n */\n runtimeUrl?: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * @deprecated use runtimeUrl instead\n */\n url?: string;\n\n /**\n * Additional headers to be sent with the request.\n *\n * For example:\n * ```js\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 * For example:\n * ```js\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body?: Record<string, any>;\n\n /**\n * The children to be rendered within the CopilotKit.\n */\n children: ReactNode;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * For example:\n * ```js\n * {\n * 'user_id': 'users_id',\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|