@grafana/assistant 0.1.32 → 0.1.34
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 +12 -2
- package/dist/esm/components/button/OpenAssistantButton.js +106 -0
- package/dist/esm/components/button/OpenAssistantButton.js.map +1 -0
- package/dist/esm/components/button/OpenAssistantSplitButton.js +135 -0
- package/dist/esm/components/button/OpenAssistantSplitButton.js.map +1 -0
- package/dist/esm/components/button/QueryWithAssistantButton.js +62 -0
- package/dist/esm/components/button/QueryWithAssistantButton.js.map +1 -0
- package/dist/esm/components/index.js +8 -0
- package/dist/esm/components/index.js.map +1 -0
- package/dist/esm/components/input/AITextArea.js +91 -0
- package/dist/esm/components/input/AITextArea.js.map +1 -0
- package/dist/esm/components/input/AITextInput.js +70 -0
- package/dist/esm/components/input/AITextInput.js.map +1 -0
- package/dist/esm/components/input/types.js +2 -0
- package/dist/esm/components/input/types.js.map +1 -0
- package/dist/esm/components/input/useAIGeneration.js +58 -0
- package/dist/esm/components/input/useAIGeneration.js.map +1 -0
- package/dist/esm/components/input/useGeneratingPlaceholder.js +38 -0
- package/dist/esm/components/input/useGeneratingPlaceholder.js.map +1 -0
- package/dist/esm/components/prompt-card/AssistantPromptCard.js +115 -0
- package/dist/esm/components/prompt-card/AssistantPromptCard.js.map +1 -0
- package/dist/esm/components/prompt-card/useAnimatedPlaceholder.js +68 -0
- package/dist/esm/components/prompt-card/useAnimatedPlaceholder.js.map +1 -0
- package/dist/esm/context/base.js +47 -0
- package/dist/esm/context/base.js.map +1 -0
- package/dist/esm/context/chat.js +78 -0
- package/dist/esm/context/chat.js.map +1 -0
- package/dist/esm/context/component.js +141 -0
- package/dist/esm/context/component.js.map +1 -0
- package/dist/esm/context/dashboard.js +49 -0
- package/dist/esm/context/dashboard.js.map +1 -0
- package/dist/esm/context/datasource.js +25 -0
- package/dist/esm/context/datasource.js.map +1 -0
- package/dist/esm/context/entity.js +35 -0
- package/dist/esm/context/entity.js.map +1 -0
- package/dist/esm/context/factory.js +60 -0
- package/dist/esm/context/factory.js.map +1 -0
- package/dist/esm/context/index.js +13 -0
- package/dist/esm/context/index.js.map +1 -0
- package/dist/esm/context/label.js +62 -0
- package/dist/esm/context/label.js.map +1 -0
- package/dist/esm/context/page.js +365 -0
- package/dist/esm/context/page.js.map +1 -0
- package/dist/esm/context/questions.js +111 -0
- package/dist/esm/context/questions.js.map +1 -0
- package/dist/esm/context/skill.js +28 -0
- package/dist/esm/context/skill.js.map +1 -0
- package/dist/esm/context/types.js +2 -0
- package/dist/esm/context/types.js.map +1 -0
- package/dist/esm/extension/extension.js +45 -0
- package/dist/esm/extension/extension.js.map +1 -0
- package/dist/esm/extension/index.js +2 -0
- package/dist/esm/extension/index.js.map +1 -0
- package/dist/esm/functions.js +22 -0
- package/dist/esm/functions.js.map +1 -0
- package/dist/esm/hook.js +23 -0
- package/dist/esm/hook.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/inline/index.js +3 -0
- package/dist/esm/inline/index.js.map +1 -0
- package/dist/esm/inline/inlineAssistant.js +75 -0
- package/dist/esm/inline/inlineAssistant.js.map +1 -0
- package/dist/esm/inline/types.js +2 -0
- package/dist/esm/inline/types.js.map +1 -0
- package/dist/esm/inline/useInlineAssistant.js +158 -0
- package/dist/esm/inline/useInlineAssistant.js.map +1 -0
- package/dist/esm/k6.js +33 -0
- package/dist/esm/k6.js.map +1 -0
- package/dist/esm/lens/index.js +3 -0
- package/dist/esm/lens/index.js.map +1 -0
- package/dist/esm/lens/investigationLens.js +103 -0
- package/dist/esm/lens/investigationLens.js.map +1 -0
- package/dist/esm/lens/types.js +2 -0
- package/dist/esm/lens/types.js.map +1 -0
- package/dist/esm/lens/useInvestigationThroughLens.js +125 -0
- package/dist/esm/lens/useInvestigationThroughLens.js.map +1 -0
- package/dist/esm/limits/index.js +140 -0
- package/dist/esm/limits/index.js.map +1 -0
- package/dist/esm/plugin.js +52 -0
- package/dist/esm/plugin.js.map +1 -0
- package/dist/esm/sidebar.js +81 -0
- package/dist/esm/sidebar.js.map +1 -0
- package/dist/esm/terms/index.js +136 -0
- package/dist/esm/terms/index.js.map +1 -0
- package/dist/esm/terms/settings.gen.js +6 -0
- package/dist/esm/terms/settings.gen.js.map +1 -0
- package/dist/esm/terms/versionCompare.js +83 -0
- package/dist/esm/terms/versionCompare.js.map +1 -0
- package/dist/esm/tools/index.js +2 -0
- package/dist/esm/tools/index.js.map +1 -0
- package/dist/esm/tools/toolFactory.js +64 -0
- package/dist/esm/tools/toolFactory.js.map +1 -0
- package/dist/esm/tools/types.js +2 -0
- package/dist/esm/tools/types.js.map +1 -0
- package/dist/esm/utils/errorHandling.js +95 -0
- package/dist/esm/utils/errorHandling.js.map +1 -0
- package/dist/esm/utils/hash.js +13 -0
- package/dist/esm/utils/hash.js.map +1 -0
- package/dist/esm/utils/theme.js +65 -0
- package/dist/esm/utils/theme.js.map +1 -0
- package/dist/extension/extension.d.ts +81 -20
- package/dist/extension/extension.d.ts.map +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/terms/settings.gen.d.ts +134 -0
- package/dist/terms/settings.gen.d.ts.map +1 -1
- package/package.json +12 -6
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
const GENERATING_PHRASES = [
|
|
3
|
+
'Generating...',
|
|
4
|
+
'Brewing...',
|
|
5
|
+
'Cooking...',
|
|
6
|
+
'Crunching...',
|
|
7
|
+
'Phrasing...',
|
|
8
|
+
'Wording...',
|
|
9
|
+
'Crafting...',
|
|
10
|
+
'Composing...',
|
|
11
|
+
'Drafting...',
|
|
12
|
+
'Shaping...',
|
|
13
|
+
'Forming...',
|
|
14
|
+
'Molding...',
|
|
15
|
+
'Sketching...',
|
|
16
|
+
'Whipping up...',
|
|
17
|
+
'Conjuring...',
|
|
18
|
+
'Stirring...',
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Returns a random placeholder phrase while generating, or the provided
|
|
22
|
+
* default placeholder when idle. A new phrase is picked each time generation starts.
|
|
23
|
+
*/
|
|
24
|
+
export function useGeneratingPlaceholder(isGenerating, defaultPlaceholder) {
|
|
25
|
+
const [phrase, setPhrase] = useState('');
|
|
26
|
+
const wasGenerating = useRef(false);
|
|
27
|
+
if (isGenerating && !wasGenerating.current) {
|
|
28
|
+
const next = GENERATING_PHRASES[Math.floor(Math.random() * GENERATING_PHRASES.length)];
|
|
29
|
+
setPhrase(next);
|
|
30
|
+
wasGenerating.current = true;
|
|
31
|
+
return next;
|
|
32
|
+
}
|
|
33
|
+
if (!isGenerating) {
|
|
34
|
+
wasGenerating.current = false;
|
|
35
|
+
}
|
|
36
|
+
return isGenerating ? phrase : defaultPlaceholder;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=useGeneratingPlaceholder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGeneratingPlaceholder.js","sourceRoot":"","sources":["../../../../src/components/input/useGeneratingPlaceholder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,MAAM,kBAAkB,GAAG;IACzB,eAAe;IACf,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,aAAa;IACb,YAAY;IACZ,aAAa;IACb,cAAc;IACd,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,gBAAgB;IAChB,cAAc;IACd,aAAa;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,YAAqB,EAAE,kBAA0B;IACxF,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACzC,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAEpC,IAAI,YAAY,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;QACvF,SAAS,CAAC,IAAI,CAAC,CAAC;QAChB,aAAa,CAAC,OAAO,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC;IAChC,CAAC;IAED,OAAO,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
3
|
+
import { IconButton, Input, useStyles2 } from '@grafana/ui';
|
|
4
|
+
import { css, cx, keyframes } from '@emotion/css';
|
|
5
|
+
import { reportInteraction } from '@grafana/runtime';
|
|
6
|
+
import { useAssistant } from '../../hook';
|
|
7
|
+
import { createBorderAnimation, getBackgroundGradientColors } from '../../utils/theme';
|
|
8
|
+
import { useAnimatedPlaceholder, DEFAULT_EXAMPLE_PROMPTS } from './useAnimatedPlaceholder';
|
|
9
|
+
/**
|
|
10
|
+
* A prompt card component that opens the Grafana Assistant with a user-typed prompt and context.
|
|
11
|
+
* Renders nothing if the assistant is not available. Positioning is the consumer's responsibility.
|
|
12
|
+
*/
|
|
13
|
+
export function AssistantPromptCard(props) {
|
|
14
|
+
const { isAvailable, openAssistant } = useAssistant();
|
|
15
|
+
if (!isAvailable || !openAssistant) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return _jsx(AssistantPromptCardView, { ...props, openAssistant: openAssistant });
|
|
19
|
+
}
|
|
20
|
+
export function AssistantPromptCardView({ origin, context, mode, placeholder, examplePrompts, animated = true, onClose, onSubmit, onClick, className, openAssistant, }) {
|
|
21
|
+
const [prompt, setPrompt] = useState('');
|
|
22
|
+
const inputRef = useRef(null);
|
|
23
|
+
const styles = useStyles2(getStyles);
|
|
24
|
+
const resolvedPrompts = examplePrompts !== null && examplePrompts !== void 0 ? examplePrompts : (placeholder !== undefined ? [] : DEFAULT_EXAMPLE_PROMPTS);
|
|
25
|
+
const staticPlaceholder = placeholder !== null && placeholder !== void 0 ? placeholder : 'Ask Assistant...';
|
|
26
|
+
const animatedPlaceholder = useAnimatedPlaceholder(staticPlaceholder, resolvedPrompts, prompt.length > 0);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
reportInteraction('grafana_assistant_app_prompt_card_displayed', { from: origin });
|
|
29
|
+
}, [origin]);
|
|
30
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: context is an intentional re-trigger to re-focus the input when the context changes
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const rafId = requestAnimationFrame(() => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); });
|
|
33
|
+
return () => cancelAnimationFrame(rafId);
|
|
34
|
+
}, [context]);
|
|
35
|
+
const submit = useCallback((text) => {
|
|
36
|
+
const trimmed = text.trim();
|
|
37
|
+
if (!trimmed) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
openAssistant({ prompt: trimmed, context, autoSend: true, origin, mode });
|
|
41
|
+
onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(trimmed);
|
|
42
|
+
setPrompt('');
|
|
43
|
+
}, [openAssistant, context, origin, mode, onSubmit]);
|
|
44
|
+
const handleKeyDown = (e) => {
|
|
45
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
submit(prompt);
|
|
48
|
+
}
|
|
49
|
+
if (e.key === 'Escape') {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return (_jsx("div", { className: cx(animated ? styles.card : styles.cardStatic, className), onClick: onClick, role: "search", "aria-label": staticPlaceholder, "data-testid": "assistant-prompt-card", children: _jsx("div", { className: styles.inputRow, children: _jsx(Input, { ref: inputRef, value: prompt, onChange: (e) => setPrompt(e.currentTarget.value), onKeyDown: handleKeyDown, placeholder: animatedPlaceholder, suffix: _jsx(IconButton, { name: "ai-sparkle", onClick: () => submit(prompt), disabled: !prompt.trim(), tooltip: "Send to assistant", "aria-label": "Send to assistant", "data-testid": "assistant-prompt-card-send" }), "data-testid": "assistant-prompt-card-input" }) }) }));
|
|
55
|
+
}
|
|
56
|
+
function getGlowShadow(theme) {
|
|
57
|
+
const baseShadow = theme.isDark ? 'rgb(17 18 23)' : 'rgb(245 245 245)';
|
|
58
|
+
return [
|
|
59
|
+
'rgba(168, 85, 247, 0.25) 3px -1px 20px',
|
|
60
|
+
'rgba(249, 115, 22, 0.18) -5px 3px 40px',
|
|
61
|
+
'rgba(168, 85, 247, 0.12) 7px 4px 60px',
|
|
62
|
+
`${baseShadow} 0 6px 30px`,
|
|
63
|
+
].join(', ');
|
|
64
|
+
}
|
|
65
|
+
const getStyles = (theme) => {
|
|
66
|
+
const backgroundColor = theme.colors.background.primary;
|
|
67
|
+
const [gradientColor1, gradientColor2] = getBackgroundGradientColors(theme);
|
|
68
|
+
const borderAnimation = keyframes({
|
|
69
|
+
label: 'prompt-card-border',
|
|
70
|
+
...createBorderAnimation(theme, backgroundColor),
|
|
71
|
+
});
|
|
72
|
+
const cardBase = {
|
|
73
|
+
label: 'assistant-prompt-card',
|
|
74
|
+
position: 'relative',
|
|
75
|
+
display: 'flex',
|
|
76
|
+
flexDirection: 'column',
|
|
77
|
+
gap: theme.spacing(1),
|
|
78
|
+
padding: theme.spacing(1),
|
|
79
|
+
borderRadius: theme.shape.radius.lg,
|
|
80
|
+
boxShadow: getGlowShadow(theme),
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
card: css({
|
|
84
|
+
...cardBase,
|
|
85
|
+
cornerShape: 'squircle',
|
|
86
|
+
background: backgroundColor,
|
|
87
|
+
border: '1px solid transparent',
|
|
88
|
+
backgroundImage: `
|
|
89
|
+
linear-gradient(${backgroundColor}, ${backgroundColor}),
|
|
90
|
+
conic-gradient(from 0deg, transparent 60%, ${gradientColor1} 80%, ${gradientColor2} 100%, transparent 15%)
|
|
91
|
+
`,
|
|
92
|
+
backgroundOrigin: 'border-box',
|
|
93
|
+
backgroundClip: 'padding-box, border-box',
|
|
94
|
+
[theme.transitions.handleMotion('no-preference')]: {
|
|
95
|
+
animation: `${borderAnimation} 2s linear infinite`,
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
cardStatic: css({
|
|
99
|
+
...cardBase,
|
|
100
|
+
label: 'assistant-prompt-card-static',
|
|
101
|
+
background: theme.colors.background.elevated,
|
|
102
|
+
border: `1px solid ${theme.colors.border.weak}`,
|
|
103
|
+
}),
|
|
104
|
+
inputRow: css({
|
|
105
|
+
label: 'prompt-card-input-row',
|
|
106
|
+
display: 'flex',
|
|
107
|
+
alignItems: 'center',
|
|
108
|
+
gap: theme.spacing(0.5),
|
|
109
|
+
'& input': {
|
|
110
|
+
border: 'none !important',
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=AssistantPromptCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssistantPromptCard.js","sourceRoot":"","sources":["../../../../src/components/prompt-card/AssistantPromptCard.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsB,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE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CAAC;YACZ,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YACvB,SAAS,EAAE;gBACT,MAAM,EAAE,iBAAiB;aAC1B;SACF,CAAC;KACH,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
const DEFAULT_EXAMPLE_PROMPTS = [
|
|
3
|
+
'What does this panel show?',
|
|
4
|
+
'Explain the trend in this data',
|
|
5
|
+
'Why is there a spike?',
|
|
6
|
+
'Add a threshold at 80%',
|
|
7
|
+
'Change the legend to table mode',
|
|
8
|
+
];
|
|
9
|
+
export { DEFAULT_EXAMPLE_PROMPTS };
|
|
10
|
+
export function useAnimatedPlaceholder(staticPlaceholder, prompts, hasUserInput) {
|
|
11
|
+
const [display, setDisplay] = useState('');
|
|
12
|
+
const indexRef = useRef(0);
|
|
13
|
+
const charRef = useRef(0);
|
|
14
|
+
const phaseRef = useRef('typing');
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
indexRef.current = 0;
|
|
17
|
+
charRef.current = 0;
|
|
18
|
+
phaseRef.current = 'typing';
|
|
19
|
+
setDisplay('');
|
|
20
|
+
if (hasUserInput || prompts.length === 0) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const tick = () => {
|
|
24
|
+
const currentPrompt = prompts[indexRef.current];
|
|
25
|
+
if (phaseRef.current === 'typing') {
|
|
26
|
+
charRef.current++;
|
|
27
|
+
setDisplay(currentPrompt.slice(0, charRef.current));
|
|
28
|
+
if (charRef.current >= currentPrompt.length) {
|
|
29
|
+
phaseRef.current = 'pause';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (phaseRef.current === 'pause') {
|
|
33
|
+
phaseRef.current = 'erasing';
|
|
34
|
+
}
|
|
35
|
+
else if (phaseRef.current === 'erasing') {
|
|
36
|
+
charRef.current--;
|
|
37
|
+
setDisplay(currentPrompt.slice(0, charRef.current));
|
|
38
|
+
if (charRef.current <= 0) {
|
|
39
|
+
phaseRef.current = 'typing';
|
|
40
|
+
indexRef.current = (indexRef.current + 1) % prompts.length;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const getDelay = () => {
|
|
45
|
+
if (phaseRef.current === 'pause') {
|
|
46
|
+
return 800;
|
|
47
|
+
}
|
|
48
|
+
if (phaseRef.current === 'erasing') {
|
|
49
|
+
return 15;
|
|
50
|
+
}
|
|
51
|
+
return 30 + Math.random() * 20;
|
|
52
|
+
};
|
|
53
|
+
let timeoutId;
|
|
54
|
+
const schedule = () => {
|
|
55
|
+
timeoutId = setTimeout(() => {
|
|
56
|
+
tick();
|
|
57
|
+
schedule();
|
|
58
|
+
}, getDelay());
|
|
59
|
+
};
|
|
60
|
+
schedule();
|
|
61
|
+
return () => clearTimeout(timeoutId);
|
|
62
|
+
}, [hasUserInput, prompts]);
|
|
63
|
+
if (hasUserInput || prompts.length === 0) {
|
|
64
|
+
return staticPlaceholder;
|
|
65
|
+
}
|
|
66
|
+
return display;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=useAnimatedPlaceholder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAnimatedPlaceholder.js","sourceRoot":"","sources":["../../../../src/components/prompt-card/useAnimatedPlaceholder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEpD,MAAM,uBAAuB,GAAG;IAC9B,4BAA4B;IAC5B,gCAAgC;IAChC,uBAAuB;IACvB,wBAAwB;IACxB,iCAAiC;CAClC,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,MAAM,UAAU,sBAAsB,CAAC,iBAAyB,EAAE,OAAiB,EAAE,YAAqB;IACxG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6
|
+
this.id = hash(params.id);
|
|
7
|
+
this.type = params.type;
|
|
8
|
+
}
|
|
9
|
+
/** Whether size limits should be bypassed for this context item. Defaults to false. */
|
|
10
|
+
get bypassLimits() {
|
|
11
|
+
var _a;
|
|
12
|
+
return (_a = this.params.bypassLimits) !== null && _a !== void 0 ? _a : false;
|
|
13
|
+
}
|
|
14
|
+
formatForLLM(codeElementIds) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
return {
|
|
17
|
+
type: this.type,
|
|
18
|
+
codeElementIds,
|
|
19
|
+
bypassLimits: this.bypassLimits,
|
|
20
|
+
data: {
|
|
21
|
+
name: (_a = this.params.text) !== null && _a !== void 0 ? _a : '',
|
|
22
|
+
text: (_b = this.params.text) !== null && _b !== void 0 ? _b : '',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
equals(other) {
|
|
27
|
+
if (!(other instanceof NodeData)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return this.id === other.id && this.type === other.type;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class StructuredNodeData extends NodeData {
|
|
34
|
+
constructor(params) {
|
|
35
|
+
super({ ...params, id: hash(JSON.stringify(params.data)), type: 'structured' });
|
|
36
|
+
this.data = params.data;
|
|
37
|
+
}
|
|
38
|
+
formatForLLM(codeElementIds) {
|
|
39
|
+
return {
|
|
40
|
+
type: this.type,
|
|
41
|
+
codeElementIds,
|
|
42
|
+
bypassLimits: this.bypassLimits,
|
|
43
|
+
data: this.data,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAkCrC,MAAM,OAAO,QAAQ;IAKnB,YAAmB,MAAsB;QAAtB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c;YACd,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { StructuredNodeData } from './base';
|
|
2
|
+
import { createContextByType } from './factory';
|
|
3
|
+
const defaultIcons = {
|
|
4
|
+
datasource: 'database',
|
|
5
|
+
label_name: 'database',
|
|
6
|
+
label_value: 'database',
|
|
7
|
+
dashboard: 'dashboard',
|
|
8
|
+
dashboard_folder: 'folder',
|
|
9
|
+
unknown: 'circle-mono',
|
|
10
|
+
structured: 'gf-grid',
|
|
11
|
+
component: 'gf-grid',
|
|
12
|
+
entity: 'asserts',
|
|
13
|
+
skill: 'play',
|
|
14
|
+
};
|
|
15
|
+
function getTitleFromContextNode(nodeData) {
|
|
16
|
+
var _a;
|
|
17
|
+
return nodeData instanceof StructuredNodeData
|
|
18
|
+
? nodeData.formatForLLM().data.name
|
|
19
|
+
: ((_a = nodeData.text) !== null && _a !== void 0 ? _a : 'Given Context');
|
|
20
|
+
}
|
|
21
|
+
function getImgFromContextNode(nodeData) {
|
|
22
|
+
if ('img' in nodeData) {
|
|
23
|
+
return nodeData.img;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new chat context item that can be added to conversations.
|
|
29
|
+
*
|
|
30
|
+
* This function creates structured context items that provide additional information
|
|
31
|
+
* to the AI assistant during conversations. Context items can include:
|
|
32
|
+
* - Datasources (metrics, logs, traces)
|
|
33
|
+
* - Labels and their values
|
|
34
|
+
* - Dashboards and folders
|
|
35
|
+
* - Structured data objects
|
|
36
|
+
*
|
|
37
|
+
* The created context item includes display metadata (title, icon, image) and
|
|
38
|
+
* the underlying data that will be formatted and sent to the LLM when the
|
|
39
|
+
* context is included in a conversation.
|
|
40
|
+
*
|
|
41
|
+
* @param type - The type of context to create (Datasource, Label, Dashboard etc.)
|
|
42
|
+
* @param params - Type-specific parameters for creating the context item
|
|
43
|
+
* @returns A ChatContextItem that can be added to conversation context
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Create a context that will be passed into the function triggering an assistant open
|
|
48
|
+
* openAssistant({
|
|
49
|
+
* ...
|
|
50
|
+
* origin: 'my-feature',
|
|
51
|
+
* context: [
|
|
52
|
+
* createAssistantContextItem('datasource', {
|
|
53
|
+
* datasourceUid: datasource.uid,
|
|
54
|
+
* img: datasource.meta?.info?.logos?.small,
|
|
55
|
+
* }),
|
|
56
|
+
* ],
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function createAssistantContextItem(type, params) {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
const nodeData = createContextByType(type, params);
|
|
63
|
+
const defaultTitle = (_a = params.title) !== null && _a !== void 0 ? _a : getTitleFromContextNode(nodeData);
|
|
64
|
+
const img = (_b = params.img) !== null && _b !== void 0 ? _b : getImgFromContextNode(nodeData);
|
|
65
|
+
return {
|
|
66
|
+
node: {
|
|
67
|
+
id: nodeData.id,
|
|
68
|
+
name: defaultTitle,
|
|
69
|
+
img,
|
|
70
|
+
icon: (_c = params.icon) !== null && _c !== void 0 ? _c : defaultIcons[type],
|
|
71
|
+
navigable: false,
|
|
72
|
+
selectable: true,
|
|
73
|
+
data: nodeData,
|
|
74
|
+
},
|
|
75
|
+
occurrences: [],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=chat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../src/context/chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAA4B,MAAM,WAAW,CAAC;AAG1E,MAAM,YAAY,GAAmC;IACnD,UAAU,EAAE,UAAU;IACtB,UAA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KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { NodeData } from './base';
|
|
3
|
+
import { providePageContext, usePageContext } from './page';
|
|
4
|
+
import { createAssistantContextItem } from './chat';
|
|
5
|
+
export class ComponentNodeData extends NodeData {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
const namespace = params.namespace || 'components';
|
|
8
|
+
super({ ...params, id: `${namespace}-${Object.keys(params.components).join('-')}`, type: 'component' });
|
|
9
|
+
this.components = params.components;
|
|
10
|
+
this.prompt = params.prompt;
|
|
11
|
+
this.namespace = namespace;
|
|
12
|
+
}
|
|
13
|
+
formatForLLM(codeElementIds) {
|
|
14
|
+
return {
|
|
15
|
+
type: this.type,
|
|
16
|
+
codeElementIds,
|
|
17
|
+
data: {
|
|
18
|
+
name: `Custom UI components (${this.namespace})`,
|
|
19
|
+
prompt: this.prompt
|
|
20
|
+
? this.prompt +
|
|
21
|
+
'\n\nIMPORTANT: The instructions and components described above are scoped to this specific context item only. Do not apply them to unrelated queries or components.'
|
|
22
|
+
: '',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* React hook that provides all components available globally.
|
|
29
|
+
* Components are available everywhere, regardless of URL patterns.
|
|
30
|
+
*
|
|
31
|
+
* @returns Object containing all components available globally, keyed by namespace.componentName
|
|
32
|
+
*/
|
|
33
|
+
export function usePageComponents() {
|
|
34
|
+
const pageContext = usePageContext({ allowComponents: true, allowQuestions: false });
|
|
35
|
+
// Use useMemo to avoid recreating the components object on every render
|
|
36
|
+
const components = useMemo(() => {
|
|
37
|
+
const allComponents = {};
|
|
38
|
+
// Filter for component context items and extract their components
|
|
39
|
+
for (const item of pageContext.filter((item) => { var _a; return (_a = item.node.data) === null || _a === void 0 ? void 0 : _a.components; })) {
|
|
40
|
+
const componentData = item.node.data;
|
|
41
|
+
if ((componentData === null || componentData === void 0 ? void 0 : componentData.components) && Object.keys(componentData.components).length > 0) {
|
|
42
|
+
const namespace = componentData.namespace || componentData.name || 'components';
|
|
43
|
+
// Add each component with namespace_componentName format
|
|
44
|
+
for (const [componentName, component] of Object.entries(componentData.components)) {
|
|
45
|
+
allComponents[`${namespace}_${componentName}`] = component;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return allComponents;
|
|
50
|
+
}, [pageContext]);
|
|
51
|
+
return components;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Provide components to the assistant.
|
|
55
|
+
*
|
|
56
|
+
* Components are always available globally, but the prompt is only applied when the URL pattern matches.
|
|
57
|
+
*
|
|
58
|
+
* For catch-all URL patterns, returns a setter that takes a context array.
|
|
59
|
+
* For specific URL patterns, returns a setter that takes components and prompt separately.
|
|
60
|
+
*
|
|
61
|
+
* @param prompt - The prompt to use for the components (only applied when URL matches).
|
|
62
|
+
* @param namespace - The namespace to use for the components.
|
|
63
|
+
* @param components - The components to provide (always available).
|
|
64
|
+
* @param urlPattern - The URL pattern to match for the prompt (components are always available).
|
|
65
|
+
* @returns A setter function to update the context, with an unregister method attached
|
|
66
|
+
*/
|
|
67
|
+
export function provideComponents(prompt, namespace, components, urlPattern = /.*/) {
|
|
68
|
+
// Check if the URL pattern is catch-all (.*) - if so, register everything together
|
|
69
|
+
const isCatchAll = (pattern) => {
|
|
70
|
+
if (pattern instanceof RegExp) {
|
|
71
|
+
return pattern.source === '.*' && pattern.flags === '';
|
|
72
|
+
}
|
|
73
|
+
return pattern === '.*' || pattern === '/.*/';
|
|
74
|
+
};
|
|
75
|
+
if (isCatchAll(urlPattern)) {
|
|
76
|
+
// If pattern is catch-all, register components and prompt together globally
|
|
77
|
+
const setContext = providePageContext(/.*/, [
|
|
78
|
+
createAssistantContextItem('component', {
|
|
79
|
+
components,
|
|
80
|
+
prompt,
|
|
81
|
+
namespace,
|
|
82
|
+
}),
|
|
83
|
+
]);
|
|
84
|
+
// Create a wrapper setter that matches the expected signature
|
|
85
|
+
const setter = (newComponents, newPrompt) => {
|
|
86
|
+
setContext([
|
|
87
|
+
createAssistantContextItem('component', {
|
|
88
|
+
components: newComponents,
|
|
89
|
+
prompt: newPrompt,
|
|
90
|
+
namespace,
|
|
91
|
+
}),
|
|
92
|
+
]);
|
|
93
|
+
};
|
|
94
|
+
// Attach unregister method
|
|
95
|
+
setter.unregister = setContext.unregister;
|
|
96
|
+
return setter;
|
|
97
|
+
}
|
|
98
|
+
// For specific URL patterns, separate components (global) from prompt (URL-specific)
|
|
99
|
+
const globalComponents = providePageContext(/.*/, [
|
|
100
|
+
createAssistantContextItem('component', {
|
|
101
|
+
components,
|
|
102
|
+
prompt: '', // No prompt for global components
|
|
103
|
+
namespace,
|
|
104
|
+
}),
|
|
105
|
+
]);
|
|
106
|
+
// Only register prompt for specific URL pattern
|
|
107
|
+
const promptContext = providePageContext(urlPattern, [
|
|
108
|
+
createAssistantContextItem('component', {
|
|
109
|
+
components: {}, // No components, just prompt
|
|
110
|
+
prompt,
|
|
111
|
+
namespace,
|
|
112
|
+
}),
|
|
113
|
+
]);
|
|
114
|
+
// Return a setter that properly separates components and prompt
|
|
115
|
+
// When updating, we extract components and prompt from the new data and update each registration appropriately
|
|
116
|
+
const setter = (newComponents, newPrompt) => {
|
|
117
|
+
// Update global components registration with new components (but empty prompt)
|
|
118
|
+
globalComponents([
|
|
119
|
+
createAssistantContextItem('component', {
|
|
120
|
+
components: newComponents,
|
|
121
|
+
prompt: '', // No prompt for global components
|
|
122
|
+
namespace,
|
|
123
|
+
}),
|
|
124
|
+
]);
|
|
125
|
+
// Update URL-specific registration with new prompt (but empty components)
|
|
126
|
+
promptContext([
|
|
127
|
+
createAssistantContextItem('component', {
|
|
128
|
+
components: {}, // No components, just prompt
|
|
129
|
+
prompt: newPrompt,
|
|
130
|
+
namespace,
|
|
131
|
+
}),
|
|
132
|
+
]);
|
|
133
|
+
};
|
|
134
|
+
// Attach unregister method that cleans up both registrations
|
|
135
|
+
setter.unregister = () => {
|
|
136
|
+
globalComponents.unregister();
|
|
137
|
+
promptContext.unregister();
|
|
138
|
+
};
|
|
139
|
+
return setter;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/context/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,OAAO,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAmB,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AAcpD,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAK7C,YAAY,MAAoC;QAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,YAAY,CAAC;QACnD,KAAK,CAAC,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;QACxG,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,YAAY,CAAC,cAAyB;QACpC,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,cAAc;YACd,IAAI,EAAE;gBACJ,IAAI,EAAE,yBAAyB,IAAI,CAAC,SAAS,GAAG;gBAChD,MAAM,EAAE,IAAI,CAAC,MAAM;oBACjB,CAAC,CAAC,IAAI,CAAC,MAAM;wBACX,qKAAqK;oBACvK,CAAC,CAAC,EAAE;a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G;IAC/G,MAAM,MAAM,GAAG,CAAC,aAAsD,EAAE,SAAiB,EAAE,EAAE;QAC3F,+EAA+E;QAC/E,gBAAgB,CAAC;YACf,0BAA0B,CAAC,WAAW,EAAE;gBACtC,UAAU,EAAE,aAAa;gBACzB,MAAM,EAAE,EAAE,EAAE,kCAAkC;gBAC9C,SAAS;aACV,CAAC;SACH,CAAC,CAAC;QAEH,0EAA0E;QAC1E,aAAa,CAAC;YACZ,0BAA0B,CAAC,WAAW,EAAE;gBACtC,UAAU,EAAE,EAAE,EAAE,6BAA6B;gBAC7C,MAAM,EAAE,SAAS;gBACjB,SAAS;aACV,CAAC;SACH,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,6DAA6D;IAC7D,MAAM,CAAC,UAAU,GAAG,GAAG,EAAE;QACvB,gBAAgB,CAAC,UAAU,EAAE,CAAC;QAC9B,aAAa,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { NodeData } from './base';
|
|
2
|
+
export class DashboardNodeData extends NodeData {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
super({ ...params, id: params.dashboardUid, type: 'dashboard' });
|
|
5
|
+
this.dashboardUid = params.dashboardUid;
|
|
6
|
+
this.dashboardTitle = params.dashboardTitle;
|
|
7
|
+
this.folderUid = params.folderUid;
|
|
8
|
+
this.folderTitle = params.folderTitle;
|
|
9
|
+
this.text = params.dashboardTitle;
|
|
10
|
+
}
|
|
11
|
+
formatForLLM(codeElementIds) {
|
|
12
|
+
return {
|
|
13
|
+
type: this.type,
|
|
14
|
+
codeElementIds,
|
|
15
|
+
bypassLimits: this.bypassLimits,
|
|
16
|
+
data: {
|
|
17
|
+
name: this.dashboardTitle,
|
|
18
|
+
dashboardUid: this.dashboardUid,
|
|
19
|
+
dashboardTitle: this.dashboardTitle,
|
|
20
|
+
folderUid: this.folderUid,
|
|
21
|
+
folderTitle: this.folderTitle,
|
|
22
|
+
text: this.text,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class FolderNodeData extends NodeData {
|
|
28
|
+
constructor(params) {
|
|
29
|
+
super({ ...params, id: params.folderUid, type: 'dashboard_folder' });
|
|
30
|
+
this.text = '';
|
|
31
|
+
this.folderUid = params.folderUid;
|
|
32
|
+
this.folderTitle = params.folderTitle;
|
|
33
|
+
this.text = params.folderTitle;
|
|
34
|
+
}
|
|
35
|
+
formatForLLM(codeElementIds) {
|
|
36
|
+
return {
|
|
37
|
+
type: this.type,
|
|
38
|
+
codeElementIds,
|
|
39
|
+
bypassLimits: this.bypassLimits,
|
|
40
|
+
data: {
|
|
41
|
+
name: this.folderTitle,
|
|
42
|
+
folderUid: this.folderUid,
|
|
43
|
+
folderTitle: this.folderTitle,
|
|
44
|
+
text: this.text,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=dashboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboard.js","sourceRoot":"","sources":["../../../src/context/dashboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAenD,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAM7C,YAAY,MAAoC;QAC9C,KAAK,CAAC,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,IAAI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
|
|
3
|
+
constructor(params) {
|
|
4
|
+
super({ ...params, id: params.datasourceUid, type: 'datasource' });
|
|
5
|
+
this.datasourceUid = params.datasourceUid;
|
|
6
|
+
this.datasourceType = params.datasourceType;
|
|
7
|
+
this.datasourceName = params.datasourceName;
|
|
8
|
+
this.img = params.img;
|
|
9
|
+
this.text = params.datasourceName;
|
|
10
|
+
}
|
|
11
|
+
formatForLLM(codeElementIds) {
|
|
12
|
+
return {
|
|
13
|
+
type: this.type,
|
|
14
|
+
codeElementIds,
|
|
15
|
+
bypassLimits: this.bypassLimits,
|
|
16
|
+
data: {
|
|
17
|
+
name: this.datasourceName,
|
|
18
|
+
uid: this.datasourceUid,
|
|
19
|
+
type: this.datasourceType,
|
|
20
|
+
text: this.text,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=datasource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../../src/context/datasource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAanD,MAAM,OAAO,kBAAmB,SAAQ,QAAQ;IAM9C,YAAY,MAAsD;QAChE,KAAK,CAAC,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC;IACpC,CAAC;IAED,YAAY,CAAC,cAAyB;QACpC,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,cAAc;YACd,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI,CAAC,cAAc;gBACzB,GAAG,EAAE,IAAI,CAAC,aAAa;gBACvB,IAAI,EAAE,IAAI,CAAC,cAAc;gBACzB,IAAI,EAAE,IAAI,CAAC,IAAI;aACa;SAC/B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { NodeData } from './base';
|
|
2
|
+
export class EntityNodeData extends NodeData {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
var _a, _b, _c;
|
|
5
|
+
super({
|
|
6
|
+
id: `${params.type}-${params.name}-${[(_a = params.scope) === null || _a === void 0 ? void 0 : _a.env, (_b = params.scope) === null || _b === void 0 ? void 0 : _b.site, (_c = params.scope) === null || _c === void 0 ? void 0 : _c.namespace].filter(Boolean).join('-')}`,
|
|
7
|
+
type: 'entity',
|
|
8
|
+
title: params.title,
|
|
9
|
+
hidden: params.hidden,
|
|
10
|
+
img: params.img,
|
|
11
|
+
icon: params.icon,
|
|
12
|
+
text: params.name,
|
|
13
|
+
});
|
|
14
|
+
this.entityType = params.type;
|
|
15
|
+
this.name = params.name;
|
|
16
|
+
this.scope = params.scope;
|
|
17
|
+
this.properties = params.properties;
|
|
18
|
+
this.text = params.name;
|
|
19
|
+
}
|
|
20
|
+
formatForLLM(codeElementIds) {
|
|
21
|
+
return {
|
|
22
|
+
type: 'entity',
|
|
23
|
+
codeElementIds,
|
|
24
|
+
bypassLimits: this.bypassLimits,
|
|
25
|
+
data: {
|
|
26
|
+
name: this.name,
|
|
27
|
+
text: this.text,
|
|
28
|
+
type: this.entityType,
|
|
29
|
+
scope: this.scope,
|
|
30
|
+
properties: this.properties,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=entity.js.map
|