@copilotkit/react-core 1.4.2-tyler-reset-chat.2 → 1.4.3-pre.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 +10 -17
- package/dist/{chunk-USL3EHJB.mjs → chunk-AG7FH7OD.mjs} +2 -2
- package/dist/{chunk-6QKA3SNN.mjs → chunk-DHGXL5PC.mjs} +16 -12
- package/dist/{chunk-6QKA3SNN.mjs.map → chunk-DHGXL5PC.mjs.map} +1 -1
- package/dist/{chunk-24AHWFXB.mjs → chunk-EUIBVFV6.mjs} +20 -41
- package/dist/chunk-EUIBVFV6.mjs.map +1 -0
- package/dist/{chunk-3AYELZJS.mjs → chunk-JHEAUB3Z.mjs} +2 -2
- package/dist/{chunk-YTYNTCQL.mjs → chunk-O22KGHOQ.mjs} +21 -37
- package/dist/chunk-O22KGHOQ.mjs.map +1 -0
- package/dist/{chunk-JR55I3FL.mjs → chunk-OT67R4NB.mjs} +2 -2
- package/dist/{chunk-XUPO37VH.mjs → chunk-UOVONDR6.mjs} +2 -2
- package/dist/{chunk-UYKBEKKH.mjs → chunk-XBVKTDXP.mjs} +16 -41
- package/dist/chunk-XBVKTDXP.mjs.map +1 -0
- package/dist/{chunk-2JP64U3A.mjs → chunk-XQFVXX6R.mjs} +5 -10
- package/dist/{chunk-2JP64U3A.mjs.map → chunk-XQFVXX6R.mjs.map} +1 -1
- package/dist/{chunk-3R4J2TPH.mjs → chunk-Y7MI4PBB.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit.js +18 -19
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +2 -2
- package/dist/components/copilot-provider/index.js +18 -19
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +18 -19
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +2 -6
- package/dist/context/copilot-context.js +4 -9
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +4 -9
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +52 -122
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +16 -22
- package/dist/hooks/use-chat.d.ts +6 -22
- package/dist/hooks/use-chat.js +19 -40
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent-state-render.js +4 -9
- 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 -14
- package/dist/hooks/use-coagent.js +52 -122
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +6 -12
- package/dist/hooks/use-copilot-action.js +4 -9
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +35 -86
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +5 -5
- package/dist/hooks/use-copilot-readable.js +4 -9
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +4 -9
- 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 +66 -132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -23
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +3 -3
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +3 -3
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +2 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +2 -2
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit.tsx +18 -10
- package/src/context/copilot-context.tsx +9 -22
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-chat.ts +28 -62
- package/src/hooks/use-coagent.ts +24 -38
- package/src/hooks/use-copilot-chat.ts +14 -41
- package/dist/chunk-24AHWFXB.mjs.map +0 -1
- package/dist/chunk-UYKBEKKH.mjs.map +0 -1
- package/dist/chunk-YTYNTCQL.mjs.map +0 -1
- /package/dist/{chunk-USL3EHJB.mjs.map → chunk-AG7FH7OD.mjs.map} +0 -0
- /package/dist/{chunk-3AYELZJS.mjs.map → chunk-JHEAUB3Z.mjs.map} +0 -0
- /package/dist/{chunk-JR55I3FL.mjs.map → chunk-OT67R4NB.mjs.map} +0 -0
- /package/dist/{chunk-XUPO37VH.mjs.map → chunk-UOVONDR6.mjs.map} +0 -0
- /package/dist/{chunk-3R4J2TPH.mjs.map → chunk-Y7MI4PBB.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-copilot-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["/**\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * In its most basic usage, useCopilotReadable accepts a single string argument\n * representing any piece of app state, making it available for the Copilot to use\n * as context when responding to user input.\n *\n * ```tsx\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotReadable({\n * description: \"The list of employees\",\n * value: employees,\n * });\n * }\n * ```\n *\n * ### Nested Components\n *\n * Optionally, you can maintain the hierarchical structure of information by passing\n * `parentId`. This allows you to use `useCopilotReadable` in nested components:\n *\n * ```tsx /employeeContextId/1 {17,23}\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * function Employee(props: EmployeeProps) {\n * const { employeeName, workProfile, metadata } = props;\n *\n * // propagate any information to copilot\n * const employeeContextId = useCopilotReadable({\n * description: \"Employee name\",\n * value: employeeName\n * });\n *\n * // Pass a parentID to maintain a hierarchical structure.\n * // Especially useful with child React components, list elements, etc.\n * useCopilotReadable({\n * description: \"Work profile\",\n * value: workProfile.description(),\n * parentId: employeeContextId\n * });\n *\n * useCopilotReadable({\n * description: \"Employee metadata\",\n * value: metadata.description(),\n * parentId: employeeContextId\n * });\n *\n * return (\n * // Render as usual...\n * );\n * }\n * ```\n */\nimport { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\n\n/**\n * Options for the useCopilotReadable hook.\n */\nexport interface UseCopilotReadableOptions {\n /**\n * The description of the information to be added to the Copilot context.\n */\n description: string;\n /**\n * The value to be added to the Copilot context. Object values are automatically stringified.\n */\n value: any;\n /**\n * The ID of the parent context, if any.\n */\n parentId?: string;\n /**\n * An array of categories to control which context are visible where. Particularly useful\n * with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n */\n categories?: string[];\n\n /**\n * A custom conversion function to use to serialize the value to a string. If not provided, the value\n * will be serialized using `JSON.stringify`.\n */\n convert?: (description: string, value: any) => string;\n}\n\nfunction convertToJSON(description: string, value: any): string {\n return `${description}: ${typeof value === \"string\" ? value : JSON.stringify(value)}`;\n}\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n */\nexport function useCopilotReadable(\n { description, value, parentId, categories, convert }: UseCopilotReadableOptions,\n dependencies?: any[],\n): string | undefined {\n const { addContext, removeContext } = useCopilotContext();\n const idRef = useRef<string>();\n convert = convert || convertToJSON;\n\n const information = convert(description, value);\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext, ...(dependencies || [])]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { CopilotRuntimeClient } from \"@copilotkit/runtime-client-gql\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\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 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 agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string | null;\n setThreadId: React.Dispatch<React.SetStateAction<string | null>>;\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\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\n agentSession: null,\n setAgentSession: () => {},\n\n agentLock: null,\n\n threadId: null,\n setThreadId: () => {},\n\n runId: null,\n setRunId: () => {},\n\n chatAbortControllerRef: { current: 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 return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+DA,IAAAA,gBAAkC;;;AC7DlC,mBAAkB;AAuJlB,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,EAEzB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EAExB,WAAW;AAAA,EAEX,UAAU;AAAA,EACV,aAAa,MAAM;AAAA,EAAC;AAAA,EAEpB,OAAO;AAAA,EACP,UAAU,MAAM;AAAA,EAAC;AAAA,EAEjB,wBAAwB,EAAE,SAAS,KAAK;AAC1C;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADrIA,SAAS,cAAc,aAAqB,OAAoB;AAC9D,SAAO,GAAG,gBAAgB,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;AACpF;AAKO,SAAS,mBACd,EAAE,aAAa,OAAO,UAAU,YAAY,QAAQ,GACpD,cACoB;AACpB,QAAM,EAAE,YAAY,cAAc,IAAI,kBAAkB;AACxD,QAAM,YAAQ,sBAAe;AAC7B,YAAU,WAAW;AAErB,QAAM,cAAc,QAAQ,aAAa,KAAK;AAE9C,+BAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,UAAU,UAAU;AACvD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,eAAe,GAAI,gBAAgB,CAAC,CAAE,CAAC;AAE9E,SAAO,MAAM;AACf;","names":["import_react","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-copilot-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["/**\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * In its most basic usage, useCopilotReadable accepts a single string argument\n * representing any piece of app state, making it available for the Copilot to use\n * as context when responding to user input.\n *\n * ```tsx\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotReadable({\n * description: \"The list of employees\",\n * value: employees,\n * });\n * }\n * ```\n *\n * ### Nested Components\n *\n * Optionally, you can maintain the hierarchical structure of information by passing\n * `parentId`. This allows you to use `useCopilotReadable` in nested components:\n *\n * ```tsx /employeeContextId/1 {17,23}\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * function Employee(props: EmployeeProps) {\n * const { employeeName, workProfile, metadata } = props;\n *\n * // propagate any information to copilot\n * const employeeContextId = useCopilotReadable({\n * description: \"Employee name\",\n * value: employeeName\n * });\n *\n * // Pass a parentID to maintain a hierarchical structure.\n * // Especially useful with child React components, list elements, etc.\n * useCopilotReadable({\n * description: \"Work profile\",\n * value: workProfile.description(),\n * parentId: employeeContextId\n * });\n *\n * useCopilotReadable({\n * description: \"Employee metadata\",\n * value: metadata.description(),\n * parentId: employeeContextId\n * });\n *\n * return (\n * // Render as usual...\n * );\n * }\n * ```\n */\nimport { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\n\n/**\n * Options for the useCopilotReadable hook.\n */\nexport interface UseCopilotReadableOptions {\n /**\n * The description of the information to be added to the Copilot context.\n */\n description: string;\n /**\n * The value to be added to the Copilot context. Object values are automatically stringified.\n */\n value: any;\n /**\n * The ID of the parent context, if any.\n */\n parentId?: string;\n /**\n * An array of categories to control which context are visible where. Particularly useful\n * with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n */\n categories?: string[];\n\n /**\n * A custom conversion function to use to serialize the value to a string. If not provided, the value\n * will be serialized using `JSON.stringify`.\n */\n convert?: (description: string, value: any) => string;\n}\n\nfunction convertToJSON(description: string, value: any): string {\n return `${description}: ${typeof value === \"string\" ? value : JSON.stringify(value)}`;\n}\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n */\nexport function useCopilotReadable(\n { description, value, parentId, categories, convert }: UseCopilotReadableOptions,\n dependencies?: any[],\n): string | undefined {\n const { addContext, removeContext } = useCopilotContext();\n const idRef = useRef<string>();\n convert = convert || convertToJSON;\n\n const information = convert(description, value);\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext, ...(dependencies || [])]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { CopilotRuntimeClient } from \"@copilotkit/runtime-client-gql\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\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 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 // runtime\n runtimeClient: CopilotRuntimeClient;\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\n agentSession: null,\n setAgentSession: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+DA,IAAAA,gBAAkC;;;AC7DlC,mBAAkB;AAkJlB,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,EAEhC,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAC1B;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADxHA,SAAS,cAAc,aAAqB,OAAoB;AAC9D,SAAO,GAAG,gBAAgB,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;AACpF;AAKO,SAAS,mBACd,EAAE,aAAa,OAAO,UAAU,YAAY,QAAQ,GACpD,cACoB;AACpB,QAAM,EAAE,YAAY,cAAc,IAAI,kBAAkB;AACxD,QAAM,YAAQ,sBAAe;AAC7B,YAAU,WAAW;AAErB,QAAM,cAAc,QAAQ,aAAa,KAAK;AAE9C,+BAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,UAAU,UAAU;AACvD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,eAAe,GAAI,gBAAgB,CAAC,CAAE,CAAC;AAE9E,SAAO,MAAM;AACf;","names":["import_react","React"]}
|
|
@@ -104,17 +104,12 @@ var emptyCopilotContext = {
|
|
|
104
104
|
coagentStates: {},
|
|
105
105
|
setCoagentStates: () => {
|
|
106
106
|
},
|
|
107
|
+
coagentStatesRef: { current: {} },
|
|
108
|
+
setCoagentStatesWithRef: () => {
|
|
109
|
+
},
|
|
107
110
|
agentSession: null,
|
|
108
111
|
setAgentSession: () => {
|
|
109
|
-
}
|
|
110
|
-
agentLock: null,
|
|
111
|
-
threadId: null,
|
|
112
|
-
setThreadId: () => {
|
|
113
|
-
},
|
|
114
|
-
runId: null,
|
|
115
|
-
setRunId: () => {
|
|
116
|
-
},
|
|
117
|
-
chatAbortControllerRef: { current: null }
|
|
112
|
+
}
|
|
118
113
|
};
|
|
119
114
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
120
115
|
function useCopilotContext() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { CopilotRuntimeClient } from \"@copilotkit/runtime-client-gql\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\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 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
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { CopilotRuntimeClient } from \"@copilotkit/runtime-client-gql\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\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 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 // runtime\n runtimeClient: CopilotRuntimeClient;\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\n agentSession: null,\n setAgentSession: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAkC;;;ACElC,mBAAkB;AAkJlB,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,EAEhC,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAC1B;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;AD5MO,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAAI,kBAAkB;AACxE,QAAM,YAAQ,sBAAe;AAE7B,+BAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,GAAG,YAAY,CAAC;AAE/D,SAAO,MAAM;AACf;","names":["import_react","React"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { useCoAgentStateRender } from './hooks/use-coagent-state-render.js';
|
|
|
8
8
|
export { useMakeCopilotDocumentReadable } from './hooks/use-make-copilot-document-readable.js';
|
|
9
9
|
export { UseChatHelpers } from './hooks/use-chat.js';
|
|
10
10
|
export { useCopilotReadable } from './hooks/use-copilot-readable.js';
|
|
11
|
-
export {
|
|
11
|
+
export { useCoAgent } from './hooks/use-coagent.js';
|
|
12
12
|
export { useCopilotRuntimeClient } from './hooks/use-copilot-runtime-client.js';
|
|
13
13
|
export { DocumentPointer } from './types/document-pointer.js';
|
|
14
14
|
export { SystemMessageFunction } from './types/system-message.js';
|
package/dist/index.js
CHANGED
|
@@ -87,10 +87,7 @@ __export(src_exports, {
|
|
|
87
87
|
CopilotTask: () => CopilotTask,
|
|
88
88
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
89
89
|
extract: () => extract,
|
|
90
|
-
runAgent: () => runAgent,
|
|
91
90
|
shouldShowDevConsole: () => shouldShowDevConsole,
|
|
92
|
-
startAgent: () => startAgent,
|
|
93
|
-
stopAgent: () => stopAgent,
|
|
94
91
|
useCoAgent: () => useCoAgent,
|
|
95
92
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
96
93
|
useCopilotAction: () => useCopilotAction,
|
|
@@ -155,17 +152,12 @@ var emptyCopilotContext = {
|
|
|
155
152
|
coagentStates: {},
|
|
156
153
|
setCoagentStates: () => {
|
|
157
154
|
},
|
|
155
|
+
coagentStatesRef: { current: {} },
|
|
156
|
+
setCoagentStatesWithRef: () => {
|
|
157
|
+
},
|
|
158
158
|
agentSession: null,
|
|
159
159
|
setAgentSession: () => {
|
|
160
|
-
}
|
|
161
|
-
agentLock: null,
|
|
162
|
-
threadId: null,
|
|
163
|
-
setThreadId: () => {
|
|
164
|
-
},
|
|
165
|
-
runId: null,
|
|
166
|
-
setRunId: () => {
|
|
167
|
-
},
|
|
168
|
-
chatAbortControllerRef: { current: null }
|
|
160
|
+
}
|
|
169
161
|
};
|
|
170
162
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
171
163
|
function useCopilotContext() {
|
|
@@ -957,6 +949,17 @@ ${nonDocumentStrings}`;
|
|
|
957
949
|
});
|
|
958
950
|
};
|
|
959
951
|
const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
|
|
952
|
+
const coagentStatesRef = (0, import_react8.useRef)({});
|
|
953
|
+
const setCoagentStatesWithRef = (0, import_react8.useCallback)(
|
|
954
|
+
(value) => {
|
|
955
|
+
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
956
|
+
coagentStatesRef.current = newValue;
|
|
957
|
+
setCoagentStates((prev) => {
|
|
958
|
+
return newValue;
|
|
959
|
+
});
|
|
960
|
+
},
|
|
961
|
+
[]
|
|
962
|
+
);
|
|
960
963
|
let initialAgentSession = null;
|
|
961
964
|
if (props.agent) {
|
|
962
965
|
initialAgentSession = {
|
|
@@ -964,9 +967,6 @@ ${nonDocumentStrings}`;
|
|
|
964
967
|
};
|
|
965
968
|
}
|
|
966
969
|
const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
|
|
967
|
-
const [threadId, setThreadId] = (0, import_react8.useState)(null);
|
|
968
|
-
const [runId, setRunId] = (0, import_react8.useState)(null);
|
|
969
|
-
const chatAbortControllerRef = (0, import_react8.useRef)(null);
|
|
970
970
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
971
971
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
972
972
|
CopilotContext.Provider,
|
|
@@ -997,15 +997,11 @@ ${nonDocumentStrings}`;
|
|
|
997
997
|
showDevConsole,
|
|
998
998
|
coagentStates,
|
|
999
999
|
setCoagentStates,
|
|
1000
|
+
coagentStatesRef,
|
|
1001
|
+
setCoagentStatesWithRef,
|
|
1000
1002
|
agentSession,
|
|
1001
1003
|
setAgentSession,
|
|
1002
|
-
runtimeClient
|
|
1003
|
-
agentLock: props.agent || null,
|
|
1004
|
-
threadId,
|
|
1005
|
-
setThreadId,
|
|
1006
|
-
runId,
|
|
1007
|
-
setRunId,
|
|
1008
|
-
chatAbortControllerRef
|
|
1004
|
+
runtimeClient
|
|
1009
1005
|
},
|
|
1010
1006
|
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
1011
1007
|
}
|
|
@@ -1058,26 +1054,18 @@ function useChat(options) {
|
|
|
1058
1054
|
actions,
|
|
1059
1055
|
onFunctionCall,
|
|
1060
1056
|
onCoAgentStateRender,
|
|
1061
|
-
|
|
1062
|
-
|
|
1057
|
+
setCoagentStatesWithRef,
|
|
1058
|
+
coagentStatesRef,
|
|
1063
1059
|
agentSession,
|
|
1064
|
-
setAgentSession
|
|
1065
|
-
threadId,
|
|
1066
|
-
setThreadId,
|
|
1067
|
-
runId,
|
|
1068
|
-
setRunId,
|
|
1069
|
-
chatAbortControllerRef
|
|
1060
|
+
setAgentSession
|
|
1070
1061
|
} = options;
|
|
1062
|
+
const abortControllerRef = (0, import_react9.useRef)();
|
|
1063
|
+
const threadIdRef = (0, import_react9.useRef)(null);
|
|
1064
|
+
const runIdRef = (0, import_react9.useRef)(null);
|
|
1071
1065
|
const { addGraphQLErrorsToast } = useToast();
|
|
1072
1066
|
const runChatCompletionRef = (0, import_react9.useRef)();
|
|
1073
|
-
const coagentStatesRef = (0, import_react9.useRef)(coagentStates);
|
|
1074
|
-
coagentStatesRef.current = coagentStates;
|
|
1075
1067
|
const agentSessionRef = (0, import_react9.useRef)(agentSession);
|
|
1076
1068
|
agentSessionRef.current = agentSession;
|
|
1077
|
-
const threadIdRef = (0, import_react9.useRef)(threadId);
|
|
1078
|
-
threadIdRef.current = threadId;
|
|
1079
|
-
const runIdRef = (0, import_react9.useRef)(runId);
|
|
1080
|
-
runIdRef.current = runId;
|
|
1081
1069
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
1082
1070
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared5.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1083
1071
|
const runtimeClient = useCopilotRuntimeClient({
|
|
@@ -1095,7 +1083,8 @@ function useChat(options) {
|
|
|
1095
1083
|
role: import_runtime_client_gql4.Role.Assistant
|
|
1096
1084
|
})
|
|
1097
1085
|
];
|
|
1098
|
-
|
|
1086
|
+
const abortController = new AbortController();
|
|
1087
|
+
abortControllerRef.current = abortController;
|
|
1099
1088
|
setMessages([...previousMessages, ...newMessages]);
|
|
1100
1089
|
const systemMessage = makeSystemMessageCallback();
|
|
1101
1090
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
@@ -1148,7 +1137,7 @@ function useChat(options) {
|
|
|
1148
1137
|
}))
|
|
1149
1138
|
}),
|
|
1150
1139
|
properties: copilotConfig.properties,
|
|
1151
|
-
signal: (_d =
|
|
1140
|
+
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
1152
1141
|
})
|
|
1153
1142
|
);
|
|
1154
1143
|
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
@@ -1167,9 +1156,6 @@ function useChat(options) {
|
|
|
1167
1156
|
break;
|
|
1168
1157
|
}
|
|
1169
1158
|
if (done) {
|
|
1170
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1171
|
-
return [];
|
|
1172
|
-
}
|
|
1173
1159
|
break;
|
|
1174
1160
|
}
|
|
1175
1161
|
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
@@ -1177,8 +1163,6 @@ function useChat(options) {
|
|
|
1177
1163
|
}
|
|
1178
1164
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
1179
1165
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
1180
|
-
setThreadId(threadIdRef.current);
|
|
1181
|
-
setRunId(runIdRef.current);
|
|
1182
1166
|
const messages2 = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1183
1167
|
(0, import_runtime_client_gql4.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
1184
1168
|
);
|
|
@@ -1207,22 +1191,12 @@ function useChat(options) {
|
|
|
1207
1191
|
if (action) {
|
|
1208
1192
|
followUp = action.followUp;
|
|
1209
1193
|
}
|
|
1210
|
-
const result = yield
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
new Promise((_, reject) => {
|
|
1217
|
-
var _a2;
|
|
1218
|
-
return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener("abort", () => reject(new Error("Operation was aborted")));
|
|
1219
|
-
})
|
|
1220
|
-
]);
|
|
1221
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1222
|
-
actionResults[message.id] = "";
|
|
1223
|
-
} else {
|
|
1224
|
-
actionResults[message.id] = result;
|
|
1225
|
-
}
|
|
1194
|
+
const result = yield onFunctionCall({
|
|
1195
|
+
messages: previousMessages,
|
|
1196
|
+
name: message.name,
|
|
1197
|
+
args: message.arguments
|
|
1198
|
+
});
|
|
1199
|
+
actionResults[message.id] = result;
|
|
1226
1200
|
} catch (e) {
|
|
1227
1201
|
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
1228
1202
|
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
@@ -1250,7 +1224,7 @@ function useChat(options) {
|
|
|
1250
1224
|
}
|
|
1251
1225
|
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
1252
1226
|
if (lastAgentStateMessage) {
|
|
1253
|
-
|
|
1227
|
+
setCoagentStatesWithRef((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1254
1228
|
[lastAgentStateMessage.agentName]: {
|
|
1255
1229
|
name: lastAgentStateMessage.agentName,
|
|
1256
1230
|
state: lastAgentStateMessage.state,
|
|
@@ -1317,12 +1291,13 @@ function useChat(options) {
|
|
|
1317
1291
|
});
|
|
1318
1292
|
const stop = () => {
|
|
1319
1293
|
var _a;
|
|
1320
|
-
(_a =
|
|
1294
|
+
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1321
1295
|
};
|
|
1322
1296
|
return {
|
|
1323
1297
|
append,
|
|
1324
1298
|
reload,
|
|
1325
|
-
stop
|
|
1299
|
+
stop,
|
|
1300
|
+
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
1326
1301
|
};
|
|
1327
1302
|
}
|
|
1328
1303
|
|
|
@@ -1341,17 +1316,11 @@ function useCopilotChat(_a = {}) {
|
|
|
1341
1316
|
setIsLoading,
|
|
1342
1317
|
chatInstructions,
|
|
1343
1318
|
actions,
|
|
1344
|
-
|
|
1345
|
-
|
|
1319
|
+
coagentStatesRef,
|
|
1320
|
+
setCoagentStatesWithRef,
|
|
1346
1321
|
coAgentStateRenders,
|
|
1347
1322
|
agentSession,
|
|
1348
|
-
setAgentSession
|
|
1349
|
-
agentLock,
|
|
1350
|
-
threadId,
|
|
1351
|
-
setThreadId,
|
|
1352
|
-
runId,
|
|
1353
|
-
setRunId,
|
|
1354
|
-
chatAbortControllerRef
|
|
1323
|
+
setAgentSession
|
|
1355
1324
|
} = useCopilotContext();
|
|
1356
1325
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1357
1326
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
@@ -1387,7 +1356,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1387
1356
|
}),
|
|
1388
1357
|
[coAgentStateRenders]
|
|
1389
1358
|
);
|
|
1390
|
-
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1359
|
+
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1391
1360
|
actions: Object.values(actions),
|
|
1392
1361
|
copilotConfig: copilotApiConfig,
|
|
1393
1362
|
initialMessages: options.initialMessages || [],
|
|
@@ -1398,15 +1367,10 @@ function useCopilotChat(_a = {}) {
|
|
|
1398
1367
|
makeSystemMessageCallback,
|
|
1399
1368
|
isLoading,
|
|
1400
1369
|
setIsLoading,
|
|
1401
|
-
|
|
1402
|
-
|
|
1370
|
+
coagentStatesRef,
|
|
1371
|
+
setCoagentStatesWithRef,
|
|
1403
1372
|
agentSession,
|
|
1404
|
-
setAgentSession
|
|
1405
|
-
threadId,
|
|
1406
|
-
setThreadId,
|
|
1407
|
-
runId,
|
|
1408
|
-
setRunId,
|
|
1409
|
-
chatAbortControllerRef
|
|
1373
|
+
setAgentSession
|
|
1410
1374
|
}));
|
|
1411
1375
|
const latestAppend = useUpdatedRef(append);
|
|
1412
1376
|
const latestAppendFunc = (0, import_react10.useCallback)(
|
|
@@ -1437,32 +1401,18 @@ function useCopilotChat(_a = {}) {
|
|
|
1437
1401
|
},
|
|
1438
1402
|
[latestSetMessages]
|
|
1439
1403
|
);
|
|
1440
|
-
const
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
setRunId(null);
|
|
1445
|
-
setCoagentStates({});
|
|
1446
|
-
let initialAgentSession = null;
|
|
1447
|
-
if (agentLock) {
|
|
1448
|
-
initialAgentSession = {
|
|
1449
|
-
agentName: agentLock
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
setAgentSession(initialAgentSession);
|
|
1453
|
-
}, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
|
|
1454
|
-
const latestReset = useUpdatedRef(reset);
|
|
1455
|
-
const latestResetFunc = (0, import_react10.useCallback)(() => {
|
|
1456
|
-
return latestReset.current();
|
|
1457
|
-
}, [latestReset]);
|
|
1404
|
+
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
1405
|
+
const latestRunChatCompletionFunc = (0, import_react10.useCallback)(() => {
|
|
1406
|
+
return latestRunChatCompletion.current();
|
|
1407
|
+
}, [latestRunChatCompletion]);
|
|
1458
1408
|
return {
|
|
1459
1409
|
visibleMessages: messages,
|
|
1460
1410
|
appendMessage: latestAppendFunc,
|
|
1461
1411
|
setMessages: latestSetMessagesFunc,
|
|
1462
1412
|
reloadMessages: latestReloadFunc,
|
|
1463
1413
|
stopGeneration: latestStopFunc,
|
|
1464
|
-
reset: latestResetFunc,
|
|
1465
1414
|
deleteMessage: latestDeleteFunc,
|
|
1415
|
+
runChatCompletion: latestRunChatCompletionFunc,
|
|
1466
1416
|
isLoading
|
|
1467
1417
|
};
|
|
1468
1418
|
}
|
|
@@ -1665,8 +1615,8 @@ function useCoAgent(options) {
|
|
|
1665
1615
|
const generalContext = useCopilotContext();
|
|
1666
1616
|
const messagesContext = useCopilotMessagesContext();
|
|
1667
1617
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1668
|
-
const { coagentStates,
|
|
1669
|
-
const { appendMessage } = useCopilotChat();
|
|
1618
|
+
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
|
|
1619
|
+
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
1670
1620
|
const getCoagentState = (coagentStates2, name2) => {
|
|
1671
1621
|
if (coagentStates2[name2]) {
|
|
1672
1622
|
return coagentStates2[name2];
|
|
@@ -1683,15 +1633,13 @@ function useCoAgent(options) {
|
|
|
1683
1633
|
}
|
|
1684
1634
|
};
|
|
1685
1635
|
const setState = (newState) => {
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
});
|
|
1694
|
-
});
|
|
1636
|
+
let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
|
|
1637
|
+
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
1638
|
+
setCoagentStatesWithRef(__spreadProps(__spreadValues({}, coagentStatesRef.current), {
|
|
1639
|
+
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
1640
|
+
state: updatedState
|
|
1641
|
+
})
|
|
1642
|
+
}));
|
|
1695
1643
|
};
|
|
1696
1644
|
const coagentState = getCoagentState(coagentStates, name);
|
|
1697
1645
|
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
@@ -1701,11 +1649,7 @@ function useCoAgent(options) {
|
|
|
1701
1649
|
} else if (coagentStates[name] === void 0) {
|
|
1702
1650
|
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
1703
1651
|
}
|
|
1704
|
-
}, [
|
|
1705
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
1706
|
-
// reset initialstate on reset
|
|
1707
|
-
coagentStates[name] === void 0
|
|
1708
|
-
]);
|
|
1652
|
+
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
1709
1653
|
return {
|
|
1710
1654
|
name,
|
|
1711
1655
|
nodeName: coagentState.nodeName,
|
|
@@ -1719,7 +1663,7 @@ function useCoAgent(options) {
|
|
|
1719
1663
|
stopAgent(name, context);
|
|
1720
1664
|
},
|
|
1721
1665
|
run: (hint) => {
|
|
1722
|
-
return runAgent(name, context, appendMessage, hint);
|
|
1666
|
+
return runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
1723
1667
|
}
|
|
1724
1668
|
};
|
|
1725
1669
|
}
|
|
@@ -1733,22 +1677,11 @@ function stopAgent(name, context) {
|
|
|
1733
1677
|
const { agentSession, setAgentSession } = context;
|
|
1734
1678
|
if (agentSession && agentSession.agentName === name) {
|
|
1735
1679
|
setAgentSession(null);
|
|
1736
|
-
context.setCoagentStates((prevAgentStates) => {
|
|
1737
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1738
|
-
[name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
|
|
1739
|
-
running: false,
|
|
1740
|
-
active: false,
|
|
1741
|
-
threadId: void 0,
|
|
1742
|
-
nodeName: void 0,
|
|
1743
|
-
runId: void 0
|
|
1744
|
-
})
|
|
1745
|
-
});
|
|
1746
|
-
});
|
|
1747
1680
|
} else {
|
|
1748
1681
|
console.warn(`No agent session found for ${name}`);
|
|
1749
1682
|
}
|
|
1750
1683
|
}
|
|
1751
|
-
function runAgent(name, context, appendMessage, hint) {
|
|
1684
|
+
function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
1752
1685
|
return __async(this, null, function* () {
|
|
1753
1686
|
var _a, _b;
|
|
1754
1687
|
const { agentSession, setAgentSession } = context;
|
|
@@ -1764,12 +1697,16 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
1764
1697
|
previousState = message.state;
|
|
1765
1698
|
}
|
|
1766
1699
|
}
|
|
1767
|
-
let state = ((_b = (_a = context.
|
|
1700
|
+
let state = ((_b = (_a = context.coagentStatesRef.current) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
|
|
1768
1701
|
if (hint) {
|
|
1769
1702
|
const hintMessage = hint({ previousState, currentState: state });
|
|
1770
1703
|
if (hintMessage) {
|
|
1771
1704
|
yield appendMessage(hintMessage);
|
|
1705
|
+
} else {
|
|
1706
|
+
yield runChatCompletion();
|
|
1772
1707
|
}
|
|
1708
|
+
} else {
|
|
1709
|
+
yield runChatCompletion();
|
|
1773
1710
|
}
|
|
1774
1711
|
});
|
|
1775
1712
|
}
|
|
@@ -1881,10 +1818,7 @@ ${instructions}
|
|
|
1881
1818
|
CopilotTask,
|
|
1882
1819
|
defaultCopilotContextCategories,
|
|
1883
1820
|
extract,
|
|
1884
|
-
runAgent,
|
|
1885
1821
|
shouldShowDevConsole,
|
|
1886
|
-
startAgent,
|
|
1887
|
-
stopAgent,
|
|
1888
1822
|
useCoAgent,
|
|
1889
1823
|
useCoAgentStateRender,
|
|
1890
1824
|
useCopilotAction,
|