@copilotkit/react-core 1.50.0-beta.2 → 1.50.0-beta.4
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 +33 -0
- package/dist/{chunk-BPJ6V4YX.mjs → chunk-4HRUQH6U.mjs} +2 -2
- package/dist/{chunk-7BYHZLPL.mjs → chunk-4RRMC7L2.mjs} +4 -4
- package/dist/chunk-4RRMC7L2.mjs.map +1 -0
- package/dist/{chunk-D3QSYDJR.mjs → chunk-7IBF6RBW.mjs} +2 -2
- package/dist/{chunk-OVYFRPSN.mjs → chunk-ABWT4DRT.mjs} +2 -2
- package/dist/{chunk-WVLHXIFP.mjs → chunk-AFNWX62Q.mjs} +2 -2
- package/dist/{chunk-WVLHXIFP.mjs.map → chunk-AFNWX62Q.mjs.map} +1 -1
- package/dist/{chunk-LD3MGPZB.mjs → chunk-HE22TZMF.mjs} +2 -2
- package/dist/{chunk-EHXVGFWN.mjs → chunk-OX2QTNTD.mjs} +3 -3
- package/dist/{chunk-LHKZJ2ND.mjs → chunk-PMWUKW3Z.mjs} +3 -3
- package/dist/{chunk-OAEX7G5G.mjs → chunk-PQPWQ6GH.mjs} +2 -2
- package/dist/{chunk-TGIWTM6S.mjs → chunk-QNUAXSDP.mjs} +2 -2
- package/dist/{chunk-TGIWTM6S.mjs.map → chunk-QNUAXSDP.mjs.map} +1 -1
- package/dist/{chunk-ISNVEPPQ.mjs → chunk-VV56AVPB.mjs} +17 -7
- package/dist/chunk-VV56AVPB.mjs.map +1 -0
- package/dist/{chunk-6SK26J65.mjs → chunk-Y2L7KDVW.mjs} +2 -2
- package/dist/{chunk-WMJVBMUX.mjs → chunk-YCG6SNAU.mjs} +2 -2
- package/dist/{chunk-BR5YEYZJ.mjs → chunk-YTQHRJUA.mjs} +2 -2
- package/dist/{chunk-6F7Q6CPI.mjs → chunk-ZCV3A2FP.mjs} +4 -4
- package/dist/{chunk-SD7TUPQM.mjs → chunk-ZU6ZBX4E.mjs} +32 -37
- package/dist/chunk-ZU6ZBX4E.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +1 -1
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +26 -31
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +7 -7
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +26 -31
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +7 -7
- package/dist/components/dev-console/console-trigger.js +1 -1
- package/dist/components/dev-console/console-trigger.js.map +1 -1
- package/dist/components/dev-console/console-trigger.mjs +3 -3
- package/dist/components/dev-console/developer-console-modal.js +1 -1
- package/dist/components/dev-console/developer-console-modal.js.map +1 -1
- package/dist/components/dev-console/developer-console-modal.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +26 -31
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +7 -7
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +1 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-81022020.d.ts → copilot-context-ec77e921.d.ts} +2 -2
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +19 -9
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +11 -11
- package/dist/hooks/use-coagent-state-render-bridge.js +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.mjs +2 -2
- package/dist/hooks/use-coagent-state-render.js +1 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +1 -1
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +2 -2
- package/dist/hooks/use-copilot-chat-headless_c.js +17 -7
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +5 -5
- package/dist/hooks/use-copilot-chat.js +17 -7
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +5 -5
- package/dist/hooks/use-copilot-chat_internal.js +17 -7
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +4 -4
- package/dist/hooks/use-langgraph-interrupt-render.js +16 -6
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +3 -3
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- 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 +1 -1
- package/dist/index.js +43 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -17
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +8 -8
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +8 -8
- package/dist/types/index.d.ts +1 -1
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/v2/index.css +4 -0
- package/dist/v2/index.css.map +1 -0
- package/dist/v2/index.js.map +1 -1
- package/dist/v2/index.mjs +2 -0
- package/dist/v2/index.mjs.map +1 -1
- package/package.json +10 -8
- package/src/components/copilot-provider/copilotkit.tsx +30 -30
- package/src/context/copilot-context.tsx +2 -2
- package/src/hooks/use-coagent-state-render-bridge.tsx +2 -2
- package/src/hooks/use-langgraph-interrupt-render.ts +15 -5
- package/src/hooks/use-langgraph-interrupt.ts +2 -3
- package/src/types/interrupt-action.ts +1 -4
- package/src/v2/index.ts +2 -0
- package/tsup.config.ts +1 -1
- package/dist/chunk-7BYHZLPL.mjs.map +0 -1
- package/dist/chunk-ISNVEPPQ.mjs.map +0 -1
- package/dist/chunk-SD7TUPQM.mjs.map +0 -1
- /package/dist/{chunk-BPJ6V4YX.mjs.map → chunk-4HRUQH6U.mjs.map} +0 -0
- /package/dist/{chunk-D3QSYDJR.mjs.map → chunk-7IBF6RBW.mjs.map} +0 -0
- /package/dist/{chunk-OVYFRPSN.mjs.map → chunk-ABWT4DRT.mjs.map} +0 -0
- /package/dist/{chunk-LD3MGPZB.mjs.map → chunk-HE22TZMF.mjs.map} +0 -0
- /package/dist/{chunk-EHXVGFWN.mjs.map → chunk-OX2QTNTD.mjs.map} +0 -0
- /package/dist/{chunk-LHKZJ2ND.mjs.map → chunk-PMWUKW3Z.mjs.map} +0 -0
- /package/dist/{chunk-OAEX7G5G.mjs.map → chunk-PQPWQ6GH.mjs.map} +0 -0
- /package/dist/{chunk-6SK26J65.mjs.map → chunk-Y2L7KDVW.mjs.map} +0 -0
- /package/dist/{chunk-WMJVBMUX.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
- /package/dist/{chunk-BR5YEYZJ.mjs.map → chunk-YTQHRJUA.mjs.map} +0 -0
- /package/dist/{chunk-6F7Q6CPI.mjs.map → chunk-ZCV3A2FP.mjs.map} +0 -0
- /package/src/v2/{styles.css → index.css} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 1.50.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bad5f06: - feat: port old endpoint creators to 2.0
|
|
8
|
+
- 33f47e3: - fix: fix predictive state update
|
|
9
|
+
- fix: fix state setters
|
|
10
|
+
- 907ae5d: - feat: route CPK implementation to 2.0 copilotkitnext
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 8ce60af: - feat: enable coagent state renders
|
|
15
|
+
- 04057d5: - fix: refrain from adding placeholder message
|
|
16
|
+
- 2c93ff1: - fix: re-enable repeatable interrupt renders
|
|
17
|
+
- b0e3652: - chore: Update to latest of vnext
|
|
18
|
+
- 7643e71: - fix: make suggestions available
|
|
19
|
+
- d55a8bd: - feat(runtime): export v2 of the runtime as a subpackage
|
|
20
|
+
- fix(runtime): update method for merging tools in assignToolsToAgent
|
|
21
|
+
- fix: remove redundant agent instantiation code
|
|
22
|
+
- c38da1c: - feat: add suggestions support to 1.5
|
|
23
|
+
- 3c60073: - fix: better sync back-and-forth state, including initial state
|
|
24
|
+
- 962546c: - fix: resolve agent name directly from provider props
|
|
25
|
+
- ca8eb39: - fix: fix result arguments passed to tool calls
|
|
26
|
+
- c3d55e5: - fix: refactor interrupts mechanism to use a queue
|
|
27
|
+
- 5840bab: - fix: adjust dependencies
|
|
28
|
+
- 7808fac: - feat: add spinner indicator to show chat readiness for conversation
|
|
29
|
+
- c70210e: - feat: use copilotnext's single endpoint
|
|
30
|
+
- d2c57a1: - fix: export v2 styles
|
|
31
|
+
- Updated dependencies [b0e3652]
|
|
32
|
+
- Updated dependencies [4942f62]
|
|
33
|
+
- @copilotkit/runtime-client-gql@1.50.0-beta.4
|
|
34
|
+
- @copilotkit/shared@1.50.0-beta.4
|
|
35
|
+
|
|
3
36
|
## 1.10.7-next.0
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-EG56H77V.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useCopilotContext
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__spreadProps,
|
|
9
9
|
__spreadValues
|
|
@@ -56,4 +56,4 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
56
56
|
export {
|
|
57
57
|
useCopilotAuthenticatedAction_c
|
|
58
58
|
};
|
|
59
|
-
//# sourceMappingURL=chunk-
|
|
59
|
+
//# sourceMappingURL=chunk-4HRUQH6U.mjs.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-EFL5OBKN.mjs";
|
|
4
4
|
import {
|
|
5
5
|
CopilotContext
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__spreadProps,
|
|
9
9
|
__spreadValues
|
|
@@ -15,11 +15,11 @@ import { dataToUUID } from "@copilotkit/shared";
|
|
|
15
15
|
function useLangGraphInterrupt(action, dependencies) {
|
|
16
16
|
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = useContext(CopilotContext);
|
|
17
17
|
const { addToast } = useToast();
|
|
18
|
-
const actionId = dataToUUID(
|
|
18
|
+
const actionId = dataToUUID(action, "lgAction");
|
|
19
19
|
useEffect(() => {
|
|
20
20
|
if (!action)
|
|
21
21
|
return;
|
|
22
|
-
setInterruptAction(
|
|
22
|
+
setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
23
23
|
return () => {
|
|
24
24
|
removeInterruptAction(actionId);
|
|
25
25
|
};
|
|
@@ -29,4 +29,4 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
29
29
|
export {
|
|
30
30
|
useLangGraphInterrupt
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-4RRMC7L2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-langgraph-interrupt.ts"],"sourcesContent":["import { useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { LangGraphInterruptRender } from \"../types/interrupt-action\";\nimport { useToast } from \"../components/toast/toast-provider\";\nimport { dataToUUID } from \"@copilotkit/shared\";\n\nexport function useLangGraphInterrupt<TEventValue = any>(\n action: Omit<LangGraphInterruptRender<TEventValue>, \"id\">,\n dependencies?: any[],\n) {\n const { setInterruptAction, removeInterruptAction, interruptActions, threadId } =\n useContext(CopilotContext);\n const { addToast } = useToast();\n\n const actionId = dataToUUID(action, \"lgAction\");\n\n useEffect(() => {\n if (!action) return;\n\n // if (!action.enabled) {\n // TODO: if there are any other actions registered, we need to warn the user that a current action without \"enabled\" might render for everything\n // addToast({\n // type: \"warning\",\n // message: \"An action is already registered for the interrupt event\",\n // });\n // return;\n // }\n\n setInterruptAction({ ...action, id: actionId });\n\n // Cleanup: remove action on unmount\n return () => {\n removeInterruptAction(actionId);\n };\n }, [setInterruptAction, removeInterruptAction, threadId, actionId, ...(dependencies || [])]);\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,YAAY,iBAA0B;AAI/C,SAAS,kBAAkB;AAEpB,SAAS,sBACd,QACA,cACA;AACA,QAAM,EAAE,oBAAoB,uBAAuB,kBAAkB,SAAS,IAC5E,WAAW,cAAc;AAC3B,QAAM,EAAE,SAAS,IAAI,SAAS;AAE9B,QAAM,WAAW,WAAW,QAAQ,UAAU;AAE9C,YAAU,MAAM;AACd,QAAI,CAAC;AAAQ;AAWb,uBAAmB,iCAAK,SAAL,EAAa,IAAI,SAAS,EAAC;AAG9C,WAAO,MAAM;AACX,4BAAsB,QAAQ;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,UAAU,UAAU,GAAI,gBAAgB,CAAC,CAAE,CAAC;AAC7F;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCopilotContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
4
4
|
|
|
5
5
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
6
6
|
import { 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-7IBF6RBW.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCopilotContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
4
4
|
|
|
5
5
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
6
6
|
import { useEffect } from "react";
|
|
@@ -21,4 +21,4 @@ function useCopilotAdditionalInstructions({ instructions, available = "enabled"
|
|
|
21
21
|
export {
|
|
22
22
|
useCopilotAdditionalInstructions
|
|
23
23
|
};
|
|
24
|
-
//# sourceMappingURL=chunk-
|
|
24
|
+
//# sourceMappingURL=chunk-ABWT4DRT.mjs.map
|
|
@@ -78,7 +78,7 @@ var emptyCopilotContext = {
|
|
|
78
78
|
interruptEventQueue: {},
|
|
79
79
|
addInterruptEvent: () => {
|
|
80
80
|
},
|
|
81
|
-
|
|
81
|
+
resolveInterruptEvent: () => {
|
|
82
82
|
},
|
|
83
83
|
onError: () => {
|
|
84
84
|
},
|
|
@@ -107,4 +107,4 @@ export {
|
|
|
107
107
|
CopilotContext,
|
|
108
108
|
useCopilotContext
|
|
109
109
|
};
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
110
|
+
//# sourceMappingURL=chunk-AFNWX62Q.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/copilot-context.tsx"],"sourcesContent":["import {\n CopilotCloudConfig,\n FunctionCallHandler,\n CopilotErrorHandler,\n CopilotKitError,\n} from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\n CopilotRuntimeClient,\n ExtensionsInput,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\nimport {\n LangGraphInterruptRender,\n LangGraphInterruptActionSetter,\n QueuedInterruptEvent,\n} from \"../types/interrupt-action\";\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 /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | React.JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | React.JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface AuthState {\n status: \"authenticated\" | \"unauthenticated\";\n authHeaders: Record<string, string>;\n userId?: string;\n metadata?: Record<string, any>;\n}\n\nexport type ActionName = string;\nexport type ContextTree = Tree;\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\n // registered actions for component-based rendering\n setRegisteredActions: (actionConfig: any) => string;\n removeRegisteredAction: (actionKey: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\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 getAllContext: () => Tree;\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 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 additionalInstructions?: string[];\n setAdditionalInstructions: React.Dispatch<React.SetStateAction<string[]>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean;\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n setCoagentStatesWithRef: (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => void;\n\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string;\n setThreadId: React.Dispatch<React.SetStateAction<string>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Partial<Pick<ForwardedParametersInput, \"temperature\">>;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates_c?: Record<ActionName, AuthState>;\n setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n interruptActions: Record<string, LangGraphInterruptRender>;\n setInterruptAction: LangGraphInterruptActionSetter;\n removeInterruptAction: (actionId: string) => void;\n interruptEventQueue: Record<string, QueuedInterruptEvent[]>;\n addInterruptEvent: (queuedEvent: QueuedInterruptEvent) => void;\n removeInterruptEvent: (threadId: string, eventId: string) => void;\n\n /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onError: CopilotErrorHandler;\n\n // banner error state\n bannerError: CopilotKitError | null;\n setBannerError: React.Dispatch<React.SetStateAction<CopilotKitError | null>>;\n // Internal error handlers\n // These are used to handle errors that occur during the execution of the chat.\n // They are not intended for use by the developer. A component can register itself an error listener to be activated somewhere else as needed\n internalErrorHandlers: Record<string, CopilotErrorHandler>;\n setInternalErrorHandler: (handler: Record<string, CopilotErrorHandler>) => void;\n removeInternalErrorHandler: (id: string) => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n setRegisteredActions: () => \"\",\n removeRegisteredAction: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n getAllContext: () => [],\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n additionalInstructions: [],\n setAdditionalInstructions: () => 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: false,\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: \"\",\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\n extensions: {},\n setExtensions: () => {},\n interruptActions: {},\n setInterruptAction: () => {},\n removeInterruptAction: () => {},\n interruptEventQueue: {},\n addInterruptEvent: () => {},\n removeInterruptEvent: () => {},\n onError: () => {},\n bannerError: null,\n setBannerError: () => {},\n internalErrorHandlers: {},\n setInternalErrorHandler: () => {},\n removeInternalErrorHandler: () => {},\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}\n"],"mappings":";;;;;AAWA,OAAO,WAAW;AAuOlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,sBAAsB,MAAM;AAAA,EAC5B,wBAAwB,MAAM;AAAA,EAAC;AAAA,EAE/B,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,eAAe,MAAM,CAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MA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M;AAAA,EAAC;AAAA,EAC3B,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,qBAAqB,CAAC;AAAA,EACtB,mBAAmB,MAAM;AAAA,EAAC;AAAA,EAC1B,sBAAsB,MAAM;AAAA,EAAC;AAAA,EAC7B,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,aAAa;AAAA,EACb,gBAAgB,MAAM;AAAA,EAAC;AAAA,EACvB,uBAAuB,CAAC;AAAA,EACxB,yBAAyB,MAAM;AAAA,EAAC;AAAA,EAChC,4BAA4B,MAAM;AAAA,EAAC;AACrC;AAEO,IAAM,iBAAiB,MAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,MAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,QAAc;AAC9C,QAAM,IAAI,MAAM,uEAAuE;AACzF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/context/copilot-context.tsx"],"sourcesContent":["import {\n CopilotCloudConfig,\n FunctionCallHandler,\n CopilotErrorHandler,\n CopilotKitError,\n} from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\n CopilotRuntimeClient,\n ExtensionsInput,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\nimport {\n LangGraphInterruptRender,\n LangGraphInterruptActionSetter,\n QueuedInterruptEvent,\n} from \"../types/interrupt-action\";\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 /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | React.JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | React.JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface AuthState {\n status: \"authenticated\" | \"unauthenticated\";\n authHeaders: Record<string, string>;\n userId?: string;\n metadata?: Record<string, any>;\n}\n\nexport type ActionName = string;\nexport type ContextTree = Tree;\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\n // registered actions for component-based rendering\n setRegisteredActions: (actionConfig: any) => string;\n removeRegisteredAction: (actionKey: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\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 getAllContext: () => Tree;\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 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 additionalInstructions?: string[];\n setAdditionalInstructions: React.Dispatch<React.SetStateAction<string[]>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean;\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n setCoagentStatesWithRef: (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => void;\n\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string;\n setThreadId: React.Dispatch<React.SetStateAction<string>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Partial<Pick<ForwardedParametersInput, \"temperature\">>;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates_c?: Record<ActionName, AuthState>;\n setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n interruptActions: Record<string, LangGraphInterruptRender>;\n setInterruptAction: LangGraphInterruptActionSetter;\n removeInterruptAction: (actionId: string) => void;\n interruptEventQueue: Record<string, QueuedInterruptEvent[]>;\n addInterruptEvent: (queuedEvent: QueuedInterruptEvent) => void;\n resolveInterruptEvent: (threadId: string, eventId: string, response: string) => void;\n\n /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onError: CopilotErrorHandler;\n\n // banner error state\n bannerError: CopilotKitError | null;\n setBannerError: React.Dispatch<React.SetStateAction<CopilotKitError | null>>;\n // Internal error handlers\n // These are used to handle errors that occur during the execution of the chat.\n // They are not intended for use by the developer. A component can register itself an error listener to be activated somewhere else as needed\n internalErrorHandlers: Record<string, CopilotErrorHandler>;\n setInternalErrorHandler: (handler: Record<string, CopilotErrorHandler>) => void;\n removeInternalErrorHandler: (id: string) => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n setRegisteredActions: () => \"\",\n removeRegisteredAction: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n getAllContext: () => [],\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n additionalInstructions: [],\n setAdditionalInstructions: () => 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: false,\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: \"\",\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\n extensions: {},\n setExtensions: () => {},\n interruptActions: {},\n setInterruptAction: () => {},\n removeInterruptAction: () => {},\n interruptEventQueue: {},\n addInterruptEvent: () => {},\n resolveInterruptEvent: () => {},\n onError: () => {},\n bannerError: null,\n setBannerError: () => {},\n internalErrorHandlers: {},\n setInternalErrorHandler: () => {},\n removeInternalErrorHandler: () => {},\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>` !!!\");\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
} from "./chunk-
|
|
9
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
10
10
|
import {
|
|
11
11
|
CopilotMessagesContext
|
|
12
12
|
} from "./chunk-DMLQZG75.mjs";
|
|
@@ -183,4 +183,4 @@ export {
|
|
|
183
183
|
MessagesTapProvider,
|
|
184
184
|
CopilotMessages
|
|
185
185
|
};
|
|
186
|
-
//# sourceMappingURL=chunk-
|
|
186
|
+
//# sourceMappingURL=chunk-HE22TZMF.mjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCopilotChatInternal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZCV3A2FP.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useCopilotContext
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__async
|
|
9
9
|
} from "./chunk-SKC7AJIV.mjs";
|
|
@@ -83,4 +83,4 @@ function useCopilotChatHeadless_c(options = {}) {
|
|
|
83
83
|
export {
|
|
84
84
|
useCopilotChatHeadless_c
|
|
85
85
|
};
|
|
86
|
-
//# sourceMappingURL=chunk-
|
|
86
|
+
//# sourceMappingURL=chunk-OX2QTNTD.mjs.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DeveloperConsoleModal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YCG6SNAU.mjs";
|
|
4
4
|
import {
|
|
5
5
|
CopilotKitIcon
|
|
6
6
|
} from "./chunk-PIF5KJYI.mjs";
|
|
7
7
|
import {
|
|
8
8
|
useCopilotContext
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
10
10
|
|
|
11
11
|
// src/components/dev-console/console-trigger.tsx
|
|
12
12
|
import { useState, useEffect, useRef } from "react";
|
|
@@ -228,4 +228,4 @@ function ConsoleTrigger({ position = "bottom-right" }) {
|
|
|
228
228
|
export {
|
|
229
229
|
ConsoleTrigger
|
|
230
230
|
};
|
|
231
|
-
//# sourceMappingURL=chunk-
|
|
231
|
+
//# sourceMappingURL=chunk-PMWUKW3Z.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCopilotChatInternal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZCV3A2FP.mjs";
|
|
4
4
|
|
|
5
5
|
// src/hooks/use-copilot-chat.ts
|
|
6
6
|
function useCopilotChat(options = {}) {
|
|
@@ -33,4 +33,4 @@ function useCopilotChat(options = {}) {
|
|
|
33
33
|
export {
|
|
34
34
|
useCopilotChat
|
|
35
35
|
};
|
|
36
|
-
//# sourceMappingURL=chunk-
|
|
36
|
+
//# sourceMappingURL=chunk-PQPWQ6GH.mjs.map
|
|
@@ -85,7 +85,7 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
85
85
|
return canRender;
|
|
86
86
|
}
|
|
87
87
|
const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
|
|
88
|
-
(c) => c.stateRenderId === stateRenderId && dataToUUID(
|
|
88
|
+
(c) => c.stateRenderId === stateRenderId && dataToUUID(getStateWithoutConstantKeys(c.stateSnapshot)) === dataToUUID(getStateWithoutConstantKeys(renderSnapshot))
|
|
89
89
|
);
|
|
90
90
|
if (renderClaimedByOtherMessage) {
|
|
91
91
|
if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
|
|
@@ -163,4 +163,4 @@ export {
|
|
|
163
163
|
useCoagentStateRenderBridge,
|
|
164
164
|
CoAgentStateRenderBridge
|
|
165
165
|
};
|
|
166
|
-
//# sourceMappingURL=chunk-
|
|
166
|
+
//# sourceMappingURL=chunk-QNUAXSDP.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-coagent-state-render-bridge.tsx"],"sourcesContent":["import { ReactCustomMessageRendererPosition, useAgent } from \"@copilotkitnext/react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport type { AgentSubscriber } from \"@ag-ui/client\";\nimport { useCoAgentStateRenders } from \"../context\";\nimport { dataToUUID, parseJson } from \"@copilotkit/shared\";\n\nfunction getStateWithoutConstantKeys(state: any) {\n if (!state) return {};\n const { messages, tools, copilotkit, ...stateWithoutConstantKeys } = state;\n return stateWithoutConstantKeys;\n}\n\n// Function that compares states, without the constant keys\nfunction areStatesEquals(a: any, b: any) {\n if ((a && !b) || (!a && b)) return false;\n const { messages, tools, copilotkit, ...aWithoutConstantKeys } = a;\n const {\n messages: bMessages,\n tools: bTools,\n copilotkit: bCopilotkit,\n ...bWithoutConstantKeys\n } = b;\n\n return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);\n}\n\n/**\n * Bridge hook that connects agent state renders to chat messages.\n *\n * ## Purpose\n * This hook finds matching state render configurations (registered via useCoAgentStateRender)\n * and returns UI to render in chat.\n * It ensures each state render appears bound to a specific message, preventing duplicates while\n * allowing re-binding when the underlying state changes significantly.\n *\n * ## Message-ID-Based Claiming System\n *\n * ### The Problem\n * Multiple bridge component instances render simultaneously (one per message). Without coordination,\n * they would all try to render the same state render, causing duplicates.\n *\n * ### The Solution: Message-ID Claims with State Comparison\n * Each state render is \"claimed\" by exactly one **message ID** (not runId):\n *\n * **Claim Structure**: `claimsRef.current[messageId] = { stateRenderId, runId, stateSnapshot, locked }`\n *\n * **Primary binding is by messageId because**:\n * - runId is not always available immediately (starts as \"pending\")\n * - messageId is the stable identifier throughout the message lifecycle\n * - Claims persist across component remounts via context ref\n *\n * ### Claiming Logic Flow\n *\n * 1. **Message already has a claim**:\n * - Check if the claim matches the current stateRenderId\n * - If yes → render (this message owns this render)\n * - Update runId if it was \"pending\" and now available\n *\n * 2. **State render claimed by another message**:\n * - Compare state snapshots (ignoring constant keys: messages, tools, copilotkit)\n * - If states are identical → block rendering (duplicate)\n * - **If states are different → allow claiming** (new data, new message)\n * - This handles cases where the same render type shows different states in different messages\n *\n * 3. **Unclaimed state render**:\n * - Only allow claiming if runId is \"pending\" (initial render)\n * - If runId is real but no claim exists → block (edge case protection)\n * - Create new claim: `claimsRef.current[messageId] = { stateRenderId, runId }`\n *\n * ### State Snapshot Locking\n *\n * Once a state snapshot is captured and locked for a message:\n * - The UI always renders with the locked snapshot (not live agent.state)\n * - Prevents UI from appearing \"wiped\" during state transitions\n * - Locked when: stateSnapshot prop is available (from message persistence)\n * - Unlocked state: can still update from live agent.state\n *\n * ### Synchronous Claiming (Ref-based)\n *\n * Claims are stored in a context-level ref (not React state):\n * - Multiple bridges render in the same tick\n * - State updates are async - would allow duplicates before update completes\n * - Ref provides immediate, synchronous claim checking\n * - Survives component remounts (stored in context, not component)\n *\n * ## Flow Example\n *\n * ```\n * Time 1: Message A renders, runId=undefined, state={progress: 50%}\n * → effectiveRunId = \"pending\"\n * → Claims: claimsRef[\"msgA\"] = { stateRenderId: \"tasks\", runId: \"pending\", stateSnapshot: {progress: 50%} }\n * → Renders UI with 50% progress\n *\n * Time 2: Message B renders, runId=undefined, same state\n * → Checks: \"tasks\" already claimed by msgA with same state\n * → Returns null (blocked - duplicate)\n *\n * Time 3: Real runId appears (e.g., \"run-123\")\n * → Updates claim: claimsRef[\"msgA\"].runId = \"run-123\"\n * → Message A continues rendering\n *\n * Time 4: Agent processes more, state={progress: 100%}\n * → Message A: locked to 50% (stateSnapshot locked)\n * → Message C renders with state={progress: 100%}\n * → Checks: \"tasks\" claimed by msgA but state is DIFFERENT (50% vs 100%)\n * → Allows new claim: claimsRef[\"msgC\"] = { stateRenderId: \"tasks\", runId: \"run-123\", stateSnapshot: {progress: 100%} }\n * → Both messages render independently with their own snapshots\n * ```\n */\nexport interface CoAgentStateRenderBridgeProps {\n message: any;\n position: ReactCustomMessageRendererPosition;\n runId: string;\n messageIndex: number;\n messageIndexInRun: number;\n numberOfMessagesInRun: number;\n agentId: string;\n stateSnapshot: any;\n}\n\nexport function useCoagentStateRenderBridge(agentId: string, props: CoAgentStateRenderBridgeProps) {\n const { stateSnapshot, messageIndexInRun, message } = props;\n const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();\n const { agent } = useAgent({ agentId });\n const [nodeName, setNodeName] = useState<string | undefined>(undefined);\n\n const runId = props.runId ?? message.runId;\n const effectiveRunId = runId || \"pending\";\n\n useEffect(() => {\n if (!agent) return;\n const subscriber: AgentSubscriber = {\n onStepStartedEvent: ({ event }) => {\n if (event.stepName !== nodeName) {\n setNodeName(event.stepName);\n }\n },\n onStepFinishedEvent: ({ event }) => {\n if (event.stepName === nodeName) {\n setNodeName(undefined);\n }\n },\n };\n\n const { unsubscribe } = agent.subscribe(subscriber);\n return () => {\n unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agentId, nodeName]);\n\n const getStateRender = useCallback(\n (messageId: string) => {\n return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {\n if (claimsRef.current[messageId]) {\n return stateRenderId === claimsRef.current[messageId].stateRenderId;\n }\n const matchingAgentName = stateRender.name === agentId;\n const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;\n return matchingAgentName && matchesNodeContext;\n });\n },\n [coAgentStateRenders, nodeName, agentId],\n );\n\n // Message ID-based claim system - A state render can only be claimed by one message ID\n const handleRenderRequest = ({\n stateRenderId,\n messageId,\n runId,\n stateSnapshot: renderSnapshot,\n }: {\n stateRenderId: string;\n messageId: string;\n runId?: string;\n stateSnapshot?: any;\n }): boolean => {\n // Check if this message has already claimed this state render\n if (claimsRef.current[messageId]) {\n const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;\n\n // Update runId if it doesn't exist\n if (\n canRender &&\n runId &&\n (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === \"pending\")\n ) {\n claimsRef.current[messageId].runId = runId;\n }\n\n return canRender;\n }\n\n // Do not allow render if any other message has claimed this state render\n const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(\n (c) =>\n c.stateRenderId === stateRenderId &&\n dataToUUID(JSON.stringify(getStateWithoutConstantKeys(c.stateSnapshot))) ===\n dataToUUID(JSON.stringify(getStateWithoutConstantKeys(renderSnapshot))),\n );\n if (renderClaimedByOtherMessage) {\n // If:\n // - state render already claimed\n // - snapshot exists in the claiming object and is different from current,\n if (\n renderSnapshot &&\n renderClaimedByOtherMessage.stateSnapshot &&\n !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)\n ) {\n claimsRef.current[messageId] = { stateRenderId, runId };\n return true;\n }\n return false;\n }\n\n // No existing claim anywhere yet – allow this message to claim even if we already know the runId.\n if (!runId) {\n return false;\n }\n\n claimsRef.current[messageId] = { stateRenderId, runId };\n return true;\n };\n\n return useMemo(() => {\n if (messageIndexInRun !== 0) {\n return null;\n }\n\n const [stateRenderId, stateRender] = getStateRender(message.id) ?? [];\n\n if (!stateRender || !stateRenderId) {\n return null;\n }\n\n // Is there any state we can use?\n const snapshot = stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : agent?.state;\n\n // Synchronously check/claim - returns true if this message can render\n const canRender = handleRenderRequest({\n stateRenderId,\n messageId: message.id,\n runId: effectiveRunId,\n stateSnapshot: snapshot,\n });\n if (!canRender) {\n return null;\n }\n\n // If we found state, and given that now there's a claim for the current message, let's save it in the claim\n if (snapshot && !claimsRef.current[message.id].locked) {\n if (stateSnapshot) {\n claimsRef.current[message.id].stateSnapshot = snapshot;\n claimsRef.current[message.id].locked = true;\n } else {\n claimsRef.current[message.id].stateSnapshot = snapshot;\n }\n }\n\n if (stateRender.handler) {\n stateRender.handler({\n state: stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : (agent?.state ?? {}),\n nodeName: nodeName ?? \"\",\n });\n }\n\n if (stateRender.render) {\n const status = agent?.isRunning ? \"inProgress\" : \"complete\";\n\n if (typeof stateRender.render === \"string\") return stateRender.render;\n\n return stateRender.render({\n status,\n // Always use state from claim, to make sure the state does not seem \"wiped\" for a fraction of a second\n state: claimsRef.current[message.id].stateSnapshot ?? {},\n nodeName: nodeName ?? \"\",\n });\n }\n }, [\n getStateRender,\n stateSnapshot,\n agent?.state,\n agent?.isRunning,\n nodeName,\n effectiveRunId,\n message.id,\n messageIndexInRun,\n ]);\n}\n\nexport function CoAgentStateRenderBridge(props: CoAgentStateRenderBridgeProps) {\n return useCoagentStateRenderBridge(props.agentId, props);\n}\n"],"mappings":";;;;;;;;AAAA,SAA6C,gBAAgB;AAC7D,SAAS,aAAa,WAAW,SAAS,gBAAgB;AAG1D,SAAS,YAAY,iBAAiB;AAEtC,SAAS,4BAA4B,OAAY;AAC/C,MAAI,CAAC;AAAO,WAAO,CAAC;AACpB,QAAqE,YAA7D,YAAU,OAAO,WAR3B,IAQuE,IAA7B,qCAA6B,IAA7B,CAAhC,YAAU,SAAO;AACzB,SAAO;AACT;AAGA,SAAS,gBAAgB,GAAQ,GAAQ;AACvC,MAAK,KAAK,CAAC,KAAO,CAAC,KAAK;AAAI,WAAO;AACnC,QAAiE,QAAzD,YAAU,OAAO,WAf3B,IAemE,IAAzB,iCAAyB,IAAzB,CAAhC,YAAU,SAAO;AACzB,QAKI,QAJF;AAAA,cAAU;AAAA,IACV,OAAO;AAAA,IACP,YAAY;AAAA,EAnBhB,IAqBM,IADC,iCACD,IADC;AAAA,IAHH;AAAA,IACA;AAAA,IACA;AAAA;AAIF,SAAO,KAAK,UAAU,oBAAoB,MAAM,KAAK,UAAU,oBAAoB;AACrF;AAgGO,SAAS,4BAA4B,SAAiB,OAAsC;AAxHnG;AAyHE,QAAM,EAAE,eAAe,mBAAmB,QAAQ,IAAI;AACtD,QAAM,EAAE,qBAAqB,UAAU,IAAI,uBAAuB;AAClE,QAAM,EAAE,MAAM,IAAI,SAAS,EAAE,QAAQ,CAAC;AACtC,QAAM,CAAC,UAAU,WAAW,IAAI,SAA6B,MAAS;AAEtE,QAAM,SAAQ,WAAM,UAAN,YAAe,QAAQ;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AE,EAAE,gBAAgB;AAAA,MAChD;AAAA,IACF;AAEA,QAAI,YAAY,SAAS;AACvB,kBAAY,QAAQ;AAAA,QAClB,OAAO,gBAAgB,UAAU,eAAe,aAAa,KAAK,oCAAO,UAAP,YAAgB,CAAC;AAAA,QACnF,UAAU,8BAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAEA,QAAI,YAAY,QAAQ;AACtB,YAAM,UAAS,+BAAO,aAAY,eAAe;AAEjD,UAAI,OAAO,YAAY,WAAW;AAAU,eAAO,YAAY;AAE/D,aAAO,YAAY,OAAO;AAAA,QACxB;AAAA;AAAA,QAEA,QAAO,eAAU,QAAQ,QAAQ,EAAE,EAAE,kBAA9B,YAA+C,CAAC;AAAA,QACvD,UAAU,8BAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,+BAAO;AAAA,IACP,+BAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,EACF,CAAC;AACH;AAEO,SAAS,yBAAyB,OAAsC;AAC7E,SAAO,4BAA4B,MAAM,SAAS,KAAK;AACzD;","names":["runId","_a"]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-coagent-state-render-bridge.tsx"],"sourcesContent":["import { ReactCustomMessageRendererPosition, useAgent } from \"@copilotkitnext/react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport type { AgentSubscriber } from \"@ag-ui/client\";\nimport { useCoAgentStateRenders } from \"../context\";\nimport { dataToUUID, parseJson } from \"@copilotkit/shared\";\n\nfunction getStateWithoutConstantKeys(state: any) {\n if (!state) return {};\n const { messages, tools, copilotkit, ...stateWithoutConstantKeys } = state;\n return stateWithoutConstantKeys;\n}\n\n// Function that compares states, without the constant keys\nfunction areStatesEquals(a: any, b: any) {\n if ((a && !b) || (!a && b)) return false;\n const { messages, tools, copilotkit, ...aWithoutConstantKeys } = a;\n const {\n messages: bMessages,\n tools: bTools,\n copilotkit: bCopilotkit,\n ...bWithoutConstantKeys\n } = b;\n\n return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);\n}\n\n/**\n * Bridge hook that connects agent state renders to chat messages.\n *\n * ## Purpose\n * This hook finds matching state render configurations (registered via useCoAgentStateRender)\n * and returns UI to render in chat.\n * It ensures each state render appears bound to a specific message, preventing duplicates while\n * allowing re-binding when the underlying state changes significantly.\n *\n * ## Message-ID-Based Claiming System\n *\n * ### The Problem\n * Multiple bridge component instances render simultaneously (one per message). Without coordination,\n * they would all try to render the same state render, causing duplicates.\n *\n * ### The Solution: Message-ID Claims with State Comparison\n * Each state render is \"claimed\" by exactly one **message ID** (not runId):\n *\n * **Claim Structure**: `claimsRef.current[messageId] = { stateRenderId, runId, stateSnapshot, locked }`\n *\n * **Primary binding is by messageId because**:\n * - runId is not always available immediately (starts as \"pending\")\n * - messageId is the stable identifier throughout the message lifecycle\n * - Claims persist across component remounts via context ref\n *\n * ### Claiming Logic Flow\n *\n * 1. **Message already has a claim**:\n * - Check if the claim matches the current stateRenderId\n * - If yes → render (this message owns this render)\n * - Update runId if it was \"pending\" and now available\n *\n * 2. **State render claimed by another message**:\n * - Compare state snapshots (ignoring constant keys: messages, tools, copilotkit)\n * - If states are identical → block rendering (duplicate)\n * - **If states are different → allow claiming** (new data, new message)\n * - This handles cases where the same render type shows different states in different messages\n *\n * 3. **Unclaimed state render**:\n * - Only allow claiming if runId is \"pending\" (initial render)\n * - If runId is real but no claim exists → block (edge case protection)\n * - Create new claim: `claimsRef.current[messageId] = { stateRenderId, runId }`\n *\n * ### State Snapshot Locking\n *\n * Once a state snapshot is captured and locked for a message:\n * - The UI always renders with the locked snapshot (not live agent.state)\n * - Prevents UI from appearing \"wiped\" during state transitions\n * - Locked when: stateSnapshot prop is available (from message persistence)\n * - Unlocked state: can still update from live agent.state\n *\n * ### Synchronous Claiming (Ref-based)\n *\n * Claims are stored in a context-level ref (not React state):\n * - Multiple bridges render in the same tick\n * - State updates are async - would allow duplicates before update completes\n * - Ref provides immediate, synchronous claim checking\n * - Survives component remounts (stored in context, not component)\n *\n * ## Flow Example\n *\n * ```\n * Time 1: Message A renders, runId=undefined, state={progress: 50%}\n * → effectiveRunId = \"pending\"\n * → Claims: claimsRef[\"msgA\"] = { stateRenderId: \"tasks\", runId: \"pending\", stateSnapshot: {progress: 50%} }\n * → Renders UI with 50% progress\n *\n * Time 2: Message B renders, runId=undefined, same state\n * → Checks: \"tasks\" already claimed by msgA with same state\n * → Returns null (blocked - duplicate)\n *\n * Time 3: Real runId appears (e.g., \"run-123\")\n * → Updates claim: claimsRef[\"msgA\"].runId = \"run-123\"\n * → Message A continues rendering\n *\n * Time 4: Agent processes more, state={progress: 100%}\n * → Message A: locked to 50% (stateSnapshot locked)\n * → Message C renders with state={progress: 100%}\n * → Checks: \"tasks\" claimed by msgA but state is DIFFERENT (50% vs 100%)\n * → Allows new claim: claimsRef[\"msgC\"] = { stateRenderId: \"tasks\", runId: \"run-123\", stateSnapshot: {progress: 100%} }\n * → Both messages render independently with their own snapshots\n * ```\n */\nexport interface CoAgentStateRenderBridgeProps {\n message: any;\n position: ReactCustomMessageRendererPosition;\n runId: string;\n messageIndex: number;\n messageIndexInRun: number;\n numberOfMessagesInRun: number;\n agentId: string;\n stateSnapshot: any;\n}\n\nexport function useCoagentStateRenderBridge(agentId: string, props: CoAgentStateRenderBridgeProps) {\n const { stateSnapshot, messageIndexInRun, message } = props;\n const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();\n const { agent } = useAgent({ agentId });\n const [nodeName, setNodeName] = useState<string | undefined>(undefined);\n\n const runId = props.runId ?? message.runId;\n const effectiveRunId = runId || \"pending\";\n\n useEffect(() => {\n if (!agent) return;\n const subscriber: AgentSubscriber = {\n onStepStartedEvent: ({ event }) => {\n if (event.stepName !== nodeName) {\n setNodeName(event.stepName);\n }\n },\n onStepFinishedEvent: ({ event }) => {\n if (event.stepName === nodeName) {\n setNodeName(undefined);\n }\n },\n };\n\n const { unsubscribe } = agent.subscribe(subscriber);\n return () => {\n unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agentId, nodeName]);\n\n const getStateRender = useCallback(\n (messageId: string) => {\n return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {\n if (claimsRef.current[messageId]) {\n return stateRenderId === claimsRef.current[messageId].stateRenderId;\n }\n const matchingAgentName = stateRender.name === agentId;\n const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;\n return matchingAgentName && matchesNodeContext;\n });\n },\n [coAgentStateRenders, nodeName, agentId],\n );\n\n // Message ID-based claim system - A state render can only be claimed by one message ID\n const handleRenderRequest = ({\n stateRenderId,\n messageId,\n runId,\n stateSnapshot: renderSnapshot,\n }: {\n stateRenderId: string;\n messageId: string;\n runId?: string;\n stateSnapshot?: any;\n }): boolean => {\n // Check if this message has already claimed this state render\n if (claimsRef.current[messageId]) {\n const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;\n\n // Update runId if it doesn't exist\n if (\n canRender &&\n runId &&\n (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === \"pending\")\n ) {\n claimsRef.current[messageId].runId = runId;\n }\n\n return canRender;\n }\n\n // Do not allow render if any other message has claimed this state render\n const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(\n (c) =>\n c.stateRenderId === stateRenderId &&\n dataToUUID(getStateWithoutConstantKeys(c.stateSnapshot)) ===\n dataToUUID(getStateWithoutConstantKeys(renderSnapshot)),\n );\n if (renderClaimedByOtherMessage) {\n // If:\n // - state render already claimed\n // - snapshot exists in the claiming object and is different from current,\n if (\n renderSnapshot &&\n renderClaimedByOtherMessage.stateSnapshot &&\n !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)\n ) {\n claimsRef.current[messageId] = { stateRenderId, runId };\n return true;\n }\n return false;\n }\n\n // No existing claim anywhere yet – allow this message to claim even if we already know the runId.\n if (!runId) {\n return false;\n }\n\n claimsRef.current[messageId] = { stateRenderId, runId };\n return true;\n };\n\n return useMemo(() => {\n if (messageIndexInRun !== 0) {\n return null;\n }\n\n const [stateRenderId, stateRender] = getStateRender(message.id) ?? [];\n\n if (!stateRender || !stateRenderId) {\n return null;\n }\n\n // Is there any state we can use?\n const snapshot = stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : agent?.state;\n\n // Synchronously check/claim - returns true if this message can render\n const canRender = handleRenderRequest({\n stateRenderId,\n messageId: message.id,\n runId: effectiveRunId,\n stateSnapshot: snapshot,\n });\n if (!canRender) {\n return null;\n }\n\n // If we found state, and given that now there's a claim for the current message, let's save it in the claim\n if (snapshot && !claimsRef.current[message.id].locked) {\n if (stateSnapshot) {\n claimsRef.current[message.id].stateSnapshot = snapshot;\n claimsRef.current[message.id].locked = true;\n } else {\n claimsRef.current[message.id].stateSnapshot = snapshot;\n }\n }\n\n if (stateRender.handler) {\n stateRender.handler({\n state: stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : (agent?.state ?? {}),\n nodeName: nodeName ?? \"\",\n });\n }\n\n if (stateRender.render) {\n const status = agent?.isRunning ? \"inProgress\" : \"complete\";\n\n if (typeof stateRender.render === \"string\") return stateRender.render;\n\n return stateRender.render({\n status,\n // Always use state from claim, to make sure the state does not seem \"wiped\" for a fraction of a second\n state: claimsRef.current[message.id].stateSnapshot ?? {},\n nodeName: nodeName ?? \"\",\n });\n }\n }, [\n getStateRender,\n stateSnapshot,\n agent?.state,\n agent?.isRunning,\n nodeName,\n effectiveRunId,\n message.id,\n messageIndexInRun,\n ]);\n}\n\nexport function CoAgentStateRenderBridge(props: CoAgentStateRenderBridgeProps) {\n return useCoagentStateRenderBridge(props.agentId, props);\n}\n"],"mappings":";;;;;;;;AAAA,SAA6C,gBAAgB;AAC7D,SAAS,aAAa,WAAW,SAAS,gBAAgB;AAG1D,SAAS,YAAY,iBAAiB;AAEtC,SAAS,4BAA4B,OAAY;AAC/C,MAAI,CAAC;AAAO,WAAO,CAAC;AAC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IACH;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,+BAAO;AAAA,IACP,+BAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,EACF,CAAC;AACH;AAEO,SAAS,yBAAyB,OAAsC;AAC7E,SAAO,4BAA4B,MAAM,SAAS,KAAK;AACzD;","names":["runId","_a"]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-I76HKHPJ.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useCopilotContext
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__spreadProps,
|
|
9
9
|
__spreadValues
|
|
@@ -25,7 +25,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
25
25
|
threadId,
|
|
26
26
|
interruptEventQueue,
|
|
27
27
|
addInterruptEvent,
|
|
28
|
-
|
|
28
|
+
resolveInterruptEvent
|
|
29
29
|
} = useCopilotContext();
|
|
30
30
|
const existingConfig = useCopilotChatConfiguration();
|
|
31
31
|
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
@@ -33,6 +33,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
if (!agent)
|
|
35
35
|
return;
|
|
36
|
+
let localInterrupt = null;
|
|
36
37
|
const subscriber = {
|
|
37
38
|
onCustomEvent: ({ event }) => {
|
|
38
39
|
if (event.name === "on_interrupt") {
|
|
@@ -41,12 +42,21 @@ function useLangGraphInterruptRender(agent) {
|
|
|
41
42
|
type: event.type,
|
|
42
43
|
value: parseJson(event.value, event.value)
|
|
43
44
|
};
|
|
44
|
-
const eventId = dataToUUID(
|
|
45
|
-
|
|
45
|
+
const eventId = dataToUUID(eventData, "interruptEvents");
|
|
46
|
+
localInterrupt = {
|
|
46
47
|
eventId,
|
|
47
48
|
threadId,
|
|
48
49
|
event: eventData
|
|
49
|
-
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
onRunStartedEvent: () => {
|
|
54
|
+
localInterrupt = null;
|
|
55
|
+
},
|
|
56
|
+
onRunFinalized: () => {
|
|
57
|
+
if (localInterrupt) {
|
|
58
|
+
addInterruptEvent(localInterrupt);
|
|
59
|
+
localInterrupt = null;
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
};
|
|
@@ -64,7 +74,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
76
|
});
|
|
67
|
-
|
|
77
|
+
resolveInterruptEvent(threadId, eventId, response != null ? response : "");
|
|
68
78
|
},
|
|
69
79
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
80
|
[agent, threadId]
|
|
@@ -112,4 +122,4 @@ function useLangGraphInterruptRender(agent) {
|
|
|
112
122
|
export {
|
|
113
123
|
useLangGraphInterruptRender
|
|
114
124
|
};
|
|
115
|
-
//# sourceMappingURL=chunk-
|
|
125
|
+
//# sourceMappingURL=chunk-VV56AVPB.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-langgraph-interrupt-render.ts"],"sourcesContent":["import { useCopilotContext } from \"../context\";\nimport React, { useCallback, useEffect, useMemo } from \"react\";\nimport type { AbstractAgent, AgentSubscriber } from \"@ag-ui/client\";\nimport { MetaEventName } from \"@copilotkit/runtime-client-gql\";\nimport { dataToUUID, parseJson } from \"@copilotkit/shared\";\nimport { useAgentNodeName } from \"./use-agent-nodename\";\nimport { useCopilotChatConfiguration } from \"@copilotkitnext/react\";\n\ntype InterruptProps = {\n event: any;\n result: any;\n render: (props: {\n event: any;\n result: any;\n resolve: (response: string) => void;\n }) => string | React.ReactElement;\n resolve: (response: string) => void;\n};\n\nconst InterruptRenderer: React.FC<InterruptProps> = ({ event, result, render, resolve }) => {\n return render({ event, result, resolve });\n};\n\nexport function useLangGraphInterruptRender(\n agent: AbstractAgent,\n): string | React.ReactElement | null {\n const {\n interruptActions,\n agentSession,\n threadId,\n interruptEventQueue,\n addInterruptEvent,\n resolveInterruptEvent,\n } = useCopilotContext();\n const existingConfig = useCopilotChatConfiguration();\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n const nodeName = useAgentNodeName(resolvedAgentId);\n\n useEffect(() => {\n if (!agent) return;\n let localInterrupt: any = null;\n const subscriber: AgentSubscriber = {\n onCustomEvent: ({ event }) => {\n if (event.name === \"on_interrupt\") {\n const eventData = {\n name: MetaEventName.LangGraphInterruptEvent,\n type: event.type,\n value: parseJson(event.value, event.value),\n };\n const eventId = dataToUUID(eventData, \"interruptEvents\");\n localInterrupt = {\n eventId,\n threadId,\n event: eventData,\n };\n }\n },\n onRunStartedEvent: () => {\n localInterrupt = null;\n },\n onRunFinalized: () => {\n if (localInterrupt) {\n addInterruptEvent(localInterrupt);\n localInterrupt = null;\n }\n },\n };\n\n const { unsubscribe } = agent.subscribe(subscriber);\n return () => {\n unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agent, threadId]);\n\n const handleResolve = useCallback(\n (eventId: string, response?: string) => {\n agent?.runAgent({\n forwardedProps: {\n command: {\n resume: response,\n },\n },\n });\n resolveInterruptEvent(threadId, eventId, response ?? \"\");\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent, threadId],\n );\n\n return useMemo(() => {\n // Get the queue for this thread and find the first unresponded event\n const eventQueue = interruptEventQueue[threadId] || [];\n const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);\n\n if (!currentQueuedEvent || !agentSession) return null;\n\n // Find the first matching action from all registered actions\n const allActions = Object.values(interruptActions);\n const matchingAction = allActions.find((action) => {\n if (!action.enabled) return true; // No filter = match all\n return action.enabled({\n eventValue: currentQueuedEvent.event.value,\n agentMetadata: {\n ...agentSession,\n nodeName,\n },\n });\n });\n\n if (!matchingAction) return null;\n\n const { render, handler } = matchingAction;\n\n const resolveInterrupt = (response: string) => {\n handleResolve(currentQueuedEvent.eventId, response);\n };\n\n let result = null;\n if (handler) {\n result = handler({\n event: currentQueuedEvent.event,\n resolve: resolveInterrupt,\n });\n }\n\n if (!render) return null;\n\n return React.createElement(InterruptRenderer, {\n event: currentQueuedEvent.event,\n result,\n render,\n resolve: resolveInterrupt,\n });\n }, [interruptActions, interruptEventQueue, threadId, agentSession, handleResolve]);\n}\n"],"mappings":";;;;;;;;;;;;AACA,OAAO,SAAS,aAAa,WAAW,eAAe;AAEvD,SAAS,qBAAqB;AAC9B,SAAS,YAAY,iBAAiB;AAEtC,SAAS,mCAAmC;AAa5C,IAAM,oBAA8C,CAAC,EAAE,OAAO,QAAQ,QAAQ,QAAQ,MAAM;AAC1F,SAAO,OAAO,EAAE,OAAO,QAAQ,QAAQ,CAAC;AAC1C;AAEO,SAAS,4BACd,OACoC;AAzBtC;AA0BE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,kBAAkB;AACtB,QAAM,iBAAiB,4BAA4B;AACnD,QAAM,mBAAkB,sDAAgB,YAAhB,YAA2B;AACnD,QAAM,WAAW,iBAAiB,eAAe;AAEjD,YAAU,MAAM;AACd,QAAI,CAAC;AAAO;AACZ,QAAI,iBAAsB;AAC1B,UAAM,aAA8B;AAAA,MAClC,eAAe,CAAC,EAAE,MAAM,MAAM;AAC5B,YAAI,MAAM,SAAS,gBAAgB;AACjC,gBAAM,YAAY;AAAA,YAChB,MAAM,cAAc;AAAA,YACpB,MAAM,MAAM;AAAA,YACZ,OAAO,UAAU,MAAM,OAAO,MAAM,KAAK;AAAA,UAC3C;AACA,gBAAM,UAAU,WAAW,WAAW,iBAAiB;AACvD,2BAAiB;AAAA,YACf;AAAA,YACA;AAAA,YACA,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,MACA,mBAAmB,MAAM;AACvB,yBAAiB;AAAA,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AAA,IACH;AAEA,QAAI,CAAC;AAAQ,aAAO;AAEpB,WAAO,MAAM,cAAc,mBAAmB;AAAA,MAC5C,OAAO,mBAAmB;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,SAAS;AAAA,IACX,CAAC;AAAA,EACH,GAAG,CAAC,kBAAkB,qBAAqB,UAAU,cAAc,aAAa,CAAC;AACnF;","names":[]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-4CEQJ2X6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
defaultCopilotContextCategories
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZU6ZBX4E.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__async,
|
|
9
9
|
__spreadValues
|
|
@@ -117,4 +117,4 @@ ${instructions}
|
|
|
117
117
|
export {
|
|
118
118
|
CopilotTask
|
|
119
119
|
};
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
120
|
+
//# sourceMappingURL=chunk-Y2L7KDVW.mjs.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./chunk-PIF5KJYI.mjs";
|
|
6
6
|
import {
|
|
7
7
|
useCopilotContext
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
9
9
|
import {
|
|
10
10
|
useCopilotMessagesContext
|
|
11
11
|
} from "./chunk-DMLQZG75.mjs";
|
|
@@ -756,4 +756,4 @@ function ContextTab({ context }) {
|
|
|
756
756
|
export {
|
|
757
757
|
DeveloperConsoleModal
|
|
758
758
|
};
|
|
759
|
-
//# sourceMappingURL=chunk-
|
|
759
|
+
//# sourceMappingURL=chunk-YCG6SNAU.mjs.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-FDOMAPJY.mjs";
|
|
7
7
|
import {
|
|
8
8
|
CopilotContext
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
10
10
|
|
|
11
11
|
// src/hooks/use-coagent-state-render.ts
|
|
12
12
|
import { useRef, useContext, useEffect } from "react";
|
|
@@ -83,4 +83,4 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
83
83
|
export {
|
|
84
84
|
useCoAgentStateRender
|
|
85
85
|
};
|
|
86
|
-
//# sourceMappingURL=chunk-
|
|
86
|
+
//# sourceMappingURL=chunk-YTQHRJUA.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useLangGraphInterruptRender
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VV56AVPB.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useLazyToolRenderer
|
|
6
6
|
} from "./chunk-ZVF5Q6IH.mjs";
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
} from "./chunk-6PUNP7CD.mjs";
|
|
13
13
|
import {
|
|
14
14
|
CoAgentStateRenderBridge
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-QNUAXSDP.mjs";
|
|
16
16
|
import {
|
|
17
17
|
useCopilotContext
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
19
19
|
import {
|
|
20
20
|
__async,
|
|
21
21
|
__spreadProps,
|
|
@@ -745,4 +745,4 @@ export {
|
|
|
745
745
|
useCopilotChatInternal,
|
|
746
746
|
defaultSystemMessage
|
|
747
747
|
};
|
|
748
|
-
//# sourceMappingURL=chunk-
|
|
748
|
+
//# sourceMappingURL=chunk-ZCV3A2FP.mjs.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
CopilotErrorBoundary
|
|
3
|
+
} from "./chunk-LHERIF3L.mjs";
|
|
4
4
|
import {
|
|
5
5
|
CopilotMessages,
|
|
6
6
|
MessagesTapProvider
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-HE22TZMF.mjs";
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
ConsoleTrigger
|
|
10
|
+
} from "./chunk-PMWUKW3Z.mjs";
|
|
11
11
|
import {
|
|
12
12
|
shouldShowDevConsole
|
|
13
13
|
} from "./chunk-ICIK2BSB.mjs";
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from "./chunk-YYN33GSG.mjs";
|
|
20
20
|
import {
|
|
21
21
|
CoAgentStateRenderBridge
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-QNUAXSDP.mjs";
|
|
23
23
|
import {
|
|
24
24
|
ThreadsProvider,
|
|
25
25
|
useThreads
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
} from "./chunk-FDOMAPJY.mjs";
|
|
40
40
|
import {
|
|
41
41
|
CopilotContext
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
43
43
|
import {
|
|
44
44
|
__async,
|
|
45
45
|
__objRest,
|
|
@@ -65,14 +65,7 @@ function CopilotKit(_a) {
|
|
|
65
65
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
66
66
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
67
67
|
const renderArr = useMemo(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
68
|
-
return /* @__PURE__ */ jsx(ToastProvider, { enabled, children: /* @__PURE__ */ jsx(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ jsx(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ jsx(
|
|
69
|
-
CopilotKitProvider,
|
|
70
|
-
__spreadProps(__spreadValues({}, props), {
|
|
71
|
-
renderCustomMessages: renderArr,
|
|
72
|
-
useSingleEndpoint: true,
|
|
73
|
-
children: /* @__PURE__ */ jsx(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
|
|
74
|
-
})
|
|
75
|
-
) }) }) });
|
|
68
|
+
return /* @__PURE__ */ jsx(ToastProvider, { enabled, children: /* @__PURE__ */ jsx(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ jsx(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ jsx(CopilotKitProvider, __spreadProps(__spreadValues({}, props), { renderCustomMessages: renderArr, useSingleEndpoint: true, children: /* @__PURE__ */ jsx(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) })) }) }) });
|
|
76
69
|
}
|
|
77
70
|
function CopilotKitInternal(cpkProps) {
|
|
78
71
|
var _b;
|
|
@@ -310,20 +303,17 @@ ${nonDocumentStrings}`;
|
|
|
310
303
|
const chatAbortControllerRef = useRef(null);
|
|
311
304
|
const showDevConsole = shouldShowDevConsole(props.showDevConsole);
|
|
312
305
|
const [interruptActions, _setInterruptActions] = useState({});
|
|
313
|
-
const setInterruptAction = useCallback(
|
|
314
|
-
(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
[action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
|
|
322
|
-
});
|
|
306
|
+
const setInterruptAction = useCallback((action) => {
|
|
307
|
+
_setInterruptActions((prev) => {
|
|
308
|
+
var _a2;
|
|
309
|
+
if (action == null || !action.id) {
|
|
310
|
+
return prev;
|
|
311
|
+
}
|
|
312
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
313
|
+
[action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
|
|
323
314
|
});
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
);
|
|
315
|
+
});
|
|
316
|
+
}, []);
|
|
327
317
|
const removeInterruptAction = useCallback((actionId) => {
|
|
328
318
|
_setInterruptActions((prev) => {
|
|
329
319
|
const _a2 = prev, { [actionId]: _ } = _a2, rest = __objRest(_a2, [__restKey(actionId)]);
|
|
@@ -339,14 +329,19 @@ ${nonDocumentStrings}`;
|
|
|
339
329
|
});
|
|
340
330
|
});
|
|
341
331
|
}, []);
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
332
|
+
const resolveInterruptEvent = useCallback(
|
|
333
|
+
(threadId2, eventId, response) => {
|
|
334
|
+
setInterruptEventQueue((prev) => {
|
|
335
|
+
const threadQueue = prev[threadId2] || [];
|
|
336
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
337
|
+
[threadId2]: threadQueue.map(
|
|
338
|
+
(queuedEvent) => queuedEvent.eventId === eventId ? __spreadProps(__spreadValues({}, queuedEvent), { event: __spreadProps(__spreadValues({}, queuedEvent.event), { response }) }) : queuedEvent
|
|
339
|
+
)
|
|
340
|
+
});
|
|
347
341
|
});
|
|
348
|
-
}
|
|
349
|
-
|
|
342
|
+
},
|
|
343
|
+
[]
|
|
344
|
+
);
|
|
350
345
|
const memoizedChildren = useMemo(() => children, [children]);
|
|
351
346
|
const [bannerError, setBannerError] = useState(null);
|
|
352
347
|
const agentLock = useMemo(() => {
|
|
@@ -464,7 +459,7 @@ ${nonDocumentStrings}`;
|
|
|
464
459
|
removeInterruptAction,
|
|
465
460
|
interruptEventQueue,
|
|
466
461
|
addInterruptEvent,
|
|
467
|
-
|
|
462
|
+
resolveInterruptEvent,
|
|
468
463
|
bannerError,
|
|
469
464
|
setBannerError,
|
|
470
465
|
onError: handleErrors,
|
|
@@ -545,4 +540,4 @@ export {
|
|
|
545
540
|
CopilotKitInternal,
|
|
546
541
|
defaultCopilotContextCategories
|
|
547
542
|
};
|
|
548
|
-
//# sourceMappingURL=chunk-
|
|
543
|
+
//# sourceMappingURL=chunk-ZU6ZBX4E.mjs.map
|