@papermap/papermap 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,12 +1,15 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Layout } from 'react-grid-layout';
3
+ import { LucideIcon } from 'lucide-react';
2
4
  import * as React$1 from 'react';
3
5
  import React__default, { RefObject } from 'react';
4
6
  import * as class_variance_authority_types from 'class-variance-authority/types';
5
7
  import { VariantProps } from 'class-variance-authority';
6
8
  import * as zustand from 'zustand';
9
+ import { QueryClient } from '@tanstack/react-query';
7
10
  import * as axios from 'axios';
8
11
  import { AxiosInstance } from 'axios';
9
- import { Layout } from 'react-grid-layout';
12
+ import { DriveStep } from 'driver.js';
10
13
 
11
14
  interface PaperChatProps {
12
15
  token?: string;
@@ -29,9 +32,15 @@ interface PaperChatProps {
29
32
  * Defaults to `true`.
30
33
  */
31
34
  showToolbar?: boolean;
35
+ /**
36
+ * Called after the floating assistant panel is closed (e.g. to refetch dashboard charts).
37
+ */
38
+ onAssistantClose?: () => void;
32
39
  }
33
- declare function PaperChat({ token, workspaceId, dashboardId, apiUrl, onToolbarHeightChange, showToolbar, ...uiProps }: PaperChatProps): react_jsx_runtime.JSX.Element;
40
+ declare function PaperChat({ token, workspaceId, dashboardId, apiUrl, onToolbarHeightChange, onAssistantClose, showToolbar, ...uiProps }: PaperChatProps): react_jsx_runtime.JSX.Element;
34
41
 
42
+ /** One row of tabular chart data (column keys depend on the query). */
43
+ type ChartDataRow = Record<string, unknown>;
35
44
  type TChartMeta$1 = {
36
45
  title?: string;
37
46
  subtitle?: string;
@@ -39,7 +48,14 @@ type TChartMeta$1 = {
39
48
  footer?: string;
40
49
  showLegend?: boolean;
41
50
  variant?: string;
42
- [key: string]: any;
51
+ [key: string]: unknown;
52
+ };
53
+ type ChartVisualizationConfig = {
54
+ colors: string[];
55
+ width: number;
56
+ height: number;
57
+ title?: string;
58
+ [key: string]: unknown;
43
59
  };
44
60
  type TChartResponse = {
45
61
  llm_data_chat_id: string;
@@ -48,7 +64,7 @@ type TChartResponse = {
48
64
  chart_response?: {
49
65
  chart_type: string;
50
66
  error?: boolean;
51
- data: any[];
67
+ data: ChartDataRow[];
52
68
  response_type: string;
53
69
  text_response?: string;
54
70
  schema_hints: {
@@ -56,13 +72,7 @@ type TChartResponse = {
56
72
  y_key: string;
57
73
  label_key: string;
58
74
  };
59
- visualization_config: {
60
- colors: string[];
61
- width: number;
62
- height: number;
63
- title?: string;
64
- [key: string]: any;
65
- };
75
+ visualization_config: ChartVisualizationConfig;
66
76
  };
67
77
  meta: TChartMeta$1;
68
78
  pin: boolean;
@@ -83,8 +93,8 @@ interface VisualizationConfig {
83
93
  colors: string[];
84
94
  width: number;
85
95
  height: number;
86
- title: string;
87
- [key: string]: any;
96
+ title?: string;
97
+ [key: string]: unknown;
88
98
  }
89
99
  interface ChartResponse {
90
100
  response_type: string;
@@ -101,6 +111,34 @@ type ConversationHistory = Omit<TChartResponse, 'chart_response'> & {
101
111
  latest_user_name?: string | null;
102
112
  };
103
113
 
114
+ type ResizeHandle = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw';
115
+ type TLayout = Layout & {
116
+ resizeHandles?: ResizeHandle[];
117
+ };
118
+ type PaperBoardLayouts = {
119
+ [key: string]: TLayout[];
120
+ };
121
+ interface DashboardTheme {
122
+ primary: string;
123
+ secondary: string;
124
+ interactive: string;
125
+ container: string;
126
+ module: string;
127
+ accent: string;
128
+ outline: string;
129
+ dialog: string;
130
+ fontFamily: string;
131
+ borderRadius: number;
132
+ cardBg?: string;
133
+ dashboardBg?: string;
134
+ cardIcons?: string;
135
+ cardText?: string;
136
+ cardTitle?: string;
137
+ buttonPrimary?: string;
138
+ buttonSecondary?: string;
139
+ buttonText?: string;
140
+ }
141
+
104
142
  interface PaperCardProps {
105
143
  /**
106
144
  * Connection details for API calls. Optional when the card is rendered inside
@@ -122,6 +160,16 @@ interface PaperCardProps {
122
160
  * and logged only.
123
161
  */
124
162
  onSave?: (chart: TChartResponse) => void;
163
+ /**
164
+ * Called after the user successfully pins/saves a chart to the dashboard (streaming dialog
165
+ * or built-in ChartView save). Use this to refetch dashboard data from the host.
166
+ */
167
+ onPinnedToDashboard?: (chart: TChartResponse) => void;
168
+ /**
169
+ * Called after the streaming chart assistant dialog closes. Use with `onPinnedToDashboard`
170
+ * to refetch dashboard data so tiles reflect edits made in the assistant.
171
+ */
172
+ onAssistantClosed?: () => void;
125
173
  /**
126
174
  * The chat ID to load a chart for. When provided, the component will
127
175
  * fetch the latest chart for this chat on mount (overrides `id` → localStorage map).
@@ -167,7 +215,7 @@ interface PaperCardProps {
167
215
  /** When true, chart toolbar actions are visually disabled during layout editing. */
168
216
  isEditMode?: boolean;
169
217
  /** When true, show resize affordance and disable toolbar actions. */
170
- /** Optional stable identifier for standalone resize handle instrumentation. */
218
+ /** Optional stable identifier for standalone resize handle / host linking (when used). */
171
219
  className?: string;
172
220
  /**
173
221
  * Card variant. When `"streaming"`, clicking the edit icon opens an
@@ -175,8 +223,16 @@ interface PaperCardProps {
175
223
  * just calling onEditClick or opening the toolbar chat.
176
224
  */
177
225
  variant?: 'default' | 'streaming';
226
+ /**
227
+ * When true with `variant="streaming"` and no chart yet, omits the extra
228
+ * chat-bar hint row (“Ask anything about your data”). Used by `PaperBoard`
229
+ * so grid tiles are not redundant with board-level empty copy.
230
+ */
231
+ hideStreamingEmptySubtext?: boolean;
232
+ /** Passed into maximize `ChartDialog` / streaming dialog for themed dashboards (e.g. from `PaperBoard`). */
233
+ dashboardTheme?: DashboardTheme;
178
234
  }
179
- declare function PaperCard({ token: tokenProp, workspaceId: workspaceIdProp, dashboardId: dashboardIdProp, apiUrl: apiUrlProp, id, onSave, chartId, chart: chartProp, theme, onEditClick, onDelete, isViewer, wide, hideVariants, showToolbar, isEditMode, className, variant, }: PaperCardProps): react_jsx_runtime.JSX.Element;
235
+ declare function PaperCard({ token: tokenProp, workspaceId: workspaceIdProp, dashboardId: dashboardIdProp, apiUrl: apiUrlProp, id, onSave, onPinnedToDashboard, onAssistantClosed, chartId, chart: chartProp, theme, onEditClick, onDelete, isViewer, wide, hideVariants, showToolbar, isEditMode, className, variant, hideStreamingEmptySubtext, dashboardTheme, }: PaperCardProps): react_jsx_runtime.JSX.Element;
180
236
 
181
237
  declare function ChatAssistant(): react_jsx_runtime.JSX.Element;
182
238
 
@@ -193,10 +249,10 @@ interface FinalResponse {
193
249
  response_type: string;
194
250
  generated_text: string;
195
251
  chart_type?: string;
196
- data?: any[];
252
+ data?: unknown[];
197
253
  pandas_code?: string;
198
254
  thoughts?: string;
199
- [key: string]: any;
255
+ [key: string]: unknown;
200
256
  };
201
257
  llm_data_id: string;
202
258
  total_iterations: number;
@@ -236,7 +292,7 @@ interface StreamState {
236
292
  timeline: TimelineEvent[];
237
293
  currentPhase: string;
238
294
  error: string | null;
239
- finalResponse: any | null;
295
+ finalResponse: unknown | null;
240
296
  isComplete: boolean;
241
297
  isConnected: boolean;
242
298
  isStreaming: boolean;
@@ -270,6 +326,43 @@ declare function ChartHistory(): react_jsx_runtime.JSX.Element;
270
326
 
271
327
  declare function SavedMemory(): react_jsx_runtime.JSX.Element;
272
328
 
329
+ interface PaperDashboardSelectProps {
330
+ workspaceId: string;
331
+ dashboardId: string;
332
+ onChange: (dashboardId: string) => void;
333
+ dashboardTheme?: DashboardTheme;
334
+ disabled?: boolean;
335
+ className?: string;
336
+ /**
337
+ * When true, sets `dashboardId` on the current URL search params via `replaceState`
338
+ * (same idea as the main app embedded dashboard).
339
+ */
340
+ syncDashboardIdToUrl?: boolean;
341
+ }
342
+ /**
343
+ * Dashboard picker for the current workspace only (matches main app `DashboardSelect` / embedded UX).
344
+ */
345
+ declare function PaperDashboardSelect({ workspaceId, dashboardId, onChange, dashboardTheme, disabled, className, syncDashboardIdToUrl, }: PaperDashboardSelectProps): react_jsx_runtime.JSX.Element;
346
+
347
+ type DashboardNavbarItem = {
348
+ title: string;
349
+ /** Absolute or relative URL; pathname (before `?`) is used for the active state. */
350
+ href: string;
351
+ disabled?: boolean;
352
+ icon?: LucideIcon;
353
+ };
354
+ interface DashboardTabNavigationProps {
355
+ className?: string;
356
+ items: DashboardNavbarItem[];
357
+ dashboardTheme?: DashboardTheme;
358
+ /** Renders on the right (e.g. `PaperDashboardSelect`). */
359
+ rightSlot?: React.ReactNode;
360
+ }
361
+ /**
362
+ * Top tab bar styled like the main app `TabNavigation` (embedded layout navbar), without Next.js `Link`.
363
+ */
364
+ declare function DashboardTabNavigation({ className, items, dashboardTheme, rightSlot, }: DashboardTabNavigationProps): react_jsx_runtime.JSX.Element;
365
+
273
366
  interface TChartMeta {
274
367
  title?: string;
275
368
  subtitle?: string;
@@ -278,14 +371,14 @@ interface TChartMeta {
278
371
  showLegend?: boolean;
279
372
  }
280
373
  interface ChartViewProps {
281
- data: any[];
374
+ data: ChartDataRow[];
282
375
  chartMeta: TChartMeta;
283
376
  error?: boolean;
284
377
  chartType: string;
285
378
  variant?: string;
286
379
  className?: string;
287
380
  containerClassName?: string;
288
- visualizationConfig?: Record<string, any>;
381
+ visualizationConfig?: Record<string, unknown>;
289
382
  previewMode?: boolean;
290
383
  onMetaChange?: (key: 'title' | 'description' | 'footer' | 'subtitle', value: string) => void;
291
384
  chartId?: string;
@@ -308,6 +401,15 @@ interface ChartViewProps {
308
401
  * of the default bottom-left outline button. Used in streaming layouts.
309
402
  */
310
403
  compactSave?: boolean;
404
+ /**
405
+ * Called after a successful pin/save to the dashboard via the built-in save action.
406
+ * Not invoked when `onSaveToDashboard` overrides the handler.
407
+ */
408
+ onAfterPinToDashboard?: () => void;
409
+ /** When set (and not skipped), header and controls use dashboard theme tokens. */
410
+ dashboardTheme?: DashboardTheme;
411
+ /** When true, ignore `dashboardTheme` (e.g. dialog with `skipDashboardTheme`). */
412
+ skipDashboardTheme?: boolean;
311
413
  }
312
414
  declare function ChartView(props: ChartViewProps): react_jsx_runtime.JSX.Element;
313
415
 
@@ -326,7 +428,25 @@ interface ChartDialogProps {
326
428
  visualizationConfig: Record<string, any>;
327
429
  onMetaChange: (key: 'title' | 'description' | 'footer' | 'subtitle', value: string) => void;
328
430
  variant?: string;
431
+ /**
432
+ * Optional hook for the **minimize** control only: invoked immediately before `onOpenChange(false)`.
433
+ * Backdrop click and Escape call **only** `onOpenChange(false)` (Radix default).
434
+ */
329
435
  onClose?: () => void;
436
+ /**
437
+ * When true, hides the chart variation selector in the dialog (embedded edge cases).
438
+ * Default false — matches main-app maximize dialog (variant switching allowed).
439
+ */
440
+ hideVariantControls?: boolean;
441
+ /**
442
+ * Workspace dashboard theme: injects scoped CSS and `dashboard-theme` on the dialog surface (main-app parity).
443
+ * Omit when no custom theme; combine with `skipDashboardTheme` for chat-embedded dialogs.
444
+ */
445
+ dashboardTheme?: DashboardTheme;
446
+ /**
447
+ * When true, do not apply `dashboardTheme` to the dialog shell or inner `ChartView` (e.g. `ChatAssistant`).
448
+ */
449
+ skipDashboardTheme?: boolean;
330
450
  }
331
451
  declare function ChartDialog(props: ChartDialogProps): react_jsx_runtime.JSX.Element;
332
452
 
@@ -337,8 +457,10 @@ interface StreamingChartDialogProps {
337
457
  onClose?: () => void;
338
458
  /** After a successful Save-to-dashboard (pin) from this dialog; errors from the host are caught and logged. */
339
459
  onSave?: (chart: TChartResponse) => void;
460
+ /** Optional workspace theme for inline chart and maximize `ChartDialog` (from `PaperCard` / `PaperBoard`). */
461
+ dashboardTheme?: DashboardTheme;
340
462
  }
341
- declare function StreamingChartDialog({ isOpen, onOpenChange, chartId, onClose, onSave, }: StreamingChartDialogProps): React$1.ReactPortal;
463
+ declare function StreamingChartDialog({ isOpen, onOpenChange, chartId, onClose, onSave, dashboardTheme, }: StreamingChartDialogProps): React$1.ReactPortal;
342
464
 
343
465
  interface DataTableProps {
344
466
  data: any[];
@@ -395,12 +517,17 @@ interface StreamingChatPanelProps {
395
517
  * dialog when the chart column is hidden so chat isn’t artificially narrow.
396
518
  */
397
519
  expandMessageColumnOnMobile?: boolean;
520
+ /**
521
+ * Horizontal padding for the scrollable message list (main `ChatAssistant` uses wide gutters
522
+ * when expanded without the chart split: `px-32 md:px-48 lg:px-[320px] xl:px-[448px]`).
523
+ */
524
+ messagesPaddingClassName?: string;
398
525
  /** Auto-focuses the prompt input when this panel mounts (used by dialog hosts). */
399
526
  autoFocusInput?: boolean;
400
527
  /** Optional action rendered beside submit button in the input row. */
401
528
  inputAction?: React__default.ReactNode;
402
529
  }
403
- declare function StreamingChatPanel({ className, expandMessageColumnOnMobile, autoFocusInput, inputAction, }: StreamingChatPanelProps): react_jsx_runtime.JSX.Element;
530
+ declare function StreamingChatPanel({ className, expandMessageColumnOnMobile, messagesPaddingClassName, autoFocusInput, inputAction, }: StreamingChatPanelProps): react_jsx_runtime.JSX.Element;
404
531
 
405
532
  interface LogoStandAloneProps {
406
533
  className?: string;
@@ -430,38 +557,11 @@ declare function createStreamingService(client: AxiosInstance): {
430
557
  cancelChartRequest: (request_id: string, reason?: string) => Promise<any>;
431
558
  };
432
559
 
433
- type ResizeHandle = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw';
434
- type TLayout = Layout & {
435
- resizeHandles?: ResizeHandle[];
436
- };
437
- type PaperBoardLayouts = {
438
- [key: string]: TLayout[];
439
- };
440
- interface DashboardTheme {
441
- primary: string;
442
- secondary: string;
443
- interactive: string;
444
- container: string;
445
- module: string;
446
- accent: string;
447
- outline: string;
448
- dialog: string;
449
- fontFamily: string;
450
- borderRadius: number;
451
- cardBg?: string;
452
- dashboardBg?: string;
453
- cardIcons?: string;
454
- cardText?: string;
455
- cardTitle?: string;
456
- buttonPrimary?: string;
457
- buttonSecondary?: string;
458
- buttonText?: string;
459
- }
460
-
461
560
  declare function createChartService(client: AxiosInstance): {
462
561
  getDashboards: (params: {
463
562
  workspace_id: string;
464
563
  }) => Promise<any>;
564
+ getDashboardById: (dashboardId: string) => Promise<any>;
465
565
  updateDashboardLayout: (dashboardId: string, layout: TLayout[]) => Promise<any>;
466
566
  createChat: (data: {
467
567
  name: string;
@@ -491,7 +591,7 @@ declare function createChartService(client: AxiosInstance): {
491
591
  page?: number;
492
592
  }) => Promise<any>;
493
593
  getChartById: (chartId: string) => Promise<any>;
494
- updateChartMeta: (chatId: string, meta: Record<string, any>) => Promise<any>;
594
+ updateChartMeta: (chatId: string, meta: TChartMeta$1) => Promise<any>;
495
595
  updateChartPin: (chatId: string, pin: boolean) => Promise<any>;
496
596
  bookmarkConversation: (data: {
497
597
  llm_data_id: string;
@@ -508,9 +608,44 @@ declare function createChartService(client: AxiosInstance): {
508
608
  }) => Promise<any>;
509
609
  };
510
610
 
611
+ /** Plain JSON object (not array, not null). */
612
+ type JsonObject = Record<string, unknown>;
613
+ /** Workspace `meta` fields used for dashboard theming (matches main app). */
614
+ interface WorkspaceMeta {
615
+ apply_theme_to_all_dashboards?: boolean;
616
+ default_theme?: DashboardTheme;
617
+ theme?: Record<string, DashboardTheme | undefined>;
618
+ [key: string]: unknown;
619
+ }
620
+ /**
621
+ * Minimal workspace/dashboard document shape returned by workspace and dashboard APIs.
622
+ * Extra fields are preserved via the index signature.
623
+ */
624
+ interface WorkspaceEntity {
625
+ id?: string;
626
+ name?: string;
627
+ workspace_type?: string;
628
+ default_dashboard?: string;
629
+ meta?: WorkspaceMeta;
630
+ /** Present on some dashboard GET payloads */
631
+ title?: string;
632
+ [key: string]: unknown;
633
+ }
634
+ /**
635
+ * Normalizes workspace or dashboard API responses that may be either the entity or `{ data: entity }`.
636
+ * Returns `null` when the payload is not a non-null object (e.g. raw array or primitive).
637
+ */
638
+ declare function unwrapWorkspacePayload(res: unknown): WorkspaceEntity | null;
639
+
511
640
  declare function createWorkspaceService(client: AxiosInstance): {
641
+ listWorkspaces: (params?: {
642
+ page?: number;
643
+ per_page?: number;
644
+ search_term?: string;
645
+ }) => Promise<any>;
512
646
  getWorkspace: (workspaceId: string) => Promise<any>;
513
- updateWorkspace: (workspaceId: string, workspace: Record<string, any>) => Promise<any>;
647
+ updateWorkspace: (workspaceId: string, workspace: JsonObject) => Promise<any>;
648
+ verifyDatabaseConnection: (workspaceId: string) => Promise<any>;
514
649
  };
515
650
 
516
651
  type PapermapHttpServices = {
@@ -525,6 +660,10 @@ declare function createPapermapServices(config: {
525
660
  apiUrl?: string;
526
661
  }): PapermapHttpServices;
527
662
 
663
+ type MessageProgressEvent = {
664
+ event_type?: string;
665
+ data?: JsonObject;
666
+ };
528
667
  interface Message {
529
668
  id?: string;
530
669
  llm_data_id?: string;
@@ -541,14 +680,41 @@ interface Message {
541
680
  rundown_turn_label?: string;
542
681
  noIcons?: boolean;
543
682
  feedback?: 'positive' | 'negative' | null;
544
- progress_events?: {
545
- event_type?: string;
546
- data?: Record<string, any>;
547
- }[];
683
+ progress_events?: MessageProgressEvent[];
548
684
  originalContent?: string;
549
- [key: string]: any;
685
+ [key: string]: unknown;
550
686
  }
551
687
 
688
+ type PapermapTelemetryLevel = 'debug' | 'info' | 'warn' | 'error';
689
+ interface PapermapTelemetryEvent {
690
+ level: PapermapTelemetryLevel;
691
+ category: 'store' | 'sse' | 'network' | 'plugin' | 'ui' | 'runtime' | string;
692
+ message: string;
693
+ data?: Record<string, unknown>;
694
+ /** Original error or value; hosts should treat as opaque if serialized. */
695
+ cause?: unknown;
696
+ }
697
+ interface PapermapObservability {
698
+ emit: (event: PapermapTelemetryEvent) => void;
699
+ reportError: (error: unknown, context?: Record<string, unknown>) => void;
700
+ }
701
+ interface PapermapObservabilityOptions {
702
+ /** Receives every structured event (debug–error). */
703
+ onTelemetry?: (event: PapermapTelemetryEvent) => void;
704
+ /** Shortcut for failures; also receives a normalized telemetry event via `onTelemetry` when both are set. */
705
+ onError?: (error: unknown, context?: Record<string, unknown>) => void;
706
+ /**
707
+ * When true (default), mirror `warn`/`error` telemetry to the console in non-production runtimes.
708
+ * Set false in tests or strict hosts. Production never mirrors unless you log inside `onTelemetry`.
709
+ */
710
+ mirrorToConsoleInDev?: boolean;
711
+ }
712
+ /**
713
+ * Builds the observability facade used by `PapermapProvider` / `createPapermapStore`.
714
+ * With no options, production is silent; dev (non-test) mirrors warn/error to `console`.
715
+ */
716
+ declare function createPapermapObservability(options?: PapermapObservabilityOptions): PapermapObservability;
717
+
552
718
  declare const CHAT_MODAL_TAB: {
553
719
  readonly CHAT: "CHAT";
554
720
  readonly SAVED_MEMORY: "SAVED_MEMORY";
@@ -561,6 +727,11 @@ interface PapermapStoreConfig {
561
727
  workspaceId: string;
562
728
  dashboardId: string;
563
729
  apiUrl?: string;
730
+ /**
731
+ * React Query client used when the store invalidates queries (e.g. after creating a chat).
732
+ * `PapermapProvider` supplies a per-identity instance so cache cannot leak across tenant/workspace switches.
733
+ */
734
+ queryClient?: QueryClient;
564
735
  /**
565
736
  * Optional: use your own state (e.g. Redux) to control the selected model.
566
737
  * When provided, this value is used as the initial model instead of sessionStorage.
@@ -571,6 +742,11 @@ interface PapermapStoreConfig {
571
742
  * Ideal place to dispatch a Redux action in the host app.
572
743
  */
573
744
  onModelChange?: (model: string | null) => void;
745
+ /**
746
+ * Structured telemetry for hosts. Defaults to a quiet implementation (no production console noise).
747
+ * `PapermapProvider` supplies a shared instance when `observability` options are passed.
748
+ */
749
+ observability?: PapermapObservability;
574
750
  }
575
751
  type Services = PapermapHttpServices;
576
752
  interface Refs {
@@ -608,10 +784,10 @@ interface PapermapState {
608
784
  browserUse: boolean;
609
785
  selectedModel: string | null;
610
786
  viewExecution: boolean;
611
- chartData: any[];
787
+ chartData: ChartDataRow[];
612
788
  allMeta: TChartMeta$1;
613
789
  selectedChartType: string;
614
- chartVisuals: Record<string, any>;
790
+ chartVisuals: Record<string, unknown>;
615
791
  totalPages: number;
616
792
  currentPage: number;
617
793
  isLoadingMore: boolean;
@@ -643,11 +819,11 @@ interface PapermapActions {
643
819
  updateBrowserUse: (v: boolean) => void;
644
820
  setSelectedModel: (v: string | null) => void;
645
821
  setViewExecution: (v: boolean) => void;
646
- updateChartData: (data: any[]) => void;
822
+ updateChartData: (data: ChartDataRow[]) => void;
647
823
  updateAllMeta: (meta: TChartMeta$1) => void;
648
824
  updateChartType: (v: string) => void;
649
- updateChartVisuals: (v: Record<string, any>) => void;
650
- updateLatestChart: (result: any) => void;
825
+ updateChartVisuals: (v: Record<string, unknown>) => void;
826
+ updateLatestChart: (result: unknown) => void;
651
827
  clearLatestChart: () => void;
652
828
  setUseSSEStreaming: (v: boolean) => void;
653
829
  setSseRequestId: (v: string | null) => void;
@@ -707,6 +883,55 @@ interface OpenPapermapChatAssistantOptions {
707
883
  */
708
884
  declare function openPapermapChatAssistant(storeApi: PapermapStoreApi, options?: OpenPapermapChatAssistantOptions): void;
709
885
 
886
+ /** Mirrors `package.json` version; run `npm run sync:sdk-version` or `npm run build` to refresh. */
887
+ declare const PAPERMAP_SDK_VERSION: "1.1.0";
888
+ /** Contract revision for hosts that gate advanced features; bump only for breaking contract changes. */
889
+ declare const PAPERMAP_PLUGIN_CONTRACT_VERSION: 1;
890
+ type PapermapCapability = 'chat' | 'charts' | 'dashboard' | 'streaming' | 'workspace' | (string & {});
891
+ interface PapermapPluginManifest {
892
+ id: string;
893
+ name?: string;
894
+ /** Plugin’s own semver. */
895
+ version: string;
896
+ /**
897
+ * Required SDK range for this package, e.g. `^1.0.0`.
898
+ * Only caret (`^x.y.z`) and exact `x.y.z` forms are interpreted; unknown shapes are ignored (lenient).
899
+ */
900
+ peerRange?: string;
901
+ capabilities?: PapermapCapability[];
902
+ }
903
+ interface PapermapPluginContext {
904
+ manifest: PapermapPluginManifest;
905
+ workspaceId: string;
906
+ dashboardId: string;
907
+ apiUrl?: string;
908
+ observability: PapermapObservability;
909
+ }
910
+ interface PapermapPluginLifecycle {
911
+ onActivate?: (ctx: PapermapPluginContext) => void | Promise<void>;
912
+ onDeactivate?: (ctx: PapermapPluginContext) => void | Promise<void>;
913
+ onDispose?: (ctx: PapermapPluginContext) => void | Promise<void>;
914
+ }
915
+ interface PapermapPluginRegistration {
916
+ manifest: PapermapPluginManifest;
917
+ lifecycle?: PapermapPluginLifecycle;
918
+ }
919
+ declare function parseSemverPrefix(version: string): [number, number, number] | null;
920
+ /**
921
+ * Returns whether the running SDK version satisfies the plugin’s declared range.
922
+ */
923
+ declare function checkPluginPeerCompatibility(hostSdkVersion: string, pluginPeerRange?: string): {
924
+ ok: true;
925
+ } | {
926
+ ok: false;
927
+ reason: string;
928
+ };
929
+ declare function createPluginContext(registration: PapermapPluginRegistration, identity: {
930
+ workspaceId: string;
931
+ dashboardId: string;
932
+ apiUrl?: string;
933
+ }, observability: PapermapObservability): PapermapPluginContext;
934
+
710
935
  type PapermapConnectionValue = {
711
936
  token: string;
712
937
  workspaceId: string;
@@ -714,10 +939,26 @@ type PapermapConnectionValue = {
714
939
  apiUrl?: string;
715
940
  services: PapermapHttpServices;
716
941
  };
717
- interface PapermapProviderProps extends PapermapStoreConfig {
942
+ type PapermapProviderProps = Omit<PapermapStoreConfig, 'observability'> & {
718
943
  children: React__default.ReactNode;
719
- }
720
- declare function PapermapProvider({ children, token, workspaceId, dashboardId, apiUrl, initialModel, onModelChange, }: PapermapProviderProps): react_jsx_runtime.JSX.Element;
944
+ /** Optional structured telemetry; forwarded to the Zustand store and SSE bridge. */
945
+ observability?: PapermapObservabilityOptions;
946
+ /** Optional plugin manifest + lifecycle (v1 contract). Safe to omit for all existing embeds. */
947
+ plugin?: PapermapPluginRegistration;
948
+ };
949
+ /**
950
+ * Supplies Zustand chat state, HTTP services, and React Query for one **identity boundary**.
951
+ *
952
+ * **Runtime switches:** When any of `token`, `workspaceId`, `dashboardId`, or `apiUrl` change, the
953
+ * provider creates a **new** Zustand store and **new** `QueryClient`. Chat UI state and TanStack Query
954
+ * cache from the previous boundary are not carried over, which avoids stale tenant/workspace data.
955
+ *
956
+ * **Stable props:** Changing only `initialModel`, `onModelChange`, `observability`, `plugin`, or
957
+ * `children` does **not** reset the store or query cache (except `observability.mirrorToConsoleInDev`,
958
+ * which recreates the telemetry facade). `onModelChange` / `onTelemetry` / `onError` may be inline —
959
+ * the latest callback is always invoked via refs.
960
+ */
961
+ declare function PapermapProvider({ children, token, workspaceId, dashboardId, apiUrl, initialModel, onModelChange, observability: observabilityProp, plugin, }: PapermapProviderProps): react_jsx_runtime.JSX.Element;
721
962
  declare function usePapermapStore<T>(selector: (state: PapermapStore) => T): T;
722
963
  /**
723
964
  * Access the raw store API (for refs, services, imperative calls).
@@ -733,12 +974,25 @@ declare function usePapermapStoreApiOptional(): PapermapStoreApi | null;
733
974
  declare function usePapermapConnection(): PapermapConnectionValue;
734
975
  declare function usePapermapConnectionOptional(): PapermapConnectionValue | null;
735
976
 
736
- interface KeyboardShortcutHandlers {
977
+ interface UseKeyboardShortcutsOptions {
978
+ shortcutKey?: string;
737
979
  onToggle?: () => void;
980
+ /**
981
+ * Legacy Escape when not using `escapeLayerActive` + `instanceId`.
982
+ * Prefer `onEscapeLayerClose` for multiple embeds.
983
+ */
738
984
  onEscape?: () => void;
739
- shortcutKey?: string;
985
+ /** Stable id from `useId()` — enables multi-instance shortcut + Escape stacking. */
986
+ instanceId?: string;
987
+ /** Root that contains this chat surface (toolbar, overlays, portaled UI). */
988
+ shortcutRootRef?: RefObject<HTMLElement | null>;
989
+ /** When true, Escape is handled via a global stack (deepest / last-opened closes first). */
990
+ escapeLayerActive?: boolean;
991
+ onEscapeLayerClose?: () => void;
992
+ /** Bumps when portaled DOM attaches so `shortcutRootRef` can be bound. */
993
+ shortcutLayoutSyncKey?: string | number;
740
994
  }
741
- declare function useKeyboardShortcuts({ onToggle, onEscape, shortcutKey, }: KeyboardShortcutHandlers): void;
995
+ declare function useKeyboardShortcuts({ onToggle, onEscape, shortcutKey, instanceId, shortcutRootRef, escapeLayerActive, onEscapeLayerClose, shortcutLayoutSyncKey, }: UseKeyboardShortcutsOptions): void;
742
996
 
743
997
  declare function useAutoResize(textareaRef: RefObject<HTMLTextAreaElement | null>, minHeight?: number, maxHeight?: number): {
744
998
  resize: () => void;
@@ -750,7 +1004,7 @@ declare function useAutoFade(enabled: boolean, delay?: number, suppressWhen?: bo
750
1004
  };
751
1005
 
752
1006
  interface UseAnalyticsStreamOptions {
753
- onComplete?: (data: any) => void;
1007
+ onComplete?: (data: unknown) => void;
754
1008
  onError?: (error: string) => void;
755
1009
  onThought?: (thought: AgentThought) => void;
756
1010
  onToolCall?: (toolCall: ToolCall) => void;
@@ -767,12 +1021,30 @@ declare function useAnalyticsStream(requestId: string | null, authHeaders: Recor
767
1021
  timeline: TimelineEvent[];
768
1022
  currentPhase: string;
769
1023
  error: string | null;
770
- finalResponse: any | null;
1024
+ finalResponse: unknown | null;
771
1025
  isComplete: boolean;
772
1026
  isConnected: boolean;
773
1027
  isStreaming: boolean;
774
1028
  };
775
1029
 
1030
+ interface TourStep extends DriveStep {
1031
+ element?: string;
1032
+ popover?: {
1033
+ title?: string;
1034
+ description: string;
1035
+ side?: 'left' | 'right' | 'top' | 'bottom';
1036
+ align?: 'start' | 'center' | 'end';
1037
+ };
1038
+ }
1039
+ interface UseTourOptions {
1040
+ onComplete?: () => void;
1041
+ onSkip?: () => void;
1042
+ }
1043
+ declare function useTour(options?: UseTourOptions): {
1044
+ startTour: (steps: TourStep[]) => void;
1045
+ stopTour: () => void;
1046
+ };
1047
+
776
1048
  interface DecodedToken {
777
1049
  api_key_id: string;
778
1050
  workspace_id: string;
@@ -789,6 +1061,26 @@ declare function createApiClient(token: string, apiUrl?: string): {
789
1061
  authHeaders: Record<string, string>;
790
1062
  };
791
1063
 
1064
+ /** Normalized API origin segment so keys differ per host when IDs collide. */
1065
+ declare function papermapApiBaseSegment(apiUrl?: string): string;
1066
+ /**
1067
+ * Hierarchical TanStack Query keys scoped by API base + workspace + dashboard.
1068
+ * Prevents cache bleed when the same dashboard id appears under different workspaces or APIs.
1069
+ */
1070
+ declare const papermapQueryKeys: {
1071
+ readonly root: readonly ["papermap"];
1072
+ readonly scope: (params: {
1073
+ workspaceId: string;
1074
+ dashboardId: string;
1075
+ apiUrl?: string;
1076
+ }) => readonly ["papermap", string, "ws", string, "dash", string];
1077
+ readonly conversationHistory: (workspaceId: string, dashboardId: string, apiUrl?: string) => readonly ["papermap", string, "ws", string, "dash", string, "conversationHistory"];
1078
+ readonly chartCards: (workspaceId: string, dashboardId: string, apiUrl?: string) => readonly ["papermap", string, "ws", string, "dash", string, "chartCards"];
1079
+ readonly dashboardsForWorkspace: (workspaceId: string, apiUrl?: string) => readonly ["papermap", string, "ws", string, "dashboards"];
1080
+ readonly workspacesList: (apiUrl?: string) => readonly ["papermap", string, "workspaces", "list"];
1081
+ readonly models: (apiUrl: string | undefined, token: string) => readonly ["papermap", string, "models", string];
1082
+ };
1083
+
792
1084
  interface PaperBoardProps {
793
1085
  token?: string;
794
1086
  workspaceId?: string;
@@ -832,8 +1124,44 @@ interface PaperBoardProps {
832
1124
  enableFetch?: boolean;
833
1125
  showChatAssistant?: boolean;
834
1126
  variant?: 'default' | 'streaming';
1127
+ /**
1128
+ * When true, shows a “Tour” control in the header and enables the dashboard product tour (driver.js).
1129
+ * Default false until the embed tour UX is finalized.
1130
+ */
1131
+ showDashboardTour?: boolean;
1132
+ /**
1133
+ * When true, starts the tour once after load if it has not been completed (localStorage).
1134
+ * Waits until the chat bar is not open or focused. Default false for embeds.
1135
+ */
1136
+ autoStartDashboardTour?: boolean;
1137
+ /** Overrides localStorage key for tour completion (`1` = done). */
1138
+ dashboardTourStorageKey?: string;
1139
+ /** Called when the user finishes or skips the tour (after persisting completion). */
1140
+ onDashboardTourComplete?: () => void;
1141
+ /**
1142
+ * When true (default), show workspace and dashboard dropdowns in the header when `enableFetch` is on
1143
+ * and the board is not in viewer mode. With a parent `PapermapProvider`, you must also pass
1144
+ * `onWorkspaceDashboardChange` so the host can update provider props.
1145
+ */
1146
+ showWorkspaceDashboardSelect?: boolean;
1147
+ /** Update parent state when the user picks another workspace or dashboard (required with a parent provider). */
1148
+ onWorkspaceDashboardChange?: (ctx: {
1149
+ workspaceId: string;
1150
+ dashboardId: string;
1151
+ }) => void;
835
1152
  }
836
- declare function PaperBoard({ token, workspaceId, dashboardId, apiUrl, ...rest }: PaperBoardProps): react_jsx_runtime.JSX.Element;
1153
+ declare function PaperBoard({ token, workspaceId, dashboardId, apiUrl, showWorkspaceDashboardSelect, onWorkspaceDashboardChange, ...rest }: PaperBoardProps): react_jsx_runtime.JSX.Element;
1154
+
1155
+ declare function readDashboardTourCompleted(key: string): boolean;
1156
+ declare function markDashboardTourCompleted(key: string): void;
1157
+ type BuildDashboardTourStepsOptions = {
1158
+ showToolbar: boolean;
1159
+ showChatAssistant: boolean;
1160
+ };
1161
+ /**
1162
+ * Driver.js steps aligned with main app GridDashboard tour (workspace selector omitted in embed).
1163
+ */
1164
+ declare function buildDashboardTourSteps({ showToolbar, showChatAssistant, }: BuildDashboardTourStepsOptions): TourStep[];
837
1165
 
838
1166
  type ThemePreset = 'default' | 'lime' | 'blue' | 'green' | 'purple' | 'ocean' | 'sunset' | 'dark' | 'minimal';
839
1167
 
@@ -865,10 +1193,7 @@ declare const presetDisplayNames: Record<ThemePreset, string>;
865
1193
  * 1. `meta.apply_theme_to_all_dashboards` + `meta.default_theme`
866
1194
  * 2. `meta.theme[dashboardId]` (falls back to `default_dashboard` when `dashboardId` is empty)
867
1195
  */
868
- declare function resolveDashboardThemeFromWorkspace(workspace: {
869
- meta?: Record<string, any>;
870
- default_dashboard?: string;
871
- } | null | undefined, dashboardId: string): DashboardTheme | undefined;
1196
+ declare function resolveDashboardThemeFromWorkspace(workspace: WorkspaceEntity | null | undefined, dashboardId: string): DashboardTheme | undefined;
872
1197
 
873
1198
  /**
874
1199
  * Persistent link between a host-owned stable id (`id` on {@link PaperCard})
@@ -917,4 +1242,4 @@ declare function resolveChartFetchChatId(params: {
917
1242
  dashboardId?: string;
918
1243
  }): string | undefined;
919
1244
 
920
- export { type AgentThought, AgentThoughtDisplay, BookmarkButton, BranchButton, ButtonWithTooltip, CHART_CARD_CHAT_MAP_KEY, CHAT_MODAL_TAB, type ChartCardIdLink, type ChartCardStorageNamespace, ChartDialog, ChartHistory, type ChartResponse, ChartView, ChatAssistant, type ChatModalTabType, type ConversationHistory, type DashboardTheme, DataTable, type DecodedToken, FeedbackButtons, type FinalResponse, LogoStandAlone, type Message, ModelSelector, MorphGradient, type OpenPapermapChatAssistantOptions, PaperBoard, type TLayout as PaperBoardLayoutItem, type PaperBoardLayouts, PaperCard, type PaperCardProps, PaperChat, type PaperChatProps, type PapermapActions, PapermapProvider as PapermapConfigProvider, type PapermapConnectionValue, type PapermapHttpServices, PapermapProvider, type PapermapState, type PapermapStore, type PapermapStoreApi, type PapermapStoreConfig, RecentConversations, SavedMemory, type StreamState, StreamingChartDialog, StreamingChatPanel, StreamingTimeline, type TChartMeta$1 as TChartMeta, type TChartResponse, ThemeCustomizationSettings, type ThemeCustomizationSettingsProps, type ThemePreset, type ThemeSaveMeta, type TimelineEvent, type ToolCall, ToolCallDisplay, buildAuthHeaders, createApiClient, createPapermapServices, createPapermapStore, decodeToken, defaultTheme, getChartCardIdLink, openPapermapChatAssistant, presetDisplayNames, removeChartCardIdLink, resolveChartFetchChatId, resolveDashboardThemeFromWorkspace, themePresetList, themePresets, upsertChartCardIdLink, useAnalyticsStream, useAutoFade, useAutoResize, useKeyboardShortcuts, usePapermapConnection, usePapermapConnectionOptional, usePapermapStore, usePapermapStoreApi, usePapermapStoreApiOptional };
1245
+ export { type AgentThought, AgentThoughtDisplay, BookmarkButton, BranchButton, ButtonWithTooltip, CHART_CARD_CHAT_MAP_KEY, CHAT_MODAL_TAB, type ChartCardIdLink, type ChartCardStorageNamespace, type ChartDataRow, ChartDialog, ChartHistory, type ChartResponse, ChartView, type ChartVisualizationConfig, ChatAssistant, type ChatModalTabType, type ConversationHistory, type DashboardNavbarItem, DashboardTabNavigation, type DashboardTabNavigationProps, type DashboardTheme, DataTable, type DecodedToken, FeedbackButtons, type FinalResponse, type JsonObject, LogoStandAlone, type Message, type MessageProgressEvent, ModelSelector, MorphGradient, type OpenPapermapChatAssistantOptions, PAPERMAP_PLUGIN_CONTRACT_VERSION, PAPERMAP_SDK_VERSION, PaperBoard, type TLayout as PaperBoardLayoutItem, type PaperBoardLayouts, PaperCard, type PaperCardProps, PaperChat, type PaperChatProps, PaperDashboardSelect, type PaperDashboardSelectProps, type PapermapActions, type PapermapCapability, PapermapProvider as PapermapConfigProvider, type PapermapConnectionValue, type PapermapHttpServices, type PapermapObservability, type PapermapObservabilityOptions, type PapermapPluginContext, type PapermapPluginLifecycle, type PapermapPluginManifest, type PapermapPluginRegistration, PapermapProvider, type PapermapState, type PapermapStore, type PapermapStoreApi, type PapermapStoreConfig, type PapermapTelemetryEvent, type PapermapTelemetryLevel, RecentConversations, SavedMemory, type StreamState, StreamingChartDialog, StreamingChatPanel, StreamingTimeline, type TChartMeta$1 as TChartMeta, type TChartResponse, ThemeCustomizationSettings, type ThemeCustomizationSettingsProps, type ThemePreset, type ThemeSaveMeta, type TimelineEvent, type ToolCall, ToolCallDisplay, type TourStep, type UseTourOptions, type WorkspaceEntity, type WorkspaceMeta, buildAuthHeaders, buildDashboardTourSteps, checkPluginPeerCompatibility, createApiClient, createPapermapObservability, createPapermapServices, createPapermapStore, createPluginContext, decodeToken, defaultTheme, getChartCardIdLink, markDashboardTourCompleted, openPapermapChatAssistant, papermapApiBaseSegment, papermapQueryKeys, parseSemverPrefix, presetDisplayNames, readDashboardTourCompleted, removeChartCardIdLink, resolveChartFetchChatId, resolveDashboardThemeFromWorkspace, themePresetList, themePresets, unwrapWorkspacePayload, upsertChartCardIdLink, useAnalyticsStream, useAutoFade, useAutoResize, useKeyboardShortcuts, usePapermapConnection, usePapermapConnectionOptional, usePapermapStore, usePapermapStoreApi, usePapermapStoreApiOptional, useTour };