@grafana/assistant 0.0.15 → 0.0.16

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 CHANGED
@@ -36,7 +36,9 @@ function MyComponent() {
36
36
  }
37
37
 
38
38
  return (
39
- <button onClick={() => openAssistant({ prompt: 'Help me analyze data' })}>
39
+ <button onClick={() => openAssistant({
40
+ origin: 'button',
41
+ prompt: 'Help me analyze data' })}>
40
42
  Open Assistant
41
43
  </button>
42
44
  );
@@ -49,10 +51,15 @@ function MyComponent() {
49
51
  import { openAssistant, closeAssistant } from '@grafana/assistant';
50
52
 
51
53
  // Open the assistant with an initial prompt
52
- openAssistant({ prompt: 'Show me CPU usage over the last hour' });
54
+ openAssistant({ origin: 'some-feature', prompt: 'Show me CPU usage over the last hour' });
55
+
56
+ // Open the assistant with initial prompt and autoSend set to false
57
+ openAssistant({ origin: 'some-feature', prompt: 'Help me analyze data', autoSend: false })
53
58
 
54
59
  // Open the assistant without an initial prompt
55
- openAssistant({});
60
+ openAssistant({
61
+ origin: 'some-page',
62
+ });
56
63
 
57
64
  // Close the assistant
58
65
  closeAssistant();
@@ -61,16 +68,14 @@ closeAssistant();
61
68
  ### Using Context with the Assistant
62
69
 
63
70
  ```typescript
64
- import { openAssistant, createContext } from '@grafana/assistant';
71
+ import { openAssistant, createAssistantContextItem } from '@grafana/assistant';
65
72
 
66
73
  // Create context items to provide additional information to the assistant
67
- const datasourceContext = createContext('datasource', {
68
- datasourceName: 'My Prometheus',
74
+ const datasourceContext = createAssistantContextItem('datasource', {
69
75
  datasourceUid: 'prometheus-uid',
70
- datasourceType: 'prometheus'
71
76
  });
72
77
 
73
- const dashboardContext = createContext('dashboard', {
78
+ const dashboardContext = createAssistantContextItem('dashboard', {
74
79
  dashboardUid: 'dashboard-uid',
75
80
  dashboardTitle: 'System Overview',
76
81
  folderUid: 'folder-uid',
@@ -79,9 +84,26 @@ const dashboardContext = createContext('dashboard', {
79
84
 
80
85
  // Open the assistant with initial prompt and context
81
86
  openAssistant({
87
+ origin: 'dashboard-page',
82
88
  prompt: 'Analyze the CPU metrics from this dashboard',
83
89
  context: [datasourceContext, dashboardContext]
84
90
  });
91
+
92
+ // Create hidden context for system instructions (won't show in UI pills)
93
+ const systemInstructions = createAssistantContextItem('structured', {
94
+ hidden: true,
95
+ title: 'System Instructions',
96
+ data: {
97
+ instructions: 'When analyzing metrics, always consider seasonal patterns and anomalies',
98
+ preferences: 'Use clear, technical language and provide actionable insights'
99
+ }
100
+ });
101
+
102
+ // Include hidden context with visible context
103
+ openAssistant({
104
+ prompt: 'What are the trends in this data?',
105
+ context: [datasourceContext, systemInstructions]
106
+ });
85
107
  ```
86
108
 
87
109
  ### Providing Page-Specific Context
@@ -89,10 +111,10 @@ openAssistant({
89
111
  You can register context items that are automatically included when the assistant is opened on pages matching specific URL patterns. The `providePageContext` function returns a setter function that allows you to update the context dynamically:
90
112
 
91
113
  ```typescript
92
- import { providePageContext, createContext } from '@grafana/assistant';
114
+ import { providePageContext, createAssistantContextItem } from '@grafana/assistant';
93
115
 
94
116
  // Create initial context for dashboard pages
95
- const dashboardContext = createContext('structured', {
117
+ const dashboardContext = createAssistantContextItem('structured', {
96
118
  data: {
97
119
  name: 'Dashboard Context',
98
120
  pageType: 'dashboard',
@@ -107,7 +129,7 @@ const setContext = providePageContext('/d/*', [dashboardContext]);
107
129
  // Later, dynamically update the context based on user interactions or data changes
108
130
  setContext([
109
131
  dashboardContext,
110
- createContext('structured', {
132
+ createAssistantContextItem('structured', {
111
133
  data: {
112
134
  name: 'Panel Context',
113
135
  selectedPanel: 'cpu-usage-panel',
@@ -118,6 +140,17 @@ setContext([
118
140
 
119
141
  // Clean up when no longer needed
120
142
  setContext.unregister();
143
+
144
+ // Example: Provide hidden system instructions for explore pages
145
+ providePageContext('/explore', [
146
+ createAssistantContextItem('structured', {
147
+ hidden: true,
148
+ title: 'Additional instructions',
149
+ data: {
150
+ 'System Instructions': 'When working with explore queries, always validate the time range and check for data availability. Suggest using recording rules for expensive queries.',
151
+ },
152
+ }),
153
+ ]);
121
154
  ```
122
155
 
123
156
  ### Using Page Context in React Components
@@ -125,10 +158,10 @@ setContext.unregister();
125
158
  For React components, use the `useProvidePageContext` hook which automatically handles cleanup:
126
159
 
127
160
  ```typescript
128
- import { useProvidePageContext, createContext } from '@grafana/assistant';
161
+ import { useProvidePageContext, createAssistantContextItem } from '@grafana/assistant';
129
162
 
130
163
  function DashboardComponent() {
131
- const dashboardContext = createContext('structured', {
164
+ const dashboardContext = createAssistantContextItem('structured', {
132
165
  data: {
133
166
  name: 'Dashboard Context',
134
167
  pageType: 'dashboard'
@@ -142,7 +175,7 @@ function DashboardComponent() {
142
175
  const handlePanelSelect = (panelId: string) => {
143
176
  setContext([
144
177
  dashboardContext,
145
- createContext('structured', {
178
+ createAssistantContextItem('structured', {
146
179
  data: {
147
180
  name: 'Panel Context',
148
181
  selectedPanel: panelId
@@ -173,22 +206,20 @@ function MyComponent() {
173
206
 
174
207
  ### Creating Context Items
175
208
 
176
- The `createContext` function allows you to create structured context items that provide the assistant with additional information about your Grafana resources.
209
+ The `createAssistantContextItem` function allows you to create structured context items that provide the assistant with additional information about your Grafana resources.
177
210
 
178
211
  ```typescript
179
- import { createContext } from '@grafana/assistant';
212
+ import { createAssistantContextItem } from '@grafana/assistant';
180
213
 
181
214
  // Create a datasource context
182
- const datasourceContext = createContext('datasource', {
183
- datasourceName: 'Production Prometheus',
215
+ const datasourceContext = createAssistantContextItem('datasource', {
184
216
  datasourceUid: 'prom-123',
185
- datasourceType: 'prometheus',
186
217
  title: 'Main Datasource', // Optional custom title
187
218
  icon: 'database' // Optional custom icon
188
219
  });
189
220
 
190
221
  // Create a dashboard context
191
- const dashboardContext = createContext('dashboard', {
222
+ const dashboardContext = createAssistantContextItem('dashboard', {
192
223
  dashboardUid: 'dash-456',
193
224
  dashboardTitle: 'Application Overview',
194
225
  folderUid: 'folder-789',
@@ -196,14 +227,14 @@ const dashboardContext = createContext('dashboard', {
196
227
  });
197
228
 
198
229
  // Create a label context
199
- const labelContext = createContext('label_name', {
230
+ const labelContext = createAssistantContextItem('label_name', {
200
231
  datasourceUid: 'prom-123',
201
232
  datasourceType: 'prometheus',
202
233
  labelName: 'service'
203
234
  });
204
235
 
205
236
  // Create a label value context
206
- const labelValueContext = createContext('label_value', {
237
+ const labelValueContext = createAssistantContextItem('label_value', {
207
238
  datasourceUid: 'prom-123',
208
239
  datasourceType: 'prometheus',
209
240
  labelName: 'service',
@@ -211,13 +242,13 @@ const labelValueContext = createContext('label_value', {
211
242
  });
212
243
 
213
244
  // Create a folder context
214
- const folderContext = createContext('dashboard_folder', {
245
+ const folderContext = createAssistantContextItem('dashboard_folder', {
215
246
  folderUid: 'folder-789',
216
247
  folderTitle: 'Production Dashboards'
217
248
  });
218
249
 
219
250
  // Create structured data context
220
- const structuredContext = createContext('structured', {
251
+ const structuredContext = createAssistantContextItem('structured', {
221
252
  data: {
222
253
  name: 'Custom Data',
223
254
  metrics: ['cpu_usage', 'memory_usage'],
@@ -226,10 +257,63 @@ const structuredContext = createContext('structured', {
226
257
  });
227
258
 
228
259
  // Create generic context
229
- const genericContext = createContext('unknown', {
260
+ const genericContext = createAssistantContextItem('unknown', {
230
261
  id: 'my-context',
231
262
  text: 'Some additional context information'
232
263
  });
264
+
265
+ // Create hidden context (useful for system instructions)
266
+ const hiddenInstructions = createAssistantContextItem('structured', {
267
+ hidden: true, // Won't be shown in UI pills but will be sent to the assistant
268
+ title: 'Page-specific instructions',
269
+ data: {
270
+ instructions: 'Always provide step-by-step explanations',
271
+ context: 'This is a complex system with multiple dependencies'
272
+ }
273
+ });
274
+ ```
275
+
276
+ ### Using Hidden Context for System Instructions
277
+
278
+ The `hidden` parameter allows you to provide context to the assistant without showing it in the UI pills. This is particularly useful for:
279
+
280
+ - **System instructions**: Provide behavioral guidelines specific to certain pages
281
+ - **Metadata**: Include technical details that might confuse users if shown
282
+ - **Contextual rules**: Add page-specific rules without cluttering the interface
283
+
284
+ Example use cases:
285
+
286
+ ```typescript
287
+ // Provide exploration-specific guidelines
288
+ providePageContext('/explore', [
289
+ createAssistantContextItem('structured', {
290
+ hidden: true,
291
+ title: 'Explore Page Guidelines',
292
+ data: {
293
+ instructions: [
294
+ 'Always validate time ranges before running queries',
295
+ 'Suggest using recording rules for expensive queries',
296
+ 'Warn about queries that might impact performance'
297
+ ],
298
+ queryLimits: {
299
+ maxTimeRange: '24h',
300
+ suggestedSampleInterval: '1m'
301
+ }
302
+ }
303
+ })
304
+ ]);
305
+
306
+ // Add dashboard-specific context
307
+ providePageContext('/d/*', [
308
+ createAssistantContextItem('structured', {
309
+ hidden: true,
310
+ title: 'Dashboard Instructions',
311
+ data: {
312
+ bestPractices: 'Encourage users to use template variables for flexibility',
313
+ performance: 'Suggest panel caching for slow queries'
314
+ }
315
+ })
316
+ ]);
233
317
  ```
234
318
 
235
319
  ### Exposing Functions to the Assistant
@@ -263,6 +347,52 @@ export const getExtensionConfigs = () => [
263
347
  ];
264
348
  ```
265
349
 
350
+ ### Using the OpenAssistantButton Component
351
+
352
+ The `OpenAssistantButton` is a pre-built Button component that provides an easy way to add assistant functionality to your UI with a single button click. It automatically checks availability and hides itself if the Assistant is not available.
353
+
354
+ ```typescript
355
+ import { OpenAssistantButton, createAssistantContextItem } from '@grafana/assistant';
356
+
357
+ function MyDashboard() {
358
+ const dashboardContext = createAssistantContextItem('dashboard', {
359
+ dashboardUid: 'dashboard-123',
360
+ dashboardTitle: 'CPU Metrics Dashboard'
361
+ });
362
+
363
+ return (
364
+ <div>
365
+ <h1>Dashboard</h1>
366
+
367
+ {/* Basic usage */}
368
+ <OpenAssistantButton
369
+ prompt="Help me analyze the CPU usage trends in this dashboard"
370
+ context={[dashboardContext]}
371
+ origin="dashboard-menu"
372
+ />
373
+
374
+ {/* Icon-only button */}
375
+ <OpenAssistantButton
376
+ prompt="Show me optimization suggestions"
377
+ iconOnlyButton={true}
378
+ name="Get AI suggestions"
379
+ size="md"
380
+ origin="loki-query-editor"
381
+ />
382
+
383
+ {/* Button without auto-send */}
384
+ <OpenAssistantButton
385
+ prompt="What patterns do you see in the data?"
386
+ autoSend={false}
387
+ name="Ask Assistant"
388
+ size="lg"
389
+ origin="panel-viewer"
390
+ />
391
+ </div>
392
+ );
393
+ }
394
+ ```
395
+
266
396
  ## API Reference
267
397
 
268
398
  ### React Hooks
@@ -292,6 +422,23 @@ A React hook for providing page context that automatically cleans up on unmount.
292
422
 
293
423
  **Returns:** A setter function to update the context
294
424
 
425
+ ### React Components
426
+
427
+ #### `<OpenAssistantButton />`
428
+
429
+ A pre-built React component that renders a button to open the Grafana Assistant with configurable prompt and context.
430
+
431
+ **Parameters:**
432
+ - `prompt: string` - **Required** The initial prompt to display in the assistant
433
+ - `origin: string` - **Required** Origin of the request that opened the assistant
434
+ - `context?: ChatContextItem[]` - Optional context items created with `createAssistantContextItem`
435
+ - `autoSend?: boolean` - Whether to automatically send the initial prompt (defaults to `true`)
436
+ - `title?: string` - Text to display on the button (defaults to `'Analyze with Assistant'`)
437
+ - `size?: 'xs' | 'sm' | 'md' | 'lg'` - Button size (defaults to `'sm'`)
438
+ - `iconOnlyButton?: boolean` - If `true`, renders as an icon-only button with tooltip (defaults to `false`)
439
+
440
+ **Returns:** JSX element or `null` if assistant is not available
441
+
295
442
  ### Availability Functions
296
443
 
297
444
  #### `isAssistantAvailable(): Observable<boolean>`
@@ -308,8 +455,10 @@ Opens the Grafana Assistant sidebar.
308
455
 
309
456
  **Parameters:**
310
457
  - `props: OpenAssistantProps` - Configuration object
458
+ - `origin: string` - The origin of the request that opened the assistant. This is used to track the source of the request. Should be a static string that helps identify the source of the request.
311
459
  - `prompt?: string` - Optional initial prompt to display in the assistant
312
460
  - `context?: ChatContextItem[]` - Optional context items to provide additional information to the assistant
461
+ - `autoSend?: boolean` - Optional flag to automatically send the initial prompt
313
462
 
314
463
  #### `closeAssistant(): void`
315
464
 
@@ -317,7 +466,7 @@ Closes the Grafana Assistant sidebar.
317
466
 
318
467
  ### Context Functions
319
468
 
320
- #### `createContext<T>(type: T, params: ContextTypeParams<T>): ChatContextItem`
469
+ #### `createAssistantContextItem<T>(type: T, params: ContextTypeParams<T>): ChatContextItem`
321
470
 
322
471
  Creates a context item that can be passed to the assistant to provide additional information.
323
472
 
@@ -330,7 +479,8 @@ Creates a context item that can be passed to the assistant to provide additional
330
479
  - `'label_value'` - Label value context
331
480
  - `'structured'` - Custom structured data context
332
481
  - `'unknown'` - Generic text context
333
- - `params` - Parameters specific to the context type (see Context Types section)
482
+ - `params` - Parameters specific to the context type (see Context Types section). All context types support:
483
+ - `hidden?: boolean` - If true, the context item will not be shown in the UI pills but will still be sent to the assistant. This is useful for providing system instructions, behavioral guidelines, or other metadata that shouldn't clutter the user interface.
334
484
 
335
485
  **Returns:** A `ChatContextItem` that can be passed to `openAssistant`
336
486
 
@@ -382,12 +532,12 @@ Registers questions for specific pages based on URL patterns. Returns a setter f
382
532
  const setQuestions = provideQuestions("/d/*", [
383
533
  {
384
534
  prompt: "What metrics are available in this dashboard?",
385
- context: [], // Optional context items created with `createContext`
535
+ context: [], // Optional context items created with `createAssistantContextItem`
386
536
  },
387
537
  {
388
538
  prompt: "How can I optimize the queries in this dashboard?",
389
539
  context: [
390
- createContext("dashboard", {
540
+ createAssistantContextItem("dashboard", {
391
541
  dashboardUid: 'dashboard-uid',
392
542
  dashboardTitle: 'System Overview',
393
543
  folderUid: 'folder-uid',
@@ -470,13 +620,15 @@ function AssistantComponent() {
470
620
  type OpenAssistantProps = {
471
621
  prompt?: string;
472
622
  context?: ChatContextItem[];
623
+ autoSend?: boolean;
473
624
  };
474
625
  ```
475
626
 
476
627
  Configuration object for opening the assistant.
477
628
 
478
629
  - `prompt` - Optional initial prompt to display
479
- - `context` - Optional context items to provide
630
+ - `context` - Optional context items to provide
631
+ - `autoSend` - Optional flag to automatically send the initial prompt
480
632
 
481
633
  #### `ChatContextItem`
482
634
 
@@ -534,11 +686,10 @@ Represents a registered questions mapping.
534
686
 
535
687
  ```typescript
536
688
  interface CreateDatasourceContextParams {
537
- datasourceName: string;
538
689
  datasourceUid: string;
539
- datasourceType: string;
540
690
  title?: string;
541
691
  icon?: IconName;
692
+ hidden?: boolean; // If true, the context item will not be shown in the context pills
542
693
  }
543
694
  ```
544
695
 
@@ -552,6 +703,7 @@ interface CreateDashboardContextParams {
552
703
  folderTitle?: string;
553
704
  title?: string;
554
705
  icon?: IconName;
706
+ hidden?: boolean; // If true, the context item will not be shown in the context pills
555
707
  }
556
708
  ```
557
709
 
@@ -563,6 +715,7 @@ interface CreateFolderContextParams {
563
715
  folderTitle: string;
564
716
  title?: string;
565
717
  icon?: IconName;
718
+ hidden?: boolean; // If true, the context item will not be shown in the context pills
566
719
  }
567
720
  ```
568
721
 
@@ -575,6 +728,7 @@ interface CreateLabelNameContextParams {
575
728
  labelName: string;
576
729
  title?: string;
577
730
  icon?: IconName;
731
+ hidden?: boolean; // If true, the context item will not be shown in the context pills
578
732
  }
579
733
  ```
580
734
 
@@ -588,6 +742,7 @@ interface CreateLabelValueContextParams {
588
742
  labelValue: string;
589
743
  title?: string;
590
744
  icon?: IconName;
745
+ hidden?: boolean; // If true, the context item will not be shown in the context pills
591
746
  }
592
747
  ```
593
748
 
@@ -598,6 +753,7 @@ interface StructuredNodeDataParams {
598
753
  data: Record<string, any>;
599
754
  title?: string;
600
755
  icon?: IconName;
756
+ hidden?: boolean; // If true, the context item will not be shown in the context pills
601
757
  }
602
758
  ```
603
759
 
@@ -609,6 +765,7 @@ interface NodeDataParams {
609
765
  text?: string;
610
766
  title?: string;
611
767
  icon?: IconName;
768
+ hidden?: boolean; // If true, the context item will not be shown in the context pills
612
769
  }
613
770
  ```
614
771
 
@@ -689,9 +846,7 @@ export type LabelNameNodeData;
689
846
  export type LabelValueNodeData;
690
847
  export type StructuredNodeData;
691
848
  export type TreeNode;
692
-
693
- // Enums
694
- export enum ItemDataType;
849
+ export type ItemDataType;
695
850
  ```
696
851
 
697
852
  ## License
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { ChatContextItem } from '../context/types';
3
+ export interface OpenAssistantButtonProps {
4
+ /** Prompt to pass to the openAssistant function. */
5
+ prompt: string;
6
+ /** Origin of the request that opened the assistant. This is used to track the source of the request. Should be a static string that helps identify the source of the request. */
7
+ origin: string;
8
+ /** Context to pass to the openAssistant function. Optional, defaults to undefined. Created with `createAssistantContextItem`. */
9
+ context?: ChatContextItem[];
10
+ /** Whether to automatically send the prompt. Optional, defaults to true. */
11
+ autoSend?: boolean;
12
+ /** Text to display on the button. Optional, defaults to 'Analyze with Assistant' */
13
+ title?: string;
14
+ /** Button size, defaults to sm */
15
+ size?: 'xs' | 'sm' | 'md' | 'lg';
16
+ /** If true, the button will be Assistant icon only with name as title. Defaults to false. */
17
+ iconOnlyButton?: boolean;
18
+ }
19
+ /**
20
+ * A button component that opens the Grafana Assistant with configurable prompt and context.
21
+ */
22
+ export declare function OpenAssistantButton({ prompt, origin, context, autoSend, title, size, iconOnlyButton, }: OpenAssistantButtonProps): React.JSX.Element | null;
@@ -0,0 +1 @@
1
+ export { OpenAssistantButton, type OpenAssistantButtonProps } from './OpenAssistantButton';
@@ -2,6 +2,7 @@ import { IconName } from '@grafana/ui';
2
2
  import { type ContextItemData } from './types';
3
3
  export interface BaseParams {
4
4
  title?: string;
5
+ hidden?: boolean;
5
6
  img?: string;
6
7
  icon?: IconName;
7
8
  }
@@ -9,9 +10,6 @@ export interface NodeDataParams extends BaseParams {
9
10
  id: string;
10
11
  text?: string;
11
12
  }
12
- export interface StructuredNodeDataParams extends BaseParams {
13
- data: Record<string, any>;
14
- }
15
13
  export declare class NodeData {
16
14
  params: NodeDataParams;
17
15
  id: string;
@@ -19,6 +17,9 @@ export declare class NodeData {
19
17
  constructor(params: NodeDataParams);
20
18
  formatForLLM(codeElementIds?: string[]): ContextItemData;
21
19
  }
20
+ export interface StructuredNodeDataParams extends BaseParams {
21
+ data: Record<string, any>;
22
+ }
22
23
  export declare class StructuredNodeData {
23
24
  params: StructuredNodeDataParams;
24
25
  id: string;
@@ -1,22 +1,5 @@
1
- import { NodeDataParams, StructuredNodeDataParams } from './base';
2
- import { CreateDashboardContextParams, CreateFolderContextParams } from './dashboard';
3
- import { CreateDatasourceContextParams } from './datasource';
4
- import { CreateLabelNameContextParams, CreateLabelValueContextParams } from './label';
5
- import { ChatContextItem, ItemDataType } from './types';
6
- type ContextTypeMap = {
7
- [ItemDataType.Datasource]: CreateDatasourceContextParams;
8
- [ItemDataType.LabelName]: CreateLabelNameContextParams;
9
- [ItemDataType.LabelValue]: CreateLabelValueContextParams;
10
- [ItemDataType.Dashboard]: CreateDashboardContextParams;
11
- [ItemDataType.DashboardFolder]: CreateFolderContextParams;
12
- [ItemDataType.Structured]: StructuredNodeDataParams;
13
- [ItemDataType.Unknown]: NodeDataParams;
14
- };
15
- /**
16
- * @deprecated This function is deprecated and will be removed in a future release because it collides with React's context naming.
17
- * Use createContextItem instead.
18
- */
19
- export declare function createContext<T extends keyof ContextTypeMap>(type: T, params: ContextTypeMap[T]): ChatContextItem;
1
+ import { ContextTypeRegistry } from './factory';
2
+ import { ChatContextItem } from './types';
20
3
  /**
21
4
  * Creates a new chat context item that can be added to conversations.
22
5
  *
@@ -40,16 +23,14 @@ export declare function createContext<T extends keyof ContextTypeMap>(type: T, p
40
23
  * // Create a context that will be passed into the function triggering an assistant open
41
24
  * openAssistant({
42
25
  * ...
26
+ * origin: 'my-feature',
43
27
  * context: [
44
- * createAssistantContext(ItemDataType.Datasource, {
28
+ * createAssistantContextItem('datasource', {
45
29
  * datasourceUid: datasource.uid,
46
- * datasourceName: datasource.name,
47
- * datasourceType: datasource.type,
48
30
  * img: datasource.meta?.info?.logos?.small,
49
31
  * }),
50
32
  * ],
51
33
  * });
52
34
  * ```
53
35
  */
54
- export declare function createContextItem<T extends keyof ContextTypeMap>(type: T, params: ContextTypeMap[T]): ChatContextItem;
55
- export {};
36
+ export declare function createAssistantContextItem<T extends keyof ContextTypeRegistry>(type: T, params: ContextTypeRegistry[T]['params']): ChatContextItem;
@@ -15,7 +15,6 @@ export declare class DashboardNodeData extends NodeData {
15
15
  dashboardTitle: string;
16
16
  folderUid?: string;
17
17
  folderTitle?: string;
18
- text: string;
19
18
  constructor(params: CreateDashboardContextParams);
20
19
  formatForLLM(codeElementIds?: string[]): ContextItemData;
21
20
  }
@@ -1,15 +1,19 @@
1
1
  import { BaseParams, NodeData } from './base';
2
+ import { DatasourceMeta } from './factory';
2
3
  import { type ContextItemData } from './types';
4
+ /**
5
+ * Type used to create a datasource context item.
6
+ *
7
+ * All required attributes will be inferred from the datasources uid.
8
+ */
3
9
  export interface CreateDatasourceContextParams extends BaseParams {
4
- datasourceName: string;
5
10
  datasourceUid: string;
6
- datasourceType: string;
7
11
  }
8
12
  export declare class DatasourceNodeData extends NodeData {
9
13
  datasourceUid: string;
10
14
  datasourceType: string;
11
15
  datasourceName: string;
12
- text: string;
13
- constructor(params: CreateDatasourceContextParams);
16
+ img?: string;
17
+ constructor(params: CreateDatasourceContextParams & DatasourceMeta);
14
18
  formatForLLM(codeElementIds?: string[]): ContextItemData;
15
19
  }
@@ -2,38 +2,45 @@ import { NodeData, NodeDataParams, StructuredNodeData, StructuredNodeDataParams
2
2
  import { DashboardNodeData, FolderNodeData, type CreateDashboardContextParams, type CreateFolderContextParams } from './dashboard';
3
3
  import { DatasourceNodeData, type CreateDatasourceContextParams } from './datasource';
4
4
  import { LabelNameNodeData, LabelValueNodeData, type CreateLabelNameContextParams, type CreateLabelValueContextParams } from './label';
5
- type ContextTypeMap = {
5
+ /**
6
+ * registry to handle the type mappings between ItemData type, params and node data
7
+ */
8
+ export type ContextTypeRegistry = {
6
9
  datasource: {
7
10
  params: CreateDatasourceContextParams;
8
- return: DatasourceNodeData;
11
+ node: DatasourceNodeData;
9
12
  };
10
13
  label_name: {
11
14
  params: CreateLabelNameContextParams;
12
- return: LabelNameNodeData;
15
+ node: LabelNameNodeData;
13
16
  };
14
17
  label_value: {
15
18
  params: CreateLabelValueContextParams;
16
- return: LabelValueNodeData;
19
+ node: LabelValueNodeData;
17
20
  };
18
21
  dashboard: {
19
22
  params: CreateDashboardContextParams;
20
- return: DashboardNodeData;
23
+ node: DashboardNodeData;
21
24
  };
22
25
  dashboard_folder: {
23
26
  params: CreateFolderContextParams;
24
- return: FolderNodeData;
27
+ node: FolderNodeData;
25
28
  };
26
29
  structured: {
27
30
  params: StructuredNodeDataParams;
28
- return: StructuredNodeData;
31
+ node: StructuredNodeData;
29
32
  };
30
33
  unknown: {
31
34
  params: NodeDataParams;
32
- return: NodeData;
35
+ node: NodeData;
33
36
  };
34
37
  };
38
+ export type DatasourceMeta = {
39
+ datasourceType: string;
40
+ datasourceName: string;
41
+ img?: string;
42
+ };
35
43
  /**
36
44
  * Creates context nodes based on type with full type safety using generics
37
45
  */
38
- export declare function createContextByType<T extends keyof ContextTypeMap>(type: T, params: ContextTypeMap[T]['params']): ContextTypeMap[T]['return'];
39
- export {};
46
+ export declare function createContextByType<T extends keyof ContextTypeRegistry>(type: T, params: ContextTypeRegistry[T]['params']): ContextTypeRegistry[T]['node'];
@@ -1,8 +1,8 @@
1
1
  import { BaseParams, NodeData } from './base';
2
+ import { DatasourceMeta } from './factory';
2
3
  import { type ContextItemData } from './types';
3
4
  export interface CreateLabelNameContextParams extends BaseParams {
4
5
  datasourceUid: string;
5
- datasourceType: string;
6
6
  labelName: string;
7
7
  }
8
8
  export interface CreateLabelValueContextParams extends CreateLabelNameContextParams {
@@ -11,17 +11,19 @@ export interface CreateLabelValueContextParams extends CreateLabelNameContextPar
11
11
  export declare class LabelNameNodeData extends NodeData {
12
12
  datasourceUid: string;
13
13
  datasourceType: string;
14
+ datasourceName: string;
14
15
  labelName: string;
15
- text: string;
16
- constructor(params: CreateLabelNameContextParams);
16
+ img?: string;
17
+ constructor(params: CreateLabelNameContextParams & DatasourceMeta);
17
18
  formatForLLM(codeElementIds?: string[]): ContextItemData;
18
19
  }
19
20
  export declare class LabelValueNodeData extends NodeData {
20
21
  datasourceUid: string;
21
22
  datasourceType: string;
23
+ datasourceName: string;
22
24
  labelName: string;
23
25
  labelValue: string;
24
- text: string;
25
- constructor(params: CreateLabelValueContextParams);
26
+ img?: string;
27
+ constructor(params: CreateLabelValueContextParams & DatasourceMeta);
26
28
  formatForLLM(codeElementIds?: string[]): ContextItemData;
27
29
  }
@@ -5,15 +5,7 @@ export interface BaseItemData {
5
5
  }
6
6
  export interface UnknownItemData extends BaseItemData {
7
7
  }
8
- export declare enum ItemDataType {
9
- Unknown = "unknown",
10
- Datasource = "datasource",
11
- LabelName = "label_name",
12
- LabelValue = "label_value",
13
- Dashboard = "dashboard",
14
- DashboardFolder = "dashboard_folder",
15
- Structured = "structured"
16
- }
8
+ export type ItemDataType = 'unknown' | 'datasource' | 'label_name' | 'label_value' | 'dashboard' | 'dashboard_folder' | 'structured';
17
9
  export interface ContextItemData {
18
10
  type: ItemDataType;
19
11
  codeElementIds?: string[];
@@ -33,11 +25,14 @@ export interface TreeNode {
33
25
  export interface DatasourceItemData extends BaseItemData {
34
26
  uid: string;
35
27
  type: string;
28
+ img?: string;
36
29
  }
37
30
  export interface LabelNameItemData extends BaseItemData {
38
31
  datasourceUid: string;
39
32
  datasourceType: string;
33
+ datasourceName: string;
40
34
  labelName: string;
35
+ img?: string;
41
36
  }
42
37
  export interface LabelValueItemData extends LabelNameItemData {
43
38
  labelValue: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export { createContext, createContextItem, ChatContextItem, DashboardNodeData, DatasourceNodeData, FolderNodeData, ItemDataType, LabelNameNodeData, LabelValueNodeData, StructuredNodeData, TreeNode, providePageContext, useProvidePageContext, PageContextRegistration, usePageContext, provideQuestions, useProvideQuestions, useQuestions, Question, QuestionRegistration, } from './context/index';
1
+ export { createAssistantContextItem, ChatContextItem, DashboardNodeData, DatasourceNodeData, FolderNodeData, ItemDataType, LabelNameNodeData, LabelValueNodeData, StructuredNodeData, TreeNode, providePageContext, useProvidePageContext, PageContextRegistration, usePageContext, provideQuestions, useProvideQuestions, useQuestions, Question, QuestionRegistration, } from './context/index';
2
2
  export * from './functions';
3
3
  export * from './hook';
4
4
  export * from './plugin';
5
5
  export * from './sidebar';
6
+ export * from './components';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var e,t={d:(e,a)=>{for(var n in a)t.o(a,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:a[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},a={};function n(e){let t=5381;for(let a=0;a<e.length;a++)t=(t<<5)+t+e.charCodeAt(a);return(t>>>0).toString(16)}t.r(a),t.d(a,{CALLBACK_EXTENSION_POINT:()=>C,DashboardNodeData:()=>o,DatasourceNodeData:()=>d,FolderNodeData:()=>i,ItemDataType:()=>e,LabelNameNodeData:()=>l,LabelValueNodeData:()=>u,StructuredNodeData:()=>r,closeAssistant:()=>M,createContext:()=>f,createContextItem:()=>h,getExposeAssistantFunctionsConfig:()=>F,isAssistantAvailable:()=>V,newFunctionNamespace:()=>A,openAssistant:()=>k,providePageContext:()=>y,provideQuestions:()=>D,useAssistant:()=>R,usePageContext:()=>N,useProvidePageContext:()=>T,useProvideQuestions:()=>S,useQuestions:()=>I}),function(e){e.Unknown="unknown",e.Datasource="datasource",e.LabelName="label_name",e.LabelValue="label_value",e.Dashboard="dashboard",e.DashboardFolder="dashboard_folder",e.Structured="structured"}(e||(e={}));class s{constructor(e){this.params=e,this.text="",this.id=n(e.id)}formatForLLM(t){var a,n;return{type:e.Unknown,codeElementIds:t,data:{name:null!==(a=this.params.text)&&void 0!==a?a:"",text:null!==(n=this.params.text)&&void 0!==n?n:""}}}}class r{constructor(e){this.params=e,this.id=n(JSON.stringify(e.data))}formatForLLM(t){return{type:e.Structured,codeElementIds:t,data:this.params.data}}}class o extends s{constructor(e){super({...e,id:e.dashboardUid}),this.text="",this.dashboardUid=e.dashboardUid,this.dashboardTitle=e.dashboardTitle,this.folderUid=e.folderUid,this.folderTitle=e.folderTitle,this.text=e.dashboardTitle}formatForLLM(t){return{type:e.Dashboard,codeElementIds:t,data:{name:this.dashboardTitle,dashboardUid:this.dashboardUid,dashboardTitle:this.dashboardTitle,folderUid:this.folderUid,folderTitle:this.folderTitle,text:this.text}}}}class i extends s{constructor(e){super({...e,id:e.folderUid}),this.text="",this.folderUid=e.folderUid,this.folderTitle=e.folderTitle,this.text=e.folderTitle}formatForLLM(t){return{type:e.DashboardFolder,codeElementIds:t,data:{name:this.folderTitle,folderUid:this.folderUid,folderTitle:this.folderTitle,text:this.text}}}}class d extends s{constructor(e){super({...e,id:e.datasourceUid}),this.text="",this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.datasourceName=e.datasourceName,this.text=e.datasourceName}formatForLLM(t){return{type:e.Datasource,codeElementIds:t,data:{name:this.datasourceName,uid:this.datasourceUid,type:this.datasourceType,text:this.text}}}}class l extends s{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}`}),this.text="",this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.labelName=e.labelName,this.text=e.labelName}formatForLLM(t){return{type:e.LabelName,codeElementIds:t,data:{name:this.labelName,datasourceUid:this.datasourceUid,datasourceType:this.datasourceType,labelName:this.labelName,text:this.text}}}}class u extends s{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}-${e.labelValue}`}),this.text="",this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.labelName=e.labelName,this.labelValue=e.labelValue,this.text=e.labelValue}formatForLLM(t){return{type:e.LabelValue,codeElementIds:t,data:{name:this.labelValue,datasourceUid:this.datasourceUid,datasourceType:this.datasourceType,labelName:this.labelName,labelValue:this.labelValue,text:this.text}}}}const c={[e.Datasource]:"database",[e.LabelName]:"database",[e.LabelValue]:"database",[e.Dashboard]:"dashboard",[e.DashboardFolder]:"folder",[e.Unknown]:"circle-mono",[e.Structured]:"gf-grid"};function p(t,a){return t===e.Datasource?a.datasourceName:t===e.LabelName?a.labelName:t===e.LabelValue?a.labelValue:t===e.Dashboard?a.dashboardTitle:t===e.DashboardFolder?a.folderTitle:t===e.Structured?a.data.name:"Given Context"}function f(e,t){var a,n;const f=function(e,t){switch(e){case"datasource":return new d(t);case"label_name":return new l(t);case"label_value":return new u(t);case"dashboard":return new o(t);case"dashboard_folder":return new i(t);case"structured":return new r(t);case"unknown":return new s(t);default:return console.error(`Unknown context type: ${e}`),new s(t)}}(e,t);return{node:{id:f.id,name:null!==(a=t.title)&&void 0!==a?a:p(e,t),img:t.img,icon:null!==(n=t.icon)&&void 0!==n?n:c[e],navigable:!1,selectable:!0,data:f},occurrences:[]}}function h(e,t){return f(e,t)}const m=require("@grafana/runtime"),b=require("react"),v=[],x="grafana-assistant:page-context-sync",g="grafana-assistant:page-context-update",w="grafana-assistant:page-context-remove",E="grafana-assistant:location-changed";let L=!1;function y(e,t){const a=v.findIndex((t=>{return a=t.urlPattern,n=e,"string"==typeof a&&"string"==typeof n?a===n:a instanceof RegExp&&n instanceof RegExp&&a.source===n.source&&a.flags===n.flags;var a,n}));let n;-1!==a?(n=v[a],n.context=[...t]):(n={id:`page-context-${Date.now()}-${Math.random().toString(36).slice(2,11)}`,urlPattern:e,context:[...t]},v.push(n)),window.dispatchEvent(new CustomEvent(g,{detail:n})),window.dispatchEvent(new CustomEvent(x,{detail:{registry:v}}));const s=e=>{const t=v.findIndex((e=>e.id===n.id));-1!==t&&(v[t].context=[...e],window.dispatchEvent(new CustomEvent(g,{detail:v[t]})))};return s.unregister=()=>{const e=v.findIndex((e=>e.id===n.id));-1!==e&&(v.splice(e,1),window.dispatchEvent(new CustomEvent(w,{detail:{id:n.id}})))},s}function T(e,t=[]){const a=(0,b.useRef)(void 0),n=(0,b.useRef)(t);return n.current=t,(0,b.useEffect)((()=>(a.current=y(e,n.current),()=>{var e;null===(e=a.current)||void 0===e||e.unregister()})),[e]),(0,b.useEffect)((()=>{a.current&&a.current(t)}),[t]),(0,b.useCallback)((e=>{var t;null===(t=a.current)||void 0===t||t.call(a,e)}),[])}function N(e={allowQuestions:!1}){const[t,a]=(0,b.useState)([]),n=(0,m.useLocationService)(),s=(0,b.useRef)("");return(0,b.useEffect)((()=>{const e=()=>{const e=function(e,t){if(!e)return[];const a=[];for(const n of t)U(e,n.urlPattern)&&a.push(...n.context);return a}(n.getLocation().pathname,v);a(e)},t=()=>{e()},r=t=>{var a;const s=null===(a=t.detail)||void 0===a?void 0:a.pathname;s&&s===n.getLocation().pathname&&e()},o=n.getLocationObservable().subscribe((t=>{const a=t.pathname;a!==s.current&&(s.current=a,function(e){window.dispatchEvent(new CustomEvent(E,{detail:{pathname:e}}))}(a),e())}));return e(),window.addEventListener(x,t),window.addEventListener(g,t),window.addEventListener(w,t),window.addEventListener(E,r),()=>{o.unsubscribe(),window.removeEventListener(x,t),window.removeEventListener(g,t),window.removeEventListener(w,t),window.removeEventListener(E,r)}}),[n]),e.allowQuestions?t:t.filter((e=>{var t;return"question"!==(null===(t=e.node.data)||void 0===t?void 0:t.type)}))}function U(e,t){if(t instanceof RegExp)return t.test(e);if("string"==typeof t){const a=t.replace(/\*\*/g,"\0DOUBLE_STAR\0").replace(/\*/g,"[^/]*").replace(/\u0000DOUBLE_STAR\u0000/g,".*").replace(/\?/g,".");return new RegExp(`^${a}$`).test(e)}return!1}function D(e,t){const a=e=>e.map(((e,t)=>({node:{id:`question-${t}`,name:e.prompt,navigable:!1,selectable:!0,icon:"question-circle",data:{type:"question",prompt:e.prompt,context:e.context||[]}},occurrences:[]}))),n=y(e,a(t)),s=e=>{n(a(e))};return s.unregister=n.unregister,s}function S(e,t=[]){const a=e=>e.map(((e,t)=>({node:{id:`question-${t}`,name:e.prompt,navigable:!1,selectable:!0,icon:"question-circle",data:{type:"question",prompt:e.prompt,context:e.context||[]}},occurrences:[]}))),n=T(e,a(t));return e=>{n(a(e))}}function I(){const e=N({allowQuestions:!0});return P(e)}L||(window.addEventListener(x,(e=>{var t;const a=null===(t=e.detail)||void 0===t?void 0:t.registry;if(a){const e=new Set(v.map((e=>e.id))),t=a.filter((t=>!e.has(t.id)));v.push(...t)}})),window.addEventListener(g,(e=>{const t=e.detail;if(t){const e=v.findIndex((e=>e.id===t.id));-1!==e?v[e]=t:v.push(t)}})),window.addEventListener(w,(e=>{var t;const a=null===(t=e.detail)||void 0===t?void 0:t.id;if(a){const e=v.findIndex((e=>e.id===a));-1!==e&&v.splice(e,1)}})),L=!0);const P=e=>e.filter((e=>{var t;return"question"===(null===(t=e.node.data)||void 0===t?void 0:t.type)})).map((e=>{var t,a;return{prompt:(null===(t=e.node.data)||void 0===t?void 0:t.prompt)||e.node.name,context:(null===(a=e.node.data)||void 0===a?void 0:a.context)||[]}})),C="grafana-assistant-app/callback/v0-alpha";function A(e,t){return{namespace:e,functions:t}}function F(e){return{title:"callback",targets:[C],fn:()=>e.map((e=>({namespace:e.namespace,functions:e.functions})))}}const O=require("rxjs");function V(){if(!m.getObservablePluginLinks)return(0,O.of)(!1);return(0,m.getObservablePluginLinks)({extensionPointId:"grafana/extension-sidebar/v0-alpha"}).pipe((0,O.map)((e=>e.some((e=>"grafana-assistant-app"===e.pluginId&&"Grafana Assistant"===e.title)))))}const q=require("@grafana/data");class $ extends q.BusEventWithPayload{}$.type="open-extension-sidebar";class _ extends q.BusEventBase{}function k(e){!function(e,t,a){const n=new $({pluginId:"grafana-assistant-app",componentTitle:"Grafana Assistant",props:a});(0,m.getAppEvents)().publish(n)}(0,0,{initialPrompt:e.prompt,initialContext:e.context})}function M(){!function(){const e=new _;(0,m.getAppEvents)().publish(e)}()}function R(){const[e,t]=(0,b.useState)(!1);return(0,b.useEffect)((()=>{const e=V().subscribe((e=>t(e)));return()=>{e.unsubscribe()}}),[]),[e,e?k:void 0,e?M:void 0]}_.type="close-extension-sidebar",module.exports=a})();
1
+ (()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n);return(t>>>0).toString(16)}e.r(t),e.d(t,{CALLBACK_EXTENSION_POINT:()=>T,DashboardNodeData:()=>i,DatasourceNodeData:()=>c,FolderNodeData:()=>o,LabelNameNodeData:()=>u,LabelValueNodeData:()=>l,OpenAssistantButton:()=>it,StructuredNodeData:()=>a,closeAssistant:()=>q,createAssistantContextItem:()=>p,getExposeAssistantFunctionsConfig:()=>_,isAssistantAvailable:()=>O,newFunctionNamespace:()=>U,openAssistant:()=>j,providePageContext:()=>k,provideQuestions:()=>S,useAssistant:()=>D,usePageContext:()=>A,useProvidePageContext:()=>E,useProvideQuestions:()=>$,useQuestions:()=>N});class r{constructor(e){this.params=e,this.text="",this.id=n(e.id)}formatForLLM(e){var t,n;return{type:"unknown",codeElementIds:e,data:{name:null!==(t=this.params.text)&&void 0!==t?t:"",text:null!==(n=this.params.text)&&void 0!==n?n:""}}}}class a{constructor(e){this.params=e,this.id=n(JSON.stringify(e.data))}formatForLLM(e){return{type:"structured",codeElementIds:e,data:this.params.data}}}const s=require("@grafana/runtime");class i extends r{constructor(e){super({...e,id:e.dashboardUid}),this.dashboardUid=e.dashboardUid,this.dashboardTitle=e.dashboardTitle,this.folderUid=e.folderUid,this.folderTitle=e.folderTitle,this.text=e.dashboardTitle}formatForLLM(e){return{type:"dashboard",codeElementIds:e,data:{name:this.dashboardTitle,dashboardUid:this.dashboardUid,dashboardTitle:this.dashboardTitle,folderUid:this.folderUid,folderTitle:this.folderTitle,text:this.text}}}}class o extends r{constructor(e){super({...e,id:e.folderUid}),this.text="",this.folderUid=e.folderUid,this.folderTitle=e.folderTitle,this.text=e.folderTitle}formatForLLM(e){return{type:"dashboard_folder",codeElementIds:e,data:{name:this.folderTitle,folderUid:this.folderUid,folderTitle:this.folderTitle,text:this.text}}}}class c extends r{constructor(e){super({...e,id:e.datasourceUid}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.datasourceName=e.datasourceName,this.img=e.img,this.text=e.datasourceName}formatForLLM(e){return{type:"datasource",codeElementIds:e,data:{name:this.datasourceName,uid:this.datasourceUid,type:this.datasourceType,text:this.text,img:this.img}}}}class u extends r{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}`}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.datasourceName=e.datasourceName,this.labelName=e.labelName,this.text=e.labelName,this.img=e.img}formatForLLM(e){return{type:"label_name",codeElementIds:e,data:{name:this.labelName,datasourceUid:this.datasourceUid,datasourceType:this.datasourceType,datasourceName:this.datasourceName,labelName:this.labelName,img:this.img,text:this.text}}}}class l extends r{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}-${e.labelValue}`}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.datasourceName=e.datasourceName,this.labelName=e.labelName,this.labelValue=e.labelValue,this.text=e.labelValue,this.img=e.img}formatForLLM(e){return{type:"label_value",codeElementIds:e,data:{name:this.labelValue,datasourceUid:this.datasourceUid,datasourceType:this.datasourceType,datasourceName:this.datasourceName,labelName:this.labelName,labelValue:this.labelValue,text:this.text,img:this.img}}}}function d(e){var t,n,r,a,i;const o=(0,s.getDataSourceSrv)().getInstanceSettings(e);return{datasourceType:null!==(t=null==o?void 0:o.type)&&void 0!==t?t:"unknown",datasourceName:null!==(n=null==o?void 0:o.name)&&void 0!==n?n:e,img:null===(i=null===(a=null===(r=null==o?void 0:o.meta)||void 0===r?void 0:r.info)||void 0===a?void 0:a.logos)||void 0===i?void 0:i.small}}const f={datasource:"database",label_name:"database",label_value:"database",dashboard:"dashboard",dashboard_folder:"folder",unknown:"circle-mono",structured:"gf-grid"};function p(e,t){var n,s,p;const h=function(e,t){switch(e){case"datasource":return new c({...t,...d(t.datasourceUid)});case"label_name":return new u({...t,...d(t.datasourceUid)});case"label_value":return new l({...t,...d(t.datasourceUid)});case"dashboard":return new i(t);case"dashboard_folder":return new o(t);case"structured":return new a(t);case"unknown":return new r(t);default:return console.error(`Unknown context type: ${e}`),new r(t)}}(e,t),m=null!==(n=t.title)&&void 0!==n?n:function(e){var t;return e instanceof a?e.formatForLLM().data.name:null!==(t=e.text)&&void 0!==t?t:"Given Context"}(h),v=null!==(s=t.img)&&void 0!==s?s:function(e){if("img"in e)return e.img}(h);return{node:{id:h.id,name:m,img:v,icon:null!==(p=t.icon)&&void 0!==p?p:f[e],navigable:!1,selectable:!0,data:h},occurrences:[]}}const h=require("react");var m=e.n(h);const v=[],g="grafana-assistant:page-context-sync",b="grafana-assistant:page-context-update",y="grafana-assistant:page-context-remove",x="grafana-assistant:location-changed";let w=!1;function k(e,t){const n=v.findIndex((t=>{return n=t.urlPattern,r=e,"string"==typeof n&&"string"==typeof r?n===r:n instanceof RegExp&&r instanceof RegExp&&n.source===r.source&&n.flags===r.flags;var n,r}));let r;-1!==n?(r=v[n],r.context=[...t]):(r={id:`page-context-${Date.now()}-${Math.random().toString(36).slice(2,11)}`,urlPattern:e,context:[...t]},v.push(r)),window.dispatchEvent(new CustomEvent(b,{detail:r})),window.dispatchEvent(new CustomEvent(g,{detail:{registry:v}}));const a=e=>{const t=v.findIndex((e=>e.id===r.id));-1!==t&&(v[t].context=[...e],window.dispatchEvent(new CustomEvent(b,{detail:v[t]})))};return a.unregister=()=>{const e=v.findIndex((e=>e.id===r.id));-1!==e&&(v.splice(e,1),window.dispatchEvent(new CustomEvent(y,{detail:{id:r.id}})))},a}function E(e,t=[]){const n=(0,h.useRef)(void 0),r=(0,h.useRef)(t);return r.current=t,(0,h.useEffect)((()=>(n.current=k(e,r.current),()=>{var e;null===(e=n.current)||void 0===e||e.unregister()})),[e]),(0,h.useEffect)((()=>{n.current&&n.current(t)}),[t]),(0,h.useCallback)((e=>{var t;null===(t=n.current)||void 0===t||t.call(n,e)}),[])}function A(e={allowQuestions:!1}){const[t,n]=(0,h.useState)([]),r=(0,s.useLocationService)(),a=(0,h.useRef)("");return(0,h.useEffect)((()=>{const e=()=>{const e=function(e,t){if(!e)return[];const n=[];for(const r of t)C(e,r.urlPattern)&&n.push(...r.context);return n}(r.getLocation().pathname,v);n(e)},t=()=>{e()},s=t=>{var n;const a=null===(n=t.detail)||void 0===n?void 0:n.pathname;a&&a===r.getLocation().pathname&&e()},i=r.getLocationObservable().subscribe((t=>{const n=t.pathname;n!==a.current&&(a.current=n,function(e){window.dispatchEvent(new CustomEvent(x,{detail:{pathname:e}}))}(n),e())}));return e(),window.addEventListener(g,t),window.addEventListener(b,t),window.addEventListener(y,t),window.addEventListener(x,s),()=>{i.unsubscribe(),window.removeEventListener(g,t),window.removeEventListener(b,t),window.removeEventListener(y,t),window.removeEventListener(x,s)}}),[r]),e.allowQuestions?t:t.filter((e=>{var t;return"question"!==(null===(t=e.node.data)||void 0===t?void 0:t.type)}))}function C(e,t){if(t instanceof RegExp)return t.test(e);if("string"==typeof t){const n=t.replace(/\*\*/g,"\0DOUBLE_STAR\0").replace(/\*/g,"[^/]*").replace(/\u0000DOUBLE_STAR\u0000/g,".*").replace(/\?/g,".");return new RegExp(`^${n}$`).test(e)}return!1}function S(e,t){const n=e=>e.map(((e,t)=>({node:{id:`question-${t}`,name:e.prompt,navigable:!1,selectable:!0,icon:"question-circle",data:{type:"question",prompt:e.prompt,context:e.context||[]}},occurrences:[]}))),r=k(e,n(t)),a=e=>{r(n(e))};return a.unregister=r.unregister,a}function $(e,t=[]){const n=e=>e.map(((e,t)=>({node:{id:`question-${t}`,name:e.prompt,navigable:!1,selectable:!0,icon:"question-circle",data:{type:"question",prompt:e.prompt,context:e.context||[]}},occurrences:[]}))),r=E(e,n(t));return e=>{r(n(e))}}function N(){const e=A({allowQuestions:!0});return L(e)}w||(window.addEventListener(g,(e=>{var t;const n=null===(t=e.detail)||void 0===t?void 0:t.registry;if(n){const e=new Set(v.map((e=>e.id))),t=n.filter((t=>!e.has(t.id)));v.push(...t)}})),window.addEventListener(b,(e=>{const t=e.detail;if(t){const e=v.findIndex((e=>e.id===t.id));-1!==e?v[e]=t:v.push(t)}})),window.addEventListener(y,(e=>{var t;const n=null===(t=e.detail)||void 0===t?void 0:t.id;if(n){const e=v.findIndex((e=>e.id===n));-1!==e&&v.splice(e,1)}})),w=!0);const L=e=>e.filter((e=>{var t;return"question"===(null===(t=e.node.data)||void 0===t?void 0:t.type)})).map((e=>{var t,n;return{prompt:(null===(t=e.node.data)||void 0===t?void 0:t.prompt)||e.node.name,context:(null===(n=e.node.data)||void 0===n?void 0:n.context)||[]}})),T="grafana-assistant-app/callback/v0-alpha";function U(e,t){return{namespace:e,functions:t}}function _(e){return{title:"callback",targets:[T],fn:()=>e.map((e=>({namespace:e.namespace,functions:e.functions})))}}const I=require("rxjs");function O(){if(!s.getObservablePluginLinks)return(0,I.of)(!1);return(0,s.getObservablePluginLinks)({extensionPointId:"grafana/extension-sidebar/v0-alpha"}).pipe((0,I.map)((e=>e.some((e=>"grafana-assistant-app"===e.pluginId&&"Grafana Assistant"===e.title)))))}const P=require("@grafana/data");class R extends P.BusEventWithPayload{}R.type="open-extension-sidebar";class M extends P.BusEventBase{}function j(e){var t,n;(0,s.reportInteraction)("grafana_assistant_app_opened_sidebar",{from:e.origin,prompt:null!==(t=e.prompt)&&void 0!==t?t:""}),function(e,t,n){const r=new R({pluginId:"grafana-assistant-app",componentTitle:"Grafana Assistant",props:n});(0,s.getAppEvents)().publish(r)}(0,0,{initialPrompt:e.prompt,initialContext:e.context,initialAutoSend:null===(n=e.autoSend)||void 0===n||n})}function q(){!function(){const e=new M;(0,s.getAppEvents)().publish(e)}()}function D(){const[e,t]=(0,h.useState)(!1);return(0,h.useEffect)((()=>{const e=O().subscribe((e=>t(e)));return()=>{e.unsubscribe()}}),[]),[e,e?j:void 0,e?q:void 0]}M.type="close-extension-sidebar";const F=require("@grafana/ui");var z=function(){function e(e){var t=this;this._insertTag=function(e){var n;n=0===t.tags.length?t.insertionPoint?t.insertionPoint.nextSibling:t.prepend?t.container.firstChild:t.before:t.tags[t.tags.length-1].nextSibling,t.container.insertBefore(e,n),t.tags.push(e)},this.isSpeedy=void 0===e.speedy||e.speedy,this.tags=[],this.ctr=0,this.nonce=e.nonce,this.key=e.key,this.container=e.container,this.prepend=e.prepend,this.insertionPoint=e.insertionPoint,this.before=null}var t=e.prototype;return t.hydrate=function(e){e.forEach(this._insertTag)},t.insert=function(e){this.ctr%(this.isSpeedy?65e3:1)==0&&this._insertTag(function(e){var t=document.createElement("style");return t.setAttribute("data-emotion",e.key),void 0!==e.nonce&&t.setAttribute("nonce",e.nonce),t.appendChild(document.createTextNode("")),t.setAttribute("data-s",""),t}(this));var t=this.tags[this.tags.length-1];if(this.isSpeedy){var n=function(e){if(e.sheet)return e.sheet;for(var t=0;t<document.styleSheets.length;t++)if(document.styleSheets[t].ownerNode===e)return document.styleSheets[t]}(t);try{n.insertRule(e,n.cssRules.length)}catch(e){}}else t.appendChild(document.createTextNode(e));this.ctr++},t.flush=function(){this.tags.forEach((function(e){var t;return null==(t=e.parentNode)?void 0:t.removeChild(e)})),this.tags=[],this.ctr=0},e}(),G=Math.abs,B=String.fromCharCode,V=Object.assign;function Q(e){return e.trim()}function W(e,t,n){return e.replace(t,n)}function H(e,t){return e.indexOf(t)}function J(e,t){return 0|e.charCodeAt(t)}function K(e,t,n){return e.slice(t,n)}function X(e){return e.length}function Z(e){return e.length}function Y(e,t){return t.push(e),e}var ee=1,te=1,ne=0,re=0,ae=0,se="";function ie(e,t,n,r,a,s,i){return{value:e,root:t,parent:n,type:r,props:a,children:s,line:ee,column:te,length:i,return:""}}function oe(e,t){return V(ie("",null,null,"",null,null,0),e,{length:-e.length},t)}function ce(){return ae=re>0?J(se,--re):0,te--,10===ae&&(te=1,ee--),ae}function ue(){return ae=re<ne?J(se,re++):0,te++,10===ae&&(te=1,ee++),ae}function le(){return J(se,re)}function de(){return re}function fe(e,t){return K(se,e,t)}function pe(e){switch(e){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function he(e){return ee=te=1,ne=X(se=e),re=0,[]}function me(e){return se="",e}function ve(e){return Q(fe(re-1,ye(91===e?e+2:40===e?e+1:e)))}function ge(e){for(;(ae=le())&&ae<33;)ue();return pe(e)>2||pe(ae)>3?"":" "}function be(e,t){for(;--t&&ue()&&!(ae<48||ae>102||ae>57&&ae<65||ae>70&&ae<97););return fe(e,de()+(t<6&&32==le()&&32==ue()))}function ye(e){for(;ue();)switch(ae){case e:return re;case 34:case 39:34!==e&&39!==e&&ye(ae);break;case 40:41===e&&ye(e);break;case 92:ue()}return re}function xe(e,t){for(;ue()&&e+ae!==57&&(e+ae!==84||47!==le()););return"/*"+fe(t,re-1)+"*"+B(47===e?e:ue())}function we(e){for(;!pe(le());)ue();return fe(e,re)}var ke="-ms-",Ee="-moz-",Ae="-webkit-",Ce="comm",Se="rule",$e="decl",Ne="@keyframes";function Le(e,t){for(var n="",r=Z(e),a=0;a<r;a++)n+=t(e[a],a,e,t)||"";return n}function Te(e,t,n,r){switch(e.type){case"@layer":if(e.children.length)break;case"@import":case $e:return e.return=e.return||e.value;case Ce:return"";case Ne:return e.return=e.value+"{"+Le(e.children,r)+"}";case Se:e.value=e.props.join(",")}return X(n=Le(e.children,r))?e.return=e.value+"{"+n+"}":""}function Ue(e){return me(_e("",null,null,null,[""],e=he(e),0,[0],e))}function _e(e,t,n,r,a,s,i,o,c){for(var u=0,l=0,d=i,f=0,p=0,h=0,m=1,v=1,g=1,b=0,y="",x=a,w=s,k=r,E=y;v;)switch(h=b,b=ue()){case 40:if(108!=h&&58==J(E,d-1)){-1!=H(E+=W(ve(b),"&","&\f"),"&\f")&&(g=-1);break}case 34:case 39:case 91:E+=ve(b);break;case 9:case 10:case 13:case 32:E+=ge(h);break;case 92:E+=be(de()-1,7);continue;case 47:switch(le()){case 42:case 47:Y(Oe(xe(ue(),de()),t,n),c);break;default:E+="/"}break;case 123*m:o[u++]=X(E)*g;case 125*m:case 59:case 0:switch(b){case 0:case 125:v=0;case 59+l:-1==g&&(E=W(E,/\f/g,"")),p>0&&X(E)-d&&Y(p>32?Pe(E+";",r,n,d-1):Pe(W(E," ","")+";",r,n,d-2),c);break;case 59:E+=";";default:if(Y(k=Ie(E,t,n,u,l,a,o,y,x=[],w=[],d),s),123===b)if(0===l)_e(E,t,k,k,x,s,d,o,w);else switch(99===f&&110===J(E,3)?100:f){case 100:case 108:case 109:case 115:_e(e,k,k,r&&Y(Ie(e,k,k,0,0,a,o,y,a,x=[],d),w),a,w,d,o,r?x:w);break;default:_e(E,k,k,k,[""],w,0,o,w)}}u=l=p=0,m=g=1,y=E="",d=i;break;case 58:d=1+X(E),p=h;default:if(m<1)if(123==b)--m;else if(125==b&&0==m++&&125==ce())continue;switch(E+=B(b),b*m){case 38:g=l>0?1:(E+="\f",-1);break;case 44:o[u++]=(X(E)-1)*g,g=1;break;case 64:45===le()&&(E+=ve(ue())),f=le(),l=d=X(y=E+=we(de())),b++;break;case 45:45===h&&2==X(E)&&(m=0)}}return s}function Ie(e,t,n,r,a,s,i,o,c,u,l){for(var d=a-1,f=0===a?s:[""],p=Z(f),h=0,m=0,v=0;h<r;++h)for(var g=0,b=K(e,d+1,d=G(m=i[h])),y=e;g<p;++g)(y=Q(m>0?f[g]+" "+b:W(b,/&\f/g,f[g])))&&(c[v++]=y);return ie(e,t,n,0===a?Se:o,c,u,l)}function Oe(e,t,n){return ie(e,t,n,Ce,B(ae),K(e,2,-2),0)}function Pe(e,t,n,r){return ie(e,t,n,$e,K(e,0,r),K(e,r+1,-1),r)}var Re=function(e,t,n){for(var r=0,a=0;r=a,a=le(),38===r&&12===a&&(t[n]=1),!pe(a);)ue();return fe(e,re)},Me=new WeakMap,je=function(e){if("rule"===e.type&&e.parent&&!(e.length<1)){for(var t=e.value,n=e.parent,r=e.column===n.column&&e.line===n.line;"rule"!==n.type;)if(!(n=n.parent))return;if((1!==e.props.length||58===t.charCodeAt(0)||Me.get(n))&&!r){Me.set(e,!0);for(var a=[],s=function(e,t){return me(function(e,t){var n=-1,r=44;do{switch(pe(r)){case 0:38===r&&12===le()&&(t[n]=1),e[n]+=Re(re-1,t,n);break;case 2:e[n]+=ve(r);break;case 4:if(44===r){e[++n]=58===le()?"&\f":"",t[n]=e[n].length;break}default:e[n]+=B(r)}}while(r=ue());return e}(he(e),t))}(t,a),i=n.props,o=0,c=0;o<s.length;o++)for(var u=0;u<i.length;u++,c++)e.props[c]=a[o]?s[o].replace(/&\f/g,i[u]):i[u]+" "+s[o]}}},qe=function(e){if("decl"===e.type){var t=e.value;108===t.charCodeAt(0)&&98===t.charCodeAt(2)&&(e.return="",e.value="")}};function De(e,t){switch(function(e,t){return 45^J(e,0)?(((t<<2^J(e,0))<<2^J(e,1))<<2^J(e,2))<<2^J(e,3):0}(e,t)){case 5103:return Ae+"print-"+e+e;case 5737:case 4201:case 3177:case 3433:case 1641:case 4457:case 2921:case 5572:case 6356:case 5844:case 3191:case 6645:case 3005:case 6391:case 5879:case 5623:case 6135:case 4599:case 4855:case 4215:case 6389:case 5109:case 5365:case 5621:case 3829:return Ae+e+e;case 5349:case 4246:case 4810:case 6968:case 2756:return Ae+e+Ee+e+ke+e+e;case 6828:case 4268:return Ae+e+ke+e+e;case 6165:return Ae+e+ke+"flex-"+e+e;case 5187:return Ae+e+W(e,/(\w+).+(:[^]+)/,Ae+"box-$1$2"+ke+"flex-$1$2")+e;case 5443:return Ae+e+ke+"flex-item-"+W(e,/flex-|-self/,"")+e;case 4675:return Ae+e+ke+"flex-line-pack"+W(e,/align-content|flex-|-self/,"")+e;case 5548:return Ae+e+ke+W(e,"shrink","negative")+e;case 5292:return Ae+e+ke+W(e,"basis","preferred-size")+e;case 6060:return Ae+"box-"+W(e,"-grow","")+Ae+e+ke+W(e,"grow","positive")+e;case 4554:return Ae+W(e,/([^-])(transform)/g,"$1"+Ae+"$2")+e;case 6187:return W(W(W(e,/(zoom-|grab)/,Ae+"$1"),/(image-set)/,Ae+"$1"),e,"")+e;case 5495:case 3959:return W(e,/(image-set\([^]*)/,Ae+"$1$`$1");case 4968:return W(W(e,/(.+:)(flex-)?(.*)/,Ae+"box-pack:$3"+ke+"flex-pack:$3"),/s.+-b[^;]+/,"justify")+Ae+e+e;case 4095:case 3583:case 4068:case 2532:return W(e,/(.+)-inline(.+)/,Ae+"$1$2")+e;case 8116:case 7059:case 5753:case 5535:case 5445:case 5701:case 4933:case 4677:case 5533:case 5789:case 5021:case 4765:if(X(e)-1-t>6)switch(J(e,t+1)){case 109:if(45!==J(e,t+4))break;case 102:return W(e,/(.+:)(.+)-([^]+)/,"$1"+Ae+"$2-$3$1"+Ee+(108==J(e,t+3)?"$3":"$2-$3"))+e;case 115:return~H(e,"stretch")?De(W(e,"stretch","fill-available"),t)+e:e}break;case 4949:if(115!==J(e,t+1))break;case 6444:switch(J(e,X(e)-3-(~H(e,"!important")&&10))){case 107:return W(e,":",":"+Ae)+e;case 101:return W(e,/(.+:)([^;!]+)(;|!.+)?/,"$1"+Ae+(45===J(e,14)?"inline-":"")+"box$3$1"+Ae+"$2$3$1"+ke+"$2box$3")+e}break;case 5936:switch(J(e,t+11)){case 114:return Ae+e+ke+W(e,/[svh]\w+-[tblr]{2}/,"tb")+e;case 108:return Ae+e+ke+W(e,/[svh]\w+-[tblr]{2}/,"tb-rl")+e;case 45:return Ae+e+ke+W(e,/[svh]\w+-[tblr]{2}/,"lr")+e}return Ae+e+ke+e+e}return e}var Fe=[function(e,t,n,r){if(e.length>-1&&!e.return)switch(e.type){case $e:e.return=De(e.value,e.length);break;case Ne:return Le([oe(e,{value:W(e.value,"@","@"+Ae)})],r);case Se:if(e.length)return function(e,t){return e.map(t).join("")}(e.props,(function(t){switch(function(e){return(e=/(::plac\w+|:read-\w+)/.exec(e))?e[0]:e}(t)){case":read-only":case":read-write":return Le([oe(e,{props:[W(t,/:(read-\w+)/,":-moz-$1")]})],r);case"::placeholder":return Le([oe(e,{props:[W(t,/:(plac\w+)/,":"+Ae+"input-$1")]}),oe(e,{props:[W(t,/:(plac\w+)/,":-moz-$1")]}),oe(e,{props:[W(t,/:(plac\w+)/,ke+"input-$1")]})],r)}return""}))}}],ze={animationIterationCount:1,aspectRatio:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,scale:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1};function Ge(e){var t=Object.create(null);return function(n){return void 0===t[n]&&(t[n]=e(n)),t[n]}}var Be=/[A-Z]|^ms/g,Ve=/_EMO_([^_]+?)_([^]*?)_EMO_/g,Qe=function(e){return 45===e.charCodeAt(1)},We=function(e){return null!=e&&"boolean"!=typeof e},He=Ge((function(e){return Qe(e)?e:e.replace(Be,"-$&").toLowerCase()})),Je=function(e,t){switch(e){case"animation":case"animationName":if("string"==typeof t)return t.replace(Ve,(function(e,t,n){return Xe={name:t,styles:n,next:Xe},t}))}return 1===ze[e]||Qe(e)||"number"!=typeof t||0===t?t:t+"px"};function Ke(e,t,n){if(null==n)return"";var r=n;if(void 0!==r.__emotion_styles)return r;switch(typeof n){case"boolean":return"";case"object":var a=n;if(1===a.anim)return Xe={name:a.name,styles:a.styles,next:Xe},a.name;var s=n;if(void 0!==s.styles){var i=s.next;if(void 0!==i)for(;void 0!==i;)Xe={name:i.name,styles:i.styles,next:Xe},i=i.next;return s.styles+";"}return function(e,t,n){var r="";if(Array.isArray(n))for(var a=0;a<n.length;a++)r+=Ke(e,t,n[a])+";";else for(var s in n){var i=n[s];if("object"!=typeof i){var o=i;null!=t&&void 0!==t[o]?r+=s+"{"+t[o]+"}":We(o)&&(r+=He(s)+":"+Je(s,o)+";")}else if(!Array.isArray(i)||"string"!=typeof i[0]||null!=t&&void 0!==t[i[0]]){var c=Ke(e,t,i);switch(s){case"animation":case"animationName":r+=He(s)+":"+c+";";break;default:r+=s+"{"+c+"}"}}else for(var u=0;u<i.length;u++)We(i[u])&&(r+=He(s)+":"+Je(s,i[u])+";")}return r}(e,t,n);case"function":if(void 0!==e){var o=Xe,c=n(e);return Xe=o,Ke(e,t,c)}}var u=n;if(null==t)return u;var l=t[u];return void 0!==l?l:u}var Xe,Ze=/label:\s*([^\s;{]+)\s*(;|$)/g;function Ye(e,t,n){if(1===e.length&&"object"==typeof e[0]&&null!==e[0]&&void 0!==e[0].styles)return e[0];var r=!0,a="";Xe=void 0;var s=e[0];null==s||void 0===s.raw?(r=!1,a+=Ke(n,t,s)):a+=s[0];for(var i=1;i<e.length;i++)a+=Ke(n,t,e[i]),r&&(a+=s[i]);Ze.lastIndex=0;for(var o,c="";null!==(o=Ze.exec(a));)c+="-"+o[1];var u=function(e){for(var t,n=0,r=0,a=e.length;a>=4;++r,a-=4)t=1540483477*(65535&(t=255&e.charCodeAt(r)|(255&e.charCodeAt(++r))<<8|(255&e.charCodeAt(++r))<<16|(255&e.charCodeAt(++r))<<24))+(59797*(t>>>16)<<16),n=1540483477*(65535&(t^=t>>>24))+(59797*(t>>>16)<<16)^1540483477*(65535&n)+(59797*(n>>>16)<<16);switch(a){case 3:n^=(255&e.charCodeAt(r+2))<<16;case 2:n^=(255&e.charCodeAt(r+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(r)))+(59797*(n>>>16)<<16)}return(((n=1540483477*(65535&(n^=n>>>13))+(59797*(n>>>16)<<16))^n>>>15)>>>0).toString(36)}(a)+c;return{name:u,styles:a,next:Xe}}function et(e,t,n){var r="";return n.split(" ").forEach((function(n){void 0!==e[n]?t.push(e[n]+";"):n&&(r+=n+" ")})),r}function tt(e,t){if(void 0===e.inserted[t.name])return e.insert("",t,e.sheet,!0)}function nt(e,t,n){var r=[],a=et(e,r,n);return r.length<2?n:a+t(r)}var rt=function e(t){for(var n="",r=0;r<t.length;r++){var a=t[r];if(null!=a){var s=void 0;switch(typeof a){case"boolean":break;case"object":if(Array.isArray(a))s=e(a);else for(var i in s="",a)a[i]&&i&&(s&&(s+=" "),s+=i);break;default:s=a}s&&(n&&(n+=" "),n+=s)}}return n};var at=function(e){var t=function(e){var t=e.key;if("css"===t){var n=document.querySelectorAll("style[data-emotion]:not([data-s])");Array.prototype.forEach.call(n,(function(e){-1!==e.getAttribute("data-emotion").indexOf(" ")&&(document.head.appendChild(e),e.setAttribute("data-s",""))}))}var r,a,s=e.stylisPlugins||Fe,i={},o=[];r=e.container||document.head,Array.prototype.forEach.call(document.querySelectorAll('style[data-emotion^="'+t+' "]'),(function(e){for(var t=e.getAttribute("data-emotion").split(" "),n=1;n<t.length;n++)i[t[n]]=!0;o.push(e)}));var c,u,l,d,f=[Te,(d=function(e){c.insert(e)},function(e){e.root||(e=e.return)&&d(e)})],p=(u=[je,qe].concat(s,f),l=Z(u),function(e,t,n,r){for(var a="",s=0;s<l;s++)a+=u[s](e,t,n,r)||"";return a});a=function(e,t,n,r){c=n,Le(Ue(e?e+"{"+t.styles+"}":t.styles),p),r&&(h.inserted[t.name]=!0)};var h={key:t,sheet:new z({key:t,container:r,nonce:e.nonce,speedy:e.speedy,prepend:e.prepend,insertionPoint:e.insertionPoint}),nonce:e.nonce,inserted:i,registered:{},insert:a};return h.sheet.hydrate(o),h}(e);t.sheet.speedy=function(e){this.isSpeedy=e},t.compat=!0;var n=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];var a=Ye(n,t.registered,void 0);return function(e,t){!function(e,t){var n=e.key+"-"+t.name;void 0===e.registered[n]&&(e.registered[n]=t.styles)}(e,t);var n=e.key+"-"+t.name;if(void 0===e.inserted[t.name]){var r=t;do{e.insert(t===r?"."+n:"",r,e.sheet,!0),r=r.next}while(void 0!==r)}}(t,a),t.key+"-"+a.name};return{css:n,cx:function(){for(var e=arguments.length,r=new Array(e),a=0;a<e;a++)r[a]=arguments[a];return nt(t.registered,n,rt(r))},injectGlobal:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];var a=Ye(n,t.registered);tt(t,a)},keyframes:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];var a=Ye(n,t.registered),s="animation-"+a.name;return tt(t,{name:a.name,styles:"@keyframes "+s+"{"+a.styles+"}"}),s},hydrate:function(e){e.forEach((function(e){t.inserted[e]=!0}))},flush:function(){t.registered={},t.inserted={},t.sheet.flush()},sheet:t.sheet,cache:t,getRegisteredStyles:et.bind(null,t.registered),merge:nt.bind(null,t.registered,n)}}({key:"css"}),st=(at.flush,at.hydrate,at.cx,at.merge,at.getRegisteredStyles,at.injectGlobal,at.keyframes,at.css);function it({prompt:e,origin:t,context:n,autoSend:r=!0,title:a="Analyze with Assistant",size:s="sm",iconOnlyButton:i=!1}){const o=(0,F.useStyles2)(ot),[c,u]=D();return c&&u?m().createElement(m().Fragment,null,i?m().createElement(F.IconButton,{name:"ai-sparkle",onClick:()=>u({prompt:e,context:n,autoSend:r,origin:t}),variant:"secondary",size:s,"aria-label":a,className:o.icon,tooltip:a}):m().createElement(F.Button,{icon:"ai-sparkle",onClick:()=>u({prompt:e,context:n,autoSend:r,origin:t}),variant:"secondary",fill:"solid",size:s,title:a,"aria-label":a,className:o.button},a)):null}at.sheet,at.cache;const ot=e=>({button:st({label:"assistant-button",border:"1px solid transparent",borderImage:"linear-gradient(90deg, rgb(168, 85, 247), rgb(249, 115, 22)) 1"}),icon:st({label:"assistant-icon",border:"1px solid transparent",backgroundClip:"padding-box",padding:e.spacing(.5),"&:hover":{borderImage:"linear-gradient(90deg, rgb(168, 85, 247), rgb(249, 115, 22)) 1 !important",border:"1px solid transparent",backgroundClip:"padding-box"}})});module.exports=t})();
package/dist/sidebar.d.ts CHANGED
@@ -1,14 +1,18 @@
1
1
  import { ChatContextItem } from './context/types';
2
2
  export type OpenAssistantProps = {
3
+ origin: string;
3
4
  prompt?: string;
4
5
  context?: ChatContextItem[];
6
+ autoSend?: boolean;
5
7
  };
6
8
  /**
7
9
  * Open the Grafana Assistant sidebar with a given initial prompt.
8
10
  *
9
11
  * @param props - The props to pass to the assistant.
12
+ * @param props.origin - The origin of the request that opened the assistant. This is used to track the source of the request. Should be a static string that helps identify the source of the request.
10
13
  * @param props.prompt - The initial prompt to display in the assistant.
11
14
  * @param props.context - The initial context to display in the assistant. Created with `createContext`.
15
+ * @param props.autoSend - Whether to automatically send the initial prompt. When true, opens a chat and sends the initial prompt right away. When false, opens chat and updates user message without sending it. Defaults to true.
12
16
  */
13
17
  export declare function openAssistant(props: OpenAssistantProps): void;
14
18
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/assistant",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "Type definitions and helper functions for Grafana Assistant",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",