@glodon-aiot/bot-client-sdk 3.26.0-alpha.9 → 3.26.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 +271 -225
- package/dist/es/AgentSession.mjs +301 -228
- package/dist/es/BotClient.mjs +200 -123
- package/dist/es/Config.mjs +56 -67
- package/dist/es/DialogSession.mjs +123 -118
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/PayloadTypes.mjs +13 -2
- package/dist/es/Session.mjs +405 -312
- package/dist/es/api/index.mjs +31 -30
- package/dist/es/builtinTools/constants.mjs +12 -5
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +182 -160
- package/dist/es/builtinTools/paths.mjs +34 -27
- package/dist/es/builtinTools/platformSkills.mjs +248 -0
- package/dist/es/builtinTools/schemas.mjs +63 -18
- package/dist/es/builtinTools/tools.mjs +368 -244
- package/dist/es/index.mjs +73 -67
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -131
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +60 -55
- package/dist/es/localFiles/constants.mjs +24 -28
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
- package/dist/es/localFiles/errors.mjs +44 -35
- package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
- package/dist/es/localFiles/host/protocol.mjs +27 -14
- package/dist/es/localFiles/host/sandboxClient.mjs +297 -127
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/schemas.mjs +22 -53
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +156 -89
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
- package/dist/es/localMcp/client.mjs +234 -0
- package/dist/es/localMcp/endpoints.mjs +94 -0
- package/dist/es/localMcp/register.mjs +207 -0
- package/dist/es/localMcp/registry.mjs +43 -0
- package/dist/es/package.json.mjs +34 -54
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/es/utils.mjs +24 -11
- package/dist/lib/index.js +48 -40
- package/dist/src/AgentSession.d.ts +13 -0
- package/dist/src/BotClient.d.ts +13 -1
- package/dist/src/Config.d.ts +6 -7
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/PayloadTypes.d.ts +20 -0
- package/dist/src/Session.d.ts +24 -3
- package/dist/src/api/index.d.ts +2 -2
- package/dist/src/builtinTools/command.d.ts +7 -0
- package/dist/src/builtinTools/constants.d.ts +10 -2
- package/dist/src/builtinTools/paths.d.ts +3 -2
- package/dist/src/builtinTools/platformSkills.d.ts +92 -0
- package/dist/src/builtinTools/tools.d.ts +13 -0
- package/dist/src/constant.d.ts +1 -1
- package/dist/src/index.d.ts +6 -3
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +7 -4
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
- package/dist/src/localFiles/constants.d.ts +4 -13
- package/dist/src/localFiles/errors.d.ts +1 -1
- package/dist/src/localFiles/host/protocol.d.ts +14 -3
- package/dist/src/localFiles/host/sandboxClient.d.ts +50 -0
- package/dist/src/localFiles/index.d.ts +9 -5
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/schemas.d.ts +0 -2
- package/dist/src/localFiles/types.d.ts +2 -22
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +25 -3
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
- package/dist/src/localMcp/client.d.ts +15 -0
- package/dist/src/localMcp/endpoints.d.ts +19 -0
- package/dist/src/localMcp/register.d.ts +34 -0
- package/dist/src/localMcp/registry.d.ts +27 -0
- package/dist/src/sessionUpload.d.ts +14 -0
- package/dist/src/utils.d.ts +6 -0
- package/package.json +4 -24
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
}, y = (
|
|
13
|
-
var M = (
|
|
14
|
-
var
|
|
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
|
-
|
|
18
|
-
} catch (
|
|
19
|
-
d(
|
|
17
|
+
l(t.next(r));
|
|
18
|
+
} catch (o) {
|
|
19
|
+
d(o);
|
|
20
20
|
}
|
|
21
21
|
}, e = (r) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
d(
|
|
23
|
+
l(t.throw(r));
|
|
24
|
+
} catch (o) {
|
|
25
|
+
d(o);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
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
|
|
30
|
+
import { IHistoryRole as T, PromptVariableType as v, ChatMessageRole as O } from "@glodon-aiot/apis";
|
|
31
31
|
import V from "./Logger.mjs";
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import { configuration as
|
|
35
|
-
import { fetchEventSource as
|
|
36
|
-
const
|
|
37
|
-
class
|
|
38
|
-
constructor(
|
|
39
|
-
super(
|
|
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((
|
|
44
|
-
this._ready = !0, this.event.emit("ready"), this.frozen = !1,
|
|
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(
|
|
48
|
-
return
|
|
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:
|
|
54
|
-
sessionId:
|
|
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
|
-
},
|
|
64
|
-
stream:
|
|
63
|
+
}, o = y(f({}, d), {
|
|
64
|
+
stream: R.stream
|
|
65
65
|
});
|
|
66
|
-
|
|
66
|
+
p(`${R.apiRoot}/chat/v2/chat?applicationId=${t}&sessionId=${n}`, {
|
|
67
67
|
method: "POST",
|
|
68
68
|
headers: {
|
|
69
|
-
Authorization: `Bearer ${this.
|
|
69
|
+
Authorization: `Bearer ${this.requestToken}`,
|
|
70
70
|
"Content-Type": "application/json"
|
|
71
71
|
},
|
|
72
|
-
body: JSON.stringify(
|
|
72
|
+
body: JSON.stringify(o),
|
|
73
73
|
openWhenHidden: !0,
|
|
74
74
|
signal: h,
|
|
75
|
-
onopen(
|
|
76
|
-
return
|
|
75
|
+
onopen(m) {
|
|
76
|
+
return m.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
|
|
77
77
|
},
|
|
78
|
-
onmessage(
|
|
79
|
-
if (!
|
|
80
|
-
let
|
|
78
|
+
onmessage(m) {
|
|
79
|
+
if (!m.data.includes('{"code": ')) {
|
|
80
|
+
let s = {};
|
|
81
81
|
try {
|
|
82
|
-
|
|
83
|
-
} catch (
|
|
82
|
+
s = JSON.parse(m.data);
|
|
83
|
+
} catch (I) {
|
|
84
84
|
}
|
|
85
|
-
(
|
|
86
|
-
const
|
|
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:
|
|
93
|
-
messageTime:
|
|
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(
|
|
99
|
+
return (e == null ? void 0 : e.onmessage) && e.onmessage(a);
|
|
100
100
|
}
|
|
101
|
-
const
|
|
102
|
-
if (r.reference =
|
|
103
|
-
const
|
|
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:
|
|
110
|
+
sessionId: n,
|
|
111
111
|
messageTime: r.messageTime,
|
|
112
112
|
isReplying: !0
|
|
113
113
|
};
|
|
114
|
-
e != null && e.onmessage && e.onmessage(
|
|
114
|
+
e != null && e.onmessage && e.onmessage(s);
|
|
115
115
|
} else
|
|
116
|
-
return e != null && e.onclose && e.onclose(r),
|
|
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
|
|
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:
|
|
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(
|
|
140
|
+
e != null && e.onclose && e.onclose(m);
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
postChatV3EventSource(
|
|
146
|
-
return
|
|
147
|
-
const r = this,
|
|
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:
|
|
152
|
-
sessionId:
|
|
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
|
-
},
|
|
166
|
-
stream:
|
|
167
|
-
});
|
|
168
|
-
|
|
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.
|
|
173
|
+
Authorization: `Bearer ${this.requestToken}`,
|
|
172
174
|
"Content-Type": "application/json"
|
|
173
175
|
},
|
|
174
|
-
body: JSON.stringify(
|
|
176
|
+
body: JSON.stringify(m),
|
|
175
177
|
openWhenHidden: !0,
|
|
176
178
|
signal: h,
|
|
177
|
-
onopen(
|
|
178
|
-
return
|
|
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(
|
|
181
|
-
if (!
|
|
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(
|
|
186
|
-
} catch (
|
|
187
|
-
|
|
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
|
|
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,
|
|
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
|
|
205
|
+
const s = y(f({}, o), {
|
|
201
206
|
isReplying: !1
|
|
202
207
|
});
|
|
203
|
-
e != null && e.onclose && e.onclose(
|
|
208
|
+
e != null && e.onclose && e.onclose(s);
|
|
204
209
|
}
|
|
205
210
|
});
|
|
206
211
|
});
|
|
207
212
|
}
|
|
208
|
-
sendQuestion(
|
|
209
|
-
return
|
|
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:
|
|
215
|
-
} =
|
|
219
|
+
imageContent: l
|
|
220
|
+
} = t, {
|
|
216
221
|
stream: r,
|
|
217
|
-
referenceFirst:
|
|
218
|
-
} =
|
|
222
|
+
referenceFirst: o
|
|
223
|
+
} = n;
|
|
219
224
|
if (this.active || (yield this.activate()), this._id) {
|
|
220
|
-
const
|
|
221
|
-
let
|
|
225
|
+
const m = this.convertKnowledgesToChatFormat(this.knowledges);
|
|
226
|
+
let g = {
|
|
222
227
|
content: d,
|
|
223
228
|
fileIds: h,
|
|
224
|
-
referenceFirst:
|
|
229
|
+
referenceFirst: o,
|
|
225
230
|
oldMessageId: e,
|
|
226
|
-
promptVariables: this.promptVariables.filter((
|
|
227
|
-
[
|
|
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((
|
|
230
|
-
[
|
|
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:
|
|
237
|
+
knowledges: m,
|
|
233
238
|
enableTitleSummary: this.resolveEnableTitleSummary(),
|
|
234
|
-
imageContent:
|
|
239
|
+
imageContent: l
|
|
235
240
|
};
|
|
236
|
-
this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id,
|
|
241
|
+
this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, g, this.ctrl.signal, {
|
|
237
242
|
onopen: () => {
|
|
238
|
-
|
|
243
|
+
S.log("open", this.ctrl);
|
|
239
244
|
},
|
|
240
|
-
onmessage: (
|
|
245
|
+
onmessage: (s) => {
|
|
241
246
|
if (this._stopAnswer)
|
|
242
247
|
return;
|
|
243
|
-
let
|
|
244
|
-
|
|
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: (
|
|
247
|
-
this._stopAnswer || (
|
|
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
|
|
265
|
+
return u(this, null, function* () {
|
|
261
266
|
throw new Error("MCP registration is not supported by DialogSession");
|
|
262
267
|
});
|
|
263
268
|
}
|
|
264
|
-
addMcpServers(
|
|
265
|
-
return
|
|
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
|
|
275
|
+
return u(this, null, function* () {
|
|
271
276
|
throw new Error("MCP registration is not supported by DialogSession");
|
|
272
277
|
});
|
|
273
278
|
}
|
|
274
|
-
convertKnowledgesToChatFormat(
|
|
275
|
-
return
|
|
276
|
-
id:
|
|
277
|
-
fileIds:
|
|
278
|
-
} :
|
|
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
|
-
|
|
287
|
+
Y as default
|
|
283
288
|
};
|
package/dist/es/EventBus.mjs
CHANGED
|
@@ -1,64 +1,68 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
for (var
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
for (var
|
|
9
|
-
L.call(e,
|
|
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
|
|
12
|
+
var v = (s, e, t) => (f(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
13
13
|
import M from "./Logger.mjs";
|
|
14
|
-
const
|
|
15
|
-
class
|
|
14
|
+
const o = new M("[EventBus] ");
|
|
15
|
+
class m {
|
|
16
|
+
/** disableLog 只关掉这一条总线;日志本身仍受 debug 模式控制。 */
|
|
16
17
|
constructor(e = !1) {
|
|
17
|
-
|
|
18
|
-
|
|
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,
|
|
27
|
+
on(e, t, r = !1) {
|
|
24
28
|
this.eventListenerMap[e] || (this.eventListenerMap[e] = []), r ? this.eventListenerMap[e].push({
|
|
25
|
-
fn:
|
|
29
|
+
fn: t,
|
|
26
30
|
once: !0
|
|
27
|
-
}) : this.eventListenerMap[e].push(
|
|
31
|
+
}) : this.eventListenerMap[e].push(t), this.trace(`add event ${e} listener ${r ? ", call once" : ""}`);
|
|
28
32
|
}
|
|
29
|
-
once(e,
|
|
30
|
-
this.on(e,
|
|
33
|
+
once(e, t) {
|
|
34
|
+
this.on(e, t, !0);
|
|
31
35
|
}
|
|
32
|
-
off(e,
|
|
36
|
+
off(e, t) {
|
|
33
37
|
if (this.eventListenerMap[e]) {
|
|
34
|
-
const r = this.eventListenerMap[e].findIndex((
|
|
35
|
-
if (typeof
|
|
38
|
+
const r = this.eventListenerMap[e].findIndex((n) => {
|
|
39
|
+
if (typeof n == "function" && t === n)
|
|
36
40
|
return !0;
|
|
37
|
-
if (
|
|
41
|
+
if (n = n, n.fn === t)
|
|
38
42
|
return !0;
|
|
39
43
|
});
|
|
40
|
-
r < 0 ?
|
|
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
|
-
|
|
46
|
+
this.trace(`event ${e} listeners is empty`);
|
|
43
47
|
}
|
|
44
|
-
emit(e,
|
|
48
|
+
emit(e, t) {
|
|
45
49
|
if (!this.eventListenerMap[e]) {
|
|
46
|
-
|
|
50
|
+
this.trace(`event ${e} listeners is empty`, t);
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
49
53
|
const r = [];
|
|
50
|
-
for (let
|
|
51
|
-
const
|
|
52
|
-
typeof
|
|
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((
|
|
55
|
-
|
|
56
|
-
}),
|
|
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
|
-
|
|
67
|
+
m as default
|
|
64
68
|
};
|
package/dist/es/Logger.mjs
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
constructor(
|
|
6
|
-
this.prefix =
|
|
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
|
-
|
|
9
|
-
this.
|
|
8
|
+
log(...r) {
|
|
9
|
+
e.debug && console.log(this.prefix, ...r);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
this.
|
|
11
|
+
info(...r) {
|
|
12
|
+
e.debug && console.info(`%c ${this.prefix} %o`, "color:#0f0;", ...r);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
warn(...r) {
|
|
15
|
+
e.debug && console.warn(this.prefix, ...r);
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
error(...r) {
|
|
18
|
+
e.debug && console.error(this.prefix, ...r);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
28
|
-
let t =
|
|
25
|
+
s(e, "debug", !1);
|
|
26
|
+
let t = e;
|
|
29
27
|
export {
|
|
30
28
|
t as default
|
|
31
29
|
};
|
package/dist/es/PayloadTypes.mjs
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
var
|
|
1
|
+
var i = /* @__PURE__ */ ((n) => (n[n.Normal = 0] = "Normal", n[n.Debug = 1] = "Debug", n))(i || {}), a = /* @__PURE__ */ ((n) => (n[n.InsufficientBalance = 11937] = "InsufficientBalance", n[n.ConversionFailed = 11938] = "ConversionFailed", n[n.QuotaCheckFailed = 11939] = "QuotaCheckFailed", n))(a || {});
|
|
2
|
+
const t = {
|
|
3
|
+
11937: "余额不足",
|
|
4
|
+
11938: "用量换算失败",
|
|
5
|
+
11939: "额度校验失败"
|
|
6
|
+
};
|
|
7
|
+
function u(n) {
|
|
8
|
+
return n === 11937 || n === 11938 || n === 11939;
|
|
9
|
+
}
|
|
2
10
|
export {
|
|
3
|
-
|
|
11
|
+
t as USAGE_ERROR_DEFAULT_MESSAGES,
|
|
12
|
+
a as UsageErrorCode,
|
|
13
|
+
i as UserMode,
|
|
14
|
+
u as isUsageErrorCode
|
|
4
15
|
};
|