@pillar-ai/react 0.1.8 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { Pillar } from '@pillar-ai/sdk';
2
+ import { scanPageDirect, Pillar } from '@pillar-ai/sdk';
3
3
  import { createContext, useState, useRef, useEffect, useCallback, useMemo, useContext } from 'react';
4
4
  import { createRoot } from 'react-dom/client';
5
5
 
@@ -10,13 +10,24 @@ const PillarContext = createContext(null);
10
10
  // ============================================================================
11
11
  // Provider Component
12
12
  // ============================================================================
13
- function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
13
+ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScanning: _domScanning, // Deprecated - DOM scanning is disabled
14
+ children, }) {
14
15
  const [pillar, setPillar] = useState(null);
15
16
  const [state, setState] = useState("uninitialized");
16
17
  const [isPanelOpen, setIsPanelOpen] = useState(false);
18
+ // DOM scanning is disabled - always false
19
+ const isDOMScanningEnabled = false;
20
+ // Support both productKey (new) and helpCenter (deprecated)
21
+ const resolvedKey = productKey ?? helpCenter;
17
22
  // Keep a ref to the latest onTask callback to avoid re-subscribing
18
23
  const onTaskRef = useRef(onTask);
19
24
  onTaskRef.current = onTask;
25
+ // Warn about deprecated helpCenter usage
26
+ useEffect(() => {
27
+ if (helpCenter && !productKey) {
28
+ console.warn('[Pillar React] "helpCenter" prop is deprecated. Use "productKey" instead.');
29
+ }
30
+ }, []);
20
31
  // Keep a ref to cards to access latest versions
21
32
  const cardsRef = useRef(cards);
22
33
  cardsRef.current = cards;
@@ -43,8 +54,9 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
43
54
  return;
44
55
  }
45
56
  // Initialize new instance
57
+ // Note: DOM scanning is disabled, config.domScanning is ignored
46
58
  const instance = await Pillar.init({
47
- helpCenter,
59
+ productKey: resolvedKey,
48
60
  ...config,
49
61
  });
50
62
  if (mounted) {
@@ -75,7 +87,7 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
75
87
  // Note: We intentionally don't call Pillar.destroy() here
76
88
  // The singleton persists to maintain state across route changes
77
89
  };
78
- }, [helpCenter]); // Re-initialize if helpCenter changes
90
+ }, [resolvedKey]); // Re-initialize if productKey changes
79
91
  // Update state when SDK state changes
80
92
  useEffect(() => {
81
93
  if (pillar) {
@@ -100,6 +112,7 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
100
112
  return unsubscribe;
101
113
  }
102
114
  }, [pillar]);
115
+ // DOM scanning is disabled - no sync needed
103
116
  // Register custom card renderers
104
117
  useEffect(() => {
105
118
  if (!pillar || !cards)
@@ -161,6 +174,15 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
161
174
  const setTextSelectionEnabled = useCallback((enabled) => {
162
175
  pillar?.setTextSelectionEnabled(enabled);
163
176
  }, [pillar]);
177
+ // DOM scanning is disabled - this is a no-op
178
+ const setDOMScanningEnabled = useCallback((_enabled) => {
179
+ // DOM scanning is disabled - this method has no effect
180
+ }, []);
181
+ const scanPage = useCallback((options) => {
182
+ if (!pillar)
183
+ return null;
184
+ return scanPageDirect(options);
185
+ }, [pillar]);
164
186
  const on = useCallback((event, callback) => {
165
187
  return pillar?.on(event, callback) ?? (() => { });
166
188
  }, [pillar]);
@@ -179,6 +201,9 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
179
201
  navigate,
180
202
  setTheme,
181
203
  setTextSelectionEnabled,
204
+ setDOMScanningEnabled,
205
+ isDOMScanningEnabled,
206
+ scanPage,
182
207
  on,
183
208
  }), [
184
209
  pillar,
@@ -193,6 +218,9 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
193
218
  navigate,
194
219
  setTheme,
195
220
  setTextSelectionEnabled,
221
+ setDOMScanningEnabled,
222
+ isDOMScanningEnabled,
223
+ scanPage,
196
224
  on,
197
225
  ]);
198
226
  return (jsx(PillarContext.Provider, { value: value, children: children }));
@@ -219,8 +247,7 @@ function usePillarContext() {
219
247
  * @example
220
248
  * ```tsx
221
249
  * <PillarProvider
222
- * helpCenter="my-help"
223
- * publicKey="pk_xxx"
250
+ * productKey="my-product-key"
224
251
  * config={{ panel: { container: 'manual' } }}
225
252
  * >
226
253
  * <div className="my-layout">
@@ -355,5 +382,107 @@ function usePillar() {
355
382
  };
356
383
  }
357
384
 
358
- export { PillarPanel, PillarProvider, useHelpPanel, usePillar, usePillarContext };
385
+ /**
386
+ * usePillarTool Hook
387
+ *
388
+ * Register one or more tools with co-located metadata and handlers.
389
+ * Tools are registered on mount and unregistered on unmount.
390
+ *
391
+ * @example Single tool
392
+ * ```tsx
393
+ * import { usePillarTool } from '@pillar-ai/react';
394
+ *
395
+ * function CartButton() {
396
+ * usePillarTool({
397
+ * name: 'add_to_cart',
398
+ * description: 'Add a product to the shopping cart',
399
+ * inputSchema: {
400
+ * type: 'object',
401
+ * properties: {
402
+ * productId: { type: 'string', description: 'Product ID' },
403
+ * quantity: { type: 'number', description: 'Quantity to add' },
404
+ * },
405
+ * required: ['productId', 'quantity'],
406
+ * },
407
+ * execute: async ({ productId, quantity }) => {
408
+ * await cartApi.add(productId, quantity);
409
+ * return { content: [{ type: 'text', text: 'Added to cart' }] };
410
+ * },
411
+ * });
412
+ *
413
+ * return <button>Cart</button>;
414
+ * }
415
+ * ```
416
+ *
417
+ * @example Multiple tools
418
+ * ```tsx
419
+ * import { usePillarTool } from '@pillar-ai/react';
420
+ *
421
+ * function BillingPage() {
422
+ * usePillarTool([
423
+ * {
424
+ * name: 'get_current_plan',
425
+ * description: 'Get the current billing plan',
426
+ * execute: async () => ({ plan: 'pro', price: 29 }),
427
+ * },
428
+ * {
429
+ * name: 'upgrade_plan',
430
+ * description: 'Upgrade to a higher plan',
431
+ * inputSchema: {
432
+ * type: 'object',
433
+ * properties: { planId: { type: 'string' } },
434
+ * required: ['planId'],
435
+ * },
436
+ * execute: async ({ planId }) => {
437
+ * await billingApi.upgrade(planId);
438
+ * return { content: [{ type: 'text', text: 'Upgraded!' }] };
439
+ * },
440
+ * },
441
+ * ]);
442
+ *
443
+ * return <div>Billing Content</div>;
444
+ * }
445
+ * ```
446
+ */
447
+ /**
448
+ * Register one or more Pillar tools with co-located metadata and handlers.
449
+ *
450
+ * The tools are registered when the component mounts and automatically
451
+ * unregistered when it unmounts. The `execute` functions always capture
452
+ * the latest React state and props via refs, so you don't need to worry
453
+ * about stale closures.
454
+ *
455
+ * @param schemaOrSchemas - Single tool schema or array of tool schemas
456
+ */
457
+ function usePillarTool(schemaOrSchemas) {
458
+ const { pillar } = usePillarContext();
459
+ // Normalize to array for consistent handling
460
+ const schemas = useMemo(() => (Array.isArray(schemaOrSchemas) ? schemaOrSchemas : [schemaOrSchemas]), [schemaOrSchemas]);
461
+ // Keep refs to latest schemas so handlers capture current state/props
462
+ const schemasRef = useRef(schemas);
463
+ schemasRef.current = schemas;
464
+ // Stable dependency key for the effect (tool names joined)
465
+ const toolNamesKey = useMemo(() => schemas.map((s) => s.name).join(','), [schemas]);
466
+ useEffect(() => {
467
+ if (!pillar)
468
+ return;
469
+ // Register all tools and collect unsubscribe functions
470
+ const unsubscribes = schemasRef.current.map((schema, index) => {
471
+ return pillar.defineTool({
472
+ ...schema,
473
+ // Wrap execute to always use the latest ref version
474
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
475
+ execute: (input) => schemasRef.current[index].execute(input),
476
+ });
477
+ });
478
+ // Cleanup: unregister all tools
479
+ return () => {
480
+ unsubscribes.forEach((unsub) => unsub());
481
+ };
482
+ }, [pillar, toolNamesKey]);
483
+ }
484
+ /** @deprecated Use usePillarTool instead */
485
+ const usePillarAction = usePillarTool;
486
+
487
+ export { PillarPanel, PillarProvider, useHelpPanel, usePillar, usePillarAction, usePillarContext, usePillarTool };
359
488
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/PillarProvider.tsx","../src/PillarPanel.tsx","../src/hooks/useHelpPanel.ts","../src/hooks/usePillar.ts"],"sourcesContent":["/**\n * PillarProvider\n * Context provider that initializes and manages the Pillar SDK\n */\n\nimport {\n Pillar,\n type CardCallbacks,\n type PillarConfig,\n type PillarEvents,\n type PillarState,\n type TaskExecutePayload,\n type ThemeConfig,\n} from \"@pillar-ai/sdk\";\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ComponentType,\n type ReactNode,\n} from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\n\n// ============================================================================\n// Card Types\n// ============================================================================\n\n/**\n * Props passed to custom card components.\n */\nexport interface CardComponentProps<T = Record<string, unknown>> {\n /** Data extracted by the AI for this action */\n data: T;\n /** Called when user confirms the action */\n onConfirm: (modifiedData?: Record<string, unknown>) => void;\n /** Called when user cancels the action */\n onCancel: () => void;\n /** Called to report state changes (loading, success, error) */\n onStateChange?: (\n state: \"loading\" | \"success\" | \"error\",\n message?: string\n ) => void;\n}\n\n/**\n * A React component that can be used as a custom card renderer.\n */\nexport type CardComponent<T = Record<string, unknown>> = ComponentType<\n CardComponentProps<T>\n>;\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface PillarContextValue {\n /** The Pillar SDK instance */\n pillar: Pillar | null;\n\n /** Current SDK state */\n state: PillarState;\n\n /** Whether the SDK is ready */\n isReady: boolean;\n\n /** Whether the panel is currently open */\n isPanelOpen: boolean;\n\n /** Open the help panel */\n open: (options?: {\n view?: string;\n article?: string;\n search?: string;\n focusInput?: boolean;\n }) => void;\n\n /** Close the help panel */\n close: () => void;\n\n /** Toggle the help panel */\n toggle: () => void;\n\n /** Open a specific article */\n openArticle: (slug: string) => void;\n\n /** Open a specific category */\n openCategory: (slug: string) => Promise<void>;\n\n /** Perform a search */\n search: (query: string) => void;\n\n /** Navigate to a specific view */\n navigate: (view: string, params?: Record<string, string>) => void;\n\n /** Update the panel theme at runtime */\n setTheme: (theme: Partial<ThemeConfig>) => void;\n\n /** Enable or disable the text selection \"Ask AI\" popover */\n setTextSelectionEnabled: (enabled: boolean) => void;\n\n /** Subscribe to SDK events */\n on: <K extends keyof PillarEvents>(\n event: K,\n callback: (data: PillarEvents[K]) => void\n ) => () => void;\n}\n\nexport interface PillarProviderProps {\n /** Help center subdomain or identifier */\n helpCenter: string;\n\n /**\n * Additional SDK configuration\n *\n * Notable options:\n * - `panel.useShadowDOM`: Whether to isolate styles in Shadow DOM (default: false).\n * Set to false to let custom cards inherit your app's CSS (Tailwind, etc.)\n */\n config?: Omit<PillarConfig, \"helpCenter\">;\n\n /**\n * Handler called when a task action is triggered from the chat.\n * Use this to handle AI-suggested actions like opening modals, navigating, etc.\n *\n * @example\n * ```tsx\n * <PillarProvider\n * helpCenter=\"my-app\"\n * onTask={(task) => {\n * switch (task.name) {\n * case 'invite_team_member':\n * openInviteModal(task.data);\n * break;\n * case 'open_settings':\n * router.push('/settings');\n * break;\n * }\n * }}\n * >\n * ```\n */\n onTask?: (task: TaskExecutePayload) => void;\n\n /**\n * Custom card components to render for inline_ui type actions.\n * Map card type names to React components that will render the inline UI.\n *\n * @example\n * ```tsx\n * import { InviteMembersCard } from './cards/InviteMembersCard';\n *\n * <PillarProvider\n * helpCenter=\"my-app\"\n * cards={{\n * invite_members: InviteMembersCard,\n * confirm_delete: ConfirmDeleteCard,\n * }}\n * >\n * ```\n */\n cards?: Record<string, CardComponent>;\n\n /** Children components */\n children: ReactNode;\n}\n\n// ============================================================================\n// Context\n// ============================================================================\n\nconst PillarContext = createContext<PillarContextValue | null>(null);\n\n// ============================================================================\n// Provider Component\n// ============================================================================\n\nexport function PillarProvider({\n helpCenter,\n config,\n onTask,\n cards,\n children,\n}: PillarProviderProps): React.ReactElement {\n const [pillar, setPillar] = useState<Pillar | null>(null);\n const [state, setState] = useState<PillarState>(\"uninitialized\");\n const [isPanelOpen, setIsPanelOpen] = useState(false);\n\n // Keep a ref to the latest onTask callback to avoid re-subscribing\n const onTaskRef = useRef(onTask);\n onTaskRef.current = onTask;\n\n // Keep a ref to cards to access latest versions\n const cardsRef = useRef(cards);\n cardsRef.current = cards;\n\n // Initialize SDK\n useEffect(() => {\n let mounted = true;\n\n const initPillar = async () => {\n try {\n // Pillar is a singleton - check if already initialized\n const existingInstance = Pillar.getInstance();\n if (existingInstance) {\n // Reuse existing instance (preserves chat history, panel state, etc.)\n if (mounted) {\n setPillar(existingInstance);\n setState(existingInstance.state);\n\n // Re-subscribe to events\n existingInstance.on(\"panel:open\", () => {\n setIsPanelOpen(true);\n });\n\n existingInstance.on(\"panel:close\", () => {\n setIsPanelOpen(false);\n });\n }\n return;\n }\n\n // Initialize new instance\n const instance = await Pillar.init({\n helpCenter,\n ...config,\n });\n\n if (mounted) {\n setPillar(instance);\n setState(instance.state);\n\n // Listen for panel open/close\n instance.on(\"panel:open\", () => {\n setIsPanelOpen(true);\n });\n\n instance.on(\"panel:close\", () => {\n setIsPanelOpen(false);\n });\n }\n } catch (error) {\n console.error(\"[Pillar React] Failed to initialize:\", error);\n if (mounted) {\n setState(\"error\");\n }\n }\n };\n\n initPillar();\n\n // Cleanup - DON'T destroy the singleton on unmount\n // This preserves conversation history and panel state across navigation\n // Pillar.destroy() should only be called explicitly when the app unmounts completely\n return () => {\n mounted = false;\n // Note: We intentionally don't call Pillar.destroy() here\n // The singleton persists to maintain state across route changes\n };\n }, [helpCenter]); // Re-initialize if helpCenter changes\n\n // Update state when SDK state changes\n useEffect(() => {\n if (pillar) {\n const unsubscribe = pillar.on(\"ready\", () => {\n setState(\"ready\");\n });\n\n const unsubscribeError = pillar.on(\"error\", () => {\n setState(\"error\");\n });\n\n return () => {\n unsubscribe();\n unsubscribeError();\n };\n }\n }, [pillar]);\n\n // Register task handler\n useEffect(() => {\n if (pillar) {\n const unsubscribe = pillar.on(\"task:execute\", (task) => {\n onTaskRef.current?.(task);\n });\n\n return unsubscribe;\n }\n }, [pillar]);\n\n // Register custom card renderers\n useEffect(() => {\n if (!pillar || !cards) return;\n\n const unsubscribers: Array<() => void> = [];\n const roots: Map<HTMLElement, Root> = new Map();\n\n // Register each card component as a vanilla renderer\n Object.entries(cards).forEach(([cardType, Component]) => {\n const unsubscribe = pillar.registerCard(\n cardType,\n (container, data, callbacks: CardCallbacks) => {\n // Create a React root for this container\n const root = createRoot(container);\n roots.set(container, root);\n\n // Render the React component\n root.render(\n <Component\n data={data}\n onConfirm={callbacks.onConfirm}\n onCancel={callbacks.onCancel}\n onStateChange={callbacks.onStateChange}\n />\n );\n\n // Return cleanup function\n return () => {\n const existingRoot = roots.get(container);\n if (existingRoot) {\n existingRoot.unmount();\n roots.delete(container);\n }\n };\n }\n );\n\n unsubscribers.push(unsubscribe);\n });\n\n return () => {\n // Cleanup all registrations\n unsubscribers.forEach((unsub) => unsub());\n // Unmount all React roots\n roots.forEach((root) => root.unmount());\n roots.clear();\n };\n }, [pillar, cards]);\n\n // Actions\n const open = useCallback(\n (options?: {\n view?: string;\n article?: string;\n search?: string;\n focusInput?: boolean;\n }) => {\n pillar?.open(options);\n },\n [pillar]\n );\n\n const close = useCallback(() => {\n pillar?.close();\n }, [pillar]);\n\n const toggle = useCallback(() => {\n pillar?.toggle();\n }, [pillar]);\n\n const openArticle = useCallback(\n (slug: string) => {\n pillar?.open({ article: slug });\n },\n [pillar]\n );\n\n const openCategory = useCallback(\n async (slug: string) => {\n pillar?.navigate(\"category\", { slug });\n },\n [pillar]\n );\n\n const search = useCallback(\n (query: string) => {\n pillar?.open({ search: query });\n },\n [pillar]\n );\n\n const navigate = useCallback(\n (view: string, params?: Record<string, string>) => {\n pillar?.navigate(view, params);\n },\n [pillar]\n );\n\n const setTheme = useCallback(\n (theme: Partial<ThemeConfig>) => {\n pillar?.setTheme(theme);\n },\n [pillar]\n );\n\n const setTextSelectionEnabled = useCallback(\n (enabled: boolean) => {\n pillar?.setTextSelectionEnabled(enabled);\n },\n [pillar]\n );\n\n const on = useCallback(\n <K extends keyof PillarEvents>(\n event: K,\n callback: (data: PillarEvents[K]) => void\n ) => {\n return pillar?.on(event, callback) ?? (() => {});\n },\n [pillar]\n );\n\n // Context value\n const value = useMemo<PillarContextValue>(\n () => ({\n pillar,\n state,\n isReady: state === \"ready\",\n isPanelOpen,\n open,\n close,\n toggle,\n openArticle,\n openCategory,\n search,\n navigate,\n setTheme,\n setTextSelectionEnabled,\n on,\n }),\n [\n pillar,\n state,\n isPanelOpen,\n open,\n close,\n toggle,\n openArticle,\n openCategory,\n search,\n navigate,\n setTheme,\n setTextSelectionEnabled,\n on,\n ]\n );\n\n return (\n <PillarContext.Provider value={value}>{children}</PillarContext.Provider>\n );\n}\n\n// ============================================================================\n// Hook\n// ============================================================================\n\nexport function usePillarContext(): PillarContextValue {\n const context = useContext(PillarContext);\n\n if (!context) {\n throw new Error(\"usePillarContext must be used within a PillarProvider\");\n }\n\n return context;\n}\n","/**\n * PillarPanel Component\n * Renders the Pillar help panel at a custom location in the DOM\n */\n\nimport React, { useRef, useEffect, type CSSProperties, type HTMLAttributes } from 'react';\nimport { usePillarContext } from './PillarProvider';\n\nexport interface PillarPanelProps extends HTMLAttributes<HTMLDivElement> {\n /** Custom class name for the container */\n className?: string;\n \n /** Custom inline styles for the container */\n style?: CSSProperties;\n}\n\n/**\n * Renders the Pillar help panel at a custom location in the DOM.\n * Use this when you want to control where the panel is rendered instead of\n * having it automatically appended to document.body.\n * \n * **Important**: When using this component, set `panel.container: 'manual'` in your\n * PillarProvider config to prevent automatic mounting.\n * \n * @example\n * ```tsx\n * <PillarProvider \n * helpCenter=\"my-help\" \n * publicKey=\"pk_xxx\"\n * config={{ panel: { container: 'manual' } }}\n * >\n * <div className=\"my-layout\">\n * <Sidebar />\n * <PillarPanel className=\"help-panel-container\" />\n * <MainContent />\n * </div>\n * </PillarProvider>\n * ```\n */\nexport function PillarPanel({ \n className, \n style,\n ...props \n}: PillarPanelProps): React.ReactElement {\n const containerRef = useRef<HTMLDivElement>(null);\n const { pillar, isReady } = usePillarContext();\n const hasMounted = useRef(false);\n\n useEffect(() => {\n // Only mount once when SDK is ready and we have a container\n if (!isReady || !pillar || !containerRef.current || hasMounted.current) {\n return;\n }\n\n // Mount the panel into our container\n pillar.mountPanelTo(containerRef.current);\n hasMounted.current = true;\n\n // Cleanup is handled by Pillar.destroy() in the provider\n }, [isReady, pillar]);\n\n return (\n <div \n ref={containerRef} \n className={className}\n style={style}\n data-pillar-panel-container=\"\"\n {...props}\n />\n );\n}\n\n","/**\n * useHelpPanel Hook\n * Panel-specific controls and state\n */\n\nimport { useCallback } from 'react';\nimport { usePillarContext } from '../PillarProvider';\n\nexport interface UseHelpPanelResult {\n /** Whether the panel is currently open */\n isOpen: boolean;\n \n /** Open the panel */\n open: (options?: { view?: string; article?: string; search?: string }) => void;\n \n /** Close the panel */\n close: () => void;\n \n /** Toggle the panel */\n toggle: () => void;\n \n /** Open a specific article in the panel */\n openArticle: (slug: string) => void;\n \n /** Open a specific category in the panel */\n openCategory: (slug: string) => Promise<void>;\n \n /** Open search with a query */\n openSearch: (query?: string) => void;\n \n /** Open the AI chat */\n openChat: () => void;\n}\n\n/**\n * Hook for panel-specific controls\n * \n * @example\n * ```tsx\n * function HelpButton() {\n * const { isOpen, toggle, openChat } = useHelpPanel();\n * \n * return (\n * <div>\n * <button onClick={toggle}>\n * {isOpen ? 'Close' : 'Help'}\n * </button>\n * <button onClick={openChat}>\n * Ask AI\n * </button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useHelpPanel(): UseHelpPanelResult {\n const { isPanelOpen, open, close, toggle, openArticle, openCategory, search, navigate } = usePillarContext();\n\n const openSearch = useCallback(\n (query?: string) => {\n if (query) {\n search(query);\n } else {\n open({ view: 'search' });\n }\n },\n [search, open]\n );\n\n const openChat = useCallback(() => {\n navigate('chat');\n }, [navigate]);\n\n return {\n isOpen: isPanelOpen,\n open,\n close,\n toggle,\n openArticle,\n openCategory,\n openSearch,\n openChat,\n };\n}\n\n","/**\n * usePillar Hook\n * Access Pillar SDK instance and state with optional type-safe onTask\n */\n\nimport type {\n SyncActionDefinitions,\n ActionDefinitions,\n ActionDataType,\n ActionNames,\n} from '@pillar-ai/sdk';\nimport { useCallback } from 'react';\nimport { usePillarContext, type PillarContextValue } from '../PillarProvider';\n\nexport type UsePillarResult = PillarContextValue;\n\n/**\n * Extended result with type-safe onTask method.\n *\n * @template TActions - The action definitions for type inference\n */\nexport interface TypedUsePillarResult<\n TActions extends SyncActionDefinitions | ActionDefinitions,\n> extends Omit<PillarContextValue, 'pillar'> {\n pillar: PillarContextValue['pillar'];\n /**\n * Type-safe task handler registration.\n *\n * @param taskName - The action name (autocompleted from your actions)\n * @param handler - Handler function with typed data parameter\n * @returns Unsubscribe function\n */\n onTask: <TName extends ActionNames<TActions>>(\n taskName: TName,\n handler: (data: ActionDataType<TActions, TName>) => void\n ) => () => void;\n}\n\n/**\n * Hook to access the Pillar SDK instance and state\n *\n * @example Basic usage (untyped)\n * ```tsx\n * function MyComponent() {\n * const { isReady, open, close, isPanelOpen } = usePillar();\n *\n * if (!isReady) return <div>Loading...</div>;\n *\n * return (\n * <button onClick={() => open()}>\n * {isPanelOpen ? 'Close Help' : 'Get Help'}\n * </button>\n * );\n * }\n * ```\n *\n * @example Type-safe onTask with action definitions\n * ```tsx\n * import { actions } from '@/lib/pillar/actions';\n *\n * function MyComponent() {\n * const { pillar, onTask } = usePillar<typeof actions>();\n *\n * useEffect(() => {\n * // TypeScript knows data has { type, url, name }\n * const unsub = onTask('add_new_source', (data) => {\n * console.log(data.url); // ✓ Typed!\n * });\n * return unsub;\n * }, [onTask]);\n * }\n * ```\n */\nexport function usePillar<\n TActions extends SyncActionDefinitions | ActionDefinitions = SyncActionDefinitions,\n>(): TypedUsePillarResult<TActions> {\n const context = usePillarContext();\n\n // Create a type-safe wrapper around pillar.onTask\n const onTask = useCallback(\n <TName extends ActionNames<TActions>>(\n taskName: TName,\n handler: (data: ActionDataType<TActions, TName>) => void\n ): (() => void) => {\n if (!context.pillar) {\n // Return no-op if pillar not ready\n return () => {};\n }\n // Cast handler to match the SDK's expected type\n // The runtime behavior is the same, this is just for type narrowing\n return context.pillar.onTask(\n taskName as string,\n handler as (data: Record<string, unknown>) => void\n );\n },\n [context.pillar]\n );\n\n return {\n ...context,\n onTask,\n };\n}\n\n"],"names":["_jsx"],"mappings":";;;;;AA0KA;AACA;AACA;AAEA,MAAM,aAAa,GAAG,aAAa,CAA4B,IAAI,CAAC;AAEpE;AACA;AACA;AAEM,SAAU,cAAc,CAAC,EAC7B,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,QAAQ,GACY,EAAA;IACpB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC;IACzD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAc,eAAe,CAAC;IAChE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;;AAGrD,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;AAChC,IAAA,SAAS,CAAC,OAAO,GAAG,MAAM;;AAG1B,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC;AAC9B,IAAA,QAAQ,CAAC,OAAO,GAAG,KAAK;;IAGxB,SAAS,CAAC,MAAK;QACb,IAAI,OAAO,GAAG,IAAI;AAElB,QAAA,MAAM,UAAU,GAAG,YAAW;AAC5B,YAAA,IAAI;;AAEF,gBAAA,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,EAAE;gBAC7C,IAAI,gBAAgB,EAAE;;oBAEpB,IAAI,OAAO,EAAE;wBACX,SAAS,CAAC,gBAAgB,CAAC;AAC3B,wBAAA,QAAQ,CAAC,gBAAgB,CAAC,KAAK,CAAC;;AAGhC,wBAAA,gBAAgB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAK;4BACrC,cAAc,CAAC,IAAI,CAAC;AACtB,wBAAA,CAAC,CAAC;AAEF,wBAAA,gBAAgB,CAAC,EAAE,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AAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,gBAAgB,EAAE;AAE5G,IAAA,MAAM,UAAU,GAAG,WAAW,CAC5B,CAAC,KAAc,KAAI;QACjB,IAAI,KAAK,EAAE;YACT,MAAM,CAAC,KAAK,CAAC;QACf;aAAO;AACL,YAAA,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC1B;AACF,IAAA,CAAC,EACD,CAAC,MAAM,EAAE,IAAI,CAAC,CACf;AAED,IAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAK;QAChC,QAAQ,CAAC,MAAM,CAAC;AAClB,IAAA,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEd,OAAO;AACL,QAAA,MAAM,EAAE,WAAW;QACnB,IAAI;QACJ,KAAK;QACL,MAAM;QACN,WAAW;QACX,YAAY;QACZ,UAAU;QACV,QAAQ;KACT;AACH;;ACnFA;;;AAGG;AAmCH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;SACa,SAAS,GAAA;AAGvB,IAAA,MAAM,OAAO,GAAG,gBAAgB,EAAE;;IAGlC,MAAM,MAAM,GAAG,WAAW,CACxB,CACE,QAAe,EACf,OAAwD,KACxC;AAChB,QAAA,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;;AAEnB,YAAA,OAAO,MAAK,EAAE,CAAC;QACjB;;;QAGA,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAC1B,QAAkB,EAClB,OAAkD,CACnD;AACH,IAAA,CAAC,EACD,CAAC,OAAO,CAAC,MAAM,CAAC,CACjB;IAED,OAAO;AACL,QAAA,GAAG,OAAO;QACV,MAAM;KACP;AACH;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/PillarProvider.tsx","../src/PillarPanel.tsx","../src/hooks/useHelpPanel.ts","../src/hooks/usePillar.ts","../src/hooks/usePillarTool.ts"],"sourcesContent":["/**\n * PillarProvider\n * Context provider that initializes and manages the Pillar SDK\n */\n\nimport {\n Pillar,\n scanPageDirect,\n type CardCallbacks,\n type CompactScanResult,\n type PillarConfig,\n type PillarEvents,\n type PillarState,\n type ScanOptions,\n type TaskExecutePayload,\n type ThemeConfig,\n} from \"@pillar-ai/sdk\";\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ComponentType,\n type ReactNode,\n} from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\n\n// ============================================================================\n// Card Types\n// ============================================================================\n\n/**\n * Props passed to custom card components.\n */\nexport interface CardComponentProps<T = Record<string, unknown>> {\n /** Data extracted by the AI for this action */\n data: T;\n /** Called when user confirms the action */\n onConfirm: (modifiedData?: Record<string, unknown>) => void;\n /** Called when user cancels the action */\n onCancel: () => void;\n /** Called to report state changes (loading, success, error) */\n onStateChange?: (\n state: \"loading\" | \"success\" | \"error\",\n message?: string\n ) => void;\n}\n\n/**\n * A React component that can be used as a custom card renderer.\n */\nexport type CardComponent<T = Record<string, unknown>> = ComponentType<\n CardComponentProps<T>\n>;\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface PillarContextValue {\n /** The Pillar SDK instance */\n pillar: Pillar | null;\n\n /** Current SDK state */\n state: PillarState;\n\n /** Whether the SDK is ready */\n isReady: boolean;\n\n /** Whether the panel is currently open */\n isPanelOpen: boolean;\n\n /** Open the help panel */\n open: (options?: {\n view?: string;\n article?: string;\n search?: string;\n focusInput?: boolean;\n }) => void;\n\n /** Close the help panel */\n close: () => void;\n\n /** Toggle the help panel */\n toggle: () => void;\n\n /** Open a specific article */\n openArticle: (slug: string) => void;\n\n /** Open a specific category */\n openCategory: (slug: string) => Promise<void>;\n\n /** Perform a search */\n search: (query: string) => void;\n\n /** Navigate to a specific view */\n navigate: (view: string, params?: Record<string, string>) => void;\n\n /** Update the panel theme at runtime */\n setTheme: (theme: Partial<ThemeConfig>) => void;\n\n /** Enable or disable the text selection \"Ask AI\" popover */\n setTextSelectionEnabled: (enabled: boolean) => void;\n\n /**\n * Enable or disable DOM scanning.\n * @deprecated DOM scanning is currently disabled and this method has no effect.\n */\n setDOMScanningEnabled: (enabled: boolean) => void;\n\n /**\n * Whether DOM scanning is enabled.\n * @deprecated Always returns false - DOM scanning is disabled.\n */\n isDOMScanningEnabled: boolean;\n\n /** Manually scan the page and get the compact result */\n scanPage: (options?: ScanOptions) => CompactScanResult | null;\n\n /** Subscribe to SDK events */\n on: <K extends keyof PillarEvents>(\n event: K,\n callback: (data: PillarEvents[K]) => void\n ) => () => void;\n}\n\nexport interface PillarProviderProps {\n /**\n * Your product key from the Pillar app.\n * Get it at app.trypillar.com\n */\n productKey?: string;\n\n /**\n * @deprecated Use `productKey` instead. Will be removed in v1.0.\n */\n helpCenter?: string;\n\n /**\n * Additional SDK configuration\n *\n * Notable options:\n * - `panel.useShadowDOM`: Whether to isolate styles in Shadow DOM (default: false).\n * Set to false to let custom cards inherit your app's CSS (Tailwind, etc.)\n */\n config?: Omit<PillarConfig, \"productKey\" | \"helpCenter\">;\n\n /**\n * Handler called when a task action is triggered from the chat.\n * Use this to handle AI-suggested actions like opening modals, navigating, etc.\n *\n * @example\n * ```tsx\n * <PillarProvider\n * productKey=\"my-product-key\"\n * onTask={(task) => {\n * switch (task.name) {\n * case 'invite_team_member':\n * openInviteModal(task.data);\n * break;\n * case 'open_settings':\n * router.push('/settings');\n * break;\n * }\n * }}\n * >\n * ```\n */\n onTask?: (task: TaskExecutePayload) => void;\n\n /**\n * Custom card components to render for inline_ui type actions.\n * Map card type names to React components that will render the inline UI.\n *\n * @example\n * ```tsx\n * import { InviteMembersCard } from './cards/InviteMembersCard';\n *\n * <PillarProvider\n * productKey=\"my-product-key\"\n * cards={{\n * invite_members: InviteMembersCard,\n * confirm_delete: ConfirmDeleteCard,\n * }}\n * >\n * ```\n */\n cards?: Record<string, CardComponent>;\n\n /**\n * Enable DOM scanning to send page context with messages.\n * @deprecated DOM scanning is currently disabled. This prop has no effect.\n */\n domScanning?: boolean;\n\n /**\n * Enable DOM scanning dev mode to preview the scanned page before sending.\n * Shows a modal with the AST tree visualization before each message is sent.\n * Useful for debugging what context will be sent to the LLM.\n /** Children components */\n children: ReactNode;\n}\n\n// ============================================================================\n// Context\n// ============================================================================\n\nconst PillarContext = createContext<PillarContextValue | null>(null);\n\n// ============================================================================\n// Provider Component\n// ============================================================================\n\nexport function PillarProvider({\n productKey,\n helpCenter,\n config,\n onTask,\n cards,\n domScanning: _domScanning, // Deprecated - DOM scanning is disabled\n children,\n}: PillarProviderProps): React.ReactElement {\n const [pillar, setPillar] = useState<Pillar | null>(null);\n const [state, setState] = useState<PillarState>(\"uninitialized\");\n const [isPanelOpen, setIsPanelOpen] = useState(false);\n // DOM scanning is disabled - always false\n const isDOMScanningEnabled = false;\n\n // Support both productKey (new) and helpCenter (deprecated)\n const resolvedKey = productKey ?? helpCenter;\n\n // Keep a ref to the latest onTask callback to avoid re-subscribing\n const onTaskRef = useRef(onTask);\n onTaskRef.current = onTask;\n\n // Warn about deprecated helpCenter usage\n useEffect(() => {\n if (helpCenter && !productKey) {\n console.warn(\n '[Pillar React] \"helpCenter\" prop is deprecated. Use \"productKey\" instead.'\n );\n }\n }, []);\n\n // Keep a ref to cards to access latest versions\n const cardsRef = useRef(cards);\n cardsRef.current = cards;\n\n // Initialize SDK\n useEffect(() => {\n let mounted = true;\n\n const initPillar = async () => {\n try {\n // Pillar is a singleton - check if already initialized\n const existingInstance = Pillar.getInstance();\n if (existingInstance) {\n // Reuse existing instance (preserves chat history, panel state, etc.)\n if (mounted) {\n setPillar(existingInstance);\n setState(existingInstance.state);\n\n // Re-subscribe to events\n existingInstance.on(\"panel:open\", () => {\n setIsPanelOpen(true);\n });\n\n existingInstance.on(\"panel:close\", () => {\n setIsPanelOpen(false);\n });\n }\n return;\n }\n\n // Initialize new instance\n // Note: DOM scanning is disabled, config.domScanning is ignored\n const instance = await Pillar.init({\n productKey: resolvedKey,\n ...config,\n });\n\n if (mounted) {\n setPillar(instance);\n setState(instance.state);\n\n // Listen for panel open/close\n instance.on(\"panel:open\", () => {\n setIsPanelOpen(true);\n });\n\n instance.on(\"panel:close\", () => {\n setIsPanelOpen(false);\n });\n }\n } catch (error) {\n console.error(\"[Pillar React] Failed to initialize:\", error);\n if (mounted) {\n setState(\"error\");\n }\n }\n };\n\n initPillar();\n\n // Cleanup - DON'T destroy the singleton on unmount\n // This preserves conversation history and panel state across navigation\n // Pillar.destroy() should only be called explicitly when the app unmounts completely\n return () => {\n mounted = false;\n // Note: We intentionally don't call Pillar.destroy() here\n // The singleton persists to maintain state across route changes\n };\n }, [resolvedKey]); // Re-initialize if productKey changes\n\n // Update state when SDK state changes\n useEffect(() => {\n if (pillar) {\n const unsubscribe = pillar.on(\"ready\", () => {\n setState(\"ready\");\n });\n\n const unsubscribeError = pillar.on(\"error\", () => {\n setState(\"error\");\n });\n\n return () => {\n unsubscribe();\n unsubscribeError();\n };\n }\n }, [pillar]);\n\n // Register task handler\n useEffect(() => {\n if (pillar) {\n const unsubscribe = pillar.on(\"task:execute\", (task) => {\n onTaskRef.current?.(task);\n });\n\n return unsubscribe;\n }\n }, [pillar]);\n\n // DOM scanning is disabled - no sync needed\n\n // Register custom card renderers\n useEffect(() => {\n if (!pillar || !cards) return;\n\n const unsubscribers: Array<() => void> = [];\n const roots: Map<HTMLElement, Root> = new Map();\n\n // Register each card component as a vanilla renderer\n Object.entries(cards).forEach(([cardType, Component]) => {\n const unsubscribe = pillar.registerCard(\n cardType,\n (container, data, callbacks: CardCallbacks) => {\n // Create a React root for this container\n const root = createRoot(container);\n roots.set(container, root);\n\n // Render the React component\n root.render(\n <Component\n data={data}\n onConfirm={callbacks.onConfirm}\n onCancel={callbacks.onCancel}\n onStateChange={callbacks.onStateChange}\n />\n );\n\n // Return cleanup function\n return () => {\n const existingRoot = roots.get(container);\n if (existingRoot) {\n existingRoot.unmount();\n roots.delete(container);\n }\n };\n }\n );\n\n unsubscribers.push(unsubscribe);\n });\n\n return () => {\n // Cleanup all registrations\n unsubscribers.forEach((unsub) => unsub());\n // Unmount all React roots\n roots.forEach((root) => root.unmount());\n roots.clear();\n };\n }, [pillar, cards]);\n\n // Actions\n const open = useCallback(\n (options?: {\n view?: string;\n article?: string;\n search?: string;\n focusInput?: boolean;\n }) => {\n pillar?.open(options);\n },\n [pillar]\n );\n\n const close = useCallback(() => {\n pillar?.close();\n }, [pillar]);\n\n const toggle = useCallback(() => {\n pillar?.toggle();\n }, [pillar]);\n\n const openArticle = useCallback(\n (slug: string) => {\n pillar?.open({ article: slug });\n },\n [pillar]\n );\n\n const openCategory = useCallback(\n async (slug: string) => {\n pillar?.navigate(\"category\", { slug });\n },\n [pillar]\n );\n\n const search = useCallback(\n (query: string) => {\n pillar?.open({ search: query });\n },\n [pillar]\n );\n\n const navigate = useCallback(\n (view: string, params?: Record<string, string>) => {\n pillar?.navigate(view, params);\n },\n [pillar]\n );\n\n const setTheme = useCallback(\n (theme: Partial<ThemeConfig>) => {\n pillar?.setTheme(theme);\n },\n [pillar]\n );\n\n const setTextSelectionEnabled = useCallback(\n (enabled: boolean) => {\n pillar?.setTextSelectionEnabled(enabled);\n },\n [pillar]\n );\n\n // DOM scanning is disabled - this is a no-op\n const setDOMScanningEnabled = useCallback(\n (_enabled: boolean) => {\n // DOM scanning is disabled - this method has no effect\n },\n []\n );\n\n const scanPage = useCallback(\n (options?: ScanOptions): CompactScanResult | null => {\n if (!pillar) return null;\n return scanPageDirect(options);\n },\n [pillar]\n );\n\n const on = useCallback(\n <K extends keyof PillarEvents>(\n event: K,\n callback: (data: PillarEvents[K]) => void\n ) => {\n return pillar?.on(event, callback) ?? (() => {});\n },\n [pillar]\n );\n\n // Context value\n const value = useMemo<PillarContextValue>(\n () => ({\n pillar,\n state,\n isReady: state === \"ready\",\n isPanelOpen,\n open,\n close,\n toggle,\n openArticle,\n openCategory,\n search,\n navigate,\n setTheme,\n setTextSelectionEnabled,\n setDOMScanningEnabled,\n isDOMScanningEnabled,\n scanPage,\n on,\n }),\n [\n pillar,\n state,\n isPanelOpen,\n open,\n close,\n toggle,\n openArticle,\n openCategory,\n search,\n navigate,\n setTheme,\n setTextSelectionEnabled,\n setDOMScanningEnabled,\n isDOMScanningEnabled,\n scanPage,\n on,\n ]\n );\n\n return (\n <PillarContext.Provider value={value}>{children}</PillarContext.Provider>\n );\n}\n\n// ============================================================================\n// Hook\n// ============================================================================\n\nexport function usePillarContext(): PillarContextValue {\n const context = useContext(PillarContext);\n\n if (!context) {\n throw new Error(\"usePillarContext must be used within a PillarProvider\");\n }\n\n return context;\n}\n","/**\n * PillarPanel Component\n * Renders the Pillar help panel at a custom location in the DOM\n */\n\nimport React, { useRef, useEffect, type CSSProperties, type HTMLAttributes } from 'react';\nimport { usePillarContext } from './PillarProvider';\n\nexport interface PillarPanelProps extends HTMLAttributes<HTMLDivElement> {\n /** Custom class name for the container */\n className?: string;\n \n /** Custom inline styles for the container */\n style?: CSSProperties;\n}\n\n/**\n * Renders the Pillar help panel at a custom location in the DOM.\n * Use this when you want to control where the panel is rendered instead of\n * having it automatically appended to document.body.\n * \n * **Important**: When using this component, set `panel.container: 'manual'` in your\n * PillarProvider config to prevent automatic mounting.\n * \n * @example\n * ```tsx\n * <PillarProvider \n * productKey=\"my-product-key\"\n * config={{ panel: { container: 'manual' } }}\n * >\n * <div className=\"my-layout\">\n * <Sidebar />\n * <PillarPanel className=\"help-panel-container\" />\n * <MainContent />\n * </div>\n * </PillarProvider>\n * ```\n */\nexport function PillarPanel({ \n className, \n style,\n ...props \n}: PillarPanelProps): React.ReactElement {\n const containerRef = useRef<HTMLDivElement>(null);\n const { pillar, isReady } = usePillarContext();\n const hasMounted = useRef(false);\n\n useEffect(() => {\n // Only mount once when SDK is ready and we have a container\n if (!isReady || !pillar || !containerRef.current || hasMounted.current) {\n return;\n }\n\n // Mount the panel into our container\n pillar.mountPanelTo(containerRef.current);\n hasMounted.current = true;\n\n // Cleanup is handled by Pillar.destroy() in the provider\n }, [isReady, pillar]);\n\n return (\n <div \n ref={containerRef} \n className={className}\n style={style}\n data-pillar-panel-container=\"\"\n {...props}\n />\n );\n}\n\n","/**\n * useHelpPanel Hook\n * Panel-specific controls and state\n */\n\nimport { useCallback } from 'react';\nimport { usePillarContext } from '../PillarProvider';\n\nexport interface UseHelpPanelResult {\n /** Whether the panel is currently open */\n isOpen: boolean;\n \n /** Open the panel */\n open: (options?: { view?: string; article?: string; search?: string }) => void;\n \n /** Close the panel */\n close: () => void;\n \n /** Toggle the panel */\n toggle: () => void;\n \n /** Open a specific article in the panel */\n openArticle: (slug: string) => void;\n \n /** Open a specific category in the panel */\n openCategory: (slug: string) => Promise<void>;\n \n /** Open search with a query */\n openSearch: (query?: string) => void;\n \n /** Open the AI chat */\n openChat: () => void;\n}\n\n/**\n * Hook for panel-specific controls\n * \n * @example\n * ```tsx\n * function HelpButton() {\n * const { isOpen, toggle, openChat } = useHelpPanel();\n * \n * return (\n * <div>\n * <button onClick={toggle}>\n * {isOpen ? 'Close' : 'Help'}\n * </button>\n * <button onClick={openChat}>\n * Ask AI\n * </button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useHelpPanel(): UseHelpPanelResult {\n const { isPanelOpen, open, close, toggle, openArticle, openCategory, search, navigate } = usePillarContext();\n\n const openSearch = useCallback(\n (query?: string) => {\n if (query) {\n search(query);\n } else {\n open({ view: 'search' });\n }\n },\n [search, open]\n );\n\n const openChat = useCallback(() => {\n navigate('chat');\n }, [navigate]);\n\n return {\n isOpen: isPanelOpen,\n open,\n close,\n toggle,\n openArticle,\n openCategory,\n openSearch,\n openChat,\n };\n}\n\n","/**\n * usePillar Hook\n * Access Pillar SDK instance and state with optional type-safe onTask\n */\n\nimport type {\n SyncActionDefinitions,\n ActionDefinitions,\n ActionDataType,\n ActionNames,\n} from '@pillar-ai/sdk';\nimport { useCallback } from 'react';\nimport { usePillarContext, type PillarContextValue } from '../PillarProvider';\n\nexport type UsePillarResult = PillarContextValue;\n\n/**\n * Extended result with type-safe onTask method.\n *\n * @template TActions - The action definitions for type inference\n */\nexport interface TypedUsePillarResult<\n TActions extends SyncActionDefinitions | ActionDefinitions,\n> extends Omit<PillarContextValue, 'pillar'> {\n pillar: PillarContextValue['pillar'];\n /**\n * Type-safe task handler registration.\n *\n * @param taskName - The action name (autocompleted from your actions)\n * @param handler - Handler function with typed data parameter\n * @returns Unsubscribe function\n */\n onTask: <TName extends ActionNames<TActions>>(\n taskName: TName,\n handler: (data: ActionDataType<TActions, TName>) => void\n ) => () => void;\n}\n\n/**\n * Hook to access the Pillar SDK instance and state\n *\n * @example Basic usage (untyped)\n * ```tsx\n * function MyComponent() {\n * const { isReady, open, close, isPanelOpen } = usePillar();\n *\n * if (!isReady) return <div>Loading...</div>;\n *\n * return (\n * <button onClick={() => open()}>\n * {isPanelOpen ? 'Close Help' : 'Get Help'}\n * </button>\n * );\n * }\n * ```\n *\n * @example Type-safe onTask with action definitions\n * ```tsx\n * import { actions } from '@/lib/pillar/actions';\n *\n * function MyComponent() {\n * const { pillar, onTask } = usePillar<typeof actions>();\n *\n * useEffect(() => {\n * // TypeScript knows data has { type, url, name }\n * const unsub = onTask('add_new_source', (data) => {\n * console.log(data.url); // ✓ Typed!\n * });\n * return unsub;\n * }, [onTask]);\n * }\n * ```\n */\nexport function usePillar<\n TActions extends SyncActionDefinitions | ActionDefinitions = SyncActionDefinitions,\n>(): TypedUsePillarResult<TActions> {\n const context = usePillarContext();\n\n // Create a type-safe wrapper around pillar.onTask\n const onTask = useCallback(\n <TName extends ActionNames<TActions>>(\n taskName: TName,\n handler: (data: ActionDataType<TActions, TName>) => void\n ): (() => void) => {\n if (!context.pillar) {\n // Return no-op if pillar not ready\n return () => {};\n }\n // Cast handler to match the SDK's expected type\n // The runtime behavior is the same, this is just for type narrowing\n return context.pillar.onTask(\n taskName as string,\n handler as (data: Record<string, unknown>) => void\n );\n },\n [context.pillar]\n );\n\n return {\n ...context,\n onTask,\n };\n}\n\n","/**\n * usePillarTool Hook\n *\n * Register one or more tools with co-located metadata and handlers.\n * Tools are registered on mount and unregistered on unmount.\n *\n * @example Single tool\n * ```tsx\n * import { usePillarTool } from '@pillar-ai/react';\n *\n * function CartButton() {\n * usePillarTool({\n * name: 'add_to_cart',\n * description: 'Add a product to the shopping cart',\n * inputSchema: {\n * type: 'object',\n * properties: {\n * productId: { type: 'string', description: 'Product ID' },\n * quantity: { type: 'number', description: 'Quantity to add' },\n * },\n * required: ['productId', 'quantity'],\n * },\n * execute: async ({ productId, quantity }) => {\n * await cartApi.add(productId, quantity);\n * return { content: [{ type: 'text', text: 'Added to cart' }] };\n * },\n * });\n *\n * return <button>Cart</button>;\n * }\n * ```\n *\n * @example Multiple tools\n * ```tsx\n * import { usePillarTool } from '@pillar-ai/react';\n *\n * function BillingPage() {\n * usePillarTool([\n * {\n * name: 'get_current_plan',\n * description: 'Get the current billing plan',\n * execute: async () => ({ plan: 'pro', price: 29 }),\n * },\n * {\n * name: 'upgrade_plan',\n * description: 'Upgrade to a higher plan',\n * inputSchema: {\n * type: 'object',\n * properties: { planId: { type: 'string' } },\n * required: ['planId'],\n * },\n * execute: async ({ planId }) => {\n * await billingApi.upgrade(planId);\n * return { content: [{ type: 'text', text: 'Upgraded!' }] };\n * },\n * },\n * ]);\n *\n * return <div>Billing Content</div>;\n * }\n * ```\n */\n\nimport { useEffect, useRef, useMemo } from 'react';\nimport type { ToolSchema } from '@pillar-ai/sdk';\nimport { usePillarContext } from '../PillarProvider';\n\n/**\n * Register a single Pillar tool with co-located metadata and handler.\n */\nexport function usePillarTool<TInput = Record<string, unknown>>(\n schema: ToolSchema<TInput>\n): void;\n\n/**\n * Register multiple Pillar tools with co-located metadata and handlers.\n */\nexport function usePillarTool(schemas: ToolSchema[]): void;\n\n/**\n * Register one or more Pillar tools with co-located metadata and handlers.\n *\n * The tools are registered when the component mounts and automatically\n * unregistered when it unmounts. The `execute` functions always capture\n * the latest React state and props via refs, so you don't need to worry\n * about stale closures.\n *\n * @param schemaOrSchemas - Single tool schema or array of tool schemas\n */\nexport function usePillarTool<TInput = Record<string, unknown>>(\n schemaOrSchemas: ToolSchema<TInput> | ToolSchema[]\n): void {\n const { pillar } = usePillarContext();\n\n // Normalize to array for consistent handling\n const schemas = useMemo(\n () => (Array.isArray(schemaOrSchemas) ? schemaOrSchemas : [schemaOrSchemas]),\n [schemaOrSchemas]\n );\n\n // Keep refs to latest schemas so handlers capture current state/props\n const schemasRef = useRef(schemas);\n schemasRef.current = schemas;\n\n // Stable dependency key for the effect (tool names joined)\n const toolNamesKey = useMemo(\n () => schemas.map((s) => s.name).join(','),\n [schemas]\n );\n\n useEffect(() => {\n if (!pillar) return;\n\n // Register all tools and collect unsubscribe functions\n const unsubscribes = schemasRef.current.map((schema, index) => {\n return pillar.defineTool({\n ...schema,\n // Wrap execute to always use the latest ref version\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n execute: (input: any) => schemasRef.current[index].execute(input),\n } as ToolSchema);\n });\n\n // Cleanup: unregister all tools\n return () => {\n unsubscribes.forEach((unsub) => unsub());\n };\n }, [pillar, toolNamesKey]);\n}\n\n/** @deprecated Use usePillarTool instead */\nexport const usePillarAction = usePillarTool;\n"],"names":["_jsx"],"mappings":";;;;;AA8MA;AACA;AACA;AAEA,MAAM,aAAa,GAAG,aAAa,CAA4B,IAAI,CAAC;AAEpE;AACA;AACA;SAEgB,cAAc,CAAC,EAC7B,UAAU,EACV,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,WAAW,EAAE,YAAY;AACzB,QAAQ,GACY,EAAA;IACpB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC;IACzD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAc,eAAe,CAAC;IAChE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;;IAErD,MAAM,oBAAo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================================================
13
13
  // Provider Component
14
14
  // ============================================================================
15
- function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
15
+ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScanning: _domScanning, // Deprecated - DOM scanning is disabled
16
+ children, }) {
16
17
  const [pillar, setPillar] = react.useState(null);
17
18
  const [state, setState] = react.useState("uninitialized");
18
19
  const [isPanelOpen, setIsPanelOpen] = react.useState(false);
20
+ // DOM scanning is disabled - always false
21
+ const isDOMScanningEnabled = false;
22
+ // Support both productKey (new) and helpCenter (deprecated)
23
+ const resolvedKey = productKey ?? helpCenter;
19
24
  // Keep a ref to the latest onTask callback to avoid re-subscribing
20
25
  const onTaskRef = react.useRef(onTask);
21
26
  onTaskRef.current = onTask;
27
+ // Warn about deprecated helpCenter usage
28
+ react.useEffect(() => {
29
+ if (helpCenter && !productKey) {
30
+ console.warn('[Pillar React] "helpCenter" prop is deprecated. Use "productKey" instead.');
31
+ }
32
+ }, []);
22
33
  // Keep a ref to cards to access latest versions
23
34
  const cardsRef = react.useRef(cards);
24
35
  cardsRef.current = cards;
@@ -45,8 +56,9 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
45
56
  return;
46
57
  }
47
58
  // Initialize new instance
59
+ // Note: DOM scanning is disabled, config.domScanning is ignored
48
60
  const instance = await sdk.Pillar.init({
49
- helpCenter,
61
+ productKey: resolvedKey,
50
62
  ...config,
51
63
  });
52
64
  if (mounted) {
@@ -77,7 +89,7 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
77
89
  // Note: We intentionally don't call Pillar.destroy() here
78
90
  // The singleton persists to maintain state across route changes
79
91
  };
80
- }, [helpCenter]); // Re-initialize if helpCenter changes
92
+ }, [resolvedKey]); // Re-initialize if productKey changes
81
93
  // Update state when SDK state changes
82
94
  react.useEffect(() => {
83
95
  if (pillar) {
@@ -102,6 +114,7 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
102
114
  return unsubscribe;
103
115
  }
104
116
  }, [pillar]);
117
+ // DOM scanning is disabled - no sync needed
105
118
  // Register custom card renderers
106
119
  react.useEffect(() => {
107
120
  if (!pillar || !cards)
@@ -163,6 +176,15 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
163
176
  const setTextSelectionEnabled = react.useCallback((enabled) => {
164
177
  pillar?.setTextSelectionEnabled(enabled);
165
178
  }, [pillar]);
179
+ // DOM scanning is disabled - this is a no-op
180
+ const setDOMScanningEnabled = react.useCallback((_enabled) => {
181
+ // DOM scanning is disabled - this method has no effect
182
+ }, []);
183
+ const scanPage = react.useCallback((options) => {
184
+ if (!pillar)
185
+ return null;
186
+ return sdk.scanPageDirect(options);
187
+ }, [pillar]);
166
188
  const on = react.useCallback((event, callback) => {
167
189
  return pillar?.on(event, callback) ?? (() => { });
168
190
  }, [pillar]);
@@ -181,6 +203,9 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
181
203
  navigate,
182
204
  setTheme,
183
205
  setTextSelectionEnabled,
206
+ setDOMScanningEnabled,
207
+ isDOMScanningEnabled,
208
+ scanPage,
184
209
  on,
185
210
  }), [
186
211
  pillar,
@@ -195,6 +220,9 @@ function PillarProvider({ helpCenter, config, onTask, cards, children, }) {
195
220
  navigate,
196
221
  setTheme,
197
222
  setTextSelectionEnabled,
223
+ setDOMScanningEnabled,
224
+ isDOMScanningEnabled,
225
+ scanPage,
198
226
  on,
199
227
  ]);
200
228
  return (jsxRuntime.jsx(PillarContext.Provider, { value: value, children: children }));
@@ -221,8 +249,7 @@ function usePillarContext() {
221
249
  * @example
222
250
  * ```tsx
223
251
  * <PillarProvider
224
- * helpCenter="my-help"
225
- * publicKey="pk_xxx"
252
+ * productKey="my-product-key"
226
253
  * config={{ panel: { container: 'manual' } }}
227
254
  * >
228
255
  * <div className="my-layout">
@@ -357,9 +384,113 @@ function usePillar() {
357
384
  };
358
385
  }
359
386
 
387
+ /**
388
+ * usePillarTool Hook
389
+ *
390
+ * Register one or more tools with co-located metadata and handlers.
391
+ * Tools are registered on mount and unregistered on unmount.
392
+ *
393
+ * @example Single tool
394
+ * ```tsx
395
+ * import { usePillarTool } from '@pillar-ai/react';
396
+ *
397
+ * function CartButton() {
398
+ * usePillarTool({
399
+ * name: 'add_to_cart',
400
+ * description: 'Add a product to the shopping cart',
401
+ * inputSchema: {
402
+ * type: 'object',
403
+ * properties: {
404
+ * productId: { type: 'string', description: 'Product ID' },
405
+ * quantity: { type: 'number', description: 'Quantity to add' },
406
+ * },
407
+ * required: ['productId', 'quantity'],
408
+ * },
409
+ * execute: async ({ productId, quantity }) => {
410
+ * await cartApi.add(productId, quantity);
411
+ * return { content: [{ type: 'text', text: 'Added to cart' }] };
412
+ * },
413
+ * });
414
+ *
415
+ * return <button>Cart</button>;
416
+ * }
417
+ * ```
418
+ *
419
+ * @example Multiple tools
420
+ * ```tsx
421
+ * import { usePillarTool } from '@pillar-ai/react';
422
+ *
423
+ * function BillingPage() {
424
+ * usePillarTool([
425
+ * {
426
+ * name: 'get_current_plan',
427
+ * description: 'Get the current billing plan',
428
+ * execute: async () => ({ plan: 'pro', price: 29 }),
429
+ * },
430
+ * {
431
+ * name: 'upgrade_plan',
432
+ * description: 'Upgrade to a higher plan',
433
+ * inputSchema: {
434
+ * type: 'object',
435
+ * properties: { planId: { type: 'string' } },
436
+ * required: ['planId'],
437
+ * },
438
+ * execute: async ({ planId }) => {
439
+ * await billingApi.upgrade(planId);
440
+ * return { content: [{ type: 'text', text: 'Upgraded!' }] };
441
+ * },
442
+ * },
443
+ * ]);
444
+ *
445
+ * return <div>Billing Content</div>;
446
+ * }
447
+ * ```
448
+ */
449
+ /**
450
+ * Register one or more Pillar tools with co-located metadata and handlers.
451
+ *
452
+ * The tools are registered when the component mounts and automatically
453
+ * unregistered when it unmounts. The `execute` functions always capture
454
+ * the latest React state and props via refs, so you don't need to worry
455
+ * about stale closures.
456
+ *
457
+ * @param schemaOrSchemas - Single tool schema or array of tool schemas
458
+ */
459
+ function usePillarTool(schemaOrSchemas) {
460
+ const { pillar } = usePillarContext();
461
+ // Normalize to array for consistent handling
462
+ const schemas = react.useMemo(() => (Array.isArray(schemaOrSchemas) ? schemaOrSchemas : [schemaOrSchemas]), [schemaOrSchemas]);
463
+ // Keep refs to latest schemas so handlers capture current state/props
464
+ const schemasRef = react.useRef(schemas);
465
+ schemasRef.current = schemas;
466
+ // Stable dependency key for the effect (tool names joined)
467
+ const toolNamesKey = react.useMemo(() => schemas.map((s) => s.name).join(','), [schemas]);
468
+ react.useEffect(() => {
469
+ if (!pillar)
470
+ return;
471
+ // Register all tools and collect unsubscribe functions
472
+ const unsubscribes = schemasRef.current.map((schema, index) => {
473
+ return pillar.defineTool({
474
+ ...schema,
475
+ // Wrap execute to always use the latest ref version
476
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
477
+ execute: (input) => schemasRef.current[index].execute(input),
478
+ });
479
+ });
480
+ // Cleanup: unregister all tools
481
+ return () => {
482
+ unsubscribes.forEach((unsub) => unsub());
483
+ };
484
+ }, [pillar, toolNamesKey]);
485
+ }
486
+ /** @deprecated Use usePillarTool instead */
487
+ const usePillarAction = usePillarTool;
488
+
360
489
  exports.PillarPanel = PillarPanel;
361
490
  exports.PillarProvider = PillarProvider;
362
491
  exports.useHelpPanel = useHelpPanel;
363
492
  exports.usePillar = usePillar;
493
+ exports.usePillarAction = usePillarAction;
364
494
  exports.usePillarContext = usePillarContext;
495
+ exports.usePillarTool = usePillarTool;
365
496
  //# sourceMappingURL=index.js.map