@nethru/kit 1.1.14 → 1.1.17

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.
@@ -5,19 +5,21 @@ import ChatMessages from './ChatMessages';
5
5
  import ChatInput from './input/ChatInput';
6
6
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
7
  function AiChat({
8
- mainPageRef,
8
+ pageRef,
9
+ pagePath,
9
10
  sx
10
11
  }) {
11
12
  const {
12
13
  messages,
13
14
  isLoading,
14
15
  chatContainerRef,
15
- mainPageRef: _mainPageRef
16
+ pageRef: _pageRef,
17
+ setPagePath
16
18
  } = useChatContext();
17
19
  useEffect(() => {
18
- if (!mainPageRef) return;
19
- _mainPageRef.current = mainPageRef.current;
20
- }, [mainPageRef?.current]);
20
+ if (pageRef) _pageRef.current = pageRef.current;
21
+ setPagePath(pagePath);
22
+ }, [pageRef?.current, pagePath]);
21
23
  return /*#__PURE__*/_jsxs(Stack, {
22
24
  sx: {
23
25
  ...styles.container,
@@ -20,8 +20,9 @@ export function ChatProvider({
20
20
  const [option, setOption] = useState();
21
21
  const options = useMemo(() => defaultOptions);
22
22
  const [tools, setTools] = useState([]);
23
+ const [pagePath, setPagePath] = useState();
23
24
  const chatContainerRef = useRef(null);
24
- const mainPageRef = useRef(null);
25
+ const pageRef = useRef(null);
25
26
  useEffect(() => {
26
27
  loadModels();
27
28
  // loadTools();
@@ -78,11 +79,11 @@ export function ChatProvider({
78
79
  return await response.json();
79
80
  }
80
81
  async function analyzePage(message) {
81
- if (!mainPageRef.current) throw new Error('No main page');
82
+ if (!pageRef.current) throw new Error('No main page');
82
83
  const {
83
84
  apiUrl
84
85
  } = getConfig();
85
- const html = mainPageRef.current?.innerHTML;
86
+ const html = pageRef.current?.innerHTML;
86
87
  const response = await fetch(`${apiUrl}/api/pages/analyze`, {
87
88
  method: 'POST',
88
89
  headers: {
@@ -92,7 +93,7 @@ export function ChatProvider({
92
93
  conversationId: conversationId,
93
94
  message: message,
94
95
  htmlContent: html,
95
- pageUrl: window.location.href,
96
+ pagePath: pagePath,
96
97
  provider: provider,
97
98
  model: model,
98
99
  forceRefresh: true
@@ -114,7 +115,7 @@ export function ChatProvider({
114
115
  setInputValue('');
115
116
  setIsLoading(true);
116
117
  try {
117
- let data = option === 'analyze' ? await analyzePage(message) : await answer(message);
118
+ let data = option === 'ANALYZE' ? await analyzePage(message) : await answer(message);
118
119
  setConversationId(data.conversationId);
119
120
  setMessages(prev => [...prev, {
120
121
  role: data.role,
@@ -153,8 +154,10 @@ export function ChatProvider({
153
154
  option,
154
155
  setOption,
155
156
  tools,
157
+ pagePath,
158
+ setPagePath,
156
159
  chatContainerRef,
157
- mainPageRef,
160
+ pageRef,
158
161
  sendMessage,
159
162
  clearChat,
160
163
  conversationId
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { Box, Divider, MenuItem, Select } from "@mui/material";
3
3
  import { useChatContext } from "../contexts/ChatContext";
4
+ import typography from "@nethru/ui/base/styles/typography";
4
5
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
5
6
  export default function ModelSelect({
6
7
  ...props
@@ -26,7 +27,10 @@ export default function ModelSelect({
26
27
  onChange: onChange,
27
28
  disableUnderline: true,
28
29
  sx: styles.select,
29
- renderValue: value => findModel(providers, value)?.name,
30
+ renderValue: value => /*#__PURE__*/_jsx(Box, {
31
+ sx: styles.value,
32
+ children: findModel(providers, value)?.name
33
+ }),
30
34
  ...props,
31
35
  children: makeOptions(providers)
32
36
  })
@@ -41,10 +45,10 @@ function makeOptions(providers) {
41
45
  value: model.id,
42
46
  children: /*#__PURE__*/_jsxs(Box, {
43
47
  children: [/*#__PURE__*/_jsx(Box, {
44
- sx: styles.name,
48
+ sx: styles.option.name,
45
49
  children: model.name
46
50
  }), /*#__PURE__*/_jsx(Box, {
47
- sx: styles.desc,
51
+ sx: styles.option.desc,
48
52
  children: model.description
49
53
  })]
50
54
  })
@@ -72,12 +76,17 @@ const styles = {
72
76
  color: '#666',
73
77
  fontSize: '11px'
74
78
  },
75
- name: {
76
- fontWeight: 400,
77
- fontSize: '12px'
79
+ value: {
80
+ fontFamily: typography.fontFamily
78
81
  },
79
- desc: {
80
- fontSize: '11px',
81
- fontWeight: 200
82
+ option: {
83
+ name: {
84
+ fontWeight: 400,
85
+ fontSize: '12px'
86
+ },
87
+ desc: {
88
+ fontSize: '11px',
89
+ fontWeight: 200
90
+ }
82
91
  }
83
92
  };
@@ -27,7 +27,7 @@ export default function Options({
27
27
  value: option,
28
28
  onChange: (_, value) => setOption(value),
29
29
  children: options.map(o => /*#__PURE__*/_jsx(Tooltip, {
30
- title: o.label,
30
+ title: option === o.value ? "" : o.label,
31
31
  slotProps: {
32
32
  tooltip: {
33
33
  sx: styles.tooltip
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nethru/kit",
3
- "version": "1.1.14",
3
+ "version": "1.1.17",
4
4
  "description": "A React component library by Nethru",
5
5
  "main": "dist/index.js",
6
6
  "homepage": ".",