@glodon-aiot/bot-client-sdk 3.26.0-alpha.9 → 3.26.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.
Files changed (72) hide show
  1. package/README.md +243 -225
  2. package/dist/es/AgentSession.mjs +267 -197
  3. package/dist/es/BotClient.mjs +200 -123
  4. package/dist/es/Config.mjs +56 -67
  5. package/dist/es/DialogSession.mjs +123 -118
  6. package/dist/es/EventBus.mjs +38 -34
  7. package/dist/es/Logger.mjs +19 -21
  8. package/dist/es/Session.mjs +338 -284
  9. package/dist/es/api/index.mjs +31 -30
  10. package/dist/es/builtinTools/constants.mjs +12 -5
  11. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +182 -160
  12. package/dist/es/builtinTools/paths.mjs +34 -27
  13. package/dist/es/builtinTools/platformSkills.mjs +248 -0
  14. package/dist/es/builtinTools/schemas.mjs +63 -18
  15. package/dist/es/builtinTools/tools.mjs +368 -244
  16. package/dist/es/index.mjs +62 -61
  17. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  18. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -131
  19. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +60 -55
  20. package/dist/es/localFiles/constants.mjs +24 -28
  21. package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
  22. package/dist/es/localFiles/errors.mjs +44 -35
  23. package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
  24. package/dist/es/localFiles/host/protocol.mjs +27 -14
  25. package/dist/es/localFiles/host/sandboxClient.mjs +297 -127
  26. package/dist/es/localFiles/preview.mjs +33 -0
  27. package/dist/es/localFiles/schemas.mjs +22 -53
  28. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +156 -89
  29. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  30. package/dist/es/localMcp/client.mjs +234 -0
  31. package/dist/es/localMcp/endpoints.mjs +94 -0
  32. package/dist/es/localMcp/register.mjs +207 -0
  33. package/dist/es/localMcp/registry.mjs +43 -0
  34. package/dist/es/package.json.mjs +34 -54
  35. package/dist/es/sessionUpload.mjs +49 -0
  36. package/dist/es/utils.mjs +24 -11
  37. package/dist/lib/index.js +48 -40
  38. package/dist/src/AgentSession.d.ts +13 -0
  39. package/dist/src/BotClient.d.ts +13 -1
  40. package/dist/src/Config.d.ts +6 -7
  41. package/dist/src/EventBus.d.ts +3 -0
  42. package/dist/src/Logger.d.ts +15 -8
  43. package/dist/src/PayloadTypes.d.ts +2 -0
  44. package/dist/src/Session.d.ts +19 -2
  45. package/dist/src/api/index.d.ts +2 -2
  46. package/dist/src/builtinTools/command.d.ts +7 -0
  47. package/dist/src/builtinTools/constants.d.ts +10 -2
  48. package/dist/src/builtinTools/paths.d.ts +3 -2
  49. package/dist/src/builtinTools/platformSkills.d.ts +92 -0
  50. package/dist/src/builtinTools/tools.d.ts +13 -0
  51. package/dist/src/constant.d.ts +1 -1
  52. package/dist/src/index.d.ts +2 -1
  53. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  54. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +7 -4
  55. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
  56. package/dist/src/localFiles/constants.d.ts +4 -13
  57. package/dist/src/localFiles/errors.d.ts +1 -1
  58. package/dist/src/localFiles/host/protocol.d.ts +14 -3
  59. package/dist/src/localFiles/host/sandboxClient.d.ts +50 -0
  60. package/dist/src/localFiles/index.d.ts +9 -5
  61. package/dist/src/localFiles/preview.d.ts +2 -0
  62. package/dist/src/localFiles/schemas.d.ts +0 -2
  63. package/dist/src/localFiles/types.d.ts +2 -22
  64. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +25 -3
  65. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  66. package/dist/src/localMcp/client.d.ts +15 -0
  67. package/dist/src/localMcp/endpoints.d.ts +19 -0
  68. package/dist/src/localMcp/register.d.ts +34 -0
  69. package/dist/src/localMcp/registry.d.ts +27 -0
  70. package/dist/src/sessionUpload.d.ts +14 -0
  71. package/dist/src/utils.d.ts +6 -0
  72. package/package.json +4 -24
@@ -1,57 +1,57 @@
1
- var I = Object.defineProperty, A = Object.defineProperties;
2
- var P = Object.getOwnPropertyDescriptors;
3
- var w = Object.getOwnPropertySymbols;
4
- var b = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
5
- var R = (l, c, s) => c in l ? I(l, c, { enumerable: !0, configurable: !0, writable: !0, value: s }) : l[c] = s, u = (l, c) => {
6
- for (var s in c || (c = {}))
7
- b.call(c, s) && R(l, s, c[s]);
8
- if (w)
9
- for (var s of w(c))
10
- D.call(c, s) && R(l, s, c[s]);
11
- return l;
12
- }, y = (l, c) => A(l, P(c));
13
- var M = (l, c, s) => (R(l, typeof c != "symbol" ? c + "" : c, s), s);
14
- var f = (l, c, s) => new Promise((t, d) => {
1
+ var A = Object.defineProperty, P = Object.defineProperties;
2
+ var b = Object.getOwnPropertyDescriptors;
3
+ var C = Object.getOwnPropertySymbols;
4
+ var D = Object.prototype.hasOwnProperty, $ = Object.prototype.propertyIsEnumerable;
5
+ var w = (i, c, t) => c in i ? A(i, c, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[c] = t, f = (i, c) => {
6
+ for (var t in c || (c = {}))
7
+ D.call(c, t) && w(i, t, c[t]);
8
+ if (C)
9
+ for (var t of C(c))
10
+ $.call(c, t) && w(i, t, c[t]);
11
+ return i;
12
+ }, y = (i, c) => P(i, b(c));
13
+ var M = (i, c, t) => (w(i, typeof c != "symbol" ? c + "" : c, t), t);
14
+ var u = (i, c, t) => new Promise((n, d) => {
15
15
  var h = (r) => {
16
16
  try {
17
- i(s.next(r));
18
- } catch (m) {
19
- d(m);
17
+ l(t.next(r));
18
+ } catch (o) {
19
+ d(o);
20
20
  }
21
21
  }, e = (r) => {
22
22
  try {
23
- i(s.throw(r));
24
- } catch (m) {
25
- d(m);
23
+ l(t.throw(r));
24
+ } catch (o) {
25
+ d(o);
26
26
  }
27
- }, i = (r) => r.done ? t(r.value) : Promise.resolve(r.value).then(h, e);
28
- i((s = s.apply(l, c)).next());
27
+ }, l = (r) => r.done ? n(r.value) : Promise.resolve(r.value).then(h, e);
28
+ l((t = t.apply(i, c)).next());
29
29
  });
30
- import { IHistoryRole as C, PromptVariableType as v, ChatMessageRole as O } from "@glodon-aiot/apis";
30
+ import { IHistoryRole as T, PromptVariableType as v, ChatMessageRole as O } from "@glodon-aiot/apis";
31
31
  import V from "./Logger.mjs";
32
- import $ from "./Session.mjs";
33
- import _ from "dayjs";
34
- import { configuration as S } from "./Config.mjs";
35
- import { fetchEventSource as T } from "./api/fetchEventSource/fetch.mjs";
36
- const p = new V("[DialogSession] ");
37
- class k extends $ {
38
- constructor(s, t = "", d, h, e, i) {
39
- super(s, t, d, h, e, i);
32
+ import _ from "./Session.mjs";
33
+ import E from "dayjs";
34
+ import { configuration as R } from "./Config.mjs";
35
+ import { fetchEventSource as p } from "./api/fetchEventSource/fetch.mjs";
36
+ const S = new V("[DialogSession] ");
37
+ class Y extends _ {
38
+ constructor(t, n = "", d, h, e, l) {
39
+ super(t, n, d, h, e, l);
40
40
  M(this, "ctrl", new AbortController());
41
41
  }
42
42
  prepareConnection() {
43
- return new Promise((s) => f(this, null, function* () {
44
- this._ready = !0, this.event.emit("ready"), this.frozen = !1, s(!0);
43
+ return new Promise((t) => u(this, null, function* () {
44
+ this._ready = !0, this.event.emit("ready"), this.frozen = !1, t(!0);
45
45
  }));
46
46
  }
47
- postChatV2EventSource(s, t, d, h, e, i) {
48
- return f(this, null, function* () {
47
+ postChatV2EventSource(t, n, d, h, e, l) {
48
+ return u(this, null, function* () {
49
49
  const r = {
50
50
  code: 0,
51
51
  // messageId: uuidv4(),
52
52
  content: "",
53
- role: C.Robot,
54
- sessionId: t,
53
+ role: T.Robot,
54
+ sessionId: n,
55
55
  reference: [],
56
56
  searchReference: [],
57
57
  messageTime: "",
@@ -60,60 +60,60 @@ class k extends $ {
60
60
  isAgree: 0
61
61
  },
62
62
  isReplying: !1
63
- }, m = y(u({}, d), {
64
- stream: S.stream
63
+ }, o = y(f({}, d), {
64
+ stream: R.stream
65
65
  });
66
- T(`${S.apiRoot}/chat/v2/chat?applicationId=${s}&sessionId=${t}`, {
66
+ p(`${R.apiRoot}/chat/v2/chat?applicationId=${t}&sessionId=${n}`, {
67
67
  method: "POST",
68
68
  headers: {
69
- Authorization: `Bearer ${this.token}`,
69
+ Authorization: `Bearer ${this.requestToken}`,
70
70
  "Content-Type": "application/json"
71
71
  },
72
- body: JSON.stringify(m),
72
+ body: JSON.stringify(o),
73
73
  openWhenHidden: !0,
74
74
  signal: h,
75
- onopen(g) {
76
- return g.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
75
+ onopen(m) {
76
+ return m.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
77
77
  },
78
- onmessage(g) {
79
- if (!g.data.includes('{"code": ')) {
80
- let a = {};
78
+ onmessage(m) {
79
+ if (!m.data.includes('{"code": ')) {
80
+ let s = {};
81
81
  try {
82
- a = JSON.parse(g.data);
83
- } catch (E) {
82
+ s = JSON.parse(m.data);
83
+ } catch (I) {
84
84
  }
85
- (a == null ? void 0 : a.mtype) === "search" ? r.searchReference.push(a) : r.content = r.content + g.data;
86
- const o = {
85
+ (s == null ? void 0 : s.mtype) === "search" ? r.searchReference.push(s) : r.content = r.content + m.data;
86
+ const a = {
87
87
  content: r.content,
88
88
  role: 1,
89
89
  reference: r.reference,
90
90
  searchReference: r.searchReference,
91
91
  messageId: r.messageId,
92
- sessionId: t,
93
- messageTime: _(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
92
+ sessionId: n,
93
+ messageTime: E(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
94
94
  comment: {
95
95
  isAgree: 0
96
96
  },
97
97
  isReplying: !0
98
98
  };
99
- return (e == null ? void 0 : e.onmessage) && e.onmessage(o);
99
+ return (e == null ? void 0 : e.onmessage) && e.onmessage(a);
100
100
  }
101
- const n = JSON.parse(g.data);
102
- if (r.reference = n.data.reference, r.searchReference = n.data.searchReference, r.messageTime = n.data.messageTime, r.messageId = n.data.messageId, r.llmModel = n.data.llmModel, r.content = n.data.content, r.code = n.code, n.code === 200) {
103
- const a = {
101
+ const g = JSON.parse(m.data);
102
+ if (r.reference = g.data.reference, r.searchReference = g.data.searchReference, r.messageTime = g.data.messageTime, r.messageId = g.data.messageId, r.llmModel = g.data.llmModel, r.content = g.data.content, r.code = g.code, g.code === 200) {
103
+ const s = {
104
104
  code: r.code,
105
105
  content: r.content,
106
106
  role: 1,
107
107
  reference: r.reference,
108
108
  searchReference: r.searchReference,
109
109
  messageId: r.messageId,
110
- sessionId: t,
110
+ sessionId: n,
111
111
  messageTime: r.messageTime,
112
112
  isReplying: !0
113
113
  };
114
- e != null && e.onmessage && e.onmessage(a);
114
+ e != null && e.onmessage && e.onmessage(s);
115
115
  } else
116
- return e != null && e.onclose && e.onclose(r), i && i({
116
+ return e != null && e.onclose && e.onclose(r), l && l({
117
117
  code: r.code,
118
118
  message: r.message
119
119
  });
@@ -122,14 +122,14 @@ class k extends $ {
122
122
  e != null && e.onerror && e.onerror();
123
123
  },
124
124
  onclose() {
125
- const g = {
125
+ const m = {
126
126
  code: r.code,
127
127
  content: r.content,
128
128
  role: 1,
129
129
  reference: r.reference,
130
130
  searchReference: r.searchReference,
131
131
  messageId: r.messageId,
132
- sessionId: t,
132
+ sessionId: n,
133
133
  messageTime: r.messageTime,
134
134
  comment: {
135
135
  isAgree: 0
@@ -137,19 +137,19 @@ class k extends $ {
137
137
  isReplying: !1,
138
138
  index: -1
139
139
  };
140
- e != null && e.onclose && e.onclose(g);
140
+ e != null && e.onclose && e.onclose(m);
141
141
  }
142
142
  });
143
143
  });
144
144
  }
145
- postChatV3EventSource(s, t, d, h, e, i) {
146
- return f(this, null, function* () {
147
- const r = this, m = {
145
+ postChatV3EventSource(t, n, d, h, e, l) {
146
+ return u(this, null, function* () {
147
+ const r = this, o = {
148
148
  code: 0,
149
149
  // messageId: uuidv4(),
150
150
  content: "",
151
- role: C.Robot,
152
- sessionId: t,
151
+ role: T.Robot,
152
+ sessionId: n,
153
153
  reference: [],
154
154
  searchReference: [],
155
155
  messageTime: "",
@@ -162,89 +162,94 @@ class k extends $ {
162
162
  thinkingSecs: "",
163
163
  thinkingStatus: "",
164
164
  searchingStatus: ""
165
- }, g = y(u({}, d), {
166
- stream: S.stream
167
- });
168
- T(`${S.apiRoot}/chat/v3/chat?applicationId=${s}&sessionId=${t}`, {
165
+ }, m = y(f({}, d), {
166
+ stream: R.stream
167
+ }), g = m.imageContent;
168
+ S.log("question:request", Array.isArray(g) ? y(f({}, m), {
169
+ imageContent: `[${g.length}]`
170
+ }) : m), p(`${R.apiRoot}/chat/v3/chat?applicationId=${t}&sessionId=${n}`, {
169
171
  method: "POST",
170
172
  headers: {
171
- Authorization: `Bearer ${this.token}`,
173
+ Authorization: `Bearer ${this.requestToken}`,
172
174
  "Content-Type": "application/json"
173
175
  },
174
- body: JSON.stringify(g),
176
+ body: JSON.stringify(m),
175
177
  openWhenHidden: !0,
176
178
  signal: h,
177
- onopen(n) {
178
- return n.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
179
+ onopen(s) {
180
+ return S.log("question:opened", {
181
+ ok: s.ok,
182
+ status: s.status
183
+ }), s.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
179
184
  },
180
- onmessage(n) {
181
- if (!n.data && !n.event && !n.id && !n.retry)
185
+ onmessage(s) {
186
+ if (!s.data && !s.event && !s.id && !s.retry)
182
187
  return;
183
188
  let a = {};
184
189
  try {
185
- a = JSON.parse(n.data);
186
- } catch (o) {
187
- console.error("parse eventData to JSON failed. ", n.data);
190
+ a = JSON.parse(s.data);
191
+ } catch (I) {
192
+ S.error("parse eventData to JSON failed. ", s.data);
188
193
  }
189
- if (a.code !== 200)
190
- return m.index = -1, m.code = a.code, m.message = a.message, e != null && e.onmessage && e.onmessage(m), i && i({
194
+ if (S.log("response", a), a.code !== 200)
195
+ return o.index = -1, o.code = a.code, o.message = a.message, e != null && e.onmessage && e.onmessage(o), l && l({
191
196
  code: a.code,
192
197
  message: a.message
193
198
  });
194
- r.handleStreamAnswer(a, m), e != null && e.onmessage && e.onmessage(m);
199
+ r.handleStreamAnswer(a, o), e != null && e.onmessage && e.onmessage(o);
195
200
  },
196
201
  onerror() {
197
202
  e != null && e.onerror && e.onerror();
198
203
  },
199
204
  onclose() {
200
- const n = y(u({}, m), {
205
+ const s = y(f({}, o), {
201
206
  isReplying: !1
202
207
  });
203
- e != null && e.onclose && e.onclose(n);
208
+ e != null && e.onclose && e.onclose(s);
204
209
  }
205
210
  });
206
211
  });
207
212
  }
208
- sendQuestion(s, t) {
209
- return f(this, null, function* () {
213
+ sendQuestion(t, n) {
214
+ return u(this, null, function* () {
210
215
  const {
211
216
  content: d,
212
217
  fileIds: h,
213
218
  oldMessageId: e,
214
- imageContent: i
215
- } = s, {
219
+ imageContent: l
220
+ } = t, {
216
221
  stream: r,
217
- referenceFirst: m
218
- } = t;
222
+ referenceFirst: o
223
+ } = n;
219
224
  if (this.active || (yield this.activate()), this._id) {
220
- const g = this.convertKnowledgesToChatFormat(this.knowledges);
221
- let n = {
225
+ const m = this.convertKnowledgesToChatFormat(this.knowledges);
226
+ let g = {
222
227
  content: d,
223
228
  fileIds: h,
224
- referenceFirst: m,
229
+ referenceFirst: o,
225
230
  oldMessageId: e,
226
- promptVariables: this.promptVariables.filter((a) => a.type === v.User).reduce((a, o) => y(u({}, a), {
227
- [o.key]: o.value
231
+ promptVariables: this.promptVariables.filter((s) => s.type === v.User).reduce((s, a) => y(f({}, s), {
232
+ [a.key]: a.value
228
233
  }), {}),
229
- systemPromptVariables: this.promptVariables.filter((a) => a.type === v.System).reduce((a, o) => y(u({}, a), {
230
- [o.key]: o.value
234
+ systemPromptVariables: this.promptVariables.filter((s) => s.type === v.System).reduce((s, a) => y(f({}, s), {
235
+ [a.key]: a.value
231
236
  }), {}),
232
- knowledges: g,
237
+ knowledges: m,
233
238
  enableTitleSummary: this.resolveEnableTitleSummary(),
234
- imageContent: i
239
+ imageContent: l
235
240
  };
236
- this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, n, this.ctrl.signal, {
241
+ this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, g, this.ctrl.signal, {
237
242
  onopen: () => {
238
- p.log("open", this.ctrl);
243
+ S.log("open", this.ctrl);
239
244
  },
240
- onmessage: (a) => {
245
+ onmessage: (s) => {
241
246
  if (this._stopAnswer)
242
247
  return;
243
- let o = this.messages[this.messages.length - 1];
244
- o && o.role === O.Robot ? (o = u(u({}, o), a), this.messages[this.messages.length - 1] = o, this.event.emit("message:content", o), this.event.emit("message:updated", o)) : (this.pushMessage(a), this.event.emit("message:content", a));
248
+ let a = this.messages[this.messages.length - 1];
249
+ a && a.role === O.Robot ? (a = f(f({}, a), s), this.messages[this.messages.length - 1] = a, this.event.emit("message:content", a), this.event.emit("message:updated", a)) : (this.pushMessage(s), this.event.emit("message:content", s));
245
250
  },
246
- onclose: (a) => f(this, null, function* () {
247
- this._stopAnswer || (p.log(a, "onclose"), this.event.emit("answer:finish", a));
251
+ onclose: (s) => u(this, null, function* () {
252
+ this._stopAnswer || (S.log(s, "onclose"), this.event.emit("answer:finish", s));
248
253
  }),
249
254
  onerror: () => {
250
255
  this._stopAnswer || (this.event.emit("message:error", ""), this.frozen = !1);
@@ -257,27 +262,27 @@ class k extends $ {
257
262
  this.ctrl.abort();
258
263
  }
259
264
  registerMcpFromClientConfig() {
260
- return f(this, null, function* () {
265
+ return u(this, null, function* () {
261
266
  throw new Error("MCP registration is not supported by DialogSession");
262
267
  });
263
268
  }
264
- addMcpServers(s) {
265
- return f(this, null, function* () {
269
+ addMcpServers(t) {
270
+ return u(this, null, function* () {
266
271
  throw new Error("MCP registration is not supported by DialogSession");
267
272
  });
268
273
  }
269
274
  listMcpServers() {
270
- return f(this, null, function* () {
275
+ return u(this, null, function* () {
271
276
  throw new Error("MCP registration is not supported by DialogSession");
272
277
  });
273
278
  }
274
- convertKnowledgesToChatFormat(s) {
275
- return s ? s.map((t) => t != null && t.fileIds ? {
276
- id: t.id,
277
- fileIds: t.fileIds
278
- } : t.id) : [];
279
+ convertKnowledgesToChatFormat(t) {
280
+ return t ? t.map((n) => n != null && n.fileIds ? {
281
+ id: n.id,
282
+ fileIds: n.fileIds
283
+ } : n.id) : [];
279
284
  }
280
285
  }
281
286
  export {
282
- k as default
287
+ Y as default
283
288
  };
@@ -1,64 +1,68 @@
1
- var u = Object.defineProperty;
2
- var v = Object.getOwnPropertySymbols;
3
- var o = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
4
- var l = (s, e, n) => e in s ? u(s, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : s[e] = n, a = (s, e) => {
5
- for (var n in e || (e = {}))
6
- o.call(e, n) && l(s, n, e[n]);
7
- if (v)
8
- for (var n of v(e))
9
- L.call(e, n) && l(s, n, e[n]);
1
+ var l = Object.defineProperty;
2
+ var h = Object.getOwnPropertySymbols;
3
+ var u = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
4
+ var f = (s, e, t) => e in s ? l(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, a = (s, e) => {
5
+ for (var t in e || (e = {}))
6
+ u.call(e, t) && f(s, t, e[t]);
7
+ if (h)
8
+ for (var t of h(e))
9
+ L.call(e, t) && f(s, t, e[t]);
10
10
  return s;
11
11
  };
12
- var h = (s, e, n) => (l(s, typeof e != "symbol" ? e + "" : e, n), n);
12
+ var v = (s, e, t) => (f(s, typeof e != "symbol" ? e + "" : e, t), t);
13
13
  import M from "./Logger.mjs";
14
- const i = new M("[EventBus] ");
15
- class $ {
14
+ const o = new M("[EventBus] ");
15
+ class m {
16
+ /** disableLog 只关掉这一条总线;日志本身仍受 debug 模式控制。 */
16
17
  constructor(e = !1) {
17
- h(this, "eventListenerMap", {});
18
- e && i.disable();
18
+ v(this, "eventListenerMap", {});
19
+ this.disableLog = e;
20
+ }
21
+ trace(e, ...t) {
22
+ this.disableLog || o.log(e, ...t);
19
23
  }
20
24
  getEventListenerMap() {
21
25
  return a({}, this.eventListenerMap);
22
26
  }
23
- on(e, n, r = !1) {
27
+ on(e, t, r = !1) {
24
28
  this.eventListenerMap[e] || (this.eventListenerMap[e] = []), r ? this.eventListenerMap[e].push({
25
- fn: n,
29
+ fn: t,
26
30
  once: !0
27
- }) : this.eventListenerMap[e].push(n), i.log(`add event ${e} listener ${r ? ", call once" : ""}`);
31
+ }) : this.eventListenerMap[e].push(t), this.trace(`add event ${e} listener ${r ? ", call once" : ""}`);
28
32
  }
29
- once(e, n) {
30
- this.on(e, n, !0);
33
+ once(e, t) {
34
+ this.on(e, t, !0);
31
35
  }
32
- off(e, n) {
36
+ off(e, t) {
33
37
  if (this.eventListenerMap[e]) {
34
- const r = this.eventListenerMap[e].findIndex((t) => {
35
- if (typeof t == "function" && n === t)
38
+ const r = this.eventListenerMap[e].findIndex((n) => {
39
+ if (typeof n == "function" && t === n)
36
40
  return !0;
37
- if (t = t, t.fn === n)
41
+ if (n = n, n.fn === t)
38
42
  return !0;
39
43
  });
40
- r < 0 ? i.log(`event ${e} listener ${n.name} is not found`) : (this.eventListenerMap[e].splice(r, 1), i.log(`remove event ${e} listener`));
44
+ r < 0 ? this.trace(`event ${e} listener ${t.name} is not found`) : (this.eventListenerMap[e].splice(r, 1), this.trace(`remove event ${e} listener`));
41
45
  } else
42
- i.log(`event ${e} listeners is empty`);
46
+ this.trace(`event ${e} listeners is empty`);
43
47
  }
44
- emit(e, n) {
48
+ emit(e, t) {
45
49
  if (!this.eventListenerMap[e]) {
46
- i.log(`event ${e} listeners is empty`);
50
+ this.trace(`event ${e} listeners is empty`, t);
47
51
  return;
48
52
  }
49
53
  const r = [];
50
- for (let t = 0; t < this.eventListenerMap[e].length; t++) {
51
- const f = this.eventListenerMap[e][t];
52
- typeof f == "function" ? f(n) : r.push(f);
54
+ for (let n = 0; n < this.eventListenerMap[e].length; n++) {
55
+ const i = this.eventListenerMap[e][n];
56
+ typeof i == "function" ? i(t) : r.push(i);
53
57
  }
54
- r.forEach((t) => {
55
- t && (t.fn(n), this.off(e, t.fn));
56
- }), i.log(`event ${e} is fired, has ${this.eventListenerMap[e].length} listeners`);
58
+ r.forEach((n) => {
59
+ n && (n.fn(t), this.off(e, n.fn));
60
+ }), this.trace(`event ${e} is fired, has ${this.eventListenerMap[e].length} listeners`, t);
57
61
  }
58
62
  removeAllListeners() {
59
63
  this.eventListenerMap = {};
60
64
  }
61
65
  }
62
66
  export {
63
- $ as default
67
+ m as default
64
68
  };
@@ -1,31 +1,29 @@
1
- var n = Object.defineProperty;
2
- var f = (s, e, i) => e in s ? n(s, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[e] = i;
3
- var r = (s, e, i) => (f(s, typeof e != "symbol" ? e + "" : e, i), i);
4
- const o = class o {
5
- constructor(e, i = !1) {
6
- this.prefix = e, this.open = i;
1
+ var f = Object.defineProperty;
2
+ var n = (o, r, i) => r in o ? f(o, r, { enumerable: !0, configurable: !0, writable: !0, value: i }) : o[r] = i;
3
+ var s = (o, r, i) => (n(o, typeof r != "symbol" ? r + "" : r, i), i);
4
+ const e = class e {
5
+ constructor(r) {
6
+ this.prefix = r;
7
7
  }
8
- disable() {
9
- this.open = !1;
8
+ log(...r) {
9
+ e.debug && console.log(this.prefix, ...r);
10
10
  }
11
- enable() {
12
- this.open = !0;
11
+ info(...r) {
12
+ e.debug && console.info(`%c ${this.prefix} %o`, "color:#0f0;", ...r);
13
13
  }
14
- log(...e) {
15
- !this.open && !o.debug || console.log(this.prefix, ...e);
14
+ warn(...r) {
15
+ e.debug && console.warn(this.prefix, ...r);
16
16
  }
17
- info(...e) {
18
- !this.open && !o.debug || console.info(`%c ${this.prefix} %o`, "color:#0f0;", ...e);
17
+ error(...r) {
18
+ e.debug && console.error(this.prefix, ...r);
19
19
  }
20
- error(...e) {
21
- !this.open && !o.debug || console.error(this.prefix, ...e);
22
- }
23
- warn(...e) {
24
- !this.open && !o.debug || console.warn(this.prefix, ...e);
20
+ /** 非 debug 也会输出。调用方无法感知的失败才用这个。 */
21
+ report(...r) {
22
+ console.error(this.prefix, ...r);
25
23
  }
26
24
  };
27
- r(o, "debug", !1);
28
- let t = o;
25
+ s(e, "debug", !1);
26
+ let t = e;
29
27
  export {
30
28
  t as default
31
29
  };