@cmnd-ai/chatbot-react 1.6.0 → 1.7.0

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.
@@ -0,0 +1,11 @@
1
+ declare class StreamError extends Error {
2
+ name: string;
3
+ path: string[];
4
+ error: string;
5
+ constructor({ message, path, error, }: {
6
+ message: string;
7
+ path?: string[];
8
+ error: string;
9
+ });
10
+ }
11
+ export default StreamError;
@@ -0,0 +1,12 @@
1
+ class StreamError extends Error {
2
+ name;
3
+ path;
4
+ error;
5
+ constructor({ message, path, error, }) {
6
+ super(message);
7
+ this.name = "StreamError";
8
+ this.path = path || [];
9
+ this.error = error;
10
+ }
11
+ }
12
+ export default StreamError;
@@ -1,3 +1,4 @@
1
+ import StreamError from "./StreamError.js";
1
2
  const processStream = async (reader, onData) => {
2
3
  if (!onData)
3
4
  return;
@@ -32,7 +33,11 @@ const processStream = async (reader, onData) => {
32
33
  try {
33
34
  const dataObject = JSON.parse(fullMessageContext + dataString);
34
35
  if (dataObject.error) {
35
- throw new Error(dataObject.error);
36
+ throw new StreamError({
37
+ error: dataObject.error,
38
+ path: dataObject.path,
39
+ message: dataObject.error,
40
+ });
36
41
  }
37
42
  if (dataObject.content) {
38
43
  fullAssistantMessage += dataObject.content;
@@ -59,9 +64,10 @@ const processStream = async (reader, onData) => {
59
64
  }
60
65
  }
61
66
  catch (error) {
67
+ console.error("Error processing stream", error);
62
68
  onData({
63
69
  completionFinished: true,
64
- message: error instanceof Error
70
+ message: error instanceof StreamError
65
71
  ? error.message
66
72
  : "Oops! I ran into a problem.",
67
73
  finalResponseWithUsageData: true,
@@ -72,6 +78,7 @@ const processStream = async (reader, onData) => {
72
78
  }
73
79
  }
74
80
  catch (error) {
81
+ console.error("Error processing stream", error);
75
82
  onData({
76
83
  completionFinished: true,
77
84
  message: "Oops! I ran into a problem.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmnd-ai/chatbot-react",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "main": "dist/index.js",
5
5
  "description": "",
6
6
  "type": "module",