@pillar-ai/react 0.1.13 → 0.1.14

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.
@@ -1,8 +1,21 @@
1
1
  /**
2
2
  * HelpButton Component
3
3
  * Pre-styled button to open the help panel
4
+ *
5
+ * Styling follows the dual-class pattern:
6
+ * - Internal class (_pillar-help-btn): Contains default styles
7
+ * - Public class (pillar-help-btn): Empty by default, for user overrides
8
+ *
9
+ * Supports CSS variable customization:
10
+ * - --pillar-btn-primary-bg
11
+ * - --pillar-btn-primary-color
12
+ * - --pillar-btn-secondary-bg
13
+ * - --pillar-btn-secondary-color
14
+ * - --pillar-btn-ghost-color
15
+ * - --pillar-btn-radius
16
+ * - --pillar-btn-font-family
4
17
  */
5
- import React, { type ReactNode, type ButtonHTMLAttributes } from 'react';
18
+ import { type ButtonHTMLAttributes, type ReactNode } from 'react';
6
19
  export interface HelpButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {
7
20
  /** Button content - defaults to "Help" */
8
21
  children?: ReactNode;
@@ -22,6 +35,10 @@ export interface HelpButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonEle
22
35
  /**
23
36
  * Pre-styled help button that integrates with Pillar
24
37
  *
38
+ * Uses CSS classes for styling with CSS variable support:
39
+ * - Internal classes (_pillar-help-btn-*): Default styles
40
+ * - Public classes (pillar-help-btn-*): For user overrides
41
+ *
25
42
  * @example
26
43
  * ```tsx
27
44
  * // Basic usage
@@ -34,6 +51,12 @@ export interface HelpButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonEle
34
51
  * <HelpButton action="search" searchQuery="getting started">
35
52
  * Search Help
36
53
  * </HelpButton>
54
+ *
55
+ * // Customize via CSS variables
56
+ * // :root { --pillar-btn-primary-bg: #8b5cf6; }
57
+ *
58
+ * // Or via public class overrides
59
+ * // .pillar-help-btn--primary { background: #8b5cf6; }
37
60
  * ```
38
61
  */
39
- export declare function HelpButton({ children, action, searchQuery, articleSlug, onClick: customOnClick, variant, size, style, disabled, ...props }: HelpButtonProps): React.ReactElement;
62
+ export declare function HelpButton({ children, action, searchQuery, articleSlug, onClick: customOnClick, variant, size, style, disabled, className, ...props }: HelpButtonProps): JSX.Element;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * usePillarRender Hook
3
+ *
4
+ * Register a React component to render inline in the chat when the agent
5
+ * calls an `inline_ui` tool. The component receives data from the agent
6
+ * and can submit results back.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { usePillarRender, type PillarRenderProps } from '@pillar-ai/react';
11
+ *
12
+ * function InviteCard({ data, submit, cancel }: PillarRenderProps<{ emails: string[] }>) {
13
+ * const [emails, setEmails] = useState(data.emails || []);
14
+ * return (
15
+ * <div>
16
+ * <input
17
+ * value={emails.join(',')}
18
+ * onChange={(e) => setEmails(e.target.value.split(','))}
19
+ * />
20
+ * <button onClick={() => submit({ invited: emails })}>Send</button>
21
+ * <button onClick={cancel}>Cancel</button>
22
+ * </div>
23
+ * );
24
+ * }
25
+ *
26
+ * function TeamPage() {
27
+ * usePillarRender({
28
+ * name: 'invite_members',
29
+ * description: 'Show invite UI when user wants to add team members',
30
+ * inputSchema: {
31
+ * type: 'object',
32
+ * properties: { emails: { type: 'array', items: { type: 'string' } } },
33
+ * },
34
+ * render: InviteCard,
35
+ * });
36
+ *
37
+ * return <div>Team content...</div>;
38
+ * }
39
+ * ```
40
+ */
41
+ import { type ComponentType } from 'react';
42
+ /**
43
+ * Props passed to the render component.
44
+ *
45
+ * @template TData - Type of the data extracted by the agent
46
+ */
47
+ export interface PillarRenderProps<TData extends Record<string, unknown> = Record<string, unknown>> {
48
+ /** Data extracted by the agent from the conversation */
49
+ data: TData;
50
+ /** Submit result back to the agent. Call this when the user confirms/completes the action. */
51
+ submit: (result: unknown) => void;
52
+ /** Cancel/dismiss the UI. Call this when the user cancels the action. */
53
+ cancel: () => void;
54
+ /** Report loading/success/error states for visual feedback */
55
+ setStatus: (status: 'loading' | 'success' | 'error', message?: string) => void;
56
+ }
57
+ /**
58
+ * Schema for registering a render component.
59
+ *
60
+ * @template TData - Type of the data extracted by the agent
61
+ */
62
+ export interface PillarRenderSchema<TData extends Record<string, unknown> = Record<string, unknown>> {
63
+ /**
64
+ * Unique name for this render context (e.g., 'invite_members').
65
+ * This becomes the card_type that the agent references.
66
+ */
67
+ name: string;
68
+ /**
69
+ * Human-readable description for AI matching.
70
+ * Describes when the agent should use this UI.
71
+ */
72
+ description: string;
73
+ /**
74
+ * Example user queries that should trigger this render context.
75
+ * Used for semantic matching alongside the description.
76
+ */
77
+ examples?: string[];
78
+ /**
79
+ * JSON Schema for data extraction from user query.
80
+ * The agent will extract structured data from the conversation
81
+ * to populate the `data` prop passed to your component.
82
+ */
83
+ inputSchema?: {
84
+ type: 'object';
85
+ properties: Record<string, unknown>;
86
+ required?: string[];
87
+ };
88
+ /**
89
+ * React component to render inline in the chat panel.
90
+ * Receives PillarRenderProps with data from the agent and callbacks.
91
+ */
92
+ render: ComponentType<PillarRenderProps<TData>>;
93
+ }
94
+ /**
95
+ * Register a single render context.
96
+ */
97
+ export declare function usePillarRender<TData extends Record<string, unknown> = Record<string, unknown>>(schema: PillarRenderSchema<TData>): void;
98
+ /**
99
+ * Register multiple render contexts.
100
+ */
101
+ export declare function usePillarRender(schemas: PillarRenderSchema[]): void;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * usePillarTasks Hook
3
+ * Declarative bulk registration of task handlers with automatic cleanup.
4
+ *
5
+ * Replaces the manual useEffect + unsubscribers[] pattern with a single
6
+ * hook call that accepts a map of task name → handler.
7
+ *
8
+ * Uses a ref internally so handlers are always up-to-date without
9
+ * re-registering on every render. Re-registration only happens when
10
+ * the Pillar instance changes.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import type { Actions } from '@/lib/pillar/actions';
15
+ *
16
+ * function MyTaskHandlers() {
17
+ * const router = useRouter();
18
+ *
19
+ * usePillarTasks<Actions>({
20
+ * open_settings: (data) => router.push('/settings'),
21
+ * open_knowledge: (data) => router.push('/knowledge'),
22
+ * update_brand_name: async (data) => {
23
+ * await api.updateBrandName(data.name);
24
+ * return { success: true };
25
+ * },
26
+ * });
27
+ *
28
+ * return null;
29
+ * }
30
+ * ```
31
+ */
32
+ import type { SyncActionDefinitions, ActionDefinitions, ActionDataType, ActionNames } from '@pillar-ai/sdk';
33
+ /**
34
+ * Type-safe map of action names to handler functions.
35
+ *
36
+ * Known action names (from TActions) get typed `data` parameters with
37
+ * autocomplete. Arbitrary string keys are also accepted for ad-hoc tasks
38
+ * (e.g. "escalate", "navigate") that aren't in the actions definition.
39
+ *
40
+ * Uses an intersection of a mapped type (for typed keys) with a loose
41
+ * index signature (for ad-hoc keys). The index signature uses
42
+ * `(...args: any[]) => any` to avoid contravariance conflicts with
43
+ * typed handlers.
44
+ */
45
+ export type TaskHandlerMap<TActions extends SyncActionDefinitions | ActionDefinitions> = {
46
+ [K in ActionNames<TActions>]?: (data: ActionDataType<TActions, K>) => void | unknown | Promise<void | unknown>;
47
+ } & {
48
+ [key: string]: ((...args: any[]) => any) | undefined;
49
+ };
50
+ /**
51
+ * Declaratively register multiple task handlers at once.
52
+ *
53
+ * Handlers are stored in a ref so they always reflect the latest
54
+ * closures without causing re-registration. The effect only re-runs
55
+ * when the Pillar SDK instance itself changes.
56
+ *
57
+ * @param tasks - Map of task name → handler function
58
+ */
59
+ export declare function usePillarTasks<TActions extends SyncActionDefinitions | ActionDefinitions = SyncActionDefinitions>(tasks: TaskHandlerMap<TActions>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pillar-ai/react",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "React SDK for Pillar product copilot — AI assistant for SaaS and web apps",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",
@@ -55,7 +55,7 @@
55
55
  "react-dom": ">=17.0.0 || >=19.0.0"
56
56
  },
57
57
  "dependencies": {
58
- "@pillar-ai/sdk": "^0.1.22"
58
+ "@pillar-ai/sdk": "^0.1.25"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@rollup/plugin-commonjs": "^25.0.7",