llmasaservice-ui 0.2.13 → 0.2.14

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
@@ -23,6 +23,7 @@ interface ChatPanelProps {
23
23
  url?: string | null;
24
24
  scrollToEnd?: boolean;
25
25
  prismStyle?: PrismStyle;
26
+ service?: string | null;
26
27
  }
27
28
  interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
28
29
  inline?: boolean;
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ interface ChatPanelProps {
23
23
  url?: string | null;
24
24
  scrollToEnd?: boolean;
25
25
  prismStyle?: PrismStyle;
26
+ service?: string | null;
26
27
  }
27
28
  interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
28
29
  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 = ({
74
+ var ChatPanel = (0, import_react.forwardRef)(({
75
75
  project_id,
76
76
  initialPrompt = "",
77
77
  title = "Chat",
@@ -88,13 +88,18 @@ var ChatPanel = ({
88
88
  url = null,
89
89
  scrollToEnd = false,
90
90
  initialMessage = "",
91
- prismStyle = theme === "light" ? import_material_light.default : import_material_dark.default
92
- }) => {
91
+ prismStyle = theme === "light" ? import_material_light.default : import_material_dark.default,
92
+ service = null
93
+ }, ref) => {
93
94
  const { send, response, idle, stop } = (0, import_llmasaservice_client.useLLM)({
94
95
  project_id,
95
96
  customer,
96
97
  url
97
98
  });
99
+ (0, import_react.useImperativeHandle)(ref, () => ({
100
+ getHistory: () => history,
101
+ setHistory: (newHistory) => setHistory(newHistory)
102
+ }));
98
103
  const [nextPrompt, setNextPrompt] = (0, import_react.useState)("");
99
104
  const [lastController, setLastController] = (0, import_react.useState)(new AbortController());
100
105
  const [history, setHistory] = (0, import_react.useState)({});
@@ -123,7 +128,7 @@ var ChatPanel = ({
123
128
  setIsLoading(true);
124
129
  if (lastController) stop(lastController);
125
130
  const controller = new AbortController();
126
- send(initialPrompt, messages, true, true, null, controller);
131
+ send(initialPrompt, messages, true, true, service, controller);
127
132
  setLastPrompt(initialPrompt);
128
133
  setLastController(controller);
129
134
  setHistory({});
@@ -171,7 +176,7 @@ var ChatPanel = ({
171
176
  });
172
177
  });
173
178
  const controller = new AbortController();
174
- send(nextPrompt, messagesAndHistory, true, true, null, controller);
179
+ send(nextPrompt, messagesAndHistory, true, true, service, controller);
175
180
  setLastPrompt(nextPrompt);
176
181
  setLastController(controller);
177
182
  setNextPrompt("");
@@ -351,7 +356,7 @@ var ChatPanel = ({
351
356
  /* @__PURE__ */ import_react.default.createElement("path", { d: "M8 8h16v16H8z" })
352
357
  )))
353
358
  ));
354
- };
359
+ });
355
360
  var ChatPanel_default = ChatPanel;
356
361
  // Annotate the CommonJS export names for ESM import in node:
357
362
  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, { useEffect, useRef, useState } from "react";
35
+ import React, { forwardRef, useEffect, useImperativeHandle, 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 = ({
41
+ var ChatPanel = forwardRef(({
42
42
  project_id,
43
43
  initialPrompt = "",
44
44
  title = "Chat",
@@ -55,13 +55,18 @@ var ChatPanel = ({
55
55
  url = null,
56
56
  scrollToEnd = false,
57
57
  initialMessage = "",
58
- prismStyle = theme === "light" ? materialLight : materialDark
59
- }) => {
58
+ prismStyle = theme === "light" ? materialLight : materialDark,
59
+ service = null
60
+ }, ref) => {
60
61
  const { send, response, idle, stop } = useLLM({
61
62
  project_id,
62
63
  customer,
63
64
  url
64
65
  });
66
+ useImperativeHandle(ref, () => ({
67
+ getHistory: () => history,
68
+ setHistory: (newHistory) => setHistory(newHistory)
69
+ }));
65
70
  const [nextPrompt, setNextPrompt] = useState("");
66
71
  const [lastController, setLastController] = useState(new AbortController());
67
72
  const [history, setHistory] = useState({});
@@ -90,7 +95,7 @@ var ChatPanel = ({
90
95
  setIsLoading(true);
91
96
  if (lastController) stop(lastController);
92
97
  const controller = new AbortController();
93
- send(initialPrompt, messages, true, true, null, controller);
98
+ send(initialPrompt, messages, true, true, service, controller);
94
99
  setLastPrompt(initialPrompt);
95
100
  setLastController(controller);
96
101
  setHistory({});
@@ -138,7 +143,7 @@ var ChatPanel = ({
138
143
  });
139
144
  });
140
145
  const controller = new AbortController();
141
- send(nextPrompt, messagesAndHistory, true, true, null, controller);
146
+ send(nextPrompt, messagesAndHistory, true, true, service, controller);
142
147
  setLastPrompt(nextPrompt);
143
148
  setLastController(controller);
144
149
  setNextPrompt("");
@@ -318,7 +323,7 @@ var ChatPanel = ({
318
323
  /* @__PURE__ */ React.createElement("path", { d: "M8 8h16v16H8z" })
319
324
  )))
320
325
  ));
321
- };
326
+ });
322
327
  var ChatPanel_default = ChatPanel;
323
328
  export {
324
329
  ChatPanel_default as ChatPanel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llmasaservice-ui",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
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, { useEffect, useRef, useState } from "react";
2
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
3
3
  import ReactMarkdown from "react-markdown";
4
4
  import "./ChatPanel.css";
5
5
  import remarkGfm from "remark-gfm";
@@ -26,13 +26,14 @@ export interface ChatPanelProps {
26
26
  url?: string | null;
27
27
  scrollToEnd?: boolean;
28
28
  prismStyle?: PrismStyle;
29
+ service?: string | null;
29
30
  }
30
31
 
31
32
  interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
32
33
  inline?: boolean;
33
34
  }
34
35
 
35
- const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
36
+ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = forwardRef(({
36
37
  project_id,
37
38
  initialPrompt = "",
38
39
  title = "Chat",
@@ -50,13 +51,19 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
50
51
  scrollToEnd = false,
51
52
  initialMessage = "",
52
53
  prismStyle = theme === "light" ? materialLight: materialDark,
53
- }) => {
54
+ service = null,
55
+ }, ref) => {
54
56
  const { send, response, idle, stop } = useLLM({
55
57
  project_id: project_id,
56
58
  customer: customer,
57
59
  url: url,
58
60
  });
59
61
 
62
+ useImperativeHandle(ref, () => ({
63
+ getHistory: () => history,
64
+ setHistory: (newHistory: { [key: string]: string }) => setHistory(newHistory),
65
+ }));
66
+
60
67
  const [nextPrompt, setNextPrompt] = useState("");
61
68
  const [lastController, setLastController] = useState(new AbortController());
62
69
  const [history, setHistory] = useState<{ [prompt: string]: string }>({});
@@ -95,7 +102,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
95
102
  if (lastController) stop(lastController);
96
103
  const controller = new AbortController();
97
104
 
98
- send(initialPrompt, messages, true, true, null, controller);
105
+ send(initialPrompt, messages, true, true, service, controller);
99
106
  setLastPrompt(initialPrompt);
100
107
  setLastController(controller);
101
108
  setHistory({});
@@ -156,7 +163,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
156
163
  });
157
164
 
158
165
  const controller = new AbortController();
159
- send(nextPrompt, messagesAndHistory, true, true, null, controller);
166
+ send(nextPrompt, messagesAndHistory, true, true, service, controller);
160
167
 
161
168
  setLastPrompt(nextPrompt);
162
169
  setLastController(controller);
@@ -372,6 +379,6 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
372
379
  </div>
373
380
  </>
374
381
  );
375
- };
382
+ });
376
383
 
377
384
  export default ChatPanel;