@pillar-ai/sdk 0.1.21 → 0.1.22
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/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 +1 -1
- package/dist/actions/types.d.ts +0 -89
- package/dist/api/ag-ui-adapter.d.ts +76 -0
- package/dist/api/ag-ui-bridge.d.ts +49 -0
- package/dist/api/ag-ui-client.d.ts +102 -0
- package/dist/api/ag-ui-handler.d.ts +89 -0
- package/dist/api/mcp-client.d.ts +46 -24
- package/dist/cli/sync.js +62 -43
- package/dist/components/Button/FloatingButton.d.ts +46 -0
- package/dist/components/PagePilot/styles.d.ts +1 -1
- package/dist/components/Panel/TabNavigation.d.ts +16 -0
- package/dist/components/Panel/styles.d.ts +1 -1
- package/dist/components/Progress/AGUIProgress.d.ts +15 -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 +10 -0
- package/dist/components/Views/ArticleView.d.ts +10 -0
- package/dist/components/Views/CategoryView.d.ts +11 -0
- package/dist/components/Views/HelpCenterArticles.d.ts +17 -0
- package/dist/components/Views/SearchView.d.ts +10 -0
- package/dist/components/Views/SupportView.d.ts +15 -0
- package/dist/components/shared/ArticleCard.d.ts +17 -0
- package/dist/components/shared/CategoryCard.d.ts +17 -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 +57 -38
- package/dist/core/config.d.ts +1 -1
- package/dist/core/events.d.ts +7 -1
- package/dist/index.d.ts +2 -2
- package/dist/pillar.esm.js +1 -1
- package/dist/store/chat.d.ts +2 -0
- package/dist/store/tooltips.d.ts +21 -0
- package/dist/tools/index.d.ts +27 -0
- package/dist/tools/registry.d.ts +106 -0
- package/dist/tools/types.d.ts +564 -0
- package/dist/utils/helpdesk.d.ts +33 -0
- package/dist/utils/markdown.d.ts +9 -0
- package/dist/utils/resilient-fetch.d.ts +25 -0
- package/package.json +3 -2
- package/src/actions/types.ts +0 -622
package/src/actions/types.ts
DELETED
|
@@ -1,622 +0,0 @@
|
|
|
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
|
-
* // lib/pillar/actions/index.ts
|
|
10
|
-
* import type { SyncActionDefinitions } from '@pillar-ai/sdk';
|
|
11
|
-
*
|
|
12
|
-
* export const actions = {
|
|
13
|
-
* open_settings: {
|
|
14
|
-
* description: 'Navigate to the settings page',
|
|
15
|
-
* type: 'navigate' as const,
|
|
16
|
-
* path: '/settings',
|
|
17
|
-
* autoRun: true,
|
|
18
|
-
* },
|
|
19
|
-
* } as const satisfies SyncActionDefinitions;
|
|
20
|
-
*
|
|
21
|
-
* export default actions;
|
|
22
|
-
*
|
|
23
|
-
* // Sync via CI/CD: npx pillar-sync --actions ./lib/pillar/actions/index.ts
|
|
24
|
-
* // Register handlers at runtime: pillar.onTask('open_settings', () => router.push('/settings'));
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Supported action types.
|
|
30
|
-
*
|
|
31
|
-
* - navigate: Navigate to a page within the app
|
|
32
|
-
* - open_modal: Open a modal or dialog
|
|
33
|
-
* - fill_form: Fill form fields with data
|
|
34
|
-
* - trigger_action: Trigger a custom action
|
|
35
|
-
* - query: Fetch data from the client and return to the agent (implies returns: true)
|
|
36
|
-
* - copy_text: Copy text to clipboard
|
|
37
|
-
* - external_link: Open an external URL
|
|
38
|
-
* - start_tutorial: Start a tutorial/walkthrough
|
|
39
|
-
* - inline_ui: Display inline UI card in chat
|
|
40
|
-
*/
|
|
41
|
-
export type ActionType =
|
|
42
|
-
| 'navigate'
|
|
43
|
-
| 'open_modal'
|
|
44
|
-
| 'fill_form'
|
|
45
|
-
| 'trigger_action'
|
|
46
|
-
| 'query'
|
|
47
|
-
| 'copy_text'
|
|
48
|
-
| 'external_link'
|
|
49
|
-
| 'start_tutorial'
|
|
50
|
-
| 'inline_ui';
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Supported platforms for action deployments.
|
|
54
|
-
*/
|
|
55
|
-
export type Platform = 'web' | 'ios' | 'android' | 'desktop';
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Schema property definition for a single field.
|
|
59
|
-
* Supports nested objects and arrays with items.
|
|
60
|
-
*/
|
|
61
|
-
export interface ActionDataSchemaProperty {
|
|
62
|
-
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
63
|
-
description?: string;
|
|
64
|
-
enum?: string[];
|
|
65
|
-
default?: unknown;
|
|
66
|
-
/** Items schema for array types */
|
|
67
|
-
items?: ActionDataSchemaProperty;
|
|
68
|
-
/** Nested properties for object types */
|
|
69
|
-
properties?: Record<string, ActionDataSchemaProperty>;
|
|
70
|
-
/** Required fields for nested object types */
|
|
71
|
-
required?: string[];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* JSON Schema definition for action data.
|
|
76
|
-
*
|
|
77
|
-
* When provided, the AI will extract data from the user's query
|
|
78
|
-
* and populate the action's data field before execution.
|
|
79
|
-
*/
|
|
80
|
-
export interface ActionDataSchema {
|
|
81
|
-
type: 'object';
|
|
82
|
-
properties: Record<string, ActionDataSchemaProperty>;
|
|
83
|
-
required?: string[];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Definition for a single action.
|
|
88
|
-
*
|
|
89
|
-
* Actions are defined in code and synced to the server during CI/CD.
|
|
90
|
-
* The server stores the metadata, and the SDK executes the handler locally.
|
|
91
|
-
*
|
|
92
|
-
* @template TData - Type for the data passed to the handler
|
|
93
|
-
*/
|
|
94
|
-
export interface ActionDefinition<TData = Record<string, unknown>> {
|
|
95
|
-
/**
|
|
96
|
-
* Human-readable description for AI matching.
|
|
97
|
-
*
|
|
98
|
-
* The AI uses semantic similarity to match user queries to this description.
|
|
99
|
-
* Be specific about when this action should be suggested.
|
|
100
|
-
*
|
|
101
|
-
* @example "Navigate to the billing page. Suggest when user asks about payments, invoices, or subscription."
|
|
102
|
-
*/
|
|
103
|
-
description: string;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Example user queries that should trigger this action.
|
|
107
|
-
*
|
|
108
|
-
* Provide 3-5 natural phrasings users might say:
|
|
109
|
-
* - Imperative: "open settings", "go to billing"
|
|
110
|
-
* - Questions: "where can I change my password?"
|
|
111
|
-
* - Informal: "settings", "show analytics"
|
|
112
|
-
*
|
|
113
|
-
* These are embedded and used for semantic matching alongside the description.
|
|
114
|
-
*/
|
|
115
|
-
examples?: string[];
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Type of action - determines how the SDK handles it.
|
|
119
|
-
*/
|
|
120
|
-
type: ActionType;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Path for navigate actions.
|
|
124
|
-
*
|
|
125
|
-
* Can include template variables like `/users/{userId}`.
|
|
126
|
-
*/
|
|
127
|
-
path?: string;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* External URL for external_link actions.
|
|
131
|
-
*/
|
|
132
|
-
externalUrl?: string;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* JSON Schema for data extraction from user query.
|
|
136
|
-
*
|
|
137
|
-
* When provided, the AI will attempt to extract structured data
|
|
138
|
-
* from the conversation before executing the action.
|
|
139
|
-
*/
|
|
140
|
-
dataSchema?: ActionDataSchema;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Default data to pass to the handler.
|
|
144
|
-
*/
|
|
145
|
-
defaultData?: TData;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Context required for this action to be available.
|
|
149
|
-
*
|
|
150
|
-
* @example { loggedIn: true, plan: 'pro' }
|
|
151
|
-
*/
|
|
152
|
-
requiredContext?: Record<string, unknown>;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Whether to auto-run this action without user confirmation.
|
|
156
|
-
*
|
|
157
|
-
* Only the highest-scoring action can auto-run.
|
|
158
|
-
* Use for simple navigations where user intent is clear.
|
|
159
|
-
*
|
|
160
|
-
* @default false
|
|
161
|
-
*/
|
|
162
|
-
autoRun?: boolean;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Whether the action completes immediately after execution.
|
|
166
|
-
*
|
|
167
|
-
* If false, the SDK waits for host app confirmation.
|
|
168
|
-
* Use true for simple navigations and clipboard operations.
|
|
169
|
-
*
|
|
170
|
-
* @default false
|
|
171
|
-
*/
|
|
172
|
-
autoComplete?: boolean;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Whether this action returns data for the agent.
|
|
176
|
-
*
|
|
177
|
-
* If true, the handler's return value is sent back to the agent
|
|
178
|
-
* for further reasoning. Use for query/lookup actions that inform
|
|
179
|
-
* the agent's next decision.
|
|
180
|
-
*
|
|
181
|
-
* @default false
|
|
182
|
-
*/
|
|
183
|
-
returns?: boolean;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Concrete examples of valid parameter objects for the AI to reference.
|
|
187
|
-
*
|
|
188
|
-
* Each example should have a `description` explaining the scenario
|
|
189
|
-
* and a `parameters` object matching the `dataSchema`.
|
|
190
|
-
* Useful for complex schemas where the AI benefits from seeing
|
|
191
|
-
* what a correct call looks like.
|
|
192
|
-
*/
|
|
193
|
-
parameterExamples?: Array<{
|
|
194
|
-
description: string;
|
|
195
|
-
parameters: Record<string, unknown>;
|
|
196
|
-
}>;
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Handler function executed when the action is triggered.
|
|
200
|
-
*
|
|
201
|
-
* This runs in the client - the server only stores metadata.
|
|
202
|
-
* If `returns: true`, the return value is sent to the agent.
|
|
203
|
-
*/
|
|
204
|
-
handler: (data: TData) => void | unknown | Promise<void | unknown>;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Map of action name to definition.
|
|
209
|
-
*
|
|
210
|
-
* Action names should be snake_case identifiers.
|
|
211
|
-
*/
|
|
212
|
-
export type ActionDefinitions = Record<string, ActionDefinition<unknown>>;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Metadata for a single action in the manifest (no handler).
|
|
216
|
-
*
|
|
217
|
-
* This is what gets synced to the server.
|
|
218
|
-
*/
|
|
219
|
-
export interface ActionManifestEntry {
|
|
220
|
-
name: string;
|
|
221
|
-
description: string;
|
|
222
|
-
examples?: string[];
|
|
223
|
-
type: ActionType;
|
|
224
|
-
path?: string;
|
|
225
|
-
external_url?: string;
|
|
226
|
-
auto_run?: boolean;
|
|
227
|
-
auto_complete?: boolean;
|
|
228
|
-
returns_data?: boolean;
|
|
229
|
-
data_schema?: ActionDataSchema;
|
|
230
|
-
default_data?: Record<string, unknown>;
|
|
231
|
-
required_context?: Record<string, unknown>;
|
|
232
|
-
parameter_examples?: Array<{
|
|
233
|
-
description: string;
|
|
234
|
-
parameters: Record<string, unknown>;
|
|
235
|
-
}>;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Action manifest - synced to server during CI/CD.
|
|
240
|
-
*
|
|
241
|
-
* Contains all action metadata without handlers.
|
|
242
|
-
*/
|
|
243
|
-
export interface ActionManifest {
|
|
244
|
-
/**
|
|
245
|
-
* Platform this manifest is for.
|
|
246
|
-
*/
|
|
247
|
-
platform: Platform;
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Version of the client app (semver or git SHA).
|
|
251
|
-
*/
|
|
252
|
-
version: string;
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Git commit SHA for traceability.
|
|
256
|
-
*/
|
|
257
|
-
gitSha?: string;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* When this manifest was generated.
|
|
261
|
-
*/
|
|
262
|
-
generatedAt: string;
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Action definitions (without handlers).
|
|
266
|
-
*/
|
|
267
|
-
actions: ActionManifestEntry[];
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Custom agent guidance synced alongside actions.
|
|
271
|
-
* Injected into the AI agent's prompt as product_guidance.
|
|
272
|
-
*/
|
|
273
|
-
agentGuidance?: string;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Client info set during SDK initialization.
|
|
278
|
-
*/
|
|
279
|
-
export interface ClientInfo {
|
|
280
|
-
platform: Platform;
|
|
281
|
-
version: string;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Action definition for syncing (without handler).
|
|
286
|
-
*
|
|
287
|
-
* Use this type when defining actions for CI/CD sync.
|
|
288
|
-
* Handlers are registered separately at runtime via pillar.onTask().
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* ```ts
|
|
292
|
-
* import type { SyncActionDefinitions } from '@pillar-ai/sdk';
|
|
293
|
-
*
|
|
294
|
-
* export const actions: SyncActionDefinitions = {
|
|
295
|
-
* open_settings: {
|
|
296
|
-
* description: 'Navigate to settings page',
|
|
297
|
-
* type: 'navigate',
|
|
298
|
-
* path: '/settings',
|
|
299
|
-
* autoRun: true,
|
|
300
|
-
* },
|
|
301
|
-
* };
|
|
302
|
-
* ```
|
|
303
|
-
*/
|
|
304
|
-
export interface SyncActionDefinition<TData = Record<string, unknown>> {
|
|
305
|
-
/** Human-readable description for AI matching */
|
|
306
|
-
description: string;
|
|
307
|
-
|
|
308
|
-
/** Example user queries that should trigger this action */
|
|
309
|
-
examples?: string[];
|
|
310
|
-
|
|
311
|
-
/** Type of action */
|
|
312
|
-
type: ActionType;
|
|
313
|
-
|
|
314
|
-
/** Path for navigate actions */
|
|
315
|
-
path?: string;
|
|
316
|
-
|
|
317
|
-
/** External URL for external_link actions */
|
|
318
|
-
externalUrl?: string;
|
|
319
|
-
|
|
320
|
-
/** JSON Schema for data extraction from user query */
|
|
321
|
-
dataSchema?: ActionDataSchema;
|
|
322
|
-
|
|
323
|
-
/** Default data to pass to the handler */
|
|
324
|
-
defaultData?: TData;
|
|
325
|
-
|
|
326
|
-
/** Context required for this action to be available */
|
|
327
|
-
requiredContext?: Record<string, unknown>;
|
|
328
|
-
|
|
329
|
-
/** Whether to auto-run this action without user confirmation */
|
|
330
|
-
autoRun?: boolean;
|
|
331
|
-
|
|
332
|
-
/** Whether the action completes immediately after execution */
|
|
333
|
-
autoComplete?: boolean;
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Whether this action returns data for the agent.
|
|
337
|
-
* If true, the handler's return value is sent back to the agent.
|
|
338
|
-
*/
|
|
339
|
-
returns?: boolean;
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Concrete examples of valid parameter objects for the AI to reference.
|
|
343
|
-
* Each example should have a `description` and a `parameters` object
|
|
344
|
-
* matching the `dataSchema`.
|
|
345
|
-
*/
|
|
346
|
-
parameterExamples?: Array<{
|
|
347
|
-
description: string;
|
|
348
|
-
parameters: Record<string, unknown>;
|
|
349
|
-
}>;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Map of action name to sync definition (no handlers).
|
|
354
|
-
*
|
|
355
|
-
* Use this type for your actions file that gets synced via CI/CD.
|
|
356
|
-
*/
|
|
357
|
-
export type SyncActionDefinitions = Record<string, SyncActionDefinition<unknown>>;
|
|
358
|
-
|
|
359
|
-
// ============================================================================
|
|
360
|
-
// Type Utilities for Type-Safe onTask
|
|
361
|
-
// ============================================================================
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Base data types for each action type.
|
|
365
|
-
* These are automatically inferred from the action's `type` field.
|
|
366
|
-
*/
|
|
367
|
-
export interface NavigateActionData {
|
|
368
|
-
/** CSS selector to highlight after navigation */
|
|
369
|
-
highlight_selector?: string;
|
|
370
|
-
/** Path that was navigated to (injected by SDK) */
|
|
371
|
-
path?: string;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export interface TriggerActionData {
|
|
375
|
-
/** The action being triggered */
|
|
376
|
-
action?: string;
|
|
377
|
-
/** Additional action parameters */
|
|
378
|
-
[key: string]: unknown;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export interface InlineUIData {
|
|
382
|
-
/** Card type for rendering */
|
|
383
|
-
card_type: string;
|
|
384
|
-
/** Additional card data */
|
|
385
|
-
[key: string]: unknown;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
export interface ExternalLinkData {
|
|
389
|
-
/** The URL being opened */
|
|
390
|
-
url?: string;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
export interface CopyTextData {
|
|
394
|
-
/** Text to copy to clipboard */
|
|
395
|
-
text?: string;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export interface QueryActionData {
|
|
399
|
-
/** Query parameters passed to the handler */
|
|
400
|
-
[key: string]: unknown;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Maps action types to their default data shapes.
|
|
405
|
-
* Used for automatic type inference in onTask handlers.
|
|
406
|
-
*/
|
|
407
|
-
export interface ActionTypeDataMap {
|
|
408
|
-
navigate: NavigateActionData;
|
|
409
|
-
trigger_action: TriggerActionData;
|
|
410
|
-
query: QueryActionData;
|
|
411
|
-
inline_ui: InlineUIData;
|
|
412
|
-
external_link: ExternalLinkData;
|
|
413
|
-
copy_text: CopyTextData;
|
|
414
|
-
open_modal: Record<string, unknown>;
|
|
415
|
-
fill_form: Record<string, unknown>;
|
|
416
|
-
start_tutorial: Record<string, unknown>;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Extract the data type for a specific action from an ActionDefinitions map.
|
|
421
|
-
*
|
|
422
|
-
* Type inference priority:
|
|
423
|
-
* 1. If `defaultData` is defined, use that type (for custom fields)
|
|
424
|
-
* 2. Otherwise, infer from the action's `type` field using ActionTypeDataMap
|
|
425
|
-
* 3. Fall back to Record<string, unknown>
|
|
426
|
-
*
|
|
427
|
-
* @example
|
|
428
|
-
* ```ts
|
|
429
|
-
* const actions = {
|
|
430
|
-
* // Inferred from type: "navigate" → NavigateActionData
|
|
431
|
-
* open_settings: {
|
|
432
|
-
* description: '...',
|
|
433
|
-
* type: 'navigate',
|
|
434
|
-
* path: '/settings',
|
|
435
|
-
* },
|
|
436
|
-
* // Custom data via defaultData
|
|
437
|
-
* add_source: {
|
|
438
|
-
* description: '...',
|
|
439
|
-
* type: 'navigate',
|
|
440
|
-
* defaultData: { type: '', url: '', name: '' },
|
|
441
|
-
* },
|
|
442
|
-
* } as const satisfies SyncActionDefinitions;
|
|
443
|
-
* ```
|
|
444
|
-
*/
|
|
445
|
-
export type ActionDataType<
|
|
446
|
-
TActions extends SyncActionDefinitions | ActionDefinitions,
|
|
447
|
-
TName extends keyof TActions,
|
|
448
|
-
> = TActions[TName] extends { defaultData: infer D }
|
|
449
|
-
? D extends Record<string, unknown>
|
|
450
|
-
? D
|
|
451
|
-
: Record<string, unknown>
|
|
452
|
-
: TActions[TName] extends { type: infer T }
|
|
453
|
-
? T extends keyof ActionTypeDataMap
|
|
454
|
-
? ActionTypeDataMap[T]
|
|
455
|
-
: Record<string, unknown>
|
|
456
|
-
: Record<string, unknown>;
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Extract all action names from an ActionDefinitions map.
|
|
460
|
-
*
|
|
461
|
-
* @example
|
|
462
|
-
* ```ts
|
|
463
|
-
* const actions = { open_settings: {...}, add_source: {...} };
|
|
464
|
-
* type Names = ActionNames<typeof actions>; // 'open_settings' | 'add_source'
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
export type ActionNames<T extends SyncActionDefinitions | ActionDefinitions> =
|
|
468
|
-
Extract<keyof T, string>;
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Typed task handler function.
|
|
472
|
-
*
|
|
473
|
-
* @template TData - The data type for this action
|
|
474
|
-
*/
|
|
475
|
-
export type TypedTaskHandler<TData = Record<string, unknown>> = (
|
|
476
|
-
data: TData
|
|
477
|
-
) => void | Promise<void>;
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Type-safe onTask method signature.
|
|
481
|
-
*
|
|
482
|
-
* When actions are provided to PillarProvider, this type enables
|
|
483
|
-
* TypeScript to infer the correct data type for each action handler.
|
|
484
|
-
*
|
|
485
|
-
* @template TActions - The action definitions map
|
|
486
|
-
*/
|
|
487
|
-
export interface TypedOnTask<
|
|
488
|
-
TActions extends SyncActionDefinitions | ActionDefinitions,
|
|
489
|
-
> {
|
|
490
|
-
<TName extends ActionNames<TActions>>(
|
|
491
|
-
taskName: TName,
|
|
492
|
-
handler: TypedTaskHandler<ActionDataType<TActions, TName>>
|
|
493
|
-
): () => void;
|
|
494
|
-
|
|
495
|
-
// Fallback overload for arbitrary string keys (runtime-only tasks)
|
|
496
|
-
(taskName: string, handler: TypedTaskHandler): () => void;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Extended Pillar interface with type-safe onTask.
|
|
501
|
-
*
|
|
502
|
-
* Use this when you want strongly typed task handlers based on
|
|
503
|
-
* your action definitions.
|
|
504
|
-
*
|
|
505
|
-
* @template TActions - The action definitions map
|
|
506
|
-
*
|
|
507
|
-
* @example
|
|
508
|
-
* ```ts
|
|
509
|
-
* import type { TypedPillar } from '@pillar-ai/sdk';
|
|
510
|
-
* import type { actions } from './actions';
|
|
511
|
-
*
|
|
512
|
-
* const pillar = usePillar<typeof actions>();
|
|
513
|
-
*
|
|
514
|
-
* // TypeScript knows `data` has { type, url, name }
|
|
515
|
-
* pillar.onTask('add_source', (data) => {
|
|
516
|
-
* console.log(data.url);
|
|
517
|
-
* });
|
|
518
|
-
* ```
|
|
519
|
-
*/
|
|
520
|
-
export interface TypedPillarMethods<
|
|
521
|
-
TActions extends SyncActionDefinitions | ActionDefinitions,
|
|
522
|
-
> {
|
|
523
|
-
onTask: TypedOnTask<TActions>;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
// ============================================================================
|
|
527
|
-
// Unified Action Schema (new API — co-locates metadata + handler)
|
|
528
|
-
// ============================================================================
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Result returned from an action's execute function.
|
|
532
|
-
*
|
|
533
|
-
* Follows the MCP tool result format. Plain objects are also accepted
|
|
534
|
-
* by the SDK and normalized to this shape automatically.
|
|
535
|
-
*/
|
|
536
|
-
export interface ActionResult {
|
|
537
|
-
content: Array<
|
|
538
|
-
| { type: 'text'; text: string }
|
|
539
|
-
| { type: 'image'; data: string; mimeType: string }
|
|
540
|
-
>;
|
|
541
|
-
isError?: boolean;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Unified action definition that co-locates metadata and handler.
|
|
546
|
-
*
|
|
547
|
-
* Use with `pillar.defineAction()` or the `usePillarAction()` React hook.
|
|
548
|
-
* The CLI scanner (`npx pillar-sync --scan ./src`) discovers these
|
|
549
|
-
* definitions automatically — no barrel file needed.
|
|
550
|
-
*
|
|
551
|
-
* @template TInput - Type of the input object passed to `execute`
|
|
552
|
-
*
|
|
553
|
-
* @example
|
|
554
|
-
* ```ts
|
|
555
|
-
* pillar.defineAction({
|
|
556
|
-
* name: 'add_to_cart',
|
|
557
|
-
* description: 'Add a product to the shopping cart',
|
|
558
|
-
* inputSchema: {
|
|
559
|
-
* type: 'object',
|
|
560
|
-
* properties: {
|
|
561
|
-
* productId: { type: 'string', description: 'Product ID' },
|
|
562
|
-
* quantity: { type: 'number', description: 'Quantity to add' },
|
|
563
|
-
* },
|
|
564
|
-
* required: ['productId', 'quantity'],
|
|
565
|
-
* },
|
|
566
|
-
* execute: async ({ productId, quantity }) => {
|
|
567
|
-
* await cartApi.add(productId, quantity);
|
|
568
|
-
* return { content: [{ type: 'text', text: 'Added to cart' }] };
|
|
569
|
-
* },
|
|
570
|
-
* });
|
|
571
|
-
* ```
|
|
572
|
-
*/
|
|
573
|
-
export interface ActionSchema<TInput = Record<string, unknown>> {
|
|
574
|
-
/** Unique action name (e.g., 'add_to_cart') */
|
|
575
|
-
name: string;
|
|
576
|
-
|
|
577
|
-
/** Human-readable description for AI matching */
|
|
578
|
-
description: string;
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Type of action - determines how the SDK handles it and organizes it in the UI.
|
|
582
|
-
*/
|
|
583
|
-
type?: ActionType;
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* JSON Schema describing the input parameters.
|
|
587
|
-
* The AI extracts structured data from the conversation to populate these.
|
|
588
|
-
*/
|
|
589
|
-
inputSchema?: {
|
|
590
|
-
type: 'object';
|
|
591
|
-
properties: Record<string, unknown>;
|
|
592
|
-
required?: string[];
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* Example user queries that should trigger this action.
|
|
597
|
-
* Used for semantic matching alongside the description.
|
|
598
|
-
*/
|
|
599
|
-
examples?: string[];
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* Whether to auto-execute without user confirmation.
|
|
603
|
-
* @default false
|
|
604
|
-
*/
|
|
605
|
-
autoRun?: boolean;
|
|
606
|
-
|
|
607
|
-
/**
|
|
608
|
-
* Whether the action completes immediately after execution.
|
|
609
|
-
* @default true
|
|
610
|
-
*/
|
|
611
|
-
autoComplete?: boolean;
|
|
612
|
-
|
|
613
|
-
/**
|
|
614
|
-
* Handler function executed when the AI invokes this action.
|
|
615
|
-
*
|
|
616
|
-
* Can return:
|
|
617
|
-
* - An `ActionResult` with MCP-style content blocks
|
|
618
|
-
* - A plain object (SDK normalizes it for the agent)
|
|
619
|
-
* - `void` if the action has no return value
|
|
620
|
-
*/
|
|
621
|
-
execute: (input: TInput) => Promise<ActionResult | unknown | void> | ActionResult | unknown | void;
|
|
622
|
-
}
|