@blueking/ai-blueking 0.1.4 → 0.1.5-beta.1

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/README.md CHANGED
@@ -79,6 +79,8 @@ npm i @blueking/ai-blueking
79
79
 
80
80
  // 发送消息
81
81
  const handleSend = (message: string) => {
82
+ // 记录当前消息记录
83
+ const chatHistory = [...messages.value];
82
84
  // 添加一条消息
83
85
  messages.value.push({
84
86
  role: 'user',
@@ -88,8 +90,7 @@ npm i @blueking/ai-blueking
88
90
  chatHelper.stream(
89
91
  {
90
92
  inputs: {
91
- input: message,
92
- chat_history: messages.value,
93
+ chat_history: chatHistory,
93
94
  },
94
95
  },
95
96
  1,
@@ -1,32 +1,32 @@
1
- var u = Object.defineProperty;
2
- var g = (a, t, e) => t in a ? u(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var s = (a, t, e) => (g(a, typeof t != "symbol" ? t + "" : t, e), e);
4
- const E = (a) => {
1
+ var b = Object.defineProperty;
2
+ var f = (r, t, e) => t in r ? b(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var n = (r, t, e) => (f(r, typeof t != "symbol" ? t + "" : t, e), e);
4
+ const m = (r) => {
5
5
  try {
6
- return JSON.parse(a), !0;
6
+ return JSON.parse(r), !0;
7
7
  } catch {
8
8
  return !1;
9
9
  }
10
10
  };
11
- class m {
12
- constructor(t, e, r, o, h) {
13
- s(this, "controllerMap");
14
- s(this, "handleEnd");
15
- s(this, "handleError");
16
- s(this, "handleReceiveMessage");
17
- s(this, "handleStart");
18
- s(this, "url");
19
- this.url = t, this.handleStart = e, this.handleReceiveMessage = r, this.handleEnd = o, this.handleError = h, this.controllerMap = {};
11
+ class y {
12
+ constructor(t, e, a, o, h) {
13
+ n(this, "controllerMap");
14
+ n(this, "handleEnd");
15
+ n(this, "handleError");
16
+ n(this, "handleReceiveMessage");
17
+ n(this, "handleStart");
18
+ n(this, "url");
19
+ this.url = t, this.handleStart = e, this.handleReceiveMessage = a, this.handleEnd = o, this.handleError = h, this.controllerMap = {};
20
20
  }
21
21
  stop(t) {
22
- var e, r;
23
- return (r = (e = this.controllerMap[t]) == null ? void 0 : e.abort) == null || r.call(e), this.handleEnd(t);
22
+ var e, a;
23
+ return (a = (e = this.controllerMap[t]) == null ? void 0 : e.abort) == null || a.call(e), this.handleEnd(t);
24
24
  }
25
25
  async stream(t, e) {
26
- const r = new AbortController();
27
- this.controllerMap[e] = r, fetch(this.url, {
26
+ const a = new AbortController();
27
+ this.controllerMap[e] = a, fetch(this.url, {
28
28
  method: "post",
29
- signal: r.signal,
29
+ signal: a.signal,
30
30
  headers: {
31
31
  "Content-Type": "application/json"
32
32
  },
@@ -37,26 +37,33 @@ class m {
37
37
  const h = o.body.pipeThrough(new window.TextDecoderStream()).getReader();
38
38
  for (; ; )
39
39
  try {
40
- const { value: n, done: c } = await h.read();
41
- if (c)
40
+ const { value: s, done: d } = await h.read();
41
+ if (d)
42
42
  break;
43
- n.toString().split(`
44
- `).forEach((i) => {
45
- const l = i.trim();
46
- if (E(l)) {
47
- const { event: d, content: p } = JSON.parse(l);
48
- switch (d) {
43
+ s.toString().split(`
44
+ `).forEach((p) => {
45
+ const l = p.trim();
46
+ if (m(l)) {
47
+ const { event: u, content: g, result: E, code: c, message: i } = JSON.parse(l);
48
+ if (E === !1) {
49
+ this.handleError(i, c, e);
50
+ return;
51
+ }
52
+ switch (u) {
49
53
  case "text":
50
- this.handleReceiveMessage(p, e);
54
+ this.handleReceiveMessage(g, e);
51
55
  break;
52
56
  case "done":
53
57
  this.handleEnd(e);
54
58
  break;
59
+ case "error":
60
+ this.handleError(i, c, e);
61
+ break;
55
62
  }
56
63
  }
57
64
  });
58
- } catch (n) {
59
- (n == null ? void 0 : n.code) !== 20 && this.handleError(n.message, n.code, e);
65
+ } catch (s) {
66
+ (s == null ? void 0 : s.code) !== 20 && this.handleError(s.message, s.code, e);
60
67
  break;
61
68
  }
62
69
  }).catch((o) => {
@@ -65,5 +72,5 @@ class m {
65
72
  }
66
73
  }
67
74
  export {
68
- m as ChatHelper
75
+ y as ChatHelper
69
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/ai-blueking",
3
- "version": "0.1.4",
3
+ "version": "0.1.5-beta.1",
4
4
  "description": "AI 小鲸",
5
5
  "license": "MIT",
6
6
  "author": "Tencent BlueKing",