@copilotkit/react-core 1.1.3-feat-runtime-remote-actions.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -12
- package/dist/chunk-5JB4B2SV.mjs +1 -0
- package/dist/{chunk-HABY7NLH.mjs → chunk-AIW2RAN2.mjs} +6 -35
- package/dist/chunk-AIW2RAN2.mjs.map +1 -0
- package/dist/{chunk-RBNULK3U.mjs → chunk-CFCRJA63.mjs} +5 -39
- package/dist/chunk-CFCRJA63.mjs.map +1 -0
- package/dist/{chunk-3U22BXKC.mjs → chunk-EVK5346D.mjs} +3 -4
- package/dist/chunk-EVK5346D.mjs.map +1 -0
- package/dist/{chunk-A37GANOW.mjs → chunk-GSL4ZHUB.mjs} +4 -4
- package/dist/chunk-GSL4ZHUB.mjs.map +1 -0
- package/dist/{chunk-TCZBK3HZ.mjs → chunk-HUC6EZVP.mjs} +4 -7
- package/dist/chunk-HUC6EZVP.mjs.map +1 -0
- package/dist/{chunk-CODXG6KU.mjs → chunk-LB53QWLY.mjs} +2 -2
- package/dist/{chunk-J2YXDQHR.mjs → chunk-LB7ULLSU.mjs} +3 -14
- package/dist/chunk-LB7ULLSU.mjs.map +1 -0
- package/dist/{chunk-XSZDVRPW.mjs → chunk-PZOEBYWP.mjs} +11 -62
- package/dist/chunk-PZOEBYWP.mjs.map +1 -0
- package/dist/{chunk-326LK7LX.mjs → chunk-QR4XKQOA.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -4
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.js +5 -50
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +2 -2
- package/dist/components/copilot-provider/index.js +5 -50
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +5 -50
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +2 -21
- package/dist/context/copilot-context.js +2 -13
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +0 -2
- package/dist/context/index.js +2 -13
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/index.js +21 -223
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +12 -21
- package/dist/hooks/use-chat.d.ts +4 -26
- package/dist/hooks/use-chat.js +9 -57
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-copilot-action.js +4 -15
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-chat.js +13 -100
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +4 -4
- package/dist/hooks/use-copilot-readable.js +2 -13
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +2 -13
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +0 -4
- package/dist/index.js +31 -267
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -24
- package/dist/lib/copilot-task.d.ts +0 -2
- package/dist/lib/copilot-task.js +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +3 -3
- package/dist/lib/index.d.ts +0 -2
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +3 -3
- package/dist/utils/extract.d.ts +0 -2
- package/dist/utils/extract.js +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +3 -3
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +3 -3
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +0 -5
- package/src/components/copilot-provider/copilotkit.tsx +3 -45
- package/src/context/copilot-context.tsx +2 -39
- package/src/hooks/index.ts +0 -2
- package/src/hooks/use-chat.ts +11 -106
- package/src/hooks/use-copilot-action.ts +2 -2
- package/src/hooks/use-copilot-chat.ts +0 -31
- package/src/lib/copilot-task.ts +1 -2
- package/src/utils/extract.ts +2 -7
- package/dist/chunk-3U22BXKC.mjs.map +0 -1
- package/dist/chunk-A37GANOW.mjs.map +0 -1
- package/dist/chunk-BWYAGPEF.mjs +0 -1
- package/dist/chunk-HABY7NLH.mjs.map +0 -1
- package/dist/chunk-J2YXDQHR.mjs.map +0 -1
- package/dist/chunk-Q4TTTAXQ.mjs +0 -87
- package/dist/chunk-Q4TTTAXQ.mjs.map +0 -1
- package/dist/chunk-RBNULK3U.mjs.map +0 -1
- package/dist/chunk-STUXJ3BN.mjs +0 -44
- package/dist/chunk-STUXJ3BN.mjs.map +0 -1
- package/dist/chunk-TCZBK3HZ.mjs.map +0 -1
- package/dist/chunk-XSZDVRPW.mjs.map +0 -1
- package/dist/hooks/use-coagent-action.d.ts +0 -5
- package/dist/hooks/use-coagent-action.js +0 -156
- package/dist/hooks/use-coagent-action.js.map +0 -1
- package/dist/hooks/use-coagent-action.mjs +0 -9
- package/dist/hooks/use-coagent-action.mjs.map +0 -1
- package/dist/hooks/use-coagent.d.ts +0 -27
- package/dist/hooks/use-coagent.js +0 -219
- package/dist/hooks/use-coagent.js.map +0 -1
- package/dist/hooks/use-coagent.mjs +0 -10
- package/dist/hooks/use-coagent.mjs.map +0 -1
- package/dist/types/coagent-action.d.ts +0 -17
- package/dist/types/coagent-action.js +0 -19
- package/dist/types/coagent-action.js.map +0 -1
- package/dist/types/coagent-action.mjs +0 -1
- package/dist/types/coagent-action.mjs.map +0 -1
- package/dist/types/coagent-state.d.ts +0 -11
- package/dist/types/coagent-state.js +0 -19
- package/dist/types/coagent-state.js.map +0 -1
- package/dist/types/coagent-state.mjs +0 -1
- package/dist/types/coagent-state.mjs.map +0 -1
- package/src/hooks/use-coagent-action.ts +0 -44
- package/src/hooks/use-coagent.ts +0 -133
- package/src/types/coagent-action.ts +0 -17
- package/src/types/coagent-state.ts +0 -9
- /package/dist/{chunk-BWYAGPEF.mjs.map → chunk-5JB4B2SV.mjs.map} +0 -0
- /package/dist/{chunk-CODXG6KU.mjs.map → chunk-LB53QWLY.mjs.map} +0 -0
- /package/dist/{chunk-326LK7LX.mjs.map → chunk-QR4XKQOA.mjs.map} +0 -0
package/dist/context/index.js
CHANGED
|
@@ -63,12 +63,7 @@ var emptyCopilotContext = {
|
|
|
63
63
|
},
|
|
64
64
|
removeAction: () => {
|
|
65
65
|
},
|
|
66
|
-
|
|
67
|
-
setCoagentAction: () => {
|
|
68
|
-
},
|
|
69
|
-
removeCoagentAction: () => {
|
|
70
|
-
},
|
|
71
|
-
chatComponentsCache: { current: { actions: {}, coagentActions: {} } },
|
|
66
|
+
chatComponentsCache: { current: {} },
|
|
72
67
|
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
73
68
|
addContext: () => "",
|
|
74
69
|
removeContext: () => {
|
|
@@ -101,13 +96,7 @@ var emptyCopilotContext = {
|
|
|
101
96
|
},
|
|
102
97
|
removeChatSuggestionConfiguration: () => {
|
|
103
98
|
},
|
|
104
|
-
showDevConsole: "auto"
|
|
105
|
-
coagentStates: {},
|
|
106
|
-
setCoagentStates: () => {
|
|
107
|
-
},
|
|
108
|
-
agentSession: null,
|
|
109
|
-
setAgentSession: () => {
|
|
110
|
-
}
|
|
99
|
+
showDevConsole: "auto"
|
|
111
100
|
};
|
|
112
101
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
113
102
|
function useCopilotContext() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport type { CopilotContextParams } from \"./copilot-context\";\nexport type { CopilotApiConfig } from \"./copilot-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\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\";\
|
|
1
|
+
{"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport type { CopilotContextParams } from \"./copilot-context\";\nexport type { CopilotApiConfig } from \"./copilot-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\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 * 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 * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // chat\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => 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\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 showDevConsole: \"auto\",\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,mBAAkB;AA+GlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,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,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,WAAW;AAAA,EACX,cAAc,MAAM,sBAAsB,KAAK;AAAA,EAE/C,kBAAkB;AAAA,EAClB,qBAAqB,MAAM,sBAAsB,EAAE;AAAA,EAEnD,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,IAEA,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;AAAA,EAC1C,gBAAgB;AAClB;AAEO,IAAM,iBAAiB,aAAAA,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;","names":["React"]}
|
package/dist/context/index.mjs
CHANGED
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './use-copilot-chat.js';
|
|
2
2
|
export { useCopilotAction } from './use-copilot-action.js';
|
|
3
|
-
export { useCoAgentAction } from './use-coagent-action.js';
|
|
4
3
|
export { useMakeCopilotDocumentReadable } from './use-make-copilot-document-readable.js';
|
|
5
4
|
export { UseChatHelpers } from './use-chat.js';
|
|
6
5
|
export { useCopilotReadable } from './use-copilot-readable.js';
|
|
7
|
-
export { useCoAgent } from './use-coagent.js';
|
|
8
6
|
import '@copilotkit/runtime-client-gql';
|
|
9
7
|
import '../types/system-message.js';
|
|
10
8
|
import '../types/frontend-action.js';
|
|
11
9
|
import '@copilotkit/shared';
|
|
12
10
|
import 'react';
|
|
13
|
-
import '../types/coagent-action.js';
|
|
14
11
|
import '../types/document-pointer.js';
|
|
15
12
|
import '../context/copilot-context.js';
|
|
16
13
|
import './use-tree.js';
|
|
17
14
|
import '../types/chat-suggestion-configuration.js';
|
|
18
|
-
import '../types/coagent-state.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -79,8 +79,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
79
79
|
// src/hooks/index.ts
|
|
80
80
|
var hooks_exports = {};
|
|
81
81
|
__export(hooks_exports, {
|
|
82
|
-
useCoAgent: () => useCoAgent,
|
|
83
|
-
useCoAgentAction: () => useCoAgentAction,
|
|
84
82
|
useCopilotAction: () => useCopilotAction,
|
|
85
83
|
useCopilotChat: () => useCopilotChat,
|
|
86
84
|
useCopilotReadable: () => useCopilotReadable,
|
|
@@ -99,12 +97,7 @@ var emptyCopilotContext = {
|
|
|
99
97
|
},
|
|
100
98
|
removeAction: () => {
|
|
101
99
|
},
|
|
102
|
-
|
|
103
|
-
setCoagentAction: () => {
|
|
104
|
-
},
|
|
105
|
-
removeCoagentAction: () => {
|
|
106
|
-
},
|
|
107
|
-
chatComponentsCache: { current: { actions: {}, coagentActions: {} } },
|
|
100
|
+
chatComponentsCache: { current: {} },
|
|
108
101
|
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
109
102
|
addContext: () => "",
|
|
110
103
|
removeContext: () => {
|
|
@@ -137,13 +130,7 @@ var emptyCopilotContext = {
|
|
|
137
130
|
},
|
|
138
131
|
removeChatSuggestionConfiguration: () => {
|
|
139
132
|
},
|
|
140
|
-
showDevConsole: "auto"
|
|
141
|
-
coagentStates: {},
|
|
142
|
-
setCoagentStates: () => {
|
|
143
|
-
},
|
|
144
|
-
agentSession: null,
|
|
145
|
-
setAgentSession: () => {
|
|
146
|
-
}
|
|
133
|
+
showDevConsole: "auto"
|
|
147
134
|
};
|
|
148
135
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
149
136
|
function useCopilotContext() {
|
|
@@ -175,12 +162,7 @@ function useChat(options) {
|
|
|
175
162
|
initialMessages,
|
|
176
163
|
isLoading,
|
|
177
164
|
actions,
|
|
178
|
-
onFunctionCall
|
|
179
|
-
onCoagentAction,
|
|
180
|
-
setCoagentStates,
|
|
181
|
-
coagentStates,
|
|
182
|
-
agentSession,
|
|
183
|
-
setAgentSession
|
|
165
|
+
onFunctionCall
|
|
184
166
|
} = options;
|
|
185
167
|
const abortControllerRef = (0, import_react2.useRef)();
|
|
186
168
|
const threadIdRef = (0, import_react2.useRef)(null);
|
|
@@ -209,7 +191,7 @@ function useChat(options) {
|
|
|
209
191
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
210
192
|
const stream = import_runtime_client_gql.CopilotRuntimeClient.asStream(
|
|
211
193
|
runtimeClient.generateCopilotResponse({
|
|
212
|
-
data: __spreadProps(__spreadValues(
|
|
194
|
+
data: __spreadProps(__spreadValues({
|
|
213
195
|
frontend: {
|
|
214
196
|
actions: actions.map((action) => ({
|
|
215
197
|
name: action.name,
|
|
@@ -220,7 +202,7 @@ function useChat(options) {
|
|
|
220
202
|
},
|
|
221
203
|
threadId: threadIdRef.current,
|
|
222
204
|
runId: runIdRef.current,
|
|
223
|
-
messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(
|
|
205
|
+
messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messagesWithContext)
|
|
224
206
|
}, copilotConfig.cloud ? {
|
|
225
207
|
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
226
208
|
guardrails: {
|
|
@@ -234,13 +216,6 @@ function useChat(options) {
|
|
|
234
216
|
metadata: {
|
|
235
217
|
requestType: import_runtime_client_gql.CopilotRequestType.Chat
|
|
236
218
|
}
|
|
237
|
-
}), agentSession ? {
|
|
238
|
-
agentSession
|
|
239
|
-
} : {}), {
|
|
240
|
-
agentStates: Object.values(coagentStates).map((state) => ({
|
|
241
|
-
agentName: state.name,
|
|
242
|
-
state: JSON.stringify(state.state)
|
|
243
|
-
}))
|
|
244
219
|
}),
|
|
245
220
|
properties: copilotConfig.properties,
|
|
246
221
|
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
@@ -248,8 +223,7 @@ function useChat(options) {
|
|
|
248
223
|
);
|
|
249
224
|
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
250
225
|
const reader = stream.getReader();
|
|
251
|
-
let
|
|
252
|
-
let executedCoagentActions = [];
|
|
226
|
+
let results = {};
|
|
253
227
|
try {
|
|
254
228
|
while (true) {
|
|
255
229
|
const { done, value } = yield reader.read();
|
|
@@ -261,9 +235,7 @@ function useChat(options) {
|
|
|
261
235
|
}
|
|
262
236
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
263
237
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
264
|
-
const messages2 = (0, import_runtime_client_gql.convertGqlOutputToMessages)(
|
|
265
|
-
(0, import_runtime_client_gql.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
266
|
-
);
|
|
238
|
+
const messages2 = (0, import_runtime_client_gql.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
|
|
267
239
|
if (messages2.length === 0) {
|
|
268
240
|
continue;
|
|
269
241
|
}
|
|
@@ -278,30 +250,8 @@ function useChat(options) {
|
|
|
278
250
|
} else {
|
|
279
251
|
for (const message of messages2) {
|
|
280
252
|
newMessages.push(message);
|
|
281
|
-
if (message instanceof import_runtime_client_gql.AgentStateMessage) {
|
|
282
|
-
if (message.running) {
|
|
283
|
-
setCoagentStates((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
284
|
-
[message.agentName]: {
|
|
285
|
-
name: message.agentName,
|
|
286
|
-
state: message.state,
|
|
287
|
-
running: message.running,
|
|
288
|
-
active: message.active,
|
|
289
|
-
threadId: message.threadId,
|
|
290
|
-
nodeName: message.nodeName,
|
|
291
|
-
runId: message.runId
|
|
292
|
-
}
|
|
293
|
-
}));
|
|
294
|
-
setAgentSession({
|
|
295
|
-
threadId: message.threadId,
|
|
296
|
-
agentName: message.agentName,
|
|
297
|
-
nodeName: message.nodeName
|
|
298
|
-
});
|
|
299
|
-
} else {
|
|
300
|
-
setAgentSession(null);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
253
|
if (message instanceof import_runtime_client_gql.ActionExecutionMessage && message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
304
|
-
if (!(message.id in
|
|
254
|
+
if (!(message.id in results)) {
|
|
305
255
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
306
256
|
break;
|
|
307
257
|
}
|
|
@@ -310,27 +260,16 @@ function useChat(options) {
|
|
|
310
260
|
name: message.name,
|
|
311
261
|
args: message.arguments
|
|
312
262
|
});
|
|
313
|
-
|
|
263
|
+
results[message.id] = result;
|
|
314
264
|
}
|
|
315
265
|
newMessages.push(
|
|
316
266
|
new import_runtime_client_gql.ResultMessage({
|
|
317
|
-
result: import_runtime_client_gql.ResultMessage.encodeResult(
|
|
267
|
+
result: import_runtime_client_gql.ResultMessage.encodeResult(results[message.id]),
|
|
318
268
|
actionExecutionId: message.id,
|
|
319
269
|
actionName: message.name
|
|
320
270
|
})
|
|
321
271
|
);
|
|
322
272
|
}
|
|
323
|
-
if (message instanceof import_runtime_client_gql.AgentStateMessage && !message.active && !executedCoagentActions.includes(message.id) && onCoagentAction) {
|
|
324
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
yield onCoagentAction({
|
|
328
|
-
name: message.agentName,
|
|
329
|
-
nodeName: message.nodeName,
|
|
330
|
-
state: message.state
|
|
331
|
-
});
|
|
332
|
-
executedCoagentActions.push(message.id);
|
|
333
|
-
}
|
|
334
273
|
}
|
|
335
274
|
}
|
|
336
275
|
if (newMessages.length > 0) {
|
|
@@ -339,7 +278,7 @@ function useChat(options) {
|
|
|
339
278
|
}
|
|
340
279
|
if (
|
|
341
280
|
// if we have client side results
|
|
342
|
-
Object.values(
|
|
281
|
+
Object.values(results).length || // or the last message we received is a result
|
|
343
282
|
newMessages.length && newMessages[newMessages.length - 1] instanceof import_runtime_client_gql.ResultMessage
|
|
344
283
|
) {
|
|
345
284
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -408,12 +347,7 @@ function useCopilotChat(_a = {}) {
|
|
|
408
347
|
isLoading,
|
|
409
348
|
setIsLoading,
|
|
410
349
|
chatInstructions,
|
|
411
|
-
actions
|
|
412
|
-
coagentStates,
|
|
413
|
-
setCoagentStates,
|
|
414
|
-
coagentActions,
|
|
415
|
-
agentSession,
|
|
416
|
-
setAgentSession
|
|
350
|
+
actions
|
|
417
351
|
} = useCopilotContext();
|
|
418
352
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
419
353
|
const deleteMessage = (0, import_react4.useCallback)(
|
|
@@ -430,39 +364,16 @@ function useCopilotChat(_a = {}) {
|
|
|
430
364
|
role: import_runtime_client_gql2.Role.System
|
|
431
365
|
});
|
|
432
366
|
}, [getContextString, makeSystemMessage, chatInstructions]);
|
|
433
|
-
const onCoagentAction = (0, import_react4.useCallback)(
|
|
434
|
-
(args) => __async(this, null, function* () {
|
|
435
|
-
var _a2;
|
|
436
|
-
const { name, nodeName, state } = args;
|
|
437
|
-
let action = Object.values(coagentActions).find(
|
|
438
|
-
(action2) => action2.name === name && action2.nodeName === nodeName
|
|
439
|
-
);
|
|
440
|
-
if (!action) {
|
|
441
|
-
action = Object.values(coagentActions).find(
|
|
442
|
-
(action2) => action2.name === name && !action2.nodeName
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
if (action) {
|
|
446
|
-
yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
|
|
447
|
-
}
|
|
448
|
-
}),
|
|
449
|
-
[coagentActions]
|
|
450
|
-
);
|
|
451
367
|
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
452
368
|
actions: Object.values(actions),
|
|
453
369
|
copilotConfig: copilotApiConfig,
|
|
454
370
|
initialMessages: options.initialMessages || [],
|
|
455
371
|
onFunctionCall: getFunctionCallHandler(),
|
|
456
|
-
onCoagentAction,
|
|
457
372
|
messages,
|
|
458
373
|
setMessages,
|
|
459
374
|
makeSystemMessageCallback,
|
|
460
375
|
isLoading,
|
|
461
|
-
setIsLoading
|
|
462
|
-
coagentStates,
|
|
463
|
-
setCoagentStates,
|
|
464
|
-
agentSession,
|
|
465
|
-
setAgentSession
|
|
376
|
+
setIsLoading
|
|
466
377
|
}));
|
|
467
378
|
const latestAppend = useUpdatedRef(append);
|
|
468
379
|
const latestAppendFunc = (0, import_react4.useCallback)(
|
|
@@ -545,7 +456,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
545
456
|
actions[idRef.current].handler = action.handler;
|
|
546
457
|
if (typeof action.render === "function") {
|
|
547
458
|
if (chatComponentsCache.current !== null) {
|
|
548
|
-
chatComponentsCache.current
|
|
459
|
+
chatComponentsCache.current[action.name] = action.render;
|
|
549
460
|
}
|
|
550
461
|
}
|
|
551
462
|
}
|
|
@@ -556,7 +467,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
556
467
|
}
|
|
557
468
|
setAction(idRef.current, action);
|
|
558
469
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
559
|
-
chatComponentsCache.current
|
|
470
|
+
chatComponentsCache.current[action.name] = action.render;
|
|
560
471
|
}
|
|
561
472
|
return () => {
|
|
562
473
|
removeAction(idRef.current);
|
|
@@ -577,48 +488,12 @@ function useCopilotAction(action, dependencies) {
|
|
|
577
488
|
]);
|
|
578
489
|
}
|
|
579
490
|
|
|
580
|
-
// src/hooks/use-coagent-action.ts
|
|
581
|
-
var import_react6 = require("react");
|
|
582
|
-
var import_shared4 = require("@copilotkit/shared");
|
|
583
|
-
function useCoAgentAction(action, dependencies) {
|
|
584
|
-
const { setCoagentAction, removeCoagentAction, coagentActions, chatComponentsCache } = (0, import_react6.useContext)(CopilotContext);
|
|
585
|
-
const idRef = (0, import_react6.useRef)((0, import_shared4.randomId)());
|
|
586
|
-
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
587
|
-
if (dependencies === void 0) {
|
|
588
|
-
if (coagentActions[idRef.current]) {
|
|
589
|
-
coagentActions[idRef.current].handler = action.handler;
|
|
590
|
-
if (typeof action.render === "function") {
|
|
591
|
-
if (chatComponentsCache.current !== null) {
|
|
592
|
-
chatComponentsCache.current.coagentActions[key] = action.render;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
(0, import_react6.useEffect)(() => {
|
|
598
|
-
setCoagentAction(idRef.current, action);
|
|
599
|
-
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
600
|
-
chatComponentsCache.current.coagentActions[key] = action.render;
|
|
601
|
-
}
|
|
602
|
-
return () => {
|
|
603
|
-
removeCoagentAction(idRef.current);
|
|
604
|
-
};
|
|
605
|
-
}, [
|
|
606
|
-
setCoagentAction,
|
|
607
|
-
removeCoagentAction,
|
|
608
|
-
action.name,
|
|
609
|
-
// include render only if it's a string
|
|
610
|
-
typeof action.render === "string" ? action.render : void 0,
|
|
611
|
-
// dependencies set by the developer
|
|
612
|
-
...dependencies || []
|
|
613
|
-
]);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
491
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
617
|
-
var
|
|
492
|
+
var import_react6 = require("react");
|
|
618
493
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
619
494
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
620
|
-
const idRef = (0,
|
|
621
|
-
(0,
|
|
495
|
+
const idRef = (0, import_react6.useRef)();
|
|
496
|
+
(0, import_react6.useEffect)(() => {
|
|
622
497
|
const id = addDocumentContext(document, categories);
|
|
623
498
|
idRef.current = id;
|
|
624
499
|
return () => {
|
|
@@ -629,16 +504,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
629
504
|
}
|
|
630
505
|
|
|
631
506
|
// src/hooks/use-copilot-readable.ts
|
|
632
|
-
var
|
|
507
|
+
var import_react7 = require("react");
|
|
633
508
|
function convertToJSON(description, value) {
|
|
634
509
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
635
510
|
}
|
|
636
511
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
637
512
|
const { addContext, removeContext } = useCopilotContext();
|
|
638
|
-
const idRef = (0,
|
|
513
|
+
const idRef = (0, import_react7.useRef)();
|
|
639
514
|
convert = convert || convertToJSON;
|
|
640
515
|
const information = convert(description, value);
|
|
641
|
-
(0,
|
|
516
|
+
(0, import_react7.useEffect)(() => {
|
|
642
517
|
const id = addContext(information, parentId, categories);
|
|
643
518
|
idRef.current = id;
|
|
644
519
|
return () => {
|
|
@@ -647,85 +522,8 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
647
522
|
}, [information, parentId, addContext, removeContext, ...dependencies || []]);
|
|
648
523
|
return idRef.current;
|
|
649
524
|
}
|
|
650
|
-
|
|
651
|
-
// src/hooks/use-coagent.ts
|
|
652
|
-
var import_react9 = require("react");
|
|
653
|
-
function useCoAgent(options) {
|
|
654
|
-
const isExternalStateManagement = (options2) => {
|
|
655
|
-
return "state" in options2 && "setState" in options2;
|
|
656
|
-
};
|
|
657
|
-
const { name } = options;
|
|
658
|
-
const isInternalStateManagementWithInitial = (options2) => {
|
|
659
|
-
return "initialState" in options2;
|
|
660
|
-
};
|
|
661
|
-
const { coagentStates, setCoagentStates } = useCopilotContext();
|
|
662
|
-
const getCoagentState = (coagentStates2, name2) => {
|
|
663
|
-
if (coagentStates2[name2]) {
|
|
664
|
-
return coagentStates2[name2];
|
|
665
|
-
} else {
|
|
666
|
-
return {
|
|
667
|
-
name: name2,
|
|
668
|
-
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
669
|
-
running: false,
|
|
670
|
-
active: false,
|
|
671
|
-
threadId: void 0,
|
|
672
|
-
nodeName: void 0,
|
|
673
|
-
runId: void 0
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
const setState = (newState) => {
|
|
678
|
-
setCoagentStates((prevAgentStates) => {
|
|
679
|
-
let coagentState2 = getCoagentState(prevAgentStates, name);
|
|
680
|
-
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
681
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
682
|
-
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
683
|
-
state: updatedState
|
|
684
|
-
})
|
|
685
|
-
});
|
|
686
|
-
});
|
|
687
|
-
};
|
|
688
|
-
const coagentState = getCoagentState(coagentStates, name);
|
|
689
|
-
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
690
|
-
(0, import_react9.useEffect)(() => {
|
|
691
|
-
if (isExternalStateManagement(options)) {
|
|
692
|
-
setState(options.state);
|
|
693
|
-
} else if (coagentStates[name] === void 0) {
|
|
694
|
-
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
695
|
-
}
|
|
696
|
-
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
697
|
-
return {
|
|
698
|
-
name,
|
|
699
|
-
nodeName: coagentState.nodeName,
|
|
700
|
-
state,
|
|
701
|
-
setState,
|
|
702
|
-
running: coagentState.running,
|
|
703
|
-
start: () => {
|
|
704
|
-
startAgent(name);
|
|
705
|
-
},
|
|
706
|
-
stop: () => {
|
|
707
|
-
stopAgent(name);
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
function startAgent(name) {
|
|
712
|
-
const { setAgentSession } = useCopilotContext();
|
|
713
|
-
setAgentSession({
|
|
714
|
-
agentName: name
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
function stopAgent(name) {
|
|
718
|
-
const { agentSession, setAgentSession } = useCopilotContext();
|
|
719
|
-
if (agentSession && agentSession.agentName === name) {
|
|
720
|
-
setAgentSession(null);
|
|
721
|
-
} else {
|
|
722
|
-
console.warn(`No agent session found for ${name}`);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
525
|
// Annotate the CommonJS export names for ESM import in node:
|
|
726
526
|
0 && (module.exports = {
|
|
727
|
-
useCoAgent,
|
|
728
|
-
useCoAgentAction,
|
|
729
527
|
useCopilotAction,
|
|
730
528
|
useCopilotChat,
|
|
731
529
|
useCopilotReadable,
|