@grafana/assistant 0.1.32 → 0.1.33

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.
Files changed (101) hide show
  1. package/dist/esm/components/button/OpenAssistantButton.js +106 -0
  2. package/dist/esm/components/button/OpenAssistantButton.js.map +1 -0
  3. package/dist/esm/components/button/OpenAssistantSplitButton.js +135 -0
  4. package/dist/esm/components/button/OpenAssistantSplitButton.js.map +1 -0
  5. package/dist/esm/components/button/QueryWithAssistantButton.js +62 -0
  6. package/dist/esm/components/button/QueryWithAssistantButton.js.map +1 -0
  7. package/dist/esm/components/index.js +8 -0
  8. package/dist/esm/components/index.js.map +1 -0
  9. package/dist/esm/components/input/AITextArea.js +91 -0
  10. package/dist/esm/components/input/AITextArea.js.map +1 -0
  11. package/dist/esm/components/input/AITextInput.js +70 -0
  12. package/dist/esm/components/input/AITextInput.js.map +1 -0
  13. package/dist/esm/components/input/types.js +2 -0
  14. package/dist/esm/components/input/types.js.map +1 -0
  15. package/dist/esm/components/input/useAIGeneration.js +58 -0
  16. package/dist/esm/components/input/useAIGeneration.js.map +1 -0
  17. package/dist/esm/components/input/useGeneratingPlaceholder.js +38 -0
  18. package/dist/esm/components/input/useGeneratingPlaceholder.js.map +1 -0
  19. package/dist/esm/components/prompt-card/AssistantPromptCard.js +115 -0
  20. package/dist/esm/components/prompt-card/AssistantPromptCard.js.map +1 -0
  21. package/dist/esm/components/prompt-card/useAnimatedPlaceholder.js +68 -0
  22. package/dist/esm/components/prompt-card/useAnimatedPlaceholder.js.map +1 -0
  23. package/dist/esm/context/base.js +47 -0
  24. package/dist/esm/context/base.js.map +1 -0
  25. package/dist/esm/context/chat.js +78 -0
  26. package/dist/esm/context/chat.js.map +1 -0
  27. package/dist/esm/context/component.js +141 -0
  28. package/dist/esm/context/component.js.map +1 -0
  29. package/dist/esm/context/dashboard.js +49 -0
  30. package/dist/esm/context/dashboard.js.map +1 -0
  31. package/dist/esm/context/datasource.js +25 -0
  32. package/dist/esm/context/datasource.js.map +1 -0
  33. package/dist/esm/context/entity.js +35 -0
  34. package/dist/esm/context/entity.js.map +1 -0
  35. package/dist/esm/context/factory.js +60 -0
  36. package/dist/esm/context/factory.js.map +1 -0
  37. package/dist/esm/context/index.js +13 -0
  38. package/dist/esm/context/index.js.map +1 -0
  39. package/dist/esm/context/label.js +62 -0
  40. package/dist/esm/context/label.js.map +1 -0
  41. package/dist/esm/context/page.js +365 -0
  42. package/dist/esm/context/page.js.map +1 -0
  43. package/dist/esm/context/questions.js +111 -0
  44. package/dist/esm/context/questions.js.map +1 -0
  45. package/dist/esm/context/skill.js +28 -0
  46. package/dist/esm/context/skill.js.map +1 -0
  47. package/dist/esm/context/types.js +2 -0
  48. package/dist/esm/context/types.js.map +1 -0
  49. package/dist/esm/extension/extension.js +45 -0
  50. package/dist/esm/extension/extension.js.map +1 -0
  51. package/dist/esm/extension/index.js +2 -0
  52. package/dist/esm/extension/index.js.map +1 -0
  53. package/dist/esm/functions.js +22 -0
  54. package/dist/esm/functions.js.map +1 -0
  55. package/dist/esm/hook.js +23 -0
  56. package/dist/esm/hook.js.map +1 -0
  57. package/dist/esm/index.js +16 -0
  58. package/dist/esm/index.js.map +1 -0
  59. package/dist/esm/inline/index.js +3 -0
  60. package/dist/esm/inline/index.js.map +1 -0
  61. package/dist/esm/inline/inlineAssistant.js +75 -0
  62. package/dist/esm/inline/inlineAssistant.js.map +1 -0
  63. package/dist/esm/inline/types.js +2 -0
  64. package/dist/esm/inline/types.js.map +1 -0
  65. package/dist/esm/inline/useInlineAssistant.js +158 -0
  66. package/dist/esm/inline/useInlineAssistant.js.map +1 -0
  67. package/dist/esm/k6.js +33 -0
  68. package/dist/esm/k6.js.map +1 -0
  69. package/dist/esm/lens/index.js +3 -0
  70. package/dist/esm/lens/index.js.map +1 -0
  71. package/dist/esm/lens/investigationLens.js +103 -0
  72. package/dist/esm/lens/investigationLens.js.map +1 -0
  73. package/dist/esm/lens/types.js +2 -0
  74. package/dist/esm/lens/types.js.map +1 -0
  75. package/dist/esm/lens/useInvestigationThroughLens.js +125 -0
  76. package/dist/esm/lens/useInvestigationThroughLens.js.map +1 -0
  77. package/dist/esm/limits/index.js +140 -0
  78. package/dist/esm/limits/index.js.map +1 -0
  79. package/dist/esm/plugin.js +52 -0
  80. package/dist/esm/plugin.js.map +1 -0
  81. package/dist/esm/sidebar.js +81 -0
  82. package/dist/esm/sidebar.js.map +1 -0
  83. package/dist/esm/terms/index.js +136 -0
  84. package/dist/esm/terms/index.js.map +1 -0
  85. package/dist/esm/terms/settings.gen.js +6 -0
  86. package/dist/esm/terms/settings.gen.js.map +1 -0
  87. package/dist/esm/terms/versionCompare.js +83 -0
  88. package/dist/esm/terms/versionCompare.js.map +1 -0
  89. package/dist/esm/tools/index.js +2 -0
  90. package/dist/esm/tools/index.js.map +1 -0
  91. package/dist/esm/tools/toolFactory.js +64 -0
  92. package/dist/esm/tools/toolFactory.js.map +1 -0
  93. package/dist/esm/tools/types.js +2 -0
  94. package/dist/esm/tools/types.js.map +1 -0
  95. package/dist/esm/utils/errorHandling.js +95 -0
  96. package/dist/esm/utils/errorHandling.js.map +1 -0
  97. package/dist/esm/utils/hash.js +13 -0
  98. package/dist/esm/utils/hash.js.map +1 -0
  99. package/dist/esm/utils/theme.js +65 -0
  100. package/dist/esm/utils/theme.js.map +1 -0
  101. package/package.json +12 -6
@@ -0,0 +1,106 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect } from 'react';
3
+ import { Button, IconButton, useStyles2 } from '@grafana/ui';
4
+ import { css } from '@emotion/css';
5
+ import { useAssistant } from '../../hook';
6
+ import { reportInteraction } from '@grafana/runtime';
7
+ /**
8
+ * A button component that opens the Grafana Assistant with configurable prompt and context.
9
+ */
10
+ export function OpenAssistantButton(props) {
11
+ // If the assistant is not available, return empty
12
+ const { isAvailable, openAssistant } = useAssistant();
13
+ if (!isAvailable || !openAssistant) {
14
+ return null;
15
+ }
16
+ return _jsx(OpenAssistantButtonView, { ...props, openAssistant: openAssistant });
17
+ }
18
+ /**
19
+ * Presentational component separated from OpenAssistantButton to avoid hook dependencies in Storybook.
20
+ * It is not exported for users of the package.
21
+ */
22
+ export function OpenAssistantButtonView({ prompt, origin, context, autoSend = true, title = 'Analyze with Assistant', size = 'sm', iconOnlyButton = false, openAssistant, onClick, }) {
23
+ const styles = useStyles2(getStyles);
24
+ useEffect(() => {
25
+ reportInteraction('grafana_assistant_app_open_sidebar_button_displayed', {
26
+ from: origin,
27
+ });
28
+ }, [origin]);
29
+ return (_jsx(_Fragment, { children: iconOnlyButton ? (_jsx(IconButton, { name: "ai-sparkle", onClick: () => {
30
+ onClick === null || onClick === void 0 ? void 0 : onClick();
31
+ openAssistant({ prompt, context, autoSend, origin });
32
+ }, variant: "secondary", size: size, "aria-label": title, className: styles.icon, tooltip: title, "data-testid": "assistant-icon-button" })) : (_jsx(Button, { icon: "ai-sparkle", onClick: () => {
33
+ onClick === null || onClick === void 0 ? void 0 : onClick();
34
+ openAssistant({ prompt, context, autoSend, origin });
35
+ }, variant: "secondary", fill: "solid", size: size, title: title, "aria-label": title, className: styles.button, "data-testid": "assistant-button", children: title })) }));
36
+ }
37
+ const getStyles = (theme) => {
38
+ const baseBackground = theme.colors.secondary.main;
39
+ const elevatedBackground = theme.colors.emphasize(baseBackground, 0.05);
40
+ // Canvas is what's typically underneath buttons
41
+ const underlyingColor = theme.colors.background.canvas;
42
+ const borderWidth = 1;
43
+ const outerRadius = theme.shape.radius.default;
44
+ // inner radius = outer radius - border width, but take at least 1px
45
+ const innerRadius = `max(calc(${outerRadius} - ${borderWidth}px), 1px)`;
46
+ // Gradient border layer (::before)
47
+ const gradientBorderLayer = {
48
+ content: '""',
49
+ position: 'absolute',
50
+ inset: 0,
51
+ borderRadius: outerRadius,
52
+ cornerShape: 'squircle',
53
+ background: 'linear-gradient(90deg, rgb(168, 85, 247), rgb(249, 115, 22))',
54
+ zIndex: -2,
55
+ pointerEvents: 'none',
56
+ };
57
+ // Solid background layer factory (::after)
58
+ // Layer transparent color over canvas to make it opaque and mask the gradient properly
59
+ const solidBackgroundLayer = (background) => ({
60
+ content: '""',
61
+ position: 'absolute',
62
+ inset: `${borderWidth}px`,
63
+ borderRadius: innerRadius,
64
+ cornerShape: 'squircle',
65
+ background: `linear-gradient(${background}, ${background}), ${underlyingColor}`,
66
+ zIndex: -1,
67
+ transition: 'none',
68
+ pointerEvents: 'none',
69
+ });
70
+ return {
71
+ button: css({
72
+ label: 'assistant-button',
73
+ width: 'fit-content',
74
+ maxWidth: '100%',
75
+ position: 'relative',
76
+ isolation: 'isolate',
77
+ border: 'none',
78
+ transition: 'none !important',
79
+ '&::before': gradientBorderLayer,
80
+ '&::after': {
81
+ ...solidBackgroundLayer(baseBackground),
82
+ transition: 'none',
83
+ },
84
+ '&:hover': {
85
+ transition: 'none !important',
86
+ },
87
+ '&:hover::after': {
88
+ background: `linear-gradient(${elevatedBackground}, ${elevatedBackground}), ${underlyingColor}`,
89
+ },
90
+ }),
91
+ icon: css({
92
+ label: 'assistant-icon',
93
+ position: 'relative',
94
+ isolation: 'isolate',
95
+ border: 'none',
96
+ background: 'none',
97
+ padding: theme.spacing(0.5),
98
+ '&::before': { ...gradientBorderLayer, transition: 'background 0.1s ease' },
99
+ '&:hover::after': {
100
+ ...solidBackgroundLayer(baseBackground),
101
+ background: `linear-gradient(${elevatedBackground}, ${elevatedBackground}), ${underlyingColor}`,
102
+ },
103
+ }),
104
+ };
105
+ };
106
+ //# sourceMappingURL=OpenAssistantButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAssistantButton.js","sourceRoot":"","sources":["../../../../src/components/button/OpenAssistantButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,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AAkB,MAAM,eAAe,EAAE;aAChG;SACF,CAAC;KACH,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,135 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect } from 'react';
3
+ import { Button, ButtonGroup, Dropdown, Tooltip, useStyles2 } from '@grafana/ui';
4
+ import { css, cx } from '@emotion/css';
5
+ import { useAssistant } from '../../hook';
6
+ import { reportInteraction } from '@grafana/runtime';
7
+ const defaultDropdownButtonWidths = {
8
+ sm: 32,
9
+ md: 36,
10
+ lg: 40,
11
+ };
12
+ /**
13
+ * A split button component that opens the Grafana Assistant with a dropdown for additional actions.
14
+ * The gradient border wraps around both buttons as a unified control.
15
+ */
16
+ export function OpenAssistantSplitButton(props) {
17
+ const { isAvailable, openAssistant } = useAssistant();
18
+ if (!isAvailable || !openAssistant) {
19
+ return null;
20
+ }
21
+ return _jsx(OpenAssistantSplitButtonView, { ...props, openAssistant: openAssistant });
22
+ }
23
+ export function OpenAssistantSplitButtonView({ prompt, origin, context, autoSend = true, title = 'Chat with Assistant', size = 'sm', onClick, menuItems, tooltip, dropdownButtonWidth, openAssistant, }) {
24
+ const styles = useStyles2(getStyles);
25
+ const hasMenuItems = Boolean(menuItems);
26
+ const resolvedDropdownButtonWidth = toCssWidth(dropdownButtonWidth !== null && dropdownButtonWidth !== void 0 ? dropdownButtonWidth : defaultDropdownButtonWidths[size]);
27
+ useEffect(() => {
28
+ reportInteraction('grafana_assistant_app_open_sidebar_split_button_displayed', {
29
+ from: origin,
30
+ });
31
+ }, [origin]);
32
+ const handleMainClick = () => {
33
+ onClick === null || onClick === void 0 ? void 0 : onClick();
34
+ openAssistant({ prompt, context, autoSend, origin });
35
+ };
36
+ const wrapperContent = (_jsx("div", { className: styles.wrapper, children: _jsxs(ButtonGroup, { className: styles.buttonGroup, children: [_jsx(Button, { icon: "ai-sparkle", onClick: handleMainClick, variant: "secondary", fill: "solid", size: size, "aria-label": title, className: cx(styles.segmentButton, hasMenuItems ? styles.mainButtonSplit : styles.mainButtonSolo), "data-testid": "assistant-split-button-main", children: title }), menuItems && (_jsx(Dropdown, { overlay: menuItems, children: _jsx(Button, { variant: "secondary", icon: "angle-down", size: size, "aria-label": "More AI actions", className: cx(styles.segmentButton, styles.dropdownButton), style: { width: resolvedDropdownButtonWidth, minWidth: resolvedDropdownButtonWidth }, "data-testid": "assistant-split-button-dropdown" }) }))] }) }));
37
+ return tooltip ? _jsx(Tooltip, { content: tooltip, children: wrapperContent }) : wrapperContent;
38
+ }
39
+ const getStyles = (theme) => {
40
+ const baseBackground = theme.colors.secondary.main;
41
+ const elevatedBackground = theme.colors.emphasize(baseBackground, 0.05);
42
+ const underlyingColor = theme.colors.background.canvas;
43
+ const dividerColor = theme.colors.border.weak;
44
+ const borderWidth = 1;
45
+ const outerRadius = theme.shape.radius.default;
46
+ const innerRadius = `max(calc(${outerRadius} - ${borderWidth}px), 1px)`;
47
+ return {
48
+ wrapper: css({
49
+ label: 'assistant-split-button-wrapper',
50
+ position: 'relative',
51
+ isolation: 'isolate',
52
+ display: 'inline-block',
53
+ // Gradient border around the entire button group
54
+ '&::before': {
55
+ content: '""',
56
+ position: 'absolute',
57
+ inset: 0,
58
+ borderRadius: outerRadius,
59
+ cornerShape: 'squircle',
60
+ background: 'linear-gradient(90deg, rgb(168, 85, 247), rgb(249, 115, 22))',
61
+ zIndex: -1,
62
+ pointerEvents: 'none',
63
+ },
64
+ // Solid background layer
65
+ '&::after': {
66
+ content: '""',
67
+ position: 'absolute',
68
+ inset: `${borderWidth}px`,
69
+ borderRadius: innerRadius,
70
+ cornerShape: 'squircle',
71
+ background: `linear-gradient(${baseBackground}, ${baseBackground}), ${underlyingColor}`,
72
+ zIndex: -1,
73
+ pointerEvents: 'none',
74
+ },
75
+ }),
76
+ buttonGroup: css({
77
+ label: 'assistant-split-button-group',
78
+ gap: 0,
79
+ position: 'relative',
80
+ zIndex: 1,
81
+ borderRadius: innerRadius,
82
+ overflow: 'hidden',
83
+ // Make buttons transparent to show the wrapper's gradient
84
+ '& button': {
85
+ border: 'none',
86
+ boxShadow: 'none',
87
+ background: 'transparent !important',
88
+ },
89
+ }),
90
+ segmentButton: css({
91
+ label: 'assistant-split-button-segment',
92
+ position: 'relative',
93
+ '&:hover': {
94
+ background: `${elevatedBackground} !important`,
95
+ },
96
+ '&:focus-visible': {
97
+ background: `${elevatedBackground} !important`,
98
+ },
99
+ '&[aria-expanded="true"]': {
100
+ background: `${elevatedBackground} !important`,
101
+ },
102
+ }),
103
+ mainButtonSolo: css({
104
+ label: 'assistant-split-button-main-solo',
105
+ borderRadius: innerRadius,
106
+ }),
107
+ mainButtonSplit: css({
108
+ label: 'assistant-split-button-main-split',
109
+ borderTopLeftRadius: innerRadius,
110
+ borderBottomLeftRadius: innerRadius,
111
+ borderTopRightRadius: 0,
112
+ borderBottomRightRadius: 0,
113
+ }),
114
+ dropdownButton: css({
115
+ label: 'assistant-split-button-dropdown',
116
+ display: 'inline-flex',
117
+ alignItems: 'center',
118
+ justifyContent: 'center',
119
+ gap: 0,
120
+ borderTopLeftRadius: 0,
121
+ borderBottomLeftRadius: 0,
122
+ borderTopRightRadius: innerRadius,
123
+ borderBottomRightRadius: innerRadius,
124
+ padding: '0 !important',
125
+ boxShadow: `inset 1px 0 0 ${dividerColor}`,
126
+ '& svg': {
127
+ margin: 0,
128
+ },
129
+ }),
130
+ };
131
+ };
132
+ function toCssWidth(width) {
133
+ return typeof width === 'number' ? `${width}px` : width;
134
+ }
135
+ //# sourceMappingURL=OpenAssistantSplitButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAssistantSplitButton.js","sourceRoot":"","sources":["../../../../src/components/button/OpenAssistantSplitButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC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,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { CoreApp } from '@grafana/data';
3
+ import { createAssistantContextItem } from '../../context';
4
+ import { useAssistant } from '../../hook';
5
+ import { OpenAssistantButtonView } from './OpenAssistantButton';
6
+ function queryIsEmpty(query) {
7
+ const dataQueryProps = ['refId', 'hide', 'key', 'queryType', 'datasource'];
8
+ for (const key in query) {
9
+ if (key === 'label') {
10
+ continue;
11
+ }
12
+ if (!dataQueryProps.includes(key)) {
13
+ return false;
14
+ }
15
+ }
16
+ return true;
17
+ }
18
+ export function QueryWithAssistantButton({ size, currentQuery, queries, dataSourceInstanceSettings, app, datasourceApi, title = 'Query with Assistant', }) {
19
+ var _a;
20
+ const { isAvailable, openAssistant } = useAssistant();
21
+ if (!isAvailable || !openAssistant) {
22
+ return null;
23
+ }
24
+ const origin = `grafana/query-editor/${dataSourceInstanceSettings.type}/${(_a = app !== null && app !== void 0 ? app : CoreApp.Unknown) !== null && _a !== void 0 ? _a : 'unknown'}`;
25
+ const hasCurrentQuery = !queryIsEmpty(currentQuery);
26
+ const otherQueries = queries.filter((q) => q.refId !== currentQuery.refId && !queryIsEmpty(q));
27
+ const context = [
28
+ createAssistantContextItem('datasource', {
29
+ datasourceUid: dataSourceInstanceSettings.uid,
30
+ }),
31
+ ];
32
+ if (hasCurrentQuery) {
33
+ context.push(createAssistantContextItem('structured', {
34
+ title: 'Current query',
35
+ data: currentQuery,
36
+ }));
37
+ }
38
+ if (otherQueries.length > 0) {
39
+ context.push(createAssistantContextItem('structured', {
40
+ title: 'Other queries',
41
+ data: {
42
+ queries: otherQueries,
43
+ },
44
+ }));
45
+ }
46
+ const queryDisplayText = hasCurrentQuery && (datasourceApi === null || datasourceApi === void 0 ? void 0 : datasourceApi.getQueryDisplayText) ? datasourceApi.getQueryDisplayText(currentQuery) : null;
47
+ const isUpdating = !!queryDisplayText;
48
+ const actionText = isUpdating
49
+ ? 'Help me update the current query to answer my questions and provide the insights I need.'
50
+ : 'Help me create a new query to answer my questions and provide the insights I need.';
51
+ const codeBlockLines = [];
52
+ if (queryDisplayText) {
53
+ codeBlockLines.push(`Current query: ${queryDisplayText}`);
54
+ }
55
+ codeBlockLines.push(`Selected data source: ${dataSourceInstanceSettings.name}`);
56
+ const actionableSentence = isUpdating
57
+ ? 'Please describe what you want to change or improve in this query.'
58
+ : "Please describe what you want to query and what insights you're looking for.";
59
+ const prompt = [actionText, '```', ...codeBlockLines, '```', actionableSentence].join('\n');
60
+ return (_jsx(OpenAssistantButtonView, { prompt: prompt, origin: origin, context: context, autoSend: false, title: title, size: size, openAssistant: openAssistant }));
61
+ }
62
+ //# sourceMappingURL=QueryWithAssistantButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryWithAssistantButton.js","sourceRoot":"","sources":["../../../../src/components/button/QueryWithAssistantButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAuD,MAAM,eAAe,CAAC;AAG7F,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,SAAS,YAAY,CAAC,KAAgB;IACpC,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAE3E,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;YACpB,SAAS;QACX,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAYD,MAAM,UAAU,wBAAwB,CAAuC,EAC7E,IAAI,EACJ,YAAY,EACZ,OAAO,EACP,0BA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,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEjH,MAAM,UAAU,GAAG,CAAC,CAAC,gBAAgB,CAAC;IACtC,MAAM,UAAU,GAAG,UAAU;QAC3B,CAAC,CAAC,0FAA0F;QAC5F,CAAC,CAAC,oFAAoF,CAAC;IAEzF,MAAM,cAAc,GAAa,EAAE,CAAC;IAEpC,IAAI,gBAAgB,EAAE,CAAC;QACrB,cAAc,CAAC,IAAI,CAAC,kBAAkB,gBAAgB,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,cAAc,CAAC,IAAI,CAAC,yBAAyB,0BAA0B,CAAC,IAAI,EAAE,CAAC,CAAC;IAEhF,MAAM,kBAAkB,GAAG,UAAU;QACnC,CAAC,CAAC,mEAAmE;QACrE,CAAC,CAAC,8EAA8E,CAAC;IAEnF,MAAM,MAAM,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,cAAc,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE5F,OAAO,CACL,KAAC,uBAAuB,IACtB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,KAAK,EACf,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,aAAa,GAC5B,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { OpenAssistantButton } from './button/OpenAssistantButton';
2
+ export { OpenAssistantSplitButton } from './button/OpenAssistantSplitButton';
3
+ export { AITextInput } from './input/AITextInput';
4
+ export { AITextArea } from './input/AITextArea';
5
+ export { useAIGeneration } from './input/useAIGeneration';
6
+ export { QueryWithAssistantButton } from './button/QueryWithAssistantButton';
7
+ export { AssistantPromptCard, AssistantPromptCardView, } from './prompt-card/AssistantPromptCard';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAiC,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAsC,MAAM,mCAAmC,CAAC;AACjH,OAAO,EAAE,WAAW,EAAyB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAwB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,eAAe,EAA+B,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,wBAAwB,EAAsC,MAAM,mCAAmC,CAAC;AACjH,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAGxB,MAAM,mCAAmC,CAAC"}
@@ -0,0 +1,91 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { TextArea, IconButton, useStyles2 } from '@grafana/ui';
3
+ import { css, cx, keyframes } from '@emotion/css';
4
+ import { createBorderAnimation, getBackgroundGradientColors } from '../../utils/theme';
5
+ import { useAIGeneration } from './useAIGeneration';
6
+ import { useGeneratingPlaceholder } from './useGeneratingPlaceholder';
7
+ /**
8
+ * An AI-powered controlled textarea component that uses the Grafana Assistant engine to generate content.
9
+ * Features an integrated send button as well as a gradient border animation while generating.
10
+ */
11
+ export function AITextArea({ value, onChange, placeholder, origin, systemPrompt, onComplete, onError, onDelta, disabled = false, autoGenerate = false, streaming = false, getUserPrompt, rows = 4, className, 'data-testid': dataTestId, }) {
12
+ const { displayValue, isSendDisabled, handleGenerate, isGenerating, error } = useAIGeneration({
13
+ value,
14
+ onChange,
15
+ origin,
16
+ systemPrompt,
17
+ onComplete,
18
+ onError,
19
+ onDelta,
20
+ disabled,
21
+ autoGenerate,
22
+ streaming,
23
+ getUserPrompt,
24
+ });
25
+ const styles = useStyles2(getStyles);
26
+ const activePlaceholder = useGeneratingPlaceholder(isGenerating, placeholder !== null && placeholder !== void 0 ? placeholder : 'Ask AI to generate... (Cmd/Ctrl+Enter to send)');
27
+ const effectiveRows = Math.max(rows, 2);
28
+ const handleKeyDown = (e) => {
29
+ // Cmd/Ctrl + Enter to send
30
+ if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
31
+ e.preventDefault();
32
+ handleGenerate();
33
+ }
34
+ };
35
+ return (_jsxs("div", { className: cx(styles.textareaWrapper, { [styles.animatedWrapper]: isGenerating }, className), "data-testid": dataTestId, children: [_jsx(TextArea, { value: displayValue, onKeyDown: handleKeyDown, onChange: (e) => onChange(e.currentTarget.value), placeholder: activePlaceholder, disabled: disabled || isGenerating, rows: effectiveRows, className: styles.textarea, invalid: !!error, "data-testid": dataTestId ? `${dataTestId}-textarea` : undefined }), _jsx(IconButton, { name: "ai-sparkle", onClick: handleGenerate, disabled: isSendDisabled, className: styles.sendButton, "aria-label": "Generate with AI", tooltip: isSendDisabled ? 'Enter text to generate' : 'Generate with AI (Cmd/Ctrl+Enter)', "data-testid": dataTestId ? `${dataTestId}-send` : undefined })] }));
36
+ }
37
+ const getStyles = (theme) => {
38
+ const backgroundColor = theme.colors.background.primary;
39
+ const borderAnimation = keyframes({
40
+ label: 'ai-textarea-border-animation',
41
+ ...createBorderAnimation(theme, backgroundColor),
42
+ });
43
+ const [gradientColor1, gradientColor2] = getBackgroundGradientColors(theme);
44
+ return {
45
+ textareaWrapper: css({
46
+ label: 'ai-textarea-wrapper',
47
+ position: 'relative',
48
+ border: '1px solid transparent',
49
+ borderRadius: theme.shape.radius.default,
50
+ cornerShape: 'squircle',
51
+ }),
52
+ animatedWrapper: css({
53
+ label: 'ai-textarea-animated',
54
+ border: '1px solid transparent',
55
+ // Set initial backgroundImage with both gradients so Chrome can animate properly
56
+ backgroundImage: `
57
+ linear-gradient(${backgroundColor}, ${backgroundColor}),
58
+ conic-gradient(from 0deg, transparent 60%, ${gradientColor1} 80%, ${gradientColor2} 100%, transparent 15%)
59
+ `,
60
+ backgroundOrigin: 'border-box',
61
+ backgroundClip: 'padding-box, border-box',
62
+ animation: `${borderAnimation} 2s linear infinite`,
63
+ '& textarea': {
64
+ // Remove the default border from the textarea when animated wrapper is active
65
+ border: 'none !important',
66
+ },
67
+ }),
68
+ textarea: css({
69
+ label: 'ai-textarea',
70
+ // ensures the text does not "underflow" the send button
71
+ paddingRight: theme.spacing(4),
72
+ // Keep at least a 2-row visual height even if outer styles try to shrink the control
73
+ minHeight: theme.spacing(6),
74
+ '& textarea': {
75
+ minHeight: theme.spacing(6),
76
+ },
77
+ // Hide scrollbar
78
+ scrollbarWidth: 'none', // Firefox
79
+ '&::-webkit-scrollbar': {
80
+ display: 'none', // Chrome, Safari, Edge
81
+ },
82
+ }),
83
+ sendButton: css({
84
+ label: 'ai-textarea-send',
85
+ position: 'absolute',
86
+ right: theme.spacing(1),
87
+ top: theme.spacing(1),
88
+ }),
89
+ };
90
+ };
91
+ //# sourceMappingURL=AITextArea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AITextArea.js","sourceRoot":"","sources":["../../../../src/components/input/AITextArea.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAEvF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAOtE;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,QAAQ,EACR,WAAW,EACX,MAAM,EACN,YAAY,EACZ,UAAU,EACV,OAAO,EACP,OAAO,EACP,QAAQ,GAAG,KAAK,EAChB,YAAY,GAAG,KAAK,EACpB,SAAS,GAAG,KAAK,EACjB,aAAa,EACb,IAAI,GAAG,CAAC,EACR,SAAS,EACT,aAAa,EAAE,UAAU,GACT;IAChB,MAAM,EAAE,YAAY,EAAE,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C9E,MAAM,EAAE,iBAAiB;aAC1B;SACF,CAAC;QACF,QAAQ,EAAE,GAAG,CAAC;YACZ,KAAK,EAAE,aAAa;YACpB,wDAAwD;YACxD,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YAC9B,qFAAqF;YACrF,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YAC3B,YAAY,EAAE;gBACZ,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;aAC5B;YACD,iBAAiB;YACjB,cAAc,EAAE,MAAM,EAAE,UAAU;YAClC,sBAAsB,EAAE;gBACtB,OAAO,EAAE,MAAM,EAAE,uBAAuB;aACzC;SACF,CAAC;QACF,UAAU,EAAE,GAAG,CAAC;YACd,KAAK,EAAE,kBAAkB;YACzB,QAAQ,EAAE,UAAU;YACpB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YACvB,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;SACtB,CAAC;KACH,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Input, IconButton, useStyles2 } from '@grafana/ui';
3
+ import { css, cx, keyframes } from '@emotion/css';
4
+ import { createBorderAnimation, getBackgroundGradientColors } from '../../utils/theme';
5
+ import { useAIGeneration } from './useAIGeneration';
6
+ import { useGeneratingPlaceholder } from './useGeneratingPlaceholder';
7
+ /**
8
+ * An AI-powered controlled text input component that uses the Grafana Assistant engine to generate content.
9
+ * Features an integrated send button as well as a gradient border animation while generating.
10
+ */
11
+ export function AITextInput({ value, onChange, placeholder, origin, systemPrompt, onComplete, onError, onDelta, disabled = false, autoGenerate = false, streaming = false, getUserPrompt, className, 'data-testid': dataTestId, }) {
12
+ const { displayValue, isSendDisabled, handleGenerate, isGenerating, error } = useAIGeneration({
13
+ value,
14
+ onChange,
15
+ origin,
16
+ systemPrompt,
17
+ onComplete,
18
+ onError,
19
+ onDelta,
20
+ disabled,
21
+ autoGenerate,
22
+ streaming,
23
+ getUserPrompt,
24
+ });
25
+ const styles = useStyles2(getStyles);
26
+ const activePlaceholder = useGeneratingPlaceholder(isGenerating, placeholder !== null && placeholder !== void 0 ? placeholder : 'Ask AI to generate...');
27
+ const handleKeyDown = (e) => {
28
+ // Cmd/Ctrl + Enter to send
29
+ if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
30
+ e.preventDefault();
31
+ handleGenerate();
32
+ }
33
+ };
34
+ const addonAfter = (_jsx(IconButton, { name: "ai-sparkle", onClick: handleGenerate, disabled: isSendDisabled, tooltip: isSendDisabled ? 'Enter text to generate' : 'Generate with AI', "data-testid": dataTestId ? `${dataTestId}-send` : undefined }));
35
+ return (_jsx("div", { className: cx(styles.wrapper, { [styles.animatedWrapper]: isGenerating }, className), "data-testid": dataTestId, children: _jsx(Input, { value: displayValue, onKeyDown: handleKeyDown, onChange: (e) => onChange(e.currentTarget.value), placeholder: activePlaceholder, disabled: disabled || isGenerating, suffix: addonAfter, invalid: !!error, "data-testid": dataTestId ? `${dataTestId}-input` : undefined }) }));
36
+ }
37
+ const getStyles = (theme) => {
38
+ const backgroundColor = theme.colors.background.primary;
39
+ const borderAnimation = keyframes({
40
+ label: 'ai-input-border-animation',
41
+ ...createBorderAnimation(theme, backgroundColor),
42
+ });
43
+ const [gradientColor1, gradientColor2] = getBackgroundGradientColors(theme);
44
+ return {
45
+ wrapper: css({
46
+ label: 'ai-text-input-wrapper',
47
+ position: 'relative',
48
+ border: '1px solid transparent',
49
+ borderRadius: theme.shape.radius.default,
50
+ cornerShape: 'squircle',
51
+ }),
52
+ animatedWrapper: css({
53
+ label: 'ai-text-input-animated',
54
+ border: '1px solid transparent',
55
+ // Set initial backgroundImage with both gradients so Chrome can animate properly
56
+ backgroundImage: `
57
+ linear-gradient(${backgroundColor}, ${backgroundColor}),
58
+ conic-gradient(from 0deg, transparent 60%, ${gradientColor1} 80%, ${gradientColor2} 100%, transparent 15%)
59
+ `,
60
+ backgroundOrigin: 'border-box',
61
+ backgroundClip: 'padding-box, border-box',
62
+ animation: `${borderAnimation} 2s linear infinite`,
63
+ '& input': {
64
+ // Remove the default border from the input when animated wrapper is active
65
+ border: 'none !important',
66
+ },
67
+ }),
68
+ };
69
+ };
70
+ //# sourceMappingURL=AITextInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AITextInput.js","sourceRoot":"","sources":["../../../../src/components/input/AITextInput.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAEvF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAItE;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EAC1B,KAAK,EACL,QAAQ,EACR,WAAW,EACX,MAAM,EACN,YAAY,EACZ,UAAU,EACV,OAAO,EACP,OAAO,EACP,QAAQ,GAAG,KAAK,EAChB,YAAY,GAAG,KAAK,EACpB,SAAS,GAAG,KAAK,EACjB,aAAa,EACb,SAAS,EACT,aAAa,EAAE,UAAU,GACR;IACjB,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,eAAe,CAAC;QAC5F,KAAK;QACL,QAAQ;QACR,MAAM;QACN,YAAY;QACZ,UAAU;QACV,OAAO;QACP,OAAO;QACP,QAAQ;QACR,YAAY;QACZ,SAAS;QACT,aAAa;KACd,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,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,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC;IACxD,MAAM,eAAe,GAAG,SAAS,CAAC;QAChC,KAAK,EAAE,2BAA2B;QAClC,GAAG,qBAAqB,CAAC,KAAK,EAAE,eAAe,CAAC;KACjD,CAAC,CAAC;IAEH,MAAM,CAAC,cAAc,EAAE,cAAc,CAAC,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAE5E,OAAO;QACL,OAAO,EAAE,GAAG,CAAC;YACX,KAAK,EAAE,uBAAuB;YAC9B,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,uBAAuB;YAC/B,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO;YACxC,WAAW,EAAE,UAAU;SACxB,CAAC;QACF,eAAe,EAAE,GAAG,CAAC;YACnB,KAAK,EAAE,wBAAwB;YAC/B,MAAM,EAAE,uBAAuB;YAC/B,iFAAiF;YACjF,eAAe,EAAE;0BACG,eAAe,KAAK,eAAe;qDACR,cAAc,SAAS,cAAc;OACnF;YACD,gBAAgB,EAAE,YAAY;YAC9B,cAAc,EAAE,yBAAyB;YACzC,SAAS,EAAE,GAAG,eAAe,qBAAqB;YAClD,SAAS,EAAE;gBACT,2EAA2E;gBAC3E,MAAM,EAAE,iBAAiB;aAC1B;SACF,CAAC;KACH,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/input/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,58 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { useInlineAssistant } from '../../inline/useInlineAssistant';
3
+ export function useAIGeneration({ value, onChange, origin, systemPrompt, onComplete, onError, onDelta, disabled = false, autoGenerate = false, streaming = false, getUserPrompt, }) {
4
+ const { generate, isGenerating, content, error, reset } = useInlineAssistant();
5
+ const hasAutoGenerated = useRef(false);
6
+ const valueBeforeGeneration = useRef(value);
7
+ const getUserPromptRef = useRef(getUserPrompt);
8
+ getUserPromptRef.current = getUserPrompt;
9
+ const displayValue = isGenerating ? (streaming ? content : '') : value;
10
+ const resolvedPrompt = getUserPrompt ? getUserPrompt(value.trim()) : value.trim();
11
+ const isSendDisabled = !resolvedPrompt || disabled || isGenerating;
12
+ const doGenerate = useCallback((prompt) => {
13
+ valueBeforeGeneration.current = value;
14
+ onChange('');
15
+ reset();
16
+ generate({
17
+ prompt,
18
+ origin,
19
+ systemPrompt,
20
+ onDelta,
21
+ onComplete: (text) => {
22
+ onChange(text);
23
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(text);
24
+ },
25
+ onError: (err) => {
26
+ onChange(valueBeforeGeneration.current);
27
+ onError === null || onError === void 0 ? void 0 : onError(err);
28
+ },
29
+ });
30
+ }, [value, onChange, origin, systemPrompt, onDelta, onComplete, onError, generate, reset]);
31
+ // Auto-generate at most once, on mount, evaluating the props as they are at mount.
32
+ const maybeAutoGenerateRef = useRef(() => { });
33
+ maybeAutoGenerateRef.current = () => {
34
+ if (autoGenerate && systemPrompt && !value && !hasAutoGenerated.current && !disabled) {
35
+ hasAutoGenerated.current = true;
36
+ doGenerate(systemPrompt);
37
+ }
38
+ };
39
+ useEffect(() => {
40
+ maybeAutoGenerateRef.current();
41
+ }, []);
42
+ const handleGenerate = useCallback(() => {
43
+ const fn = getUserPromptRef.current;
44
+ const prompt = fn ? fn(value.trim()) : value.trim();
45
+ if (!prompt || disabled || isGenerating) {
46
+ return;
47
+ }
48
+ doGenerate(prompt);
49
+ }, [value, disabled, isGenerating, doGenerate]);
50
+ return {
51
+ displayValue,
52
+ isSendDisabled,
53
+ handleGenerate,
54
+ isGenerating,
55
+ error,
56
+ };
57
+ }
58
+ //# sourceMappingURL=useAIGeneration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAIGeneration.js","sourceRoot":"","sources":["../../../../src/components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,IAAI,QAAQ,IAAI,YAAY,EAAE,CAAC;YACxC,OAAO;QACT,CAAC;QACD,UAAU,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;IAEhD,OAAO;QACL,YAAY;QACZ,cAAc;QACd,cAAc;QACd,YAAY;QACZ,KAAK;KACN,CAAC;AACJ,CAAC"}
@@ -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"}