@pillar-ai/sdk 0.1.13 → 0.1.15

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -44
  3. package/dist/actions/types.d.ts +39 -3
  4. package/dist/api/client.d.ts +119 -16
  5. package/dist/api/mcp-client.d.ts +137 -87
  6. package/dist/cli/sync.js +72 -13
  7. package/dist/components/DebugPanel/DebugPanel.d.ts +25 -0
  8. package/dist/components/DebugPanel/index.d.ts +2 -0
  9. package/dist/components/DevTools/index.d.ts +5 -0
  10. package/dist/components/DevTools/styles.d.ts +5 -0
  11. package/dist/components/PagePilot/PagePilotBanner.d.ts +7 -0
  12. package/dist/components/PagePilot/PagePilotManager.d.ts +42 -0
  13. package/dist/components/PagePilot/index.d.ts +7 -0
  14. package/dist/components/PagePilot/styles.d.ts +6 -0
  15. package/dist/components/Panel/Header.d.ts +3 -5
  16. package/dist/components/Panel/HistoryDropdown.d.ts +10 -0
  17. package/dist/components/Panel/PanelContent.d.ts +1 -2
  18. package/dist/components/Panel/TaskButton.d.ts +4 -14
  19. package/dist/components/Panel/UnifiedChatInput.d.ts +5 -1
  20. package/dist/components/Panel/styles.d.ts +2 -2
  21. package/dist/components/Plan/InlinePlanView.d.ts +1 -1
  22. package/dist/components/Plan/PlanDocument.d.ts +18 -0
  23. package/dist/components/Plan/PlanStepItem.d.ts +1 -1
  24. package/dist/components/Plan/PlanView.d.ts +1 -1
  25. package/dist/components/Plan/index.d.ts +1 -0
  26. package/dist/components/Progress/ProgressGroup.d.ts +20 -0
  27. package/dist/components/Progress/ProgressRow.d.ts +9 -2
  28. package/dist/components/Progress/ProgressStack.d.ts +24 -0
  29. package/dist/components/Progress/ReasoningDisclosure.d.ts +16 -0
  30. package/dist/components/Progress/index.d.ts +2 -0
  31. package/dist/components/Views/HomeView.d.ts +3 -0
  32. package/dist/components/Views/ResumePrompt.d.ts +22 -0
  33. package/dist/components/Views/index.d.ts +1 -0
  34. package/dist/components/index.d.ts +1 -0
  35. package/dist/components/shared/icons.d.ts +24 -0
  36. package/dist/components/shared/index.d.ts +1 -0
  37. package/dist/core/Pillar.d.ts +325 -70
  38. package/dist/core/config.d.ts +133 -4
  39. package/dist/core/events.d.ts +55 -70
  40. package/dist/core/plan-executor.d.ts +29 -0
  41. package/dist/core/plan.d.ts +6 -0
  42. package/dist/hooks/index.d.ts +5 -0
  43. package/dist/hooks/useDebouncedValue.d.ts +22 -0
  44. package/dist/hooks/useInlineCard.d.ts +35 -0
  45. package/dist/hooks/usePillarInstance.d.ts +30 -0
  46. package/dist/index.d.ts +11 -9
  47. package/dist/pillar.esm.js +1 -1
  48. package/dist/store/chat.d.ts +185 -25
  49. package/dist/store/index.d.ts +2 -0
  50. package/dist/store/pagePilot.d.ts +56 -0
  51. package/dist/store/session-persistence.d.ts +62 -0
  52. package/dist/store/suggestions.d.ts +58 -0
  53. package/dist/types/dom-scanner.d.ts +50 -0
  54. package/dist/types/index.d.ts +1 -0
  55. package/dist/types/user-context.d.ts +32 -1
  56. package/dist/utils/debug.d.ts +150 -0
  57. package/dist/utils/dom-scanner.d.ts +70 -0
  58. package/dist/utils/markdown-components.d.ts +53 -0
  59. package/dist/utils/preact-markdown.d.ts +17 -0
  60. package/dist/utils/route-observer.d.ts +67 -0
  61. package/package.json +1 -1
  62. package/src/actions/types.ts +43 -2
  63. package/dist/utils/markdown.d.ts +0 -9
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pillar, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -61,62 +61,61 @@ First, register your product in the [Pillar app](https://app.trypillar.com):
61
61
  ```javascript
62
62
  import { Pillar } from "@pillar-ai/sdk";
63
63
 
64
- await Pillar.init({
64
+ // Initialize and get the instance
65
+ const pillar = await Pillar.init({
65
66
  productKey: "your-product-key", // From Pillar app
66
67
  });
68
+
69
+ // Now you can use instance methods
70
+ pillar.setContext({ currentPage: "/dashboard" });
71
+ pillar.open();
72
+ ```
73
+
74
+ You can also get the instance later using `Pillar.getInstance()`:
75
+
76
+ ```javascript
77
+ // Anywhere in your app after init
78
+ const pillar = Pillar.getInstance();
79
+ pillar?.setContext({ currentPage: "/settings" });
67
80
  ```
68
81
 
69
82
  ## Defining Actions
70
83
 
71
- Define what your co-pilot can do. When users make requests, Pillar matches intent to actions and executes them:
84
+ Define what your co-pilot can do. When users make requests, Pillar matches intent to actions and executes them.
85
+
86
+ ### Register Task Handlers
87
+
88
+ Use `onTask` to handle actions when the AI executes them:
72
89
 
73
90
  ```javascript
74
- Pillar.init({
91
+ const pillar = await Pillar.init({
75
92
  productKey: "your-product-key",
76
- actions: {
77
- // Navigation actions
78
- go_to_settings: {
79
- type: "navigate",
80
- label: "Open Settings",
81
- description: "Navigate to the settings page",
82
- path: "/settings",
83
- },
93
+ });
84
94
 
85
- // Trigger actions that execute code
86
- export_to_csv: {
87
- type: "trigger",
88
- label: "Export to CSV",
89
- description: "Export current data to a CSV file",
90
- },
95
+ // Handle navigation
96
+ pillar.onTask("go_to_settings", (data) => {
97
+ router.push("/settings");
98
+ });
91
99
 
92
- // Actions with data schemas
93
- update_preferences: {
94
- type: "trigger",
95
- label: "Update Preferences",
96
- description: "Update notification preferences",
97
- dataSchema: {
98
- emailAlerts: { type: "boolean" },
99
- frequency: { type: "string", enum: ["daily", "weekly", "monthly"] },
100
- },
101
- },
102
- },
100
+ // Handle triggers
101
+ pillar.onTask("export_to_csv", async (data) => {
102
+ await downloadCSV();
103
+ });
103
104
 
104
- onTask: (actionName, data) => {
105
- // Your code executes here
106
- if (actionName === "export_to_csv") {
107
- downloadCSV();
108
- }
109
- if (actionName === "update_preferences") {
110
- updateUserPreferences(data.emailAlerts, data.frequency);
111
- }
112
- },
105
+ // Handle actions with data
106
+ pillar.onTask("update_preferences", (data) => {
107
+ updateUserPreferences(data.emailAlerts, data.frequency);
113
108
  });
114
109
  ```
115
110
 
111
+ ### Code-First Action Definitions
112
+
113
+ For production, define actions in code and sync them via the `pillar-sync` CLI during CI/CD. See [Setting Up Actions](https://trypillar.com/docs/guides/actions) for details.
114
+
116
115
  ## Configuration
117
116
 
118
117
  ```javascript
119
- Pillar.init({
118
+ const pillar = await Pillar.init({
120
119
  productKey: "your-product-key",
121
120
 
122
121
  panel: {
@@ -141,12 +140,15 @@ Pillar.init({
141
140
 
142
141
  | Method | Description |
143
142
  |--------|-------------|
144
- | `Pillar.init(config)` | Initialize the SDK with your configuration |
145
- | `Pillar.open()` | Open the co-pilot panel |
146
- | `Pillar.close()` | Close the co-pilot panel |
147
- | `Pillar.toggle()` | Toggle the co-pilot panel |
148
- | `Pillar.setContext(context)` | Update the user/product context |
149
- | `Pillar.on(event, callback)` | Subscribe to SDK events |
143
+ | `Pillar.init(config)` | Initialize the SDK, returns the instance |
144
+ | `Pillar.getInstance()` | Get the initialized SDK instance |
145
+ | `pillar.open()` | Open the co-pilot panel |
146
+ | `pillar.close()` | Close the co-pilot panel |
147
+ | `pillar.toggle()` | Toggle the co-pilot panel |
148
+ | `pillar.setContext(context)` | Update the user/product context |
149
+ | `pillar.on(event, callback)` | Subscribe to SDK events |
150
+
151
+ > **Note:** `Pillar.init()` and `Pillar.getInstance()` are static methods on the class. All other methods (lowercase `pillar`) are instance methods - call them on the instance returned from `init()` or `getInstance()`.
150
152
 
151
153
  For complete API documentation, see the [API Reference](https://trypillar.com/docs/reference/core).
152
154
 
@@ -31,12 +31,13 @@
31
31
  * - open_modal: Open a modal or dialog
32
32
  * - fill_form: Fill form fields with data
33
33
  * - trigger_action: Trigger a custom action
34
+ * - query: Fetch data from the client and return to the agent (implies returns: true)
34
35
  * - copy_text: Copy text to clipboard
35
36
  * - external_link: Open an external URL
36
37
  * - start_tutorial: Start a tutorial/walkthrough
37
38
  * - inline_ui: Display inline UI card in chat
38
39
  */
39
- export type ActionType = 'navigate' | 'open_modal' | 'fill_form' | 'trigger_action' | 'copy_text' | 'external_link' | 'start_tutorial' | 'inline_ui';
40
+ export type ActionType = 'navigate' | 'open_modal' | 'fill_form' | 'trigger_action' | 'query' | 'copy_text' | 'external_link' | 'start_tutorial' | 'inline_ui';
40
41
  /**
41
42
  * Supported platforms for action deployments.
42
43
  */
@@ -156,6 +157,18 @@ export interface ActionDefinition<TData = Record<string, unknown>> {
156
157
  * @default false
157
158
  */
158
159
  returns?: boolean;
160
+ /**
161
+ * Concrete examples of valid parameter objects for the AI to reference.
162
+ *
163
+ * Each example should have a `description` explaining the scenario
164
+ * and a `parameters` object matching the `dataSchema`.
165
+ * Useful for complex schemas where the AI benefits from seeing
166
+ * what a correct call looks like.
167
+ */
168
+ parameterExamples?: Array<{
169
+ description: string;
170
+ parameters: Record<string, unknown>;
171
+ }>;
159
172
  /**
160
173
  * Handler function executed when the action is triggered.
161
174
  *
@@ -169,7 +182,7 @@ export interface ActionDefinition<TData = Record<string, unknown>> {
169
182
  *
170
183
  * Action names should be snake_case identifiers.
171
184
  */
172
- export type ActionDefinitions = Record<string, ActionDefinition<any>>;
185
+ export type ActionDefinitions = Record<string, ActionDefinition<unknown>>;
173
186
  /**
174
187
  * Metadata for a single action in the manifest (no handler).
175
188
  *
@@ -188,6 +201,10 @@ export interface ActionManifestEntry {
188
201
  data_schema?: ActionDataSchema;
189
202
  default_data?: Record<string, unknown>;
190
203
  required_context?: Record<string, unknown>;
204
+ parameter_examples?: Array<{
205
+ description: string;
206
+ parameters: Record<string, unknown>;
207
+ }>;
191
208
  }
192
209
  /**
193
210
  * Action manifest - synced to server during CI/CD.
@@ -215,6 +232,11 @@ export interface ActionManifest {
215
232
  * Action definitions (without handlers).
216
233
  */
217
234
  actions: ActionManifestEntry[];
235
+ /**
236
+ * Custom agent guidance synced alongside actions.
237
+ * Injected into the AI agent's prompt as product_guidance.
238
+ */
239
+ agentGuidance?: string;
218
240
  }
219
241
  /**
220
242
  * Client info set during SDK initialization.
@@ -269,13 +291,22 @@ export interface SyncActionDefinition<TData = Record<string, unknown>> {
269
291
  * If true, the handler's return value is sent back to the agent.
270
292
  */
271
293
  returns?: boolean;
294
+ /**
295
+ * Concrete examples of valid parameter objects for the AI to reference.
296
+ * Each example should have a `description` and a `parameters` object
297
+ * matching the `dataSchema`.
298
+ */
299
+ parameterExamples?: Array<{
300
+ description: string;
301
+ parameters: Record<string, unknown>;
302
+ }>;
272
303
  }
273
304
  /**
274
305
  * Map of action name to sync definition (no handlers).
275
306
  *
276
307
  * Use this type for your actions file that gets synced via CI/CD.
277
308
  */
278
- export type SyncActionDefinitions = Record<string, SyncActionDefinition<any>>;
309
+ export type SyncActionDefinitions = Record<string, SyncActionDefinition<unknown>>;
279
310
  /**
280
311
  * Base data types for each action type.
281
312
  * These are automatically inferred from the action's `type` field.
@@ -306,6 +337,10 @@ export interface CopyTextData {
306
337
  /** Text to copy to clipboard */
307
338
  text?: string;
308
339
  }
340
+ export interface QueryActionData {
341
+ /** Query parameters passed to the handler */
342
+ [key: string]: unknown;
343
+ }
309
344
  /**
310
345
  * Maps action types to their default data shapes.
311
346
  * Used for automatic type inference in onTask handlers.
@@ -313,6 +348,7 @@ export interface CopyTextData {
313
348
  export interface ActionTypeDataMap {
314
349
  navigate: NavigateActionData;
315
350
  trigger_action: TriggerActionData;
351
+ query: QueryActionData;
316
352
  inline_ui: InlineUIData;
317
353
  external_link: ExternalLinkData;
318
354
  copy_text: CopyTextData;
@@ -5,10 +5,10 @@
5
5
  import type { TaskButtonData } from '../components/Panel/TaskButton';
6
6
  import type { ResolvedConfig } from '../core/config';
7
7
  import type { Context, Suggestion, UserProfile } from '../core/context';
8
- import type { ExecutionPlan } from '../core/plan';
9
8
  import type { Workflow } from '../core/workflow';
10
9
  import type { UserContextItem } from '../types/user-context';
11
- import type { ChatImage, ImageUploadResponse } from './mcp-client';
10
+ import type { ActionRequest, ChatImage, ImageUploadResponse } from './mcp-client';
11
+ import { MCPClient } from './mcp-client';
12
12
  export interface ArticleSummary {
13
13
  id: string;
14
14
  title: string;
@@ -23,6 +23,8 @@ export interface ChatMessage {
23
23
  export interface SuggestedQuestion {
24
24
  id: string;
25
25
  text: string;
26
+ /** If true, this is an admin-configured suggestion that should rank first */
27
+ manual?: boolean;
26
28
  }
27
29
  export interface ChatResponse {
28
30
  message: string;
@@ -32,21 +34,31 @@ export interface ChatResponse {
32
34
  messageId?: string;
33
35
  actions?: TaskButtonData[];
34
36
  }
37
+ /**
38
+ * Child item within a progress event (e.g., search source, plan step).
39
+ */
40
+ export interface ProgressChild {
41
+ id: string;
42
+ label: string;
43
+ url?: string;
44
+ }
45
+ /**
46
+ * Progress event for tracking AI response generation steps.
47
+ * Uses a generic design where the server controls display text via `label`.
48
+ *
49
+ * The new schema uses `id` and `status` fields. Legacy fields are kept
50
+ * for backwards compatibility with older backend versions.
51
+ */
35
52
  export interface ProgressEvent {
36
- kind: 'processing' | 'search' | 'search_complete' | 'query' | 'query_complete' | 'query_failed' | 'generating';
37
- message?: string;
53
+ kind: string;
54
+ id?: string;
55
+ label?: string;
56
+ status?: 'active' | 'done' | 'error';
57
+ text?: string;
58
+ children?: ProgressChild[];
59
+ metadata?: Record<string, unknown>;
38
60
  progress_id?: string;
39
- metadata?: {
40
- sources?: Array<{
41
- title: string;
42
- url: string;
43
- score?: number;
44
- }>;
45
- result_count?: number;
46
- query?: string;
47
- action_name?: string;
48
- no_sources_used?: boolean;
49
- };
61
+ message?: string;
50
62
  }
51
63
  /**
52
64
  * Server-side embed config response.
@@ -69,12 +81,76 @@ export interface ServerEmbedConfig {
69
81
  };
70
82
  };
71
83
  }
84
+ /**
85
+ * Conversation summary in history list.
86
+ */
87
+ export interface ConversationSummary {
88
+ id: string;
89
+ title: string;
90
+ startedAt: string | null;
91
+ lastMessageAt: string | null;
92
+ messageCount: number;
93
+ }
94
+ /**
95
+ * Display step in the agent's timeline.
96
+ * This is a human-readable timeline that includes thinking, tool decisions, and tool results.
97
+ * Used for UI display of the agent's reasoning process.
98
+ */
99
+ export interface DisplayStep {
100
+ step_type: 'thinking' | 'tool_decision' | 'parallel_tool_decision' | 'tool_result' | 'token_summary' | 'step_start' | 'generating' | 'narration';
101
+ iteration?: number;
102
+ timestamp_ms?: number;
103
+ content?: string;
104
+ tool?: string;
105
+ tools?: Array<{
106
+ tool: string;
107
+ arguments: Record<string, unknown>;
108
+ }>;
109
+ arguments?: Record<string, unknown>;
110
+ success?: boolean;
111
+ reasoning?: string;
112
+ label?: string;
113
+ [key: string]: unknown;
114
+ }
115
+ /**
116
+ * Message in conversation history.
117
+ * Contains display-oriented fields for UI rendering.
118
+ * LLM-native fields (llm_message) are kept server-side for conversation replay.
119
+ */
120
+ export interface HistoryMessage {
121
+ id: string;
122
+ role: 'user' | 'assistant';
123
+ content: string;
124
+ timestamp: string | null;
125
+ display_trace?: DisplayStep[];
126
+ }
127
+ /**
128
+ * Full conversation with messages.
129
+ */
130
+ export interface ConversationDetail extends ConversationSummary {
131
+ messages: HistoryMessage[];
132
+ }
72
133
  export declare class APIClient {
73
134
  private config;
74
135
  private abortControllers;
75
136
  private mcpClient;
137
+ private _externalUserId;
76
138
  constructor(config: ResolvedConfig);
139
+ /**
140
+ * Get the underlying MCP client.
141
+ * Used by Pillar for direct MCP operations like sendActionResult.
142
+ */
143
+ get mcp(): MCPClient;
77
144
  private get baseUrl();
145
+ /**
146
+ * Set the external user ID for authenticated users.
147
+ * This ID will be included in all subsequent requests.
148
+ */
149
+ setExternalUserId(userId: string): void;
150
+ /**
151
+ * Clear the external user ID (for logout).
152
+ */
153
+ clearExternalUserId(): void;
78
154
  /**
79
155
  * Get or create a persistent visitor ID.
80
156
  * Stored in localStorage to persist across sessions.
@@ -110,7 +186,7 @@ export declare class APIClient {
110
186
  * @returns Promise with signed URL and expiration
111
187
  */
112
188
  uploadImage(file: File): Promise<ImageUploadResponse>;
113
- chat(message: string, history?: ChatMessage[], onChunk?: (chunk: string) => void, articleSlug?: string, existingConversationId?: string | null, onActions?: (actions: TaskButtonData[]) => void, onPlan?: (plan: ExecutionPlan) => void, userContext?: UserContextItem[], images?: ChatImage[], onProgress?: (progress: ProgressEvent) => void): Promise<ChatResponse>;
189
+ chat(message: string, history?: ChatMessage[], onChunk?: (chunk: string) => void, articleSlug?: string, existingConversationId?: string | null, onActions?: (actions: TaskButtonData[]) => void, userContext?: UserContextItem[], images?: ChatImage[], onProgress?: (progress: ProgressEvent) => void, onConversationStarted?: (conversationId: string, assistantMessageId?: string) => void, onActionRequest?: (request: ActionRequest) => Promise<void>, signal?: AbortSignal, onRequestId?: (requestId: number) => void): Promise<ChatResponse>;
114
190
  /**
115
191
  * Legacy chat method using the old /ai/chat/ endpoint.
116
192
  * @deprecated Use chat() which uses the MCP protocol.
@@ -154,5 +230,32 @@ export declare class APIClient {
154
230
  * Note: Context is passed to the MCP ask tool as additional arguments.
155
231
  */
156
232
  chatWithContext(message: string, history: ChatMessage[] | undefined, ctx: Context, userProfile: UserProfile, onChunk?: (chunk: string) => void, existingConversationId?: string | null, onActions?: (actions: TaskButtonData[]) => void): Promise<ChatResponse>;
233
+ /**
234
+ * Identify the current user after login.
235
+ * Links the anonymous visitor to the authenticated user ID, enabling
236
+ * cross-device conversation history.
237
+ *
238
+ * @param userId - Client's authenticated user ID
239
+ * @param profile - Optional user profile data
240
+ */
241
+ identify(userId: string, profile?: {
242
+ name?: string;
243
+ email?: string;
244
+ metadata?: Record<string, unknown>;
245
+ }): Promise<void>;
246
+ /**
247
+ * List past conversations for the current visitor.
248
+ *
249
+ * @param limit - Max number of conversations to return (default: 20, max: 50)
250
+ * @returns List of conversation summaries
251
+ */
252
+ listConversations(limit?: number): Promise<ConversationSummary[]>;
253
+ /**
254
+ * Get a single conversation with all messages.
255
+ *
256
+ * @param conversationId - UUID of the conversation
257
+ * @returns Conversation with messages
258
+ */
259
+ getConversation(conversationId: string): Promise<ConversationDetail | null>;
157
260
  cancelAllRequests(): void;
158
261
  }