@grafana/assistant 0.0.14 → 0.0.15

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.
@@ -12,5 +12,44 @@ type ContextTypeMap = {
12
12
  [ItemDataType.Structured]: StructuredNodeDataParams;
13
13
  [ItemDataType.Unknown]: NodeDataParams;
14
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
+ */
15
19
  export declare function createContext<T extends keyof ContextTypeMap>(type: T, params: ContextTypeMap[T]): ChatContextItem;
20
+ /**
21
+ * Creates a new chat context item that can be added to conversations.
22
+ *
23
+ * This function creates structured context items that provide additional information
24
+ * to the AI assistant during conversations. Context items can include:
25
+ * - Datasources (metrics, logs, traces)
26
+ * - Labels and their values
27
+ * - Dashboards and folders
28
+ * - Structured data objects
29
+ *
30
+ * The created context item includes display metadata (title, icon, image) and
31
+ * the underlying data that will be formatted and sent to the LLM when the
32
+ * context is included in a conversation.
33
+ *
34
+ * @param type - The type of context to create (Datasource, Label, Dashboard etc.)
35
+ * @param params - Type-specific parameters for creating the context item
36
+ * @returns A ChatContextItem that can be added to conversation context
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Create a context that will be passed into the function triggering an assistant open
41
+ * openAssistant({
42
+ * ...
43
+ * context: [
44
+ * createAssistantContext(ItemDataType.Datasource, {
45
+ * datasourceUid: datasource.uid,
46
+ * datasourceName: datasource.name,
47
+ * datasourceType: datasource.type,
48
+ * img: datasource.meta?.info?.logos?.small,
49
+ * }),
50
+ * ],
51
+ * });
52
+ * ```
53
+ */
54
+ export declare function createContextItem<T extends keyof ContextTypeMap>(type: T, params: ContextTypeMap[T]): ChatContextItem;
16
55
  export {};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { createContext, ChatContextItem, DashboardNodeData, DatasourceNodeData, FolderNodeData, ItemDataType, LabelNameNodeData, LabelValueNodeData, StructuredNodeData, TreeNode, providePageContext, PageContextRegistration, usePageContext, provideQuestions, useProvideQuestions, useQuestions, Question, QuestionRegistration, } from './context/index';
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';
2
2
  export * from './functions';
3
3
  export * from './hook';
4
4
  export * from './plugin';
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:()=>I,DashboardNodeData:()=>o,DatasourceNodeData:()=>d,FolderNodeData:()=>i,ItemDataType:()=>e,LabelNameNodeData:()=>l,LabelValueNodeData:()=>u,StructuredNodeData:()=>r,closeAssistant:()=>_,createContext:()=>f,getExposeAssistantFunctionsConfig:()=>A,isAssistantAvailable:()=>F,newFunctionNamespace:()=>P,openAssistant:()=>$,providePageContext:()=>L,provideQuestions:()=>N,useAssistant:()=>k,usePageContext:()=>y,useProvideQuestions:()=>U,useQuestions:()=>D}),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:[]}}const h=require("@grafana/runtime"),m=require("react"),b=[],v="grafana-assistant:page-context-sync",x="grafana-assistant:page-context-update",g="grafana-assistant:page-context-remove",w="grafana-assistant:location-changed";let E=!1;function L(e,t){const a=b.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=b[a],n.context=[...t]):(n={id:`page-context-${Date.now()}-${Math.random().toString(36).slice(2,11)}`,urlPattern:e,context:[...t]},b.push(n)),window.dispatchEvent(new CustomEvent(x,{detail:n})),window.dispatchEvent(new CustomEvent(v,{detail:{registry:b}}));const s=e=>{const t=b.findIndex((e=>e.id===n.id));-1!==t&&(b[t].context=[...e],window.dispatchEvent(new CustomEvent(x,{detail:b[t]})))};return s.unregister=()=>{const e=b.findIndex((e=>e.id===n.id));-1!==e&&(b.splice(e,1),window.dispatchEvent(new CustomEvent(g,{detail:{id:n.id}})))},s}function y(e={allowQuestions:!1}){const[t,a]=(0,m.useState)([]),n=(0,h.useLocationService)(),s=(0,m.useRef)("");return(0,m.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}(n.getLocation().pathname,b);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(w,{detail:{pathname:e}}))}(a),e())}));return e(),window.addEventListener(v,t),window.addEventListener(x,t),window.addEventListener(g,t),window.addEventListener(w,r),()=>{o.unsubscribe(),window.removeEventListener(v,t),window.removeEventListener(x,t),window.removeEventListener(g,t),window.removeEventListener(w,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 T(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 N(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=L(e,a(t)),s=e=>{n(a(e))};return s.unregister=n.unregister,s}function U(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=function(e,t=[]){const a=(0,m.useRef)(),n=(0,m.useRef)(t);return n.current=t,(0,m.useEffect)((()=>(a.current=L(e,n.current),()=>{var e;null===(e=a.current)||void 0===e||e.unregister()})),[e]),(0,m.useEffect)((()=>{a.current&&a.current(t)}),[t]),(0,m.useCallback)((e=>{var t;null===(t=a.current)||void 0===t||t.call(a,e)}),[])}(e,a(t));return e=>{n(a(e))}}function D(){const e=y({allowQuestions:!0});return S(e)}E||(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(b.map((e=>e.id))),t=a.filter((t=>!e.has(t.id)));b.push(...t)}})),window.addEventListener(x,(e=>{const t=e.detail;if(t){const e=b.findIndex((e=>e.id===t.id));-1!==e?b[e]=t:b.push(t)}})),window.addEventListener(g,(e=>{var t;const a=null===(t=e.detail)||void 0===t?void 0:t.id;if(a){const e=b.findIndex((e=>e.id===a));-1!==e&&b.splice(e,1)}})),E=!0);const S=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)||[]}})),I="grafana-assistant-app/callback/v0-alpha";function P(e,t){return{namespace:e,functions:t}}function A(e){return{title:"callback",targets:[I],fn:()=>e.map((e=>({namespace:e.namespace,functions:e.functions})))}}const C=require("rxjs");function F(){if(!h.getObservablePluginLinks)return(0,C.of)(!1);return(0,h.getObservablePluginLinks)({extensionPointId:"grafana/extension-sidebar/v0-alpha"}).pipe((0,C.map)((e=>e.some((e=>"grafana-assistant-app"===e.pluginId&&"Grafana Assistant"===e.title)))))}const O=require("@grafana/data");class V extends O.BusEventWithPayload{}V.type="open-extension-sidebar";class q extends O.BusEventBase{}function $(e){!function(e,t,a){const n=new V({pluginId:"grafana-assistant-app",componentTitle:"Grafana Assistant",props:a});(0,h.getAppEvents)().publish(n)}(0,0,{initialPrompt:e.prompt,initialContext:e.context})}function _(){!function(){const e=new q;(0,h.getAppEvents)().publish(e)}()}function k(){const[e,t]=(0,m.useState)(!1);return(0,m.useEffect)((()=>{const e=F().subscribe((e=>t(e)));return()=>{e.unsubscribe()}}),[]),[e,e?$:void 0,e?_:void 0]}q.type="close-extension-sidebar",module.exports=a})();
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})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/assistant",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Type definitions and helper functions for Grafana Assistant",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,7 +21,6 @@
21
21
  ],
22
22
  "author": "Grafana Labs",
23
23
  "license": "Apache-2.0",
24
- "dependencies": {},
25
24
  "devDependencies": {
26
25
  "react": "18.3.1",
27
26
  "rxjs": "7.8.2",
@@ -34,11 +33,11 @@
34
33
  "access": "public"
35
34
  },
36
35
  "peerDependencies": {
37
- "react": ">=18.0.0",
38
- "rxjs": ">=7.0.0",
39
36
  "@grafana/data": ">=12.1.0",
40
37
  "@grafana/runtime": ">=12.1.0",
41
38
  "@grafana/scenes": ">=5.41.0",
42
- "@grafana/ui": ">=12.1.0"
39
+ "@grafana/ui": ">=12.1.0",
40
+ "react": ">=18.0.0",
41
+ "rxjs": ">=7.0.0"
43
42
  }
44
43
  }