{"version":3,"file":"index.cjs","sources":["../src/hooks/use-copilot-action.ts","../src/hooks/use-frontend-tool.ts","../src/hooks/use-copilot-readable.ts","../src/components/copilot-provider/CopilotKit.vue"],"sourcesContent":["/**\n * V1 compatibility wrapper for useCopilotAction.\n *\n * Accepts the legacy Parameter[] action format and routes to the appropriate\n * v2 composable (useFrontendTool, useHumanInTheLoop, or useRenderTool).\n */\nimport type { WatchSource } from \"vue\";\nimport type { Parameter, MappedParameterTypes } from \"@copilotkit/shared\";\nimport { getZodParameters, parseJson } from \"@copilotkit/shared\";\nimport { useFrontendTool as useFrontendToolV2 } from \"../v2/hooks/use-frontend-tool\";\nimport { useHumanInTheLoop as useHumanInTheLoopV2 } from \"../v2/hooks/use-human-in-the-loop\";\nimport { useRenderTool as useRenderToolV2 } from \"../v2/hooks/use-render-tool\";\nimport type { VueFrontendTool, VueHumanInTheLoop } from \"../v2/types\";\n\n// Wraps a v1 render function so a JSON-string `result` is parsed before being\n// passed through. Mirrors the v1 React behavior. If render is a Component\n// (object) rather than a function, returns it unchanged — Components receive\n// props through Vue's prop system and the user is responsible for parsing.\nfunction wrapRenderWithJsonResult<R>(render: R): R {\n  if (typeof render !== \"function\") return render;\n  return ((props: { result?: unknown }) => {\n    const next =\n      typeof props.result === \"string\"\n        ? { ...props, result: parseJson(props.result, props.result) }\n        : props;\n    return (render as (p: unknown) => unknown)(next);\n  }) as R;\n}\n\nexport interface FrontendAction<T extends Parameter[] | [] = []> {\n  name: string;\n  description?: string;\n  parameters?: T;\n  handler?: (args: MappedParameterTypes<T>) => unknown | Promise<unknown>;\n  followUp?: boolean;\n  available?: \"disabled\" | \"enabled\" | \"remote\" | \"frontend\";\n  render?: VueFrontendTool<MappedParameterTypes<T>>[\"render\"];\n  renderAndWaitForResponse?: VueFrontendTool<MappedParameterTypes<T>>[\"render\"];\n  renderAndWait?: VueFrontendTool<MappedParameterTypes<T>>[\"render\"];\n  agentId?: string;\n}\n\nexport interface CatchAllFrontendAction {\n  name: \"*\";\n  render: (props: unknown) => unknown;\n}\n\nexport function useCopilotAction<const T extends Parameter[] | [] = []>(\n  action: FrontendAction<T> | CatchAllFrontendAction,\n  deps?: WatchSource<unknown>[],\n): void {\n  const zodParameters =\n    \"parameters\" in action\n      ? getZodParameters(action.parameters as T)\n      : undefined;\n\n  // Catch-all render action\n  if (action.name === \"*\") {\n    useRenderToolV2(\n      {\n        name: \"*\",\n        render: wrapRenderWithJsonResult(\n          (action as CatchAllFrontendAction).render,\n        ),\n        ...(\"agentId\" in action\n          ? { agentId: (action as FrontendAction<T>).agentId }\n          : {}),\n      },\n      deps,\n    );\n    return;\n  }\n\n  const typedAction = action as FrontendAction<T>;\n\n  // Human-in-the-loop: has renderAndWaitForResponse or renderAndWait\n  if (\n    \"renderAndWaitForResponse\" in typedAction ||\n    \"renderAndWait\" in typedAction\n  ) {\n    const render =\n      typedAction.render ??\n      typedAction.renderAndWaitForResponse ??\n      typedAction.renderAndWait;\n\n    if (!render) {\n      console.warn(\n        `[CopilotKit] useCopilotAction: HITL action '${typedAction.name}' ` +\n          `has no render function. Skipping.`,\n      );\n      return;\n    }\n\n    useHumanInTheLoopV2<MappedParameterTypes<T>>(\n      {\n        name: typedAction.name,\n        description: typedAction.description,\n        parameters: zodParameters,\n        render: wrapRenderWithJsonResult(render) as VueHumanInTheLoop<\n          MappedParameterTypes<T>\n        >[\"render\"],\n        agentId: typedAction.agentId,\n      },\n      deps,\n    );\n    return;\n  }\n\n  // Render-only: available is \"frontend\" or \"disabled\" (no handler invoked remotely)\n  if (\n    typedAction.available === \"frontend\" ||\n    typedAction.available === \"disabled\"\n  ) {\n    if (typedAction.render && zodParameters) {\n      useRenderToolV2(\n        {\n          name: typedAction.name,\n          parameters: zodParameters,\n          render: wrapRenderWithJsonResult(\n            typedAction.render as (props: unknown) => unknown,\n          ),\n          agentId: typedAction.agentId,\n        },\n        deps,\n      );\n    } else {\n      console.warn(\n        `[CopilotKit] useCopilotAction: action '${typedAction.name}' ` +\n          `with available=\"${typedAction.available}\" requires both ` +\n          `'render' and 'parameters'. Skipping registration.`,\n      );\n    }\n    return;\n  }\n\n  // Default: frontend tool with handler\n  // Wrap the v1 handler (single-arg) to match v2's (args, context) => Promise<unknown> signature\n  const normalizedHandler = typedAction.handler\n    ? (args: MappedParameterTypes<T>) =>\n        Promise.resolve(typedAction.handler!(args))\n    : undefined;\n\n  // Convert v1 available (string enum) to v2 available (boolean)\n  // At this point, \"frontend\" and \"disabled\" have been handled above,\n  // so remaining values are \"enabled\", \"remote\", or undefined.\n  // \"remote\" means server-only: register the tool but mark it as not\n  // available on the frontend (matches React's ActionInputAvailability.Remote).\n  let normalizedAvailable: boolean | undefined;\n  if (typedAction.available === \"remote\") {\n    normalizedAvailable = false;\n  } else if (typedAction.available !== undefined) {\n    normalizedAvailable = true;\n  }\n\n  useFrontendToolV2<MappedParameterTypes<T>>(\n    {\n      name: typedAction.name,\n      description: typedAction.description,\n      parameters: zodParameters,\n      handler: normalizedHandler,\n      followUp: typedAction.followUp,\n      render: wrapRenderWithJsonResult(typedAction.render),\n      available: normalizedAvailable,\n      agentId: typedAction.agentId,\n    },\n    deps,\n  );\n}\n","/**\n * V1 compatibility wrapper for useFrontendTool.\n *\n * Accepts the legacy Parameter[] format and converts to Zod via getZodParameters,\n * then delegates to the v2 composable.\n */\nimport type { WatchSource } from \"vue\";\nimport {\n  type Parameter,\n  type MappedParameterTypes,\n  getZodParameters,\n  parseJson,\n} from \"@copilotkit/shared\";\nimport { useFrontendTool as useFrontendToolV2 } from \"../v2/hooks/use-frontend-tool\";\nimport type { VueFrontendTool } from \"../v2/types\";\n\nexport interface UseFrontendToolArgs<T extends Parameter[] | [] = []> {\n  name: string;\n  description?: string;\n  parameters?: T;\n  handler?: (args: MappedParameterTypes<T>) => unknown | Promise<unknown>;\n  followUp?: boolean;\n  available?: \"disabled\" | \"enabled\";\n  render?: VueFrontendTool<MappedParameterTypes<T>>[\"render\"];\n  agentId?: string;\n}\n\nexport function useFrontendTool<const T extends Parameter[] = []>(\n  tool: UseFrontendToolArgs<T>,\n  deps?: WatchSource<unknown>[],\n) {\n  const {\n    name,\n    description,\n    parameters,\n    handler,\n    followUp,\n    available,\n    render,\n    agentId,\n  } = tool;\n  const zodParameters = getZodParameters(parameters);\n\n  // Wrap the v1 handler (single-arg) to match v2's (args, context) => Promise<unknown> signature\n  const normalizedHandler = handler\n    ? (args: MappedParameterTypes<T>) => Promise.resolve(handler(args))\n    : undefined;\n\n  // Wrap render to parse JSON-string results before passing them to the\n  // user's render function — matches the v1 React behavior. If render is a\n  // Component rather than a function, leave it unchanged.\n  const normalizedRender =\n    typeof render === \"function\"\n      ? (props: { result?: unknown }) => {\n          const renderProps =\n            typeof props.result === \"string\"\n              ? { ...props, result: parseJson(props.result, props.result) }\n              : props;\n          return (render as (p: unknown) => unknown)(renderProps);\n        }\n      : render;\n\n  useFrontendToolV2<MappedParameterTypes<T>>(\n    {\n      name,\n      description,\n      parameters: zodParameters,\n      handler: normalizedHandler,\n      followUp,\n      render: normalizedRender,\n      available: available === undefined ? undefined : available !== \"disabled\",\n      agentId,\n    },\n    deps,\n  );\n}\n","/**\n * V1 compatibility wrapper for useCopilotReadable.\n *\n * Provides app-state and other information to the Copilot context.\n * Delegates directly to the v2 CopilotKitCoreVue instance.\n */\nimport { watch, ref, type Ref } from \"vue\";\nimport type { WatchSource } from \"vue\";\nimport { useCopilotKit } from \"../v2/providers/useCopilotKit\";\n\nexport interface UseCopilotReadableOptions {\n  /** The description of the information to be added to the Copilot context. */\n  description: string;\n  /** The value to be added to the Copilot context. Object values are automatically stringified. */\n  value: unknown;\n  /** Whether the context is available to the Copilot. */\n  available?: \"enabled\" | \"disabled\";\n  /** Custom conversion function to serialize the value to a string. */\n  convert?: (description: string, value: unknown) => string;\n}\n\nexport function useCopilotReadable(\n  options: UseCopilotReadableOptions,\n  deps?: WatchSource<unknown>[],\n): Ref<string | undefined> {\n  const { copilotkit } = useCopilotKit();\n  const ctxIdRef = ref<string | undefined>(undefined);\n\n  const extraDeps = deps ?? [];\n\n  watch(\n    [\n      () => options.description,\n      () => options.value,\n      () => options.convert,\n      () => options.available,\n      ...extraDeps,\n    ],\n    (_newValues, _old, onCleanup) => {\n      const core = copilotkit.value;\n      if (!core) return;\n\n      const { description, value, convert, available } = options;\n\n      let serializedValue: string;\n      try {\n        serializedValue = convert\n          ? convert(description, value)\n          : JSON.stringify(value);\n      } catch (err) {\n        console.warn(\n          `[CopilotKit] useCopilotReadable: failed to serialize ` +\n            `value for \"${description}\":`,\n          err,\n        );\n        serializedValue = String(value);\n      }\n\n      if (available === \"disabled\") return;\n\n      ctxIdRef.value = core.addContext({\n        description,\n        value: serializedValue,\n      });\n\n      onCleanup(() => {\n        if (!ctxIdRef.value) return;\n        core.removeContext(ctxIdRef.value);\n      });\n    },\n    { immediate: true },\n  );\n\n  return ctxIdRef;\n}\n","<script setup lang=\"ts\">\n/**\n * V1 compatibility wrapper for CopilotKitProvider.\n *\n * Accepts the same props as CopilotKitProvider plus legacy v1 props\n * (publicApiKey, publicLicenseKey) and delegates to the v2 provider.\n */\nimport type { CopilotKitProps } from \"./types\";\nimport CopilotKitProvider from \"../../v2/providers/CopilotKitProvider.vue\";\n\nconst props = defineProps<CopilotKitProps>();\n</script>\n\n<template>\n  <CopilotKitProvider v-bind=\"props\">\n    <slot />\n  </CopilotKitProvider>\n</template>\n"],"names":["wrapRenderWithJsonResult","render","props","next","parseJson","useCopilotAction","action","deps","zodParameters","getZodParameters","useRenderToolV2","typedAction","useHumanInTheLoopV2","normalizedHandler","args","normalizedAvailable","useFrontendToolV2","useFrontendTool","tool","name","description","parameters","handler","followUp","available","agentId","normalizedRender","renderProps","useCopilotReadable","options","copilotkit","useCopilotKit","ctxIdRef","ref","extraDeps","watch","_newValues","_old","onCleanup","core","value","convert","serializedValue","err","__props","_openBlock","_createBlock","CopilotKitProvider","_renderSlot","_ctx"],"mappings":"wPAkBA,SAASA,EAA4BC,EAAc,CACjD,OAAI,OAAOA,GAAW,WA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