@copilotkitnext/react 1.54.1-next.5 → 1.54.1-next.6

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.
Files changed (33) hide show
  1. package/dist/components/chat/CopilotChat.cjs +3 -2
  2. package/dist/components/chat/CopilotChat.cjs.map +1 -1
  3. package/dist/components/chat/CopilotChat.d.cts +2 -0
  4. package/dist/components/chat/CopilotChat.d.cts.map +1 -1
  5. package/dist/components/chat/CopilotChat.d.mts +2 -0
  6. package/dist/components/chat/CopilotChat.d.mts.map +1 -1
  7. package/dist/components/chat/CopilotChat.mjs +3 -2
  8. package/dist/components/chat/CopilotChat.mjs.map +1 -1
  9. package/dist/components/chat/CopilotPopup.cjs +1 -0
  10. package/dist/components/chat/CopilotPopup.cjs.map +1 -1
  11. package/dist/components/chat/CopilotPopup.mjs +1 -0
  12. package/dist/components/chat/CopilotPopup.mjs.map +1 -1
  13. package/dist/components/chat/CopilotSidebar.cjs +1 -0
  14. package/dist/components/chat/CopilotSidebar.cjs.map +1 -1
  15. package/dist/components/chat/CopilotSidebar.mjs +1 -0
  16. package/dist/components/chat/CopilotSidebar.mjs.map +1 -1
  17. package/dist/hooks/use-threads.cjs +18 -6
  18. package/dist/hooks/use-threads.cjs.map +1 -1
  19. package/dist/hooks/use-threads.d.cts +24 -4
  20. package/dist/hooks/use-threads.d.cts.map +1 -1
  21. package/dist/hooks/use-threads.d.mts +24 -4
  22. package/dist/hooks/use-threads.d.mts.map +1 -1
  23. package/dist/hooks/use-threads.mjs +19 -7
  24. package/dist/hooks/use-threads.mjs.map +1 -1
  25. package/dist/index.umd.js +40 -10
  26. package/dist/index.umd.js.map +1 -1
  27. package/dist/providers/CopilotChatConfigurationProvider.cjs +17 -2
  28. package/dist/providers/CopilotChatConfigurationProvider.cjs.map +1 -1
  29. package/dist/providers/CopilotChatConfigurationProvider.d.cts.map +1 -1
  30. package/dist/providers/CopilotChatConfigurationProvider.d.mts.map +1 -1
  31. package/dist/providers/CopilotChatConfigurationProvider.mjs +18 -3
  32. package/dist/providers/CopilotChatConfigurationProvider.mjs.map +1 -1
  33. package/package.json +7 -7
@@ -13,7 +13,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
13
13
  let ts_deepmerge = require("ts-deepmerge");
14
14
 
15
15
  //#region src/components/chat/CopilotChat.tsx
16
- function CopilotChat({ agentId, threadId, labels, chatView, onError, ...props }) {
16
+ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, onError, ...props }) {
17
17
  const existingConfig = require_CopilotChatConfigurationProvider.useCopilotChatConfiguration();
18
18
  const resolvedAgentId = agentId ?? existingConfig?.agentId ?? _copilotkitnext_shared.DEFAULT_AGENT_ID;
19
19
  const resolvedThreadId = (0, react.useMemo)(() => threadId ?? existingConfig?.threadId ?? (0, _copilotkitnext_shared.randomUUID)(), [threadId, existingConfig?.threadId]);
@@ -61,7 +61,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, onError, ...props })
61
61
  return () => {
62
62
  detached = true;
63
63
  connectAbortController.abort();
64
- agent.detachActiveRun();
64
+ agent.detachActiveRun().catch(() => {});
65
65
  };
66
66
  }, [
67
67
  resolvedThreadId,
@@ -196,6 +196,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, onError, ...props })
196
196
  agentId: resolvedAgentId,
197
197
  threadId: resolvedThreadId,
198
198
  labels,
199
+ isModalDefaultOpen,
199
200
  children: [transcriptionError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
200
201
  style: {
201
202
  position: "absolute",
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotChat.cjs","names":["useCopilotChatConfiguration","DEFAULT_AGENT_ID","useAgent","useCopilotKit","useSuggestions","HttpAgent","transcribeAudio","TranscriptionError","TranscriptionErrorCode","renderSlot","CopilotChatView","CopilotChatConfigurationProvider"],"sources":["../../../src/components/chat/CopilotChat.tsx"],"sourcesContent":["import { useAgent } from \"@/hooks/use-agent\";\nimport { useSuggestions } from \"@/hooks/use-suggestions\";\nimport { CopilotChatView, CopilotChatViewProps } from \"./CopilotChatView\";\nimport { CopilotChatInputMode } from \"./CopilotChatInput\";\nimport {\n CopilotChatConfigurationProvider,\n CopilotChatLabels,\n useCopilotChatConfiguration,\n} from \"@/providers/CopilotChatConfigurationProvider\";\nimport {\n DEFAULT_AGENT_ID,\n randomUUID,\n TranscriptionErrorCode,\n} from \"@copilotkitnext/shared\";\nimport { Suggestion, CopilotKitCoreErrorCode } from \"@copilotkitnext/core\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { merge } from \"ts-deepmerge\";\nimport { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport { AbstractAgent, HttpAgent } from \"@ag-ui/client\";\nimport { renderSlot, SlotValue } from \"@/lib/slots\";\nimport {\n transcribeAudio,\n TranscriptionError,\n} from \"@/lib/transcription-client\";\n\nexport type CopilotChatProps = Omit<\n CopilotChatViewProps,\n | \"messages\"\n | \"isRunning\"\n | \"suggestions\"\n | \"suggestionLoadingIndexes\"\n | \"onSelectSuggestion\"\n> & {\n agentId?: string;\n threadId?: string;\n labels?: Partial<CopilotChatLabels>;\n chatView?: SlotValue<typeof CopilotChatView>;\n /**\n * Error handler scoped to this chat's agent. Fires in addition to the\n * provider-level onError (does not suppress it). Receives only errors\n * whose context.agentId matches this chat's agent.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void | Promise<void>;\n};\nexport function CopilotChat({\n agentId,\n threadId,\n labels,\n chatView,\n onError,\n ...props\n}: CopilotChatProps) {\n // Check for existing configuration provider\n const existingConfig = useCopilotChatConfiguration();\n\n // Apply priority: props > existing config > defaults\n const resolvedAgentId =\n agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID;\n const resolvedThreadId = useMemo(\n () => threadId ?? existingConfig?.threadId ?? randomUUID(),\n [threadId, existingConfig?.threadId],\n );\n\n const { agent } = useAgent({ agentId: resolvedAgentId });\n const { copilotkit } = useCopilotKit();\n const { suggestions: autoSuggestions } = useSuggestions({\n agentId: resolvedAgentId,\n });\n\n // onError subscription — forward core errors scoped to this chat's agent\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n useEffect(() => {\n if (!onErrorRef.current) return;\n\n const subscription = copilotkit.subscribe({\n onError: (event) => {\n // Only forward errors that match this chat's agent\n if (\n event.context?.agentId === resolvedAgentId ||\n !event.context?.agentId\n ) {\n onErrorRef.current?.({\n error: event.error,\n code: event.code,\n context: event.context,\n });\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [copilotkit, resolvedAgentId]);\n\n // Transcription state\n const [transcribeMode, setTranscribeMode] =\n useState<CopilotChatInputMode>(\"input\");\n const [inputValue, setInputValue] = useState(\"\");\n const [transcriptionError, setTranscriptionError] = useState<string | null>(\n null,\n );\n const [isTranscribing, setIsTranscribing] = useState(false);\n\n // Check if transcription is enabled\n const isTranscriptionEnabled = copilotkit.audioFileTranscriptionEnabled;\n\n // Check if browser supports MediaRecorder\n const isMediaRecorderSupported =\n typeof window !== \"undefined\" && typeof MediaRecorder !== \"undefined\";\n\n const {\n messageView: providedMessageView,\n suggestionView: providedSuggestionView,\n onStop: providedStopHandler,\n ...restProps\n } = props;\n\n useEffect(() => {\n let detached = false;\n\n // Create a fresh AbortController so we can cancel the HTTP request on cleanup.\n // HttpAgent (parent of ProxiedCopilotRuntimeAgent) uses this.abortController.signal\n // in its fetch config. Unlike runAgent(), connectAgent() does NOT create a new\n // AbortController automatically, so we must set one before connecting.\n const connectAbortController = new AbortController();\n if (agent instanceof HttpAgent) {\n agent.abortController = connectAbortController;\n }\n\n const connect = async (agent: AbstractAgent) => {\n try {\n await copilotkit.connectAgent({ agent });\n } catch (error) {\n // Ignore errors from aborted connections (e.g., React StrictMode cleanup)\n if (detached) return;\n // connectAgent already emits via the subscriber system, but catch\n // here to prevent unhandled rejections from unexpected errors.\n console.error(\"CopilotChat: connectAgent failed\", error);\n }\n };\n agent.threadId = resolvedThreadId;\n connect(agent);\n return () => {\n // Abort the HTTP request and detach the active run.\n // This is critical for React StrictMode which unmounts+remounts in dev,\n // preventing duplicate /connect requests from reaching the server.\n detached = true;\n connectAbortController.abort();\n agent.detachActiveRun();\n };\n // copilotkit is intentionally excluded — it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [resolvedThreadId, agent, resolvedAgentId]);\n\n const onSubmitInput = useCallback(\n async (value: string) => {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: value,\n });\n // Clear input after submitting\n setInputValue(\"\");\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n },\n // copilotkit is intentionally excluded — it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent],\n );\n\n const handleSelectSuggestion = useCallback(\n async (suggestion: Suggestion) => {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: suggestion.message,\n });\n\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\n \"CopilotChat: runAgent failed after selecting suggestion\",\n error,\n );\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent],\n );\n\n const stopCurrentRun = useCallback(() => {\n try {\n copilotkit.stopAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: stopAgent failed\", error);\n try {\n agent.abortRun();\n } catch (abortError) {\n console.error(\"CopilotChat: abortRun fallback failed\", abortError);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agent]);\n\n // Transcription handlers\n const handleStartTranscribe = useCallback(() => {\n setTranscriptionError(null);\n setTranscribeMode(\"transcribe\");\n }, []);\n\n const handleCancelTranscribe = useCallback(() => {\n setTranscriptionError(null);\n setTranscribeMode(\"input\");\n }, []);\n\n const handleFinishTranscribe = useCallback(() => {\n setTranscribeMode(\"input\");\n }, []);\n\n // Handle audio blob from CopilotChatInput and transcribe it\n const handleFinishTranscribeWithAudio = useCallback(\n async (audioBlob: Blob) => {\n setIsTranscribing(true);\n try {\n setTranscriptionError(null);\n\n // Send to transcription endpoint\n const result = await transcribeAudio(copilotkit, audioBlob);\n\n // Insert transcribed text into input\n setInputValue((prev) => {\n const trimmedPrev = prev.trim();\n if (trimmedPrev) {\n return `${trimmedPrev} ${result.text}`;\n }\n return result.text;\n });\n } catch (error) {\n console.error(\"CopilotChat: Transcription failed\", error);\n\n // Show contextual error message based on error type\n if (error instanceof TranscriptionError) {\n const { code, retryable, message } = error.info;\n switch (code) {\n case TranscriptionErrorCode.RATE_LIMITED:\n setTranscriptionError(\"Too many requests. Please wait a moment.\");\n break;\n case TranscriptionErrorCode.AUTH_FAILED:\n setTranscriptionError(\n \"Authentication error. Please check your configuration.\",\n );\n break;\n case TranscriptionErrorCode.AUDIO_TOO_LONG:\n setTranscriptionError(\n \"Recording is too long. Please try a shorter recording.\",\n );\n break;\n case TranscriptionErrorCode.AUDIO_TOO_SHORT:\n setTranscriptionError(\n \"Recording is too short. Please try again.\",\n );\n break;\n case TranscriptionErrorCode.INVALID_AUDIO_FORMAT:\n setTranscriptionError(\"Audio format not supported.\");\n break;\n case TranscriptionErrorCode.SERVICE_NOT_CONFIGURED:\n setTranscriptionError(\"Transcription service is not available.\");\n break;\n case TranscriptionErrorCode.NETWORK_ERROR:\n setTranscriptionError(\n \"Network error. Please check your connection.\",\n );\n break;\n default:\n // For retryable errors, show more helpful message\n setTranscriptionError(\n retryable ? \"Transcription failed. Please try again.\" : message,\n );\n }\n } else {\n // Fallback for unexpected errors\n setTranscriptionError(\"Transcription failed. Please try again.\");\n }\n } finally {\n setIsTranscribing(false);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n // Clear transcription error after a delay\n useEffect(() => {\n if (transcriptionError) {\n const timer = setTimeout(() => {\n setTranscriptionError(null);\n }, 5000);\n return () => clearTimeout(timer);\n }\n }, [transcriptionError]);\n\n const mergedProps = merge(\n {\n isRunning: agent.isRunning,\n suggestions: autoSuggestions,\n onSelectSuggestion: handleSelectSuggestion,\n suggestionView: providedSuggestionView,\n },\n {\n ...restProps,\n ...(typeof providedMessageView === \"string\"\n ? { messageView: { className: providedMessageView } }\n : providedMessageView !== undefined\n ? { messageView: providedMessageView }\n : {}),\n },\n );\n\n const hasMessages = agent.messages.length > 0;\n const shouldAllowStop = agent.isRunning && hasMessages;\n const effectiveStopHandler = shouldAllowStop\n ? (providedStopHandler ?? stopCurrentRun)\n : providedStopHandler;\n\n // Determine if transcription feature should be available\n const showTranscription = isTranscriptionEnabled && isMediaRecorderSupported;\n\n // Determine mode: transcribing takes priority, then transcribe mode, then default to input\n const effectiveMode: CopilotChatInputMode = isTranscribing\n ? \"processing\"\n : transcribeMode;\n\n // Memoize messages array - only create new reference when content actually changes\n // (agent.messages is mutated in place, so we need a new reference for React to detect changes)\n\n const messages = useMemo(\n () => [...agent.messages],\n [JSON.stringify(agent.messages)],\n );\n\n const finalProps = merge(mergedProps, {\n messages,\n // Input behavior props\n onSubmitMessage: onSubmitInput,\n onStop: effectiveStopHandler,\n inputMode: effectiveMode,\n inputValue,\n onInputChange: setInputValue,\n // Only provide transcription handlers if feature is available\n onStartTranscribe: showTranscription ? handleStartTranscribe : undefined,\n onCancelTranscribe: showTranscription ? handleCancelTranscribe : undefined,\n onFinishTranscribe: showTranscription ? handleFinishTranscribe : undefined,\n onFinishTranscribeWithAudio: showTranscription\n ? handleFinishTranscribeWithAudio\n : undefined,\n }) as CopilotChatViewProps;\n\n // Always create a provider with merged values\n // This ensures priority: props > existing config > defaults\n const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);\n\n return (\n <CopilotChatConfigurationProvider\n agentId={resolvedAgentId}\n threadId={resolvedThreadId}\n labels={labels}\n >\n {transcriptionError && (\n <div\n style={{\n position: \"absolute\",\n bottom: \"100px\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n backgroundColor: \"#ef4444\",\n color: \"white\",\n padding: \"8px 16px\",\n borderRadius: \"8px\",\n fontSize: \"14px\",\n zIndex: 50,\n }}\n >\n {transcriptionError}\n </div>\n )}\n {RenderedChatView}\n </CopilotChatConfigurationProvider>\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace CopilotChat {\n export const View = CopilotChatView;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgDA,SAAgB,YAAY,EAC1B,SACA,UACA,QACA,UACA,SACA,GAAG,SACgB;CAEnB,MAAM,iBAAiBA,sEAA6B;CAGpD,MAAM,kBACJ,WAAW,gBAAgB,WAAWC;CACxC,MAAM,4CACE,YAAY,gBAAgB,oDAAwB,EAC1D,CAAC,UAAU,gBAAgB,SAAS,CACrC;CAED,MAAM,EAAE,UAAUC,2BAAS,EAAE,SAAS,iBAAiB,CAAC;CACxD,MAAM,EAAE,eAAeC,0CAAe;CACtC,MAAM,EAAE,aAAa,oBAAoBC,uCAAe,EACtD,SAAS,iBACV,CAAC;CAGF,MAAM,+BAAoB,QAAQ;AAClC,4BAAgB;AACd,aAAW,UAAU;IACpB,CAAC,QAAQ,CAAC;AAEb,4BAAgB;AACd,MAAI,CAAC,WAAW,QAAS;EAEzB,MAAM,eAAe,WAAW,UAAU,EACxC,UAAU,UAAU;AAElB,OACE,MAAM,SAAS,YAAY,mBAC3B,CAAC,MAAM,SAAS,QAEhB,YAAW,UAAU;IACnB,OAAO,MAAM;IACb,MAAM,MAAM;IACZ,SAAS,MAAM;IAChB,CAAC;KAGP,CAAC;AAEF,eAAa;AACX,gBAAa,aAAa;;IAE3B,CAAC,YAAY,gBAAgB,CAAC;CAGjC,MAAM,CAAC,gBAAgB,yCACU,QAAQ;CACzC,MAAM,CAAC,YAAY,qCAA0B,GAAG;CAChD,MAAM,CAAC,oBAAoB,6CACzB,KACD;CACD,MAAM,CAAC,gBAAgB,yCAA8B,MAAM;CAG3D,MAAM,yBAAyB,WAAW;CAG1C,MAAM,2BACJ,OAAO,WAAW,eAAe,OAAO,kBAAkB;CAE5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,wBAAwB,WAC/B,EAAE,aAAa,EAAE,WAAW,qBAAqB,EAAE,GACnD,wBAAwB,SACtB,EAAE,aAAa,qBAAqB,GACpC,EAAE;EACT,CACF;CAED,MAAM,cAAc,MAAM,SAAS,SAAS;CAE5C,MAAM,uBADkB,MAAM,aAAa,cAEtC,uBAAuB,iBACxB;CAGJ,MAAM,oBAAoB,0BAA0B;CAGpD,MAAM,gBAAsC,iBACxC,eACA;CA6BJ,MAAM,mBAAmBC,yBAAW,UAAUC,iEAnBrB,aAAa;EACpC,mCALM,CAAC,GAAG,MAAM,SAAS,EACzB,CAAC,KAAK,UAAU,MAAM,SAAS,CAAC,CACjC;EAKC,iBAAiB;EACjB,QAAQ;EACR,WAAW;EACX;EACA,eAAe;EAEf,mBAAmB,oBAAoB,wBAAwB;EAC/D,oBAAoB,oBAAoB,yBAAyB;EACjE,oBAAoB,oBAAoB,yBAAyB;EACjE,6BAA6B,oBACzB,kCACA;EACL,CAAC,CAIwE;AAE1E,QACE,4CAACC;EACC,SAAS;EACT,UAAU;EACF;aAEP,sBACC,2CAAC;GACC,OAAO;IACL,UAAU;IACV,QAAQ;IACR,MAAM;IACN,WAAW;IACX,iBAAiB;IACjB,OAAO;IACP,SAAS;IACT,cAAc;IACd,UAAU;IACV,QAAQ;IACT;aAEA;IACG,EAEP;GACgC;;;qBAMjBD"}
1
+ {"version":3,"file":"CopilotChat.cjs","names":["useCopilotChatConfiguration","DEFAULT_AGENT_ID","useAgent","useCopilotKit","useSuggestions","HttpAgent","transcribeAudio","TranscriptionError","TranscriptionErrorCode","renderSlot","CopilotChatView","CopilotChatConfigurationProvider"],"sources":["../../../src/components/chat/CopilotChat.tsx"],"sourcesContent":["import { useAgent } from \"@/hooks/use-agent\";\nimport { useSuggestions } from \"@/hooks/use-suggestions\";\nimport { CopilotChatView, CopilotChatViewProps } from \"./CopilotChatView\";\nimport { CopilotChatInputMode } from \"./CopilotChatInput\";\nimport {\n CopilotChatConfigurationProvider,\n CopilotChatLabels,\n useCopilotChatConfiguration,\n} from \"@/providers/CopilotChatConfigurationProvider\";\nimport {\n DEFAULT_AGENT_ID,\n randomUUID,\n TranscriptionErrorCode,\n} from \"@copilotkitnext/shared\";\nimport { Suggestion, CopilotKitCoreErrorCode } from \"@copilotkitnext/core\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { merge } from \"ts-deepmerge\";\nimport { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport { AbstractAgent, HttpAgent } from \"@ag-ui/client\";\nimport { renderSlot, SlotValue } from \"@/lib/slots\";\nimport {\n transcribeAudio,\n TranscriptionError,\n} from \"@/lib/transcription-client\";\n\nexport type CopilotChatProps = Omit<\n CopilotChatViewProps,\n | \"messages\"\n | \"isRunning\"\n | \"suggestions\"\n | \"suggestionLoadingIndexes\"\n | \"onSelectSuggestion\"\n> & {\n agentId?: string;\n threadId?: string;\n labels?: Partial<CopilotChatLabels>;\n chatView?: SlotValue<typeof CopilotChatView>;\n isModalDefaultOpen?: boolean;\n /**\n * Error handler scoped to this chat's agent. Fires in addition to the\n * provider-level onError (does not suppress it). Receives only errors\n * whose context.agentId matches this chat's agent.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void | Promise<void>;\n};\nexport function CopilotChat({\n agentId,\n threadId,\n labels,\n chatView,\n isModalDefaultOpen,\n onError,\n ...props\n}: CopilotChatProps) {\n // Check for existing configuration provider\n const existingConfig = useCopilotChatConfiguration();\n\n // Apply priority: props > existing config > defaults\n const resolvedAgentId =\n agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID;\n const resolvedThreadId = useMemo(\n () => threadId ?? existingConfig?.threadId ?? randomUUID(),\n [threadId, existingConfig?.threadId],\n );\n\n const { agent } = useAgent({ agentId: resolvedAgentId });\n const { copilotkit } = useCopilotKit();\n const { suggestions: autoSuggestions } = useSuggestions({\n agentId: resolvedAgentId,\n });\n\n // onError subscription — forward core errors scoped to this chat's agent\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n useEffect(() => {\n if (!onErrorRef.current) return;\n\n const subscription = copilotkit.subscribe({\n onError: (event) => {\n // Only forward errors that match this chat's agent\n if (\n event.context?.agentId === resolvedAgentId ||\n !event.context?.agentId\n ) {\n onErrorRef.current?.({\n error: event.error,\n code: event.code,\n context: event.context,\n });\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [copilotkit, resolvedAgentId]);\n\n // Transcription state\n const [transcribeMode, setTranscribeMode] =\n useState<CopilotChatInputMode>(\"input\");\n const [inputValue, setInputValue] = useState(\"\");\n const [transcriptionError, setTranscriptionError] = useState<string | null>(\n null,\n );\n const [isTranscribing, setIsTranscribing] = useState(false);\n\n // Check if transcription is enabled\n const isTranscriptionEnabled = copilotkit.audioFileTranscriptionEnabled;\n\n // Check if browser supports MediaRecorder\n const isMediaRecorderSupported =\n typeof window !== \"undefined\" && typeof MediaRecorder !== \"undefined\";\n\n const {\n messageView: providedMessageView,\n suggestionView: providedSuggestionView,\n onStop: providedStopHandler,\n ...restProps\n } = props;\n\n useEffect(() => {\n let detached = false;\n\n // Create a fresh AbortController so we can cancel the HTTP request on cleanup.\n // HttpAgent (parent of ProxiedCopilotRuntimeAgent) uses this.abortController.signal\n // in its fetch config. Unlike runAgent(), connectAgent() does NOT create a new\n // AbortController automatically, so we must set one before connecting.\n const connectAbortController = new AbortController();\n if (agent instanceof HttpAgent) {\n agent.abortController = connectAbortController;\n }\n\n const connect = async (agent: AbstractAgent) => {\n try {\n await copilotkit.connectAgent({ agent });\n } catch (error) {\n // Ignore errors from aborted connections (e.g., React StrictMode cleanup)\n if (detached) return;\n // connectAgent already emits via the subscriber system, but catch\n // here to prevent unhandled rejections from unexpected errors.\n console.error(\"CopilotChat: connectAgent failed\", error);\n }\n };\n agent.threadId = resolvedThreadId;\n connect(agent);\n return () => {\n // Abort the HTTP request and detach the active run.\n // This is critical for React StrictMode which unmounts+remounts in dev,\n // preventing duplicate /connect requests from reaching the server.\n detached = true;\n connectAbortController.abort();\n // The .catch() is required to prevent a false-positive \"Uncaught (in promise)\n // AbortError\" in browser devtools. detachActiveRun() itself does not reject,\n // but without an attached handler V8 flags the promise chain as unhandled\n // when the abort signal propagates through connected promises internally.\n void agent.detachActiveRun().catch(() => {});\n };\n // copilotkit is intentionally excluded — it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [resolvedThreadId, agent, resolvedAgentId]);\n\n const onSubmitInput = useCallback(\n async (value: string) => {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: value,\n });\n // Clear input after submitting\n setInputValue(\"\");\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n },\n // copilotkit is intentionally excluded — it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent],\n );\n\n const handleSelectSuggestion = useCallback(\n async (suggestion: Suggestion) => {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: suggestion.message,\n });\n\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\n \"CopilotChat: runAgent failed after selecting suggestion\",\n error,\n );\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent],\n );\n\n const stopCurrentRun = useCallback(() => {\n try {\n copilotkit.stopAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: stopAgent failed\", error);\n try {\n agent.abortRun();\n } catch (abortError) {\n console.error(\"CopilotChat: abortRun fallback failed\", abortError);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agent]);\n\n // Transcription handlers\n const handleStartTranscribe = useCallback(() => {\n setTranscriptionError(null);\n setTranscribeMode(\"transcribe\");\n }, []);\n\n const handleCancelTranscribe = useCallback(() => {\n setTranscriptionError(null);\n setTranscribeMode(\"input\");\n }, []);\n\n const handleFinishTranscribe = useCallback(() => {\n setTranscribeMode(\"input\");\n }, []);\n\n // Handle audio blob from CopilotChatInput and transcribe it\n const handleFinishTranscribeWithAudio = useCallback(\n async (audioBlob: Blob) => {\n setIsTranscribing(true);\n try {\n setTranscriptionError(null);\n\n // Send to transcription endpoint\n const result = await transcribeAudio(copilotkit, audioBlob);\n\n // Insert transcribed text into input\n setInputValue((prev) => {\n const trimmedPrev = prev.trim();\n if (trimmedPrev) {\n return `${trimmedPrev} ${result.text}`;\n }\n return result.text;\n });\n } catch (error) {\n console.error(\"CopilotChat: Transcription failed\", error);\n\n // Show contextual error message based on error type\n if (error instanceof TranscriptionError) {\n const { code, retryable, message } = error.info;\n switch (code) {\n case TranscriptionErrorCode.RATE_LIMITED:\n setTranscriptionError(\"Too many requests. Please wait a moment.\");\n break;\n case TranscriptionErrorCode.AUTH_FAILED:\n setTranscriptionError(\n \"Authentication error. Please check your configuration.\",\n );\n break;\n case TranscriptionErrorCode.AUDIO_TOO_LONG:\n setTranscriptionError(\n \"Recording is too long. Please try a shorter recording.\",\n );\n break;\n case TranscriptionErrorCode.AUDIO_TOO_SHORT:\n setTranscriptionError(\n \"Recording is too short. Please try again.\",\n );\n break;\n case TranscriptionErrorCode.INVALID_AUDIO_FORMAT:\n setTranscriptionError(\"Audio format not supported.\");\n break;\n case TranscriptionErrorCode.SERVICE_NOT_CONFIGURED:\n setTranscriptionError(\"Transcription service is not available.\");\n break;\n case TranscriptionErrorCode.NETWORK_ERROR:\n setTranscriptionError(\n \"Network error. Please check your connection.\",\n );\n break;\n default:\n // For retryable errors, show more helpful message\n setTranscriptionError(\n retryable ? \"Transcription failed. Please try again.\" : message,\n );\n }\n } else {\n // Fallback for unexpected errors\n setTranscriptionError(\"Transcription failed. Please try again.\");\n }\n } finally {\n setIsTranscribing(false);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n // Clear transcription error after a delay\n useEffect(() => {\n if (transcriptionError) {\n const timer = setTimeout(() => {\n setTranscriptionError(null);\n }, 5000);\n return () => clearTimeout(timer);\n }\n }, [transcriptionError]);\n\n const mergedProps = merge(\n {\n isRunning: agent.isRunning,\n suggestions: autoSuggestions,\n onSelectSuggestion: handleSelectSuggestion,\n suggestionView: providedSuggestionView,\n },\n {\n ...restProps,\n ...(typeof providedMessageView === \"string\"\n ? { messageView: { className: providedMessageView } }\n : providedMessageView !== undefined\n ? { messageView: providedMessageView }\n : {}),\n },\n );\n\n const hasMessages = agent.messages.length > 0;\n const shouldAllowStop = agent.isRunning && hasMessages;\n const effectiveStopHandler = shouldAllowStop\n ? (providedStopHandler ?? stopCurrentRun)\n : providedStopHandler;\n\n // Determine if transcription feature should be available\n const showTranscription = isTranscriptionEnabled && isMediaRecorderSupported;\n\n // Determine mode: transcribing takes priority, then transcribe mode, then default to input\n const effectiveMode: CopilotChatInputMode = isTranscribing\n ? \"processing\"\n : transcribeMode;\n\n // Memoize messages array - only create new reference when content actually changes\n // (agent.messages is mutated in place, so we need a new reference for React to detect changes)\n\n const messages = useMemo(\n () => [...agent.messages],\n [JSON.stringify(agent.messages)],\n );\n\n const finalProps = merge(mergedProps, {\n messages,\n // Input behavior props\n onSubmitMessage: onSubmitInput,\n onStop: effectiveStopHandler,\n inputMode: effectiveMode,\n inputValue,\n onInputChange: setInputValue,\n // Only provide transcription handlers if feature is available\n onStartTranscribe: showTranscription ? handleStartTranscribe : undefined,\n onCancelTranscribe: showTranscription ? handleCancelTranscribe : undefined,\n onFinishTranscribe: showTranscription ? handleFinishTranscribe : undefined,\n onFinishTranscribeWithAudio: showTranscription\n ? handleFinishTranscribeWithAudio\n : undefined,\n }) as CopilotChatViewProps;\n\n // Always create a provider with merged values\n // This ensures priority: props > existing config > defaults\n const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);\n\n return (\n <CopilotChatConfigurationProvider\n agentId={resolvedAgentId}\n threadId={resolvedThreadId}\n labels={labels}\n isModalDefaultOpen={isModalDefaultOpen}\n >\n {transcriptionError && (\n <div\n style={{\n position: \"absolute\",\n bottom: \"100px\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n backgroundColor: \"#ef4444\",\n color: \"white\",\n padding: \"8px 16px\",\n borderRadius: \"8px\",\n fontSize: \"14px\",\n zIndex: 50,\n }}\n >\n {transcriptionError}\n </div>\n )}\n {RenderedChatView}\n </CopilotChatConfigurationProvider>\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace CopilotChat {\n export const View = CopilotChatView;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,SAAgB,YAAY,EAC1B,SACA,UACA,QACA,UACA,oBACA,SACA,GAAG,SACgB;CAEnB,MAAM,iBAAiBA,sEAA6B;CAGpD,MAAM,kBACJ,WAAW,gBAAgB,WAAWC;CACxC,MAAM,4CACE,YAAY,gBAAgB,oDAAwB,EAC1D,CAAC,UAAU,gBAAgB,SAAS,CACrC;CAED,MAAM,EAAE,UAAUC,2BAAS,EAAE,SAAS,iBAAiB,CAAC;CACxD,MAAM,EAAE,eAAeC,0CAAe;CACtC,MAAM,EAAE,aAAa,oBAAoBC,uCAAe,EACtD,SAAS,iBACV,CAAC;CAGF,MAAM,+BAAoB,QAAQ;AAClC,4BAAgB;AACd,aAAW,UAAU;IACpB,CAAC,QAAQ,CAAC;AAEb,4BAAgB;AACd,MAAI,CAAC,WAAW,QAAS;EAEzB,MAAM,eAAe,WAAW,UAAU,EACxC,UAAU,UAAU;AAElB,OACE,MAAM,SAAS,YAAY,mBAC3B,CAAC,MAAM,SAAS,QAEhB,YAAW,UAAU;IACnB,OAAO,MAAM;IACb,MAAM,MAAM;IACZ,SAAS,MAAM;IAChB,CAAC;KAGP,CAAC;AAEF,eAAa;AACX,gBAAa,aAAa;;IAE3B,CAAC,YAAY,gBAAgB,CAAC;CAGjC,MAAM,CAAC,gBAAgB,yCACU,QAAQ;CACzC,MAAM,CAAC,YAAY,qCAA0B,GAAG;CAChD,MAAM,CAAC,oBAAoB,6CACzB,KACD;CACD,MAAM,CAAC,gBAAgB,yCAA8B,MAAM;CAG3D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M,sCACJ;EACE,WAAW,MAAM;EACjB,aAAa;EACb,oBAAoB;EACpB,gBAAgB;EACjB,EACD;EACE,GAAG;EACH,GAAI,OAAO,wBAAwB,WAC/B,EAAE,aAAa,EAAE,WAAW,qBAAqB,EAAE,GACnD,wBAAwB,SACtB,EAAE,aAAa,qBAAqB,GACpC,EAAE;EACT,CACF;CAED,MAAM,cAAc,MAAM,SAAS,SAAS;CAE5C,MAAM,uBADkB,MAAM,aAAa,cAEtC,uBAAuB,iBACxB;CAGJ,MAAM,oBAAoB,0BAA0B;CAGpD,MAAM,gBAAsC,iBACxC,eACA;CA6BJ,MAAM,mBAAmBC,yBAAW,UAAUC,iEAnBrB,aAAa;EACpC,mCALM,CAAC,GAAG,MAAM,SAAS,EACzB,CAAC,KAAK,UAAU,MAAM,SAAS,CAAC,CACjC;EAKC,iBAAiB;EACjB,QAAQ;EACR,WAAW;EACX;EACA,eAAe;EAEf,mBAAmB,oBAAoB,wBAAwB;EAC/D,oBAAoB,oBAAoB,yBAAyB;EACjE,oBAAoB,oBAAoB,yBAAyB;EACjE,6BAA6B,oBACzB,kCACA;EACL,CAAC,CAIwE;AAE1E,QACE,4CAACC;EACC,SAAS;EACT,UAAU;EACF;EACY;aAEnB,sBACC,2CAAC;GACC,OAAO;IACL,UAAU;IACV,QAAQ;IACR,MAAM;IACN,WAAW;IACX,iBAAiB;IACjB,OAAO;IACP,SAAS;IACT,cAAc;IACd,UAAU;IACV,QAAQ;IACT;aAEA;IACG,EAEP;GACgC;;;qBAMjBD"}
@@ -10,6 +10,7 @@ type CopilotChatProps = Omit<CopilotChatViewProps, "messages" | "isRunning" | "s
10
10
  threadId?: string;
11
11
  labels?: Partial<CopilotChatLabels>;
12
12
  chatView?: SlotValue<typeof CopilotChatView>;
13
+ isModalDefaultOpen?: boolean;
13
14
  /**
14
15
  * Error handler scoped to this chat's agent. Fires in addition to the
15
16
  * provider-level onError (does not suppress it). Receives only errors
@@ -26,6 +27,7 @@ declare function CopilotChat({
26
27
  threadId,
27
28
  labels,
28
29
  chatView,
30
+ isModalDefaultOpen,
29
31
  onError,
30
32
  ...props
31
33
  }: CopilotChatProps): react_jsx_runtime0.JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotChat.d.cts","names":[],"sources":["../../../src/components/chat/CopilotChat.tsx"],"mappings":";;;;;;;KAyBY,gBAAA,GAAmB,IAAA,CAC7B,oBAAA;EAOA,OAAA;EACA,QAAA;EACA,MAAA,GAAS,OAAA,CAAQ,iBAAA;EACjB,QAAA,GAAW,SAAA,QAAiB,eAAA;;;;;;EAM5B,OAAA,IAAW,KAAA;IACT,KAAA,EAAO,KAAA;IACP,IAAA,EAAM,uBAAA;IACN,OAAA,EAAS,MAAA;EAAA,aACE,OAAA;AAAA;AAAA,iBAEC,WAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,MAAA;EACA,QAAA;EACA,OAAA;EAAA,GACG;AAAA,GACF,gBAAA,GAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,kBA8VF,WAAA;EAAA,MACF,IAAA,SAAI,eAAA;AAAA"}
1
+ {"version":3,"file":"CopilotChat.d.cts","names":[],"sources":["../../../src/components/chat/CopilotChat.tsx"],"mappings":";;;;;;;KAyBY,gBAAA,GAAmB,IAAA,CAC7B,oBAAA;EAOA,OAAA;EACA,QAAA;EACA,MAAA,GAAS,OAAA,CAAQ,iBAAA;EACjB,QAAA,GAAW,SAAA,QAAiB,eAAA;EAC5B,kBAAA;EAXA;;;;;EAiBA,OAAA,IAAW,KAAA;IACT,KAAA,EAAO,KAAA;IACP,IAAA,EAAM,uBAAA;IACN,OAAA,EAAS,MAAA;EAAA,aACE,OAAA;AAAA;AAAA,iBAEC,WAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,MAAA;EACA,QAAA;EACA,kBAAA;EACA,OAAA;EAAA,GACG;AAAA,GACF,gBAAA,GAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,kBAmWF,WAAA;EAAA,MACF,IAAA,SAAI,eAAA;AAAA"}
@@ -10,6 +10,7 @@ type CopilotChatProps = Omit<CopilotChatViewProps, "messages" | "isRunning" | "s
10
10
  threadId?: string;
11
11
  labels?: Partial<CopilotChatLabels>;
12
12
  chatView?: SlotValue<typeof CopilotChatView>;
13
+ isModalDefaultOpen?: boolean;
13
14
  /**
14
15
  * Error handler scoped to this chat's agent. Fires in addition to the
15
16
  * provider-level onError (does not suppress it). Receives only errors
@@ -26,6 +27,7 @@ declare function CopilotChat({
26
27
  threadId,
27
28
  labels,
28
29
  chatView,
30
+ isModalDefaultOpen,
29
31
  onError,
30
32
  ...props
31
33
  }: CopilotChatProps): react_jsx_runtime0.JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotChat.d.mts","names":[],"sources":["../../../src/components/chat/CopilotChat.tsx"],"mappings":";;;;;;;KAyBY,gBAAA,GAAmB,IAAA,CAC7B,oBAAA;EAOA,OAAA;EACA,QAAA;EACA,MAAA,GAAS,OAAA,CAAQ,iBAAA;EACjB,QAAA,GAAW,SAAA,QAAiB,eAAA;;;;;;EAM5B,OAAA,IAAW,KAAA;IACT,KAAA,EAAO,KAAA;IACP,IAAA,EAAM,uBAAA;IACN,OAAA,EAAS,MAAA;EAAA,aACE,OAAA;AAAA;AAAA,iBAEC,WAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,MAAA;EACA,QAAA;EACA,OAAA;EAAA,GACG;AAAA,GACF,gBAAA,GAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,kBA8VF,WAAA;EAAA,MACF,IAAA,SAAI,eAAA;AAAA"}
1
+ {"version":3,"file":"CopilotChat.d.mts","names":[],"sources":["../../../src/components/chat/CopilotChat.tsx"],"mappings":";;;;;;;KAyBY,gBAAA,GAAmB,IAAA,CAC7B,oBAAA;EAOA,OAAA;EACA,QAAA;EACA,MAAA,GAAS,OAAA,CAAQ,iBAAA;EACjB,QAAA,GAAW,SAAA,QAAiB,eAAA;EAC5B,kBAAA;EAXA;;;;;EAiBA,OAAA,IAAW,KAAA;IACT,KAAA,EAAO,KAAA;IACP,IAAA,EAAM,uBAAA;IACN,OAAA,EAAS,MAAA;EAAA,aACE,OAAA;AAAA;AAAA,iBAEC,WAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,MAAA;EACA,QAAA;EACA,kBAAA;EACA,OAAA;EAAA,GACG;AAAA,GACF,gBAAA,GAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,kBAmWF,WAAA;EAAA,MACF,IAAA,SAAI,eAAA;AAAA"}
@@ -12,7 +12,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
12
12
  import { merge } from "ts-deepmerge";
13
13
 
14
14
  //#region src/components/chat/CopilotChat.tsx
15
- function CopilotChat({ agentId, threadId, labels, chatView, onError, ...props }) {
15
+ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, onError, ...props }) {
16
16
  const existingConfig = useCopilotChatConfiguration();
17
17
  const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID;
18
18
  const resolvedThreadId = useMemo(() => threadId ?? existingConfig?.threadId ?? randomUUID(), [threadId, existingConfig?.threadId]);
@@ -60,7 +60,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, onError, ...props })
60
60
  return () => {
61
61
  detached = true;
62
62
  connectAbortController.abort();
63
- agent.detachActiveRun();
63
+ agent.detachActiveRun().catch(() => {});
64
64
  };
65
65
  }, [
66
66
  resolvedThreadId,
@@ -195,6 +195,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, onError, ...props })
195
195
  agentId: resolvedAgentId,
196
196
  threadId: resolvedThreadId,
197
197
  labels,
198
+ isModalDefaultOpen,
198
199
  children: [transcriptionError && /* @__PURE__ */ jsx("div", {
199
200
  style: {
200
201
  position: "absolute",
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotChat.mjs","names":[],"sources":["../../../src/components/chat/CopilotChat.tsx"],"sourcesContent":["import { useAgent } from \"@/hooks/use-agent\";\nimport { useSuggestions } from \"@/hooks/use-suggestions\";\nimport { CopilotChatView, CopilotChatViewProps } from \"./CopilotChatView\";\nimport { CopilotChatInputMode } from \"./CopilotChatInput\";\nimport {\n CopilotChatConfigurationProvider,\n CopilotChatLabels,\n useCopilotChatConfiguration,\n} from \"@/providers/CopilotChatConfigurationProvider\";\nimport {\n DEFAULT_AGENT_ID,\n randomUUID,\n TranscriptionErrorCode,\n} from \"@copilotkitnext/shared\";\nimport { Suggestion, CopilotKitCoreErrorCode } from \"@copilotkitnext/core\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { merge } from \"ts-deepmerge\";\nimport { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport { AbstractAgent, HttpAgent } from \"@ag-ui/client\";\nimport { renderSlot, SlotValue } from \"@/lib/slots\";\nimport {\n transcribeAudio,\n TranscriptionError,\n} from \"@/lib/transcription-client\";\n\nexport type CopilotChatProps = Omit<\n CopilotChatViewProps,\n | \"messages\"\n | \"isRunning\"\n | \"suggestions\"\n | \"suggestionLoadingIndexes\"\n | \"onSelectSuggestion\"\n> & {\n agentId?: string;\n threadId?: string;\n labels?: Partial<CopilotChatLabels>;\n chatView?: SlotValue<typeof CopilotChatView>;\n /**\n * Error handler scoped to this chat's agent. Fires in addition to the\n * provider-level onError (does not suppress it). Receives only errors\n * whose context.agentId matches this chat's agent.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void | Promise<void>;\n};\nexport function CopilotChat({\n agentId,\n threadId,\n labels,\n chatView,\n onError,\n ...props\n}: CopilotChatProps) {\n // Check for existing configuration provider\n const existingConfig = useCopilotChatConfiguration();\n\n // Apply priority: props > existing config > defaults\n const resolvedAgentId =\n agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID;\n const resolvedThreadId = useMemo(\n () => threadId ?? existingConfig?.threadId ?? randomUUID(),\n [threadId, existingConfig?.threadId],\n );\n\n const { agent } = useAgent({ agentId: resolvedAgentId });\n const { copilotkit } = useCopilotKit();\n const { suggestions: autoSuggestions } = useSuggestions({\n agentId: resolvedAgentId,\n });\n\n // onError subscription — forward core errors scoped to this chat's agent\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n useEffect(() => {\n if (!onErrorRef.current) return;\n\n const subscription = copilotkit.subscribe({\n onError: (event) => {\n // Only forward errors that match this chat's agent\n if (\n event.context?.agentId === resolvedAgentId ||\n !event.context?.agentId\n ) {\n onErrorRef.current?.({\n error: event.error,\n code: event.code,\n context: event.context,\n });\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [copilotkit, resolvedAgentId]);\n\n // Transcription state\n const [transcribeMode, setTranscribeMode] =\n useState<CopilotChatInputMode>(\"input\");\n const [inputValue, setInputValue] = useState(\"\");\n const [transcriptionError, setTranscriptionError] = useState<string | null>(\n null,\n );\n const [isTranscribing, setIsTranscribing] = useState(false);\n\n // Check if transcription is enabled\n const isTranscriptionEnabled = copilotkit.audioFileTranscriptionEnabled;\n\n // Check if browser supports MediaRecorder\n const isMediaRecorderSupported =\n typeof window !== \"undefined\" && typeof MediaRecorder !== \"undefined\";\n\n const {\n messageView: providedMessageView,\n suggestionView: providedSuggestionView,\n onStop: providedStopHandler,\n ...restProps\n } = props;\n\n useEffect(() => {\n let detached = false;\n\n // Create a fresh AbortController so we can cancel the HTTP request on cleanup.\n // HttpAgent (parent of ProxiedCopilotRuntimeAgent) uses this.abortController.signal\n // in its fetch config. Unlike runAgent(), connectAgent() does NOT create a new\n // AbortController automatically, so we must set one before connecting.\n const connectAbortController = new AbortController();\n if (agent instanceof HttpAgent) {\n agent.abortController = connectAbortController;\n }\n\n const connect = async (agent: AbstractAgent) => {\n try {\n await copilotkit.connectAgent({ agent });\n } catch (error) {\n // Ignore errors from aborted connections (e.g., React StrictMode cleanup)\n if (detached) return;\n // connectAgent already emits via the subscriber system, but catch\n // here to prevent unhandled rejections from unexpected errors.\n console.error(\"CopilotChat: connectAgent failed\", error);\n }\n };\n agent.threadId = resolvedThreadId;\n connect(agent);\n return () => {\n // Abort the HTTP request and detach the active run.\n // This is critical for React StrictMode which unmounts+remounts in dev,\n // preventing duplicate /connect requests from reaching the server.\n detached = true;\n connectAbortController.abort();\n agent.detachActiveRun();\n };\n // copilotkit is intentionally excluded — it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [resolvedThreadId, agent, resolvedAgentId]);\n\n const onSubmitInput = useCallback(\n async (value: string) => {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: value,\n });\n // Clear input after submitting\n setInputValue(\"\");\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n },\n // copilotkit is intentionally excluded — it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent],\n );\n\n const handleSelectSuggestion = useCallback(\n async (suggestion: Suggestion) => {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: suggestion.message,\n });\n\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\n \"CopilotChat: runAgent failed after selecting suggestion\",\n error,\n );\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent],\n );\n\n const stopCurrentRun = useCallback(() => {\n try {\n copilotkit.stopAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: stopAgent failed\", error);\n try {\n agent.abortRun();\n } catch (abortError) {\n console.error(\"CopilotChat: abortRun fallback failed\", abortError);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agent]);\n\n // Transcription handlers\n const handleStartTranscribe = useCallback(() => {\n setTranscriptionError(null);\n setTranscribeMode(\"transcribe\");\n }, []);\n\n const handleCancelTranscribe = useCallback(() => {\n setTranscriptionError(null);\n setTranscribeMode(\"input\");\n }, []);\n\n const handleFinishTranscribe = useCallback(() => {\n setTranscribeMode(\"input\");\n }, []);\n\n // Handle audio blob from CopilotChatInput and transcribe it\n const handleFinishTranscribeWithAudio = useCallback(\n async (audioBlob: Blob) => {\n setIsTranscribing(true);\n try {\n setTranscriptionError(null);\n\n // Send to transcription endpoint\n const result = await transcribeAudio(copilotkit, audioBlob);\n\n // Insert transcribed text into input\n setInputValue((prev) => {\n const trimmedPrev = prev.trim();\n if (trimmedPrev) {\n return `${trimmedPrev} ${result.text}`;\n }\n return result.text;\n });\n } catch (error) {\n console.error(\"CopilotChat: Transcription failed\", error);\n\n // Show contextual error message based on error type\n if (error instanceof TranscriptionError) {\n const { code, retryable, message } = error.info;\n switch (code) {\n case TranscriptionErrorCode.RATE_LIMITED:\n setTranscriptionError(\"Too many requests. Please wait a moment.\");\n break;\n case TranscriptionErrorCode.AUTH_FAILED:\n setTranscriptionError(\n \"Authentication error. Please check your configuration.\",\n );\n break;\n case TranscriptionErrorCode.AUDIO_TOO_LONG:\n setTranscriptionError(\n \"Recording is too long. Please try a shorter recording.\",\n );\n break;\n case TranscriptionErrorCode.AUDIO_TOO_SHORT:\n setTranscriptionError(\n \"Recording is too short. Please try again.\",\n );\n break;\n case TranscriptionErrorCode.INVALID_AUDIO_FORMAT:\n setTranscriptionError(\"Audio format not supported.\");\n break;\n case TranscriptionErrorCode.SERVICE_NOT_CONFIGURED:\n setTranscriptionError(\"Transcription service is not available.\");\n break;\n case TranscriptionErrorCode.NETWORK_ERROR:\n setTranscriptionError(\n \"Network error. Please check your connection.\",\n );\n break;\n default:\n // For retryable errors, show more helpful message\n setTranscriptionError(\n retryable ? \"Transcription failed. Please try again.\" : message,\n );\n }\n } else {\n // Fallback for unexpected errors\n setTranscriptionError(\"Transcription failed. Please try again.\");\n }\n } finally {\n setIsTranscribing(false);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n // Clear transcription error after a delay\n useEffect(() => {\n if (transcriptionError) {\n const timer = setTimeout(() => {\n setTranscriptionError(null);\n }, 5000);\n return () => clearTimeout(timer);\n }\n }, [transcriptionError]);\n\n const mergedProps = merge(\n {\n isRunning: agent.isRunning,\n suggestions: autoSuggestions,\n onSelectSuggestion: handleSelectSuggestion,\n suggestionView: providedSuggestionView,\n },\n {\n ...restProps,\n ...(typeof providedMessageView === \"string\"\n ? { messageView: { className: providedMessageView } }\n : providedMessageView !== undefined\n ? { messageView: providedMessageView }\n : {}),\n },\n );\n\n const hasMessages = agent.messages.length > 0;\n const shouldAllowStop = agent.isRunning && hasMessages;\n const effectiveStopHandler = shouldAllowStop\n ? (providedStopHandler ?? stopCurrentRun)\n : providedStopHandler;\n\n // Determine if transcription feature should be available\n const showTranscription = isTranscriptionEnabled && isMediaRecorderSupported;\n\n // Determine mode: transcribing takes priority, then transcribe mode, then default to input\n const effectiveMode: CopilotChatInputMode = isTranscribing\n ? \"processing\"\n : transcribeMode;\n\n // Memoize messages array - only create new reference when content actually changes\n // (agent.messages is mutated in place, so we need a new reference for React to detect changes)\n\n const messages = useMemo(\n () => [...agent.messages],\n [JSON.stringify(agent.messages)],\n );\n\n const finalProps = merge(mergedProps, {\n messages,\n // Input behavior props\n onSubmitMessage: onSubmitInput,\n onStop: effectiveStopHandler,\n inputMode: effectiveMode,\n inputValue,\n onInputChange: setInputValue,\n // Only provide transcription handlers if feature is available\n onStartTranscribe: showTranscription ? handleStartTranscribe : undefined,\n onCancelTranscribe: showTranscription ? handleCancelTranscribe : undefined,\n onFinishTranscribe: showTranscription ? handleFinishTranscribe : undefined,\n onFinishTranscribeWithAudio: showTranscription\n ? handleFinishTranscribeWithAudio\n : undefined,\n }) as CopilotChatViewProps;\n\n // Always create a provider with merged values\n // This ensures priority: props > existing config > defaults\n const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);\n\n return (\n <CopilotChatConfigurationProvider\n agentId={resolvedAgentId}\n threadId={resolvedThreadId}\n labels={labels}\n >\n {transcriptionError && (\n <div\n style={{\n position: \"absolute\",\n bottom: \"100px\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n backgroundColor: \"#ef4444\",\n color: \"white\",\n padding: \"8px 16px\",\n borderRadius: \"8px\",\n fontSize: \"14px\",\n zIndex: 50,\n }}\n >\n {transcriptionError}\n </div>\n )}\n {RenderedChatView}\n </CopilotChatConfigurationProvider>\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace CopilotChat {\n export const View = CopilotChatView;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgDA,SAAgB,YAAY,EAC1B,SACA,UACA,QACA,UACA,SACA,GAAG,SACgB;CAEnB,MAAM,iBAAiB,6BAA6B;CAGpD,MAAM,kBACJ,WAAW,gBAAgB,WAAW;CACxC,MAAM,mBAAmB,cACjB,YAAY,gBAAgB,YAAY,YAAY,EAC1D,CAAC,UAAU,gBAAgB,SAAS,CACrC;CAED,MAAM,EAAE,UAAU,SAAS,EAAE,SAAS,iBAAiB,CAAC;CACxD,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,EAAE,aAAa,oBAAoB,eAAe,EACtD,SAAS,iBACV,CAAC;CAGF,MAAM,aAAa,OAAO,QAAQ;AAClC,iBAAgB;AACd,aAAW,UAAU;IACpB,CAAC,QAAQ,CAAC;AAEb,iBAAgB;AACd,MAAI,CAAC,WAAW,QAAS;EAEzB,MAAM,eAAe,WAAW,UAAU,EACxC,UAAU,UAAU;AAElB,OACE,MAAM,SAAS,YAAY,mBAC3B,CAAC,MAAM,SAAS,QAEhB,YAAW,UAAU;IACnB,OAAO,MAAM;IACb,MAAM,MAAM;IACZ,SAAS,MAAM;IAChB,CAAC;KAGP,CAAC;AAEF,eAAa;AACX,gBAAa,aAAa;;IAE3B,CAAC,YAAY,gBAAgB,CAAC;CAGjC,MAAM,CAAC,gBAAgB,qBACrB,SAA+B,QAAQ;CACzC,MAAM,CAAC,YAAY,iBAAiB,SAAS,GAAG;CAChD,MAAM,CAAC,oBAAoB,yBAAyB,SAClD,KACD;CACD,MAAM,CAAC,gBAAgB,qBAAqB,SAAS,MAAM;CAG3D,MAAM,yBAAyB,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;CAExB,MAAM,cAAc,MAClB;EACE,WAAW,MAAM;EACjB,aAAa;EACb,oBAAoB;EACpB,gBAAgB;EACjB,EACD;EACE,GAAG;EACH,GAAI,OAAO,wBAAwB,WAC/B,EAAE,aAAa,EAAE,WAAW,qBAAqB,EAAE,GACnD,wBAAwB,SACtB,EAAE,aAAa,qBAAqB,GACpC,EAAE;EACT,CACF;CAED,MAAM,cAAc,MAAM,SAAS,SAAS;CAE5C,MAAM,uBADkB,MAAM,aAAa,cAEtC,uBAAuB,iBACxB;CAGJ,MAAM,oBAAoB,0BAA0B;CAGpD,MAAM,gBAAsC,iBACxC,eACA;CA6BJ,MAAM,mBAAmB,WAAW,UAAU,iBAnB3B,MAAM,aAAa;EACpC,UANe,cACT,CAAC,GAAG,MAAM,SAAS,EACzB,CAAC,KAAK,UAAU,MAAM,SAAS,CAAC,CACjC;EAKC,iBAAiB;EACjB,QAAQ;EACR,WAAW;EACX;EACA,eAAe;EAEf,mBAAmB,oBAAoB,wBAAwB;EAC/D,oBAAoB,oBAAoB,yBAAyB;EACjE,oBAAoB,oBAAoB,yBAAyB;EACjE,6BAA6B,oBACzB,kCACA;EACL,CAAC,CAIwE;AAE1E,QACE,qBAAC;EACC,SAAS;EACT,UAAU;EACF;aAEP,sBACC,oBAAC;GACC,OAAO;IACL,UAAU;IACV,QAAQ;IACR,MAAM;IACN,WAAW;IACX,iBAAiB;IACjB,OAAO;IACP,SAAS;IACT,cAAc;IACd,UAAU;IACV,QAAQ;IACT;aAEA;IACG,EAEP;GACgC;;;qBAMjB"}
1
+ {"version":3,"file":"CopilotChat.mjs","names":[],"sources":["../../../src/components/chat/CopilotChat.tsx"],"sourcesContent":["import { useAgent } from \"@/hooks/use-agent\";\nimport { useSuggestions } from \"@/hooks/use-suggestions\";\nimport { CopilotChatView, CopilotChatViewProps } from \"./CopilotChatView\";\nimport { CopilotChatInputMode } from \"./CopilotChatInput\";\nimport {\n CopilotChatConfigurationProvider,\n CopilotChatLabels,\n useCopilotChatConfiguration,\n} from \"@/providers/CopilotChatConfigurationProvider\";\nimport {\n DEFAULT_AGENT_ID,\n randomUUID,\n TranscriptionErrorCode,\n} from \"@copilotkitnext/shared\";\nimport { Suggestion, CopilotKitCoreErrorCode } from \"@copilotkitnext/core\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { merge } from \"ts-deepmerge\";\nimport { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport { AbstractAgent, HttpAgent } from \"@ag-ui/client\";\nimport { renderSlot, SlotValue } from \"@/lib/slots\";\nimport {\n transcribeAudio,\n TranscriptionError,\n} from \"@/lib/transcription-client\";\n\nexport type CopilotChatProps = Omit<\n CopilotChatViewProps,\n | \"messages\"\n | \"isRunning\"\n | \"suggestions\"\n | \"suggestionLoadingIndexes\"\n | \"onSelectSuggestion\"\n> & {\n agentId?: string;\n threadId?: string;\n labels?: Partial<CopilotChatLabels>;\n chatView?: SlotValue<typeof CopilotChatView>;\n isModalDefaultOpen?: boolean;\n /**\n * Error handler scoped to this chat's agent. Fires in addition to the\n * provider-level onError (does not suppress it). Receives only errors\n * whose context.agentId matches this chat's agent.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void | Promise<void>;\n};\nexport function CopilotChat({\n agentId,\n threadId,\n labels,\n chatView,\n isModalDefaultOpen,\n onError,\n ...props\n}: CopilotChatProps) {\n // Check for existing configuration provider\n const existingConfig = useCopilotChatConfiguration();\n\n // Apply priority: props > existing config > defaults\n const resolvedAgentId =\n agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID;\n const resolvedThreadId = useMemo(\n () => threadId ?? existingConfig?.threadId ?? randomUUID(),\n [threadId, existingConfig?.threadId],\n );\n\n const { agent } = useAgent({ agentId: resolvedAgentId });\n const { copilotkit } = useCopilotKit();\n const { suggestions: autoSuggestions } = useSuggestions({\n agentId: resolvedAgentId,\n });\n\n // onError subscription — forward core errors scoped to this chat's agent\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n useEffect(() => {\n if (!onErrorRef.current) return;\n\n const subscription = copilotkit.subscribe({\n onError: (event) => {\n // Only forward errors that match this chat's agent\n if (\n event.context?.agentId === resolvedAgentId ||\n !event.context?.agentId\n ) {\n onErrorRef.current?.({\n error: event.error,\n code: event.code,\n context: event.context,\n });\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [copilotkit, resolvedAgentId]);\n\n // Transcription state\n const [transcribeMode, setTranscribeMode] =\n useState<CopilotChatInputMode>(\"input\");\n const [inputValue, setInputValue] = useState(\"\");\n const [transcriptionError, setTranscriptionError] = useState<string | null>(\n null,\n );\n const [isTranscribing, setIsTranscribing] = useState(false);\n\n // Check if transcription is enabled\n const isTranscriptionEnabled = copilotkit.audioFileTranscriptionEnabled;\n\n // Check if browser supports MediaRecorder\n const isMediaRecorderSupported =\n typeof window !== \"undefined\" && typeof MediaRecorder !== \"undefined\";\n\n const {\n messageView: providedMessageView,\n suggestionView: providedSuggestionView,\n onStop: providedStopHandler,\n ...restProps\n } = props;\n\n useEffect(() => {\n let detached = false;\n\n // Create a fresh AbortController so we can cancel the HTTP request on cleanup.\n // HttpAgent (parent of ProxiedCopilotRuntimeAgent) uses this.abortController.signal\n // in its fetch config. Unlike runAgent(), connectAgent() does NOT create a new\n // AbortController automatically, so we must set one before connecting.\n const connectAbortController = new AbortController();\n if (agent instanceof HttpAgent) {\n agent.abortController = connectAbortController;\n }\n\n const connect = async (agent: AbstractAgent) => {\n try {\n await copilotkit.connectAgent({ agent });\n } catch (error) {\n // Ignore errors from aborted connections (e.g., React StrictMode cleanup)\n if (detached) return;\n // connectAgent already emits via the subscriber system, but catch\n // here to prevent unhandled rejections from unexpected errors.\n console.error(\"CopilotChat: connectAgent failed\", error);\n }\n };\n agent.threadId = resolvedThreadId;\n connect(agent);\n return () => {\n // Abort the HTTP request and detach the active run.\n // This is critical for React StrictMode which unmounts+remounts in dev,\n // preventing duplicate /connect requests from reaching the server.\n detached = true;\n connectAbortController.abort();\n // The .catch() is required to prevent a false-positive \"Uncaught (in promise)\n // AbortError\" in browser devtools. detachActiveRun() itself does not reject,\n // but without an attached handler V8 flags the promise chain as unhandled\n // when the abort signal propagates through connected promises internally.\n void agent.detachActiveRun().catch(() => {});\n };\n // copilotkit is intentionally excluded — it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [resolvedThreadId, agent, resolvedAgentId]);\n\n const onSubmitInput = useCallback(\n async (value: string) => {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: value,\n });\n // Clear input after submitting\n setInputValue(\"\");\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n },\n // copilotkit is intentionally excluded — it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent],\n );\n\n const handleSelectSuggestion = useCallback(\n async (suggestion: Suggestion) => {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: suggestion.message,\n });\n\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\n \"CopilotChat: runAgent failed after selecting suggestion\",\n error,\n );\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent],\n );\n\n const stopCurrentRun = useCallback(() => {\n try {\n copilotkit.stopAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: stopAgent failed\", error);\n try {\n agent.abortRun();\n } catch (abortError) {\n console.error(\"CopilotChat: abortRun fallback failed\", abortError);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agent]);\n\n // Transcription handlers\n const handleStartTranscribe = useCallback(() => {\n setTranscriptionError(null);\n setTranscribeMode(\"transcribe\");\n }, []);\n\n const handleCancelTranscribe = useCallback(() => {\n setTranscriptionError(null);\n setTranscribeMode(\"input\");\n }, []);\n\n const handleFinishTranscribe = useCallback(() => {\n setTranscribeMode(\"input\");\n }, []);\n\n // Handle audio blob from CopilotChatInput and transcribe it\n const handleFinishTranscribeWithAudio = useCallback(\n async (audioBlob: Blob) => {\n setIsTranscribing(true);\n try {\n setTranscriptionError(null);\n\n // Send to transcription endpoint\n const result = await transcribeAudio(copilotkit, audioBlob);\n\n // Insert transcribed text into input\n setInputValue((prev) => {\n const trimmedPrev = prev.trim();\n if (trimmedPrev) {\n return `${trimmedPrev} ${result.text}`;\n }\n return result.text;\n });\n } catch (error) {\n console.error(\"CopilotChat: Transcription failed\", error);\n\n // Show contextual error message based on error type\n if (error instanceof TranscriptionError) {\n const { code, retryable, message } = error.info;\n switch (code) {\n case TranscriptionErrorCode.RATE_LIMITED:\n setTranscriptionError(\"Too many requests. Please wait a moment.\");\n break;\n case TranscriptionErrorCode.AUTH_FAILED:\n setTranscriptionError(\n \"Authentication error. Please check your configuration.\",\n );\n break;\n case TranscriptionErrorCode.AUDIO_TOO_LONG:\n setTranscriptionError(\n \"Recording is too long. Please try a shorter recording.\",\n );\n break;\n case TranscriptionErrorCode.AUDIO_TOO_SHORT:\n setTranscriptionError(\n \"Recording is too short. Please try again.\",\n );\n break;\n case TranscriptionErrorCode.INVALID_AUDIO_FORMAT:\n setTranscriptionError(\"Audio format not supported.\");\n break;\n case TranscriptionErrorCode.SERVICE_NOT_CONFIGURED:\n setTranscriptionError(\"Transcription service is not available.\");\n break;\n case TranscriptionErrorCode.NETWORK_ERROR:\n setTranscriptionError(\n \"Network error. Please check your connection.\",\n );\n break;\n default:\n // For retryable errors, show more helpful message\n setTranscriptionError(\n retryable ? \"Transcription failed. Please try again.\" : message,\n );\n }\n } else {\n // Fallback for unexpected errors\n setTranscriptionError(\"Transcription failed. Please try again.\");\n }\n } finally {\n setIsTranscribing(false);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n // Clear transcription error after a delay\n useEffect(() => {\n if (transcriptionError) {\n const timer = setTimeout(() => {\n setTranscriptionError(null);\n }, 5000);\n return () => clearTimeout(timer);\n }\n }, [transcriptionError]);\n\n const mergedProps = merge(\n {\n isRunning: agent.isRunning,\n suggestions: autoSuggestions,\n onSelectSuggestion: handleSelectSuggestion,\n suggestionView: providedSuggestionView,\n },\n {\n ...restProps,\n ...(typeof providedMessageView === \"string\"\n ? { messageView: { className: providedMessageView } }\n : providedMessageView !== undefined\n ? { messageView: providedMessageView }\n : {}),\n },\n );\n\n const hasMessages = agent.messages.length > 0;\n const shouldAllowStop = agent.isRunning && hasMessages;\n const effectiveStopHandler = shouldAllowStop\n ? (providedStopHandler ?? stopCurrentRun)\n : providedStopHandler;\n\n // Determine if transcription feature should be available\n const showTranscription = isTranscriptionEnabled && isMediaRecorderSupported;\n\n // Determine mode: transcribing takes priority, then transcribe mode, then default to input\n const effectiveMode: CopilotChatInputMode = isTranscribing\n ? \"processing\"\n : transcribeMode;\n\n // Memoize messages array - only create new reference when content actually changes\n // (agent.messages is mutated in place, so we need a new reference for React to detect changes)\n\n const messages = useMemo(\n () => [...agent.messages],\n [JSON.stringify(agent.messages)],\n );\n\n const finalProps = merge(mergedProps, {\n messages,\n // Input behavior props\n onSubmitMessage: onSubmitInput,\n onStop: effectiveStopHandler,\n inputMode: effectiveMode,\n inputValue,\n onInputChange: setInputValue,\n // Only provide transcription handlers if feature is available\n onStartTranscribe: showTranscription ? handleStartTranscribe : undefined,\n onCancelTranscribe: showTranscription ? handleCancelTranscribe : undefined,\n onFinishTranscribe: showTranscription ? handleFinishTranscribe : undefined,\n onFinishTranscribeWithAudio: showTranscription\n ? handleFinishTranscribeWithAudio\n : undefined,\n }) as CopilotChatViewProps;\n\n // Always create a provider with merged values\n // This ensures priority: props > existing config > defaults\n const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);\n\n return (\n <CopilotChatConfigurationProvider\n agentId={resolvedAgentId}\n threadId={resolvedThreadId}\n labels={labels}\n isModalDefaultOpen={isModalDefaultOpen}\n >\n {transcriptionError && (\n <div\n style={{\n position: \"absolute\",\n bottom: \"100px\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n backgroundColor: \"#ef4444\",\n color: \"white\",\n padding: \"8px 16px\",\n borderRadius: \"8px\",\n fontSize: \"14px\",\n zIndex: 50,\n }}\n >\n {transcriptionError}\n </div>\n )}\n {RenderedChatView}\n </CopilotChatConfigurationProvider>\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace CopilotChat {\n export const View = CopilotChatView;\n}\n"],"mappings":";;;;;;;;;;;;;;AAiDA,SAAgB,YAAY,EAC1B,SACA,UACA,QACA,UACA,oBACA,SACA,GAAG,SACgB;CAEnB,MAAM,iBAAiB,6BAA6B;CAGpD,MAAM,kBACJ,WAAW,gBAAgB,WAAW;CACxC,MAAM,mBAAmB,cACjB,YAAY,gBAAgB,YAAY,YAAY,EAC1D,CAAC,UAAU,gBAAgB,SAAS,CACrC;CAED,MAAM,EAAE,UAAU,SAAS,EAAE,SAAS,iBAAiB,CAAC;CACxD,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,EAAE,aAAa,oBAAoB,eAAe,EACtD,SAAS,iBACV,CAAC;CAGF,MAAM,aAAa,OAAO,QAAQ;AAClC,iBAAgB;AACd,aAAW,UAAU;IACpB,CAAC,QAAQ,CAAC;AAEb,iBAAgB;AACd,MAAI,CAAC,WAAW,QAAS;EAEzB,MAAM,eAAe,WAAW,UAAU,EACxC,UAAU,UAAU;AAElB,OACE,MAAM,SAAS,YAAY,mBAC3B,CAAC,MAAM,SAAS,QAEhB,YAAW,UAAU;IACnB,OAAO,MAAM;IACb,MAAM,MAAM;IACZ,SAAS,MAAM;IAChB,CAAC;KAGP,CAAC;AAEF,eAAa;AACX,gBAAa,aAAa;;IAE3B,CAAC,YAAY,gBAAgB,CAAC;CAGjC,MAAM,CAAC,gBAAgB,qBACrB,SAA+B,QAAQ;CACzC,MAAM,CAAC,YAAY,iBAAiB,SAAS,GAAG;CAChD,MAAM,CAAC,oBAAoB,yBAAyB,SAClD,KACD;CACD,MAAM,CAAC,gBAAgB,qBAA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1B,IAAK;AACR,gBAAa,aAAa,MAAM;;IAEjC,CAAC,mBAAmB,CAAC;CAExB,MAAM,cAAc,MAClB;EACE,WAAW,MAAM;EACjB,aAAa;EACb,oBAAoB;EACpB,gBAAgB;EACjB,EACD;EACE,GAAG;EACH,GAAI,OAAO,wBAAwB,WAC/B,EAAE,aAAa,EAAE,WAAW,qBAAqB,EAAE,GACnD,wBAAwB,SACtB,EAAE,aAAa,qBAAqB,GACpC,EAAE;EACT,CACF;CAED,MAAM,cAAc,MAAM,SAAS,SAAS;CAE5C,MAAM,uBADkB,MAAM,aAAa,cAEtC,uBAAuB,iBACxB;CAGJ,MAAM,oBAAoB,0BAA0B;CAGpD,MAAM,gBAAsC,iBACxC,eACA;CA6BJ,MAAM,mBAAmB,WAAW,UAAU,iBAnB3B,MAAM,aAAa;EACpC,UANe,cACT,CAAC,GAAG,MAAM,SAAS,EACzB,CAAC,KAAK,UAAU,MAAM,SAAS,CAAC,CACjC;EAKC,iBAAiB;EACjB,QAAQ;EACR,WAAW;EACX;EACA,eAAe;EAEf,mBAAmB,oBAAoB,wBAAwB;EAC/D,oBAAoB,oBAAoB,yBAAyB;EACjE,oBAAoB,oBAAoB,yBAAyB;EACjE,6BAA6B,oBACzB,kCACA;EACL,CAAC,CAIwE;AAE1E,QACE,qBAAC;EACC,SAAS;EACT,UAAU;EACF;EACY;aAEnB,sBACC,oBAAC;GACC,OAAO;IACL,UAAU;IACV,QAAQ;IACR,MAAM;IACN,WAAW;IACX,iBAAiB;IACjB,OAAO;IACP,SAAS;IACT,cAAc;IACd,UAAU;IACV,QAAQ;IACT;aAEA;IACG,EAEP;GACgC;;;qBAMjB"}
@@ -33,6 +33,7 @@ function CopilotPopup({ header, toggleButton, defaultOpen, width, height, clickO
33
33
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotChat.CopilotChat, {
34
34
  welcomeScreen: require_CopilotPopupView.default.WelcomeScreen,
35
35
  ...chatProps,
36
+ isModalDefaultOpen: defaultOpen,
36
37
  chatView: PopupViewOverride
37
38
  });
38
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotPopup.cjs","names":["CopilotPopupView","CopilotChatView","CopilotChat"],"sources":["../../../src/components/chat/CopilotPopup.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { CopilotChat, CopilotChatProps } from \"./CopilotChat\";\nimport CopilotChatView, { CopilotChatViewProps } from \"./CopilotChatView\";\nimport CopilotPopupView, { CopilotPopupViewProps } from \"./CopilotPopupView\";\n\nexport type CopilotPopupProps = Omit<CopilotChatProps, \"chatView\"> & {\n header?: CopilotPopupViewProps[\"header\"];\n toggleButton?: CopilotPopupViewProps[\"toggleButton\"];\n defaultOpen?: boolean;\n width?: CopilotPopupViewProps[\"width\"];\n height?: CopilotPopupViewProps[\"height\"];\n clickOutsideToClose?: CopilotPopupViewProps[\"clickOutsideToClose\"];\n};\n\nexport function CopilotPopup({\n header,\n toggleButton,\n defaultOpen,\n width,\n height,\n clickOutsideToClose,\n ...chatProps\n}: CopilotPopupProps) {\n const PopupViewOverride = useMemo(() => {\n const Component: React.FC<CopilotChatViewProps> = (viewProps) => {\n const {\n header: viewHeader,\n toggleButton: viewToggleButton,\n width: viewWidth,\n height: viewHeight,\n clickOutsideToClose: viewClickOutsideToClose,\n defaultOpen: viewDefaultOpen,\n ...restProps\n } = viewProps as CopilotPopupViewProps;\n\n return (\n <CopilotPopupView\n {...(restProps as CopilotPopupViewProps)}\n header={header ?? viewHeader}\n toggleButton={toggleButton ?? viewToggleButton}\n width={width ?? viewWidth}\n height={height ?? viewHeight}\n clickOutsideToClose={clickOutsideToClose ?? viewClickOutsideToClose}\n defaultOpen={defaultOpen ?? viewDefaultOpen}\n />\n );\n };\n\n return Object.assign(Component, CopilotChatView);\n }, [clickOutsideToClose, header, toggleButton, height, width, defaultOpen]);\n\n return (\n <CopilotChat\n welcomeScreen={CopilotPopupView.WelcomeScreen}\n {...chatProps}\n chatView={PopupViewOverride}\n />\n );\n}\n\nCopilotPopup.displayName = \"CopilotPopup\";\n\nexport default CopilotPopup;\n"],"mappings":";;;;;;;;;AAeA,SAAgB,aAAa,EAC3B,QACA,cACA,aACA,OACA,QACA,qBACA,GAAG,aACiB;CACpB,MAAM,6CAAkC;EACtC,MAAM,aAA6C,cAAc;GAC/D,MAAM,EACJ,QAAQ,YACR,cAAc,kBACd,OAAO,WACP,QAAQ,YACR,qBAAqB,yBACrB,aAAa,iBACb,GAAG,cACD;AAEJ,UACE,2CAACA;IACC,GAAK;IACL,QAAQ,UAAU;IAClB,cAAc,gBAAgB;IAC9B,OAAO,SAAS;IAChB,QAAQ,UAAU;IAClB,qBAAqB,uBAAuB;IAC5C,aAAa,eAAe;KAC5B;;AAIN,SAAO,OAAO,OAAO,WAAWC,gCAAgB;IAC/C;EAAC;EAAqB;EAAQ;EAAc;EAAQ;EAAO;EAAY,CAAC;AAE3E,QACE,2CAACC;EACC,eAAeF,iCAAiB;EAChC,GAAI;EACJ,UAAU;GACV;;AAIN,aAAa,cAAc"}
1
+ {"version":3,"file":"CopilotPopup.cjs","names":["CopilotPopupView","CopilotChatView","CopilotChat"],"sources":["../../../src/components/chat/CopilotPopup.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { CopilotChat, CopilotChatProps } from \"./CopilotChat\";\nimport CopilotChatView, { CopilotChatViewProps } from \"./CopilotChatView\";\nimport CopilotPopupView, { CopilotPopupViewProps } from \"./CopilotPopupView\";\n\nexport type CopilotPopupProps = Omit<CopilotChatProps, \"chatView\"> & {\n header?: CopilotPopupViewProps[\"header\"];\n toggleButton?: CopilotPopupViewProps[\"toggleButton\"];\n defaultOpen?: boolean;\n width?: CopilotPopupViewProps[\"width\"];\n height?: CopilotPopupViewProps[\"height\"];\n clickOutsideToClose?: CopilotPopupViewProps[\"clickOutsideToClose\"];\n};\n\nexport function CopilotPopup({\n header,\n toggleButton,\n defaultOpen,\n width,\n height,\n clickOutsideToClose,\n ...chatProps\n}: CopilotPopupProps) {\n const PopupViewOverride = useMemo(() => {\n const Component: React.FC<CopilotChatViewProps> = (viewProps) => {\n const {\n header: viewHeader,\n toggleButton: viewToggleButton,\n width: viewWidth,\n height: viewHeight,\n clickOutsideToClose: viewClickOutsideToClose,\n defaultOpen: viewDefaultOpen,\n ...restProps\n } = viewProps as CopilotPopupViewProps;\n\n return (\n <CopilotPopupView\n {...(restProps as CopilotPopupViewProps)}\n header={header ?? viewHeader}\n toggleButton={toggleButton ?? viewToggleButton}\n width={width ?? viewWidth}\n height={height ?? viewHeight}\n clickOutsideToClose={clickOutsideToClose ?? viewClickOutsideToClose}\n defaultOpen={defaultOpen ?? viewDefaultOpen}\n />\n );\n };\n\n return Object.assign(Component, CopilotChatView);\n }, [clickOutsideToClose, header, toggleButton, height, width, defaultOpen]);\n\n return (\n <CopilotChat\n welcomeScreen={CopilotPopupView.WelcomeScreen}\n {...chatProps}\n isModalDefaultOpen={defaultOpen}\n chatView={PopupViewOverride}\n />\n );\n}\n\nCopilotPopup.displayName = \"CopilotPopup\";\n\nexport default CopilotPopup;\n"],"mappings":";;;;;;;;;AAeA,SAAgB,aAAa,EAC3B,QACA,cACA,aACA,OACA,QACA,qBACA,GAAG,aACiB;CACpB,MAAM,6CAAkC;EACtC,MAAM,aAA6C,cAAc;GAC/D,MAAM,EACJ,QAAQ,YACR,cAAc,kBACd,OAAO,WACP,QAAQ,YACR,qBAAqB,yBACrB,aAAa,iBACb,GAAG,cACD;AAEJ,UACE,2CAACA;IACC,GAAK;IACL,QAAQ,UAAU;IAClB,cAAc,gBAAgB;IAC9B,OAAO,SAAS;IAChB,QAAQ,UAAU;IAClB,qBAAqB,uBAAuB;IAC5C,aAAa,eAAe;KAC5B;;AAIN,SAAO,OAAO,OAAO,WAAWC,gCAAgB;IAC/C;EAAC;EAAqB;EAAQ;EAAc;EAAQ;EAAO;EAAY,CAAC;AAE3E,QACE,2CAACC;EACC,eAAeF,iCAAiB;EAChC,GAAI;EACJ,oBAAoB;EACpB,UAAU;GACV;;AAIN,aAAa,cAAc"}
@@ -31,6 +31,7 @@ function CopilotPopup({ header, toggleButton, defaultOpen, width, height, clickO
31
31
  return /* @__PURE__ */ jsx(CopilotChat, {
32
32
  welcomeScreen: CopilotPopupView_default.WelcomeScreen,
33
33
  ...chatProps,
34
+ isModalDefaultOpen: defaultOpen,
34
35
  chatView: PopupViewOverride
35
36
  });
36
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotPopup.mjs","names":["CopilotPopupView","CopilotChatView"],"sources":["../../../src/components/chat/CopilotPopup.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { CopilotChat, CopilotChatProps } from \"./CopilotChat\";\nimport CopilotChatView, { CopilotChatViewProps } from \"./CopilotChatView\";\nimport CopilotPopupView, { CopilotPopupViewProps } from \"./CopilotPopupView\";\n\nexport type CopilotPopupProps = Omit<CopilotChatProps, \"chatView\"> & {\n header?: CopilotPopupViewProps[\"header\"];\n toggleButton?: CopilotPopupViewProps[\"toggleButton\"];\n defaultOpen?: boolean;\n width?: CopilotPopupViewProps[\"width\"];\n height?: CopilotPopupViewProps[\"height\"];\n clickOutsideToClose?: CopilotPopupViewProps[\"clickOutsideToClose\"];\n};\n\nexport function CopilotPopup({\n header,\n toggleButton,\n defaultOpen,\n width,\n height,\n clickOutsideToClose,\n ...chatProps\n}: CopilotPopupProps) {\n const PopupViewOverride = useMemo(() => {\n const Component: React.FC<CopilotChatViewProps> = (viewProps) => {\n const {\n header: viewHeader,\n toggleButton: viewToggleButton,\n width: viewWidth,\n height: viewHeight,\n clickOutsideToClose: viewClickOutsideToClose,\n defaultOpen: viewDefaultOpen,\n ...restProps\n } = viewProps as CopilotPopupViewProps;\n\n return (\n <CopilotPopupView\n {...(restProps as CopilotPopupViewProps)}\n header={header ?? viewHeader}\n toggleButton={toggleButton ?? viewToggleButton}\n width={width ?? viewWidth}\n height={height ?? viewHeight}\n clickOutsideToClose={clickOutsideToClose ?? viewClickOutsideToClose}\n defaultOpen={defaultOpen ?? viewDefaultOpen}\n />\n );\n };\n\n return Object.assign(Component, CopilotChatView);\n }, [clickOutsideToClose, header, toggleButton, height, width, defaultOpen]);\n\n return (\n <CopilotChat\n welcomeScreen={CopilotPopupView.WelcomeScreen}\n {...chatProps}\n chatView={PopupViewOverride}\n />\n );\n}\n\nCopilotPopup.displayName = \"CopilotPopup\";\n\nexport default CopilotPopup;\n"],"mappings":";;;;;;;AAeA,SAAgB,aAAa,EAC3B,QACA,cACA,aACA,OACA,QACA,qBACA,GAAG,aACiB;CACpB,MAAM,oBAAoB,cAAc;EACtC,MAAM,aAA6C,cAAc;GAC/D,MAAM,EACJ,QAAQ,YACR,cAAc,kBACd,OAAO,WACP,QAAQ,YACR,qBAAqB,yBACrB,aAAa,iBACb,GAAG,cACD;AAEJ,UACE,oBAACA;IACC,GAAK;IACL,QAAQ,UAAU;IAClB,cAAc,gBAAgB;IAC9B,OAAO,SAAS;IAChB,QAAQ,UAAU;IAClB,qBAAqB,uBAAuB;IAC5C,aAAa,eAAe;KAC5B;;AAIN,SAAO,OAAO,OAAO,WAAWC,wBAAgB;IAC/C;EAAC;EAAqB;EAAQ;EAAc;EAAQ;EAAO;EAAY,CAAC;AAE3E,QACE,oBAAC;EACC,eAAeD,yBAAiB;EAChC,GAAI;EACJ,UAAU;GACV;;AAIN,aAAa,cAAc"}
1
+ {"version":3,"file":"CopilotPopup.mjs","names":["CopilotPopupView","CopilotChatView"],"sources":["../../../src/components/chat/CopilotPopup.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { CopilotChat, CopilotChatProps } from \"./CopilotChat\";\nimport CopilotChatView, { CopilotChatViewProps } from \"./CopilotChatView\";\nimport CopilotPopupView, { CopilotPopupViewProps } from \"./CopilotPopupView\";\n\nexport type CopilotPopupProps = Omit<CopilotChatProps, \"chatView\"> & {\n header?: CopilotPopupViewProps[\"header\"];\n toggleButton?: CopilotPopupViewProps[\"toggleButton\"];\n defaultOpen?: boolean;\n width?: CopilotPopupViewProps[\"width\"];\n height?: CopilotPopupViewProps[\"height\"];\n clickOutsideToClose?: CopilotPopupViewProps[\"clickOutsideToClose\"];\n};\n\nexport function CopilotPopup({\n header,\n toggleButton,\n defaultOpen,\n width,\n height,\n clickOutsideToClose,\n ...chatProps\n}: CopilotPopupProps) {\n const PopupViewOverride = useMemo(() => {\n const Component: React.FC<CopilotChatViewProps> = (viewProps) => {\n const {\n header: viewHeader,\n toggleButton: viewToggleButton,\n width: viewWidth,\n height: viewHeight,\n clickOutsideToClose: viewClickOutsideToClose,\n defaultOpen: viewDefaultOpen,\n ...restProps\n } = viewProps as CopilotPopupViewProps;\n\n return (\n <CopilotPopupView\n {...(restProps as CopilotPopupViewProps)}\n header={header ?? viewHeader}\n toggleButton={toggleButton ?? viewToggleButton}\n width={width ?? viewWidth}\n height={height ?? viewHeight}\n clickOutsideToClose={clickOutsideToClose ?? viewClickOutsideToClose}\n defaultOpen={defaultOpen ?? viewDefaultOpen}\n />\n );\n };\n\n return Object.assign(Component, CopilotChatView);\n }, [clickOutsideToClose, header, toggleButton, height, width, defaultOpen]);\n\n return (\n <CopilotChat\n welcomeScreen={CopilotPopupView.WelcomeScreen}\n {...chatProps}\n isModalDefaultOpen={defaultOpen}\n chatView={PopupViewOverride}\n />\n );\n}\n\nCopilotPopup.displayName = \"CopilotPopup\";\n\nexport default CopilotPopup;\n"],"mappings":";;;;;;;AAeA,SAAgB,aAAa,EAC3B,QACA,cACA,aACA,OACA,QACA,qBACA,GAAG,aACiB;CACpB,MAAM,oBAAoB,cAAc;EACtC,MAAM,aAA6C,cAAc;GAC/D,MAAM,EACJ,QAAQ,YACR,cAAc,kBACd,OAAO,WACP,QAAQ,YACR,qBAAqB,yBACrB,aAAa,iBACb,GAAG,cACD;AAEJ,UACE,oBAACA;IACC,GAAK;IACL,QAAQ,UAAU;IAClB,cAAc,gBAAgB;IAC9B,OAAO,SAAS;IAChB,QAAQ,UAAU;IAClB,qBAAqB,uBAAuB;IAC5C,aAAa,eAAe;KAC5B;;AAIN,SAAO,OAAO,OAAO,WAAWC,wBAAgB;IAC/C;EAAC;EAAqB;EAAQ;EAAc;EAAQ;EAAO;EAAY,CAAC;AAE3E,QACE,oBAAC;EACC,eAAeD,yBAAiB;EAChC,GAAI;EACJ,oBAAoB;EACpB,UAAU;GACV;;AAIN,aAAa,cAAc"}
@@ -29,6 +29,7 @@ function CopilotSidebar({ header, toggleButton, defaultOpen, width, ...chatProps
29
29
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotChat.CopilotChat, {
30
30
  welcomeScreen: require_CopilotSidebarView.CopilotSidebarView.WelcomeScreen,
31
31
  ...chatProps,
32
+ isModalDefaultOpen: defaultOpen,
32
33
  chatView: SidebarViewOverride
33
34
  });
34
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotSidebar.cjs","names":["CopilotSidebarView","CopilotChatView","CopilotChat"],"sources":["../../../src/components/chat/CopilotSidebar.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { CopilotChat, CopilotChatProps } from \"./CopilotChat\";\nimport CopilotChatView, { CopilotChatViewProps } from \"./CopilotChatView\";\nimport {\n CopilotSidebarView,\n CopilotSidebarViewProps,\n} from \"./CopilotSidebarView\";\n\nexport type CopilotSidebarProps = Omit<CopilotChatProps, \"chatView\"> & {\n header?: CopilotSidebarViewProps[\"header\"];\n toggleButton?: CopilotSidebarViewProps[\"toggleButton\"];\n defaultOpen?: boolean;\n width?: number | string;\n};\n\nexport function CopilotSidebar({\n header,\n toggleButton,\n defaultOpen,\n width,\n ...chatProps\n}: CopilotSidebarProps) {\n const SidebarViewOverride = useMemo(() => {\n const Component: React.FC<CopilotChatViewProps> = (viewProps) => {\n const {\n header: viewHeader,\n toggleButton: viewToggleButton,\n width: viewWidth,\n defaultOpen: viewDefaultOpen,\n ...restProps\n } = viewProps as CopilotSidebarViewProps;\n\n return (\n <CopilotSidebarView\n {...(restProps as CopilotSidebarViewProps)}\n header={header ?? viewHeader}\n toggleButton={toggleButton ?? viewToggleButton}\n width={width ?? viewWidth}\n defaultOpen={defaultOpen ?? viewDefaultOpen}\n />\n );\n };\n\n return Object.assign(Component, CopilotChatView);\n }, [header, toggleButton, width, defaultOpen]);\n\n return (\n <CopilotChat\n welcomeScreen={CopilotSidebarView.WelcomeScreen}\n {...chatProps}\n chatView={SidebarViewOverride}\n />\n );\n}\n\nCopilotSidebar.displayName = \"CopilotSidebar\";\n\nexport default CopilotSidebar;\n"],"mappings":";;;;;;;;;AAgBA,SAAgB,eAAe,EAC7B,QACA,cACA,aACA,OACA,GAAG,aACmB;CACtB,MAAM,+CAAoC;EACxC,MAAM,aAA6C,cAAc;GAC/D,MAAM,EACJ,QAAQ,YACR,cAAc,kBACd,OAAO,WACP,aAAa,iBACb,GAAG,cACD;AAEJ,UACE,2CAACA;IACC,GAAK;IACL,QAAQ,UAAU;IAClB,cAAc,gBAAgB;IAC9B,OAAO,SAAS;IAChB,aAAa,eAAe;KAC5B;;AAIN,SAAO,OAAO,OAAO,WAAWC,gCAAgB;IAC/C;EAAC;EAAQ;EAAc;EAAO;EAAY,CAAC;AAE9C,QACE,2CAACC;EACC,eAAeF,8CAAmB;EAClC,GAAI;EACJ,UAAU;GACV;;AAIN,eAAe,cAAc"}
1
+ {"version":3,"file":"CopilotSidebar.cjs","names":["CopilotSidebarView","CopilotChatView","CopilotChat"],"sources":["../../../src/components/chat/CopilotSidebar.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { CopilotChat, CopilotChatProps } from \"./CopilotChat\";\nimport CopilotChatView, { CopilotChatViewProps } from \"./CopilotChatView\";\nimport {\n CopilotSidebarView,\n CopilotSidebarViewProps,\n} from \"./CopilotSidebarView\";\n\nexport type CopilotSidebarProps = Omit<CopilotChatProps, \"chatView\"> & {\n header?: CopilotSidebarViewProps[\"header\"];\n toggleButton?: CopilotSidebarViewProps[\"toggleButton\"];\n defaultOpen?: boolean;\n width?: number | string;\n};\n\nexport function CopilotSidebar({\n header,\n toggleButton,\n defaultOpen,\n width,\n ...chatProps\n}: CopilotSidebarProps) {\n const SidebarViewOverride = useMemo(() => {\n const Component: React.FC<CopilotChatViewProps> = (viewProps) => {\n const {\n header: viewHeader,\n toggleButton: viewToggleButton,\n width: viewWidth,\n defaultOpen: viewDefaultOpen,\n ...restProps\n } = viewProps as CopilotSidebarViewProps;\n\n return (\n <CopilotSidebarView\n {...(restProps as CopilotSidebarViewProps)}\n header={header ?? viewHeader}\n toggleButton={toggleButton ?? viewToggleButton}\n width={width ?? viewWidth}\n defaultOpen={defaultOpen ?? viewDefaultOpen}\n />\n );\n };\n\n return Object.assign(Component, CopilotChatView);\n }, [header, toggleButton, width, defaultOpen]);\n\n return (\n <CopilotChat\n welcomeScreen={CopilotSidebarView.WelcomeScreen}\n {...chatProps}\n isModalDefaultOpen={defaultOpen}\n chatView={SidebarViewOverride}\n />\n );\n}\n\nCopilotSidebar.displayName = \"CopilotSidebar\";\n\nexport default CopilotSidebar;\n"],"mappings":";;;;;;;;;AAgBA,SAAgB,eAAe,EAC7B,QACA,cACA,aACA,OACA,GAAG,aACmB;CACtB,MAAM,+CAAoC;EACxC,MAAM,aAA6C,cAAc;GAC/D,MAAM,EACJ,QAAQ,YACR,cAAc,kBACd,OAAO,WACP,aAAa,iBACb,GAAG,cACD;AAEJ,UACE,2CAACA;IACC,GAAK;IACL,QAAQ,UAAU;IAClB,cAAc,gBAAgB;IAC9B,OAAO,SAAS;IAChB,aAAa,eAAe;KAC5B;;AAIN,SAAO,OAAO,OAAO,WAAWC,gCAAgB;IAC/C;EAAC;EAAQ;EAAc;EAAO;EAAY,CAAC;AAE9C,QACE,2CAACC;EACC,eAAeF,8CAAmB;EAClC,GAAI;EACJ,oBAAoB;EACpB,UAAU;GACV;;AAIN,eAAe,cAAc"}
@@ -27,6 +27,7 @@ function CopilotSidebar({ header, toggleButton, defaultOpen, width, ...chatProps
27
27
  return /* @__PURE__ */ jsx(CopilotChat, {
28
28
  welcomeScreen: CopilotSidebarView.WelcomeScreen,
29
29
  ...chatProps,
30
+ isModalDefaultOpen: defaultOpen,
30
31
  chatView: SidebarViewOverride
31
32
  });
32
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CopilotSidebar.mjs","names":["CopilotChatView"],"sources":["../../../src/components/chat/CopilotSidebar.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { CopilotChat, CopilotChatProps } from \"./CopilotChat\";\nimport CopilotChatView, { CopilotChatViewProps } from \"./CopilotChatView\";\nimport {\n CopilotSidebarView,\n CopilotSidebarViewProps,\n} from \"./CopilotSidebarView\";\n\nexport type CopilotSidebarProps = Omit<CopilotChatProps, \"chatView\"> & {\n header?: CopilotSidebarViewProps[\"header\"];\n toggleButton?: CopilotSidebarViewProps[\"toggleButton\"];\n defaultOpen?: boolean;\n width?: number | string;\n};\n\nexport function CopilotSidebar({\n header,\n toggleButton,\n defaultOpen,\n width,\n ...chatProps\n}: CopilotSidebarProps) {\n const SidebarViewOverride = useMemo(() => {\n const Component: React.FC<CopilotChatViewProps> = (viewProps) => {\n const {\n header: viewHeader,\n toggleButton: viewToggleButton,\n width: viewWidth,\n defaultOpen: viewDefaultOpen,\n ...restProps\n } = viewProps as CopilotSidebarViewProps;\n\n return (\n <CopilotSidebarView\n {...(restProps as CopilotSidebarViewProps)}\n header={header ?? viewHeader}\n toggleButton={toggleButton ?? viewToggleButton}\n width={width ?? viewWidth}\n defaultOpen={defaultOpen ?? viewDefaultOpen}\n />\n );\n };\n\n return Object.assign(Component, CopilotChatView);\n }, [header, toggleButton, width, defaultOpen]);\n\n return (\n <CopilotChat\n welcomeScreen={CopilotSidebarView.WelcomeScreen}\n {...chatProps}\n chatView={SidebarViewOverride}\n />\n );\n}\n\nCopilotSidebar.displayName = \"CopilotSidebar\";\n\nexport default CopilotSidebar;\n"],"mappings":";;;;;;;AAgBA,SAAgB,eAAe,EAC7B,QACA,cACA,aACA,OACA,GAAG,aACmB;CACtB,MAAM,sBAAsB,cAAc;EACxC,MAAM,aAA6C,cAAc;GAC/D,MAAM,EACJ,QAAQ,YACR,cAAc,kBACd,OAAO,WACP,aAAa,iBACb,GAAG,cACD;AAEJ,UACE,oBAAC;IACC,GAAK;IACL,QAAQ,UAAU;IAClB,cAAc,gBAAgB;IAC9B,OAAO,SAAS;IAChB,aAAa,eAAe;KAC5B;;AAIN,SAAO,OAAO,OAAO,WAAWA,wBAAgB;IAC/C;EAAC;EAAQ;EAAc;EAAO;EAAY,CAAC;AAE9C,QACE,oBAAC;EACC,eAAe,mBAAmB;EAClC,GAAI;EACJ,UAAU;GACV;;AAIN,eAAe,cAAc"}
1
+ {"version":3,"file":"CopilotSidebar.mjs","names":["CopilotChatView"],"sources":["../../../src/components/chat/CopilotSidebar.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { CopilotChat, CopilotChatProps } from \"./CopilotChat\";\nimport CopilotChatView, { CopilotChatViewProps } from \"./CopilotChatView\";\nimport {\n CopilotSidebarView,\n CopilotSidebarViewProps,\n} from \"./CopilotSidebarView\";\n\nexport type CopilotSidebarProps = Omit<CopilotChatProps, \"chatView\"> & {\n header?: CopilotSidebarViewProps[\"header\"];\n toggleButton?: CopilotSidebarViewProps[\"toggleButton\"];\n defaultOpen?: boolean;\n width?: number | string;\n};\n\nexport function CopilotSidebar({\n header,\n toggleButton,\n defaultOpen,\n width,\n ...chatProps\n}: CopilotSidebarProps) {\n const SidebarViewOverride = useMemo(() => {\n const Component: React.FC<CopilotChatViewProps> = (viewProps) => {\n const {\n header: viewHeader,\n toggleButton: viewToggleButton,\n width: viewWidth,\n defaultOpen: viewDefaultOpen,\n ...restProps\n } = viewProps as CopilotSidebarViewProps;\n\n return (\n <CopilotSidebarView\n {...(restProps as CopilotSidebarViewProps)}\n header={header ?? viewHeader}\n toggleButton={toggleButton ?? viewToggleButton}\n width={width ?? viewWidth}\n defaultOpen={defaultOpen ?? viewDefaultOpen}\n />\n );\n };\n\n return Object.assign(Component, CopilotChatView);\n }, [header, toggleButton, width, defaultOpen]);\n\n return (\n <CopilotChat\n welcomeScreen={CopilotSidebarView.WelcomeScreen}\n {...chatProps}\n isModalDefaultOpen={defaultOpen}\n chatView={SidebarViewOverride}\n />\n );\n}\n\nCopilotSidebar.displayName = \"CopilotSidebar\";\n\nexport default CopilotSidebar;\n"],"mappings":";;;;;;;AAgBA,SAAgB,eAAe,EAC7B,QACA,cACA,aACA,OACA,GAAG,aACmB;CACtB,MAAM,sBAAsB,cAAc;EACxC,MAAM,aAA6C,cAAc;GAC/D,MAAM,EACJ,QAAQ,YACR,cAAc,kBACd,OAAO,WACP,aAAa,iBACb,GAAG,cACD;AAEJ,UACE,oBAAC;IACC,GAAK;IACL,QAAQ,UAAU;IAClB,cAAc,gBAAgB;IAC9B,OAAO,SAAS;IAChB,aAAa,eAAe;KAC5B;;AAIN,SAAO,OAAO,OAAO,WAAWA,wBAAgB;IAC/C;EAAC;EAAQ;EAAc;EAAO;EAAY,CAAC;AAE9C,QACE,oBAAC;EACC,eAAe,mBAAmB;EAClC,GAAI;EACJ,oBAAoB;EACpB,UAAU;GACV;;AAIN,eAAe,cAAc"}
@@ -52,12 +52,14 @@ function useThreadStoreSelector(store, selector) {
52
52
  * }
53
53
  * ```
54
54
  */
55
- function useThreads({ userId, agentId }) {
55
+ function useThreads({ userId, agentId, includeArchived, limit }) {
56
56
  const { copilotkit } = require_CopilotKitProvider.useCopilotKit();
57
57
  const [store] = (0, react.useState)(() => (0, _copilotkitnext_core.ɵcreateThreadStore)({ fetch: globalThis.fetch }));
58
58
  const threads = useThreadStoreSelector(store, _copilotkitnext_core.ɵselectThreads);
59
59
  const storeIsLoading = useThreadStoreSelector(store, _copilotkitnext_core.ɵselectThreadsIsLoading);
60
60
  const storeError = useThreadStoreSelector(store, _copilotkitnext_core.ɵselectThreadsError);
61
+ const hasNextPage = useThreadStoreSelector(store, _copilotkitnext_core.ɵselectHasNextPage);
62
+ const isFetchingNextPage = useThreadStoreSelector(store, _copilotkitnext_core.ɵselectIsFetchingNextPage);
61
63
  const headersKey = (0, react.useMemo)(() => {
62
64
  return JSON.stringify(Object.entries(copilotkit.headers ?? {}).sort(([left], [right]) => left.localeCompare(right)));
63
65
  }, [copilotkit.headers]);
@@ -79,7 +81,9 @@ function useThreads({ userId, agentId }) {
79
81
  headers: { ...copilotkit.headers },
80
82
  wsUrl: copilotkit.intelligence?.wsUrl,
81
83
  userId,
82
- agentId
84
+ agentId,
85
+ includeArchived,
86
+ limit
83
87
  } : null;
84
88
  store.setContext(context);
85
89
  }, [
@@ -89,15 +93,23 @@ function useThreads({ userId, agentId }) {
89
93
  copilotkit.intelligence?.wsUrl,
90
94
  userId,
91
95
  agentId,
92
- copilotkit.headers
96
+ copilotkit.headers,
97
+ includeArchived,
98
+ limit
93
99
  ]);
100
+ const renameThread = (0, react.useCallback)((threadId, name) => store.renameThread(threadId, name), [store]);
101
+ const archiveThread = (0, react.useCallback)((threadId) => store.archiveThread(threadId), [store]);
102
+ const deleteThread = (0, react.useCallback)((threadId) => store.deleteThread(threadId), [store]);
94
103
  return {
95
104
  threads,
96
105
  isLoading,
97
106
  error,
98
- renameThread: (0, react.useCallback)((threadId, name) => store.renameThread(threadId, name), [store]),
99
- archiveThread: (0, react.useCallback)((threadId) => store.archiveThread(threadId), [store]),
100
- deleteThread: (0, react.useCallback)((threadId) => store.deleteThread(threadId), [store])
107
+ hasNextPage,
108
+ isFetchingNextPage,
109
+ fetchNextPage: (0, react.useCallback)(() => store.fetchNextPage(), [store]),
110
+ renameThread,
111
+ archiveThread,
112
+ deleteThread
101
113
  };
102
114
  }
103
115
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-threads.cjs","names":["useCopilotKit","ɵselectThreads","ɵselectThreadsIsLoading","ɵselectThreadsError"],"sources":["../../src/hooks/use-threads.tsx"],"sourcesContent":["import { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport {\n ɵcreateThreadStore,\n ɵselectThreads,\n ɵselectThreadsError,\n ɵselectThreadsIsLoading,\n type ɵThread as CoreThread,\n type ɵThreadRuntimeContext,\n type ɵThreadStore,\n} from \"@copilotkitnext/core\";\nimport {\n useCallback,\n useEffect,\n useMemo,\n useState,\n useSyncExternalStore,\n} from \"react\";\n\n/**\n * A conversation thread managed by the Intelligence platform.\n *\n * Each thread has a unique `id`, an optional human-readable `name`, and\n * timestamp fields tracking creation and update times.\n */\nexport interface Thread extends CoreThread {}\n\n/**\n * Configuration for the {@link useThreads} hook.\n *\n * Both fields are required — they scope the thread list and all mutations\n * to a specific user/agent pair on the Intelligence platform.\n */\nexport interface UseThreadsInput {\n /** The ID of the current user. Thread queries and mutations are scoped to this user. */\n userId: string;\n /** The ID of the agent whose threads to list and manage. */\n agentId: string;\n}\n\n/**\n * Return value of the {@link useThreads} hook.\n *\n * The `threads` array is kept in sync with the platform via a realtime\n * WebSocket subscription (when available) and is sorted most-recently-updated\n * first. Mutations reject with an `Error` if the platform request fails.\n */\nexport interface UseThreadsResult {\n /**\n * All non-archived threads for the current user/agent pair, sorted by\n * most recently updated first. Updated in realtime when the platform\n * pushes metadata events.\n */\n threads: Thread[];\n /**\n * `true` while the initial thread list is being fetched from the platform.\n * Subsequent realtime updates do not re-enter the loading state.\n */\n isLoading: boolean;\n /**\n * The most recent error from fetching threads or executing a mutation,\n * or `null` when there is no error. Reset to `null` on the next\n * successful fetch.\n */\n error: Error | null;\n /**\n * Rename a thread on the platform.\n * Resolves when the server confirms the update; rejects on failure.\n */\n renameThread: (threadId: string, name: string) => Promise<void>;\n /**\n * Archive a thread on the platform.\n * Archived threads are excluded from subsequent list results.\n * Resolves when the server confirms the update; rejects on failure.\n */\n archiveThread: (threadId: string) => Promise<void>;\n /**\n * Permanently delete a thread from the platform.\n * This is irreversible. Resolves when the server confirms deletion;\n * rejects on failure.\n */\n deleteThread: (threadId: string) => Promise<void>;\n}\n\nfunction useThreadStoreSelector<T>(\n store: ɵThreadStore,\n selector: (state: ReturnType<ɵThreadStore[\"getState\"]>) => T,\n): T {\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) => {\n const subscription = store.select(selector).subscribe(onStoreChange);\n return () => subscription.unsubscribe();\n },\n [store, selector],\n ),\n () => selector(store.getState()),\n );\n}\n\n/**\n * React hook for listing and managing Intelligence platform threads.\n *\n * On mount the hook fetches the thread list for the given `userId`/`agentId`\n * pair. When the Intelligence platform exposes a WebSocket URL, it also opens\n * a realtime subscription so the `threads` array stays current without\n * polling — thread creates, renames, archives, and deletes from any client\n * are reflected immediately.\n *\n * Mutation methods (`renameThread`, `archiveThread`, `deleteThread`) return\n * promises that resolve once the platform confirms the operation and reject\n * with an `Error` on failure.\n *\n * @param input - User and agent identifiers that scope the thread list.\n * @returns Thread list state and stable mutation callbacks.\n *\n * @example\n * ```tsx\n * import { useThreads } from \"@copilotkitnext/react\";\n *\n * function ThreadList() {\n * const { threads, isLoading, renameThread, deleteThread } = useThreads({\n * userId: \"user-1\",\n * agentId: \"agent-1\",\n * });\n *\n * if (isLoading) return <p>Loading…</p>;\n *\n * return (\n * <ul>\n * {threads.map((t) => (\n * <li key={t.id}>\n * {t.name ?? \"Untitled\"}\n * <button onClick={() => renameThread(t.id, \"New name\")}>Rename</button>\n * <button onClick={() => deleteThread(t.id)}>Delete</button>\n * </li>\n * ))}\n * </ul>\n * );\n * }\n * ```\n */\nexport function useThreads({\n userId,\n agentId,\n}: UseThreadsInput): UseThreadsResult {\n const { copilotkit } = useCopilotKit();\n\n const [store] = useState(() =>\n ɵcreateThreadStore({\n fetch: globalThis.fetch,\n }),\n );\n\n const threads = useThreadStoreSelector(store, ɵselectThreads);\n const storeIsLoading = useThreadStoreSelector(store, ɵselectThreadsIsLoading);\n const storeError = useThreadStoreSelector(store, ɵselectThreadsError);\n const headersKey = useMemo(() => {\n return JSON.stringify(\n Object.entries(copilotkit.headers ?? {}).sort(([left], [right]) =>\n left.localeCompare(right),\n ),\n );\n }, [copilotkit.headers]);\n const runtimeError = useMemo(() => {\n if (copilotkit.runtimeUrl) {\n return null;\n }\n\n return new Error(\"Runtime URL is not configured\");\n }, [copilotkit.runtimeUrl]);\n const isLoading = runtimeError ? false : storeIsLoading;\n const error = runtimeError ?? storeError;\n\n useEffect(() => {\n store.start();\n return () => {\n store.stop();\n };\n }, [store]);\n\n useEffect(() => {\n const context: ɵThreadRuntimeContext | null = copilotkit.runtimeUrl\n ? {\n runtimeUrl: copilotkit.runtimeUrl,\n headers: { ...copilotkit.headers },\n wsUrl: copilotkit.intelligence?.wsUrl,\n userId,\n agentId,\n }\n : null;\n\n store.setContext(context);\n }, [\n store,\n copilotkit.runtimeUrl,\n headersKey,\n copilotkit.intelligence?.wsUrl,\n userId,\n agentId,\n copilotkit.headers,\n ]);\n\n const renameThread = useCallback(\n (threadId: string, name: string) => store.renameThread(threadId, name),\n [store],\n );\n\n const archiveThread = useCallback(\n (threadId: string) => store.archiveThread(threadId),\n [store],\n );\n\n const deleteThread = useCallback(\n (threadId: string) => store.deleteThread(threadId),\n [store],\n );\n\n return {\n threads,\n isLoading,\n error,\n renameThread,\n archiveThread,\n deleteThread,\n };\n}\n"],"mappings":";;;;;;AAmFA,SAAS,uBACP,OACA,UACG;AACH,gEAEK,kBAAkB;EACjB,MAAM,eAAe,MAAM,OAAO,SAAS,CAAC,UAAU,cAAc;AACpE,eAAa,aAAa,aAAa;IAEzC,CAAC,OAAO,SAAS,CAClB,QACK,SAAS,MAAM,UAAU,CAAC,CACjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CH,SAAgB,WAAW,EACzB,QACA,WACoC;CACpC,MAAM,EAAE,eAAeA,0CAAe;CAEtC,MAAM,CAAC,gFACc,EACjB,OAAO,WAAW,OACnB,CAAC,CACH;CAED,MAAM,UAAU,uBAAuB,OAAOC,oCAAe;CAC7D,MAAM,iBAAiB,uBAAuB,OAAOC,6CAAwB;CAC7E,MAAM,aAAa,uBAAuB,OAAOC,yCAAoB;CACrE,MAAM,sCAA2B;AAC/B,SAAO,KAAK,UACV,OAAO,QAAQ,WAAW,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,WACtD,KAAK,cAAc,MAAM,CAC1B,CACF;IACA,CAAC,WAAW,QAAQ,CAAC;CACxB,MAAM,wCAA6B;AACjC,MAAI,WAAW,WACb,QAAO;AAGT,yBAAO,IAAI,MAAM,gCAAgC;IAChD,CAAC,WAAW,WAAW,CAAC;CAC3B,MAAM,YAAY,eAAe,QAAQ;CACzC,MAAM,QAAQ,gBAAgB;AAE9B,4BAAgB;AACd,QAAM,OAAO;AACb,eAAa;AACX,SAAM,MAAM;;IAEb,CAAC,MAAM,CAAC;AAEX,4BAAgB;EACd,MAAM,UAAwC,WAAW,aACrD;GACE,YAAY,WAAW;GACvB,SAAS,EAAE,GAAG,WAAW,SAAS;GAClC,OAAO,WAAW,cAAc;GAChC;GACA;GACD,GACD;AAEJ,QAAM,WAAW,QAAQ;IACxB;EACD;EACA,WAAW;EACX;EACA,WAAW,cAAc;EACzB;EACA;EACA,WAAW;EACZ,CAAC;AAiBF,QAAO;EACL;EACA;EACA;EACA,sCAlBC,UAAkB,SAAiB,MAAM,aAAa,UAAU,KAAK,EACtE,CAAC,MAAM,CACR;EAiBC,uCAdC,aAAqB,MAAM,cAAc,SAAS,EACnD,CAAC,MAAM,CACR;EAaC,sCAVC,aAAqB,MAAM,aAAa,SAAS,EAClD,CAAC,MAAM,CACR;EASA"}
1
+ {"version":3,"file":"use-threads.cjs","names":["useCopilotKit","ɵselectThreads","ɵselectThreadsIsLoading","ɵselectThreadsError","ɵselectHasNextPage","ɵselectIsFetchingNextPage"],"sources":["../../src/hooks/use-threads.tsx"],"sourcesContent":["import { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport {\n ɵcreateThreadStore,\n ɵselectThreads,\n ɵselectThreadsError,\n ɵselectThreadsIsLoading,\n ɵselectHasNextPage,\n ɵselectIsFetchingNextPage,\n type ɵThread as CoreThread,\n type ɵThreadRuntimeContext,\n type ɵThreadStore,\n} from \"@copilotkitnext/core\";\nimport {\n useCallback,\n useEffect,\n useMemo,\n useState,\n useSyncExternalStore,\n} from \"react\";\n\n/**\n * A conversation thread managed by the Intelligence platform.\n *\n * Each thread has a unique `id`, an optional human-readable `name`, and\n * timestamp fields tracking creation and update times.\n */\nexport interface Thread extends CoreThread {}\n\n/**\n * Configuration for the {@link useThreads} hook.\n *\n * Both fields are required — they scope the thread list and all mutations\n * to a specific user/agent pair on the Intelligence platform.\n */\nexport interface UseThreadsInput {\n /** The ID of the current user. Thread queries and mutations are scoped to this user. */\n userId: string;\n /** The ID of the agent whose threads to list and manage. */\n agentId: string;\n /** When `true`, archived threads are included in the list. Defaults to `false`. */\n includeArchived?: boolean;\n /** Maximum number of threads to fetch per page. When set, enables cursor-based pagination. */\n limit?: number;\n}\n\n/**\n * Return value of the {@link useThreads} hook.\n *\n * The `threads` array is kept in sync with the platform via a realtime\n * WebSocket subscription (when available) and is sorted most-recently-updated\n * first. Mutations reject with an `Error` if the platform request fails.\n */\nexport interface UseThreadsResult {\n /**\n * Threads for the current user/agent pair, sorted by most recently\n * updated first. Updated in realtime when the platform pushes metadata\n * events. Includes archived threads only when `includeArchived` is set.\n */\n threads: Thread[];\n /**\n * `true` while the initial thread list is being fetched from the platform.\n * Subsequent realtime updates do not re-enter the loading state.\n */\n isLoading: boolean;\n /**\n * The most recent error from fetching threads or executing a mutation,\n * or `null` when there is no error. Reset to `null` on the next\n * successful fetch.\n */\n error: Error | null;\n /**\n * `true` when there are more threads available to fetch via\n * {@link fetchNextPage}. Only meaningful when `limit` is set.\n */\n hasNextPage: boolean;\n /**\n * `true` while a subsequent page of threads is being fetched.\n */\n isFetchingNextPage: boolean;\n /**\n * Fetch the next page of threads. No-op when {@link hasNextPage} is\n * `false` or a page fetch is already in progress.\n */\n fetchNextPage: () => void;\n /**\n * Rename a thread on the platform.\n * Resolves when the server confirms the update; rejects on failure.\n */\n renameThread: (threadId: string, name: string) => Promise<void>;\n /**\n * Archive a thread on the platform.\n * Archived threads are excluded from subsequent list results.\n * Resolves when the server confirms the update; rejects on failure.\n */\n archiveThread: (threadId: string) => Promise<void>;\n /**\n * Permanently delete a thread from the platform.\n * This is irreversible. Resolves when the server confirms deletion;\n * rejects on failure.\n */\n deleteThread: (threadId: string) => Promise<void>;\n}\n\nfunction useThreadStoreSelector<T>(\n store: ɵThreadStore,\n selector: (state: ReturnType<ɵThreadStore[\"getState\"]>) => T,\n): T {\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) => {\n const subscription = store.select(selector).subscribe(onStoreChange);\n return () => subscription.unsubscribe();\n },\n [store, selector],\n ),\n () => selector(store.getState()),\n );\n}\n\n/**\n * React hook for listing and managing Intelligence platform threads.\n *\n * On mount the hook fetches the thread list for the given `userId`/`agentId`\n * pair. When the Intelligence platform exposes a WebSocket URL, it also opens\n * a realtime subscription so the `threads` array stays current without\n * polling — thread creates, renames, archives, and deletes from any client\n * are reflected immediately.\n *\n * Mutation methods (`renameThread`, `archiveThread`, `deleteThread`) return\n * promises that resolve once the platform confirms the operation and reject\n * with an `Error` on failure.\n *\n * @param input - User and agent identifiers that scope the thread list.\n * @returns Thread list state and stable mutation callbacks.\n *\n * @example\n * ```tsx\n * import { useThreads } from \"@copilotkitnext/react\";\n *\n * function ThreadList() {\n * const { threads, isLoading, renameThread, deleteThread } = useThreads({\n * userId: \"user-1\",\n * agentId: \"agent-1\",\n * });\n *\n * if (isLoading) return <p>Loading…</p>;\n *\n * return (\n * <ul>\n * {threads.map((t) => (\n * <li key={t.id}>\n * {t.name ?? \"Untitled\"}\n * <button onClick={() => renameThread(t.id, \"New name\")}>Rename</button>\n * <button onClick={() => deleteThread(t.id)}>Delete</button>\n * </li>\n * ))}\n * </ul>\n * );\n * }\n * ```\n */\nexport function useThreads({\n userId,\n agentId,\n includeArchived,\n limit,\n}: UseThreadsInput): UseThreadsResult {\n const { copilotkit } = useCopilotKit();\n\n const [store] = useState(() =>\n ɵcreateThreadStore({\n fetch: globalThis.fetch,\n }),\n );\n\n const threads = useThreadStoreSelector(store, ɵselectThreads);\n const storeIsLoading = useThreadStoreSelector(store, ɵselectThreadsIsLoading);\n const storeError = useThreadStoreSelector(store, ɵselectThreadsError);\n const hasNextPage = useThreadStoreSelector(store, ɵselectHasNextPage);\n const isFetchingNextPage = useThreadStoreSelector(\n store,\n ɵselectIsFetchingNextPage,\n );\n const headersKey = useMemo(() => {\n return JSON.stringify(\n Object.entries(copilotkit.headers ?? {}).sort(([left], [right]) =>\n left.localeCompare(right),\n ),\n );\n }, [copilotkit.headers]);\n const runtimeError = useMemo(() => {\n if (copilotkit.runtimeUrl) {\n return null;\n }\n\n return new Error(\"Runtime URL is not configured\");\n }, [copilotkit.runtimeUrl]);\n const isLoading = runtimeError ? false : storeIsLoading;\n const error = runtimeError ?? storeError;\n\n useEffect(() => {\n store.start();\n return () => {\n store.stop();\n };\n }, [store]);\n\n useEffect(() => {\n const context: ɵThreadRuntimeContext | null = copilotkit.runtimeUrl\n ? {\n runtimeUrl: copilotkit.runtimeUrl,\n headers: { ...copilotkit.headers },\n wsUrl: copilotkit.intelligence?.wsUrl,\n userId,\n agentId,\n includeArchived,\n limit,\n }\n : null;\n\n store.setContext(context);\n }, [\n store,\n copilotkit.runtimeUrl,\n headersKey,\n copilotkit.intelligence?.wsUrl,\n userId,\n agentId,\n copilotkit.headers,\n includeArchived,\n limit,\n ]);\n\n const renameThread = useCallback(\n (threadId: string, name: string) => store.renameThread(threadId, name),\n [store],\n );\n\n const archiveThread = useCallback(\n (threadId: string) => store.archiveThread(threadId),\n [store],\n );\n\n const deleteThread = useCallback(\n (threadId: string) => store.deleteThread(threadId),\n [store],\n );\n\n const fetchNextPage = useCallback(() => store.fetchNextPage(), [store]);\n\n return {\n threads,\n isLoading,\n error,\n hasNextPage,\n isFetchingNextPage,\n fetchNextPage,\n renameThread,\n archiveThread,\n deleteThread,\n };\n}\n"],"mappings":";;;;;;AAuGA,SAAS,uBACP,OACA,UACG;AACH,gEAEK,kBAAkB;EACjB,MAAM,eAAe,MAAM,OA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uCACH,UAAkB,SAAiB,MAAM,aAAa,UAAU,KAAK,EACtE,CAAC,MAAM,CACR;CAED,MAAM,wCACH,aAAqB,MAAM,cAAc,SAAS,EACnD,CAAC,MAAM,CACR;CAED,MAAM,uCACH,aAAqB,MAAM,aAAa,SAAS,EAClD,CAAC,MAAM,CACR;AAID,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,4CARsC,MAAM,eAAe,EAAE,CAAC,MAAM,CAAC;EASrE;EACA;EACA;EACD"}
@@ -19,6 +19,10 @@ interface UseThreadsInput {
19
19
  userId: string;
20
20
  /** The ID of the agent whose threads to list and manage. */
21
21
  agentId: string;
22
+ /** When `true`, archived threads are included in the list. Defaults to `false`. */
23
+ includeArchived?: boolean;
24
+ /** Maximum number of threads to fetch per page. When set, enables cursor-based pagination. */
25
+ limit?: number;
22
26
  }
23
27
  /**
24
28
  * Return value of the {@link useThreads} hook.
@@ -29,9 +33,9 @@ interface UseThreadsInput {
29
33
  */
30
34
  interface UseThreadsResult {
31
35
  /**
32
- * All non-archived threads for the current user/agent pair, sorted by
33
- * most recently updated first. Updated in realtime when the platform
34
- * pushes metadata events.
36
+ * Threads for the current user/agent pair, sorted by most recently
37
+ * updated first. Updated in realtime when the platform pushes metadata
38
+ * events. Includes archived threads only when `includeArchived` is set.
35
39
  */
36
40
  threads: Thread[];
37
41
  /**
@@ -45,6 +49,20 @@ interface UseThreadsResult {
45
49
  * successful fetch.
46
50
  */
47
51
  error: Error | null;
52
+ /**
53
+ * `true` when there are more threads available to fetch via
54
+ * {@link fetchNextPage}. Only meaningful when `limit` is set.
55
+ */
56
+ hasNextPage: boolean;
57
+ /**
58
+ * `true` while a subsequent page of threads is being fetched.
59
+ */
60
+ isFetchingNextPage: boolean;
61
+ /**
62
+ * Fetch the next page of threads. No-op when {@link hasNextPage} is
63
+ * `false` or a page fetch is already in progress.
64
+ */
65
+ fetchNextPage: () => void;
48
66
  /**
49
67
  * Rename a thread on the platform.
50
68
  * Resolves when the server confirms the update; rejects on failure.
@@ -107,7 +125,9 @@ interface UseThreadsResult {
107
125
  */
108
126
  declare function useThreads({
109
127
  userId,
110
- agentId
128
+ agentId,
129
+ includeArchived,
130
+ limit
111
131
  }: UseThreadsInput): UseThreadsResult;
112
132
  //#endregion
113
133
  export { Thread, UseThreadsInput, UseThreadsResult, useThreads };
@@ -1 +1 @@
1
- {"version":3,"file":"use-threads.d.cts","names":[],"sources":["../../src/hooks/use-threads.tsx"],"mappings":";;;;;AAwBA;;;;UAAiB,MAAA,SAAe,OAAA;;;;;AAsBhC;;UAdiB,eAAA;EAoBN;EAlBT,MAAA;EAkCkD;EAhClD,OAAA;AAAA;;;;;;;;UAUe,gBAAA;EAsBA;;;;;EAhBf,OAAA,EAAS,MAAA;EA4BT;;;;EAvBA,SAAA;EAoFc;;;;;EA9Ed,KAAA,EAAO,KAAA;EAiFY;;;;EA5EnB,YAAA,GAAe,QAAA,UAAkB,IAAA,aAAiB,OAAA;EA2ElD;;;;;EArEA,aAAA,GAAgB,QAAA,aAAqB,OAAA;;;;;;EAMrC,YAAA,GAAe,QAAA,aAAqB,OAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6DtB,UAAA,CAAA;EACd,MAAA;EACA;AAAA,GACC,eAAA,GAAkB,gBAAA"}
1
+ {"version":3,"file":"use-threads.d.cts","names":[],"sources":["../../src/hooks/use-threads.tsx"],"mappings":";;;;;AA0BA;;;;UAAiB,MAAA,SAAe,OAAA;;;;;;;UAQf,eAAA;EAQV;EANL,MAAA;EAgBe;EAdf,OAAA;;EAEA,eAAA;EA6BO;EA3BP,KAAA;AAAA;;;;;;;;UAUe,gBAAA;EAsBf;;;;;EAhBA,OAAA,EAAS,MAAA;EA8ByC;;;;EAzBlD,SAAA;EAqCe;;;;AA6DjB;EA5FE,KAAA,EAAO,KAAA;;;;;EAKP,WAAA;EA4FC;;;EAxFD,kBAAA;EAoFA;;;;EA/EA,aAAA;EAiFA;;;;EA5EA,YAAA,GAAe,QAAA,UAAkB,IAAA,aAAiB,OAAA;EA8Ef;;;;;EAxEnC,aAAA,GAAgB,QAAA,aAAqB,OAAA;;;;;;EAMrC,YAAA,GAAe,QAAA,aAAqB,OAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6DtB,UAAA,CAAA;EACd,MAAA;EACA,OAAA;EACA,eAAA;EACA;AAAA,GACC,eAAA,GAAkB,gBAAA"}
@@ -19,6 +19,10 @@ interface UseThreadsInput {
19
19
  userId: string;
20
20
  /** The ID of the agent whose threads to list and manage. */
21
21
  agentId: string;
22
+ /** When `true`, archived threads are included in the list. Defaults to `false`. */
23
+ includeArchived?: boolean;
24
+ /** Maximum number of threads to fetch per page. When set, enables cursor-based pagination. */
25
+ limit?: number;
22
26
  }
23
27
  /**
24
28
  * Return value of the {@link useThreads} hook.
@@ -29,9 +33,9 @@ interface UseThreadsInput {
29
33
  */
30
34
  interface UseThreadsResult {
31
35
  /**
32
- * All non-archived threads for the current user/agent pair, sorted by
33
- * most recently updated first. Updated in realtime when the platform
34
- * pushes metadata events.
36
+ * Threads for the current user/agent pair, sorted by most recently
37
+ * updated first. Updated in realtime when the platform pushes metadata
38
+ * events. Includes archived threads only when `includeArchived` is set.
35
39
  */
36
40
  threads: Thread[];
37
41
  /**
@@ -45,6 +49,20 @@ interface UseThreadsResult {
45
49
  * successful fetch.
46
50
  */
47
51
  error: Error | null;
52
+ /**
53
+ * `true` when there are more threads available to fetch via
54
+ * {@link fetchNextPage}. Only meaningful when `limit` is set.
55
+ */
56
+ hasNextPage: boolean;
57
+ /**
58
+ * `true` while a subsequent page of threads is being fetched.
59
+ */
60
+ isFetchingNextPage: boolean;
61
+ /**
62
+ * Fetch the next page of threads. No-op when {@link hasNextPage} is
63
+ * `false` or a page fetch is already in progress.
64
+ */
65
+ fetchNextPage: () => void;
48
66
  /**
49
67
  * Rename a thread on the platform.
50
68
  * Resolves when the server confirms the update; rejects on failure.
@@ -107,7 +125,9 @@ interface UseThreadsResult {
107
125
  */
108
126
  declare function useThreads({
109
127
  userId,
110
- agentId
128
+ agentId,
129
+ includeArchived,
130
+ limit
111
131
  }: UseThreadsInput): UseThreadsResult;
112
132
  //#endregion
113
133
  export { Thread, UseThreadsInput, UseThreadsResult, useThreads };
@@ -1 +1 @@
1
- {"version":3,"file":"use-threads.d.mts","names":[],"sources":["../../src/hooks/use-threads.tsx"],"mappings":";;;;;AAwBA;;;;UAAiB,MAAA,SAAe,OAAA;;;;;AAsBhC;;UAdiB,eAAA;EAoBN;EAlBT,MAAA;EAkCkD;EAhClD,OAAA;AAAA;;;;;;;;UAUe,gBAAA;EAsBA;;;;;EAhBf,OAAA,EAAS,MAAA;EA4BT;;;;EAvBA,SAAA;EAoFc;;;;;EA9Ed,KAAA,EAAO,KAAA;EAiFY;;;;EA5EnB,YAAA,GAAe,QAAA,UAAkB,IAAA,aAAiB,OAAA;EA2ElD;;;;;EArEA,aAAA,GAAgB,QAAA,aAAqB,OAAA;;;;;;EAMrC,YAAA,GAAe,QAAA,aAAqB,OAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6DtB,UAAA,CAAA;EACd,MAAA;EACA;AAAA,GACC,eAAA,GAAkB,gBAAA"}
1
+ {"version":3,"file":"use-threads.d.mts","names":[],"sources":["../../src/hooks/use-threads.tsx"],"mappings":";;;;;AA0BA;;;;UAAiB,MAAA,SAAe,OAAA;;;;;;;UAQf,eAAA;EAQV;EANL,MAAA;EAgBe;EAdf,OAAA;;EAEA,eAAA;EA6BO;EA3BP,KAAA;AAAA;;;;;;;;UAUe,gBAAA;EAsBf;;;;;EAhBA,OAAA,EAAS,MAAA;EA8ByC;;;;EAzBlD,SAAA;EAqCe;;;;AA6DjB;EA5FE,KAAA,EAAO,KAAA;;;;;EAKP,WAAA;EA4FC;;;EAxFD,kBAAA;EAoFA;;;;EA/EA,aAAA;EAiFA;;;;EA5EA,YAAA,GAAe,QAA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