@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
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Types - Type definitions for code-first tool definitions.
|
|
3
|
+
*
|
|
4
|
+
* These types enable developers to define tools in their application code
|
|
5
|
+
* rather than in the admin UI, with full TypeScript support.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // lib/pillar/tools/index.ts
|
|
10
|
+
* import type { SyncToolDefinitions } from '@pillar-ai/sdk';
|
|
11
|
+
*
|
|
12
|
+
* export const tools = {
|
|
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 SyncToolDefinitions;
|
|
20
|
+
*
|
|
21
|
+
* export default tools;
|
|
22
|
+
*
|
|
23
|
+
* // Sync via CI/CD: npx pillar-sync --scan ./src
|
|
24
|
+
* // Register handlers at runtime: pillar.onTask('open_settings', () => router.push('/settings'));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Supported tool types.
|
|
29
|
+
*
|
|
30
|
+
* - navigate: Navigate to a page within the app
|
|
31
|
+
* - open_modal: Open a modal or dialog
|
|
32
|
+
* - fill_form: Fill form fields with data
|
|
33
|
+
* - trigger_tool: Trigger a custom tool
|
|
34
|
+
* - query: Fetch data from the client and return to the agent (implies returns: true)
|
|
35
|
+
* - copy_text: Copy text to clipboard
|
|
36
|
+
* - external_link: Open an external URL
|
|
37
|
+
* - start_tutorial: Start a tutorial/walkthrough
|
|
38
|
+
* - inline_ui: Display inline UI card in chat
|
|
39
|
+
*/
|
|
40
|
+
export type ToolType = 'navigate' | 'open_modal' | 'fill_form' | 'trigger_tool' | 'query' | 'copy_text' | 'external_link' | 'start_tutorial' | 'inline_ui';
|
|
41
|
+
/**
|
|
42
|
+
* Supported platforms for tool deployments.
|
|
43
|
+
*/
|
|
44
|
+
export type Platform = 'web' | 'ios' | 'android' | 'desktop';
|
|
45
|
+
/**
|
|
46
|
+
* Schema property definition for a single field.
|
|
47
|
+
* Supports nested objects and arrays with items.
|
|
48
|
+
*/
|
|
49
|
+
export interface ToolDataSchemaProperty {
|
|
50
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
51
|
+
description?: string;
|
|
52
|
+
enum?: string[];
|
|
53
|
+
default?: unknown;
|
|
54
|
+
/** Items schema for array types */
|
|
55
|
+
items?: ToolDataSchemaProperty;
|
|
56
|
+
/** Nested properties for object types */
|
|
57
|
+
properties?: Record<string, ToolDataSchemaProperty>;
|
|
58
|
+
/** Required fields for nested object types */
|
|
59
|
+
required?: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* JSON Schema definition for tool data.
|
|
63
|
+
*
|
|
64
|
+
* When provided, the AI will extract data from the user's query
|
|
65
|
+
* and populate the tool's data field before execution.
|
|
66
|
+
*/
|
|
67
|
+
export interface ToolDataSchema {
|
|
68
|
+
type: 'object';
|
|
69
|
+
properties: Record<string, ToolDataSchemaProperty>;
|
|
70
|
+
required?: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Definition for a single tool.
|
|
74
|
+
*
|
|
75
|
+
* Tools are defined in code and synced to the server during CI/CD.
|
|
76
|
+
* The server stores the metadata, and the SDK executes the handler locally.
|
|
77
|
+
*
|
|
78
|
+
* @template TData - Type for the data passed to the handler
|
|
79
|
+
*/
|
|
80
|
+
export interface ToolDefinition<TData = Record<string, unknown>> {
|
|
81
|
+
/**
|
|
82
|
+
* Human-readable description for AI matching.
|
|
83
|
+
*
|
|
84
|
+
* The AI uses semantic similarity to match user queries to this description.
|
|
85
|
+
* Be specific about when this tool should be suggested.
|
|
86
|
+
*
|
|
87
|
+
* @example "Navigate to the billing page. Suggest when user asks about payments, invoices, or subscription."
|
|
88
|
+
*/
|
|
89
|
+
description: string;
|
|
90
|
+
/**
|
|
91
|
+
* Example user queries that should trigger this tool.
|
|
92
|
+
*
|
|
93
|
+
* Provide 3-5 natural phrasings users might say:
|
|
94
|
+
* - Imperative: "open settings", "go to billing"
|
|
95
|
+
* - Questions: "where can I change my password?"
|
|
96
|
+
* - Informal: "settings", "show analytics"
|
|
97
|
+
*
|
|
98
|
+
* These are embedded and used for semantic matching alongside the description.
|
|
99
|
+
*/
|
|
100
|
+
examples?: string[];
|
|
101
|
+
/**
|
|
102
|
+
* Type of tool - determines how the SDK handles it.
|
|
103
|
+
*/
|
|
104
|
+
type: ToolType;
|
|
105
|
+
/**
|
|
106
|
+
* Path for navigate tools.
|
|
107
|
+
*
|
|
108
|
+
* Can include template variables like `/users/{userId}`.
|
|
109
|
+
*/
|
|
110
|
+
path?: string;
|
|
111
|
+
/**
|
|
112
|
+
* External URL for external_link tools.
|
|
113
|
+
*/
|
|
114
|
+
externalUrl?: string;
|
|
115
|
+
/**
|
|
116
|
+
* JSON Schema for data extraction from user query.
|
|
117
|
+
*
|
|
118
|
+
* When provided, the AI will attempt to extract structured data
|
|
119
|
+
* from the conversation before executing the tool.
|
|
120
|
+
*/
|
|
121
|
+
dataSchema?: ToolDataSchema;
|
|
122
|
+
/**
|
|
123
|
+
* Default data to pass to the handler.
|
|
124
|
+
*/
|
|
125
|
+
defaultData?: TData;
|
|
126
|
+
/**
|
|
127
|
+
* Context required for this tool to be available.
|
|
128
|
+
*
|
|
129
|
+
* @example { loggedIn: true, plan: 'pro' }
|
|
130
|
+
*/
|
|
131
|
+
requiredContext?: Record<string, unknown>;
|
|
132
|
+
/**
|
|
133
|
+
* Whether to auto-run this tool without user confirmation.
|
|
134
|
+
*
|
|
135
|
+
* Only the highest-scoring tool can auto-run.
|
|
136
|
+
* Use for simple navigations where user intent is clear.
|
|
137
|
+
*
|
|
138
|
+
* @default false
|
|
139
|
+
*/
|
|
140
|
+
autoRun?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Whether the tool completes immediately after execution.
|
|
143
|
+
*
|
|
144
|
+
* If false, the SDK waits for host app confirmation.
|
|
145
|
+
* Use true for simple navigations and clipboard operations.
|
|
146
|
+
*
|
|
147
|
+
* @default false
|
|
148
|
+
*/
|
|
149
|
+
autoComplete?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Whether this tool returns data for the agent.
|
|
152
|
+
*
|
|
153
|
+
* If true, the handler's return value is sent back to the agent
|
|
154
|
+
* for further reasoning. Use for query/lookup tools that inform
|
|
155
|
+
* the agent's next decision.
|
|
156
|
+
*
|
|
157
|
+
* @default false
|
|
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
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Handler function executed when the tool is triggered.
|
|
174
|
+
*
|
|
175
|
+
* This runs in the client - the server only stores metadata.
|
|
176
|
+
* If `returns: true`, the return value is sent to the agent.
|
|
177
|
+
*/
|
|
178
|
+
handler: (data: TData) => void | unknown | Promise<void | unknown>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Map of tool name to definition.
|
|
182
|
+
*
|
|
183
|
+
* Tool names should be snake_case identifiers.
|
|
184
|
+
*/
|
|
185
|
+
export type ToolDefinitions = Record<string, ToolDefinition<unknown>>;
|
|
186
|
+
/**
|
|
187
|
+
* Metadata for a single tool in the manifest (no handler).
|
|
188
|
+
*
|
|
189
|
+
* This is what gets synced to the server.
|
|
190
|
+
*/
|
|
191
|
+
export interface ToolManifestEntry {
|
|
192
|
+
name: string;
|
|
193
|
+
description: string;
|
|
194
|
+
examples?: string[];
|
|
195
|
+
type: ToolType;
|
|
196
|
+
path?: string;
|
|
197
|
+
external_url?: string;
|
|
198
|
+
auto_run?: boolean;
|
|
199
|
+
auto_complete?: boolean;
|
|
200
|
+
returns_data?: boolean;
|
|
201
|
+
data_schema?: ToolDataSchema;
|
|
202
|
+
default_data?: Record<string, unknown>;
|
|
203
|
+
required_context?: Record<string, unknown>;
|
|
204
|
+
parameter_examples?: Array<{
|
|
205
|
+
description: string;
|
|
206
|
+
parameters: Record<string, unknown>;
|
|
207
|
+
}>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Tool manifest - synced to server during CI/CD.
|
|
211
|
+
*
|
|
212
|
+
* Contains all tool metadata without handlers.
|
|
213
|
+
*/
|
|
214
|
+
export interface ToolManifest {
|
|
215
|
+
/**
|
|
216
|
+
* Platform this manifest is for.
|
|
217
|
+
*/
|
|
218
|
+
platform: Platform;
|
|
219
|
+
/**
|
|
220
|
+
* Version of the client app (semver or git SHA).
|
|
221
|
+
*/
|
|
222
|
+
version: string;
|
|
223
|
+
/**
|
|
224
|
+
* Git commit SHA for traceability.
|
|
225
|
+
*/
|
|
226
|
+
gitSha?: string;
|
|
227
|
+
/**
|
|
228
|
+
* When this manifest was generated.
|
|
229
|
+
*/
|
|
230
|
+
generatedAt: string;
|
|
231
|
+
/**
|
|
232
|
+
* Tool definitions (without handlers).
|
|
233
|
+
*/
|
|
234
|
+
tools: ToolManifestEntry[];
|
|
235
|
+
/**
|
|
236
|
+
* Custom agent guidance synced alongside tools.
|
|
237
|
+
* Injected into the AI agent's prompt as product_guidance.
|
|
238
|
+
*/
|
|
239
|
+
agentGuidance?: string;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Client info set during SDK initialization.
|
|
243
|
+
*/
|
|
244
|
+
export interface ClientInfo {
|
|
245
|
+
platform: Platform;
|
|
246
|
+
version: string;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Tool definition for syncing (without handler).
|
|
250
|
+
*
|
|
251
|
+
* Use this type when defining tools for CI/CD sync.
|
|
252
|
+
* Handlers are registered separately at runtime via pillar.onTask().
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* import type { SyncToolDefinitions } from '@pillar-ai/sdk';
|
|
257
|
+
*
|
|
258
|
+
* export const tools: SyncToolDefinitions = {
|
|
259
|
+
* open_settings: {
|
|
260
|
+
* description: 'Navigate to settings page',
|
|
261
|
+
* type: 'navigate',
|
|
262
|
+
* path: '/settings',
|
|
263
|
+
* autoRun: true,
|
|
264
|
+
* },
|
|
265
|
+
* };
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
export interface SyncToolDefinition<TData = Record<string, unknown>> {
|
|
269
|
+
/** Human-readable description for AI matching */
|
|
270
|
+
description: string;
|
|
271
|
+
/** Example user queries that should trigger this tool */
|
|
272
|
+
examples?: string[];
|
|
273
|
+
/** Type of tool */
|
|
274
|
+
type: ToolType;
|
|
275
|
+
/** Path for navigate tools */
|
|
276
|
+
path?: string;
|
|
277
|
+
/** External URL for external_link tools */
|
|
278
|
+
externalUrl?: string;
|
|
279
|
+
/** JSON Schema for data extraction from user query */
|
|
280
|
+
dataSchema?: ToolDataSchema;
|
|
281
|
+
/** Default data to pass to the handler */
|
|
282
|
+
defaultData?: TData;
|
|
283
|
+
/** Context required for this tool to be available */
|
|
284
|
+
requiredContext?: Record<string, unknown>;
|
|
285
|
+
/** Whether to auto-run this tool without user confirmation */
|
|
286
|
+
autoRun?: boolean;
|
|
287
|
+
/** Whether the tool completes immediately after execution */
|
|
288
|
+
autoComplete?: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* Whether this tool returns data for the agent.
|
|
291
|
+
* If true, the handler's return value is sent back to the agent.
|
|
292
|
+
*/
|
|
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
|
+
}>;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Map of tool name to sync definition (no handlers).
|
|
306
|
+
*
|
|
307
|
+
* Use this type for your tools file that gets synced via CI/CD.
|
|
308
|
+
*/
|
|
309
|
+
export type SyncToolDefinitions = Record<string, SyncToolDefinition<unknown>>;
|
|
310
|
+
/**
|
|
311
|
+
* Base data types for each tool type.
|
|
312
|
+
* These are automatically inferred from the tool's `type` field.
|
|
313
|
+
*/
|
|
314
|
+
export interface NavigateToolData {
|
|
315
|
+
/** CSS selector to highlight after navigation */
|
|
316
|
+
highlight_selector?: string;
|
|
317
|
+
/** Path that was navigated to (injected by SDK) */
|
|
318
|
+
path?: string;
|
|
319
|
+
}
|
|
320
|
+
export interface TriggerToolData {
|
|
321
|
+
/** The tool being triggered */
|
|
322
|
+
tool?: string;
|
|
323
|
+
/** Additional tool parameters */
|
|
324
|
+
[key: string]: unknown;
|
|
325
|
+
}
|
|
326
|
+
export interface InlineUIData {
|
|
327
|
+
/** Card type for rendering */
|
|
328
|
+
card_type: string;
|
|
329
|
+
/** Additional card data */
|
|
330
|
+
[key: string]: unknown;
|
|
331
|
+
}
|
|
332
|
+
export interface ExternalLinkData {
|
|
333
|
+
/** The URL being opened */
|
|
334
|
+
url?: string;
|
|
335
|
+
}
|
|
336
|
+
export interface CopyTextData {
|
|
337
|
+
/** Text to copy to clipboard */
|
|
338
|
+
text?: string;
|
|
339
|
+
}
|
|
340
|
+
export interface QueryToolData {
|
|
341
|
+
/** Query parameters passed to the handler */
|
|
342
|
+
[key: string]: unknown;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Maps tool types to their default data shapes.
|
|
346
|
+
* Used for automatic type inference in onTask handlers.
|
|
347
|
+
*/
|
|
348
|
+
export interface ToolTypeDataMap {
|
|
349
|
+
navigate: NavigateToolData;
|
|
350
|
+
trigger_tool: TriggerToolData;
|
|
351
|
+
query: QueryToolData;
|
|
352
|
+
inline_ui: InlineUIData;
|
|
353
|
+
external_link: ExternalLinkData;
|
|
354
|
+
copy_text: CopyTextData;
|
|
355
|
+
open_modal: Record<string, unknown>;
|
|
356
|
+
fill_form: Record<string, unknown>;
|
|
357
|
+
start_tutorial: Record<string, unknown>;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Extract the data type for a specific tool from a ToolDefinitions map.
|
|
361
|
+
*
|
|
362
|
+
* Type inference priority:
|
|
363
|
+
* 1. If `defaultData` is defined, use that type (for custom fields)
|
|
364
|
+
* 2. Otherwise, infer from the tool's `type` field using ToolTypeDataMap
|
|
365
|
+
* 3. Fall back to Record<string, unknown>
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```ts
|
|
369
|
+
* const tools = {
|
|
370
|
+
* // Inferred from type: "navigate" → NavigateToolData
|
|
371
|
+
* open_settings: {
|
|
372
|
+
* description: '...',
|
|
373
|
+
* type: 'navigate',
|
|
374
|
+
* path: '/settings',
|
|
375
|
+
* },
|
|
376
|
+
* // Custom data via defaultData
|
|
377
|
+
* add_source: {
|
|
378
|
+
* description: '...',
|
|
379
|
+
* type: 'navigate',
|
|
380
|
+
* defaultData: { type: '', url: '', name: '' },
|
|
381
|
+
* },
|
|
382
|
+
* } as const satisfies SyncToolDefinitions;
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
export type ToolDataType<TTools extends SyncToolDefinitions | ToolDefinitions, TName extends keyof TTools> = TTools[TName] extends {
|
|
386
|
+
defaultData: infer D;
|
|
387
|
+
} ? D extends Record<string, unknown> ? D : Record<string, unknown> : TTools[TName] extends {
|
|
388
|
+
type: infer T;
|
|
389
|
+
} ? T extends keyof ToolTypeDataMap ? ToolTypeDataMap[T] : Record<string, unknown> : Record<string, unknown>;
|
|
390
|
+
/**
|
|
391
|
+
* Extract all tool names from a ToolDefinitions map.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```ts
|
|
395
|
+
* const tools = { open_settings: {...}, add_source: {...} };
|
|
396
|
+
* type Names = ToolNames<typeof tools>; // 'open_settings' | 'add_source'
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
export type ToolNames<T extends SyncToolDefinitions | ToolDefinitions> = Extract<keyof T, string>;
|
|
400
|
+
/**
|
|
401
|
+
* Typed task handler function.
|
|
402
|
+
*
|
|
403
|
+
* @template TData - The data type for this tool
|
|
404
|
+
*/
|
|
405
|
+
export type TypedTaskHandler<TData = Record<string, unknown>> = (data: TData) => void | Promise<void>;
|
|
406
|
+
/**
|
|
407
|
+
* Type-safe onTask method signature.
|
|
408
|
+
*
|
|
409
|
+
* When tools are provided to PillarProvider, this type enables
|
|
410
|
+
* TypeScript to infer the correct data type for each tool handler.
|
|
411
|
+
*
|
|
412
|
+
* @template TTools - The tool definitions map
|
|
413
|
+
*/
|
|
414
|
+
export interface TypedOnTask<TTools extends SyncToolDefinitions | ToolDefinitions> {
|
|
415
|
+
<TName extends ToolNames<TTools>>(taskName: TName, handler: TypedTaskHandler<ToolDataType<TTools, TName>>): () => void;
|
|
416
|
+
(taskName: string, handler: TypedTaskHandler): () => void;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Extended Pillar interface with type-safe onTask.
|
|
420
|
+
*
|
|
421
|
+
* Use this when you want strongly typed task handlers based on
|
|
422
|
+
* your tool definitions.
|
|
423
|
+
*
|
|
424
|
+
* @template TTools - The tool definitions map
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* import type { TypedPillar } from '@pillar-ai/sdk';
|
|
429
|
+
* import type { tools } from './tools';
|
|
430
|
+
*
|
|
431
|
+
* const pillar = usePillar<typeof tools>();
|
|
432
|
+
*
|
|
433
|
+
* // TypeScript knows `data` has { type, url, name }
|
|
434
|
+
* pillar.onTask('add_source', (data) => {
|
|
435
|
+
* console.log(data.url);
|
|
436
|
+
* });
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
export interface TypedPillarMethods<TTools extends SyncToolDefinitions | ToolDefinitions> {
|
|
440
|
+
onTask: TypedOnTask<TTools>;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Result returned from a tool's execute function.
|
|
444
|
+
*
|
|
445
|
+
* Follows the MCP tool result format. Plain objects are also accepted
|
|
446
|
+
* by the SDK and normalized to this shape automatically.
|
|
447
|
+
*/
|
|
448
|
+
export interface ToolExecuteResult {
|
|
449
|
+
content: Array<{
|
|
450
|
+
type: 'text';
|
|
451
|
+
text: string;
|
|
452
|
+
} | {
|
|
453
|
+
type: 'image';
|
|
454
|
+
data: string;
|
|
455
|
+
mimeType: string;
|
|
456
|
+
}>;
|
|
457
|
+
isError?: boolean;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Unified tool definition that co-locates metadata and handler.
|
|
461
|
+
*
|
|
462
|
+
* Use with `pillar.defineTool()` or the `usePillarTool()` React hook.
|
|
463
|
+
* The CLI scanner (`npx pillar-sync --scan ./src`) discovers these
|
|
464
|
+
* definitions automatically — no barrel file needed.
|
|
465
|
+
*
|
|
466
|
+
* @template TInput - Type of the input object passed to `execute`
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```ts
|
|
470
|
+
* pillar.defineTool({
|
|
471
|
+
* name: 'add_to_cart',
|
|
472
|
+
* description: 'Add a product to the shopping cart',
|
|
473
|
+
* inputSchema: {
|
|
474
|
+
* type: 'object',
|
|
475
|
+
* properties: {
|
|
476
|
+
* productId: { type: 'string', description: 'Product ID' },
|
|
477
|
+
* quantity: { type: 'number', description: 'Quantity to add' },
|
|
478
|
+
* },
|
|
479
|
+
* required: ['productId', 'quantity'],
|
|
480
|
+
* },
|
|
481
|
+
* execute: async ({ productId, quantity }) => {
|
|
482
|
+
* await cartApi.add(productId, quantity);
|
|
483
|
+
* return { content: [{ type: 'text', text: 'Added to cart' }] };
|
|
484
|
+
* },
|
|
485
|
+
* });
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
export interface ToolSchema<TInput = Record<string, unknown>> {
|
|
489
|
+
/** Unique tool name (e.g., 'add_to_cart') */
|
|
490
|
+
name: string;
|
|
491
|
+
/** Human-readable description for AI matching */
|
|
492
|
+
description: string;
|
|
493
|
+
/**
|
|
494
|
+
* Type of tool - determines how the SDK handles it and organizes it in the UI.
|
|
495
|
+
*/
|
|
496
|
+
type?: ToolType;
|
|
497
|
+
/**
|
|
498
|
+
* JSON Schema describing the input parameters.
|
|
499
|
+
* The AI extracts structured data from the conversation to populate these.
|
|
500
|
+
*/
|
|
501
|
+
inputSchema?: {
|
|
502
|
+
type: 'object';
|
|
503
|
+
properties: Record<string, unknown>;
|
|
504
|
+
required?: string[];
|
|
505
|
+
};
|
|
506
|
+
/**
|
|
507
|
+
* Example user queries that should trigger this tool.
|
|
508
|
+
* Used for semantic matching alongside the description.
|
|
509
|
+
*/
|
|
510
|
+
examples?: string[];
|
|
511
|
+
/**
|
|
512
|
+
* Whether to auto-execute without user confirmation.
|
|
513
|
+
* @default false
|
|
514
|
+
*/
|
|
515
|
+
autoRun?: boolean;
|
|
516
|
+
/**
|
|
517
|
+
* Whether the tool completes immediately after execution.
|
|
518
|
+
* @default true
|
|
519
|
+
*/
|
|
520
|
+
autoComplete?: boolean;
|
|
521
|
+
/**
|
|
522
|
+
* Handler function executed when the AI invokes this tool.
|
|
523
|
+
*
|
|
524
|
+
* Can return:
|
|
525
|
+
* - A `ToolExecuteResult` with MCP-style content blocks
|
|
526
|
+
* - A plain object (SDK normalizes it for the agent)
|
|
527
|
+
* - `void` if the tool has no return value
|
|
528
|
+
*/
|
|
529
|
+
execute: (input: TInput) => Promise<ToolExecuteResult | unknown | void> | ToolExecuteResult | unknown | void;
|
|
530
|
+
}
|
|
531
|
+
/** @deprecated Use ToolType instead */
|
|
532
|
+
export type ActionType = ToolType;
|
|
533
|
+
/** @deprecated Use ToolDataSchemaProperty instead */
|
|
534
|
+
export type ActionDataSchemaProperty = ToolDataSchemaProperty;
|
|
535
|
+
/** @deprecated Use ToolDataSchema instead */
|
|
536
|
+
export type ActionDataSchema = ToolDataSchema;
|
|
537
|
+
/** @deprecated Use ToolDefinition instead */
|
|
538
|
+
export type ActionDefinition<TData = Record<string, unknown>> = ToolDefinition<TData>;
|
|
539
|
+
/** @deprecated Use ToolDefinitions instead */
|
|
540
|
+
export type ActionDefinitions = ToolDefinitions;
|
|
541
|
+
/** @deprecated Use ToolManifestEntry instead */
|
|
542
|
+
export type ActionManifestEntry = ToolManifestEntry;
|
|
543
|
+
/** @deprecated Use ToolManifest instead */
|
|
544
|
+
export type ActionManifest = ToolManifest;
|
|
545
|
+
/** @deprecated Use SyncToolDefinition instead */
|
|
546
|
+
export type SyncActionDefinition<TData = Record<string, unknown>> = SyncToolDefinition<TData>;
|
|
547
|
+
/** @deprecated Use SyncToolDefinitions instead */
|
|
548
|
+
export type SyncActionDefinitions = SyncToolDefinitions;
|
|
549
|
+
/** @deprecated Use NavigateToolData instead */
|
|
550
|
+
export type NavigateActionData = NavigateToolData;
|
|
551
|
+
/** @deprecated Use TriggerToolData instead */
|
|
552
|
+
export type TriggerActionData = TriggerToolData;
|
|
553
|
+
/** @deprecated Use QueryToolData instead */
|
|
554
|
+
export type QueryActionData = QueryToolData;
|
|
555
|
+
/** @deprecated Use ToolTypeDataMap instead */
|
|
556
|
+
export type ActionTypeDataMap = ToolTypeDataMap;
|
|
557
|
+
/** @deprecated Use ToolDataType instead */
|
|
558
|
+
export type ActionDataType<TTools extends SyncToolDefinitions | ToolDefinitions, TName extends keyof TTools> = ToolDataType<TTools, TName>;
|
|
559
|
+
/** @deprecated Use ToolNames instead */
|
|
560
|
+
export type ActionNames<T extends SyncToolDefinitions | ToolDefinitions> = ToolNames<T>;
|
|
561
|
+
/** @deprecated Use ToolExecuteResult instead */
|
|
562
|
+
export type ActionResult = ToolExecuteResult;
|
|
563
|
+
/** @deprecated Use ToolSchema instead */
|
|
564
|
+
export type ActionSchema<TInput = Record<string, unknown>> = ToolSchema<TInput>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Help Desk Utilities
|
|
3
|
+
* Functions to trigger external help desk widgets (Intercom, Pylon, Zendesk, Freshdesk)
|
|
4
|
+
*/
|
|
5
|
+
import type { HelpDeskProvider } from '../core/config';
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
Intercom?: (command: string, ...args: unknown[]) => void;
|
|
9
|
+
Pylon?: (command: string, ...args: unknown[]) => void;
|
|
10
|
+
zE?: (widget: string, command: string, ...args: unknown[]) => void;
|
|
11
|
+
FreshworksWidget?: (command: string, ...args: unknown[]) => void;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Context to pass to help desk when escalating
|
|
16
|
+
*/
|
|
17
|
+
export interface HelpDeskContext {
|
|
18
|
+
conversationSummary?: string;
|
|
19
|
+
currentPage?: string;
|
|
20
|
+
userId?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Trigger the appropriate help desk widget based on provider
|
|
24
|
+
*/
|
|
25
|
+
export declare function triggerHelpDesk(provider: HelpDeskProvider, context?: HelpDeskContext): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Open email client with optional subject and body
|
|
28
|
+
*/
|
|
29
|
+
export declare function openEmail(emailAddress: string, subject?: string, body?: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Open a URL in a new tab
|
|
32
|
+
*/
|
|
33
|
+
export declare function openUrl(url: string): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resilient fetch wrapper with configurable exponential backoff.
|
|
3
|
+
*
|
|
4
|
+
* Retries on network errors (TypeError / Failed to fetch) and 5xx responses.
|
|
5
|
+
* Does NOT retry on 4xx (client errors) since those won't resolve by retrying.
|
|
6
|
+
*
|
|
7
|
+
* Base delay default (100ms) matches the `exponential-backoff` library.
|
|
8
|
+
* Backoff schedule: baseDelayMs * 2^(attempt-1) --> 100, 200, 400, 800, 1600, 3200 ...
|
|
9
|
+
*/
|
|
10
|
+
export interface ResilientFetchOptions extends RequestInit {
|
|
11
|
+
/** Max retry attempts after the initial request (0 = no retries). Default: 0 */
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
/** Base delay in ms for exponential backoff. Default: 100 */
|
|
14
|
+
baseDelayMs?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Custom predicate to decide whether a failed attempt should be retried.
|
|
17
|
+
* Called with the caught error (for network failures) or the Response (for HTTP errors).
|
|
18
|
+
* Return `true` to retry, `false` to fail immediately.
|
|
19
|
+
* Default: retry on network errors + 5xx status codes.
|
|
20
|
+
*/
|
|
21
|
+
retryOn?: (error: unknown, response?: Response) => boolean;
|
|
22
|
+
/** Called before each retry. Useful for per-call-site logging. */
|
|
23
|
+
onRetry?: (attempt: number, delay: number, error: unknown) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function resilientFetch(url: string, options?: ResilientFetchOptions): Promise<Response>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pillar-ai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "Product copilot SDK for SaaS and web apps — AI assistant that executes tasks, not just answers questions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/pillar.esm.js",
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
"@preact/signals": "^1.3.1",
|
|
69
69
|
"marked": "^17.0.1",
|
|
70
70
|
"preact": "^10.25.4",
|
|
71
|
-
"preact-iso": "^2.9.0"
|
|
71
|
+
"preact-iso": "^2.9.0",
|
|
72
|
+
"user": "^0.0.0"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
75
|
"@babel/core": "^7.24.0",
|