@copilotkit/react-core 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454
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/CHANGELOG.md +2001 -0
- package/README.md +48 -0
- package/dist/chunk-22XKTBPF.mjs +61 -0
- package/dist/chunk-22XKTBPF.mjs.map +1 -0
- package/dist/chunk-2KT73RVG.mjs +482 -0
- package/dist/chunk-2KT73RVG.mjs.map +1 -0
- package/dist/chunk-4TDYSNUD.mjs +215 -0
- package/dist/chunk-4TDYSNUD.mjs.map +1 -0
- package/dist/chunk-5FHSUKQL.mjs +70 -0
- package/dist/chunk-5FHSUKQL.mjs.map +1 -0
- package/dist/chunk-6BQVZFNO.mjs +35 -0
- package/dist/chunk-6BQVZFNO.mjs.map +1 -0
- package/dist/chunk-6U3UH3KO.mjs +140 -0
- package/dist/chunk-6U3UH3KO.mjs.map +1 -0
- package/dist/chunk-DCTJZ742.mjs +22 -0
- package/dist/chunk-DCTJZ742.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +1 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-EWKJMQOF.mjs +107 -0
- package/dist/chunk-EWKJMQOF.mjs.map +1 -0
- package/dist/chunk-FQ53HQYZ.mjs +28 -0
- package/dist/chunk-FQ53HQYZ.mjs.map +1 -0
- package/dist/chunk-HIUT2NLX.mjs +23 -0
- package/dist/chunk-HIUT2NLX.mjs.map +1 -0
- package/dist/chunk-KSPLXKSX.mjs +160 -0
- package/dist/chunk-KSPLXKSX.mjs.map +1 -0
- package/dist/chunk-LHKIIAUQ.mjs +59 -0
- package/dist/chunk-LHKIIAUQ.mjs.map +1 -0
- package/dist/chunk-LNI2Z45S.mjs +242 -0
- package/dist/chunk-LNI2Z45S.mjs.map +1 -0
- package/dist/chunk-LUGEI4YQ.mjs +1 -0
- package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
- package/dist/chunk-MLAS4QUR.mjs +18 -0
- package/dist/chunk-MLAS4QUR.mjs.map +1 -0
- package/dist/chunk-NR2BTA6Z.mjs +1 -0
- package/dist/chunk-NR2BTA6Z.mjs.map +1 -0
- package/dist/chunk-O7ARI5CV.mjs +31 -0
- package/dist/chunk-O7ARI5CV.mjs.map +1 -0
- package/dist/chunk-SKC7AJIV.mjs +61 -0
- package/dist/chunk-SKC7AJIV.mjs.map +1 -0
- package/dist/chunk-U6JICUGO.mjs +405 -0
- package/dist/chunk-U6JICUGO.mjs.map +1 -0
- package/dist/chunk-VNTDIJSG.mjs +37 -0
- package/dist/chunk-VNTDIJSG.mjs.map +1 -0
- package/dist/chunk-WXREY7UP.mjs +87 -0
- package/dist/chunk-WXREY7UP.mjs.map +1 -0
- package/dist/chunk-XERJQUHA.mjs +31 -0
- package/dist/chunk-XERJQUHA.mjs.map +1 -0
- package/dist/chunk-XOQMISG3.mjs +120 -0
- package/dist/chunk-XOQMISG3.mjs.map +1 -0
- package/dist/chunk-XXR4QFAQ.mjs +29 -0
- package/dist/chunk-XXR4QFAQ.mjs.map +1 -0
- package/dist/chunk-YPSGKPDA.mjs +1 -0
- package/dist/chunk-YPSGKPDA.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.d.ts +16 -0
- package/dist/components/copilot-provider/copilot-messages.js +80 -0
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.mjs +9 -0
- package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit-props.d.ts +93 -0
- package/dist/components/copilot-provider/copilotkit-props.js +19 -0
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
- package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
- package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.d.ts +18 -0
- package/dist/components/copilot-provider/copilotkit.js +990 -0
- package/dist/components/copilot-provider/copilotkit.js.map +1 -0
- package/dist/components/copilot-provider/copilotkit.mjs +22 -0
- package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
- package/dist/components/copilot-provider/index.d.ts +13 -0
- package/dist/components/copilot-provider/index.js +990 -0
- package/dist/components/copilot-provider/index.js.map +1 -0
- package/dist/components/copilot-provider/index.mjs +20 -0
- package/dist/components/copilot-provider/index.mjs.map +1 -0
- package/dist/components/error-boundary/error-boundary.d.ts +22 -0
- package/dist/components/error-boundary/error-boundary.js +183 -0
- package/dist/components/error-boundary/error-boundary.js.map +1 -0
- package/dist/components/error-boundary/error-boundary.mjs +12 -0
- package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
- package/dist/components/error-boundary/error-utils.d.ts +11 -0
- package/dist/components/error-boundary/error-utils.js +177 -0
- package/dist/components/error-boundary/error-utils.js.map +1 -0
- package/dist/components/error-boundary/error-utils.mjs +13 -0
- package/dist/components/error-boundary/error-utils.mjs.map +1 -0
- package/dist/components/index.d.ts +13 -0
- package/dist/components/index.js +990 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +20 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
- package/dist/components/toast/exclamation-mark-icon.js +55 -0
- package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
- package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
- package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
- package/dist/components/toast/toast-provider.d.ts +30 -0
- package/dist/components/toast/toast-provider.js +269 -0
- package/dist/components/toast/toast-provider.js.map +1 -0
- package/dist/components/toast/toast-provider.mjs +11 -0
- package/dist/components/toast/toast-provider.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +142 -0
- package/dist/context/copilot-context.js +138 -0
- package/dist/context/copilot-context.js.map +1 -0
- package/dist/context/copilot-context.mjs +10 -0
- package/dist/context/copilot-context.mjs.map +1 -0
- package/dist/context/copilot-messages-context.d.ts +15 -0
- package/dist/context/copilot-messages-context.js +57 -0
- package/dist/context/copilot-messages-context.js.map +1 -0
- package/dist/context/copilot-messages-context.mjs +10 -0
- package/dist/context/copilot-messages-context.mjs.map +1 -0
- package/dist/context/index.d.ts +11 -0
- package/dist/context/index.js +161 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +17 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/index.d.ts +21 -0
- package/dist/hooks/index.js +1307 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +56 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/use-chat.d.ts +130 -0
- package/dist/hooks/use-chat.js +612 -0
- package/dist/hooks/use-chat.js.map +1 -0
- package/dist/hooks/use-chat.mjs +12 -0
- package/dist/hooks/use-chat.mjs.map +1 -0
- package/dist/hooks/use-coagent-state-render.d.ts +60 -0
- package/dist/hooks/use-coagent-state-render.js +195 -0
- package/dist/hooks/use-coagent-state-render.js.map +1 -0
- package/dist/hooks/use-coagent-state-render.mjs +11 -0
- package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
- package/dist/hooks/use-coagent.d.ts +199 -0
- package/dist/hooks/use-coagent.js +1068 -0
- package/dist/hooks/use-coagent.js.map +1 -0
- package/dist/hooks/use-coagent.mjs +29 -0
- package/dist/hooks/use-coagent.mjs.map +1 -0
- package/dist/hooks/use-copilot-action.d.ts +140 -0
- package/dist/hooks/use-copilot-action.js +369 -0
- package/dist/hooks/use-copilot-action.js.map +1 -0
- package/dist/hooks/use-copilot-action.mjs +11 -0
- package/dist/hooks/use-copilot-action.mjs.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.d.ts +8 -0
- package/dist/hooks/use-copilot-authenticated-action.js +418 -0
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.mjs +12 -0
- package/dist/hooks/use-copilot-authenticated-action.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.d.ts +48 -0
- package/dist/hooks/use-copilot-chat.js +932 -0
- package/dist/hooks/use-copilot-chat.js.map +1 -0
- package/dist/hooks/use-copilot-chat.mjs +24 -0
- package/dist/hooks/use-copilot-chat.mjs.map +1 -0
- package/dist/hooks/use-copilot-readable.d.ts +33 -0
- package/dist/hooks/use-copilot-readable.js +158 -0
- package/dist/hooks/use-copilot-readable.js.map +1 -0
- package/dist/hooks/use-copilot-readable.mjs +9 -0
- package/dist/hooks/use-copilot-readable.mjs.map +1 -0
- package/dist/hooks/use-copilot-runtime-client.d.ts +5 -0
- package/dist/hooks/use-copilot-runtime-client.js +182 -0
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
- package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
- package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
- package/dist/hooks/use-flat-category-store.d.ts +9 -0
- package/dist/hooks/use-flat-category-store.js +90 -0
- package/dist/hooks/use-flat-category-store.js.map +1 -0
- package/dist/hooks/use-flat-category-store.mjs +8 -0
- package/dist/hooks/use-flat-category-store.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
- package/dist/hooks/use-make-copilot-document-readable.js +153 -0
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
- package/dist/hooks/use-tree.d.ts +18 -0
- package/dist/hooks/use-tree.js +172 -0
- package/dist/hooks/use-tree.js.map +1 -0
- package/dist/hooks/use-tree.mjs +8 -0
- package/dist/hooks/use-tree.mjs.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +2228 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +83 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/copilot-task.d.ts +97 -0
- package/dist/lib/copilot-task.js +195 -0
- package/dist/lib/copilot-task.js.map +1 -0
- package/dist/lib/copilot-task.mjs +20 -0
- package/dist/lib/copilot-task.mjs.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.js +197 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/index.mjs +21 -0
- package/dist/lib/index.mjs.map +1 -0
- 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/coagent-action.d.ts +29 -0
- package/dist/types/coagent-action.js +19 -0
- package/dist/types/coagent-action.js.map +1 -0
- package/dist/types/coagent-action.mjs +1 -0
- package/dist/types/coagent-action.mjs.map +1 -0
- package/dist/types/coagent-state.d.ts +11 -0
- package/dist/types/coagent-state.js +19 -0
- package/dist/types/coagent-state.js.map +1 -0
- package/dist/types/coagent-state.mjs +1 -0
- package/dist/types/coagent-state.mjs.map +1 -0
- package/dist/types/document-pointer.d.ts +9 -0
- package/dist/types/document-pointer.js +19 -0
- package/dist/types/document-pointer.js.map +1 -0
- package/dist/types/document-pointer.mjs +1 -0
- package/dist/types/document-pointer.mjs.map +1 -0
- package/dist/types/frontend-action.d.ts +126 -0
- package/dist/types/frontend-action.js +53 -0
- package/dist/types/frontend-action.js.map +1 -0
- package/dist/types/frontend-action.mjs +8 -0
- package/dist/types/frontend-action.mjs.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/system-message.d.ts +3 -0
- package/dist/types/system-message.js +19 -0
- package/dist/types/system-message.js.map +1 -0
- package/dist/types/system-message.mjs +1 -0
- package/dist/types/system-message.mjs.map +1 -0
- package/dist/utils/dev-console.d.ts +3 -0
- package/dist/utils/dev-console.js +42 -0
- package/dist/utils/dev-console.js.map +1 -0
- package/dist/utils/dev-console.mjs +8 -0
- package/dist/utils/dev-console.mjs.map +1 -0
- package/dist/utils/extract.d.ts +43 -0
- package/dist/utils/extract.js +208 -0
- package/dist/utils/extract.js.map +1 -0
- package/dist/utils/extract.mjs +18 -0
- package/dist/utils/extract.mjs.map +1 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +226 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +21 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/utils.d.ts +2 -0
- package/dist/utils/utils.js +19 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/utils.mjs +1 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/utils.test.d.ts +2 -0
- package/dist/utils/utils.test.js +9 -0
- package/dist/utils/utils.test.js.map +1 -0
- package/dist/utils/utils.test.mjs +7 -0
- package/dist/utils/utils.test.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +69 -0
- package/src/components/copilot-provider/copilot-messages.tsx +23 -0
- package/src/components/copilot-provider/copilotkit-props.tsx +97 -0
- package/src/components/copilot-provider/copilotkit.tsx +401 -0
- package/src/components/copilot-provider/index.ts +3 -0
- package/src/components/error-boundary/error-boundary.tsx +42 -0
- package/src/components/error-boundary/error-utils.tsx +95 -0
- package/src/components/index.ts +1 -0
- package/src/components/toast/exclamation-mark-icon.tsx +27 -0
- package/src/components/toast/toast-provider.tsx +170 -0
- package/src/context/copilot-context.tsx +271 -0
- package/src/context/copilot-messages-context.tsx +29 -0
- package/src/context/index.ts +8 -0
- package/src/hooks/index.ts +12 -0
- package/src/hooks/use-chat.ts +649 -0
- package/src/hooks/use-coagent-state-render.ts +118 -0
- package/src/hooks/use-coagent.ts +368 -0
- package/src/hooks/use-copilot-action.ts +289 -0
- package/src/hooks/use-copilot-authenticated-action.ts +60 -0
- package/src/hooks/use-copilot-chat.ts +304 -0
- package/src/hooks/use-copilot-readable.ts +123 -0
- package/src/hooks/use-copilot-runtime-client.ts +28 -0
- package/src/hooks/use-flat-category-store.ts +104 -0
- package/src/hooks/use-make-copilot-document-readable.ts +30 -0
- package/src/hooks/use-tree.ts +202 -0
- package/src/index.tsx +7 -0
- package/src/lib/copilot-task.ts +201 -0
- package/src/lib/index.ts +1 -0
- package/src/types/chat-suggestion-configuration.ts +23 -0
- package/src/types/coagent-action.ts +31 -0
- package/src/types/coagent-state.ts +9 -0
- package/src/types/document-pointer.ts +7 -0
- package/src/types/frontend-action.ts +199 -0
- package/src/types/index.ts +8 -0
- package/src/types/system-message.ts +4 -0
- package/src/utils/dev-console.ts +18 -0
- package/src/utils/extract.ts +215 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/utils.test.ts +7 -0
- package/src/utils/utils.ts +1 -0
- package/tsconfig.json +12 -0
- package/tsup.config.ts +16 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface CopilotChatSuggestionConfiguration {
|
|
2
|
+
/**
|
|
3
|
+
* A prompt or instructions for the GPT to generate suggestions.
|
|
4
|
+
*/
|
|
5
|
+
instructions: string;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The minimum number of suggestions to generate. Defaults to `1`.
|
|
9
|
+
* @default 1
|
|
10
|
+
*/
|
|
11
|
+
minSuggestions?: number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The maximum number of suggestions to generate. Defaults to `3`.
|
|
15
|
+
* @default 1
|
|
16
|
+
*/
|
|
17
|
+
maxSuggestions?: number;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An optional class name to apply to the suggestions.
|
|
21
|
+
*/
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type CoAgentStateRenderProps<T> = {
|
|
2
|
+
state: T;
|
|
3
|
+
nodeName: string;
|
|
4
|
+
status: "inProgress" | "complete";
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type CoAgentStateRenderHandlerArguments<T> = {
|
|
8
|
+
nodeName: string;
|
|
9
|
+
state: T;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export interface CoAgentStateRender<T = any> {
|
|
13
|
+
/**
|
|
14
|
+
* The name of the coagent.
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* The node name of the coagent.
|
|
19
|
+
*/
|
|
20
|
+
nodeName?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The handler function to handle the state of the agent.
|
|
23
|
+
*/
|
|
24
|
+
handler?: (props: CoAgentStateRenderHandlerArguments<T>) => void | Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* The render function to handle the state of the agent.
|
|
27
|
+
*/
|
|
28
|
+
render?:
|
|
29
|
+
| ((props: CoAgentStateRenderProps<T>) => string | React.ReactElement | undefined | null)
|
|
30
|
+
| string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { ActionInputAvailability } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
import {
|
|
3
|
+
Action,
|
|
4
|
+
Parameter,
|
|
5
|
+
MappedParameterTypes,
|
|
6
|
+
actionParametersToJsonSchema,
|
|
7
|
+
} from "@copilotkit/shared";
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
interface InProgressState<T extends Parameter[] | [] = []> {
|
|
11
|
+
status: "inProgress";
|
|
12
|
+
args: Partial<MappedParameterTypes<T>>;
|
|
13
|
+
result: undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ExecutingState<T extends Parameter[] | [] = []> {
|
|
17
|
+
status: "executing";
|
|
18
|
+
args: MappedParameterTypes<T>;
|
|
19
|
+
result: undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface CompleteState<T extends Parameter[] | [] = []> {
|
|
23
|
+
status: "complete";
|
|
24
|
+
args: MappedParameterTypes<T>;
|
|
25
|
+
result: any;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface InProgressStateNoArgs<T extends Parameter[] | [] = []> {
|
|
29
|
+
status: "inProgress";
|
|
30
|
+
args: Partial<MappedParameterTypes<T>>;
|
|
31
|
+
result: undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ExecutingStateNoArgs<T extends Parameter[] | [] = []> {
|
|
35
|
+
status: "executing";
|
|
36
|
+
args: MappedParameterTypes<T>;
|
|
37
|
+
result: undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface CompleteStateNoArgs<T extends Parameter[] | [] = []> {
|
|
41
|
+
status: "complete";
|
|
42
|
+
args: MappedParameterTypes<T>;
|
|
43
|
+
result: any;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface InProgressStateWait<T extends Parameter[] | [] = []> {
|
|
47
|
+
status: "inProgress";
|
|
48
|
+
args: Partial<MappedParameterTypes<T>>;
|
|
49
|
+
/** @deprecated use respond instead */
|
|
50
|
+
handler: undefined;
|
|
51
|
+
respond: undefined;
|
|
52
|
+
result: undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface ExecutingStateWait<T extends Parameter[] | [] = []> {
|
|
56
|
+
status: "executing";
|
|
57
|
+
args: MappedParameterTypes<T>;
|
|
58
|
+
/** @deprecated use respond instead */
|
|
59
|
+
handler: (result: any) => void;
|
|
60
|
+
respond: (result: any) => void;
|
|
61
|
+
result: undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface CompleteStateWait<T extends Parameter[] | [] = []> {
|
|
65
|
+
status: "complete";
|
|
66
|
+
args: MappedParameterTypes<T>;
|
|
67
|
+
/** @deprecated use respond instead */
|
|
68
|
+
handler: undefined;
|
|
69
|
+
respond: undefined;
|
|
70
|
+
result: any;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface InProgressStateNoArgsWait<T extends Parameter[] | [] = []> {
|
|
74
|
+
status: "inProgress";
|
|
75
|
+
args: Partial<MappedParameterTypes<T>>;
|
|
76
|
+
/** @deprecated use respond instead */
|
|
77
|
+
handler: undefined;
|
|
78
|
+
respond: undefined;
|
|
79
|
+
result: undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface ExecutingStateNoArgsWait<T extends Parameter[] | [] = []> {
|
|
83
|
+
status: "executing";
|
|
84
|
+
args: MappedParameterTypes<T>;
|
|
85
|
+
/** @deprecated use respond instead */
|
|
86
|
+
handler: (result: any) => void;
|
|
87
|
+
respond: (result: any) => void;
|
|
88
|
+
result: undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface CompleteStateNoArgsWait<T extends Parameter[] | [] = []> {
|
|
92
|
+
status: "complete";
|
|
93
|
+
args: MappedParameterTypes<T>;
|
|
94
|
+
/** @deprecated use respond instead */
|
|
95
|
+
handler: undefined;
|
|
96
|
+
respond: undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type ActionRenderProps<T extends Parameter[] | [] = []> =
|
|
100
|
+
| CompleteState<T>
|
|
101
|
+
| ExecutingState<T>
|
|
102
|
+
| InProgressState<T>;
|
|
103
|
+
|
|
104
|
+
export type ActionRenderPropsNoArgs<T extends Parameter[] | [] = []> =
|
|
105
|
+
| CompleteStateNoArgs<T>
|
|
106
|
+
| ExecutingStateNoArgs<T>
|
|
107
|
+
| InProgressStateNoArgs<T>;
|
|
108
|
+
|
|
109
|
+
export type ActionRenderPropsWait<T extends Parameter[] | [] = []> =
|
|
110
|
+
| CompleteStateWait<T>
|
|
111
|
+
| ExecutingStateWait<T>
|
|
112
|
+
| InProgressStateWait<T>;
|
|
113
|
+
|
|
114
|
+
export type ActionRenderPropsNoArgsWait<T extends Parameter[] | [] = []> =
|
|
115
|
+
| CompleteStateNoArgsWait<T>
|
|
116
|
+
| ExecutingStateNoArgsWait<T>
|
|
117
|
+
| InProgressStateNoArgsWait<T>;
|
|
118
|
+
|
|
119
|
+
export type CatchAllActionRenderProps<T extends Parameter[] | [] = []> =
|
|
120
|
+
| (CompleteState<T> & {
|
|
121
|
+
name: string;
|
|
122
|
+
})
|
|
123
|
+
| (ExecutingState<T> & {
|
|
124
|
+
name: string;
|
|
125
|
+
})
|
|
126
|
+
| (InProgressState<T> & {
|
|
127
|
+
name: string;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export type FrontendActionAvailability = "disabled" | "enabled" | "remote";
|
|
131
|
+
|
|
132
|
+
export type FrontendAction<
|
|
133
|
+
T extends Parameter[] | [] = [],
|
|
134
|
+
N extends string = string,
|
|
135
|
+
> = Action<T> & {
|
|
136
|
+
name: Exclude<N, "*">;
|
|
137
|
+
/**
|
|
138
|
+
* @deprecated Use `available` instead.
|
|
139
|
+
*/
|
|
140
|
+
disabled?: boolean;
|
|
141
|
+
available?: FrontendActionAvailability;
|
|
142
|
+
followUp?: boolean;
|
|
143
|
+
} & (
|
|
144
|
+
| {
|
|
145
|
+
render?:
|
|
146
|
+
| string
|
|
147
|
+
| (T extends []
|
|
148
|
+
? (props: ActionRenderPropsNoArgs<T>) => string | React.ReactElement
|
|
149
|
+
: (props: ActionRenderProps<T>) => string | React.ReactElement);
|
|
150
|
+
/** @deprecated use renderAndWaitForResponse instead */
|
|
151
|
+
renderAndWait?: never;
|
|
152
|
+
renderAndWaitForResponse?: never;
|
|
153
|
+
}
|
|
154
|
+
| {
|
|
155
|
+
render?: never;
|
|
156
|
+
/** @deprecated use renderAndWaitForResponse instead */
|
|
157
|
+
renderAndWait?: T extends []
|
|
158
|
+
? (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement
|
|
159
|
+
: (props: ActionRenderPropsWait<T>) => React.ReactElement;
|
|
160
|
+
renderAndWaitForResponse?: T extends []
|
|
161
|
+
? (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement
|
|
162
|
+
: (props: ActionRenderPropsWait<T>) => React.ReactElement;
|
|
163
|
+
handler?: never;
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
export type CatchAllFrontendAction = {
|
|
168
|
+
name: "*";
|
|
169
|
+
render: (props: CatchAllActionRenderProps<any>) => React.ReactElement;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type RenderFunctionStatus = ActionRenderProps<any>["status"];
|
|
173
|
+
|
|
174
|
+
export function processActionsForRuntimeRequest(actions: FrontendAction<any>[]) {
|
|
175
|
+
const filteredActions = actions
|
|
176
|
+
.filter(
|
|
177
|
+
(action) =>
|
|
178
|
+
action.available !== ActionInputAvailability.Disabled &&
|
|
179
|
+
action.disabled !== true &&
|
|
180
|
+
action.name !== "*",
|
|
181
|
+
)
|
|
182
|
+
.map((action) => {
|
|
183
|
+
let available: ActionInputAvailability | undefined = ActionInputAvailability.Enabled;
|
|
184
|
+
if (action.disabled) {
|
|
185
|
+
available = ActionInputAvailability.Disabled;
|
|
186
|
+
} else if (action.available === "disabled") {
|
|
187
|
+
available = ActionInputAvailability.Disabled;
|
|
188
|
+
} else if (action.available === "remote") {
|
|
189
|
+
available = ActionInputAvailability.Remote;
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
name: action.name,
|
|
193
|
+
description: action.description || "",
|
|
194
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
|
|
195
|
+
available,
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
return filteredActions;
|
|
199
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { DocumentPointer } from "./document-pointer";
|
|
2
|
+
export type { SystemMessageFunction } from "./system-message";
|
|
3
|
+
export type {
|
|
4
|
+
ActionRenderProps,
|
|
5
|
+
RenderFunctionStatus,
|
|
6
|
+
CatchAllActionRenderProps,
|
|
7
|
+
} from "./frontend-action";
|
|
8
|
+
export type { CopilotChatSuggestionConfiguration } from "./chat-suggestion-configuration";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function shouldShowDevConsole(showDevConsole: boolean | "auto"): boolean {
|
|
2
|
+
if (typeof showDevConsole === "boolean") {
|
|
3
|
+
return showDevConsole;
|
|
4
|
+
}
|
|
5
|
+
return (
|
|
6
|
+
getHostname() === "localhost" ||
|
|
7
|
+
getHostname() === "127.0.0.1" ||
|
|
8
|
+
getHostname() === "0.0.0.0" ||
|
|
9
|
+
getHostname() === "::1"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getHostname(): string {
|
|
14
|
+
if (typeof window !== "undefined" && window.location) {
|
|
15
|
+
return window.location.hostname;
|
|
16
|
+
}
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Action,
|
|
3
|
+
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
4
|
+
MappedParameterTypes,
|
|
5
|
+
Parameter,
|
|
6
|
+
actionParametersToJsonSchema,
|
|
7
|
+
} from "@copilotkit/shared";
|
|
8
|
+
import {
|
|
9
|
+
ActionExecutionMessage,
|
|
10
|
+
Message,
|
|
11
|
+
Role,
|
|
12
|
+
TextMessage,
|
|
13
|
+
convertGqlOutputToMessages,
|
|
14
|
+
CopilotRequestType,
|
|
15
|
+
ForwardedParametersInput,
|
|
16
|
+
} from "@copilotkit/runtime-client-gql";
|
|
17
|
+
import { CopilotContextParams, CopilotMessagesContextParams } from "../context";
|
|
18
|
+
import { defaultCopilotContextCategories } from "../components";
|
|
19
|
+
import { CopilotRuntimeClient } from "@copilotkit/runtime-client-gql";
|
|
20
|
+
import {
|
|
21
|
+
convertMessagesToGqlInput,
|
|
22
|
+
filterAgentStateMessages,
|
|
23
|
+
} from "@copilotkit/runtime-client-gql";
|
|
24
|
+
|
|
25
|
+
interface InitialState<T extends Parameter[] | [] = []> {
|
|
26
|
+
status: "initial";
|
|
27
|
+
args: Partial<MappedParameterTypes<T>>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface InProgressState<T extends Parameter[] | [] = []> {
|
|
31
|
+
status: "inProgress";
|
|
32
|
+
args: Partial<MappedParameterTypes<T>>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface CompleteState<T extends Parameter[] | [] = []> {
|
|
36
|
+
status: "complete";
|
|
37
|
+
args: MappedParameterTypes<T>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type StreamHandlerArgs<T extends Parameter[] | [] = []> =
|
|
41
|
+
| InitialState<T>
|
|
42
|
+
| InProgressState<T>
|
|
43
|
+
| CompleteState<T>;
|
|
44
|
+
|
|
45
|
+
interface ExtractOptions<T extends Parameter[]> {
|
|
46
|
+
context: CopilotContextParams & CopilotMessagesContextParams;
|
|
47
|
+
instructions: string;
|
|
48
|
+
parameters: T;
|
|
49
|
+
include?: IncludeOptions;
|
|
50
|
+
data?: any;
|
|
51
|
+
abortSignal?: AbortSignal;
|
|
52
|
+
stream?: (args: StreamHandlerArgs<T>) => void;
|
|
53
|
+
requestType?: CopilotRequestType;
|
|
54
|
+
forwardedParameters?: ForwardedParametersInput;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface IncludeOptions {
|
|
58
|
+
readable?: boolean;
|
|
59
|
+
messages?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function extract<const T extends Parameter[]>({
|
|
63
|
+
context,
|
|
64
|
+
instructions,
|
|
65
|
+
parameters,
|
|
66
|
+
include,
|
|
67
|
+
data,
|
|
68
|
+
abortSignal,
|
|
69
|
+
stream,
|
|
70
|
+
requestType = CopilotRequestType.Task,
|
|
71
|
+
forwardedParameters,
|
|
72
|
+
}: ExtractOptions<T>): Promise<MappedParameterTypes<T>> {
|
|
73
|
+
const { messages } = context;
|
|
74
|
+
|
|
75
|
+
const action: Action<any> = {
|
|
76
|
+
name: "extract",
|
|
77
|
+
description: instructions,
|
|
78
|
+
parameters,
|
|
79
|
+
handler: (args: any) => {},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const includeReadable = include?.readable ?? false;
|
|
83
|
+
const includeMessages = include?.messages ?? false;
|
|
84
|
+
|
|
85
|
+
let contextString = "";
|
|
86
|
+
|
|
87
|
+
if (data) {
|
|
88
|
+
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (includeReadable) {
|
|
92
|
+
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const systemMessage: Message = new TextMessage({
|
|
96
|
+
content: makeSystemMessage(contextString, instructions),
|
|
97
|
+
role: Role.System,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const instructionsMessage: Message = new TextMessage({
|
|
101
|
+
content: makeInstructionsMessage(instructions),
|
|
102
|
+
role: Role.User,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const response = context.runtimeClient.asStream(
|
|
106
|
+
context.runtimeClient.generateCopilotResponse({
|
|
107
|
+
data: {
|
|
108
|
+
frontend: {
|
|
109
|
+
actions: [
|
|
110
|
+
{
|
|
111
|
+
name: action.name,
|
|
112
|
+
description: action.description || "",
|
|
113
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
url: window.location.href,
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
messages: convertMessagesToGqlInput(
|
|
120
|
+
includeMessages
|
|
121
|
+
? [systemMessage, instructionsMessage, ...filterAgentStateMessages(messages)]
|
|
122
|
+
: [systemMessage, instructionsMessage],
|
|
123
|
+
),
|
|
124
|
+
metadata: {
|
|
125
|
+
requestType: requestType,
|
|
126
|
+
},
|
|
127
|
+
forwardedParameters: {
|
|
128
|
+
...(forwardedParameters ?? {}),
|
|
129
|
+
toolChoice: "function",
|
|
130
|
+
toolChoiceFunctionName: action.name,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
properties: context.copilotApiConfig.properties,
|
|
134
|
+
signal: abortSignal,
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const reader = response.getReader();
|
|
139
|
+
|
|
140
|
+
let isInitial = true;
|
|
141
|
+
|
|
142
|
+
let actionExecutionMessage: ActionExecutionMessage | undefined = undefined;
|
|
143
|
+
|
|
144
|
+
while (true) {
|
|
145
|
+
const { done, value } = await reader.read();
|
|
146
|
+
|
|
147
|
+
if (done) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (abortSignal?.aborted) {
|
|
152
|
+
throw new Error("Aborted");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
actionExecutionMessage = convertGqlOutputToMessages(
|
|
156
|
+
value.generateCopilotResponse.messages,
|
|
157
|
+
).find((msg) => msg.isActionExecutionMessage()) as ActionExecutionMessage | undefined;
|
|
158
|
+
|
|
159
|
+
if (!actionExecutionMessage) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
stream?.({
|
|
164
|
+
status: isInitial ? "initial" : "inProgress",
|
|
165
|
+
args: actionExecutionMessage.arguments as Partial<MappedParameterTypes<T>>,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
isInitial = false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!actionExecutionMessage) {
|
|
172
|
+
throw new Error("extract() failed: No function call occurred");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
stream?.({
|
|
176
|
+
status: "complete",
|
|
177
|
+
args: actionExecutionMessage.arguments as MappedParameterTypes<T>,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return actionExecutionMessage.arguments as MappedParameterTypes<T>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// We need to put this in a user message since some LLMs need
|
|
184
|
+
// at least one user message to function
|
|
185
|
+
function makeInstructionsMessage(instructions: string): string {
|
|
186
|
+
return `
|
|
187
|
+
The user has given you the following task to complete:
|
|
188
|
+
|
|
189
|
+
\`\`\`
|
|
190
|
+
${instructions}
|
|
191
|
+
\`\`\`
|
|
192
|
+
|
|
193
|
+
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
194
|
+
`;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function makeSystemMessage(contextString: string, instructions: string): string {
|
|
198
|
+
return `
|
|
199
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
200
|
+
|
|
201
|
+
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.
|
|
202
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
203
|
+
|
|
204
|
+
The user has provided you with the following context:
|
|
205
|
+
\`\`\`
|
|
206
|
+
${contextString}
|
|
207
|
+
\`\`\`
|
|
208
|
+
|
|
209
|
+
They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
|
|
210
|
+
|
|
211
|
+
Please assist them as best you can.
|
|
212
|
+
|
|
213
|
+
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
214
|
+
`;
|
|
215
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig, Options } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options: Options) => ({
|
|
4
|
+
entry: ["src/**/*.{ts,tsx}"],
|
|
5
|
+
format: ["esm", "cjs"],
|
|
6
|
+
dts: true,
|
|
7
|
+
minify: false,
|
|
8
|
+
external: ["react"],
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
exclude: [
|
|
11
|
+
"**/*.test.ts", // Exclude TypeScript test files
|
|
12
|
+
"**/*.test.tsx", // Exclude TypeScript React test files
|
|
13
|
+
"**/__tests__/*", // Exclude any files inside a __tests__ directory
|
|
14
|
+
],
|
|
15
|
+
...options,
|
|
16
|
+
}));
|
package/typedoc.json
ADDED