@pillar-ai/sdk 0.1.8 → 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.
Files changed (58) hide show
  1. package/README.md +118 -60
  2. package/dist/actions/index.d.ts +1 -1
  3. package/dist/actions/registry.d.ts +15 -27
  4. package/dist/actions/types.d.ts +20 -8
  5. package/dist/api/client.d.ts +91 -5
  6. package/dist/api/mcp-client.d.ts +105 -79
  7. package/dist/cli/sync.d.ts +0 -1
  8. package/dist/cli/sync.js +102 -14
  9. package/dist/components/DebugPanel/DebugPanel.d.ts +25 -0
  10. package/dist/components/DebugPanel/index.d.ts +2 -0
  11. package/dist/components/DevTools/index.d.ts +5 -0
  12. package/dist/components/DevTools/styles.d.ts +5 -0
  13. package/dist/components/Panel/Header.d.ts +1 -1
  14. package/dist/components/Panel/HistoryDropdown.d.ts +10 -0
  15. package/dist/components/Panel/Panel.d.ts +1 -0
  16. package/dist/components/Panel/TaskButton.d.ts +4 -14
  17. package/dist/components/Panel/styles.d.ts +1 -1
  18. package/dist/components/Plan/InlinePlanView.d.ts +1 -1
  19. package/dist/components/Plan/PlanDocument.d.ts +18 -0
  20. package/dist/components/Plan/PlanStepItem.d.ts +1 -1
  21. package/dist/components/Plan/PlanView.d.ts +1 -1
  22. package/dist/components/Plan/index.d.ts +1 -0
  23. package/dist/components/Progress/ProgressRow.d.ts +16 -0
  24. package/dist/components/Progress/ProgressStack.d.ts +15 -0
  25. package/dist/components/Progress/ReasoningDisclosure.d.ts +20 -0
  26. package/dist/components/Progress/index.d.ts +3 -0
  27. package/dist/components/Views/HomeView.d.ts +3 -0
  28. package/dist/components/Views/ResumePrompt.d.ts +22 -0
  29. package/dist/components/Views/index.d.ts +1 -0
  30. package/dist/components/index.d.ts +1 -0
  31. package/dist/components/shared/icons.d.ts +24 -0
  32. package/dist/components/shared/index.d.ts +1 -0
  33. package/dist/core/Pillar.d.ts +318 -80
  34. package/dist/core/config.d.ts +141 -3
  35. package/dist/core/events.d.ts +55 -70
  36. package/dist/core/plan-executor.d.ts +29 -0
  37. package/dist/core/plan.d.ts +6 -0
  38. package/dist/hooks/index.d.ts +5 -0
  39. package/dist/hooks/useDebouncedValue.d.ts +22 -0
  40. package/dist/hooks/useInlineCard.d.ts +35 -0
  41. package/dist/hooks/usePillarInstance.d.ts +30 -0
  42. package/dist/index.d.ts +14 -12
  43. package/dist/pillar.esm.js +1 -1
  44. package/dist/store/chat.d.ts +102 -4
  45. package/dist/store/index.d.ts +1 -0
  46. package/dist/store/session-persistence.d.ts +62 -0
  47. package/dist/store/suggestions.d.ts +58 -0
  48. package/dist/types/dom-scanner.d.ts +46 -0
  49. package/dist/types/index.d.ts +1 -0
  50. package/dist/types/user-context.d.ts +32 -1
  51. package/dist/utils/debug.d.ts +150 -0
  52. package/dist/utils/dom-scanner.d.ts +44 -0
  53. package/dist/utils/markdown-components.d.ts +53 -0
  54. package/dist/utils/preact-markdown.d.ts +17 -0
  55. package/dist/utils/route-observer.d.ts +67 -0
  56. package/package.json +1 -1
  57. package/src/actions/types.ts +21 -7
  58. package/dist/utils/markdown.d.ts +0 -9
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Simple EventEmitter for SDK events
3
3
  */
4
- import type { ResolvedThemeConfig } from './config';
5
- import type { Context, UserProfile } from './context';
6
- import type { ExecutionPlan, ExecutionStep } from './plan';
7
- import type { Workflow, WorkflowStep } from './workflow';
4
+ import type { CompactScanResult } from "../types/dom-scanner";
5
+ import type { ResolvedThemeConfig } from "./config";
6
+ import type { Context, UserProfile } from "./context";
7
+ import type { Workflow, WorkflowStep } from "./workflow";
8
8
  export type EventCallback<T = unknown> = (data: T) => void;
9
9
  /**
10
10
  * Task execution payload - sent when a task button is clicked.
@@ -17,7 +17,7 @@ export interface TaskExecutePayload {
17
17
  /** Task data payload */
18
18
  data: Record<string, unknown>;
19
19
  /** Task type hint */
20
- taskType?: 'navigate' | 'open_modal' | 'fill_form' | 'trigger_action' | 'copy_text' | 'external_link' | 'start_tutorial' | 'inline_ui';
20
+ taskType?: "navigate" | "open_modal" | "fill_form" | "trigger_action" | "copy_text" | "external_link" | "start_tutorial" | "inline_ui";
21
21
  /** Path template for navigate type (already resolved with params) */
22
22
  path?: string;
23
23
  /** External URL for external_link type */
@@ -32,7 +32,7 @@ export interface CardCallbacks {
32
32
  /** Called when user cancels the action */
33
33
  onCancel: () => void;
34
34
  /** Called to report card state changes (for analytics/confirmation) */
35
- onStateChange?: (state: 'loading' | 'success' | 'error', message?: string) => void;
35
+ onStateChange?: (state: "loading" | "success" | "error", message?: string) => void;
36
36
  }
37
37
  /**
38
38
  * Card field schema definition for declarative card configuration.
@@ -43,7 +43,7 @@ export interface CardFieldSchema {
43
43
  /** Display label */
44
44
  label: string;
45
45
  /** Field type */
46
- type: 'text' | 'number' | 'email' | 'select' | 'multiselect' | 'checkbox' | 'textarea' | 'date' | 'hidden';
46
+ type: "text" | "number" | "email" | "select" | "multiselect" | "checkbox" | "textarea" | "date" | "hidden";
47
47
  /** Whether field is required */
48
48
  required?: boolean;
49
49
  /** Default value */
@@ -83,7 +83,7 @@ export interface CardRegistrationOptions {
83
83
  renderer?: CardRenderer;
84
84
  /** Theme/styling options */
85
85
  theme?: {
86
- variant?: 'default' | 'compact' | 'wide';
86
+ variant?: "default" | "compact" | "wide";
87
87
  confirmLabel?: string;
88
88
  cancelLabel?: string;
89
89
  };
@@ -107,114 +107,99 @@ export interface RegisteredCard {
107
107
  */
108
108
  export type CardRenderer = (container: HTMLElement, data: Record<string, unknown>, callbacks: CardCallbacks) => (() => void) | void;
109
109
  export interface PillarEvents {
110
- 'ready': void;
111
- 'error': Error;
112
- 'panel:open': void;
113
- 'panel:close': void;
114
- 'panel:navigate': {
110
+ ready: void;
111
+ error: Error;
112
+ "panel:open": void;
113
+ "panel:close": void;
114
+ "panel:navigate": {
115
115
  view: string;
116
116
  params?: Record<string, string>;
117
117
  };
118
- 'article:view': {
118
+ "article:view": {
119
119
  articleSlug: string;
120
120
  };
121
- 'search:query': {
121
+ "search:query": {
122
122
  query: string;
123
123
  };
124
- 'chat:message': {
124
+ "chat:message": {
125
125
  message: string;
126
126
  };
127
- 'textSelection:shown': {
127
+ "textSelection:shown": {
128
128
  text: string;
129
129
  };
130
- 'textSelection:click': {
130
+ "textSelection:click": {
131
131
  text: string;
132
132
  };
133
- 'context:change': {
133
+ "context:change": {
134
134
  context: Context;
135
135
  };
136
- 'profile:change': {
136
+ "profile:change": {
137
137
  profile: UserProfile;
138
138
  };
139
- 'action:report': {
139
+ "action:report": {
140
140
  action: string;
141
141
  metadata?: Record<string, unknown>;
142
142
  };
143
- 'action:result': {
143
+ "user:identified": {
144
+ userId: string;
145
+ profile?: {
146
+ name?: string;
147
+ email?: string;
148
+ metadata?: Record<string, unknown>;
149
+ };
150
+ };
151
+ "user:logout": Record<string, never>;
152
+ "action:result": {
144
153
  actionName: string;
145
154
  result: unknown;
155
+ toolCallId?: string;
146
156
  };
147
- 'task:execute': TaskExecutePayload;
148
- 'task:complete': {
157
+ "task:execute": TaskExecutePayload;
158
+ "task:complete": {
149
159
  id?: string;
150
160
  name: string;
151
161
  success: boolean;
152
162
  data?: Record<string, unknown>;
153
163
  };
154
- 'workflow:start': Workflow;
155
- 'workflow:step:active': {
164
+ "workflow:start": Workflow;
165
+ "workflow:step:active": {
156
166
  workflow: Workflow;
157
167
  step: WorkflowStep;
158
168
  };
159
- 'workflow:step:complete': {
169
+ "workflow:step:complete": {
160
170
  workflow: Workflow;
161
171
  step: WorkflowStep;
162
172
  success: boolean;
163
173
  };
164
- 'workflow:step:skip': {
174
+ "workflow:step:skip": {
165
175
  workflow: Workflow;
166
176
  step: WorkflowStep;
167
177
  };
168
- 'workflow:complete': Workflow;
169
- 'workflow:cancel': Workflow;
170
- 'plan:start': ExecutionPlan;
171
- 'plan:step:active': {
172
- plan: ExecutionPlan;
173
- step: ExecutionStep;
174
- };
175
- 'plan:step:confirm': {
176
- plan: ExecutionPlan;
177
- step: ExecutionStep;
178
- };
179
- 'plan:step:complete': {
180
- plan: ExecutionPlan;
181
- step: ExecutionStep;
182
- success: boolean;
183
- };
184
- 'plan:step:skip': {
185
- plan: ExecutionPlan;
186
- step: ExecutionStep;
187
- };
188
- 'plan:step:retry': {
189
- plan: ExecutionPlan;
190
- step: ExecutionStep;
191
- retryCount: number;
192
- };
193
- 'plan:step:failed': {
194
- plan: ExecutionPlan;
195
- step: ExecutionStep;
196
- error: Error;
197
- canRetry?: boolean;
198
- };
199
- 'plan:updated': ExecutionPlan;
200
- 'plan:complete': ExecutionPlan;
201
- 'plan:cancel': ExecutionPlan;
202
- 'plan:error': {
203
- plan: ExecutionPlan;
204
- error: Error;
205
- };
206
- 'theme:change': {
178
+ "workflow:complete": Workflow;
179
+ "workflow:cancel": Workflow;
180
+ "theme:change": {
207
181
  theme: ResolvedThemeConfig;
208
182
  };
209
- 'textSelection:change': {
183
+ "textSelection:change": {
184
+ enabled: boolean;
185
+ };
186
+ "dom:scanned": CompactScanResult;
187
+ "domScanning:change": {
210
188
  enabled: boolean;
211
189
  };
212
- 'sidebar:click': {
190
+ "suggestions:updated": {
191
+ suggestions: Array<{
192
+ id: string;
193
+ text: string;
194
+ }>;
195
+ route: string;
196
+ };
197
+ "sidebar:click": {
213
198
  tabId: string;
214
199
  label: string;
215
200
  };
216
201
  /** @deprecated Use 'sidebar:click' instead. Will be removed in next major version. */
217
- 'support:request': {
202
+ "support:request": {
218
203
  tabId: string;
219
204
  };
220
205
  }
@@ -39,6 +39,14 @@ export declare class PlanExecutor {
39
39
  * User clicks "Start Plan" for plans with auto_execute=false.
40
40
  */
41
41
  startPlan(): Promise<void>;
42
+ /**
43
+ * Resume execution of a stuck plan.
44
+ *
45
+ * This is a fallback method for when auto-execution fails or
46
+ * the plan gets into an inconsistent state. It manually triggers
47
+ * execution of the next ready step without requiring server confirmation.
48
+ */
49
+ resumeExecution(): Promise<void>;
42
50
  /**
43
51
  * Execute the next ready step.
44
52
  */
@@ -106,12 +114,33 @@ export declare class PlanExecutor {
106
114
  markStepDone(stepId: string): Promise<void>;
107
115
  /**
108
116
  * Internal helper to mark a step complete and advance to next.
117
+ *
118
+ * This is called when:
119
+ * - An inline step completes (via completeInlineStep)
120
+ * - A task:complete event fires for a step awaiting result (via completeStepByAction)
121
+ * - User clicks "Done" on a wizard step (via markStepDone)
122
+ *
123
+ * It reports the result to the server for step-by-step verification,
124
+ * then advances to the next step based on the server's decision.
109
125
  */
110
126
  private markStepComplete;
111
127
  /**
112
128
  * Execute a single step.
113
129
  */
114
130
  private executeStep;
131
+ /**
132
+ * Report step completion to server and handle the decision.
133
+ *
134
+ * This is the core of step-by-step verification:
135
+ * - Every step reports its result (success or failure)
136
+ * - Server decides what to do next
137
+ * - SDK executes the decision
138
+ */
139
+ private reportStepComplete;
140
+ /**
141
+ * Handle the server's decision after step completion.
142
+ */
143
+ private handleServerDecision;
115
144
  /**
116
145
  * Get the current active plan.
117
146
  */
@@ -67,6 +67,12 @@ export interface ExecutionPlan {
67
67
  created_at: string | null;
68
68
  /** When the plan completed (ISO timestamp) */
69
69
  completed_at: string | null;
70
+ /**
71
+ * Free-form document explaining the plan's approach, reasoning,
72
+ * dependencies between steps, and success criteria.
73
+ * Generated by the LLM when creating the plan.
74
+ */
75
+ document?: string;
70
76
  }
71
77
  /**
72
78
  * A single step in an execution plan.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * React/Preact hooks for the Pillar SDK
3
+ */
4
+ export { useDebouncedValue } from './useDebouncedValue';
5
+ export { usePillarInstance } from './usePillarInstance';
@@ -0,0 +1,22 @@
1
+ /**
2
+ * useDebouncedValue Hook
3
+ *
4
+ * Debounces a value by a specified delay. Useful for preventing
5
+ * rapid UI updates during streaming text or frequent state changes.
6
+ */
7
+ /**
8
+ * Returns a debounced version of the provided value.
9
+ * The returned value only updates after the specified delay has passed
10
+ * without the input value changing.
11
+ *
12
+ * @param value - The value to debounce
13
+ * @param delay - Delay in milliseconds before updating (default: 50ms)
14
+ * @returns The debounced value
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const debouncedText = useDebouncedValue(rapidlyChangingText, 50);
19
+ * // debouncedText only updates every 50ms at most
20
+ * ```
21
+ */
22
+ export declare function useDebouncedValue<T>(value: T, delay?: number): T;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * useInlineCard Hook
3
+ *
4
+ * Shared hook for rendering inline_ui cards in plan steps.
5
+ * Consolidates duplicated logic from InlinePlanView and PlanStepItem.
6
+ */
7
+ import type { RefObject } from 'preact';
8
+ import type { ExecutionStep } from '../core/plan';
9
+ export interface UseInlineCardOptions {
10
+ /** The execution step to render a card for */
11
+ step: ExecutionStep;
12
+ /** Ref to the container element for the card */
13
+ containerRef: RefObject<HTMLDivElement>;
14
+ /** Called when the inline card is confirmed with optional data */
15
+ onConfirm?: (stepId: string, data?: Record<string, unknown>) => void;
16
+ /** Called when the inline card is cancelled/skipped */
17
+ onSkip: (stepId: string) => void;
18
+ /** Component name for debug logging */
19
+ componentName?: string;
20
+ }
21
+ export interface UseInlineCardResult {
22
+ /** Whether the inline card should be shown */
23
+ shouldShow: boolean;
24
+ /** Whether this step is an inline_ui type */
25
+ isInlineUI: boolean;
26
+ }
27
+ /**
28
+ * Hook to manage inline_ui card rendering for plan steps.
29
+ *
30
+ * Handles:
31
+ * - Determining when to show the inline card
32
+ * - Rendering custom or default confirm cards
33
+ * - Wiring up confirm/cancel/stateChange callbacks
34
+ */
35
+ export declare function useInlineCard({ step, containerRef, onConfirm, onSkip, componentName, }: UseInlineCardOptions): UseInlineCardResult;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * usePillarInstance Hook
3
+ *
4
+ * Provides access to the Pillar singleton instance.
5
+ * This is a convenience hook for components that need to interact
6
+ * with the Pillar SDK (e.g., calling plan/workflow methods).
7
+ *
8
+ * Note: This returns a stable reference since Pillar is a singleton.
9
+ * The value may be null if the SDK is not initialized.
10
+ */
11
+ import Pillar from '../core/Pillar';
12
+ /**
13
+ * Hook to get the Pillar SDK instance.
14
+ *
15
+ * @returns The Pillar instance or null if not initialized
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * function MyComponent() {
20
+ * const pillar = usePillarInstance();
21
+ *
22
+ * const handleClick = () => {
23
+ * pillar?.startPlan();
24
+ * };
25
+ *
26
+ * return <button onClick={handleClick}>Start</button>;
27
+ * }
28
+ * ```
29
+ */
30
+ export declare function usePillarInstance(): Pillar | null;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Pillar SDK - Embedded Help for Your Application
2
+ * Pillar SDK - Cursor for your product
3
3
  *
4
4
  * @example
5
5
  * // Script tag usage
6
6
  * <script src="https://cdn.trypillar.com/sdk/pillar.min.js"></script>
7
7
  * <script>
8
8
  * Pillar.init({
9
- * helpCenter: 'your-help-center',
9
+ * productKey: 'your-product-key',
10
10
  * });
11
11
  * </script>
12
12
  *
@@ -15,16 +15,18 @@
15
15
  * import { Pillar } from '@pillar-ai/sdk';
16
16
  *
17
17
  * await Pillar.init({
18
- * helpCenter: 'your-help-center',
18
+ * productKey: 'your-product-key',
19
19
  * });
20
20
  */
21
- export { Pillar, type PillarState, type ChatContext } from './core/Pillar';
22
- export { EventEmitter, type PillarEvents, type TaskExecutePayload, type CardRenderer, type CardCallbacks } from './core/events';
23
- export { type PillarConfig, type ResolvedConfig, type ResolvedPanelConfig, type ResolvedMobileTriggerConfig, type PanelConfig, type EdgeTriggerConfig, type MobileTriggerConfig, type MobileTriggerPosition, type MobileTriggerIcon, type MobileTriggerSize, type UrlParamsConfig, type TextSelectionConfig, type PanelPosition, type PanelMode, type ThemeMode, type ThemeColors, type ThemeConfig, type ResolvedThemeConfig, type SidebarTabConfig, DEFAULT_SIDEBAR_TABS, } from './core/config';
24
- export { type Context, type UserProfile, type Suggestion, type AssistantContext, } from './core/context';
25
- export { type PlanStatus, type StepStatus, type ExecutionLocation, type ExecutionPlan, type ExecutionStep, type PlanEvents, } from './core/plan';
26
- export { defineActions, setClientInfo, getClientInfo, getHandler, getActionDefinition, hasAction, getActionNames, getManifest, clearRegistry, getActionCount, type ActionType, type ActionDataSchema, type ActionDefinition, type ActionDefinitions, type ActionManifest, type ActionManifestEntry, type ClientInfo, type Platform, type SyncActionDefinition, type SyncActionDefinitions, type ActionTypeDataMap, type NavigateActionData, type TriggerActionData, type InlineUIData, type ExternalLinkData, type CopyTextData, type ActionDataType, type ActionNames, type TypedTaskHandler, type TypedOnTask, type TypedPillarMethods, } from './actions';
27
- export { APIClient, type ArticleSummary, type ChatMessage, type ChatResponse, type ProgressEvent, } from './api/client';
28
- export { type ChatImage, type ImageUploadResponse, } from './api/mcp-client';
29
- import { Pillar } from './core/Pillar';
21
+ export { EventEmitter, type CardCallbacks, type CardRenderer, type PillarEvents, type TaskExecutePayload, } from "./core/events";
22
+ export { Pillar, type ChatContext, type PillarState } from "./core/Pillar";
23
+ export { DEFAULT_SIDEBAR_TABS, type DOMScanningConfig, type EdgeTriggerConfig, type InteractionHighlightConfig, type MobileTriggerConfig, type MobileTriggerIcon, type MobileTriggerPosition, type MobileTriggerSize, type PanelConfig, type PanelMode, type PanelPosition, type PillarConfig, type ResolvedConfig, type ResolvedDOMScanningConfig, type ResolvedInteractionHighlightConfig, type ResolvedMobileTriggerConfig, type ResolvedPanelConfig, type ResolvedThemeConfig, type SidebarTabConfig, type TextSelectionConfig, type ThemeColors, type ThemeConfig, type ThemeMode, type UrlParamsConfig, } from "./core/config";
24
+ export { type AssistantContext, type Context, type Suggestion, type UserProfile, } from "./core/context";
25
+ export { clearRegistry, getActionCount, getActionDefinition, getActionNames, getClientInfo, getHandler, getManifest, hasAction, setClientInfo, type ActionDataSchema, type ActionDataType, type ActionDefinition, type ActionDefinitions, type ActionManifest, type ActionManifestEntry, type ActionNames, type ActionType, type ActionTypeDataMap, type ClientInfo, type CopyTextData, type ExternalLinkData, type InlineUIData, type NavigateActionData, type Platform, type SyncActionDefinition, type SyncActionDefinitions, type TriggerActionData, type TypedOnTask, type TypedPillarMethods, type TypedTaskHandler, } from "./actions";
26
+ export { APIClient, type ArticleSummary, type ChatMessage, type ChatResponse, type ProgressEvent, } from "./api/client";
27
+ export { type ActionRequest, type ChatImage, type ImageUploadResponse, } from "./api/mcp-client";
28
+ export { DEFAULT_SCAN_OPTIONS, INTERACTABLE_ROLES, INTERACTABLE_TAGS, SKIP_TAGS, type CompactScanResult, type InteractionType, type ScanOptions, } from "./types/dom-scanner";
29
+ export { buildSelectorFromRef, clearPillarRefs, isInteractable, scanPageDirect, } from "./utils/dom-scanner";
30
+ export { generateContextId, getContextDisplayLabel, isDOMSnapshotContext, isHighlightedTextContext, type DOMSnapshotContext, type GenericContext, type HighlightedTextContext, type ProductContext, type UserContextItem, type UserProfileContext, } from "./types/user-context";
31
+ import { Pillar } from "./core/Pillar";
30
32
  export default Pillar;