@pillar-ai/sdk 0.1.0
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/README.md +129 -0
- package/dist/actions/definitions/analytics.d.ts +18 -0
- package/dist/actions/definitions/content.d.ts +40 -0
- package/dist/actions/definitions/index.d.ts +26 -0
- package/dist/actions/definitions/navigation.d.ts +65 -0
- package/dist/actions/definitions/settings.d.ts +162 -0
- package/dist/actions/definitions/sources.d.ts +44 -0
- package/dist/actions/definitions/support.d.ts +15 -0
- package/dist/actions/definitions/team.d.ts +120 -0
- package/dist/actions/index.d.ts +33 -0
- package/dist/actions/registry.d.ts +110 -0
- package/dist/actions/types.d.ts +388 -0
- package/dist/api/client.d.ts +186 -0
- package/dist/api/mcp-client.d.ts +226 -0
- package/dist/button/FloatingButton.d.ts +44 -0
- package/dist/cli/sync.d.ts +2 -0
- package/dist/components/Button/EdgeTrigger.d.ts +78 -0
- package/dist/components/Button/FloatingButton.d.ts +46 -0
- package/dist/components/Button/index.d.ts +5 -0
- package/dist/components/Cards/ConfirmActionCard.d.ts +23 -0
- package/dist/components/Cards/index.d.ts +6 -0
- package/dist/components/Panel/ChatInput.d.ts +5 -0
- package/dist/components/Panel/ContextTag.d.ts +18 -0
- package/dist/components/Panel/Header.d.ts +14 -0
- package/dist/components/Panel/Panel.d.ts +104 -0
- package/dist/components/Panel/PanelContent.d.ts +6 -0
- package/dist/components/Panel/TaskButton.d.ts +59 -0
- package/dist/components/Panel/UnifiedChatInput.d.ts +23 -0
- package/dist/components/Panel/WorkflowChecklist.d.ts +9 -0
- package/dist/components/Panel/index.d.ts +13 -0
- package/dist/components/Panel/styles.d.ts +20 -0
- package/dist/components/Plan/InlinePlanView.d.ts +24 -0
- package/dist/components/Plan/PlanStepItem.d.ts +18 -0
- package/dist/components/Plan/PlanView.d.ts +10 -0
- package/dist/components/Plan/index.d.ts +8 -0
- package/dist/components/TextSelection/TextSelectionManager.d.ts +34 -0
- package/dist/components/TextSelection/TextSelectionPopover.d.ts +14 -0
- package/dist/components/TextSelection/index.d.ts +6 -0
- package/dist/components/TextSelection/styles.d.ts +5 -0
- package/dist/components/Tooltips/Tooltip.d.ts +46 -0
- package/dist/components/Tooltips/TooltipManager.d.ts +41 -0
- package/dist/components/Tooltips/index.d.ts +6 -0
- package/dist/components/Tooltips/styles.d.ts +5 -0
- package/dist/components/Views/ArticleChatView.d.ts +9 -0
- package/dist/components/Views/ArticleView.d.ts +10 -0
- package/dist/components/Views/CategoryView.d.ts +11 -0
- package/dist/components/Views/ChatView.d.ts +5 -0
- package/dist/components/Views/DeveloperView.d.ts +6 -0
- package/dist/components/Views/HomeView.d.ts +5 -0
- package/dist/components/Views/SearchView.d.ts +10 -0
- package/dist/components/Views/index.d.ts +5 -0
- package/dist/components/context.d.ts +21 -0
- package/dist/components/index.d.ts +9 -0
- package/dist/components/shared/ArticleCard.d.ts +17 -0
- package/dist/components/shared/CategoryCard.d.ts +17 -0
- package/dist/components/shared/Empty.d.ts +11 -0
- package/dist/components/shared/Loading.d.ts +6 -0
- package/dist/components/shared/MessageInputArea.d.ts +19 -0
- package/dist/components/shared/QuestionChip.d.ts +14 -0
- package/dist/components/shared/index.d.ts +7 -0
- package/dist/content/extensions/AccordionNode.d.ts +10 -0
- package/dist/content/extensions/CalloutNode.d.ts +11 -0
- package/dist/content/extensions/index.d.ts +5 -0
- package/dist/content/index.d.ts +5 -0
- package/dist/content/renderer.d.ts +24 -0
- package/dist/core/Pillar.d.ts +454 -0
- package/dist/core/config.d.ts +253 -0
- package/dist/core/context.d.ts +71 -0
- package/dist/core/events.d.ts +228 -0
- package/dist/core/plan-executor.d.ts +101 -0
- package/dist/core/plan.d.ts +155 -0
- package/dist/core/workflow.d.ts +89 -0
- package/dist/index.d.ts +32 -0
- package/dist/panel/Panel.d.ts +53 -0
- package/dist/panel/PanelUI.d.ts +43 -0
- package/dist/panel/components/ArticleCard.d.ts +10 -0
- package/dist/panel/components/CategoryCard.d.ts +10 -0
- package/dist/panel/components/ChatInput.d.ts +36 -0
- package/dist/panel/components/Header.d.ts +16 -0
- package/dist/panel/components/SearchInput.d.ts +11 -0
- package/dist/panel/styles.d.ts +5 -0
- package/dist/panel/views/ArticleView.d.ts +21 -0
- package/dist/panel/views/CategoryView.d.ts +20 -0
- package/dist/panel/views/ChatView.d.ts +30 -0
- package/dist/panel/views/HomeView.d.ts +18 -0
- package/dist/panel/views/SearchView.d.ts +22 -0
- package/dist/pillar.esm.js +10338 -0
- package/dist/pillar.esm.js.map +1 -0
- package/dist/pillar.js +10362 -0
- package/dist/pillar.js.map +1 -0
- package/dist/pillar.min.js +2 -0
- package/dist/pillar.min.js.map +1 -0
- package/dist/store/chat.d.ts +85 -0
- package/dist/store/context.d.ts +46 -0
- package/dist/store/developer.d.ts +19 -0
- package/dist/store/index.d.ts +10 -0
- package/dist/store/panel.d.ts +43 -0
- package/dist/store/plan-persistence.d.ts +47 -0
- package/dist/store/plan.d.ts +45 -0
- package/dist/store/router.d.ts +18 -0
- package/dist/store/tooltips.d.ts +21 -0
- package/dist/store/workflow.d.ts +48 -0
- package/dist/tooltips/Tooltip.d.ts +63 -0
- package/dist/tooltips/TooltipManager.d.ts +42 -0
- package/dist/tooltips/styles.d.ts +5 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/user-context.d.ts +29 -0
- package/dist/utils/dom.d.ts +46 -0
- package/dist/utils/markdown.d.ts +9 -0
- package/dist/utils/positioning.d.ts +52 -0
- package/dist/utils/urlParams.d.ts +27 -0
- package/package.json +86 -0
- package/src/actions/types.ts +468 -0
- package/src/cli/sync.ts +477 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action Registry - Manages code-defined action handlers.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the registration and lookup mechanism for
|
|
5
|
+
* actions defined in code. Actions are registered using `defineActions()`
|
|
6
|
+
* and can be looked up by name using `getHandler()`.
|
|
7
|
+
*
|
|
8
|
+
* The registry also generates the manifest that gets synced to the server
|
|
9
|
+
* during CI/CD builds.
|
|
10
|
+
*/
|
|
11
|
+
import type { ActionDefinition, ActionDefinitions, ActionManifest, ClientInfo, Platform } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Define and register actions with the SDK.
|
|
14
|
+
*
|
|
15
|
+
* Call this during app initialization to register your action handlers.
|
|
16
|
+
* The metadata will be synced to the server during CI/CD builds.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { defineActions } from '@pillar-ai/sdk/actions';
|
|
21
|
+
* import { router } from './router';
|
|
22
|
+
*
|
|
23
|
+
* export const actions = defineActions({
|
|
24
|
+
* open_settings: {
|
|
25
|
+
* description: 'Navigate to the settings page',
|
|
26
|
+
* type: 'navigate',
|
|
27
|
+
* path: '/settings',
|
|
28
|
+
* handler: () => router.push('/settings'),
|
|
29
|
+
* },
|
|
30
|
+
* open_billing: {
|
|
31
|
+
* description: 'Navigate to billing and subscription management',
|
|
32
|
+
* type: 'navigate',
|
|
33
|
+
* path: '/settings/billing',
|
|
34
|
+
* autoRun: true,
|
|
35
|
+
* handler: (data) => router.push('/settings/billing', data),
|
|
36
|
+
* },
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param actions - Map of action name to definition
|
|
41
|
+
* @returns The same actions object (for re-export convenience)
|
|
42
|
+
*/
|
|
43
|
+
export declare function defineActions<T extends ActionDefinitions>(actions: T): T;
|
|
44
|
+
/**
|
|
45
|
+
* Set client platform and version info.
|
|
46
|
+
*
|
|
47
|
+
* Called internally by Pillar.init() to set platform/version
|
|
48
|
+
* for API requests.
|
|
49
|
+
*
|
|
50
|
+
* @param platform - Platform identifier (web, ios, android, desktop)
|
|
51
|
+
* @param version - App version (semver or git SHA)
|
|
52
|
+
*/
|
|
53
|
+
export declare function setClientInfo(platform: Platform, version: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get the current client info.
|
|
56
|
+
*
|
|
57
|
+
* @returns Client info or null if not set
|
|
58
|
+
*/
|
|
59
|
+
export declare function getClientInfo(): ClientInfo | null;
|
|
60
|
+
/**
|
|
61
|
+
* Get a registered action handler by name.
|
|
62
|
+
*
|
|
63
|
+
* @param name - Action name (e.g., "open_settings")
|
|
64
|
+
* @returns Handler function or undefined if not found
|
|
65
|
+
*/
|
|
66
|
+
export declare function getHandler(name: string): ActionDefinition['handler'] | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Get a registered action definition by name.
|
|
69
|
+
*
|
|
70
|
+
* @param name - Action name
|
|
71
|
+
* @returns Action definition or undefined if not found
|
|
72
|
+
*/
|
|
73
|
+
export declare function getActionDefinition(name: string): ActionDefinition | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Check if an action is registered.
|
|
76
|
+
*
|
|
77
|
+
* @param name - Action name
|
|
78
|
+
* @returns True if registered
|
|
79
|
+
*/
|
|
80
|
+
export declare function hasAction(name: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Get all registered action names.
|
|
83
|
+
*
|
|
84
|
+
* @returns Array of action names
|
|
85
|
+
*/
|
|
86
|
+
export declare function getActionNames(): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Get the action manifest for syncing to the server.
|
|
89
|
+
*
|
|
90
|
+
* Extracts metadata from all registered actions (without handlers)
|
|
91
|
+
* for sending to the Pillar server during CI/CD.
|
|
92
|
+
*
|
|
93
|
+
* @param platform - Platform to include in manifest
|
|
94
|
+
* @param version - Version to include in manifest
|
|
95
|
+
* @param gitSha - Optional git commit SHA
|
|
96
|
+
* @returns Action manifest object
|
|
97
|
+
*/
|
|
98
|
+
export declare function getManifest(platform: Platform, version: string, gitSha?: string): ActionManifest;
|
|
99
|
+
/**
|
|
100
|
+
* Clear all registered actions.
|
|
101
|
+
*
|
|
102
|
+
* Primarily for testing purposes.
|
|
103
|
+
*/
|
|
104
|
+
export declare function clearRegistry(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Get the count of registered actions.
|
|
107
|
+
*
|
|
108
|
+
* @returns Number of registered actions
|
|
109
|
+
*/
|
|
110
|
+
export declare function getActionCount(): number;
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action Types - Type definitions for code-first action definitions.
|
|
3
|
+
*
|
|
4
|
+
* These types enable developers to define actions in their application code
|
|
5
|
+
* rather than in the admin UI, with full TypeScript support.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { defineActions } from '@pillar-ai/sdk/actions';
|
|
10
|
+
*
|
|
11
|
+
* const actions = defineActions({
|
|
12
|
+
* open_settings: {
|
|
13
|
+
* description: 'Navigate to the settings page',
|
|
14
|
+
* type: 'navigate',
|
|
15
|
+
* path: '/settings',
|
|
16
|
+
* handler: () => router.push('/settings'),
|
|
17
|
+
* },
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Supported action types.
|
|
23
|
+
*
|
|
24
|
+
* - navigate: Navigate to a page within the app
|
|
25
|
+
* - open_modal: Open a modal or dialog
|
|
26
|
+
* - fill_form: Fill form fields with data
|
|
27
|
+
* - trigger_action: Trigger a custom action
|
|
28
|
+
* - copy_text: Copy text to clipboard
|
|
29
|
+
* - external_link: Open an external URL
|
|
30
|
+
* - start_tutorial: Start a tutorial/walkthrough
|
|
31
|
+
* - inline_ui: Display inline UI card in chat
|
|
32
|
+
*/
|
|
33
|
+
export type ActionType = 'navigate' | 'open_modal' | 'fill_form' | 'trigger_action' | 'copy_text' | 'external_link' | 'start_tutorial' | 'inline_ui';
|
|
34
|
+
/**
|
|
35
|
+
* Supported platforms for action deployments.
|
|
36
|
+
*/
|
|
37
|
+
export type Platform = 'web' | 'ios' | 'android' | 'desktop';
|
|
38
|
+
/**
|
|
39
|
+
* JSON Schema definition for action data.
|
|
40
|
+
*
|
|
41
|
+
* When provided, the AI will extract data from the user's query
|
|
42
|
+
* and populate the action's data field before execution.
|
|
43
|
+
*/
|
|
44
|
+
export interface ActionDataSchema {
|
|
45
|
+
type: 'object';
|
|
46
|
+
properties: Record<string, {
|
|
47
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
48
|
+
description?: string;
|
|
49
|
+
enum?: string[];
|
|
50
|
+
default?: unknown;
|
|
51
|
+
}>;
|
|
52
|
+
required?: string[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Definition for a single action.
|
|
56
|
+
*
|
|
57
|
+
* Actions are defined in code and synced to the server during CI/CD.
|
|
58
|
+
* The server stores the metadata, and the SDK executes the handler locally.
|
|
59
|
+
*
|
|
60
|
+
* @template TData - Type for the data passed to the handler
|
|
61
|
+
*/
|
|
62
|
+
export interface ActionDefinition<TData = Record<string, unknown>> {
|
|
63
|
+
/**
|
|
64
|
+
* Human-readable description for AI matching.
|
|
65
|
+
*
|
|
66
|
+
* The AI uses semantic similarity to match user queries to this description.
|
|
67
|
+
* Be specific about when this action should be suggested.
|
|
68
|
+
*
|
|
69
|
+
* @example "Navigate to the billing page. Suggest when user asks about payments, invoices, or subscription."
|
|
70
|
+
*/
|
|
71
|
+
description: string;
|
|
72
|
+
/**
|
|
73
|
+
* Example user queries that should trigger this action.
|
|
74
|
+
*
|
|
75
|
+
* Provide 3-5 natural phrasings users might say:
|
|
76
|
+
* - Imperative: "open settings", "go to billing"
|
|
77
|
+
* - Questions: "where can I change my password?"
|
|
78
|
+
* - Informal: "settings", "show analytics"
|
|
79
|
+
*
|
|
80
|
+
* These are embedded and used for semantic matching alongside the description.
|
|
81
|
+
*/
|
|
82
|
+
examples?: string[];
|
|
83
|
+
/**
|
|
84
|
+
* Type of action - determines how the SDK handles it.
|
|
85
|
+
*/
|
|
86
|
+
type: ActionType;
|
|
87
|
+
/**
|
|
88
|
+
* Path for navigate actions.
|
|
89
|
+
*
|
|
90
|
+
* Can include template variables like `/users/{userId}`.
|
|
91
|
+
*/
|
|
92
|
+
path?: string;
|
|
93
|
+
/**
|
|
94
|
+
* External URL for external_link actions.
|
|
95
|
+
*/
|
|
96
|
+
externalUrl?: string;
|
|
97
|
+
/**
|
|
98
|
+
* JSON Schema for data extraction from user query.
|
|
99
|
+
*
|
|
100
|
+
* When provided, the AI will attempt to extract structured data
|
|
101
|
+
* from the conversation before executing the action.
|
|
102
|
+
*/
|
|
103
|
+
dataSchema?: ActionDataSchema;
|
|
104
|
+
/**
|
|
105
|
+
* Default data to pass to the handler.
|
|
106
|
+
*/
|
|
107
|
+
defaultData?: TData;
|
|
108
|
+
/**
|
|
109
|
+
* Context required for this action to be available.
|
|
110
|
+
*
|
|
111
|
+
* @example { loggedIn: true, plan: 'pro' }
|
|
112
|
+
*/
|
|
113
|
+
requiredContext?: Record<string, unknown>;
|
|
114
|
+
/**
|
|
115
|
+
* Whether to auto-run this action without user confirmation.
|
|
116
|
+
*
|
|
117
|
+
* Only the highest-scoring action can auto-run.
|
|
118
|
+
* Use for simple navigations where user intent is clear.
|
|
119
|
+
*
|
|
120
|
+
* @default false
|
|
121
|
+
*/
|
|
122
|
+
autoRun?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Whether the action completes immediately after execution.
|
|
125
|
+
*
|
|
126
|
+
* If false, the SDK waits for host app confirmation.
|
|
127
|
+
* Use true for simple navigations and clipboard operations.
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
autoComplete?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Whether this action returns data for the agent.
|
|
134
|
+
*
|
|
135
|
+
* If true, the handler's return value is sent back to the agent
|
|
136
|
+
* for further reasoning. Use for query/lookup actions that inform
|
|
137
|
+
* the agent's next decision.
|
|
138
|
+
*
|
|
139
|
+
* @default false
|
|
140
|
+
*/
|
|
141
|
+
returns?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Handler function executed when the action is triggered.
|
|
144
|
+
*
|
|
145
|
+
* This runs in the client - the server only stores metadata.
|
|
146
|
+
* If `returns: true`, the return value is sent to the agent.
|
|
147
|
+
*/
|
|
148
|
+
handler: (data: TData) => void | unknown | Promise<void | unknown>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Map of action name to definition.
|
|
152
|
+
*
|
|
153
|
+
* Action names should be snake_case identifiers.
|
|
154
|
+
*/
|
|
155
|
+
export type ActionDefinitions = Record<string, ActionDefinition<any>>;
|
|
156
|
+
/**
|
|
157
|
+
* Metadata for a single action in the manifest (no handler).
|
|
158
|
+
*
|
|
159
|
+
* This is what gets synced to the server.
|
|
160
|
+
*/
|
|
161
|
+
export interface ActionManifestEntry {
|
|
162
|
+
name: string;
|
|
163
|
+
description: string;
|
|
164
|
+
examples?: string[];
|
|
165
|
+
type: ActionType;
|
|
166
|
+
path?: string;
|
|
167
|
+
external_url?: string;
|
|
168
|
+
auto_run?: boolean;
|
|
169
|
+
auto_complete?: boolean;
|
|
170
|
+
returns_data?: boolean;
|
|
171
|
+
data_schema?: ActionDataSchema;
|
|
172
|
+
default_data?: Record<string, unknown>;
|
|
173
|
+
required_context?: Record<string, unknown>;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Action manifest - synced to server during CI/CD.
|
|
177
|
+
*
|
|
178
|
+
* Contains all action metadata without handlers.
|
|
179
|
+
*/
|
|
180
|
+
export interface ActionManifest {
|
|
181
|
+
/**
|
|
182
|
+
* Platform this manifest is for.
|
|
183
|
+
*/
|
|
184
|
+
platform: Platform;
|
|
185
|
+
/**
|
|
186
|
+
* Version of the client app (semver or git SHA).
|
|
187
|
+
*/
|
|
188
|
+
version: string;
|
|
189
|
+
/**
|
|
190
|
+
* Git commit SHA for traceability.
|
|
191
|
+
*/
|
|
192
|
+
gitSha?: string;
|
|
193
|
+
/**
|
|
194
|
+
* When this manifest was generated.
|
|
195
|
+
*/
|
|
196
|
+
generatedAt: string;
|
|
197
|
+
/**
|
|
198
|
+
* Action definitions (without handlers).
|
|
199
|
+
*/
|
|
200
|
+
actions: ActionManifestEntry[];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Client info set during SDK initialization.
|
|
204
|
+
*/
|
|
205
|
+
export interface ClientInfo {
|
|
206
|
+
platform: Platform;
|
|
207
|
+
version: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Action definition for syncing (without handler).
|
|
211
|
+
*
|
|
212
|
+
* Use this type when defining actions for CI/CD sync.
|
|
213
|
+
* Handlers are registered separately at runtime via pillar.onTask().
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* import type { SyncActionDefinitions } from '@pillar-ai/sdk';
|
|
218
|
+
*
|
|
219
|
+
* export const actions: SyncActionDefinitions = {
|
|
220
|
+
* open_settings: {
|
|
221
|
+
* description: 'Navigate to settings page',
|
|
222
|
+
* type: 'navigate',
|
|
223
|
+
* path: '/settings',
|
|
224
|
+
* autoRun: true,
|
|
225
|
+
* },
|
|
226
|
+
* };
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
export interface SyncActionDefinition<TData = Record<string, unknown>> {
|
|
230
|
+
/** Human-readable description for AI matching */
|
|
231
|
+
description: string;
|
|
232
|
+
/** Example user queries that should trigger this action */
|
|
233
|
+
examples?: string[];
|
|
234
|
+
/** Type of action */
|
|
235
|
+
type: ActionType;
|
|
236
|
+
/** Path for navigate actions */
|
|
237
|
+
path?: string;
|
|
238
|
+
/** External URL for external_link actions */
|
|
239
|
+
externalUrl?: string;
|
|
240
|
+
/** JSON Schema for data extraction from user query */
|
|
241
|
+
dataSchema?: ActionDataSchema;
|
|
242
|
+
/** Default data to pass to the handler */
|
|
243
|
+
defaultData?: TData;
|
|
244
|
+
/** Context required for this action to be available */
|
|
245
|
+
requiredContext?: Record<string, unknown>;
|
|
246
|
+
/** Whether to auto-run this action without user confirmation */
|
|
247
|
+
autoRun?: boolean;
|
|
248
|
+
/** Whether the action completes immediately after execution */
|
|
249
|
+
autoComplete?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Whether this action returns data for the agent.
|
|
252
|
+
* If true, the handler's return value is sent back to the agent.
|
|
253
|
+
*/
|
|
254
|
+
returns?: boolean;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Map of action name to sync definition (no handlers).
|
|
258
|
+
*
|
|
259
|
+
* Use this type for your actions file that gets synced via CI/CD.
|
|
260
|
+
*/
|
|
261
|
+
export type SyncActionDefinitions = Record<string, SyncActionDefinition<any>>;
|
|
262
|
+
/**
|
|
263
|
+
* Base data types for each action type.
|
|
264
|
+
* These are automatically inferred from the action's `type` field.
|
|
265
|
+
*/
|
|
266
|
+
export interface NavigateActionData {
|
|
267
|
+
/** CSS selector to highlight after navigation */
|
|
268
|
+
highlight_selector?: string;
|
|
269
|
+
/** Path that was navigated to (injected by SDK) */
|
|
270
|
+
path?: string;
|
|
271
|
+
}
|
|
272
|
+
export interface TriggerActionData {
|
|
273
|
+
/** The action being triggered */
|
|
274
|
+
action?: string;
|
|
275
|
+
/** Additional action parameters */
|
|
276
|
+
[key: string]: unknown;
|
|
277
|
+
}
|
|
278
|
+
export interface InlineUIData {
|
|
279
|
+
/** Card type for rendering */
|
|
280
|
+
card_type: string;
|
|
281
|
+
/** Additional card data */
|
|
282
|
+
[key: string]: unknown;
|
|
283
|
+
}
|
|
284
|
+
export interface ExternalLinkData {
|
|
285
|
+
/** The URL being opened */
|
|
286
|
+
url?: string;
|
|
287
|
+
}
|
|
288
|
+
export interface CopyTextData {
|
|
289
|
+
/** Text to copy to clipboard */
|
|
290
|
+
text?: string;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Maps action types to their default data shapes.
|
|
294
|
+
* Used for automatic type inference in onTask handlers.
|
|
295
|
+
*/
|
|
296
|
+
export interface ActionTypeDataMap {
|
|
297
|
+
navigate: NavigateActionData;
|
|
298
|
+
trigger_action: TriggerActionData;
|
|
299
|
+
inline_ui: InlineUIData;
|
|
300
|
+
external_link: ExternalLinkData;
|
|
301
|
+
copy_text: CopyTextData;
|
|
302
|
+
open_modal: Record<string, unknown>;
|
|
303
|
+
fill_form: Record<string, unknown>;
|
|
304
|
+
start_tutorial: Record<string, unknown>;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Extract the data type for a specific action from an ActionDefinitions map.
|
|
308
|
+
*
|
|
309
|
+
* Type inference priority:
|
|
310
|
+
* 1. If `defaultData` is defined, use that type (for custom fields)
|
|
311
|
+
* 2. Otherwise, infer from the action's `type` field using ActionTypeDataMap
|
|
312
|
+
* 3. Fall back to Record<string, unknown>
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* const actions = {
|
|
317
|
+
* // Inferred from type: "navigate" → NavigateActionData
|
|
318
|
+
* open_settings: {
|
|
319
|
+
* description: '...',
|
|
320
|
+
* type: 'navigate',
|
|
321
|
+
* path: '/settings',
|
|
322
|
+
* },
|
|
323
|
+
* // Custom data via defaultData
|
|
324
|
+
* add_source: {
|
|
325
|
+
* description: '...',
|
|
326
|
+
* type: 'navigate',
|
|
327
|
+
* defaultData: { type: '', url: '', name: '' },
|
|
328
|
+
* },
|
|
329
|
+
* } as const satisfies SyncActionDefinitions;
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export type ActionDataType<TActions extends SyncActionDefinitions | ActionDefinitions, TName extends keyof TActions> = TActions[TName] extends {
|
|
333
|
+
defaultData: infer D;
|
|
334
|
+
} ? D extends Record<string, unknown> ? D : Record<string, unknown> : TActions[TName] extends {
|
|
335
|
+
type: infer T;
|
|
336
|
+
} ? T extends keyof ActionTypeDataMap ? ActionTypeDataMap[T] : Record<string, unknown> : Record<string, unknown>;
|
|
337
|
+
/**
|
|
338
|
+
* Extract all action names from an ActionDefinitions map.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* const actions = { open_settings: {...}, add_source: {...} };
|
|
343
|
+
* type Names = ActionNames<typeof actions>; // 'open_settings' | 'add_source'
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
export type ActionNames<T extends SyncActionDefinitions | ActionDefinitions> = Extract<keyof T, string>;
|
|
347
|
+
/**
|
|
348
|
+
* Typed task handler function.
|
|
349
|
+
*
|
|
350
|
+
* @template TData - The data type for this action
|
|
351
|
+
*/
|
|
352
|
+
export type TypedTaskHandler<TData = Record<string, unknown>> = (data: TData) => void | Promise<void>;
|
|
353
|
+
/**
|
|
354
|
+
* Type-safe onTask method signature.
|
|
355
|
+
*
|
|
356
|
+
* When actions are provided to PillarProvider, this type enables
|
|
357
|
+
* TypeScript to infer the correct data type for each action handler.
|
|
358
|
+
*
|
|
359
|
+
* @template TActions - The action definitions map
|
|
360
|
+
*/
|
|
361
|
+
export interface TypedOnTask<TActions extends SyncActionDefinitions | ActionDefinitions> {
|
|
362
|
+
<TName extends ActionNames<TActions>>(taskName: TName, handler: TypedTaskHandler<ActionDataType<TActions, TName>>): () => void;
|
|
363
|
+
(taskName: string, handler: TypedTaskHandler): () => void;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Extended Pillar interface with type-safe onTask.
|
|
367
|
+
*
|
|
368
|
+
* Use this when you want strongly typed task handlers based on
|
|
369
|
+
* your action definitions.
|
|
370
|
+
*
|
|
371
|
+
* @template TActions - The action definitions map
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* import type { TypedPillar } from '@pillar-ai/sdk';
|
|
376
|
+
* import type { actions } from './actions';
|
|
377
|
+
*
|
|
378
|
+
* const pillar = usePillar<typeof actions>();
|
|
379
|
+
*
|
|
380
|
+
* // TypeScript knows `data` has { type, url, name }
|
|
381
|
+
* pillar.onTask('add_source', (data) => {
|
|
382
|
+
* console.log(data.url);
|
|
383
|
+
* });
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
export interface TypedPillarMethods<TActions extends SyncActionDefinitions | ActionDefinitions> {
|
|
387
|
+
onTask: TypedOnTask<TActions>;
|
|
388
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client for Pillar SDK
|
|
3
|
+
* Handles all communication with the Pillar backend
|
|
4
|
+
*/
|
|
5
|
+
import type { TaskButtonData } from '../components/Panel/TaskButton';
|
|
6
|
+
import type { ResolvedConfig } from '../core/config';
|
|
7
|
+
import type { ProductContext, Suggestion, UserProfile } from '../core/context';
|
|
8
|
+
import type { ExecutionPlan } from '../core/plan';
|
|
9
|
+
import type { Workflow } from '../core/workflow';
|
|
10
|
+
import type { UserContextItem } from '../types/user-context';
|
|
11
|
+
import type { ChatImage, ImageUploadResponse } from './mcp-client';
|
|
12
|
+
export interface TooltipData {
|
|
13
|
+
id: string;
|
|
14
|
+
tooltip_id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
content: string;
|
|
17
|
+
content_html: string;
|
|
18
|
+
article_slug?: string;
|
|
19
|
+
article_title?: string;
|
|
20
|
+
show_learn_more: boolean;
|
|
21
|
+
trigger: 'hover' | 'click' | 'focus' | 'icon';
|
|
22
|
+
position: 'top' | 'bottom' | 'left' | 'right' | 'auto';
|
|
23
|
+
}
|
|
24
|
+
export interface ArticleData {
|
|
25
|
+
id: string;
|
|
26
|
+
title: string;
|
|
27
|
+
slug: string;
|
|
28
|
+
excerpt?: string;
|
|
29
|
+
/** TipTap JSON content - preferred for rendering */
|
|
30
|
+
body_json?: Record<string, unknown>;
|
|
31
|
+
/** Legacy HTML content - fallback if body_json not available */
|
|
32
|
+
content_html?: string;
|
|
33
|
+
category_name?: string;
|
|
34
|
+
category_slug?: string;
|
|
35
|
+
reading_time?: number;
|
|
36
|
+
updated_at: string;
|
|
37
|
+
related_articles?: ArticleSummary[];
|
|
38
|
+
}
|
|
39
|
+
export interface ArticleSummary {
|
|
40
|
+
id: string;
|
|
41
|
+
title: string;
|
|
42
|
+
slug: string;
|
|
43
|
+
excerpt?: string;
|
|
44
|
+
category_name?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ChatMessage {
|
|
47
|
+
role: 'user' | 'assistant';
|
|
48
|
+
content: string;
|
|
49
|
+
}
|
|
50
|
+
export interface SuggestedQuestion {
|
|
51
|
+
id: string;
|
|
52
|
+
text: string;
|
|
53
|
+
}
|
|
54
|
+
export interface ChatResponse {
|
|
55
|
+
message: string;
|
|
56
|
+
sources?: ArticleSummary[];
|
|
57
|
+
workflow?: Workflow;
|
|
58
|
+
conversationId?: string;
|
|
59
|
+
messageId?: string;
|
|
60
|
+
actions?: TaskButtonData[];
|
|
61
|
+
}
|
|
62
|
+
export interface ProgressEvent {
|
|
63
|
+
kind: 'search' | 'search_complete' | 'generating' | 'thinking';
|
|
64
|
+
message?: string;
|
|
65
|
+
progress_id?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Server-side embed config response.
|
|
69
|
+
* These are admin-configured settings that the SDK merges with local config.
|
|
70
|
+
*/
|
|
71
|
+
export interface ServerEmbedConfig {
|
|
72
|
+
panel?: {
|
|
73
|
+
enabled?: boolean;
|
|
74
|
+
position?: 'left' | 'right';
|
|
75
|
+
width?: number;
|
|
76
|
+
};
|
|
77
|
+
floatingButton?: {
|
|
78
|
+
enabled?: boolean;
|
|
79
|
+
position?: string;
|
|
80
|
+
label?: string;
|
|
81
|
+
};
|
|
82
|
+
features?: {
|
|
83
|
+
aiChatEnabled?: boolean;
|
|
84
|
+
searchEnabled?: boolean;
|
|
85
|
+
tooltipsEnabled?: boolean;
|
|
86
|
+
};
|
|
87
|
+
sidebarTabs?: Array<{
|
|
88
|
+
id: string;
|
|
89
|
+
label: string;
|
|
90
|
+
enabled: boolean;
|
|
91
|
+
order: number;
|
|
92
|
+
}>;
|
|
93
|
+
theme?: {
|
|
94
|
+
colors?: {
|
|
95
|
+
primary?: string;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export declare class APIClient {
|
|
100
|
+
private config;
|
|
101
|
+
private abortControllers;
|
|
102
|
+
private mcpClient;
|
|
103
|
+
constructor(config: ResolvedConfig);
|
|
104
|
+
private get baseUrl();
|
|
105
|
+
/**
|
|
106
|
+
* Get or create a persistent visitor ID.
|
|
107
|
+
* Stored in localStorage to persist across sessions.
|
|
108
|
+
*/
|
|
109
|
+
private getVisitorId;
|
|
110
|
+
/**
|
|
111
|
+
* Get or create a session ID.
|
|
112
|
+
* Stored in sessionStorage to persist only for the current browser session.
|
|
113
|
+
*/
|
|
114
|
+
private getSessionId;
|
|
115
|
+
/**
|
|
116
|
+
* Get the current page URL for analytics tracking.
|
|
117
|
+
*/
|
|
118
|
+
private getPageUrl;
|
|
119
|
+
private get headers();
|
|
120
|
+
private fetch;
|
|
121
|
+
/**
|
|
122
|
+
* Fetch embed configuration from server.
|
|
123
|
+
* Called during SDK init to get admin-configured settings.
|
|
124
|
+
*
|
|
125
|
+
* @returns Server config or null if fetch fails (SDK continues with defaults)
|
|
126
|
+
*/
|
|
127
|
+
fetchEmbedConfig(): Promise<ServerEmbedConfig | null>;
|
|
128
|
+
getTooltips(ids?: string[]): Promise<TooltipData[]>;
|
|
129
|
+
/**
|
|
130
|
+
* Get AI-generated suggested questions for the home view.
|
|
131
|
+
* Returns action-oriented questions based on the help center's content.
|
|
132
|
+
*/
|
|
133
|
+
getSuggestedQuestions(): Promise<SuggestedQuestion[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Upload an image for use in chat.
|
|
136
|
+
*
|
|
137
|
+
* @param file - The image file to upload
|
|
138
|
+
* @returns Promise with signed URL and expiration
|
|
139
|
+
*/
|
|
140
|
+
uploadImage(file: File): Promise<ImageUploadResponse>;
|
|
141
|
+
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>;
|
|
142
|
+
/**
|
|
143
|
+
* Legacy chat method using the old /ai/chat/ endpoint.
|
|
144
|
+
* @deprecated Use chat() which uses the MCP protocol.
|
|
145
|
+
*/
|
|
146
|
+
chatLegacy(message: string, history?: ChatMessage[], onChunk?: (chunk: string) => void, articleSlug?: string, existingConversationId?: string | null): Promise<ChatResponse>;
|
|
147
|
+
private handleStreamingChat;
|
|
148
|
+
/**
|
|
149
|
+
* Submit feedback on an AI assistant message.
|
|
150
|
+
* Fire-and-forget - errors are logged but don't throw.
|
|
151
|
+
*
|
|
152
|
+
* @param messageId - The UUID of the assistant message
|
|
153
|
+
* @param feedback - 'up' for helpful, 'down' for not helpful
|
|
154
|
+
* @param comment - Optional comment explaining the feedback
|
|
155
|
+
*/
|
|
156
|
+
submitFeedback(messageId: string, feedback: 'up' | 'down', comment?: string): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Confirm task execution result.
|
|
159
|
+
* Called by the SDK after a customer's task handler completes.
|
|
160
|
+
* Fire-and-forget - errors are logged but don't throw.
|
|
161
|
+
*
|
|
162
|
+
* @param taskId - The database UUID of the task
|
|
163
|
+
* @param status - 'success' or 'failure'
|
|
164
|
+
* @param details - Optional execution details
|
|
165
|
+
*/
|
|
166
|
+
confirmTaskExecution(taskId: string, status: 'success' | 'failure', details?: {
|
|
167
|
+
error?: string;
|
|
168
|
+
duration_ms?: number;
|
|
169
|
+
session_id?: string;
|
|
170
|
+
conversation_id?: string;
|
|
171
|
+
[key: string]: unknown;
|
|
172
|
+
}): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Get contextual help suggestions based on product context.
|
|
175
|
+
* Returns relevant articles, videos, and actions.
|
|
176
|
+
*/
|
|
177
|
+
getSuggestions(productContext: ProductContext, userProfile: UserProfile): Promise<Suggestion[]>;
|
|
178
|
+
/**
|
|
179
|
+
* Chat with enhanced context.
|
|
180
|
+
* Includes product context and user profile for better responses.
|
|
181
|
+
*
|
|
182
|
+
* Note: Context is passed to the MCP ask tool as additional arguments.
|
|
183
|
+
*/
|
|
184
|
+
chatWithContext(message: string, history: ChatMessage[] | undefined, productContext: ProductContext, userProfile: UserProfile, onChunk?: (chunk: string) => void, existingConversationId?: string | null, onActions?: (actions: TaskButtonData[]) => void): Promise<ChatResponse>;
|
|
185
|
+
cancelAllRequests(): void;
|
|
186
|
+
}
|