@grafana/assistant 0.0.9 → 0.0.10
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/context/base.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface StructuredNodeDataParams extends BaseParams {
|
|
|
14
14
|
export declare class NodeData {
|
|
15
15
|
params: NodeDataParams;
|
|
16
16
|
id: string;
|
|
17
|
+
text: string;
|
|
17
18
|
constructor(params: NodeDataParams);
|
|
18
19
|
formatForLLM(codeElementIds?: string[]): ContextItemData;
|
|
19
20
|
}
|
|
@@ -15,12 +15,14 @@ export declare class DashboardNodeData extends NodeData {
|
|
|
15
15
|
dashboardTitle: string;
|
|
16
16
|
folderUid?: string;
|
|
17
17
|
folderTitle?: string;
|
|
18
|
+
text: string;
|
|
18
19
|
constructor(params: CreateDashboardContextParams);
|
|
19
20
|
formatForLLM(codeElementIds?: string[]): ContextItemData;
|
|
20
21
|
}
|
|
21
22
|
export declare class FolderNodeData extends NodeData {
|
|
22
23
|
folderUid: string;
|
|
23
24
|
folderTitle: string;
|
|
25
|
+
text: string;
|
|
24
26
|
constructor(params: CreateFolderContextParams);
|
|
25
27
|
formatForLLM(codeElementIds?: string[]): ContextItemData;
|
|
26
28
|
}
|
|
@@ -9,6 +9,7 @@ export declare class DatasourceNodeData extends NodeData {
|
|
|
9
9
|
datasourceUid: string;
|
|
10
10
|
datasourceType: string;
|
|
11
11
|
datasourceName: string;
|
|
12
|
+
text: string;
|
|
12
13
|
constructor(params: CreateDatasourceContextParams);
|
|
13
14
|
formatForLLM(codeElementIds?: string[]): ContextItemData;
|
|
14
15
|
}
|
package/dist/context/label.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class LabelNameNodeData extends NodeData {
|
|
|
12
12
|
datasourceUid: string;
|
|
13
13
|
datasourceType: string;
|
|
14
14
|
labelName: string;
|
|
15
|
+
text: string;
|
|
15
16
|
constructor(params: CreateLabelNameContextParams);
|
|
16
17
|
formatForLLM(codeElementIds?: string[]): ContextItemData;
|
|
17
18
|
}
|
|
@@ -20,6 +21,7 @@ export declare class LabelValueNodeData extends NodeData {
|
|
|
20
21
|
datasourceType: string;
|
|
21
22
|
labelName: string;
|
|
22
23
|
labelValue: string;
|
|
24
|
+
text: string;
|
|
23
25
|
constructor(params: CreateLabelValueContextParams);
|
|
24
26
|
formatForLLM(codeElementIds?: string[]): ContextItemData;
|
|
25
27
|
}
|
package/dist/context/types.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { IconName } from '@grafana/ui';
|
|
2
|
-
export interface
|
|
3
|
-
name
|
|
2
|
+
export interface BaseItemData {
|
|
3
|
+
name: string;
|
|
4
|
+
text: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UnknownItemData extends BaseItemData {
|
|
4
7
|
}
|
|
5
8
|
export declare enum ItemDataType {
|
|
6
9
|
Unknown = "unknown",
|
|
@@ -26,13 +29,11 @@ export interface TreeNode {
|
|
|
26
29
|
icon?: IconName;
|
|
27
30
|
data?: any;
|
|
28
31
|
}
|
|
29
|
-
export interface DatasourceItemData {
|
|
30
|
-
name: string;
|
|
32
|
+
export interface DatasourceItemData extends BaseItemData {
|
|
31
33
|
uid: string;
|
|
32
34
|
type: string;
|
|
33
35
|
}
|
|
34
|
-
export interface LabelNameItemData {
|
|
35
|
-
name: string;
|
|
36
|
+
export interface LabelNameItemData extends BaseItemData {
|
|
36
37
|
datasourceUid: string;
|
|
37
38
|
datasourceType: string;
|
|
38
39
|
labelName: string;
|
|
@@ -40,15 +41,13 @@ export interface LabelNameItemData {
|
|
|
40
41
|
export interface LabelValueItemData extends LabelNameItemData {
|
|
41
42
|
labelValue: string;
|
|
42
43
|
}
|
|
43
|
-
export interface DashboardItemData {
|
|
44
|
-
name: string;
|
|
44
|
+
export interface DashboardItemData extends BaseItemData {
|
|
45
45
|
dashboardUid: string;
|
|
46
46
|
dashboardTitle: string;
|
|
47
47
|
folderUid?: string;
|
|
48
48
|
folderTitle?: string;
|
|
49
49
|
}
|
|
50
|
-
export interface FolderItemData {
|
|
51
|
-
name: string;
|
|
50
|
+
export interface FolderItemData extends BaseItemData {
|
|
52
51
|
folderUid: string;
|
|
53
52
|
folderTitle: string;
|
|
54
53
|
}
|
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:()=>N,DashboardNodeData:()=>o,DatasourceNodeData:()=>
|
|
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:()=>N,DashboardNodeData:()=>o,DatasourceNodeData:()=>d,FolderNodeData:()=>i,ItemDataType:()=>e,LabelNameNodeData:()=>l,LabelValueNodeData:()=>c,StructuredNodeData:()=>r,closeAssistant:()=>V,createContext:()=>p,getExposeAssistantFunctionsConfig:()=>D,isAssistantAvailable:()=>S,newFunctionNamespace:()=>U,openAssistant:()=>A,providePageContext:()=>E,useAssistant:()=>M,usePageContext:()=>y}),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 c 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 u={[e.Datasource]:"database",[e.LabelName]:"database",[e.LabelValue]:"database",[e.Dashboard]:"dashboard",[e.DashboardFolder]:"folder",[e.Unknown]:"circle-mono",[e.Structured]:"gf-grid"};function h(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 p(e,t){var a,n;const p=function(e,t){switch(e){case"datasource":return new d(t);case"label_name":return new l(t);case"label_value":return new c(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:p.id,name:null!==(a=t.title)&&void 0!==a?a:h(e,t),icon:null!==(n=t.icon)&&void 0!==n?n:u[e],navigable:!1,selectable:!0,data:p},occurrences:[]}}const f=require("@grafana/runtime"),b=require("react"),m=[],v="grafana-assistant:page-context-sync",x="grafana-assistant:page-context-update",w="grafana-assistant:page-context-remove",g="grafana-assistant:location-changed";let L=!1;function E(e,t){const a=m.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=m[a],n.context=[...t]):(n={id:`page-context-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,urlPattern:e,context:[...t]},m.push(n)),window.dispatchEvent(new CustomEvent(x,{detail:n})),window.dispatchEvent(new CustomEvent(v,{detail:{registry:m}}));const s=e=>{const t=m.findIndex((e=>e.id===n.id));-1!==t&&(m[t].context=[...e],window.dispatchEvent(new CustomEvent(x,{detail:m[t]})))};return s.unregister=()=>{const e=m.findIndex((e=>e.id===n.id));-1!==e&&(m.splice(e,1),window.dispatchEvent(new CustomEvent(w,{detail:{id:n.id}})))},s}function y(){const[e,t]=(0,b.useState)([]),a=(0,f.useLocationService)(),n=(0,b.useRef)("");return(0,b.useEffect)((()=>{const e=()=>{const e=function(e,t){if(!e)return[];const a=[];for(const n of t)T(e,n.urlPattern)&&a.push(...n.context);return a}(a.getLocation().pathname,m);t(e)},s=()=>{e()},r=t=>{var n;const s=null===(n=t.detail)||void 0===n?void 0:n.pathname;s&&s===a.getLocation().pathname&&e()},o=a.getLocationObservable().subscribe((t=>{const a=t.pathname;a!==n.current&&(n.current=a,function(e){window.dispatchEvent(new CustomEvent(g,{detail:{pathname:e}}))}(a),e())}));return e(),window.addEventListener(v,s),window.addEventListener(x,s),window.addEventListener(w,s),window.addEventListener(g,r),()=>{o.unsubscribe(),window.removeEventListener(v,s),window.removeEventListener(x,s),window.removeEventListener(w,s),window.removeEventListener(g,r)}}),[a]),e}function T(e,t){if(t instanceof RegExp)return t.test(e);if("string"==typeof t){const a=t.replace(/\*\*/g,".*").replace(/\*/g,"[^/]*").replace(/\?/g,".");return new RegExp(`^${a}$`).test(e)}return!1}L||(window.addEventListener(v,(e=>{var t;const a=null===(t=e.detail)||void 0===t?void 0:t.registry;if(a){const e=new Set(m.map((e=>e.id))),t=a.filter((t=>!e.has(t.id)));m.push(...t)}})),window.addEventListener(x,(e=>{const t=e.detail;if(t){const e=m.findIndex((e=>e.id===t.id));-1!==e?m[e]=t:m.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=m.findIndex((e=>e.id===a));-1!==e&&m.splice(e,1)}})),L=!0);const N="grafana-assistant-app/callback/v0-alpha";function U(e,t){return{namespace:e,functions:t}}function D(e){return{title:"callback",targets:[N],fn:()=>e.map((e=>({namespace:e.namespace,functions:e.functions})))}}const I=require("rxjs");function S(){return(0,f.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 C=require("@grafana/data");class F extends C.BusEventWithPayload{}F.type="open-extension-sidebar";class P extends C.BusEventBase{}function A(e){!function(e,t,a){const n=new F({pluginId:"grafana-assistant-app",componentTitle:"Grafana Assistant",props:a});(0,f.getAppEvents)().publish(n)}(0,0,{initialPrompt:e.prompt,initialContext:e.context})}function V(){!function(){const e=new P;(0,f.getAppEvents)().publish(e)}()}function M(){const[e,t]=(0,b.useState)(!1);return(0,b.useEffect)((()=>{const e=S().subscribe((e=>t(e)));return()=>{e.unsubscribe()}}),[]),[e,e?A:void 0,e?V:void 0]}P.type="close-extension-sidebar",module.exports=a})();
|