@papermap/papermap 1.0.1 → 1.0.2
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/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/readme.md +107 -99
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Papermap
|
|
2
2
|
|
|
3
|
-
Embeddable AI-powered components from the [Papermap](https://www.papermap.ai) data analytics platform. This is a standalone package
|
|
3
|
+
Embeddable AI-powered components from the [Papermap](https://www.papermap.ai) data analytics platform. This is a standalone package — **independent** from the main Papermap app. Services, SSE streaming, and UI are self-contained; the repos do not depend on each other.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Main components
|
|
6
6
|
|
|
7
|
-
- **`PapermapChat`**
|
|
8
|
-
- **`PapermapChartCard`**
|
|
9
|
-
- **`
|
|
7
|
+
- **`PapermapChat`** — Full AI chat assistant with streaming, conversation history, and chart generation.
|
|
8
|
+
- **`PapermapChartCard`** — Standalone chart card with toolbar actions. Use `variant="streaming"` for an embedded chart + conversation dialog (without the floating assistant).
|
|
9
|
+
- **`PapermapGridDashboard`** — Responsive grid layout of chart cards, toolbar (screenshot, generate dashboard, theme), optional chat assistant, and controlled or uncontrolled layouts.
|
|
10
10
|
|
|
11
11
|
```tsx
|
|
12
|
-
import { PapermapChat, PapermapChartCard } from 'papermap'
|
|
12
|
+
import { PapermapChat, PapermapChartCard, PapermapGridDashboard } from '@papermap/papermap'
|
|
13
13
|
|
|
14
14
|
// AI chat assistant
|
|
15
15
|
<PapermapChat
|
|
@@ -32,36 +32,52 @@ import { PapermapChat, PapermapChartCard } from 'papermap'
|
|
|
32
32
|
workspaceId="your-workspace-id"
|
|
33
33
|
dashboardId="your-dashboard-id"
|
|
34
34
|
variant="streaming"
|
|
35
|
-
chartId="your-chart-id" // optional; card
|
|
35
|
+
chartId="your-chart-id" // optional; card shows empty state if omitted
|
|
36
|
+
/>
|
|
37
|
+
|
|
38
|
+
// Full grid dashboard (wraps chart cards + optional PapermapChat)
|
|
39
|
+
<PapermapGridDashboard
|
|
40
|
+
token="..."
|
|
41
|
+
workspaceId="..."
|
|
42
|
+
dashboardId="..."
|
|
43
|
+
showChatAssistant
|
|
36
44
|
/>
|
|
37
45
|
```
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
Each top-level component handles API calls, authentication, and UI internally unless you compose lower-level exports yourself.
|
|
40
48
|
|
|
41
49
|
---
|
|
42
50
|
|
|
43
|
-
## Quick
|
|
51
|
+
## Quick start
|
|
44
52
|
|
|
45
53
|
### 1. Install
|
|
46
54
|
|
|
47
55
|
```bash
|
|
48
|
-
npm install papermap
|
|
56
|
+
npm install @papermap/papermap
|
|
49
57
|
# or
|
|
50
|
-
pnpm add papermap
|
|
58
|
+
pnpm add @papermap/papermap
|
|
51
59
|
```
|
|
52
60
|
|
|
61
|
+
**Requirements:** React 18+ and React DOM 18+ (peer dependencies).
|
|
62
|
+
|
|
53
63
|
### 2. Import styles once
|
|
54
64
|
|
|
55
65
|
```tsx
|
|
56
|
-
import 'papermap/styles.css'
|
|
66
|
+
import '@papermap/papermap/styles.css'
|
|
57
67
|
```
|
|
58
68
|
|
|
59
|
-
### 3.
|
|
69
|
+
### 3. Choose an integration pattern
|
|
70
|
+
|
|
71
|
+
#### A) Recommended: provider at app root
|
|
60
72
|
|
|
61
|
-
|
|
73
|
+
`PapermapConfigProvider` is an alias for `PapermapProvider` — same component, useful for naming consistency in app code.
|
|
62
74
|
|
|
63
75
|
```tsx
|
|
64
|
-
import {
|
|
76
|
+
import {
|
|
77
|
+
PapermapConfigProvider,
|
|
78
|
+
PapermapChat,
|
|
79
|
+
PapermapChartCard,
|
|
80
|
+
} from '@papermap/papermap'
|
|
65
81
|
|
|
66
82
|
function App() {
|
|
67
83
|
return (
|
|
@@ -78,10 +94,12 @@ function App() {
|
|
|
78
94
|
}
|
|
79
95
|
```
|
|
80
96
|
|
|
81
|
-
#### B)
|
|
97
|
+
#### B) Standalone components (no provider)
|
|
98
|
+
|
|
99
|
+
Pass `token`, `workspaceId`, and `dashboardId` on each component (or rely on an existing parent `PapermapProvider`).
|
|
82
100
|
|
|
83
101
|
```tsx
|
|
84
|
-
import { PapermapChat, PapermapChartCard } from 'papermap'
|
|
102
|
+
import { PapermapChat, PapermapChartCard } from '@papermap/papermap'
|
|
85
103
|
|
|
86
104
|
function App() {
|
|
87
105
|
return (
|
|
@@ -105,14 +123,14 @@ function App() {
|
|
|
105
123
|
|
|
106
124
|
### 4. Props
|
|
107
125
|
|
|
108
|
-
#### `PapermapChat`
|
|
126
|
+
#### `PapermapChat` props
|
|
109
127
|
|
|
110
128
|
| Prop | Type | Required | Default | Description |
|
|
111
129
|
| ------------- | ---------------------- | -------- | --------------------------------- | ------------------------------------ |
|
|
112
|
-
| `token` | `string` | Yes
|
|
113
|
-
| `workspaceId` | `string` | Yes
|
|
114
|
-
| `dashboardId` | `string` | Yes
|
|
115
|
-
| `apiUrl` | `string` | No | `https://dataapi.papermap.ai`
|
|
130
|
+
| `token` | `string` | Yes\* | -- | Base64-encoded API key token |
|
|
131
|
+
| `workspaceId` | `string` | Yes\* | -- | Workspace ID |
|
|
132
|
+
| `dashboardId` | `string` | Yes\* | -- | Dashboard ID |
|
|
133
|
+
| `apiUrl` | `string` | No | `https://dataapi.papermap.ai` | API base URL |
|
|
116
134
|
| `theme` | `'light' \| 'dark'` | No | -- | Force light or dark theme |
|
|
117
135
|
| `placeholder` | `string` | No | `"Ask anything..."` | Input placeholder text |
|
|
118
136
|
| `shortcutKey` | `string` | No | `"k"` | Keyboard shortcut (Cmd/Ctrl + key) |
|
|
@@ -120,31 +138,33 @@ function App() {
|
|
|
120
138
|
| `fadeDelay` | `number` | No | `5000` | Milliseconds before auto-fade |
|
|
121
139
|
| `className` | `string` | No | -- | Extra CSS class on toolbar container |
|
|
122
140
|
|
|
123
|
-
|
|
141
|
+
\*Omit on the component when values come from `PapermapConfigProvider` / `PapermapProvider`.
|
|
142
|
+
|
|
143
|
+
#### `PapermapChartCard` props
|
|
124
144
|
|
|
125
145
|
| Prop | Type | Required | Default | Description |
|
|
126
146
|
| -------------- | ---------------------------------------- | -------- | --------------------------------- | --------------------------------------------------------------------- |
|
|
127
|
-
| `token` | `string` | Yes
|
|
128
|
-
| `workspaceId` | `string` | Yes
|
|
129
|
-
| `dashboardId` | `string` | Yes
|
|
130
|
-
| `apiUrl` | `string` | No | `https://dataapi.papermap.ai`
|
|
131
|
-
| `chartId` | `string` | No | -- |
|
|
132
|
-
| `chart` | `TChartResponse` | No | -- | Pre-loaded chart data (skips API fetch)
|
|
147
|
+
| `token` | `string` | Yes\* | -- | Base64-encoded API key token |
|
|
148
|
+
| `workspaceId` | `string` | Yes\* | -- | Workspace ID |
|
|
149
|
+
| `dashboardId` | `string` | Yes\* | -- | Dashboard ID |
|
|
150
|
+
| `apiUrl` | `string` | No | `https://dataapi.papermap.ai` | API base URL |
|
|
151
|
+
| `chartId` | `string` | No | -- | Backend chat id to load the latest chart for |
|
|
152
|
+
| `chart` | `TChartResponse` | No | -- | Pre-loaded chart data (skips API fetch) |
|
|
133
153
|
| `theme` | `'light' \| 'dark'` | No | -- | Force light or dark theme |
|
|
134
154
|
| `onEditClick` | `(chartId: string) => void` | No | -- | Called when the edit button is clicked |
|
|
135
|
-
| `onDelete` | `(chartId: string) => void` | No | -- | Called when chart deletion is confirmed
|
|
155
|
+
| `onDelete` | `(chartId: string) => void` | No | -- | Called when chart deletion is confirmed |
|
|
136
156
|
| `onPinChange` | `(chartId: string, pinned: boolean) => void` | No | -- | Called when pin state changes |
|
|
137
157
|
| `wide` | `boolean` | No | `false` | Wide mode for table charts |
|
|
138
158
|
| `hideVariants` | `boolean` | No | `true` | Hide the chart variation selector |
|
|
139
|
-
| `showToolbar` | `boolean` | No | `true` | Show toolbar with maximize/edit/delete buttons
|
|
140
|
-
| `className` | `string` | No | -- | Extra CSS class on the card container
|
|
141
|
-
| `variant` | `'default' \| 'streaming'` | No | `'default'` |
|
|
159
|
+
| `showToolbar` | `boolean` | No | `true` | Show toolbar with maximize/edit/delete buttons |
|
|
160
|
+
| `className` | `string` | No | -- | Extra CSS class on the card container |
|
|
161
|
+
| `variant` | `'default' \| 'streaming'` | No | `'default'` | `'streaming'`: edit opens embedded dialog + chat |
|
|
142
162
|
|
|
143
|
-
**
|
|
163
|
+
**Pre-loaded chart:**
|
|
144
164
|
|
|
145
165
|
```tsx
|
|
146
|
-
import { PapermapChartCard } from 'papermap'
|
|
147
|
-
import type { TChartResponse } from 'papermap'
|
|
166
|
+
import { PapermapChartCard } from '@papermap/papermap'
|
|
167
|
+
import type { TChartResponse } from '@papermap/papermap'
|
|
148
168
|
|
|
149
169
|
const chart: TChartResponse = {
|
|
150
170
|
llm_data_chat_id: 'my-chart-id',
|
|
@@ -173,27 +193,27 @@ const chart: TChartResponse = {
|
|
|
173
193
|
/>
|
|
174
194
|
```
|
|
175
195
|
|
|
176
|
-
|
|
196
|
+
#### `PapermapGridDashboard` props (high level)
|
|
177
197
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
198
|
+
| Prop | Notes |
|
|
199
|
+
| ---- | ----- |
|
|
200
|
+
| `token`, `workspaceId`, `dashboardId`, `apiUrl` | Same as other components; can come from provider. |
|
|
201
|
+
| `charts` | Optional pre-loaded charts; otherwise fetched when `enableFetch` is true (default). |
|
|
202
|
+
| `layouts` / `onLayoutsChange` | Controlled grid layouts per breakpoint. |
|
|
203
|
+
| `isEditMode`, `editLayout`, `isViewer` | Edit vs view behavior. |
|
|
204
|
+
| `showToolbar`, `showScreenshot`, `showGenerateDashboard`, `showHeader`, `showChatAssistant` | Feature toggles. |
|
|
205
|
+
| `variant` | `'default' \| 'streaming'` for embedded chart cards (matches `PapermapChartCard`). |
|
|
206
|
+
| `dashboardTheme`, `onDashboardThemeChange`, `persistWorkspaceTheme`, `renderThemeModal` | Theming; built-in modal uses `ThemeCustomizationSettings`. |
|
|
207
|
+
| Callbacks | `onEditChart`, `onDeleteChart`, `onPinChange`, `onGenerateDashboard`, `onTakeScreenshot`, `onThemeModalOpen`, etc. |
|
|
208
|
+
|
|
209
|
+
See TypeScript types `PapermapGridDashboardProps` and Storybook stories for full detail.
|
|
186
210
|
|
|
187
211
|
### Streaming chart card variant
|
|
188
212
|
|
|
189
|
-
|
|
190
|
-
- Chart + conversation side-by-side (chat always available)
|
|
191
|
-
- SSE streaming support
|
|
192
|
-
- Save-to-dashboard + maximize chart actions
|
|
193
|
-
- Audit Log (execution replay) on assistant messages
|
|
213
|
+
With `variant="streaming"`, the edit action opens an embedded expanded view with chart + conversation, SSE streaming, save-to-dashboard and maximize actions, and audit log on assistant messages.
|
|
194
214
|
|
|
195
215
|
```tsx
|
|
196
|
-
import { PapermapChartCard } from 'papermap'
|
|
216
|
+
import { PapermapChartCard } from '@papermap/papermap'
|
|
197
217
|
|
|
198
218
|
export function EmbeddedStreamingChart() {
|
|
199
219
|
return (
|
|
@@ -203,40 +223,49 @@ export function EmbeddedStreamingChart() {
|
|
|
203
223
|
workspaceId="..."
|
|
204
224
|
dashboardId="..."
|
|
205
225
|
variant="streaming"
|
|
206
|
-
chartId="existing-chat-id"
|
|
226
|
+
chartId="existing-chat-id"
|
|
207
227
|
/>
|
|
208
228
|
</div>
|
|
209
229
|
)
|
|
210
230
|
}
|
|
211
231
|
```
|
|
212
232
|
|
|
213
|
-
**Supported chart types:** `bar`, `line`, `area`, `pie`, `radar`, `scatter`, `table`, `tile`
|
|
233
|
+
**Supported chart types:** `bar`, `line`, `area`, `pie`, `radar`, `scatter`, `table`, `tile` — aligned with the main Papermap app.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Advanced exports
|
|
238
|
+
|
|
239
|
+
For custom layouts, the package also exports subcomponents (for example `ChatAssistant`, `StreamingChartDialog`, `ChartView`, `DataTable`), Zustand store helpers (`usePapermapStore`, `createPapermapStore`), hooks (`useAnalyticsStream`, …), API helpers (`createApiClient`, `decodeToken`, `buildAuthHeaders`), streaming and chart types, **theme presets** (`themePresets`, `defaultTheme`, `ThemeCustomizationSettings`), and **chart card id ↔ chat id** persistence helpers (`getChartCardIdLink`, `resolveChartFetchChatId`, …). Import paths are the same as the main entry: `@papermap/papermap`.
|
|
214
240
|
|
|
215
241
|
---
|
|
216
242
|
|
|
217
243
|
## Troubleshooting
|
|
218
244
|
|
|
219
|
-
###
|
|
220
|
-
|
|
221
|
-
-
|
|
245
|
+
### Cannot find module `@papermap/papermap/styles.css`
|
|
246
|
+
|
|
247
|
+
- Use the scoped package name and the `./styles.css` export.
|
|
248
|
+
- Reinstall after upgrading.
|
|
222
249
|
|
|
223
250
|
### "Papermap... requires token/workspaceId/dashboardId"
|
|
224
|
-
- Provide connection values once via `PapermapConfigProvider`, or
|
|
225
|
-
- Pass them directly to each standalone component.
|
|
226
251
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
252
|
+
- Provide values once via `PapermapConfigProvider` / `PapermapProvider`, or pass them on each component.
|
|
253
|
+
|
|
254
|
+
### Requests hit the wrong backend
|
|
255
|
+
|
|
256
|
+
- Set `apiUrl` on the provider or per component. Default is `https://dataapi.papermap.ai`.
|
|
230
257
|
|
|
231
258
|
### Charts do not appear in `PapermapChartCard`
|
|
232
|
-
- Pass a valid backend `chartId` (chat id), or
|
|
233
|
-
- Provide preloaded `chart` data directly.
|
|
234
259
|
|
|
235
|
-
|
|
260
|
+
- Pass a valid backend `chartId` (chat id), or supply preloaded `chart` data.
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## How it works
|
|
236
265
|
|
|
237
266
|
### Authentication
|
|
238
267
|
|
|
239
|
-
The `token` prop is
|
|
268
|
+
The `token` prop is base64-encoded JSON:
|
|
240
269
|
|
|
241
270
|
```json
|
|
242
271
|
{
|
|
@@ -247,7 +276,7 @@ The `token` prop is a base64-encoded JSON:
|
|
|
247
276
|
}
|
|
248
277
|
```
|
|
249
278
|
|
|
250
|
-
The
|
|
279
|
+
The library decodes it and sends these headers on API requests:
|
|
251
280
|
|
|
252
281
|
- `X-API-Key-ID`
|
|
253
282
|
- `X-Workspace-ID`
|
|
@@ -255,42 +284,21 @@ The component decodes it and sets these headers on every API request:
|
|
|
255
284
|
- `X-Signature`
|
|
256
285
|
- `X-Tenant-ID: da-app`
|
|
257
286
|
|
|
258
|
-
###
|
|
259
|
-
|
|
260
|
-
1. User types a message and hits Enter
|
|
261
|
-
2. Component creates a chat via `POST /api/v1/analytics/chats` (if first message)
|
|
262
|
-
3. Message is sent via `POST /api/v1/analytics/charts/stream` with SSE enabled
|
|
263
|
-
4. SSE connection opens to `POST /api/v1/analytics/requests/stream` for real-time updates (agent thoughts, tool calls, phases)
|
|
264
|
-
5. HTTP response serves as fallback if SSE fails
|
|
265
|
-
6. Conversation history is loaded via `GET /api/v1/analytics/chats/{id}/conversations`
|
|
266
|
-
7. Recent chat history for a dashboard is loaded via `GET /api/v1/analytics/chats-history`
|
|
267
|
-
8. Full chart history for a chat is loaded via `GET /api/v1/analytics/chats/{id}/get-all-charts`
|
|
268
|
-
|
|
269
|
-
### What the User Sees
|
|
270
|
-
|
|
271
|
-
- A floating input bar fixed at the bottom-center (portaled to `document.body`)
|
|
272
|
-
- Cmd/Ctrl+K to focus, Escape to dismiss
|
|
273
|
-
- Single-line input that expands to multiline when text overflows
|
|
274
|
-
- Backdrop overlay + conversation panel when focused
|
|
275
|
-
- Submit button (arrow-up) becomes stop button (square) during loading
|
|
276
|
-
- New Chat button to start fresh conversations
|
|
277
|
-
- Auto-scroll, pagination on scroll-up for history
|
|
278
|
-
- Recent conversations panel with infinite scroll + delete actions
|
|
279
|
-
- Per-chat chart history panel, including pinning and meta updates
|
|
280
|
-
- Inline feedback (thumbs up / down) on responses, with optional branching to new chats
|
|
281
|
-
- Optional streaming view that shows real-time phases, thoughts, and tool calls (toggled via "View Execution")
|
|
282
|
-
- Model selector and search-the-web actions integrated into the toolbar
|
|
287
|
+
### Chat data flow (overview)
|
|
283
288
|
|
|
284
|
-
|
|
289
|
+
1. User sends a message; first message may create a chat via `POST /api/v1/analytics/chats`.
|
|
290
|
+
2. Message goes to `POST /api/v1/analytics/charts/stream` with SSE.
|
|
291
|
+
3. SSE connects to `POST /api/v1/analytics/requests/stream` for live updates; HTTP remains a fallback.
|
|
292
|
+
4. History: `GET /api/v1/analytics/chats/{id}/conversations`, dashboard recent chats, and full chart history per chat as needed.
|
|
285
293
|
|
|
286
|
-
|
|
294
|
+
### What users see in `PapermapChat`
|
|
287
295
|
|
|
288
|
-
|
|
296
|
+
- Floating input bar (portaled to `document.body`), Cmd/Ctrl+K to focus, Escape to dismiss.
|
|
297
|
+
- Expanding input, backdrop, conversation panel, stop during load, new chat, scroll and history pagination.
|
|
298
|
+
- Recent conversations, per-chat chart history, feedback, optional execution view, model selector, and related toolbar actions.
|
|
289
299
|
|
|
290
|
-
|
|
300
|
+
---
|
|
291
301
|
|
|
292
|
-
|
|
293
|
-
import { PapermapChat, PapermapChartCard } from 'papermap'
|
|
294
|
-
```
|
|
302
|
+
## Roadmap
|
|
295
303
|
|
|
296
|
-
|
|
304
|
+
Additional embeddable surfaces (for example richer explorers) will follow the same pattern: self-contained components with `token` / `workspaceId` / `dashboardId` and optional callbacks, exported from `@papermap/papermap`.
|