@grafana/assistant 0.0.7 → 0.0.8
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 +79 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/context/page.d.ts +18 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -84,6 +84,48 @@ openAssistant({
|
|
|
84
84
|
});
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
### Providing Page-Specific Context
|
|
88
|
+
|
|
89
|
+
You can register context items that are automatically included when the assistant is opened on pages matching specific URL patterns. The `providePageContext` function works like `useState` - it returns a setter function that allows you to update the context dynamically:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { providePageContext, createContext } from '@grafana/assistant';
|
|
93
|
+
|
|
94
|
+
// Create initial context for dashboard pages
|
|
95
|
+
const dashboardContext = createContext('structured', {
|
|
96
|
+
data: {
|
|
97
|
+
name: 'Dashboard Context',
|
|
98
|
+
pageType: 'dashboard',
|
|
99
|
+
capabilities: ['view', 'edit', 'share'],
|
|
100
|
+
help: 'Use the assistant to analyze dashboard data, create queries, or troubleshoot issues.'
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Register context for all dashboard pages and get a setter function
|
|
105
|
+
const setContext = providePageContext('/d/*', [dashboardContext]);
|
|
106
|
+
|
|
107
|
+
// Later, dynamically update the context based on user interactions or data changes
|
|
108
|
+
setContext([
|
|
109
|
+
dashboardContext,
|
|
110
|
+
createContext('structured', {
|
|
111
|
+
data: {
|
|
112
|
+
name: 'Panel Context',
|
|
113
|
+
selectedPanel: 'cpu-usage-panel',
|
|
114
|
+
panelType: 'graph'
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
// The context will automatically be included when openAssistant is called from dashboard pages
|
|
120
|
+
openAssistant({
|
|
121
|
+
prompt: 'Help me analyze this dashboard'
|
|
122
|
+
// Current context is automatically included
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Clean up when no longer needed
|
|
126
|
+
setContext.unregister();
|
|
127
|
+
```
|
|
128
|
+
|
|
87
129
|
### Creating Context Items
|
|
88
130
|
|
|
89
131
|
The `createContext` function allows you to create structured context items that provide the assistant with additional information about your Grafana resources.
|
|
@@ -230,6 +272,36 @@ Creates a context item that can be passed to the assistant to provide additional
|
|
|
230
272
|
|
|
231
273
|
**Returns:** A `ChatContextItem` that can be passed to `openAssistant`
|
|
232
274
|
|
|
275
|
+
#### `providePageContext(urlPattern: string | RegExp, initialContext: ChatContextItem[]): ((context: ChatContextItem[]) => void) & { unregister: () => void }`
|
|
276
|
+
|
|
277
|
+
Registers context items for specific pages based on URL patterns. Returns a setter function to update the context dynamically, similar to `useState`. The context will be automatically included when the assistant is opened on pages matching the pattern.
|
|
278
|
+
|
|
279
|
+
**Parameters:**
|
|
280
|
+
- `urlPattern` - URL pattern (string with wildcards or RegExp) to match against page URLs
|
|
281
|
+
- String patterns support `*` (match any characters) and `**` (match any path segments)
|
|
282
|
+
- RegExp patterns provide full regex matching capabilities
|
|
283
|
+
- `initialContext` - Initial array of `ChatContextItem` to provide when the pattern matches
|
|
284
|
+
|
|
285
|
+
**Returns:** A setter function to update the context, with an `unregister` method attached for cleanup
|
|
286
|
+
|
|
287
|
+
**Examples:**
|
|
288
|
+
```typescript
|
|
289
|
+
// String patterns - returns setter function
|
|
290
|
+
const setDashboardContext = providePageContext('/d/*', initialContext); // Match any dashboard
|
|
291
|
+
const setExploreContext = providePageContext('/explore**', initialContext); // Match explore and subpaths
|
|
292
|
+
|
|
293
|
+
// RegExp patterns
|
|
294
|
+
const setSpecificContext = providePageContext(/^\/d\/[a-zA-Z0-9]+$/, initialContext); // Match specific dashboard format
|
|
295
|
+
|
|
296
|
+
// Update context dynamically
|
|
297
|
+
setDashboardContext([...newContext]);
|
|
298
|
+
|
|
299
|
+
// Cleanup when done
|
|
300
|
+
setDashboardContext.unregister();
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
233
305
|
### Sidebar Types
|
|
234
306
|
|
|
235
307
|
#### `OpenAssistantProps`
|
|
@@ -238,11 +310,16 @@ Creates a context item that can be passed to the assistant to provide additional
|
|
|
238
310
|
type OpenAssistantProps = {
|
|
239
311
|
prompt?: string;
|
|
240
312
|
context?: ChatContextItem[];
|
|
313
|
+
includePageContext?: boolean;
|
|
241
314
|
};
|
|
242
315
|
```
|
|
243
316
|
|
|
244
317
|
Configuration object for opening the assistant.
|
|
245
318
|
|
|
319
|
+
- `prompt` - Optional initial prompt to display
|
|
320
|
+
- `context` - Optional context items to provide
|
|
321
|
+
- `includePageContext` - Whether to automatically include page context for the current URL (defaults to true)
|
|
322
|
+
|
|
246
323
|
#### `ChatContextItem`
|
|
247
324
|
|
|
248
325
|
```typescript
|
|
@@ -254,6 +331,8 @@ type ChatContextItem = {
|
|
|
254
331
|
|
|
255
332
|
A context item that provides structured information to the assistant.
|
|
256
333
|
|
|
334
|
+
|
|
335
|
+
|
|
257
336
|
### Context Types
|
|
258
337
|
|
|
259
338
|
#### Datasource Context Parameters
|
package/dist/context/index.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ChatContextItem } from './types';
|
|
2
|
+
export interface PageContextRegistration {
|
|
3
|
+
id: string;
|
|
4
|
+
urlPattern: string | RegExp;
|
|
5
|
+
context: ChatContextItem[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Registers context items for specific pages based on URL patterns.
|
|
9
|
+
* Returns a setter function to update the context dynamically, similar to useState.
|
|
10
|
+
*
|
|
11
|
+
* @param urlPattern - URL pattern (string or RegExp) to match against page URLs
|
|
12
|
+
* @param initialContext - Initial array of ChatContextItem to provide when the pattern matches
|
|
13
|
+
* @returns A setter function to update the context, with an unregister method attached
|
|
14
|
+
*/
|
|
15
|
+
export declare function providePageContext(urlPattern: string | RegExp, initialContext: ChatContextItem[]): ((context: ChatContextItem[]) => void) & {
|
|
16
|
+
unregister: () => void;
|
|
17
|
+
};
|
|
18
|
+
export declare function usePageContext(): ChatContextItem[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createContext, DashboardNodeData, DatasourceNodeData, FolderNodeData, ItemDataType, LabelNameNodeData, LabelValueNodeData, StructuredNodeData, TreeNode, } from './context/index';
|
|
1
|
+
export { createContext, DashboardNodeData, DatasourceNodeData, FolderNodeData, ItemDataType, LabelNameNodeData, LabelValueNodeData, StructuredNodeData, TreeNode, providePageContext, PageContextRegistration, usePageContext, } 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,a={d:(e,t)=>{for(var s in t)a.o(t,s)&&!a.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},o:(e,a)=>Object.prototype.hasOwnProperty.call(e,a),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function s(e){let a=5381;for(let t=0;t<e.length;t++)a=(a<<5)+a+e.charCodeAt(t);return(a>>>0).toString(16)}a.r(t),a.d(t,{CALLBACK_EXTENSION_POINT:()=>p,DashboardNodeData:()=>d,DatasourceNodeData:()=>i,FolderNodeData:()=>n,ItemDataType:()=>e,LabelNameNodeData:()=>l,LabelValueNodeData:()=>u,StructuredNodeData:()=>o,closeAssistant:()=>x,createContext:()=>h,getExposeAssistantFunctionsConfig:()=>m,isAssistantAvailable:()=>U,newFunctionNamespace:()=>f,openAssistant:()=>D,useAssistant:()=>w}),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 r{constructor(e){this.params=e,this.id=s(e.id)}formatForLLM(a){return{type:e.Unknown,codeElementIds:a,data:{name:this.params.text}}}}class o{constructor(e){this.params=e,this.id=s(JSON.stringify(e.data))}formatForLLM(a){return{type:e.Structured,codeElementIds:a,data:this.params.data}}}class d 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}formatForLLM(a){return{type:e.Dashboard,codeElementIds:a,data:{name:this.dashboardTitle,dashboardUid:this.dashboardUid,dashboardTitle:this.dashboardTitle,folderUid:this.folderUid,folderTitle:this.folderTitle}}}}class n extends r{constructor(e){super({...e,id:e.folderUid}),this.folderUid=e.folderUid,this.folderTitle=e.folderTitle}formatForLLM(a){return{type:e.DashboardFolder,codeElementIds:a,data:{name:this.folderTitle,folderUid:this.folderUid,folderTitle:this.folderTitle}}}}class i extends r{constructor(e){super({...e,id:e.datasourceUid}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.datasourceName=e.datasourceName}formatForLLM(a){return{type:e.Datasource,codeElementIds:a,data:{name:this.datasourceName,uid:this.datasourceUid,type:this.datasourceType}}}}class l extends r{constructor(e){super({...e,id:`${e.datasourceUid}-${e.labelName}`}),this.datasourceUid=e.datasourceUid,this.datasourceType=e.datasourceType,this.labelName=e.labelName}formatForLLM(a){return{type:e.LabelName,codeElementIds:a,data:{name:this.labelName,datasourceUid:this.datasourceUid,datasourceType:this.datasourceType,labelName:this.labelName}}}}class u extends r{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(a){return{type:e.LabelValue,codeElementIds:a,data:{name:this.labelValue,datasourceUid:this.datasourceUid,datasourceType:this.datasourceType,labelName:this.labelName,labelValue:this.labelValue}}}}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 b(a,t){return a===e.Datasource?t.datasourceName:a===e.LabelName?t.labelName:a===e.LabelValue?t.labelValue:a===e.Dashboard?t.dashboardTitle:a===e.DashboardFolder?t.folderTitle:a===e.Structured?t.data.name:"Given Context"}function h(e,a){var t,s;const h=function(e,a){switch(e){case"datasource":return new i(a);case"label_name":return new l(a);case"label_value":return new u(a);case"dashboard":return new d(a);case"dashboard_folder":return new n(a);case"structured":return new o(a);case"unknown":return new r(a);default:return console.error(`Unknown context type: ${e}`),new r(a)}}(e,a);return{node:{id:h.id,name:null!==(t=a.title)&&void 0!==t?t:b(e,a),icon:null!==(s=a.icon)&&void 0!==s?s:c[e],navigable:!1,selectable:!0,data:h},occurrences:[]}}const p="grafana-assistant-app/callback/v0-alpha";function f(e,a){return{namespace:e,functions:a}}function m(e){return{title:"callback",targets:[p],fn:()=>e.map(e=>({namespace:e.namespace,functions:e.functions}))}}const y=require("react"),T=require("@grafana/runtime"),N=require("rxjs");function U(){return(0,T.getObservablePluginLinks)({extensionPointId:"grafana/extension-sidebar/v0-alpha"}).pipe((0,N.map)(e=>e.some(e=>"grafana-assistant-app"===e.pluginId&&"Grafana Assistant"===e.title)))}const L=require("@grafana/data");class g extends L.BusEventWithPayload{}g.type="open-extension-sidebar";class v extends L.BusEventBase{}function D(e){!function(e,a,t){const s=new g({pluginId:"grafana-assistant-app",componentTitle:"Grafana Assistant",props:t});(0,T.getAppEvents)().publish(s)}(0,0,{initialPrompt:e.prompt,initialContext:e.context})}function x(){!function(){const e=new v;(0,T.getAppEvents)().publish(e)}()}function w(){const[e,a]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{const e=U().subscribe(e=>a(e));return()=>{e.unsubscribe()}},[]),[e,e?D:void 0,e?x:void 0]}v.type="close-extension-sidebar",module.exports=t})();
|
|
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})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/assistant",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Type definitions and helper functions for Grafana Assistant",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"prebuild": "rm -rf dist",
|
|
12
|
-
"build:dev": "webpack --config webpack.config.cjs --mode development && tsc --emitDeclarationOnly",
|
|
13
12
|
"build": "webpack --config webpack.config.cjs --mode production && tsc --emitDeclarationOnly",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
13
|
+
"dev": "webpack --config webpack.config.cjs --mode development",
|
|
14
|
+
"clean": "rm -rf dist"
|
|
16
15
|
},
|
|
17
16
|
"keywords": [
|
|
18
17
|
"grafana",
|
|
@@ -25,7 +24,7 @@
|
|
|
25
24
|
"dependencies": {},
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"react": "18.3.1",
|
|
28
|
-
"rxjs": "7.8.
|
|
27
|
+
"rxjs": "7.8.2",
|
|
29
28
|
"ts-loader": "^9.0.0",
|
|
30
29
|
"typescript": "^5.0.0",
|
|
31
30
|
"webpack": "^5.0.0",
|
|
@@ -37,9 +36,9 @@
|
|
|
37
36
|
"peerDependencies": {
|
|
38
37
|
"react": ">=18.0.0",
|
|
39
38
|
"rxjs": ">=7.0.0",
|
|
40
|
-
"@grafana/data": ">=12.
|
|
41
|
-
"@grafana/runtime": ">=12.
|
|
39
|
+
"@grafana/data": ">=12.1.0",
|
|
40
|
+
"@grafana/runtime": ">=12.1.0",
|
|
42
41
|
"@grafana/scenes": ">=5.41.0",
|
|
43
|
-
"@grafana/ui": ">=12.
|
|
42
|
+
"@grafana/ui": ">=12.1.0"
|
|
44
43
|
}
|
|
45
44
|
}
|