{"version":3,"file":"CopilotKitProvider.cjs","names":["MCPAppsActivityType","MCPAppsActivityContentSchema","MCPAppsActivityRenderer","createA2UIMessageRenderer","viewerTheme","z","CopilotKitCoreReact","CopilotKitInspector"],"sources":["../../src/providers/CopilotKitProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { AbstractAgent } from \"@ag-ui/client\";\nimport type { FrontendTool } from \"@copilotkitnext/core\";\nimport type React from \"react\";\nimport {\n  createContext,\n  useContext,\n  type ReactNode,\n  useMemo,\n  useEffect,\n  useReducer,\n  useRef,\n  useState,\n} from \"react\";\nimport { z } from \"zod\";\nimport { CopilotKitInspector } from \"../components/CopilotKitInspector\";\nimport type { CopilotKitCoreErrorCode } from \"@copilotkitnext/core\";\nimport {\n  MCPAppsActivityContentSchema,\n  MCPAppsActivityRenderer,\n  MCPAppsActivityType,\n} from \"../components/MCPAppsActivityRenderer\";\nimport { createA2UIMessageRenderer } from \"../a2ui/A2UIMessageRenderer\";\nimport { viewerTheme } from \"@copilotkit/a2ui-renderer\";\nimport type { Theme as A2UITheme } from \"@copilotkit/a2ui-renderer\";\nimport { CopilotKitCoreReact } from \"../lib/react-core\";\nimport type {\n  ReactActivityMessageRenderer,\n  ReactToolCallRenderer,\n} from \"../types\";\nimport type { ReactFrontendTool } from \"../types/frontend-tool\";\nimport type { ReactHumanInTheLoop } from \"../types/human-in-the-loop\";\nimport type { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\n\nconst HEADER_NAME = \"X-CopilotCloud-Public-Api-Key\";\nconst COPILOT_CLOUD_CHAT_URL = \"https://api.cloud.copilotkit.ai/copilotkit/v1\";\n\n// Define the context value interface - idiomatic React naming\nexport interface CopilotKitContextValue {\n  copilotkit: CopilotKitCoreReact;\n  /**\n   * Set of tool call IDs currently being executed.\n   * This is tracked at the provider level to ensure tool execution events\n   * are captured even before child components mount.\n   */\n  executingToolCallIds: ReadonlySet<string>;\n}\n\n// Empty set for default context value\nconst EMPTY_SET: ReadonlySet<string> = new Set();\n\n// Create the CopilotKit context\nconst CopilotKitContext = createContext<CopilotKitContextValue>({\n  copilotkit: null!,\n  executingToolCallIds: EMPTY_SET,\n});\n\n// Provider props interface\nexport interface CopilotKitProviderProps {\n  children: ReactNode;\n  runtimeUrl?: string;\n  headers?: Record<string, string>;\n  /**\n   * Credentials mode for fetch requests (e.g., \"include\" for HTTP-only cookies in cross-origin requests).\n   */\n  credentials?: RequestCredentials;\n  /**\n   * The Copilot Cloud public API key.\n   */\n  publicApiKey?: string;\n  /**\n   * Alias for `publicApiKey`\n   **/\n  publicLicenseKey?: string;\n  properties?: Record<string, unknown>;\n  useSingleEndpoint?: boolean;\n  agents__unsafe_dev_only?: Record<string, AbstractAgent>;\n  selfManagedAgents?: Record<string, AbstractAgent>;\n  renderToolCalls?: ReactToolCallRenderer<any>[];\n  renderActivityMessages?: ReactActivityMessageRenderer<any>[];\n  renderCustomMessages?: ReactCustomMessageRenderer[];\n  frontendTools?: ReactFrontendTool[];\n  humanInTheLoop?: ReactHumanInTheLoop[];\n  showDevConsole?: boolean | \"auto\";\n  /**\n   * Error handler called when CopilotKit encounters an error.\n   * Fires for all error types (runtime connection failures, agent errors, tool errors).\n   */\n  onError?: (event: {\n    error: Error;\n    code: CopilotKitCoreErrorCode;\n    context: Record<string, any>;\n  }) => void | Promise<void>;\n  /**\n   * Configuration for the A2UI (Agent-to-UI) renderer.\n   * The built-in A2UI renderer is activated automatically when the runtime reports\n   * that `a2ui` is configured in `CopilotRuntime`. This prop is optional and only\n   * needed if you want to override the default theme.\n   *\n   * @example\n   * ```tsx\n   * <CopilotKit runtimeUrl=\"/api/copilotkit\" a2ui={{ theme: myCustomTheme }}>\n   *   {children}\n   * </CopilotKit>\n   * ```\n   */\n  a2ui?: {\n    /**\n     * Override the default A2UI viewer theme.\n     * When omitted, the built-in `viewerTheme` from `@copilotkit/a2ui-renderer` is used.\n     */\n    theme?: A2UITheme;\n  };\n}\n\n// Small helper to normalize array props to a stable reference and warn\nfunction useStableArrayProp<T>(\n  prop: T[] | undefined,\n  warningMessage?: string,\n  isMeaningfulChange?: (initial: T[], next: T[]) => boolean,\n): T[] {\n  const empty = useMemo<T[]>(() => [], []);\n  const value = prop ?? empty;\n  const initial = useRef(value);\n\n  useEffect(() => {\n    if (\n      warningMessage &&\n      value !== initial.current &&\n      (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)\n    ) {\n      console.error(warningMessage);\n    }\n  }, [value, warningMessage]);\n\n  return value;\n}\n\n// Provider component\nexport const CopilotKitProvider: React.FC<CopilotKitProviderProps> = ({\n  children,\n  runtimeUrl,\n  headers = {},\n  credentials,\n  publicApiKey,\n  publicLicenseKey,\n  properties = {},\n  agents__unsafe_dev_only: agents = {},\n  selfManagedAgents = {},\n  renderToolCalls,\n  renderActivityMessages,\n  renderCustomMessages,\n  frontendTools,\n  humanInTheLoop,\n  showDevConsole = false,\n  useSingleEndpoint = false,\n  onError,\n  a2ui,\n}) => {\n  const [shouldRenderInspector, setShouldRenderInspector] = useState(false);\n  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = useState(false);\n\n  useEffect(() => {\n    if (typeof window === \"undefined\") {\n      return;\n    }\n\n    if (showDevConsole === true) {\n      // Explicitly show the inspector\n      setShouldRenderInspector(true);\n    } else if (showDevConsole === \"auto\") {\n      // Show on localhost or 127.0.0.1 only\n      const localhostHosts = new Set([\"localhost\", \"127.0.0.1\"]);\n      if (localhostHosts.has(window.location.hostname)) {\n        setShouldRenderInspector(true);\n      } else {\n        setShouldRenderInspector(false);\n      }\n    } else {\n      // showDevConsole is false or undefined (default false)\n      setShouldRenderInspector(false);\n    }\n  }, [showDevConsole]);\n\n  // Normalize array props to stable references with clear dev warnings\n  const renderToolCallsList = useStableArrayProp<ReactToolCallRenderer<any>>(\n    renderToolCalls,\n    \"renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.\",\n    (initial, next) => {\n      // Only warn if the shape (names+agentId) changed. Allow identity changes\n      // to support updated closures from parents (e.g., Storybook state).\n      const key = (rc?: ReactToolCallRenderer<unknown>) =>\n        `${rc?.agentId ?? \"\"}:${rc?.name ?? \"\"}`;\n      const setFrom = (arr: ReactToolCallRenderer<unknown>[]) =>\n        new Set(arr.map(key));\n      const a = setFrom(initial);\n      const b = setFrom(next);\n      if (a.size !== b.size) return true;\n      for (const k of a) if (!b.has(k)) return true;\n      return false;\n    },\n  );\n\n  const renderCustomMessagesList =\n    useStableArrayProp<ReactCustomMessageRenderer>(\n      renderCustomMessages,\n      \"renderCustomMessages must be a stable array.\",\n    );\n\n  const renderActivityMessagesList = useStableArrayProp<\n    ReactActivityMessageRenderer<any>\n  >(renderActivityMessages, \"renderActivityMessages must be a stable array.\");\n\n  // Built-in activity renderers that are always included\n  const builtInActivityRenderers = useMemo<\n    ReactActivityMessageRenderer<any>[]\n  >(() => {\n    const renderers: ReactActivityMessageRenderer<any>[] = [\n      {\n        activityType: MCPAppsActivityType,\n        content: MCPAppsActivityContentSchema,\n        render: MCPAppsActivityRenderer,\n      },\n    ];\n\n    if (runtimeA2UIEnabled) {\n      renderers.unshift(\n        createA2UIMessageRenderer({ theme: a2ui?.theme ?? viewerTheme }),\n      );\n    }\n\n    return renderers;\n  }, [runtimeA2UIEnabled, a2ui]);\n\n  // Combine user-provided activity renderers with built-in ones\n  // User-provided renderers take precedence (come first) so they can override built-ins\n  const allActivityRenderers = useMemo(() => {\n    return [...renderActivityMessagesList, ...builtInActivityRenderers];\n  }, [renderActivityMessagesList, builtInActivityRenderers]);\n\n  const resolvedPublicKey = publicApiKey ?? publicLicenseKey;\n  const mergedAgents = useMemo(\n    () => ({ ...agents, ...selfManagedAgents }),\n    [agents, selfManagedAgents],\n  );\n  const hasLocalAgents = mergedAgents && Object.keys(mergedAgents).length > 0;\n\n  // Merge a provided publicApiKey into headers (without overwriting an explicit header).\n  const mergedHeaders = useMemo(() => {\n    if (!resolvedPublicKey) return headers;\n    if (headers[HEADER_NAME]) return headers;\n    return {\n      ...headers,\n      [HEADER_NAME]: resolvedPublicKey,\n    };\n  }, [headers, resolvedPublicKey]);\n\n  if (!runtimeUrl && !resolvedPublicKey && !hasLocalAgents) {\n    const message =\n      \"Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'\";\n    if (process.env.NODE_ENV === \"production\") {\n      throw new Error(message);\n    } else {\n      // In dev/test we warn but allow to facilitate local agents and unit tests.\n      console.warn(message);\n    }\n  }\n\n  const chatApiEndpoint =\n    runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL : undefined);\n\n  const frontendToolsList = useStableArrayProp<ReactFrontendTool>(\n    frontendTools,\n    \"frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.\",\n  );\n  const humanInTheLoopList = useStableArrayProp<ReactHumanInTheLoop>(\n    humanInTheLoop,\n    \"humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead.\",\n  );\n\n  // Note: warnings for array identity changes are handled by useStableArrayProp\n\n  // Process humanInTheLoop tools to create handlers and add render components\n  const processedHumanInTheLoopTools = useMemo(() => {\n    const processedTools: FrontendTool[] = [];\n    const processedRenderToolCalls: ReactToolCallRenderer<unknown>[] = [];\n\n    humanInTheLoopList.forEach((tool) => {\n      // Create a promise-based handler for each human-in-the-loop tool\n      const frontendTool: FrontendTool = {\n        name: tool.name,\n        description: tool.description,\n        parameters: tool.parameters,\n        followUp: tool.followUp,\n        ...(tool.agentId && { agentId: tool.agentId }),\n        handler: async () => {\n          // This handler will be replaced by the hook when it runs\n          // For provider-level tools, we create a basic handler that waits for user interaction\n          return new Promise((resolve) => {\n            // The actual implementation will be handled by the render component\n            // This is a placeholder that the hook will override\n            console.warn(\n              `Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`,\n            );\n            resolve(undefined);\n          });\n        },\n      };\n      processedTools.push(frontendTool);\n\n      // Add the render component to renderToolCalls\n      if (tool.render) {\n        processedRenderToolCalls.push({\n          name: tool.name,\n          args: tool.parameters!,\n          render: tool.render,\n          ...(tool.agentId && { agentId: tool.agentId }),\n        } as ReactToolCallRenderer<unknown>);\n      }\n    });\n\n    return { tools: processedTools, renderToolCalls: processedRenderToolCalls };\n  }, [humanInTheLoopList]);\n\n  // Combine all tools for CopilotKitCore\n  const allTools = useMemo(() => {\n    const tools: FrontendTool[] = [];\n\n    // Add frontend tools\n    tools.push(...frontendToolsList);\n\n    // Add processed human-in-the-loop tools\n    tools.push(...processedHumanInTheLoopTools.tools);\n\n    return tools;\n  }, [frontendToolsList, processedHumanInTheLoopTools]);\n\n  // Combine all render tool calls\n  const allRenderToolCalls = useMemo(() => {\n    const combined: ReactToolCallRenderer<unknown>[] = [...renderToolCallsList];\n\n    // Add render components from frontend tools\n    frontendToolsList.forEach((tool) => {\n      if (tool.render) {\n        // For wildcard tools without parameters, default to z.any()\n        const args =\n          tool.parameters || (tool.name === \"*\" ? z.any() : undefined);\n        if (args) {\n          combined.push({\n            name: tool.name,\n            args: args,\n            render: tool.render,\n          } as ReactToolCallRenderer<unknown>);\n        }\n      }\n    });\n\n    // Add render components from human-in-the-loop tools\n    combined.push(...processedHumanInTheLoopTools.renderToolCalls);\n\n    return combined;\n  }, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);\n\n  // Stable instance: created once for the provider lifetime.\n  // Updates are applied via setter effects below rather than recreating the instance.\n  const copilotkitRef = useRef<CopilotKitCoreReact | null>(null);\n  if (copilotkitRef.current === null) {\n    copilotkitRef.current = new CopilotKitCoreReact({\n      runtimeUrl: chatApiEndpoint,\n      runtimeTransport: useSingleEndpoint ? \"single\" : \"rest\",\n      headers: mergedHeaders,\n      credentials,\n      properties,\n      agents__unsafe_dev_only: mergedAgents,\n      tools: allTools,\n      renderToolCalls: allRenderToolCalls,\n      renderActivityMessages: allActivityRenderers,\n      renderCustomMessages: renderCustomMessagesList,\n    });\n  }\n  const copilotkit = copilotkitRef.current;\n\n  // Sync runtimeA2UIEnabled from the core once runtime info is fetched\n  useEffect(() => {\n    const subscription = copilotkit.subscribe({\n      onRuntimeConnectionStatusChanged: () => {\n        setRuntimeA2UIEnabled(copilotkit.a2uiEnabled);\n      },\n    });\n    return () => {\n      subscription.unsubscribe();\n    };\n  }, [copilotkit]);\n\n  // Subscribe to render tool calls changes to force re-renders\n  const [, forceUpdate] = useReducer((x) => x + 1, 0);\n\n  useEffect(() => {\n    const subscription = copilotkit.subscribe({\n      onRenderToolCallsChanged: () => {\n        forceUpdate();\n      },\n    });\n\n    return () => {\n      subscription.unsubscribe();\n    };\n  }, [copilotkit]);\n\n  // Track executing tool call IDs at the provider level.\n  // This is critical for HITL reconnection: when connecting to a thread with\n  // pending tool calls, the onToolExecutionStart event fires before child components\n  // (like CopilotChatToolCallsView) mount. By tracking at the provider level,\n  // we ensure the executing state is captured and available when children mount.\n  const [executingToolCallIds, setExecutingToolCallIds] = useState<\n    ReadonlySet<string>\n  >(() => new Set());\n\n  useEffect(() => {\n    const subscription = copilotkit.subscribe({\n      onToolExecutionStart: ({ toolCallId }) => {\n        setExecutingToolCallIds((prev) => {\n          if (prev.has(toolCallId)) return prev;\n          const next = new Set(prev);\n          next.add(toolCallId);\n          return next;\n        });\n      },\n      onToolExecutionEnd: ({ toolCallId }) => {\n        setExecutingToolCallIds((prev) => {\n          if (!prev.has(toolCallId)) return prev;\n          const next = new Set(prev);\n          next.delete(toolCallId);\n          return next;\n        });\n      },\n    });\n\n    return () => {\n      subscription.unsubscribe();\n    };\n  }, [copilotkit]);\n\n  // onError subscription — forward core errors to user callback\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        onErrorRef.current?.({\n          error: event.error,\n          code: event.code,\n          context: event.context,\n        });\n      },\n    });\n\n    return () => {\n      subscription.unsubscribe();\n    };\n  }, [copilotkit]);\n\n  useEffect(() => {\n    copilotkit.setRuntimeUrl(chatApiEndpoint);\n    copilotkit.setRuntimeTransport(useSingleEndpoint ? \"single\" : \"rest\");\n    copilotkit.setHeaders(mergedHeaders);\n    copilotkit.setCredentials(credentials);\n    copilotkit.setProperties(properties);\n    copilotkit.setAgents__unsafe_dev_only(mergedAgents);\n  }, [\n    copilotkit,\n    chatApiEndpoint,\n    mergedHeaders,\n    credentials,\n    properties,\n    mergedAgents,\n    useSingleEndpoint,\n  ]);\n\n  // Sync render/tool arrays to the stable instance via setters.\n  // On mount, the constructor already receives the correct initial values,\n  // so we skip the first invocation. This is critical because child hooks\n  // (e.g., useFrontendTool, useHumanInTheLoop) register tools dynamically\n  // via addTool()/setRenderToolCalls() in their own effects, which fire\n  // BEFORE parent effects (React fires effects bottom-up). If the parent\n  // setter effects ran on mount, they would overwrite the children's tools.\n  const didMountRef = useRef(false);\n\n  useEffect(() => {\n    if (!didMountRef.current) return;\n    copilotkit.setTools(allTools);\n  }, [copilotkit, allTools]);\n\n  useEffect(() => {\n    if (!didMountRef.current) return;\n    copilotkit.setRenderToolCalls(allRenderToolCalls);\n  }, [copilotkit, allRenderToolCalls]);\n\n  useEffect(() => {\n    if (!didMountRef.current) return;\n    copilotkit.setRenderActivityMessages(allActivityRenderers);\n  }, [copilotkit, allActivityRenderers]);\n\n  useEffect(() => {\n    if (!didMountRef.current) return;\n    copilotkit.setRenderCustomMessages(renderCustomMessagesList);\n  }, [copilotkit, renderCustomMessagesList]);\n\n  // Mark mount complete — must be declared AFTER the setter effects\n  // so it runs last in the effect queue on the initial mount cycle.\n  useEffect(() => {\n    didMountRef.current = true;\n  }, []);\n\n  const contextValue = useMemo<CopilotKitContextValue>(\n    () => ({ copilotkit, executingToolCallIds }),\n    [copilotkit, executingToolCallIds],\n  );\n\n  return (\n    <CopilotKitContext.Provider value={contextValue}>\n      {children}\n      {shouldRenderInspector ? <CopilotKitInspector core={copilotkit} /> : null}\n    </CopilotKitContext.Provider>\n  );\n};\n\n// Hook to use the CopilotKit instance - returns the full context value\nexport const useCopilotKit = (): CopilotKitContextValue => {\n  const context = useContext(CopilotKitContext);\n  const [, forceUpdate] = useReducer((x) => x + 1, 0);\n\n  if (!context) {\n    throw new Error(\"useCopilotKit must be used within CopilotKitProvider\");\n  }\n  useEffect(() => {\n    const subscription = context.copilotkit.subscribe({\n      onRuntimeConnectionStatusChanged: () => {\n        forceUpdate();\n      },\n    });\n    return () => {\n      subscription.unsubscribe();\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  return context;\n};\n"],"mappings":";;;;;;;;;;;;;AAmCA,MAAM,cAAc;AACpB,MAAM,yBAAyB;AAiB/B,MAAM,6CAA0D;CAC9D,YAAY;CACZ,sCALqC,IAAI,KAAK;CAM/C,CAAC;AA6DF,SAAS,mBACP,MACA,gBACA,oBACK;CACL,MAAM,iCAA2B,EAAE,EAAE,EAAE,CAAC;CACxC,MAAM,QAAQ,QAAQ;CACtB,MAAM,4BAAiB,MAAM;AAE7B,4BAAgB;AACd,MACE,kBACA,UAAU,QAAQ,YACjB,qBAAqB,mBAAmB,QAAQ,SAAS,MAAM,GAAG,MAEnE,SAAQ,MAAM,eAAe;IAE9B,CAAC,OAAO,eAAe,CAAC;AAE3B,QAAO;;AAIT,MAAa,sBAAyD,EACpE,UACA,YACA,UAAU,EAAE,EACZ,aACA,cACA,kBACA,aAAa,EAAE,EACf,yBAAyB,SAAS,EAAE,EACpC,oBAAoB,EAAE,EACtB,iBACA,wBACA,sBACA,eACA,gBACA,iBAAiB,OACjB,oBAAoB,OACpB,SACA,WACI;CACJ,MAAM,CAAC,uBAAuB,gDAAqC,MAAM;CACzE,MAAM,CAAC,oBAAoB,6CAAkC,MAAM;AAEnE,4BAAgB;AACd,MAAI,OAAO,WAAW,YACpB;AAGF,MAAI,mBAAmB,KAErB,0BAAyB,KAAK;WACrB,mBAAmB,OAG5B,KADuB,IAAI,IAAI,CAAC,aAAa,YAAY,CAAC,CACvC,IAAI,OAAO,SAAS,SAAS,CAC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