llmasaservice-ui 0.2.14 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -24,6 +24,9 @@ interface ChatPanelProps {
24
24
  scrollToEnd?: boolean;
25
25
  prismStyle?: PrismStyle;
26
26
  service?: string | null;
27
+ historyChangedCallback?: (history: {
28
+ [prompt: string]: string;
29
+ }) => void;
27
30
  }
28
31
  interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
29
32
  inline?: boolean;
package/dist/index.d.ts CHANGED
@@ -24,6 +24,9 @@ interface ChatPanelProps {
24
24
  scrollToEnd?: boolean;
25
25
  prismStyle?: PrismStyle;
26
26
  service?: string | null;
27
+ historyChangedCallback?: (history: {
28
+ [prompt: string]: string;
29
+ }) => void;
27
30
  }
28
31
  interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
29
32
  inline?: boolean;
package/dist/index.js CHANGED
@@ -71,7 +71,7 @@ var import_remark_gfm = __toESM(require("remark-gfm"));
71
71
  var import_react_syntax_highlighter = require("react-syntax-highlighter");
72
72
  var import_material_dark = __toESM(require("react-syntax-highlighter/dist/cjs/styles/prism/material-dark.js"));
73
73
  var import_material_light = __toESM(require("react-syntax-highlighter/dist/cjs/styles/prism/material-light.js"));
74
- var ChatPanel = (0, import_react.forwardRef)(({
74
+ var ChatPanel = ({
75
75
  project_id,
76
76
  initialPrompt = "",
77
77
  title = "Chat",
@@ -89,17 +89,14 @@ var ChatPanel = (0, import_react.forwardRef)(({
89
89
  scrollToEnd = false,
90
90
  initialMessage = "",
91
91
  prismStyle = theme === "light" ? import_material_light.default : import_material_dark.default,
92
- service = null
93
- }, ref) => {
92
+ service = null,
93
+ historyChangedCallback = null
94
+ }) => {
94
95
  const { send, response, idle, stop } = (0, import_llmasaservice_client.useLLM)({
95
96
  project_id,
96
97
  customer,
97
98
  url
98
99
  });
99
- (0, import_react.useImperativeHandle)(ref, () => ({
100
- getHistory: () => history,
101
- setHistory: (newHistory) => setHistory(newHistory)
102
- }));
103
100
  const [nextPrompt, setNextPrompt] = (0, import_react.useState)("");
104
101
  const [lastController, setLastController] = (0, import_react.useState)(new AbortController());
105
102
  const [history, setHistory] = (0, import_react.useState)({});
@@ -153,6 +150,11 @@ var ChatPanel = (0, import_react.forwardRef)(({
153
150
  }
154
151
  }
155
152
  }, [response, history]);
153
+ (0, import_react.useEffect)(() => {
154
+ if (historyChangedCallback) {
155
+ historyChangedCallback(history);
156
+ }
157
+ }, [history, historyChangedCallback]);
156
158
  const continueChat = () => {
157
159
  if (!idle) {
158
160
  stop(lastController);
@@ -182,6 +184,9 @@ var ChatPanel = (0, import_react.forwardRef)(({
182
184
  setNextPrompt("");
183
185
  }
184
186
  };
187
+ const replaceHistory = (newHistory) => {
188
+ setHistory(newHistory);
189
+ };
185
190
  function copyToClipboard(text) {
186
191
  navigator.clipboard.writeText(text);
187
192
  }
@@ -356,7 +361,7 @@ var ChatPanel = (0, import_react.forwardRef)(({
356
361
  /* @__PURE__ */ import_react.default.createElement("path", { d: "M8 8h16v16H8z" })
357
362
  )))
358
363
  ));
359
- });
364
+ };
360
365
  var ChatPanel_default = ChatPanel;
361
366
  // Annotate the CommonJS export names for ESM import in node:
362
367
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -32,13 +32,13 @@ var __objRest = (source, exclude) => {
32
32
 
33
33
  // src/ChatPanel.tsx
34
34
  import { useLLM } from "llmasaservice-client";
35
- import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
35
+ import React, { useEffect, useRef, useState } from "react";
36
36
  import ReactMarkdown from "react-markdown";
37
37
  import remarkGfm from "remark-gfm";
38
38
  import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
39
39
  import materialDark from "react-syntax-highlighter/dist/cjs/styles/prism/material-dark.js";
40
40
  import materialLight from "react-syntax-highlighter/dist/cjs/styles/prism/material-light.js";
41
- var ChatPanel = forwardRef(({
41
+ var ChatPanel = ({
42
42
  project_id,
43
43
  initialPrompt = "",
44
44
  title = "Chat",
@@ -56,17 +56,14 @@ var ChatPanel = forwardRef(({
56
56
  scrollToEnd = false,
57
57
  initialMessage = "",
58
58
  prismStyle = theme === "light" ? materialLight : materialDark,
59
- service = null
60
- }, ref) => {
59
+ service = null,
60
+ historyChangedCallback = null
61
+ }) => {
61
62
  const { send, response, idle, stop } = useLLM({
62
63
  project_id,
63
64
  customer,
64
65
  url
65
66
  });
66
- useImperativeHandle(ref, () => ({
67
- getHistory: () => history,
68
- setHistory: (newHistory) => setHistory(newHistory)
69
- }));
70
67
  const [nextPrompt, setNextPrompt] = useState("");
71
68
  const [lastController, setLastController] = useState(new AbortController());
72
69
  const [history, setHistory] = useState({});
@@ -120,6 +117,11 @@ var ChatPanel = forwardRef(({
120
117
  }
121
118
  }
122
119
  }, [response, history]);
120
+ useEffect(() => {
121
+ if (historyChangedCallback) {
122
+ historyChangedCallback(history);
123
+ }
124
+ }, [history, historyChangedCallback]);
123
125
  const continueChat = () => {
124
126
  if (!idle) {
125
127
  stop(lastController);
@@ -149,6 +151,9 @@ var ChatPanel = forwardRef(({
149
151
  setNextPrompt("");
150
152
  }
151
153
  };
154
+ const replaceHistory = (newHistory) => {
155
+ setHistory(newHistory);
156
+ };
152
157
  function copyToClipboard(text) {
153
158
  navigator.clipboard.writeText(text);
154
159
  }
@@ -323,7 +328,7 @@ var ChatPanel = forwardRef(({
323
328
  /* @__PURE__ */ React.createElement("path", { d: "M8 8h16v16H8z" })
324
329
  )))
325
330
  ));
326
- });
331
+ };
327
332
  var ChatPanel_default = ChatPanel;
328
333
  export {
329
334
  ChatPanel_default as ChatPanel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llmasaservice-ui",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Prebuilt UI components for LLMAsAService.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/ChatPanel.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LLMAsAServiceCustomer, useLLM } from "llmasaservice-client";
2
- import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
2
+ import React, { useEffect, useRef, useState } from "react";
3
3
  import ReactMarkdown from "react-markdown";
4
4
  import "./ChatPanel.css";
5
5
  import remarkGfm from "remark-gfm";
@@ -27,13 +27,14 @@ export interface ChatPanelProps {
27
27
  scrollToEnd?: boolean;
28
28
  prismStyle?: PrismStyle;
29
29
  service?: string | null;
30
+ historyChangedCallback?: (history: { [prompt: string]: string }) => void;
30
31
  }
31
32
 
32
33
  interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
33
34
  inline?: boolean;
34
35
  }
35
36
 
36
- const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = forwardRef(({
37
+ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
37
38
  project_id,
38
39
  initialPrompt = "",
39
40
  title = "Chat",
@@ -52,18 +53,14 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = forwardRef(({
52
53
  initialMessage = "",
53
54
  prismStyle = theme === "light" ? materialLight: materialDark,
54
55
  service = null,
55
- }, ref) => {
56
+ historyChangedCallback = null,
57
+ }) => {
56
58
  const { send, response, idle, stop } = useLLM({
57
59
  project_id: project_id,
58
60
  customer: customer,
59
61
  url: url,
60
62
  });
61
63
 
62
- useImperativeHandle(ref, () => ({
63
- getHistory: () => history,
64
- setHistory: (newHistory: { [key: string]: string }) => setHistory(newHistory),
65
- }));
66
-
67
64
  const [nextPrompt, setNextPrompt] = useState("");
68
65
  const [lastController, setLastController] = useState(new AbortController());
69
66
  const [history, setHistory] = useState<{ [prompt: string]: string }>({});
@@ -130,6 +127,12 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = forwardRef(({
130
127
  }
131
128
  }, [response, history]);
132
129
 
130
+ useEffect(() => {
131
+ if (historyChangedCallback) {
132
+ historyChangedCallback(history);
133
+ }
134
+ }, [history, historyChangedCallback]);
135
+
133
136
  const continueChat = () => {
134
137
  if (!idle) {
135
138
  stop(lastController);
@@ -171,6 +174,10 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = forwardRef(({
171
174
  }
172
175
  };
173
176
 
177
+ const replaceHistory = (newHistory: { [prompt: string]: string }) => {
178
+ setHistory(newHistory);
179
+ }
180
+
174
181
  function copyToClipboard(text: string) {
175
182
  navigator.clipboard.writeText(text);
176
183
  }
@@ -379,6 +386,6 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = forwardRef(({
379
386
  </div>
380
387
  </>
381
388
  );
382
- });
389
+ };
383
390
 
384
391
  export default ChatPanel;