{"version":3,"file":"vue.cjs","sources":["../src/vue.ts"],"sourcesContent":["/**\n * GUI Chat Protocol - Vue Types\n *\n * This module exports Vue-specific types for GUI chat plugins.\n * Use these types when building Vue-based plugin UI components.\n */\n\nimport { inject, type Component, type InjectionKey, type Ref } from \"vue\";\nimport type { ToolPluginCore, InputHandler } from \"./index\";\n\n// Re-export all core types\nexport * from \"./index\";\n\n// ============================================================================\n// Browser-side plugin runtime\n// ============================================================================\n\n/**\n * Default shape for `BrowserPluginRuntime['endpoints']` when the\n * caller doesn't pin a specific plugin's endpoint type. Values are\n * `unknown` because hosts populate the map with plugin-specific\n * shapes (e.g. mulmoclaude provides `{ method, url }` records); each\n * plugin pins the precise shape via the `E` type parameter on\n * `useRuntime<E>()` below.\n */\nexport type DefaultPluginEndpoints = Readonly<Record<string, unknown>>;\n\n/**\n * Runtime exposed to a plugin's Vue components via `useRuntime()`. The\n * host wraps a plugin's component subtree in a scope provider that\n * `provide`s a per-plugin instance to `PLUGIN_RUNTIME_KEY`.\n *\n * Optional type parameter `E` pins the `endpoints` map's shape so a\n * plugin author can write `useRuntime<TodoEndpoints>()` and read\n * `runtime.endpoints.list.url` without an `as` cast (0.3.2). Defaults\n * to `DefaultPluginEndpoints` for backward compatibility — non-generic\n * usage (`BrowserPluginRuntime` / `useRuntime()`) keeps working\n * unchanged.\n *\n * Spec: https://github.com/receptron/mulmoclaude/issues/1110\n */\nexport interface BrowserPluginRuntime<E = DefaultPluginEndpoints> {\n  /**\n   * Scoped pub/sub client. `subscribe(\"foo\", handler)` is internally\n   * routed to channel `plugin:<pkg>:foo`. Returns an unsubscribe\n   * function.\n   */\n  pubsub: {\n    subscribe<T>(eventName: string, handler: (payload: T) => void): () => void;\n  };\n\n  /**\n   * Reactive locale ref. When the host implements a locale picker, the\n   * plugin's UI re-renders automatically.\n   */\n  locale: Ref<string>;\n\n  /** Same shape as the server-side logger. */\n  log: {\n    debug(msg: string, data?: object): void;\n    info(msg: string, data?: object): void;\n    warn(msg: string, data?: object): void;\n    error(msg: string, data?: object): void;\n  };\n\n  /**\n   * Open `url` in a new tab with `noopener,noreferrer`. Use instead of\n   * `<a target=\"_blank\">` so the security flags can't be forgotten at\n   * call sites.\n   */\n  openUrl(url: string): void;\n\n  /**\n   * POST `args` to this plugin's server-side dispatch route\n   * (`/api/plugins/runtime/<pkg>/dispatch`) and return the parsed\n   * JSON response. The host attaches the bearer token + builds the\n   * URL automatically; the plugin author doesn't need to know either.\n   * Throws on network error or non-2xx response.\n   */\n  dispatch<T = unknown>(args: object): Promise<T>;\n\n  /**\n   * Optional URL map for plugins that need more than the single\n   * `dispatch` endpoint — typically REST-shaped plugins with\n   * multiple sub-resources (`items`, `items/:id`, `columns`, …)\n   * where folding everything through `dispatch(args)` would force a\n   * server-side rewrite to a single action-discriminated POST.\n   *\n   * The host populates the map at provide time; the value shape is\n   * host-defined (mulmoclaude provides `{ method, url }` records).\n   * Single-dispatch plugins (the common runtime-loaded shape) leave\n   * it `undefined` and rely on `dispatch` alone.\n   *\n   * Pin the shape via `useRuntime<E>()`'s type parameter:\n   *\n   * ```ts\n   * interface TodoEndpoints { list: { method: \"GET\"; url: string } }\n   * const runtime = useRuntime<TodoEndpoints>();\n   * runtime.endpoints?.list.url; // ← typed, no cast\n   * ```\n   *\n   * Defaults to `DefaultPluginEndpoints` (Readonly<Record<string,\n   * unknown>>) when called without a type parameter.\n   */\n  endpoints?: E;\n}\n\n/**\n * Vue injection key for `BrowserPluginRuntime`. The host's runtime\n * plugin loader provides a per-plugin instance here; `useRuntime()`\n * inside a plugin component picks it up.\n */\nexport const PLUGIN_RUNTIME_KEY: InjectionKey<BrowserPluginRuntime> = Symbol(\"guiChatPluginRuntime\");\n\n/**\n * Composable that returns the plugin's `BrowserPluginRuntime`. Throws\n * a descriptive error if called outside the host's scope provider so\n * misuse fails loudly during development.\n *\n * Pass a plugin-specific endpoints type as the optional `E` type\n * parameter to drop the cast on `runtime.endpoints`:\n *\n * ```ts\n * const runtime = useRuntime<TodoEndpoints>();\n * runtime.endpoints?.list.url;  // ← typed, no `as`\n * ```\n *\n * Without the type parameter, `endpoints` falls back to\n * `DefaultPluginEndpoints` (Readonly<Record<string, unknown>>).\n */\nexport function useRuntime<E = DefaultPluginEndpoints>(): BrowserPluginRuntime<E> {\n  const runtime = inject(PLUGIN_RUNTIME_KEY);\n  if (!runtime) {\n    throw new Error(\n      \"useRuntime() called outside of <PluginScopedRoot> — the host must provide PLUGIN_RUNTIME_KEY\",\n    );\n  }\n  return runtime as BrowserPluginRuntime<E>;\n}\n\n// ============================================================================\n// Vue-specific Types\n// ============================================================================\n\n/**\n * Legacy Vue component-based config\n * @deprecated Use PluginConfigSchema instead\n */\nexport interface ToolPluginConfig {\n  key: string;\n  defaultValue: unknown;\n  component: Component;\n}\n\n/**\n * Vue plugin interface - extends core with Vue components\n *\n * @typeParam T - Tool-specific data type (for views)\n * @typeParam J - JSON data type (passed to LLM)\n * @typeParam A - Arguments type for execute function\n * @typeParam H - Input handler type (allows custom handlers)\n * @typeParam S - Start response type (app-specific server response)\n */\nexport interface ToolPlugin<\n  T = unknown,\n  J = unknown,\n  A extends object = object,\n  H = InputHandler,\n  S = Record<string, unknown>,\n> extends ToolPluginCore<T, J, A, H, S> {\n  viewComponent?: Component;\n  previewComponent?: Component;\n  /**\n   * Legacy Vue component-based config (for backward compatibility)\n   * @deprecated Use configSchema (PluginConfigSchema) instead\n   */\n  config?: ToolPluginConfig;\n}\n\n/**\n * Alias for ToolPlugin (Vue-specific)\n */\nexport type ToolPluginVue<\n  T = unknown,\n  J = unknown,\n  A extends object = object,\n  H = InputHandler,\n  S = Record<string, unknown>,\n> = ToolPlugin<T, J, A, H, S>;\n"],"names":["inject"],"mappings":";;;;AAgHO,MAAM,4CAAgE,sBAAsB;AAkB5F,SAAS,aAAkE;AAChF,QAAM,UAAUA,IAAAA,OAAO,kBAAkB;AACzC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,SAAO;AACT;;;;;"}