@pillar-ai/sdk 0.1.8 → 0.1.14
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 +118 -60
- package/dist/actions/index.d.ts +1 -1
- package/dist/actions/registry.d.ts +15 -27
- package/dist/actions/types.d.ts +20 -8
- package/dist/api/client.d.ts +91 -5
- package/dist/api/mcp-client.d.ts +105 -79
- package/dist/cli/sync.d.ts +0 -1
- package/dist/cli/sync.js +102 -14
- package/dist/components/DebugPanel/DebugPanel.d.ts +25 -0
- package/dist/components/DebugPanel/index.d.ts +2 -0
- package/dist/components/DevTools/index.d.ts +5 -0
- package/dist/components/DevTools/styles.d.ts +5 -0
- package/dist/components/Panel/Header.d.ts +1 -1
- package/dist/components/Panel/HistoryDropdown.d.ts +10 -0
- package/dist/components/Panel/Panel.d.ts +1 -0
- package/dist/components/Panel/TaskButton.d.ts +4 -14
- package/dist/components/Panel/styles.d.ts +1 -1
- package/dist/components/Plan/InlinePlanView.d.ts +1 -1
- package/dist/components/Plan/PlanDocument.d.ts +18 -0
- package/dist/components/Plan/PlanStepItem.d.ts +1 -1
- package/dist/components/Plan/PlanView.d.ts +1 -1
- package/dist/components/Plan/index.d.ts +1 -0
- package/dist/components/Progress/ProgressRow.d.ts +16 -0
- package/dist/components/Progress/ProgressStack.d.ts +15 -0
- package/dist/components/Progress/ReasoningDisclosure.d.ts +20 -0
- package/dist/components/Progress/index.d.ts +3 -0
- package/dist/components/Views/HomeView.d.ts +3 -0
- package/dist/components/Views/ResumePrompt.d.ts +22 -0
- package/dist/components/Views/index.d.ts +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/shared/icons.d.ts +24 -0
- package/dist/components/shared/index.d.ts +1 -0
- package/dist/core/Pillar.d.ts +318 -80
- package/dist/core/config.d.ts +141 -3
- package/dist/core/events.d.ts +55 -70
- package/dist/core/plan-executor.d.ts +29 -0
- package/dist/core/plan.d.ts +6 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useDebouncedValue.d.ts +22 -0
- package/dist/hooks/useInlineCard.d.ts +35 -0
- package/dist/hooks/usePillarInstance.d.ts +30 -0
- package/dist/index.d.ts +14 -12
- package/dist/pillar.esm.js +1 -1
- package/dist/store/chat.d.ts +102 -4
- package/dist/store/index.d.ts +1 -0
- package/dist/store/session-persistence.d.ts +62 -0
- package/dist/store/suggestions.d.ts +58 -0
- package/dist/types/dom-scanner.d.ts +46 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/user-context.d.ts +32 -1
- package/dist/utils/debug.d.ts +150 -0
- package/dist/utils/dom-scanner.d.ts +44 -0
- package/dist/utils/markdown-components.d.ts +53 -0
- package/dist/utils/preact-markdown.d.ts +17 -0
- package/dist/utils/route-observer.d.ts +67 -0
- package/package.json +1 -1
- package/src/actions/types.ts +21 -7
- package/dist/utils/markdown.d.ts +0 -9
package/README.md
CHANGED
|
@@ -1,42 +1,132 @@
|
|
|
1
1
|
# @pillar-ai/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cursor for your product — Embed an AI co-pilot that executes tasks, not just answers questions.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@pillar-ai/sdk)
|
|
6
|
+
[](https://www.npmjs.com/package/@pillar-ai/sdk)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
|
|
10
|
+
## What is Pillar?
|
|
11
|
+
|
|
12
|
+
Pillar is an embedded AI co-pilot that helps users complete tasks, not just answer questions. Users say what they want, and Pillar uses your UI to make it happen — navigating pages, pre-filling forms, and calling your APIs.
|
|
13
|
+
|
|
14
|
+
**How it works:**
|
|
15
|
+
|
|
16
|
+
1. User asks: *"Export this to CSV"* or *"Turn off email notifications"*
|
|
17
|
+
2. Pillar understands intent and chains actions
|
|
18
|
+
3. Your code executes with the user's session
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- **Task Execution** — Navigate pages, pre-fill forms, call APIs on behalf of users
|
|
23
|
+
- **Multi-Step Plans** — Chain actions into workflows for complex tasks
|
|
24
|
+
- **Context-Aware** — Knows current page, user state, and selected text
|
|
25
|
+
- **Knowledge Sync** — Trained on your docs, Zendesk, Intercom, and more
|
|
26
|
+
- **Custom Action Cards** — Render interactive UI for confirmations and data input
|
|
27
|
+
- **Framework Bindings** — First-class support for React, Vue, and Svelte
|
|
28
|
+
|
|
29
|
+
## Why Pillar?
|
|
30
|
+
|
|
31
|
+
- **Runs client-side** with the user's session — no proxy servers, no token forwarding
|
|
32
|
+
- **One npm install**, define your actions, and you're live
|
|
33
|
+
- **Syncs with your docs** for grounded, accurate answers
|
|
34
|
+
|
|
35
|
+
## Documentation
|
|
36
|
+
|
|
37
|
+
**[View Full Documentation](https://trypillar.com/docs)** | [Getting Started](https://trypillar.com/docs/getting-started/quick-start) | [API Reference](https://trypillar.com/docs/reference/core)
|
|
4
38
|
|
|
5
39
|
## Installation
|
|
6
40
|
|
|
7
41
|
```bash
|
|
8
42
|
npm install @pillar-ai/sdk
|
|
43
|
+
# or
|
|
44
|
+
pnpm add @pillar-ai/sdk
|
|
45
|
+
# or
|
|
46
|
+
yarn add @pillar-ai/sdk
|
|
9
47
|
```
|
|
10
48
|
|
|
11
49
|
## Quick Start
|
|
12
50
|
|
|
51
|
+
### 1. Get Your Product Key
|
|
52
|
+
|
|
53
|
+
First, register your product in the [Pillar app](https://app.trypillar.com):
|
|
54
|
+
|
|
55
|
+
1. Sign up or log in at [app.trypillar.com](https://app.trypillar.com)
|
|
56
|
+
2. Create a new product
|
|
57
|
+
3. Copy your **Product Key** from the settings page
|
|
58
|
+
|
|
59
|
+
### 2. Initialize the SDK
|
|
60
|
+
|
|
13
61
|
```javascript
|
|
14
62
|
import { Pillar } from "@pillar-ai/sdk";
|
|
15
63
|
|
|
16
|
-
|
|
17
|
-
|
|
64
|
+
// Initialize and get the instance
|
|
65
|
+
const pillar = await Pillar.init({
|
|
66
|
+
productKey: "your-product-key", // From Pillar app
|
|
18
67
|
});
|
|
68
|
+
|
|
69
|
+
// Now you can use instance methods
|
|
70
|
+
pillar.setContext({ currentPage: "/dashboard" });
|
|
71
|
+
pillar.open();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
You can also get the instance later using `Pillar.getInstance()`:
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
// Anywhere in your app after init
|
|
78
|
+
const pillar = Pillar.getInstance();
|
|
79
|
+
pillar?.setContext({ currentPage: "/settings" });
|
|
19
80
|
```
|
|
20
81
|
|
|
82
|
+
## Defining Actions
|
|
83
|
+
|
|
84
|
+
Define what your co-pilot can do. When users make requests, Pillar matches intent to actions and executes them.
|
|
85
|
+
|
|
86
|
+
### Register Task Handlers
|
|
87
|
+
|
|
88
|
+
Use `onTask` to handle actions when the AI executes them:
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const pillar = await Pillar.init({
|
|
92
|
+
productKey: "your-product-key",
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Handle navigation
|
|
96
|
+
pillar.onTask("go_to_settings", (data) => {
|
|
97
|
+
router.push("/settings");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Handle triggers
|
|
101
|
+
pillar.onTask("export_to_csv", async (data) => {
|
|
102
|
+
await downloadCSV();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Handle actions with data
|
|
106
|
+
pillar.onTask("update_preferences", (data) => {
|
|
107
|
+
updateUserPreferences(data.emailAlerts, data.frequency);
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Code-First Action Definitions
|
|
112
|
+
|
|
113
|
+
For production, define actions in code and sync them via the `pillar-sync` CLI during CI/CD. See [Setting Up Actions](https://trypillar.com/docs/guides/actions) for details.
|
|
114
|
+
|
|
21
115
|
## Configuration
|
|
22
116
|
|
|
23
117
|
```javascript
|
|
24
|
-
Pillar.init({
|
|
25
|
-
|
|
26
|
-
helpCenter: "your-help-center",
|
|
118
|
+
const pillar = await Pillar.init({
|
|
119
|
+
productKey: "your-product-key",
|
|
27
120
|
|
|
28
|
-
// Optional configuration
|
|
29
121
|
panel: {
|
|
30
122
|
position: "right", // 'left' | 'right'
|
|
31
123
|
mode: "push", // 'overlay' | 'push'
|
|
32
124
|
},
|
|
33
125
|
|
|
34
|
-
// Edge trigger (sidebar tab that opens the panel)
|
|
35
126
|
edgeTrigger: {
|
|
36
|
-
enabled: true, // Set to false to use your own
|
|
127
|
+
enabled: true, // Set to false to use your own button
|
|
37
128
|
},
|
|
38
129
|
|
|
39
|
-
// Theme
|
|
40
130
|
theme: {
|
|
41
131
|
mode: "auto", // 'light' | 'dark' | 'auto'
|
|
42
132
|
colors: {
|
|
@@ -46,63 +136,31 @@ Pillar.init({
|
|
|
46
136
|
});
|
|
47
137
|
```
|
|
48
138
|
|
|
49
|
-
## Custom Trigger Button
|
|
50
|
-
|
|
51
|
-
To use your own button instead of the built-in edge trigger:
|
|
52
|
-
|
|
53
|
-
```javascript
|
|
54
|
-
Pillar.init({
|
|
55
|
-
helpCenter: "your-help-center",
|
|
56
|
-
edgeTrigger: { enabled: false },
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Then control the panel programmatically
|
|
60
|
-
document.getElementById("my-help-button").addEventListener("click", () => {
|
|
61
|
-
Pillar.toggle();
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Features
|
|
66
|
-
|
|
67
|
-
- **AI Chat**: Embedded AI assistant that understands your product
|
|
68
|
-
- **Edge Trigger**: Built-in sidebar tab to open the help panel (or use your own button)
|
|
69
|
-
- **Contextual Help**: Show relevant help based on user context
|
|
70
|
-
- **Text Selection**: Allow users to ask questions about selected text
|
|
71
|
-
- **Customizable UI**: Full control over positioning, theming, and behavior
|
|
72
|
-
|
|
73
139
|
## API Reference
|
|
74
140
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
Initialize the SDK
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
141
|
+
| Method | Description |
|
|
142
|
+
|--------|-------------|
|
|
143
|
+
| `Pillar.init(config)` | Initialize the SDK, returns the instance |
|
|
144
|
+
| `Pillar.getInstance()` | Get the initialized SDK instance |
|
|
145
|
+
| `pillar.open()` | Open the co-pilot panel |
|
|
146
|
+
| `pillar.close()` | Close the co-pilot panel |
|
|
147
|
+
| `pillar.toggle()` | Toggle the co-pilot panel |
|
|
148
|
+
| `pillar.setContext(context)` | Update the user/product context |
|
|
149
|
+
| `pillar.on(event, callback)` | Subscribe to SDK events |
|
|
84
150
|
|
|
85
|
-
|
|
151
|
+
> **Note:** `Pillar.init()` and `Pillar.getInstance()` are static methods on the class. All other methods (lowercase `pillar`) are instance methods - call them on the instance returned from `init()` or `getInstance()`.
|
|
86
152
|
|
|
87
|
-
|
|
153
|
+
For complete API documentation, see the [API Reference](https://trypillar.com/docs/reference/core).
|
|
88
154
|
|
|
89
|
-
|
|
155
|
+
## Framework Integrations
|
|
90
156
|
|
|
91
|
-
|
|
157
|
+
For idiomatic integration with your framework, use our framework-specific packages:
|
|
92
158
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
## React Integration
|
|
100
|
-
|
|
101
|
-
For React applications, use the `@pillar-ai/react` package for a more idiomatic integration with hooks and components.
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
npm install @pillar-ai/react
|
|
105
|
-
```
|
|
159
|
+
| Framework | Package | Installation |
|
|
160
|
+
|-----------|---------|--------------|
|
|
161
|
+
| React | [@pillar-ai/react](https://github.com/pillarhq/sdk-react) | `npm install @pillar-ai/react` |
|
|
162
|
+
| Vue | [@pillar-ai/vue](https://github.com/pillarhq/sdk-vue) | `npm install @pillar-ai/vue` |
|
|
163
|
+
| Svelte | [@pillar-ai/svelte](https://github.com/pillarhq/sdk-svelte) | `npm install @pillar-ai/svelte` |
|
|
106
164
|
|
|
107
165
|
## License
|
|
108
166
|
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
* @module actions
|
|
31
31
|
*/
|
|
32
32
|
export type { ActionType, ActionDataSchema, ActionDefinition, ActionDefinitions, ActionManifest, ActionManifestEntry, ClientInfo, Platform, SyncActionDefinition, SyncActionDefinitions, ActionTypeDataMap, NavigateActionData, TriggerActionData, InlineUIData, ExternalLinkData, CopyTextData, ActionDataType, ActionNames, TypedTaskHandler, TypedOnTask, TypedPillarMethods, } from './types';
|
|
33
|
-
export {
|
|
33
|
+
export { setClientInfo, getClientInfo, getHandler, getActionDefinition, hasAction, getActionNames, getManifest, clearRegistry, getActionCount, } from './registry';
|
|
@@ -2,45 +2,33 @@
|
|
|
2
2
|
* Action Registry - Manages code-defined action handlers.
|
|
3
3
|
*
|
|
4
4
|
* This module provides the registration and lookup mechanism for
|
|
5
|
-
* actions defined in code. Actions are registered
|
|
6
|
-
* and can be looked up by name using `getHandler()`.
|
|
5
|
+
* actions defined in code. Actions are registered at runtime via
|
|
6
|
+
* `pillar.onTask()` and can be looked up by name using `getHandler()`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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.
|
|
8
|
+
* Action metadata is synced to the server during CI/CD builds using
|
|
9
|
+
* the `pillar-sync` CLI with a barrel file export pattern:
|
|
17
10
|
*
|
|
18
11
|
* @example
|
|
19
12
|
* ```ts
|
|
20
|
-
*
|
|
21
|
-
* import {
|
|
13
|
+
* // lib/pillar/actions/index.ts
|
|
14
|
+
* import type { SyncActionDefinitions } from '@pillar-ai/sdk';
|
|
22
15
|
*
|
|
23
|
-
* export const actions =
|
|
16
|
+
* export const actions = {
|
|
24
17
|
* open_settings: {
|
|
25
18
|
* description: 'Navigate to the settings page',
|
|
26
|
-
* type: 'navigate',
|
|
19
|
+
* type: 'navigate' as const,
|
|
27
20
|
* 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
21
|
* autoRun: true,
|
|
35
|
-
* handler: (data) => router.push('/settings/billing', data),
|
|
36
22
|
* },
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
23
|
+
* } as const satisfies SyncActionDefinitions;
|
|
24
|
+
*
|
|
25
|
+
* export default actions;
|
|
39
26
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
27
|
+
* // Sync via CI/CD:
|
|
28
|
+
* // npx pillar-sync --actions ./lib/pillar/actions/index.ts
|
|
29
|
+
* ```
|
|
42
30
|
*/
|
|
43
|
-
|
|
31
|
+
import type { ActionDefinition, ActionManifest, ClientInfo, Platform } from './types';
|
|
44
32
|
/**
|
|
45
33
|
* Set client platform and version info.
|
|
46
34
|
*
|
package/dist/actions/types.d.ts
CHANGED
|
@@ -6,16 +6,22 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
-
*
|
|
9
|
+
* // lib/pillar/actions/index.ts
|
|
10
|
+
* import type { SyncActionDefinitions } from '@pillar-ai/sdk';
|
|
10
11
|
*
|
|
11
|
-
* const actions =
|
|
12
|
+
* export const actions = {
|
|
12
13
|
* open_settings: {
|
|
13
14
|
* description: 'Navigate to the settings page',
|
|
14
|
-
* type: 'navigate',
|
|
15
|
+
* type: 'navigate' as const,
|
|
15
16
|
* path: '/settings',
|
|
16
|
-
*
|
|
17
|
+
* autoRun: true,
|
|
17
18
|
* },
|
|
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'));
|
|
19
25
|
* ```
|
|
20
26
|
*/
|
|
21
27
|
/**
|
|
@@ -25,12 +31,13 @@
|
|
|
25
31
|
* - open_modal: Open a modal or dialog
|
|
26
32
|
* - fill_form: Fill form fields with data
|
|
27
33
|
* - trigger_action: Trigger a custom action
|
|
34
|
+
* - query: Fetch data from the client and return to the agent (implies returns: true)
|
|
28
35
|
* - copy_text: Copy text to clipboard
|
|
29
36
|
* - external_link: Open an external URL
|
|
30
37
|
* - start_tutorial: Start a tutorial/walkthrough
|
|
31
38
|
* - inline_ui: Display inline UI card in chat
|
|
32
39
|
*/
|
|
33
|
-
export type ActionType = 'navigate' | 'open_modal' | 'fill_form' | 'trigger_action' | 'copy_text' | 'external_link' | 'start_tutorial' | 'inline_ui';
|
|
40
|
+
export type ActionType = 'navigate' | 'open_modal' | 'fill_form' | 'trigger_action' | 'query' | 'copy_text' | 'external_link' | 'start_tutorial' | 'inline_ui';
|
|
34
41
|
/**
|
|
35
42
|
* Supported platforms for action deployments.
|
|
36
43
|
*/
|
|
@@ -163,7 +170,7 @@ export interface ActionDefinition<TData = Record<string, unknown>> {
|
|
|
163
170
|
*
|
|
164
171
|
* Action names should be snake_case identifiers.
|
|
165
172
|
*/
|
|
166
|
-
export type ActionDefinitions = Record<string, ActionDefinition<
|
|
173
|
+
export type ActionDefinitions = Record<string, ActionDefinition<unknown>>;
|
|
167
174
|
/**
|
|
168
175
|
* Metadata for a single action in the manifest (no handler).
|
|
169
176
|
*
|
|
@@ -269,7 +276,7 @@ export interface SyncActionDefinition<TData = Record<string, unknown>> {
|
|
|
269
276
|
*
|
|
270
277
|
* Use this type for your actions file that gets synced via CI/CD.
|
|
271
278
|
*/
|
|
272
|
-
export type SyncActionDefinitions = Record<string, SyncActionDefinition<
|
|
279
|
+
export type SyncActionDefinitions = Record<string, SyncActionDefinition<unknown>>;
|
|
273
280
|
/**
|
|
274
281
|
* Base data types for each action type.
|
|
275
282
|
* These are automatically inferred from the action's `type` field.
|
|
@@ -300,6 +307,10 @@ export interface CopyTextData {
|
|
|
300
307
|
/** Text to copy to clipboard */
|
|
301
308
|
text?: string;
|
|
302
309
|
}
|
|
310
|
+
export interface QueryActionData {
|
|
311
|
+
/** Query parameters passed to the handler */
|
|
312
|
+
[key: string]: unknown;
|
|
313
|
+
}
|
|
303
314
|
/**
|
|
304
315
|
* Maps action types to their default data shapes.
|
|
305
316
|
* Used for automatic type inference in onTask handlers.
|
|
@@ -307,6 +318,7 @@ export interface CopyTextData {
|
|
|
307
318
|
export interface ActionTypeDataMap {
|
|
308
319
|
navigate: NavigateActionData;
|
|
309
320
|
trigger_action: TriggerActionData;
|
|
321
|
+
query: QueryActionData;
|
|
310
322
|
inline_ui: InlineUIData;
|
|
311
323
|
external_link: ExternalLinkData;
|
|
312
324
|
copy_text: CopyTextData;
|
package/dist/api/client.d.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
import type { TaskButtonData } from '../components/Panel/TaskButton';
|
|
6
6
|
import type { ResolvedConfig } from '../core/config';
|
|
7
7
|
import type { Context, Suggestion, UserProfile } from '../core/context';
|
|
8
|
-
import type { ExecutionPlan } from '../core/plan';
|
|
9
8
|
import type { Workflow } from '../core/workflow';
|
|
10
9
|
import type { UserContextItem } from '../types/user-context';
|
|
11
|
-
import type { ChatImage, ImageUploadResponse } from './mcp-client';
|
|
10
|
+
import type { ActionRequest, ChatImage, ImageUploadResponse } from './mcp-client';
|
|
11
|
+
import { MCPClient } from './mcp-client';
|
|
12
12
|
export interface ArticleSummary {
|
|
13
13
|
id: string;
|
|
14
14
|
title: string;
|
|
@@ -23,6 +23,8 @@ export interface ChatMessage {
|
|
|
23
23
|
export interface SuggestedQuestion {
|
|
24
24
|
id: string;
|
|
25
25
|
text: string;
|
|
26
|
+
/** If true, this is an admin-configured suggestion that should rank first */
|
|
27
|
+
manual?: boolean;
|
|
26
28
|
}
|
|
27
29
|
export interface ChatResponse {
|
|
28
30
|
message: string;
|
|
@@ -32,10 +34,31 @@ export interface ChatResponse {
|
|
|
32
34
|
messageId?: string;
|
|
33
35
|
actions?: TaskButtonData[];
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Child item within a progress event (e.g., search source, plan step).
|
|
39
|
+
*/
|
|
40
|
+
export interface ProgressChild {
|
|
41
|
+
id: string;
|
|
42
|
+
label: string;
|
|
43
|
+
url?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Progress event for tracking AI response generation steps.
|
|
47
|
+
* Uses a generic design where the server controls display text via `label`.
|
|
48
|
+
*
|
|
49
|
+
* The new schema uses `id` and `status` fields. Legacy fields are kept
|
|
50
|
+
* for backwards compatibility with older backend versions.
|
|
51
|
+
*/
|
|
35
52
|
export interface ProgressEvent {
|
|
36
|
-
kind:
|
|
37
|
-
|
|
53
|
+
kind: string;
|
|
54
|
+
id?: string;
|
|
55
|
+
label?: string;
|
|
56
|
+
status?: 'active' | 'done' | 'error';
|
|
57
|
+
text?: string;
|
|
58
|
+
children?: ProgressChild[];
|
|
59
|
+
metadata?: Record<string, unknown>;
|
|
38
60
|
progress_id?: string;
|
|
61
|
+
message?: string;
|
|
39
62
|
}
|
|
40
63
|
/**
|
|
41
64
|
* Server-side embed config response.
|
|
@@ -58,12 +81,48 @@ export interface ServerEmbedConfig {
|
|
|
58
81
|
};
|
|
59
82
|
};
|
|
60
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Conversation summary in history list.
|
|
86
|
+
*/
|
|
87
|
+
export interface ConversationSummary {
|
|
88
|
+
id: string;
|
|
89
|
+
title: string;
|
|
90
|
+
startedAt: string | null;
|
|
91
|
+
lastMessageAt: string | null;
|
|
92
|
+
messageCount: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Full conversation with messages.
|
|
96
|
+
*/
|
|
97
|
+
export interface ConversationDetail extends ConversationSummary {
|
|
98
|
+
messages: Array<{
|
|
99
|
+
id: string;
|
|
100
|
+
role: 'user' | 'assistant';
|
|
101
|
+
content: string;
|
|
102
|
+
timestamp: string | null;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
61
105
|
export declare class APIClient {
|
|
62
106
|
private config;
|
|
63
107
|
private abortControllers;
|
|
64
108
|
private mcpClient;
|
|
109
|
+
private _externalUserId;
|
|
65
110
|
constructor(config: ResolvedConfig);
|
|
111
|
+
/**
|
|
112
|
+
* Get the underlying MCP client.
|
|
113
|
+
* Used by Pillar for direct MCP operations like sendActionResult.
|
|
114
|
+
*/
|
|
115
|
+
get mcp(): MCPClient;
|
|
66
116
|
private get baseUrl();
|
|
117
|
+
/**
|
|
118
|
+
* Set the external user ID for authenticated users.
|
|
119
|
+
* This ID will be included in all subsequent requests.
|
|
120
|
+
*/
|
|
121
|
+
setExternalUserId(userId: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Clear the external user ID (for logout).
|
|
124
|
+
*/
|
|
125
|
+
clearExternalUserId(): void;
|
|
67
126
|
/**
|
|
68
127
|
* Get or create a persistent visitor ID.
|
|
69
128
|
* Stored in localStorage to persist across sessions.
|
|
@@ -99,7 +158,7 @@ export declare class APIClient {
|
|
|
99
158
|
* @returns Promise with signed URL and expiration
|
|
100
159
|
*/
|
|
101
160
|
uploadImage(file: File): Promise<ImageUploadResponse>;
|
|
102
|
-
chat(message: string, history?: ChatMessage[], onChunk?: (chunk: string) => void, articleSlug?: string, existingConversationId?: string | null, onActions?: (actions: TaskButtonData[]) => void,
|
|
161
|
+
chat(message: string, history?: ChatMessage[], onChunk?: (chunk: string) => void, articleSlug?: string, existingConversationId?: string | null, onActions?: (actions: TaskButtonData[]) => void, userContext?: UserContextItem[], images?: ChatImage[], onProgress?: (progress: ProgressEvent) => void, onConversationStarted?: (conversationId: string, messageId?: string) => void, onActionRequest?: (request: ActionRequest) => Promise<void>): Promise<ChatResponse>;
|
|
103
162
|
/**
|
|
104
163
|
* Legacy chat method using the old /ai/chat/ endpoint.
|
|
105
164
|
* @deprecated Use chat() which uses the MCP protocol.
|
|
@@ -143,5 +202,32 @@ export declare class APIClient {
|
|
|
143
202
|
* Note: Context is passed to the MCP ask tool as additional arguments.
|
|
144
203
|
*/
|
|
145
204
|
chatWithContext(message: string, history: ChatMessage[] | undefined, ctx: Context, userProfile: UserProfile, onChunk?: (chunk: string) => void, existingConversationId?: string | null, onActions?: (actions: TaskButtonData[]) => void): Promise<ChatResponse>;
|
|
205
|
+
/**
|
|
206
|
+
* Identify the current user after login.
|
|
207
|
+
* Links the anonymous visitor to the authenticated user ID, enabling
|
|
208
|
+
* cross-device conversation history.
|
|
209
|
+
*
|
|
210
|
+
* @param userId - Client's authenticated user ID
|
|
211
|
+
* @param profile - Optional user profile data
|
|
212
|
+
*/
|
|
213
|
+
identify(userId: string, profile?: {
|
|
214
|
+
name?: string;
|
|
215
|
+
email?: string;
|
|
216
|
+
metadata?: Record<string, unknown>;
|
|
217
|
+
}): Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* List past conversations for the current visitor.
|
|
220
|
+
*
|
|
221
|
+
* @param limit - Max number of conversations to return (default: 20, max: 50)
|
|
222
|
+
* @returns List of conversation summaries
|
|
223
|
+
*/
|
|
224
|
+
listConversations(limit?: number): Promise<ConversationSummary[]>;
|
|
225
|
+
/**
|
|
226
|
+
* Get a single conversation with all messages.
|
|
227
|
+
*
|
|
228
|
+
* @param conversationId - UUID of the conversation
|
|
229
|
+
* @returns Conversation with messages
|
|
230
|
+
*/
|
|
231
|
+
getConversation(conversationId: string): Promise<ConversationDetail | null>;
|
|
146
232
|
cancelAllRequests(): void;
|
|
147
233
|
}
|