@copilotkit/react-core 1.6.0-next.9 → 1.7.0-next.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 +50 -0
- package/dist/{chunk-5M47BILE.mjs → chunk-37LXOL6B.mjs} +2 -2
- package/dist/{chunk-XERJQUHA.mjs → chunk-4CEQJ2X6.mjs} +2 -2
- package/dist/{chunk-XERJQUHA.mjs.map → chunk-4CEQJ2X6.mjs.map} +1 -1
- package/dist/{chunk-JFCNSGNU.mjs → chunk-4X4XFBC6.mjs} +3 -3
- package/dist/{chunk-F7O6L7C3.mjs → chunk-7XNZHQWJ.mjs} +2 -2
- package/dist/{chunk-7HWSAEOY.mjs → chunk-AT4ALBK4.mjs} +13 -4
- package/dist/{chunk-7HWSAEOY.mjs.map → chunk-AT4ALBK4.mjs.map} +1 -1
- package/dist/{chunk-MPFP6ANM.mjs → chunk-CJTSYEYG.mjs} +3 -3
- package/dist/chunk-CQPYJIBH.mjs +1 -0
- package/dist/{chunk-ALW2T2LL.mjs → chunk-FUO5LKSJ.mjs} +114 -60
- package/dist/chunk-FUO5LKSJ.mjs.map +1 -0
- package/dist/{chunk-XOHLZIZK.mjs → chunk-JHPCDBBM.mjs} +2 -2
- package/dist/{chunk-PR5R5TTF.mjs → chunk-JMFYGW35.mjs} +2 -2
- package/dist/{chunk-T2EFA3D5.mjs → chunk-NY3BUYYZ.mjs} +2 -2
- package/dist/chunk-O3IIH54P.mjs +24 -0
- package/dist/chunk-O3IIH54P.mjs.map +1 -0
- package/dist/{chunk-7YXUCWXF.mjs → chunk-PRWPZCKZ.mjs} +10 -8
- package/dist/chunk-PRWPZCKZ.mjs.map +1 -0
- package/dist/{chunk-ZM56S3LJ.mjs → chunk-PTSWFERP.mjs} +3 -1
- package/dist/chunk-PTSWFERP.mjs.map +1 -0
- package/dist/{chunk-ADTDNMYG.mjs → chunk-RPSMTOER.mjs} +3 -3
- package/dist/{chunk-2F6RYBYS.mjs → chunk-YI7LPACV.mjs} +3 -3
- package/dist/{chunk-QJPWWVJQ.mjs → chunk-ZNWM2EVT.mjs} +4 -4
- package/dist/components/copilot-provider/copilot-messages.js +2 -0
- 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 +5 -1
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +4 -4
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +5 -1
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +4 -4
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +5 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -4
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +2 -0
- 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 +2 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-9ae8990b.d.ts → copilot-context-c402f48d.d.ts} +2 -0
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +159 -79
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +20 -16
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +113 -62
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +2 -2
- package/dist/hooks/use-coagent-state-render.js +2 -0
- 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-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +121 -68
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +8 -8
- package/dist/hooks/use-copilot-action.js +2 -0
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.d.ts +26 -0
- package/dist/hooks/use-copilot-additional-instructions.js +162 -0
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -0
- package/dist/hooks/use-copilot-additional-instructions.mjs +9 -0
- package/dist/hooks/use-copilot-additional-instructions.mjs.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.js +2 -0
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +119 -66
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +7 -7
- package/dist/hooks/use-copilot-readable.d.ts +5 -1
- package/dist/hooks/use-copilot-readable.js +13 -2
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +2 -0
- 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 +121 -68
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +8 -8
- package/dist/hooks/use-make-copilot-document-readable.js +2 -0
- 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 +2 -1
- package/dist/index.js +168 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -17
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +6 -6
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/types/frontend-action.d.ts +2 -1
- package/dist/types/frontend-action.js +1 -1
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/types/frontend-action.mjs +1 -1
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +4 -4
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +4 -4
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit.tsx +3 -1
- package/src/context/copilot-context.tsx +6 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-chat.ts +133 -58
- package/src/hooks/use-copilot-additional-instructions.ts +85 -0
- package/src/hooks/use-copilot-readable.ts +16 -2
- package/src/types/frontend-action.ts +5 -2
- package/dist/chunk-7YXUCWXF.mjs.map +0 -1
- package/dist/chunk-ALW2T2LL.mjs.map +0 -1
- package/dist/chunk-IGLITGLC.mjs +0 -1
- package/dist/chunk-ZM56S3LJ.mjs.map +0 -1
- /package/dist/{chunk-5M47BILE.mjs.map → chunk-37LXOL6B.mjs.map} +0 -0
- /package/dist/{chunk-JFCNSGNU.mjs.map → chunk-4X4XFBC6.mjs.map} +0 -0
- /package/dist/{chunk-F7O6L7C3.mjs.map → chunk-7XNZHQWJ.mjs.map} +0 -0
- /package/dist/{chunk-MPFP6ANM.mjs.map → chunk-CJTSYEYG.mjs.map} +0 -0
- /package/dist/{chunk-IGLITGLC.mjs.map → chunk-CQPYJIBH.mjs.map} +0 -0
- /package/dist/{chunk-XOHLZIZK.mjs.map → chunk-JHPCDBBM.mjs.map} +0 -0
- /package/dist/{chunk-PR5R5TTF.mjs.map → chunk-JMFYGW35.mjs.map} +0 -0
- /package/dist/{chunk-T2EFA3D5.mjs.map → chunk-NY3BUYYZ.mjs.map} +0 -0
- /package/dist/{chunk-ADTDNMYG.mjs.map → chunk-RPSMTOER.mjs.map} +0 -0
- /package/dist/{chunk-2F6RYBYS.mjs.map → chunk-YI7LPACV.mjs.map} +0 -0
- /package/dist/{chunk-QJPWWVJQ.mjs.map → chunk-ZNWM2EVT.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} 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\";\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 LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\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\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | 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;\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 // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: 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 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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\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 // runtime\n runtimeClient: CopilotRuntimeClient;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: 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 langGraphInterruptAction: LangGraphInterruptAction | null;\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n removeLangGraphInterruptAction: () => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\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 runtimeClient: {} as any,\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 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 langGraphInterruptAction: null,\n setLangGraphInterruptAction: () => null,\n removeLangGraphInterruptAction: () => null,\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","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,mBAAkB;AA4MlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,0BAA0B,MAAM;AAAA,EAAC;AAAA,EAEjC,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,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,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,EAC9B,eAAe,CAAC;AAAA,EAEhB,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;AAAA,EAChB,eAAe,CAAC;AAAA,EAChB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,kBAAkB,EAAE,SAAS,CAAC,EAAE;AAAA,EAChC,yBAAyB,MAAM;AAAA,EAAC;AAAA,EAChC,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,qBAAqB,CAAC;AAAA,EACtB,WAAW;AAAA,EACX,UAAU;AAAA,EACV,aAAa,MAAM;AAAA,EAAC;AAAA,EACpB,OAAO;AAAA,EACP,UAAU,MAAM;AAAA,EAAC;AAAA,EACjB,wBAAwB,EAAE,SAAS,KAAK;AAAA,EACxC,iBAAiB,CAAC;AAAA,EAClB,YAAY,CAAC;AAAA,EACb,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,0BAA0B;AAAA,EAC1B,6BAA6B,MAAM;AAAA,EACnC,gCAAgC,MAAM;AACxC;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,QAAc;AAC9C,QAAM,IAAI,MAAM,uEAAuE;AACzF;;;AC3RA,IAAAC,gBAAkB;AAOlB,IAAMC,uBAAoD;AAAA,EACxD,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,CAAC;AACtB;AAEO,IAAM,yBACX,cAAAC,QAAM,cAA4CD,oBAAmB;AAEhE,SAAS,4BAA0D;AACxE,QAAM,UAAU,cAAAC,QAAM,WAAW,sBAAsB;AACvD,MAAI,YAAYD,sBAAqB;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["React","import_react","emptyCopilotContext","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} 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\";\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 LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\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\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | 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;\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 // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: 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 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 | \"auto\";\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 // runtime\n runtimeClient: CopilotRuntimeClient;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: 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 langGraphInterruptAction: LangGraphInterruptAction | null;\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n removeLangGraphInterruptAction: () => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\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 runtimeClient: {} as any,\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 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 langGraphInterruptAction: null,\n setLangGraphInterruptAction: () => null,\n removeLangGraphInterruptAction: () => null,\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","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":"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","names":["React","import_react","emptyCopilotContext","React"]}
|
package/dist/context/index.mjs
CHANGED
|
@@ -138,6 +138,8 @@ interface CopilotContextParams {
|
|
|
138
138
|
removeChatSuggestionConfiguration: (id: string) => void;
|
|
139
139
|
chatInstructions: string;
|
|
140
140
|
setChatInstructions: React$1.Dispatch<React$1.SetStateAction<string>>;
|
|
141
|
+
additionalInstructions?: string[];
|
|
142
|
+
setAdditionalInstructions: React$1.Dispatch<React$1.SetStateAction<string[]>>;
|
|
141
143
|
copilotApiConfig: CopilotApiConfig;
|
|
142
144
|
showDevConsole: boolean | "auto";
|
|
143
145
|
coagentStates: Record<string, CoagentState>;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { useCopilotRuntimeClient } from './use-copilot-runtime-client.js';
|
|
|
9
9
|
export { useCopilotAuthenticatedAction_c } from './use-copilot-authenticated-action.js';
|
|
10
10
|
export { useLangGraphInterrupt } from './use-langgraph-interrupt.js';
|
|
11
11
|
export { useLangGraphInterruptRender } from './use-langgraph-interrupt-render.js';
|
|
12
|
+
export { useCopilotAdditionalInstructions } from './use-copilot-additional-instructions.js';
|
|
12
13
|
import '@copilotkit/runtime-client-gql';
|
|
13
14
|
import '../types/system-message.js';
|
|
14
15
|
import '@copilotkit/shared';
|
|
@@ -16,7 +17,7 @@ import '../types/frontend-action.js';
|
|
|
16
17
|
import 'react';
|
|
17
18
|
import '../types/coagent-action.js';
|
|
18
19
|
import '../types/document-pointer.js';
|
|
19
|
-
import '../copilot-context-
|
|
20
|
+
import '../copilot-context-c402f48d.js';
|
|
20
21
|
import './use-tree.js';
|
|
21
22
|
import '../types/chat-suggestion-configuration.js';
|
|
22
23
|
import '../types/coagent-state.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -85,6 +85,7 @@ __export(hooks_exports, {
|
|
|
85
85
|
useCoAgent: () => useCoAgent,
|
|
86
86
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
87
87
|
useCopilotAction: () => useCopilotAction,
|
|
88
|
+
useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
|
|
88
89
|
useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
|
|
89
90
|
useCopilotChat: () => useCopilotChat,
|
|
90
91
|
useCopilotReadable: () => useCopilotReadable,
|
|
@@ -122,6 +123,8 @@ var emptyCopilotContext = {
|
|
|
122
123
|
setIsLoading: () => returnAndThrowInDebug(false),
|
|
123
124
|
chatInstructions: "",
|
|
124
125
|
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
126
|
+
additionalInstructions: [],
|
|
127
|
+
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
125
128
|
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
126
129
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
127
130
|
removeDocumentContext: () => {
|
|
@@ -183,7 +186,7 @@ function returnAndThrowInDebug(_value) {
|
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
// src/hooks/use-copilot-chat.ts
|
|
186
|
-
var
|
|
189
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
187
190
|
|
|
188
191
|
// src/hooks/use-chat.ts
|
|
189
192
|
var import_react5 = require("react");
|
|
@@ -195,7 +198,7 @@ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
|
195
198
|
var import_shared = require("@copilotkit/shared");
|
|
196
199
|
function processActionsForRuntimeRequest(actions) {
|
|
197
200
|
const filteredActions = actions.filter(
|
|
198
|
-
(action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
|
|
201
|
+
(action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
199
202
|
).map((action) => {
|
|
200
203
|
let available = import_runtime_client_gql.ActionInputAvailability.Enabled;
|
|
201
204
|
if (action.disabled) {
|
|
@@ -372,8 +375,6 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
372
375
|
};
|
|
373
376
|
|
|
374
377
|
// src/hooks/use-chat.ts
|
|
375
|
-
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
376
|
-
var import_shared3 = require("@copilotkit/shared");
|
|
377
378
|
function useChat(options) {
|
|
378
379
|
const {
|
|
379
380
|
messages,
|
|
@@ -422,7 +423,7 @@ function useChat(options) {
|
|
|
422
423
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
423
424
|
setIsLoading(true);
|
|
424
425
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
425
|
-
if ((interruptEvent == null ? void 0 : interruptEvent.name) ===
|
|
426
|
+
if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
426
427
|
addErrorToast([
|
|
427
428
|
new Error(
|
|
428
429
|
"A message was sent while interrupt is active. This will cause failure on the agent side"
|
|
@@ -516,16 +517,16 @@ function useChat(options) {
|
|
|
516
517
|
setExtensions(extensionsRef.current);
|
|
517
518
|
let rawMessagesResponse = value.generateCopilotResponse.messages;
|
|
518
519
|
((_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : []).forEach((ev) => {
|
|
519
|
-
if (ev.name ===
|
|
520
|
+
if (ev.name === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent) {
|
|
520
521
|
let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
|
|
521
|
-
eventValue = (0,
|
|
522
|
+
eventValue = (0, import_shared2.parseJson)(eventValue, eventValue);
|
|
522
523
|
setLangGraphInterruptAction({
|
|
523
524
|
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev)), {
|
|
524
525
|
value: eventValue
|
|
525
526
|
})
|
|
526
527
|
});
|
|
527
528
|
}
|
|
528
|
-
if (ev.name ===
|
|
529
|
+
if (ev.name === import_runtime_client_gql3.MetaEventName.CopilotKitLangGraphInterruptEvent) {
|
|
529
530
|
const data = ev.data;
|
|
530
531
|
rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
|
|
531
532
|
interruptMessages = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
@@ -606,7 +607,7 @@ function useChat(options) {
|
|
|
606
607
|
setMessages([...previousMessages, ...newMessages]);
|
|
607
608
|
}
|
|
608
609
|
}
|
|
609
|
-
|
|
610
|
+
let finalMessages = constructFinalMessages(
|
|
610
611
|
[...syncedMessages, ...interruptMessages],
|
|
611
612
|
previousMessages,
|
|
612
613
|
newMessages
|
|
@@ -616,7 +617,7 @@ function useChat(options) {
|
|
|
616
617
|
const lastMessages = [];
|
|
617
618
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
618
619
|
const message = finalMessages[i];
|
|
619
|
-
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
|
|
620
|
+
if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
|
|
620
621
|
lastMessages.unshift(message);
|
|
621
622
|
} else {
|
|
622
623
|
break;
|
|
@@ -624,59 +625,51 @@ function useChat(options) {
|
|
|
624
625
|
}
|
|
625
626
|
for (const message of lastMessages) {
|
|
626
627
|
setMessages(finalMessages);
|
|
627
|
-
const action = actions.find(
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
"abort",
|
|
644
|
-
() => resolve("Operation was aborted by the user")
|
|
645
|
-
);
|
|
646
|
-
}
|
|
647
|
-
),
|
|
648
|
-
// if the user stopped generation, we also abort consecutive actions
|
|
649
|
-
new Promise((resolve) => {
|
|
650
|
-
var _a2;
|
|
651
|
-
if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
|
|
652
|
-
resolve("Operation was aborted by the user");
|
|
653
|
-
}
|
|
654
|
-
})
|
|
655
|
-
]);
|
|
656
|
-
} catch (e) {
|
|
657
|
-
error = e;
|
|
658
|
-
addErrorToast([error]);
|
|
659
|
-
result = `Failed to execute action ${message.name}. ${error.message}`;
|
|
660
|
-
console.error(`Failed to execute action ${message.name}: ${error}`);
|
|
661
|
-
}
|
|
628
|
+
const action = actions.find(
|
|
629
|
+
(action2) => action2.name === message.name
|
|
630
|
+
);
|
|
631
|
+
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
632
|
+
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
633
|
+
followUp = action2 == null ? void 0 : action2.followUp;
|
|
634
|
+
const resultMessage = yield executeAction({
|
|
635
|
+
onFunctionCall,
|
|
636
|
+
previousMessages,
|
|
637
|
+
message: message2,
|
|
638
|
+
chatAbortControllerRef,
|
|
639
|
+
onError: (error) => {
|
|
640
|
+
addErrorToast([error]);
|
|
641
|
+
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
642
|
+
}
|
|
643
|
+
});
|
|
662
644
|
didExecuteAction = true;
|
|
663
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id ===
|
|
664
|
-
finalMessages.splice(
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
645
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
646
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
647
|
+
return resultMessage;
|
|
648
|
+
});
|
|
649
|
+
if (action && message.isActionExecutionMessage()) {
|
|
650
|
+
const resultMessage = yield executeActionFromMessage(action, message);
|
|
651
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
652
|
+
if (pairedFeAction) {
|
|
653
|
+
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
654
|
+
name: pairedFeAction.name,
|
|
655
|
+
arguments: (0, import_shared2.parseJson)(resultMessage.result, resultMessage.result),
|
|
656
|
+
status: message.status,
|
|
657
|
+
createdAt: message.createdAt,
|
|
658
|
+
parentMessageId: message.parentMessageId
|
|
659
|
+
});
|
|
660
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
661
|
+
}
|
|
662
|
+
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
663
|
+
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
664
|
+
name: currentResultMessagePairedFeAction.name,
|
|
665
|
+
arguments: (0, import_shared2.parseJson)(message.result, message.result),
|
|
666
|
+
status: message.status,
|
|
667
|
+
createdAt: message.createdAt
|
|
668
|
+
});
|
|
669
|
+
finalMessages.push(newExecutionMessage);
|
|
670
|
+
yield executeActionFromMessage(
|
|
671
|
+
currentResultMessagePairedFeAction,
|
|
672
|
+
newExecutionMessage
|
|
680
673
|
);
|
|
681
674
|
}
|
|
682
675
|
}
|
|
@@ -747,7 +740,7 @@ function useChat(options) {
|
|
|
747
740
|
if (!event)
|
|
748
741
|
return acc;
|
|
749
742
|
switch (event.name) {
|
|
750
|
-
case
|
|
743
|
+
case import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent:
|
|
751
744
|
if (event.response) {
|
|
752
745
|
setLangGraphInterruptAction(null);
|
|
753
746
|
const value = event.value;
|
|
@@ -823,11 +816,72 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
823
816
|
}
|
|
824
817
|
return finalMessages;
|
|
825
818
|
}
|
|
819
|
+
function executeAction(_0) {
|
|
820
|
+
return __async(this, arguments, function* ({
|
|
821
|
+
onFunctionCall,
|
|
822
|
+
previousMessages,
|
|
823
|
+
message,
|
|
824
|
+
chatAbortControllerRef,
|
|
825
|
+
onError
|
|
826
|
+
}) {
|
|
827
|
+
let result;
|
|
828
|
+
let error = null;
|
|
829
|
+
try {
|
|
830
|
+
result = yield Promise.race([
|
|
831
|
+
onFunctionCall({
|
|
832
|
+
messages: previousMessages,
|
|
833
|
+
name: message.name,
|
|
834
|
+
args: message.arguments
|
|
835
|
+
}),
|
|
836
|
+
new Promise(
|
|
837
|
+
(resolve) => {
|
|
838
|
+
var _a;
|
|
839
|
+
return (_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.addEventListener(
|
|
840
|
+
"abort",
|
|
841
|
+
() => resolve("Operation was aborted by the user")
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
),
|
|
845
|
+
// if the user stopped generation, we also abort consecutive actions
|
|
846
|
+
new Promise((resolve) => {
|
|
847
|
+
var _a;
|
|
848
|
+
if ((_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.aborted) {
|
|
849
|
+
resolve("Operation was aborted by the user");
|
|
850
|
+
}
|
|
851
|
+
})
|
|
852
|
+
]);
|
|
853
|
+
} catch (e) {
|
|
854
|
+
onError(e);
|
|
855
|
+
}
|
|
856
|
+
return new import_runtime_client_gql3.ResultMessage({
|
|
857
|
+
id: "result-" + message.id,
|
|
858
|
+
result: import_runtime_client_gql3.ResultMessage.encodeResult(
|
|
859
|
+
error ? {
|
|
860
|
+
content: result,
|
|
861
|
+
error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
862
|
+
} : result
|
|
863
|
+
),
|
|
864
|
+
actionExecutionId: message.id,
|
|
865
|
+
actionName: message.name
|
|
866
|
+
});
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
function getPairedFeAction(actions, message) {
|
|
870
|
+
let actionName = null;
|
|
871
|
+
if (message.isActionExecutionMessage()) {
|
|
872
|
+
actionName = message.name;
|
|
873
|
+
} else if (message.isResultMessage()) {
|
|
874
|
+
actionName = message.actionName;
|
|
875
|
+
}
|
|
876
|
+
return actions.find(
|
|
877
|
+
(action) => action.name === actionName && action.available === "frontend" || action.pairedAction === actionName
|
|
878
|
+
);
|
|
879
|
+
}
|
|
826
880
|
|
|
827
881
|
// src/components/copilot-provider/copilotkit.tsx
|
|
828
882
|
var import_react7 = require("react");
|
|
829
883
|
var import_react_dom = require("react-dom");
|
|
830
|
-
var
|
|
884
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
831
885
|
|
|
832
886
|
// src/context/copilot-messages-context.tsx
|
|
833
887
|
var import_react6 = __toESM(require("react"));
|
|
@@ -893,9 +947,9 @@ function useCopilotChat(_a = {}) {
|
|
|
893
947
|
const makeSystemMessageCallback = (0, import_react8.useCallback)(() => {
|
|
894
948
|
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
895
949
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
896
|
-
return new
|
|
950
|
+
return new import_runtime_client_gql4.TextMessage({
|
|
897
951
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
898
|
-
role:
|
|
952
|
+
role: import_runtime_client_gql4.Role.System
|
|
899
953
|
});
|
|
900
954
|
}, [getContextString, makeSystemMessage, chatInstructions]);
|
|
901
955
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -1047,11 +1101,11 @@ ${additionalInstructions}` : "");
|
|
|
1047
1101
|
}
|
|
1048
1102
|
|
|
1049
1103
|
// src/hooks/use-copilot-action.ts
|
|
1050
|
-
var
|
|
1104
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
1051
1105
|
var import_react9 = require("react");
|
|
1052
1106
|
function useCopilotAction(action, dependencies) {
|
|
1053
1107
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1054
|
-
const idRef = (0, import_react9.useRef)((0,
|
|
1108
|
+
const idRef = (0, import_react9.useRef)((0, import_shared4.randomId)());
|
|
1055
1109
|
const renderAndWaitRef = (0, import_react9.useRef)(null);
|
|
1056
1110
|
const { addToast } = useToast();
|
|
1057
1111
|
action = __spreadValues({}, action);
|
|
@@ -1153,7 +1207,7 @@ function isFrontendAction(action) {
|
|
|
1153
1207
|
|
|
1154
1208
|
// src/hooks/use-coagent-state-render.ts
|
|
1155
1209
|
var import_react10 = require("react");
|
|
1156
|
-
var
|
|
1210
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1157
1211
|
function useCoAgentStateRender(action, dependencies) {
|
|
1158
1212
|
const {
|
|
1159
1213
|
setCoAgentStateRender,
|
|
@@ -1162,7 +1216,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1162
1216
|
chatComponentsCache,
|
|
1163
1217
|
availableAgents
|
|
1164
1218
|
} = (0, import_react10.useContext)(CopilotContext);
|
|
1165
|
-
const idRef = (0, import_react10.useRef)((0,
|
|
1219
|
+
const idRef = (0, import_react10.useRef)((0, import_shared5.randomId)());
|
|
1166
1220
|
const { addToast } = useToast();
|
|
1167
1221
|
(0, import_react10.useEffect)(() => {
|
|
1168
1222
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
@@ -1244,24 +1298,33 @@ var import_react12 = require("react");
|
|
|
1244
1298
|
function convertToJSON(description, value) {
|
|
1245
1299
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1246
1300
|
}
|
|
1247
|
-
function useCopilotReadable({
|
|
1301
|
+
function useCopilotReadable({
|
|
1302
|
+
description,
|
|
1303
|
+
value,
|
|
1304
|
+
parentId,
|
|
1305
|
+
categories,
|
|
1306
|
+
convert,
|
|
1307
|
+
available = "enabled"
|
|
1308
|
+
}, dependencies) {
|
|
1248
1309
|
const { addContext, removeContext } = useCopilotContext();
|
|
1249
1310
|
const idRef = (0, import_react12.useRef)();
|
|
1250
1311
|
convert = convert || convertToJSON;
|
|
1251
1312
|
const information = convert(description, value);
|
|
1252
1313
|
(0, import_react12.useEffect)(() => {
|
|
1314
|
+
if (available === "disabled")
|
|
1315
|
+
return;
|
|
1253
1316
|
const id = addContext(information, parentId, categories);
|
|
1254
1317
|
idRef.current = id;
|
|
1255
1318
|
return () => {
|
|
1256
1319
|
removeContext(id);
|
|
1257
1320
|
};
|
|
1258
|
-
}, [information, parentId, addContext, removeContext, ...dependencies || []]);
|
|
1321
|
+
}, [available, information, parentId, addContext, removeContext, ...dependencies || []]);
|
|
1259
1322
|
return idRef.current;
|
|
1260
1323
|
}
|
|
1261
1324
|
|
|
1262
1325
|
// src/hooks/use-coagent.ts
|
|
1263
1326
|
var import_react13 = require("react");
|
|
1264
|
-
var
|
|
1327
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1265
1328
|
function useCoAgent(options) {
|
|
1266
1329
|
const generalContext = useCopilotContext();
|
|
1267
1330
|
const { availableAgents } = generalContext;
|
|
@@ -1312,7 +1375,7 @@ function useCoAgent(options) {
|
|
|
1312
1375
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
1313
1376
|
lastLoadedState.current = newState;
|
|
1314
1377
|
lastLoadedThreadId.current = threadId;
|
|
1315
|
-
const fetchedState = (0,
|
|
1378
|
+
const fetchedState = (0, import_shared6.parseJson)(newState, {});
|
|
1316
1379
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
1317
1380
|
}
|
|
1318
1381
|
});
|
|
@@ -1438,7 +1501,7 @@ var import_react15 = __toESM(require("react"));
|
|
|
1438
1501
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
1439
1502
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
1440
1503
|
const pendingActionRef = (0, import_react14.useRef)(null);
|
|
1441
|
-
const
|
|
1504
|
+
const executeAction2 = (0, import_react14.useCallback)(
|
|
1442
1505
|
(props) => {
|
|
1443
1506
|
if (typeof action.render === "function") {
|
|
1444
1507
|
return action.render(props);
|
|
@@ -1458,13 +1521,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
1458
1521
|
onSignInComplete: (authState) => {
|
|
1459
1522
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
1460
1523
|
if (pendingActionRef.current) {
|
|
1461
|
-
|
|
1524
|
+
executeAction2(pendingActionRef.current);
|
|
1462
1525
|
pendingActionRef.current = null;
|
|
1463
1526
|
}
|
|
1464
1527
|
}
|
|
1465
1528
|
}) : import_react15.default.createElement(import_react14.Fragment);
|
|
1466
1529
|
}
|
|
1467
|
-
return
|
|
1530
|
+
return executeAction2(props);
|
|
1468
1531
|
},
|
|
1469
1532
|
[action, authStates_c, setAuthStates_c]
|
|
1470
1533
|
);
|
|
@@ -1478,13 +1541,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
1478
1541
|
|
|
1479
1542
|
// src/hooks/use-langgraph-interrupt.ts
|
|
1480
1543
|
var import_react16 = require("react");
|
|
1481
|
-
var
|
|
1544
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1482
1545
|
function useLangGraphInterrupt(action, dependencies) {
|
|
1483
1546
|
var _a;
|
|
1484
1547
|
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react16.useContext)(CopilotContext);
|
|
1485
1548
|
const { runChatCompletion } = useCopilotChat();
|
|
1486
1549
|
const { addToast } = useToast();
|
|
1487
|
-
const actionId = (0,
|
|
1550
|
+
const actionId = (0, import_shared7.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
1488
1551
|
const hasAction = (0, import_react16.useMemo)(
|
|
1489
1552
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
1490
1553
|
[langGraphInterruptAction]
|
|
@@ -1561,6 +1624,22 @@ function useLangGraphInterruptRender() {
|
|
|
1561
1624
|
resolve: resolveInterrupt
|
|
1562
1625
|
});
|
|
1563
1626
|
}
|
|
1627
|
+
|
|
1628
|
+
// src/hooks/use-copilot-additional-instructions.ts
|
|
1629
|
+
var import_react18 = require("react");
|
|
1630
|
+
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
1631
|
+
const { setAdditionalInstructions } = useCopilotContext();
|
|
1632
|
+
(0, import_react18.useEffect)(() => {
|
|
1633
|
+
if (available === "disabled")
|
|
1634
|
+
return;
|
|
1635
|
+
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|
|
1636
|
+
return () => {
|
|
1637
|
+
setAdditionalInstructions(
|
|
1638
|
+
(prevInstructions) => (prevInstructions == null ? void 0 : prevInstructions.filter((instruction) => instruction !== instructions)) || []
|
|
1639
|
+
);
|
|
1640
|
+
};
|
|
1641
|
+
}, [available, instructions, setAdditionalInstructions, ...dependencies || []]);
|
|
1642
|
+
}
|
|
1564
1643
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1565
1644
|
0 && (module.exports = {
|
|
1566
1645
|
runAgent,
|
|
@@ -1569,6 +1648,7 @@ function useLangGraphInterruptRender() {
|
|
|
1569
1648
|
useCoAgent,
|
|
1570
1649
|
useCoAgentStateRender,
|
|
1571
1650
|
useCopilotAction,
|
|
1651
|
+
useCopilotAdditionalInstructions,
|
|
1572
1652
|
useCopilotAuthenticatedAction_c,
|
|
1573
1653
|
useCopilotChat,
|
|
1574
1654
|
useCopilotReadable,
|