@pillar-ai/react 0.1.11 → 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/PillarProvider.d.ts +11 -5
- package/dist/index.d.ts +13 -1
- package/dist/index.esm.js +10 -24
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +10 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/PillarProvider.d.ts
CHANGED
|
@@ -53,9 +53,15 @@ export interface PillarContextValue {
|
|
|
53
53
|
setTheme: (theme: Partial<ThemeConfig>) => void;
|
|
54
54
|
/** Enable or disable the text selection "Ask AI" popover */
|
|
55
55
|
setTextSelectionEnabled: (enabled: boolean) => void;
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Enable or disable DOM scanning.
|
|
58
|
+
* @deprecated DOM scanning is currently disabled and this method has no effect.
|
|
59
|
+
*/
|
|
57
60
|
setDOMScanningEnabled: (enabled: boolean) => void;
|
|
58
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Whether DOM scanning is enabled.
|
|
63
|
+
* @deprecated Always returns false - DOM scanning is disabled.
|
|
64
|
+
*/
|
|
59
65
|
isDOMScanningEnabled: boolean;
|
|
60
66
|
/** Manually scan the page and get the compact result */
|
|
61
67
|
scanPage: (options?: ScanOptions) => CompactScanResult | null;
|
|
@@ -122,8 +128,7 @@ export interface PillarProviderProps {
|
|
|
122
128
|
cards?: Record<string, CardComponent>;
|
|
123
129
|
/**
|
|
124
130
|
* Enable DOM scanning to send page context with messages.
|
|
125
|
-
*
|
|
126
|
-
* @default false
|
|
131
|
+
* @deprecated DOM scanning is currently disabled. This prop has no effect.
|
|
127
132
|
*/
|
|
128
133
|
domScanning?: boolean;
|
|
129
134
|
/**
|
|
@@ -133,5 +138,6 @@ export interface PillarProviderProps {
|
|
|
133
138
|
/** Children components */
|
|
134
139
|
children: ReactNode;
|
|
135
140
|
}
|
|
136
|
-
export declare function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScanning
|
|
141
|
+
export declare function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScanning: _domScanning, // Deprecated - DOM scanning is disabled
|
|
142
|
+
children, }: PillarProviderProps): React.ReactElement;
|
|
137
143
|
export declare function usePillarContext(): PillarContextValue;
|
package/dist/index.d.ts
CHANGED
|
@@ -46,4 +46,16 @@ export { PillarPanel, type PillarPanelProps } from './PillarPanel';
|
|
|
46
46
|
export { useHelpPanel, type UseHelpPanelResult } from './hooks/useHelpPanel';
|
|
47
47
|
export { usePillar, type UsePillarResult, type TypedUsePillarResult } from './hooks/usePillar';
|
|
48
48
|
export { usePillarTool, usePillarAction } from './hooks/usePillarTool';
|
|
49
|
-
export type { EdgeTriggerConfig, MobileTriggerConfig, MobileTriggerPosition, MobileTriggerIcon, MobileTriggerSize, PanelConfig, PillarConfig, PillarEvents, PillarState, ResolvedConfig, ResolvedMobileTriggerConfig, ResolvedThemeConfig, TaskExecutePayload, TextSelectionConfig, ThemeColors, ThemeConfig, ThemeMode, CardCallbacks, CardRenderer, SidebarTabConfig, ToolDefinitions, SyncToolDefinitions, ToolDataType, ToolNames, ToolExecuteResult, ToolSchema, ToolType, ActionDefinitions, SyncActionDefinitions, ActionDataType, ActionNames, ActionResult, ActionSchema, ActionType, ChatContext,
|
|
49
|
+
export type { EdgeTriggerConfig, MobileTriggerConfig, MobileTriggerPosition, MobileTriggerIcon, MobileTriggerSize, PanelConfig, PillarConfig, PillarEvents, PillarState, ResolvedConfig, ResolvedMobileTriggerConfig, ResolvedThemeConfig, TaskExecutePayload, TextSelectionConfig, ThemeColors, ThemeConfig, ThemeMode, CardCallbacks, CardRenderer, SidebarTabConfig, ToolDefinitions, SyncToolDefinitions, ToolDataType, ToolNames, ToolExecuteResult, ToolSchema, ToolType, ActionDefinitions, SyncActionDefinitions, ActionDataType, ActionNames, ActionResult, ActionSchema, ActionType, ChatContext,
|
|
50
|
+
/** @deprecated DOM scanning is disabled */
|
|
51
|
+
DOMScanningConfig,
|
|
52
|
+
/** @deprecated DOM scanning is disabled */
|
|
53
|
+
ResolvedDOMScanningConfig,
|
|
54
|
+
/** @deprecated DOM scanning is disabled */
|
|
55
|
+
ScanOptions,
|
|
56
|
+
/** @deprecated DOM scanning is disabled */
|
|
57
|
+
CompactScanResult,
|
|
58
|
+
/** @deprecated DOM scanning is disabled */
|
|
59
|
+
InteractionType,
|
|
60
|
+
/** @deprecated DOM scanning is disabled */
|
|
61
|
+
scanPageDirect, } from '@pillar-ai/sdk';
|
package/dist/index.esm.js
CHANGED
|
@@ -10,11 +10,13 @@ const PillarContext = createContext(null);
|
|
|
10
10
|
// ============================================================================
|
|
11
11
|
// Provider Component
|
|
12
12
|
// ============================================================================
|
|
13
|
-
function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScanning
|
|
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);
|
|
17
|
-
|
|
18
|
+
// DOM scanning is disabled - always false
|
|
19
|
+
const isDOMScanningEnabled = false;
|
|
18
20
|
// Support both productKey (new) and helpCenter (deprecated)
|
|
19
21
|
const resolvedKey = productKey ?? helpCenter;
|
|
20
22
|
// Keep a ref to the latest onTask callback to avoid re-subscribing
|
|
@@ -41,10 +43,6 @@ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScan
|
|
|
41
43
|
if (mounted) {
|
|
42
44
|
setPillar(existingInstance);
|
|
43
45
|
setState(existingInstance.state);
|
|
44
|
-
// Apply DOM scanning settings to existing instance
|
|
45
|
-
if (domScanning !== undefined) {
|
|
46
|
-
existingInstance.setDOMScanningEnabled(domScanning);
|
|
47
|
-
}
|
|
48
46
|
// Re-subscribe to events
|
|
49
47
|
existingInstance.on("panel:open", () => {
|
|
50
48
|
setIsPanelOpen(true);
|
|
@@ -56,14 +54,10 @@ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScan
|
|
|
56
54
|
return;
|
|
57
55
|
}
|
|
58
56
|
// Initialize new instance
|
|
57
|
+
// Note: DOM scanning is disabled, config.domScanning is ignored
|
|
59
58
|
const instance = await Pillar.init({
|
|
60
59
|
productKey: resolvedKey,
|
|
61
60
|
...config,
|
|
62
|
-
domScanning: {
|
|
63
|
-
...config?.domScanning,
|
|
64
|
-
// Explicit prop overrides config value
|
|
65
|
-
enabled: domScanning ?? config?.domScanning?.enabled ?? false,
|
|
66
|
-
},
|
|
67
61
|
});
|
|
68
62
|
if (mounted) {
|
|
69
63
|
setPillar(instance);
|
|
@@ -118,15 +112,7 @@ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScan
|
|
|
118
112
|
return unsubscribe;
|
|
119
113
|
}
|
|
120
114
|
}, [pillar]);
|
|
121
|
-
//
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
if (pillar) {
|
|
124
|
-
if (domScanning !== undefined) {
|
|
125
|
-
pillar.setDOMScanningEnabled(domScanning);
|
|
126
|
-
setIsDOMScanningEnabledState(domScanning);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, [pillar, domScanning]);
|
|
115
|
+
// DOM scanning is disabled - no sync needed
|
|
130
116
|
// Register custom card renderers
|
|
131
117
|
useEffect(() => {
|
|
132
118
|
if (!pillar || !cards)
|
|
@@ -188,10 +174,10 @@ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScan
|
|
|
188
174
|
const setTextSelectionEnabled = useCallback((enabled) => {
|
|
189
175
|
pillar?.setTextSelectionEnabled(enabled);
|
|
190
176
|
}, [pillar]);
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}, [
|
|
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
|
+
}, []);
|
|
195
181
|
const scanPage = useCallback((options) => {
|
|
196
182
|
if (!pillar)
|
|
197
183
|
return null;
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 /** Enable or disable DOM scanning */\n setDOMScanningEnabled: (enabled: boolean) => void;\n\n /** Whether DOM scanning is enabled */\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 * When enabled, interactable elements and text content are captured and sent to the LLM.\n * @default false\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,\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 const [isDOMScanningEnabled, setIsDOMScanningEnabledState] = useState(domScanning ?? 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 // Apply DOM scanning settings to existing instance\n if (domScanning !== undefined) {\n existingInstance.setDOMScanningEnabled(domScanning);\n }\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 productKey: resolvedKey,\n ...config,\n domScanning: {\n ...config?.domScanning,\n // Explicit prop overrides config value\n enabled: domScanning ?? config?.domScanning?.enabled ?? false,\n },\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 // Sync DOM scanning props with SDK when they change\n useEffect(() => {\n if (pillar) {\n if (domScanning !== undefined) {\n pillar.setDOMScanningEnabled(domScanning);\n setIsDOMScanningEnabledState(domScanning);\n }\n }\n }, [pillar, domScanning]);\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 setDOMScanningEnabled = useCallback(\n (enabled: boolean) => {\n pillar?.setDOMScanningEnabled(enabled);\n setIsDOMScanningEnabledState(enabled);\n },\n [pillar]\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":";;;;;AAyMA;AACA;AACA;AAEA,MAAM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AAO,GAAG,OAAO,CACrB,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,CAAC,eAAe,CAAC,CAAC,EAC5E,CAAC,eAAe,CAAC,CAClB;;AAGD,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC;AAClC,IAAA,UAAU,CAAC,OAAO,GAAG,OAAO;;AAG5B,IAAA,MAAM,YAAY,GAAG,OAAO,CAC1B,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAC1C,CAAC,OAAO,CAAC,CACV;IAED,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,MAAM;YAAE;;AAGb,QAAA,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,KAAI;YAC5D,OAAO,MAAM,CAAC,UAAU,CAAC;AACvB,gBAAA,GAAG,MAAM;;;AAGT,gBAAA,OAAO,EAAE,CAAC,KAAU,KAAK,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;AACpD,aAAA,CAAC;AAClB,QAAA,CAAC,CAAC;;AAGF,QAAA,OAAO,MAAK;YACV,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;AAC1C,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC5B;AAEA;AACO,MAAM,eAAe,GAAG;;;;"}
|
|
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,oBAAoB,GAAG,KAAK;;AAGlC,IAAA,MAAM,WAAW,GAAG,UAAU,IAAI,UAAU;;AAG5C,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAA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,EAAE,GAAG,gBAAgB,EAAE;;AAGrC,IAAA,MAAM,OAAO,GAAG,OAAO,CACrB,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,CAAC,eAAe,CAAC,CAAC,EAC5E,CAAC,eAAe,CAAC,CAClB;;AAGD,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC;AAClC,IAAA,UAAU,CAAC,OAAO,GAAG,OAAO;;AAG5B,IAAA,MAAM,YAAY,GAAG,OAAO,CAC1B,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAC1C,CAAC,OAAO,CAAC,CACV;IAED,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,MAAM;YAAE;;AAGb,QAAA,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,KAAI;YAC5D,OAAO,MAAM,CAAC,UAAU,CAAC;AACvB,gBAAA,GAAG,MAAM;;;AAGT,gBAAA,OAAO,EAAE,CAAC,KAAU,KAAK,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;AACpD,aAAA,CAAC;AAClB,QAAA,CAAC,CAAC;;AAGF,QAAA,OAAO,MAAK;YACV,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;AAC1C,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC5B;AAEA;AACO,MAAM,eAAe,GAAG;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -12,11 +12,13 @@ const PillarContext = react.createContext(null);
|
|
|
12
12
|
// ============================================================================
|
|
13
13
|
// Provider Component
|
|
14
14
|
// ============================================================================
|
|
15
|
-
function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScanning
|
|
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);
|
|
19
|
-
|
|
20
|
+
// DOM scanning is disabled - always false
|
|
21
|
+
const isDOMScanningEnabled = false;
|
|
20
22
|
// Support both productKey (new) and helpCenter (deprecated)
|
|
21
23
|
const resolvedKey = productKey ?? helpCenter;
|
|
22
24
|
// Keep a ref to the latest onTask callback to avoid re-subscribing
|
|
@@ -43,10 +45,6 @@ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScan
|
|
|
43
45
|
if (mounted) {
|
|
44
46
|
setPillar(existingInstance);
|
|
45
47
|
setState(existingInstance.state);
|
|
46
|
-
// Apply DOM scanning settings to existing instance
|
|
47
|
-
if (domScanning !== undefined) {
|
|
48
|
-
existingInstance.setDOMScanningEnabled(domScanning);
|
|
49
|
-
}
|
|
50
48
|
// Re-subscribe to events
|
|
51
49
|
existingInstance.on("panel:open", () => {
|
|
52
50
|
setIsPanelOpen(true);
|
|
@@ -58,14 +56,10 @@ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScan
|
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
58
|
// Initialize new instance
|
|
59
|
+
// Note: DOM scanning is disabled, config.domScanning is ignored
|
|
61
60
|
const instance = await sdk.Pillar.init({
|
|
62
61
|
productKey: resolvedKey,
|
|
63
62
|
...config,
|
|
64
|
-
domScanning: {
|
|
65
|
-
...config?.domScanning,
|
|
66
|
-
// Explicit prop overrides config value
|
|
67
|
-
enabled: domScanning ?? config?.domScanning?.enabled ?? false,
|
|
68
|
-
},
|
|
69
63
|
});
|
|
70
64
|
if (mounted) {
|
|
71
65
|
setPillar(instance);
|
|
@@ -120,15 +114,7 @@ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScan
|
|
|
120
114
|
return unsubscribe;
|
|
121
115
|
}
|
|
122
116
|
}, [pillar]);
|
|
123
|
-
//
|
|
124
|
-
react.useEffect(() => {
|
|
125
|
-
if (pillar) {
|
|
126
|
-
if (domScanning !== undefined) {
|
|
127
|
-
pillar.setDOMScanningEnabled(domScanning);
|
|
128
|
-
setIsDOMScanningEnabledState(domScanning);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}, [pillar, domScanning]);
|
|
117
|
+
// DOM scanning is disabled - no sync needed
|
|
132
118
|
// Register custom card renderers
|
|
133
119
|
react.useEffect(() => {
|
|
134
120
|
if (!pillar || !cards)
|
|
@@ -190,10 +176,10 @@ function PillarProvider({ productKey, helpCenter, config, onTask, cards, domScan
|
|
|
190
176
|
const setTextSelectionEnabled = react.useCallback((enabled) => {
|
|
191
177
|
pillar?.setTextSelectionEnabled(enabled);
|
|
192
178
|
}, [pillar]);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}, [
|
|
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
|
+
}, []);
|
|
197
183
|
const scanPage = react.useCallback((options) => {
|
|
198
184
|
if (!pillar)
|
|
199
185
|
return null;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.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 /** Enable or disable DOM scanning */\n setDOMScanningEnabled: (enabled: boolean) => void;\n\n /** Whether DOM scanning is enabled */\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 * When enabled, interactable elements and text content are captured and sent to the LLM.\n * @default false\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,\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 const [isDOMScanningEnabled, setIsDOMScanningEnabledState] = useState(domScanning ?? 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 // Apply DOM scanning settings to existing instance\n if (domScanning !== undefined) {\n existingInstance.setDOMScanningEnabled(domScanning);\n }\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 productKey: resolvedKey,\n ...config,\n domScanning: {\n ...config?.domScanning,\n // Explicit prop overrides config value\n enabled: domScanning ?? config?.domScanning?.enabled ?? false,\n },\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 // Sync DOM scanning props with SDK when they change\n useEffect(() => {\n if (pillar) {\n if (domScanning !== undefined) {\n pillar.setDOMScanningEnabled(domScanning);\n setIsDOMScanningEnabledState(domScanning);\n }\n }\n }, [pillar, domScanning]);\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 setDOMScanningEnabled = useCallback(\n (enabled: boolean) => {\n pillar?.setDOMScanningEnabled(enabled);\n setIsDOMScanningEnabledState(enabled);\n },\n [pillar]\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":["createContext","useState","useRef","useEffect","Pillar","createRoot","_jsx","useCallback","scanPageDirect","useMemo","useContext"],"mappings":";;;;;;;AAyMA;AACA;AACA;AAEA,MAAM,aAAa,GAAGA,mBAAa,CAA4B,IAAI,CAAC;AAEpE;AACA;AACA;SAEgB,cAAc,CAAC,EAC7B,UAAU,EACV,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,WAAW,EACX,QAAQ,GACY,EAAA;IACpB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAGC,cAAQ,CAAgB,IAAI,CAAC;IACzD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAc,eAAe,CAAC;IAChE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;AACrD,IAAA,MAAM,CAAC,oBAAoB,EAAE,4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,CAAC,GAAG,CAAC,EAC1C,CAAC,OAAO,CAAC,CACV;IAEDN,eAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,MAAM;YAAE;;AAGb,QAAA,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,KAAI;YAC5D,OAAO,MAAM,CAAC,UAAU,CAAC;AACvB,gBAAA,GAAG,MAAM;;;AAGT,gBAAA,OAAO,EAAE,CAAC,KAAU,KAAK,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;AACpD,aAAA,CAAC;AAClB,QAAA,CAAC,CAAC;;AAGF,QAAA,OAAO,MAAK;YACV,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;AAC1C,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC5B;AAEA;AACO,MAAM,eAAe,GAAG;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.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":["createContext","useState","useRef","useEffect","Pillar","createRoot","_jsx","useCallback","scanPageDirect","useMemo","useContext"],"mappings":";;;;;;;AA8MA;AACA;AACA;AAEA,MAAM,aAAa,GAAGA,mBAAa,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,GAAGC,cAAQ,CAAgB,IAAI,CAAC;IACzD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAc,eAAe,CAAC;IAChE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;;IAErD,MAAM,oBAAoB,GAAG,KAAK;;AAGlC,IAAA,MAAM,WAAW,GAAG,UAAU,IAAI,UAAU;;AAG5C,IAAA,MAAM,SAAS,GAAGC,YAAM,CAAC,MAAM,CAAC;AAChC,IAAA,SAAS,CAAC,OAAO,GAAG,MAAM;;IAG1BC,eAAS,CAAC,MAAK;AACb,QAAA,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE;AAC7B,YAAA,OAAO,CAAC,IAAI,CACV,2EAA2E,CAC5E;QACH;IACF,CAAC,EAAE,EAAE,CAAC;;AAGN,IAAA,MAAM,QAAQ,GAAGD,YAAM,CAAC,KAAK,CAAC;AAC9B,IAAA,QAAQ,CAAC,OA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