@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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL Parameters Utility
|
|
3
|
+
* Handles parsing and managing URL search params for auto-opening the panel
|
|
4
|
+
*/
|
|
5
|
+
export interface PillarUrlParams {
|
|
6
|
+
/** Open the panel to home view */
|
|
7
|
+
open?: boolean;
|
|
8
|
+
/** Article slug to open */
|
|
9
|
+
article?: string;
|
|
10
|
+
/** Category slug to open */
|
|
11
|
+
category?: string;
|
|
12
|
+
/** Search query to perform */
|
|
13
|
+
search?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parse URL search params for Pillar-specific parameters
|
|
17
|
+
*/
|
|
18
|
+
export declare function parsePillarUrlParams(prefix?: string): PillarUrlParams;
|
|
19
|
+
/**
|
|
20
|
+
* Check if any Pillar URL params are present
|
|
21
|
+
*/
|
|
22
|
+
export declare function hasPillarUrlParams(prefix?: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Remove Pillar URL params from the current URL
|
|
25
|
+
* Useful for cleaning up after the panel has opened
|
|
26
|
+
*/
|
|
27
|
+
export declare function clearPillarUrlParams(prefix?: string): void;
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pillar-ai/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pillar Embedded Help SDK - Add contextual help, tooltips, and AI chat to your application",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/pillar.esm.js",
|
|
7
|
+
"module": "./dist/pillar.esm.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"pillar-sync": "./src/cli/sync.ts"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/pillar.esm.js",
|
|
16
|
+
"require": "./dist/pillar.js",
|
|
17
|
+
"default": "./dist/pillar.esm.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src/cli",
|
|
23
|
+
"src/actions/types.ts",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "rollup -c && npm run build:types",
|
|
28
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
29
|
+
"dev": "rollup -c -w",
|
|
30
|
+
"clean": "rm -rf dist",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"help",
|
|
35
|
+
"documentation",
|
|
36
|
+
"tooltips",
|
|
37
|
+
"support",
|
|
38
|
+
"chat",
|
|
39
|
+
"ai",
|
|
40
|
+
"embedded"
|
|
41
|
+
],
|
|
42
|
+
"author": "Pillar Team",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/pillarapp/pillar.git",
|
|
47
|
+
"directory": "packages/sdk"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://trypillar.com",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/pillarapp/pillar/issues"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@preact/signals": "^1.3.1",
|
|
58
|
+
"@tiptap/core": "^2.11.5",
|
|
59
|
+
"@tiptap/extension-code-block-lowlight": "^2.11.5",
|
|
60
|
+
"@tiptap/extension-heading": "^2.11.5",
|
|
61
|
+
"@tiptap/extension-image": "^2.11.5",
|
|
62
|
+
"@tiptap/extension-link": "^2.11.5",
|
|
63
|
+
"@tiptap/html": "^2.11.5",
|
|
64
|
+
"@tiptap/starter-kit": "^2.11.5",
|
|
65
|
+
"lowlight": "^3.3.0",
|
|
66
|
+
"marked": "^17.0.1",
|
|
67
|
+
"preact": "^10.25.4",
|
|
68
|
+
"preact-iso": "^2.9.0"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@babel/core": "^7.24.0",
|
|
72
|
+
"@babel/preset-typescript": "^7.24.0",
|
|
73
|
+
"@rollup/plugin-alias": "^5.1.0",
|
|
74
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
75
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
76
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
77
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
78
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
79
|
+
"@types/node": "^20.11.0",
|
|
80
|
+
"rollup": "^4.9.0",
|
|
81
|
+
"tslib": "^2.6.2",
|
|
82
|
+
"tsx": "^4.7.0",
|
|
83
|
+
"typescript": "^5.3.0"
|
|
84
|
+
},
|
|
85
|
+
"sideEffects": false
|
|
86
|
+
}
|
|
@@ -0,0 +1,468 @@
|
|
|
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
|
+
/**
|
|
23
|
+
* Supported action types.
|
|
24
|
+
*
|
|
25
|
+
* - navigate: Navigate to a page within the app
|
|
26
|
+
* - open_modal: Open a modal or dialog
|
|
27
|
+
* - fill_form: Fill form fields with data
|
|
28
|
+
* - trigger_action: Trigger a custom action
|
|
29
|
+
* - copy_text: Copy text to clipboard
|
|
30
|
+
* - external_link: Open an external URL
|
|
31
|
+
* - start_tutorial: Start a tutorial/walkthrough
|
|
32
|
+
* - inline_ui: Display inline UI card in chat
|
|
33
|
+
*/
|
|
34
|
+
export type ActionType =
|
|
35
|
+
| 'navigate'
|
|
36
|
+
| 'open_modal'
|
|
37
|
+
| 'fill_form'
|
|
38
|
+
| 'trigger_action'
|
|
39
|
+
| 'copy_text'
|
|
40
|
+
| 'external_link'
|
|
41
|
+
| 'start_tutorial'
|
|
42
|
+
| 'inline_ui';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Supported platforms for action deployments.
|
|
46
|
+
*/
|
|
47
|
+
export type Platform = 'web' | 'ios' | 'android' | 'desktop';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* JSON Schema definition for action data.
|
|
51
|
+
*
|
|
52
|
+
* When provided, the AI will extract data from the user's query
|
|
53
|
+
* and populate the action's data field before execution.
|
|
54
|
+
*/
|
|
55
|
+
export interface ActionDataSchema {
|
|
56
|
+
type: 'object';
|
|
57
|
+
properties: Record<
|
|
58
|
+
string,
|
|
59
|
+
{
|
|
60
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
61
|
+
description?: string;
|
|
62
|
+
enum?: string[];
|
|
63
|
+
default?: unknown;
|
|
64
|
+
}
|
|
65
|
+
>;
|
|
66
|
+
required?: string[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Definition for a single action.
|
|
71
|
+
*
|
|
72
|
+
* Actions are defined in code and synced to the server during CI/CD.
|
|
73
|
+
* The server stores the metadata, and the SDK executes the handler locally.
|
|
74
|
+
*
|
|
75
|
+
* @template TData - Type for the data passed to the handler
|
|
76
|
+
*/
|
|
77
|
+
export interface ActionDefinition<TData = Record<string, unknown>> {
|
|
78
|
+
/**
|
|
79
|
+
* Human-readable description for AI matching.
|
|
80
|
+
*
|
|
81
|
+
* The AI uses semantic similarity to match user queries to this description.
|
|
82
|
+
* Be specific about when this action should be suggested.
|
|
83
|
+
*
|
|
84
|
+
* @example "Navigate to the billing page. Suggest when user asks about payments, invoices, or subscription."
|
|
85
|
+
*/
|
|
86
|
+
description: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Example user queries that should trigger this action.
|
|
90
|
+
*
|
|
91
|
+
* Provide 3-5 natural phrasings users might say:
|
|
92
|
+
* - Imperative: "open settings", "go to billing"
|
|
93
|
+
* - Questions: "where can I change my password?"
|
|
94
|
+
* - Informal: "settings", "show analytics"
|
|
95
|
+
*
|
|
96
|
+
* These are embedded and used for semantic matching alongside the description.
|
|
97
|
+
*/
|
|
98
|
+
examples?: string[];
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Type of action - determines how the SDK handles it.
|
|
102
|
+
*/
|
|
103
|
+
type: ActionType;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Path for navigate actions.
|
|
107
|
+
*
|
|
108
|
+
* Can include template variables like `/users/{userId}`.
|
|
109
|
+
*/
|
|
110
|
+
path?: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* External URL for external_link actions.
|
|
114
|
+
*/
|
|
115
|
+
externalUrl?: string;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* JSON Schema for data extraction from user query.
|
|
119
|
+
*
|
|
120
|
+
* When provided, the AI will attempt to extract structured data
|
|
121
|
+
* from the conversation before executing the action.
|
|
122
|
+
*/
|
|
123
|
+
dataSchema?: ActionDataSchema;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Default data to pass to the handler.
|
|
127
|
+
*/
|
|
128
|
+
defaultData?: TData;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Context required for this action to be available.
|
|
132
|
+
*
|
|
133
|
+
* @example { loggedIn: true, plan: 'pro' }
|
|
134
|
+
*/
|
|
135
|
+
requiredContext?: Record<string, unknown>;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether to auto-run this action without user confirmation.
|
|
139
|
+
*
|
|
140
|
+
* Only the highest-scoring action can auto-run.
|
|
141
|
+
* Use for simple navigations where user intent is clear.
|
|
142
|
+
*
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
autoRun?: boolean;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Whether the action completes immediately after execution.
|
|
149
|
+
*
|
|
150
|
+
* If false, the SDK waits for host app confirmation.
|
|
151
|
+
* Use true for simple navigations and clipboard operations.
|
|
152
|
+
*
|
|
153
|
+
* @default false
|
|
154
|
+
*/
|
|
155
|
+
autoComplete?: boolean;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Whether this action returns data for the agent.
|
|
159
|
+
*
|
|
160
|
+
* If true, the handler's return value is sent back to the agent
|
|
161
|
+
* for further reasoning. Use for query/lookup actions that inform
|
|
162
|
+
* the agent's next decision.
|
|
163
|
+
*
|
|
164
|
+
* @default false
|
|
165
|
+
*/
|
|
166
|
+
returns?: boolean;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Handler function executed when the action is triggered.
|
|
170
|
+
*
|
|
171
|
+
* This runs in the client - the server only stores metadata.
|
|
172
|
+
* If `returns: true`, the return value is sent to the agent.
|
|
173
|
+
*/
|
|
174
|
+
handler: (data: TData) => void | unknown | Promise<void | unknown>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Map of action name to definition.
|
|
179
|
+
*
|
|
180
|
+
* Action names should be snake_case identifiers.
|
|
181
|
+
*/
|
|
182
|
+
export type ActionDefinitions = Record<string, ActionDefinition<any>>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Metadata for a single action in the manifest (no handler).
|
|
186
|
+
*
|
|
187
|
+
* This is what gets synced to the server.
|
|
188
|
+
*/
|
|
189
|
+
export interface ActionManifestEntry {
|
|
190
|
+
name: string;
|
|
191
|
+
description: string;
|
|
192
|
+
examples?: string[];
|
|
193
|
+
type: ActionType;
|
|
194
|
+
path?: string;
|
|
195
|
+
external_url?: string;
|
|
196
|
+
auto_run?: boolean;
|
|
197
|
+
auto_complete?: boolean;
|
|
198
|
+
returns_data?: boolean;
|
|
199
|
+
data_schema?: ActionDataSchema;
|
|
200
|
+
default_data?: Record<string, unknown>;
|
|
201
|
+
required_context?: Record<string, unknown>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Action manifest - synced to server during CI/CD.
|
|
206
|
+
*
|
|
207
|
+
* Contains all action metadata without handlers.
|
|
208
|
+
*/
|
|
209
|
+
export interface ActionManifest {
|
|
210
|
+
/**
|
|
211
|
+
* Platform this manifest is for.
|
|
212
|
+
*/
|
|
213
|
+
platform: Platform;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Version of the client app (semver or git SHA).
|
|
217
|
+
*/
|
|
218
|
+
version: string;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Git commit SHA for traceability.
|
|
222
|
+
*/
|
|
223
|
+
gitSha?: string;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* When this manifest was generated.
|
|
227
|
+
*/
|
|
228
|
+
generatedAt: string;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Action definitions (without handlers).
|
|
232
|
+
*/
|
|
233
|
+
actions: ActionManifestEntry[];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Client info set during SDK initialization.
|
|
238
|
+
*/
|
|
239
|
+
export interface ClientInfo {
|
|
240
|
+
platform: Platform;
|
|
241
|
+
version: string;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Action definition for syncing (without handler).
|
|
246
|
+
*
|
|
247
|
+
* Use this type when defining actions for CI/CD sync.
|
|
248
|
+
* Handlers are registered separately at runtime via pillar.onTask().
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* import type { SyncActionDefinitions } from '@pillar-ai/sdk';
|
|
253
|
+
*
|
|
254
|
+
* export const actions: SyncActionDefinitions = {
|
|
255
|
+
* open_settings: {
|
|
256
|
+
* description: 'Navigate to settings page',
|
|
257
|
+
* type: 'navigate',
|
|
258
|
+
* path: '/settings',
|
|
259
|
+
* autoRun: true,
|
|
260
|
+
* },
|
|
261
|
+
* };
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
export interface SyncActionDefinition<TData = Record<string, unknown>> {
|
|
265
|
+
/** Human-readable description for AI matching */
|
|
266
|
+
description: string;
|
|
267
|
+
|
|
268
|
+
/** Example user queries that should trigger this action */
|
|
269
|
+
examples?: string[];
|
|
270
|
+
|
|
271
|
+
/** Type of action */
|
|
272
|
+
type: ActionType;
|
|
273
|
+
|
|
274
|
+
/** Path for navigate actions */
|
|
275
|
+
path?: string;
|
|
276
|
+
|
|
277
|
+
/** External URL for external_link actions */
|
|
278
|
+
externalUrl?: string;
|
|
279
|
+
|
|
280
|
+
/** JSON Schema for data extraction from user query */
|
|
281
|
+
dataSchema?: ActionDataSchema;
|
|
282
|
+
|
|
283
|
+
/** Default data to pass to the handler */
|
|
284
|
+
defaultData?: TData;
|
|
285
|
+
|
|
286
|
+
/** Context required for this action to be available */
|
|
287
|
+
requiredContext?: Record<string, unknown>;
|
|
288
|
+
|
|
289
|
+
/** Whether to auto-run this action without user confirmation */
|
|
290
|
+
autoRun?: boolean;
|
|
291
|
+
|
|
292
|
+
/** Whether the action completes immediately after execution */
|
|
293
|
+
autoComplete?: boolean;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Whether this action returns data for the agent.
|
|
297
|
+
* If true, the handler's return value is sent back to the agent.
|
|
298
|
+
*/
|
|
299
|
+
returns?: boolean;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Map of action name to sync definition (no handlers).
|
|
304
|
+
*
|
|
305
|
+
* Use this type for your actions file that gets synced via CI/CD.
|
|
306
|
+
*/
|
|
307
|
+
export type SyncActionDefinitions = Record<string, SyncActionDefinition<any>>;
|
|
308
|
+
|
|
309
|
+
// ============================================================================
|
|
310
|
+
// Type Utilities for Type-Safe onTask
|
|
311
|
+
// ============================================================================
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Base data types for each action type.
|
|
315
|
+
* These are automatically inferred from the action's `type` field.
|
|
316
|
+
*/
|
|
317
|
+
export interface NavigateActionData {
|
|
318
|
+
/** CSS selector to highlight after navigation */
|
|
319
|
+
highlight_selector?: string;
|
|
320
|
+
/** Path that was navigated to (injected by SDK) */
|
|
321
|
+
path?: string;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export interface TriggerActionData {
|
|
325
|
+
/** The action being triggered */
|
|
326
|
+
action?: string;
|
|
327
|
+
/** Additional action parameters */
|
|
328
|
+
[key: string]: unknown;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface InlineUIData {
|
|
332
|
+
/** Card type for rendering */
|
|
333
|
+
card_type: string;
|
|
334
|
+
/** Additional card data */
|
|
335
|
+
[key: string]: unknown;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export interface ExternalLinkData {
|
|
339
|
+
/** The URL being opened */
|
|
340
|
+
url?: string;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface CopyTextData {
|
|
344
|
+
/** Text to copy to clipboard */
|
|
345
|
+
text?: string;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Maps action types to their default data shapes.
|
|
350
|
+
* Used for automatic type inference in onTask handlers.
|
|
351
|
+
*/
|
|
352
|
+
export interface ActionTypeDataMap {
|
|
353
|
+
navigate: NavigateActionData;
|
|
354
|
+
trigger_action: TriggerActionData;
|
|
355
|
+
inline_ui: InlineUIData;
|
|
356
|
+
external_link: ExternalLinkData;
|
|
357
|
+
copy_text: CopyTextData;
|
|
358
|
+
open_modal: Record<string, unknown>;
|
|
359
|
+
fill_form: Record<string, unknown>;
|
|
360
|
+
start_tutorial: Record<string, unknown>;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Extract the data type for a specific action from an ActionDefinitions map.
|
|
365
|
+
*
|
|
366
|
+
* Type inference priority:
|
|
367
|
+
* 1. If `defaultData` is defined, use that type (for custom fields)
|
|
368
|
+
* 2. Otherwise, infer from the action's `type` field using ActionTypeDataMap
|
|
369
|
+
* 3. Fall back to Record<string, unknown>
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```ts
|
|
373
|
+
* const actions = {
|
|
374
|
+
* // Inferred from type: "navigate" → NavigateActionData
|
|
375
|
+
* open_settings: {
|
|
376
|
+
* description: '...',
|
|
377
|
+
* type: 'navigate',
|
|
378
|
+
* path: '/settings',
|
|
379
|
+
* },
|
|
380
|
+
* // Custom data via defaultData
|
|
381
|
+
* add_source: {
|
|
382
|
+
* description: '...',
|
|
383
|
+
* type: 'navigate',
|
|
384
|
+
* defaultData: { type: '', url: '', name: '' },
|
|
385
|
+
* },
|
|
386
|
+
* } as const satisfies SyncActionDefinitions;
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
export type ActionDataType<
|
|
390
|
+
TActions extends SyncActionDefinitions | ActionDefinitions,
|
|
391
|
+
TName extends keyof TActions,
|
|
392
|
+
> = TActions[TName] extends { defaultData: infer D }
|
|
393
|
+
? D extends Record<string, unknown>
|
|
394
|
+
? D
|
|
395
|
+
: Record<string, unknown>
|
|
396
|
+
: TActions[TName] extends { type: infer T }
|
|
397
|
+
? T extends keyof ActionTypeDataMap
|
|
398
|
+
? ActionTypeDataMap[T]
|
|
399
|
+
: Record<string, unknown>
|
|
400
|
+
: Record<string, unknown>;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Extract all action names from an ActionDefinitions map.
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* const actions = { open_settings: {...}, add_source: {...} };
|
|
408
|
+
* type Names = ActionNames<typeof actions>; // 'open_settings' | 'add_source'
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
export type ActionNames<T extends SyncActionDefinitions | ActionDefinitions> =
|
|
412
|
+
Extract<keyof T, string>;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Typed task handler function.
|
|
416
|
+
*
|
|
417
|
+
* @template TData - The data type for this action
|
|
418
|
+
*/
|
|
419
|
+
export type TypedTaskHandler<TData = Record<string, unknown>> = (
|
|
420
|
+
data: TData
|
|
421
|
+
) => void | Promise<void>;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Type-safe onTask method signature.
|
|
425
|
+
*
|
|
426
|
+
* When actions are provided to PillarProvider, this type enables
|
|
427
|
+
* TypeScript to infer the correct data type for each action handler.
|
|
428
|
+
*
|
|
429
|
+
* @template TActions - The action definitions map
|
|
430
|
+
*/
|
|
431
|
+
export interface TypedOnTask<
|
|
432
|
+
TActions extends SyncActionDefinitions | ActionDefinitions,
|
|
433
|
+
> {
|
|
434
|
+
<TName extends ActionNames<TActions>>(
|
|
435
|
+
taskName: TName,
|
|
436
|
+
handler: TypedTaskHandler<ActionDataType<TActions, TName>>
|
|
437
|
+
): () => void;
|
|
438
|
+
|
|
439
|
+
// Fallback overload for arbitrary string keys (runtime-only tasks)
|
|
440
|
+
(taskName: string, handler: TypedTaskHandler): () => void;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Extended Pillar interface with type-safe onTask.
|
|
445
|
+
*
|
|
446
|
+
* Use this when you want strongly typed task handlers based on
|
|
447
|
+
* your action definitions.
|
|
448
|
+
*
|
|
449
|
+
* @template TActions - The action definitions map
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```ts
|
|
453
|
+
* import type { TypedPillar } from '@pillar-ai/sdk';
|
|
454
|
+
* import type { actions } from './actions';
|
|
455
|
+
*
|
|
456
|
+
* const pillar = usePillar<typeof actions>();
|
|
457
|
+
*
|
|
458
|
+
* // TypeScript knows `data` has { type, url, name }
|
|
459
|
+
* pillar.onTask('add_source', (data) => {
|
|
460
|
+
* console.log(data.url);
|
|
461
|
+
* });
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
export interface TypedPillarMethods<
|
|
465
|
+
TActions extends SyncActionDefinitions | ActionDefinitions,
|
|
466
|
+
> {
|
|
467
|
+
onTask: TypedOnTask<TActions>;
|
|
468
|
+
}
|