@grafana/assistant 0.0.8 → 0.0.9
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/page.d.ts +11 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/context/page.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface PageContextRegistration {
|
|
|
8
8
|
* Registers context items for specific pages based on URL patterns.
|
|
9
9
|
* Returns a setter function to update the context dynamically, similar to useState.
|
|
10
10
|
*
|
|
11
|
+
* If a registration with the same URL pattern already exists, it will be replaced.
|
|
12
|
+
*
|
|
11
13
|
* @param urlPattern - URL pattern (string or RegExp) to match against page URLs
|
|
12
14
|
* @param initialContext - Initial array of ChatContextItem to provide when the pattern matches
|
|
13
15
|
* @returns A setter function to update the context, with an unregister method attached
|
|
@@ -15,4 +17,13 @@ export interface PageContextRegistration {
|
|
|
15
17
|
export declare function providePageContext(urlPattern: string | RegExp, initialContext: ChatContextItem[]): ((context: ChatContextItem[]) => void) & {
|
|
16
18
|
unregister: () => void;
|
|
17
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* React hook for providing page context that automatically cleans up on unmount.
|
|
22
|
+
* This is the recommended way to use page context in React components.
|
|
23
|
+
*
|
|
24
|
+
* @param urlPattern - URL pattern (string or RegExp) to match against page URLs
|
|
25
|
+
* @param initialContext - Initial array of ChatContextItem to provide when the pattern matches
|
|
26
|
+
* @returns A setter function to update the context
|
|
27
|
+
*/
|
|
28
|
+
export declare function useProvidePageContext(urlPattern: string | RegExp, initialContext?: ChatContextItem[]): (context: ChatContextItem[]) => void;
|
|
18
29
|
export declare function usePageContext(): ChatContextItem[];
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e,t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[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})}},r={};function n(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r);return(t>>>0).toString(16)}t.r(r),t.d(r,{CALLBACK_EXTENSION_POINT:()=>Ue,DashboardNodeData:()=>a,DatasourceNodeData:()=>s,FolderNodeData:()=>u,ItemDataType:()=>e,LabelNameNodeData:()=>c,LabelValueNodeData:()=>l,StructuredNodeData:()=>i,closeAssistant:()=>je,createContext:()=>p,getExposeAssistantFunctionsConfig:()=>Pe,isAssistantAvailable:()=>Ie,newFunctionNamespace:()=>Ne,openAssistant:()=>De,providePageContext:()=>Te,useAssistant:()=>ke,usePageContext:()=>_e}),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 o{constructor(e){this.params=e,this.id=n(e.id)}formatForLLM(t){return{type:e.Unknown,codeElementIds:t,data:{name:this.params.text}}}}class i{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 a extends o{constructor(e){super({...e,id:e.dashboardUid}),this.dashboardUid=e.dashboardUid,this.dashboardTitle=e.dashboardTitle,this.folderUid=e.folderUid,this.folderTitle=e.folderTitle}formatForLLM(t){return{type:e.Dashboard,codeElementIds:t,data:{name:this.dashboardTitle,dashboardUid:this.dashboardUid,dashboardTitle:this.dashboardTitle,folderUid:this.folderUid,folderTitle:this.folderTitle}}}}class u extends o{constructor(e){super({...e,id:e.folderUid}),this.folderUid=e.folderUid,this.folderTitle=e.folderTitle}formatForLLM(t){return{type:e.DashboardFolder,codeElementIds:t,data:{name:this.folderTitle,folderUid:this.folderUid,folderTitle:this.folderTitle}}}}class s extends o{constructor(e){super({...e,id:e.datasourceUid}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.datasourceName=e.datasourceName}formatForLLM(t){return{type:e.Datasource,codeElementIds:t,data:{name:this.datasourceName,uid:this.datasourceUid,type:this.datasourceType}}}}class c extends o{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}`}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.labelName=e.labelName}formatForLLM(t){return{type:e.LabelName,codeElementIds:t,data:{name:this.labelName,datasourceUid:this.datasourceUid,datasourceType:this.datasourceType,labelName:this.labelName}}}}class l extends o{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}-${e.labelValue}`}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.labelName=e.labelName,this.labelValue=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}}}}const f={[e.Datasource]:"database",[e.LabelName]:"database",[e.LabelValue]:"database",[e.Dashboard]:"dashboard",[e.DashboardFolder]:"folder",[e.Unknown]:"circle-mono",[e.Structured]:"gf-grid"};function d(t,r){return t===e.Datasource?r.datasourceName:t===e.LabelName?r.labelName:t===e.LabelValue?r.labelValue:t===e.Dashboard?r.dashboardTitle:t===e.DashboardFolder?r.folderTitle:t===e.Structured?r.data.name:"Given Context"}function p(e,t){var r,n;const p=function(e,t){switch(e){case"datasource":return new s(t);case"label_name":return new c(t);case"label_value":return new l(t);case"dashboard":return new a(t);case"dashboard_folder":return new u(t);case"structured":return new i(t);case"unknown":return new o(t);default:return console.error(`Unknown context type: ${e}`),new o(t)}}(e,t);return{node:{id:p.id,name:null!==(r=t.title)&&void 0!==r?r:d(e,t),icon:null!==(n=t.icon)&&void 0!==n?n:f[e],navigable:!1,selectable:!0,data:p},occurrences:[]}}const h=require("@grafana/runtime"),b=require("react"),y=require("rxjs");function v(e){return"function"==typeof e}function m(e){return function(t){if(function(e){return v(null==e?void 0:e.lift)}(t))return t.lift((function(t){try{return e(t,this)}catch(e){this.error(e)}}));throw new TypeError("Unable to lift unknown Observable type")}}var w=function(e,t){return w=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},w(e,t)};function x(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}w(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function g(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=u(0),a.throw=u(1),a.return=u(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(s){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,n=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}function S(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function T(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function _(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}function E(e){return this instanceof E?(this.v=e,this):new E(e)}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var U,N=((U=function(e){var t;t=this,Error.call(t),t.stack=(new Error).stack,this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(e,t){return t+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}).prototype=Object.create(Error.prototype),U.prototype.constructor=U,U);function P(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var I=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,r,n,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var a=S(i),u=a.next();!u.done;u=a.next())u.value.remove(this)}catch(t){e={error:t}}finally{try{u&&!u.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}else i.remove(this);var s=this.initialTeardown;if(v(s))try{s()}catch(e){o=e instanceof N?e.errors:[e]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var l=S(c),f=l.next();!f.done;f=l.next()){var d=f.value;try{O(d)}catch(e){o=null!=o?o:[],e instanceof N?o=_(_([],T(o)),T(e.errors)):o.push(e)}}}catch(e){r={error:e}}finally{try{f&&!f.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}}if(o)throw new N(o)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)O(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(r=this._finalizers)&&void 0!==r?r:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&P(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&P(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}();function L(e){return e instanceof I||e&&"closed"in e&&v(e.remove)&&v(e.add)&&v(e.unsubscribe)}function O(e){v(e)?e():e.unsubscribe()}I.EMPTY;var A={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},D={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var o=D.delegate;return(null==o?void 0:o.setTimeout)?o.setTimeout.apply(o,_([e,t],T(r))):setTimeout.apply(void 0,_([e,t],T(r)))},clearTimeout:function(e){var t=D.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function j(e){D.setTimeout((function(){var t=A.onUnhandledError;if(!t)throw e;t(e)}))}function k(){}var F=C("C",void 0,void 0);function C(e,t,r){return{kind:e,value:t,error:r}}var M=null,V=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,L(t)&&t.add(r)):r.destination=H,r}return x(t,e),t.create=function(e,t,r){return new R(e,t,r)},t.prototype.next=function(e){this.isStopped?G(function(e){return C("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?G(C("E",void 0,e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?G(F,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(I),$=Function.prototype.bind;function z(e,t){return $.call(e,t)}var B=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){q(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){q(e)}else q(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){q(e)}},e}(),R=function(e){function t(t,r,n){var o,i,a=e.call(this)||this;return v(t)||!t?o={next:null!=t?t:void 0,error:null!=r?r:void 0,complete:null!=n?n:void 0}:a&&A.useDeprecatedNextContext?((i=Object.create(t)).unsubscribe=function(){return a.unsubscribe()},o={next:t.next&&z(t.next,i),error:t.error&&z(t.error,i),complete:t.complete&&z(t.complete,i)}):o=t,a.destination=new B(o),a}return x(t,e),t}(V);function q(e){var t;A.useDeprecatedSynchronousErrorHandling?(t=e,A.useDeprecatedSynchronousErrorHandling&&M&&(M.errorThrown=!0,M.error=t)):j(e)}function G(e,t){var r=A.onStoppedNotification;r&&D.setTimeout((function(){return r(e,t)}))}var H={closed:!0,next:k,error:function(e){throw e},complete:k};function Y(e,t,r,n,o){return new J(e,t,r,n,o)}var J=function(e){function t(t,r,n,o,i,a){var u=e.call(this,t)||this;return u.onFinalize=i,u.shouldUnsubscribe=a,u._next=r?function(e){try{r(e)}catch(e){t.error(e)}}:e.prototype._next,u._error=o?function(e){try{o(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,u._complete=n?function(){try{n()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,u}return x(t,e),t.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;e.prototype.unsubscribe.call(this),!r&&(null===(t=this.onFinalize)||void 0===t||t.call(this))}},t}(V);function K(e,t){return m((function(r,n){var o=0;r.subscribe(Y(n,(function(r){n.next(e.call(t,r,o++))})))}))}var W=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function X(e){return v(null==e?void 0:e.then)}var Q="function"==typeof Symbol&&Symbol.observable||"@@observable";function Z(e){return e}var ee=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n,o=this,i=(n=e)&&n instanceof V||function(e){return e&&v(e.next)&&v(e.error)&&v(e.complete)}(n)&&L(n)?e:new R(e,t,r);return function(e){if(A.useDeprecatedSynchronousErrorHandling){var t=!M;if(t&&(M={errorThrown:!1,error:null}),e(),t){var r=M,n=r.errorThrown,o=r.error;if(M=null,n)throw o}}else e()}((function(){var e=o,t=e.operator,r=e.source;i.add(t?t.call(i,r):r?o._subscribe(i):o._trySubscribe(i))})),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var r=this;return new(t=te(t))((function(t,n){var o=new R({next:function(t){try{e(t)}catch(e){n(e),o.unsubscribe()}},error:n,complete:t});r.subscribe(o)}))},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[Q]=function(){return this},e.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return(0===(r=e).length?Z:1===r.length?r[0]:function(e){return r.reduce((function(e,t){return t(e)}),e)})(this);var r},e.prototype.toPromise=function(e){var t=this;return new(e=te(e))((function(e,r){var n;t.subscribe((function(e){return n=e}),(function(e){return r(e)}),(function(){return e(n)}))}))},e.create=function(t){return new e(t)},e}();function te(e){var t;return null!==(t=null!=e?e:A.Promise)&&void 0!==t?t:Promise}function re(e){return v(e[Q])}function ne(e){return Symbol.asyncIterator&&v(null==e?void 0:e[Symbol.asyncIterator])}function oe(e){return new TypeError("You provided "+(null!==e&&"object"==typeof e?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var ie="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ae(e){return v(null==e?void 0:e[ie])}function ue(e){return function(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,o=r.apply(e,t||[]),i=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",(function(e){return function(t){return Promise.resolve(t).then(e,c)}})),n[Symbol.asyncIterator]=function(){return this},n;function a(e,t){o[e]&&(n[e]=function(t){return new Promise((function(r,n){i.push([e,t,r,n])>1||u(e,t)}))},t&&(n[e]=t(n[e])))}function u(e,t){try{(r=o[e](t)).value instanceof E?Promise.resolve(r.value.v).then(s,c):l(i[0][2],r)}catch(e){l(i[0][3],e)}var r}function s(e){u("next",e)}function c(e){u("throw",e)}function l(e,t){e(t),i.shift(),i.length&&u(i[0][0],i[0][1])}}(this,arguments,(function(){var t,r,n;return g(this,(function(o){switch(o.label){case 0:t=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,E(t.read())];case 3:return r=o.sent(),n=r.value,r.done?[4,E(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,E(n)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}}))}))}function se(e){return v(null==e?void 0:e.getReader)}function ce(e){if(e instanceof ee)return e;if(null!=e){if(re(e))return o=e,new ee((function(e){var t=o[Q]();if(v(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(W(e))return n=e,new ee((function(e){for(var t=0;t<n.length&&!e.closed;t++)e.next(n[t]);e.complete()}));if(X(e))return r=e,new ee((function(e){r.then((function(t){e.closed||(e.next(t),e.complete())}),(function(t){return e.error(t)})).then(null,j)}));if(ne(e))return le(e);if(ae(e))return t=e,new ee((function(e){var r,n;try{for(var o=S(t),i=o.next();!i.done;i=o.next()){var a=i.value;if(e.next(a),e.closed)return}}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}e.complete()}));if(se(e))return le(ue(e))}var t,r,n,o;throw oe(e)}function le(e){return new ee((function(t){(function(e,t){var r,n,o,i,a,u,s,c;return a=this,u=void 0,c=function(){var a,u;return g(this,(function(s){switch(s.label){case 0:s.trys.push([0,5,6,11]),r=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=S(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,o){!function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)}(n,o,(t=e[r](t)).done,t.value)}))}}}(e),s.label=1;case 1:return[4,r.next()];case 2:if((n=s.sent()).done)return[3,4];if(a=n.value,t.next(a),t.closed)return[2];s.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return u=s.sent(),o={error:u},[3,11];case 6:return s.trys.push([6,,9,10]),n&&!n.done&&(i=r.return)?[4,i.call(r)]:[3,8];case 7:s.sent(),s.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}}))},new((s=void 0)||(s=Promise))((function(e,t){function r(e){try{o(c.next(e))}catch(e){t(e)}}function n(e){try{o(c.throw(e))}catch(e){t(e)}}function o(t){var o;t.done?e(t.value):(o=t.value,o instanceof s?o:new s((function(e){e(o)}))).then(r,n)}o((c=c.apply(a,u||[])).next())}))})(e,t).catch((function(e){return t.error(e)}))}))}function fe(e,t,r,n,o){void 0===n&&(n=0),void 0===o&&(o=!1);var i=t.schedule((function(){r(),o?e.add(this.schedule(null,n)):this.unsubscribe()}),n);if(e.add(i),!o)return i}function de(e,t,r){return void 0===r&&(r=1/0),v(t)?de((function(r,n){return K((function(e,o){return t(r,e,n,o)}))(ce(e(r,n)))}),r):("number"==typeof t&&(r=t),m((function(t,n){return function(e,t,r,n){var o=[],i=0,a=0,u=!1,s=function(){!u||o.length||i||t.complete()},c=function(e){return i<n?l(e):o.push(e)},l=function(e){i++;var u=!1;ce(r(e,a++)).subscribe(Y(t,(function(e){t.next(e)}),(function(){u=!0}),void 0,(function(){if(u)try{i--;for(;o.length&&i<n;)e=void 0,e=o.shift(),l(e);s()}catch(e){t.error(e)}var e})))};return e.subscribe(Y(t,c,(function(){u=!0,s()}))),function(){}}(t,n,e,r)})))}function pe(){return void 0===(e=1)&&(e=1/0),de(Z,e);var e}function he(e){return(r=(t=e)[t.length-1])&&v(r.schedule)?e.pop():void 0;var t,r}function be(e,t){return void 0===t&&(t=0),m((function(r,n){r.subscribe(Y(n,(function(r){return fe(n,e,(function(){return n.next(r)}),t)}),(function(){return fe(n,e,(function(){return n.complete()}),t)}),(function(r){return fe(n,e,(function(){return n.error(r)}),t)})))}))}function ye(e,t){return void 0===t&&(t=0),m((function(r,n){n.add(e.schedule((function(){return r.subscribe(n)}),t))}))}function ve(e,t){if(!e)throw new Error("Iterable cannot be null");return new ee((function(r){fe(r,t,(function(){var n=e[Symbol.asyncIterator]();fe(r,t,(function(){n.next().then((function(e){e.done?r.complete():r.next(e.value)}))}),0,!0)}))}))}function me(){for(var e,t,r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return pe()((e=r,(t=he(r))?function(e,t){if(null!=e){if(re(e))return function(e,t){return ce(e).pipe(ye(t),be(t))}(e,t);if(W(e))return function(e,t){return new ee((function(r){var n=0;return t.schedule((function(){n===e.length?r.complete():(r.next(e[n++]),r.closed||this.schedule())}))}))}(e,t);if(X(e))return function(e,t){return ce(e).pipe(ye(t),be(t))}(e,t);if(ne(e))return ve(e,t);if(ae(e))return function(e,t){return new ee((function(r){var n;return fe(r,t,(function(){n=e[ie](),fe(r,t,(function(){var e,t,o;try{t=(e=n.next()).value,o=e.done}catch(e){return void r.error(e)}o?r.complete():r.next(t)}),0,!0)})),function(){return v(null==n?void 0:n.return)&&n.return()}}))}(e,t);if(se(e))return function(e,t){return ve(ue(e),t)}(e,t)}throw oe(e)}(e,t):ce(e)))}function we(e,t){return void 0===t&&(t=Z),e=null!=e?e:xe,m((function(r,n){var o,i=!0;r.subscribe(Y(n,(function(r){var a=t(r);!i&&e(o,a)||(i=!1,o=a,n.next(r))})))}))}function xe(e,t){return e===t}const ge=[],Se=new y.BehaviorSubject([]);function Te(e,t){const r={id:`page-context-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,urlPattern:e,context:[...t]};ge.push(r),Se.next([...ge]);const n=e=>{const t=ge.findIndex((e=>e.id===r.id));-1!==t&&(ge[t].context=[...e],Se.next([...ge]))};return n.unregister=()=>{const e=ge.findIndex((e=>e.id===r.id));-1!==e&&(ge.splice(e,1),Se.next([...ge]))},n}function _e(){const[e,t]=(0,b.useState)([]),r=(0,h.useLocationService)();return(0,b.useEffect)((()=>{const e=function(e){const t=e.getLocationObservable().pipe(K((e=>e.pathname)),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=he(e);return m((function(t,n){(r?me(e,t,r):me(e,t)).subscribe(n)}))}(e.getLocation().pathname),we());return(0,y.combineLatest)([t,Se.asObservable()]).pipe(K((([e,t])=>function(e,t){if(!e)return[];const r=[];for(const n of t)Ee(e,n.urlPattern)&&r.push(...n.context);return r}(e,t))),we(((e,t)=>e.length===t.length&&e.every(((e,r)=>e===t[r])))))}(r).subscribe(t);return()=>{e.unsubscribe()}}),[r]),e}function Ee(e,t){if(t instanceof RegExp)return t.test(e);if("string"==typeof t){const r=t.replace(/\*\*/g,".*").replace(/\*/g,"[^/]*").replace(/\?/g,".");return new RegExp(`^${r}$`).test(e)}return!1}const Ue="grafana-assistant-app/callback/v0-alpha";function Ne(e,t){return{namespace:e,functions:t}}function Pe(e){return{title:"callback",targets:[Ue],fn:()=>e.map((e=>({namespace:e.namespace,functions:e.functions})))}}function Ie(){return(0,h.getObservablePluginLinks)({extensionPointId:"grafana/extension-sidebar/v0-alpha"}).pipe((0,y.map)((e=>e.some((e=>"grafana-assistant-app"===e.pluginId&&"Grafana Assistant"===e.title)))))}const Le=require("@grafana/data");class Oe extends Le.BusEventWithPayload{}Oe.type="open-extension-sidebar";class Ae extends Le.BusEventBase{}function De(e){!function(e,t,r){const n=new Oe({pluginId:"grafana-assistant-app",componentTitle:"Grafana Assistant",props:r});(0,h.getAppEvents)().publish(n)}(0,0,{initialPrompt:e.prompt,initialContext:e.context})}function je(){!function(){const e=new Ae;(0,h.getAppEvents)().publish(e)}()}function ke(){const[e,t]=(0,b.useState)(!1);return(0,b.useEffect)((()=>{const e=Ie().subscribe((e=>t(e)));return()=>{e.unsubscribe()}}),[]),[e,e?De:void 0,e?je:void 0]}Ae.type="close-extension-sidebar",module.exports=r})();
|
|
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:()=>i,FolderNodeData:()=>d,ItemDataType:()=>e,LabelNameNodeData:()=>l,LabelValueNodeData:()=>c,StructuredNodeData:()=>r,closeAssistant:()=>V,createContext:()=>f,getExposeAssistantFunctionsConfig:()=>D,isAssistantAvailable:()=>S,newFunctionNamespace:()=>U,openAssistant:()=>A,providePageContext:()=>y,useAssistant:()=>M,usePageContext:()=>x}),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.id=n(e.id)}formatForLLM(t){return{type:e.Unknown,codeElementIds:t,data:{name:this.params.text}}}}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.dashboardUid=e.dashboardUid,this.dashboardTitle=e.dashboardTitle,this.folderUid=e.folderUid,this.folderTitle=e.folderTitle}formatForLLM(t){return{type:e.Dashboard,codeElementIds:t,data:{name:this.dashboardTitle,dashboardUid:this.dashboardUid,dashboardTitle:this.dashboardTitle,folderUid:this.folderUid,folderTitle:this.folderTitle}}}}class d extends s{constructor(e){super({...e,id:e.folderUid}),this.folderUid=e.folderUid,this.folderTitle=e.folderTitle}formatForLLM(t){return{type:e.DashboardFolder,codeElementIds:t,data:{name:this.folderTitle,folderUid:this.folderUid,folderTitle:this.folderTitle}}}}class i extends s{constructor(e){super({...e,id:e.datasourceUid}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.datasourceName=e.datasourceName}formatForLLM(t){return{type:e.Datasource,codeElementIds:t,data:{name:this.datasourceName,uid:this.datasourceUid,type:this.datasourceType}}}}class l extends s{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}`}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.labelName=e.labelName}formatForLLM(t){return{type:e.LabelName,codeElementIds:t,data:{name:this.labelName,datasourceUid:this.datasourceUid,datasourceType:this.datasourceType,labelName:this.labelName}}}}class c extends s{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}-${e.labelValue}`}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.labelName=e.labelName,this.labelValue=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}}}}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 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 i(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 d(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),icon:null!==(n=t.icon)&&void 0!==n?n:u[e],navigable:!1,selectable:!0,data:f},occurrences:[]}}const h=require("@grafana/runtime"),b=require("react"),m=[],v="grafana-assistant:page-context-sync",w="grafana-assistant:page-context-update",g="grafana-assistant:page-context-remove",L="grafana-assistant:location-changed";let E=!1;function y(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(w,{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(w,{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(g,{detail:{id:n.id}})))},s}function x(){const[e,t]=(0,b.useState)([]),a=(0,h.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(L,{detail:{pathname:e}}))}(a),e())}));return e(),window.addEventListener(v,s),window.addEventListener(w,s),window.addEventListener(g,s),window.addEventListener(L,r),()=>{o.unsubscribe(),window.removeEventListener(v,s),window.removeEventListener(w,s),window.removeEventListener(g,s),window.removeEventListener(L,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}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(m.map((e=>e.id))),t=a.filter((t=>!e.has(t.id)));m.push(...t)}})),window.addEventListener(w,(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(g,(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)}})),E=!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,h.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,h.getAppEvents)().publish(n)}(0,0,{initialPrompt:e.prompt,initialContext:e.context})}function V(){!function(){const e=new P;(0,h.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})();
|