@grafana/assistant 0.0.1-alpha.2 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -69
- package/dist/functions.d.ts +11 -0
- package/dist/index.d.ts +2 -12
- package/dist/index.js +1 -2
- package/dist/sidebar.d.ts +14 -0
- package/package.json +9 -4
- package/dist/dashboarding.d.ts +0 -23
- package/dist/dashboarding.js +0 -2
- package/dist/dashboarding.js.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @grafana/assistant
|
|
2
2
|
|
|
3
|
-
Type definitions for
|
|
3
|
+
Type definitions and utilities for integrating with the Grafana Assistant.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,109 +10,143 @@ npm install @grafana/assistant
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
### Opening the Assistant Sidebar
|
|
14
|
+
|
|
13
15
|
```typescript
|
|
14
|
-
import
|
|
16
|
+
import { openAssistant, closeAssistant } from '@grafana/assistant';
|
|
15
17
|
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// Open the assistant with an initial prompt
|
|
19
|
+
openAssistant({ prompt: 'Show me CPU usage over the last hour' });
|
|
20
|
+
|
|
21
|
+
// Open the assistant without an initial prompt
|
|
22
|
+
openAssistant({});
|
|
23
|
+
|
|
24
|
+
// Close the assistant
|
|
25
|
+
closeAssistant();
|
|
26
|
+
```
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
### Exposing Functions to the Assistant
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import {
|
|
32
|
+
getExposeAssistantFunctionsConfig,
|
|
33
|
+
newFunctionNamespace,
|
|
34
|
+
FunctionImplementation,
|
|
35
|
+
FunctionNamespace,
|
|
36
|
+
NamedFunctions
|
|
37
|
+
} from '@grafana/assistant';
|
|
38
|
+
|
|
39
|
+
// Define your functions
|
|
40
|
+
const myFunctions: NamedFunctions = {
|
|
41
|
+
getMetrics: (datasource: string) => {
|
|
42
|
+
return ['cpu_usage', 'memory_usage', 'disk_io'];
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
calculateAverage: (values: number[]) => {
|
|
46
|
+
return values.reduce((a, b) => a + b, 0) / values.length;
|
|
47
|
+
}
|
|
24
48
|
};
|
|
49
|
+
|
|
50
|
+
// Create a namespace for your functions
|
|
51
|
+
const namespace = newFunctionNamespace('myPlugin', myFunctions);
|
|
52
|
+
|
|
53
|
+
// Export the configuration for your plugin
|
|
54
|
+
export const getExtensionConfigs = () => [
|
|
55
|
+
getExposeAssistantFunctionsConfig([namespace])
|
|
56
|
+
];
|
|
25
57
|
```
|
|
26
58
|
|
|
27
|
-
##
|
|
59
|
+
## API Reference
|
|
28
60
|
|
|
29
|
-
###
|
|
61
|
+
### Sidebar Functions
|
|
30
62
|
|
|
31
|
-
|
|
63
|
+
#### `openAssistant(props: OpenAssistantProps): void`
|
|
64
|
+
|
|
65
|
+
Opens the Grafana Assistant sidebar.
|
|
66
|
+
|
|
67
|
+
**Parameters:**
|
|
68
|
+
- `props: OpenAssistantProps` - Configuration object
|
|
69
|
+
- `prompt?: string` - Optional initial prompt to display in the assistant
|
|
70
|
+
|
|
71
|
+
#### `closeAssistant(): void`
|
|
72
|
+
|
|
73
|
+
Closes the Grafana Assistant sidebar.
|
|
74
|
+
|
|
75
|
+
### Sidebar Types
|
|
76
|
+
|
|
77
|
+
#### `OpenAssistantProps`
|
|
32
78
|
|
|
33
79
|
```typescript
|
|
34
|
-
type
|
|
80
|
+
type OpenAssistantProps = {
|
|
81
|
+
prompt?: string;
|
|
82
|
+
};
|
|
35
83
|
```
|
|
36
84
|
|
|
37
|
-
|
|
38
|
-
- `pluginId: string` - The plugin ID of the function
|
|
39
|
-
- `namespace: string` - The namespace for the function
|
|
40
|
-
- `functionName: string` - The name of the function
|
|
41
|
-
- `functionImpl: FunctionImplementation` - The implementation of the function
|
|
85
|
+
Configuration object for opening the assistant.
|
|
42
86
|
|
|
43
|
-
###
|
|
87
|
+
### Function Extension Types
|
|
44
88
|
|
|
45
|
-
|
|
89
|
+
#### `CallbackFunction`
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
type CallbackFunction = () => FunctionNamespace[];
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
A function that returns an array of function namespaces.
|
|
96
|
+
|
|
97
|
+
#### `FunctionImplementation`
|
|
46
98
|
|
|
47
99
|
```typescript
|
|
48
100
|
type FunctionImplementation = (...args: any[]) => any;
|
|
49
101
|
```
|
|
50
102
|
|
|
51
|
-
|
|
103
|
+
A type for function implementations that can be exposed to the assistant.
|
|
52
104
|
|
|
53
|
-
|
|
105
|
+
#### `NamedFunctions`
|
|
54
106
|
|
|
55
107
|
```typescript
|
|
56
|
-
type
|
|
57
|
-
addPanel: (vizPanel: VizPanel) => void;
|
|
58
|
-
duplicatePanel: (vizPanel: VizPanel) => void;
|
|
59
|
-
copyPanel: (vizPanel: VizPanel) => void;
|
|
60
|
-
pastePanel: () => void;
|
|
61
|
-
removePanel: (panel: VizPanel) => void;
|
|
62
|
-
createNewPanel: () => void;
|
|
63
|
-
createNewRow: () => void;
|
|
64
|
-
onEnterEditMode: () => void;
|
|
65
|
-
openSaveDrawer: (options?: SaveDrawerOptions) => void;
|
|
66
|
-
onStarDashboard: () => void;
|
|
67
|
-
canEditDashboard: () => boolean;
|
|
68
|
-
exitEditMode: (options: ExitEditModeOptions) => void;
|
|
69
|
-
};
|
|
108
|
+
type NamedFunctions = Record<string, FunctionImplementation>;
|
|
70
109
|
```
|
|
71
110
|
|
|
72
|
-
|
|
111
|
+
A record of function names to their implementations.
|
|
73
112
|
|
|
74
|
-
|
|
113
|
+
#### `FunctionNamespace`
|
|
75
114
|
|
|
76
115
|
```typescript
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
116
|
+
type FunctionNamespace = {
|
|
117
|
+
namespace: string;
|
|
118
|
+
functions: NamedFunctions;
|
|
119
|
+
};
|
|
81
120
|
```
|
|
82
121
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
122
|
+
Groups functions under a namespace.
|
|
123
|
+
|
|
124
|
+
### Utility Functions
|
|
125
|
+
|
|
126
|
+
#### `newFunctionNamespace(namespace: string, functions: NamedFunctions): FunctionNamespace`
|
|
127
|
+
|
|
128
|
+
Creates a new function namespace.
|
|
129
|
+
|
|
130
|
+
**Parameters:**
|
|
131
|
+
- `namespace: string` - The namespace identifier
|
|
132
|
+
- `functions: NamedFunctions` - The functions to include in the namespace
|
|
133
|
+
|
|
134
|
+
#### `getExposeAssistantFunctionsConfig(namespaces: FunctionNamespace[]): PluginExtensionAddedFunctionConfig`
|
|
135
|
+
|
|
136
|
+
Creates a plugin extension configuration for exposing functions to the assistant.
|
|
137
|
+
|
|
138
|
+
**Parameters:**
|
|
139
|
+
- `namespaces: FunctionNamespace[]` - Array of function namespaces to expose
|
|
87
140
|
|
|
88
|
-
|
|
141
|
+
### Constants
|
|
89
142
|
|
|
90
|
-
|
|
143
|
+
#### `CALLBACK_EXTENSION_POINT`
|
|
91
144
|
|
|
92
145
|
```typescript
|
|
93
|
-
|
|
94
|
-
import type { DashboardOperations } from '@grafana/assistant';
|
|
95
|
-
|
|
96
|
-
// Retrieve a specific function from the registry
|
|
97
|
-
const onEnterEditMode = functionRegistry.getFunction<DashboardOperations['onEnterEditMode']>(
|
|
98
|
-
'grafana',
|
|
99
|
-
'dashboarding',
|
|
100
|
-
'onEnterEditMode'
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (!onEnterEditMode) {
|
|
104
|
-
throw new Error('onEnterEditMode function not found');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Use the retrieved function
|
|
108
|
-
onEnterEditMode();
|
|
146
|
+
const CALLBACK_EXTENSION_POINT = 'grafana-assistant-app/callback/v0-alpha';
|
|
109
147
|
```
|
|
110
148
|
|
|
111
|
-
|
|
112
|
-
1. Using `functionRegistry.getFunction()` to retrieve registered functions by plugin ID, namespace, and function name
|
|
113
|
-
2. Type-safe function retrieval using TypeScript generics
|
|
114
|
-
3. Null checking before using the function
|
|
115
|
-
4. Calling the retrieved function
|
|
149
|
+
The extension point ID for registering assistant functions.
|
|
116
150
|
|
|
117
151
|
## License
|
|
118
152
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PluginExtensionAddedFunctionConfig } from '@grafana/data';
|
|
2
|
+
export type CallbackFunction = () => FunctionNamespace[];
|
|
3
|
+
export type FunctionImplementation = (...args: any[]) => any;
|
|
4
|
+
export declare const CALLBACK_EXTENSION_POINT = "grafana-assistant-app/callback/v0-alpha";
|
|
5
|
+
export type NamedFunctions = Record<string, FunctionImplementation>;
|
|
6
|
+
export type FunctionNamespace = {
|
|
7
|
+
namespace: string;
|
|
8
|
+
functions: NamedFunctions;
|
|
9
|
+
};
|
|
10
|
+
export declare function newFunctionNamespace(namespace: string, functions: NamedFunctions): FunctionNamespace;
|
|
11
|
+
export declare function getExposeAssistantFunctionsConfig(namespaces: FunctionNamespace[]): PluginExtensionAddedFunctionConfig<() => FunctionNamespace[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
* Function signature for registering Assistant functions. These functions
|
|
4
|
-
* support the tools offered by the Assistant.
|
|
5
|
-
*
|
|
6
|
-
* @param pluginId - The plugin ID of the function
|
|
7
|
-
* @param namespace - The namespace for the function
|
|
8
|
-
* @param functionName - The name of the function
|
|
9
|
-
* @param functionImpl - The implementation of the function
|
|
10
|
-
*/
|
|
11
|
-
export type AddCallbackFunction = (pluginId: string, namespace: string, functionName: string, functionImpl: FunctionImplementation) => void;
|
|
12
|
-
export * from './dashboarding';
|
|
1
|
+
export * from './functions';
|
|
2
|
+
export * from './sidebar';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import*as t from"@grafana/data";import*as n from"@grafana/runtime";var a={d:(t,n)=>{for(var e in n)a.o(n,e)&&!a.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:n[e]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n)};const e="grafana-assistant-app/callback/v0-alpha";function s(t,n){return{namespace:t,functions:n}}function o(t){return{title:"callback",targets:[e],fn:()=>t.map(t=>({namespace:t.namespace,functions:t.functions}))}}const p=(r={BusEventBase:()=>t.BusEventBase,BusEventWithPayload:()=>t.BusEventWithPayload},i={},a.d(i,r),i);var r,i;const c=(t=>{var n={};return a.d(n,t),n})({getAppEvents:()=>n.getAppEvents});class u extends p.BusEventWithPayload{}u.type="open-extension-sidebar";class l extends p.BusEventBase{}function f(t){!function(t,n,a){const e=new u({pluginId:"grafana-assistant-app",componentTitle:"Grafana Assistant",props:a});(0,c.getAppEvents)().publish(e)}(0,0,{initialPrompt:t.prompt})}function v(){!function(){const t=new l;(0,c.getAppEvents)().publish(t)}()}l.type="close-extension-sidebar";export{e as CALLBACK_EXTENSION_POINT,v as closeAssistant,o as getExposeAssistantFunctionsConfig,s as newFunctionNamespace,f as openAssistant};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type OpenAssistantProps = {
|
|
2
|
+
prompt?: string;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Open the Grafana Assistant sidebar with a given initial prompt.
|
|
6
|
+
*
|
|
7
|
+
* @param props - The props to pass to the assistant.
|
|
8
|
+
* @param props.prompt - The initial prompt to display in the assistant.
|
|
9
|
+
*/
|
|
10
|
+
export declare function openAssistant(props: OpenAssistantProps): void;
|
|
11
|
+
/**
|
|
12
|
+
* Close the Grafana Assistant sidebar.
|
|
13
|
+
*/
|
|
14
|
+
export declare function closeAssistant(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/assistant",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Type definitions for Grafana Assistant functions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"prebuild": "rm -rf dist",
|
|
13
|
-
"build": "tsc",
|
|
13
|
+
"build": "webpack --config webpack.config.cjs --mode production && tsc --emitDeclarationOnly",
|
|
14
14
|
"clean": "rm -rf dist",
|
|
15
15
|
"prepublishOnly": "npm run clean && npm run build"
|
|
16
16
|
},
|
|
@@ -23,12 +23,17 @@
|
|
|
23
23
|
"author": "Grafana Labs",
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"typescript": "^5.0.0"
|
|
26
|
+
"typescript": "^5.0.0",
|
|
27
|
+
"webpack": "^5.0.0",
|
|
28
|
+
"webpack-cli": "^5.0.0",
|
|
29
|
+
"ts-loader": "^9.0.0"
|
|
27
30
|
},
|
|
28
31
|
"publishConfig": {
|
|
29
32
|
"access": "public"
|
|
30
33
|
},
|
|
31
34
|
"peerDependencies": {
|
|
32
|
-
"@grafana/scenes": ">=5.41.0"
|
|
35
|
+
"@grafana/scenes": ">=5.41.0",
|
|
36
|
+
"@grafana/runtime": ">=12.0.0",
|
|
37
|
+
"@grafana/data": ">=12.0.0"
|
|
33
38
|
}
|
|
34
39
|
}
|
package/dist/dashboarding.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { VizPanel } from '@grafana/scenes';
|
|
2
|
-
export type SaveDrawerOptions = {
|
|
3
|
-
saveAsCopy?: boolean;
|
|
4
|
-
onSaveSuccess?: () => void;
|
|
5
|
-
};
|
|
6
|
-
export type ExitEditModeOptions = {
|
|
7
|
-
skipConfirm: boolean;
|
|
8
|
-
restoreInitialState?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type DashboardOperations = {
|
|
11
|
-
addPanel: (vizPanel: VizPanel) => void;
|
|
12
|
-
duplicatePanel: (vizPanel: VizPanel) => void;
|
|
13
|
-
copyPanel: (vizPanel: VizPanel) => void;
|
|
14
|
-
pastePanel: () => void;
|
|
15
|
-
removePanel: (panel: VizPanel) => void;
|
|
16
|
-
createNewPanel: () => void;
|
|
17
|
-
createNewRow: () => void;
|
|
18
|
-
onEnterEditMode: () => void;
|
|
19
|
-
openSaveDrawer: (options?: SaveDrawerOptions) => void;
|
|
20
|
-
onStarDashboard: () => void;
|
|
21
|
-
canEditDashboard: () => boolean;
|
|
22
|
-
exitEditMode: (options: ExitEditModeOptions) => void;
|
|
23
|
-
};
|
package/dist/dashboarding.js
DELETED
package/dist/dashboarding.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dashboarding.js","sourceRoot":"","sources":["../src/dashboarding.ts"],"names":[],"mappings":""}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,cAAc,gBAAgB,CAAC"}
|