@glodon-aiot/bot-client-sdk 3.26.0-alpha.33 → 3.26.0-alpha.34
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/es/AgentSession.mjs +230 -214
- package/dist/es/BotClient.mjs +127 -85
- package/dist/es/Config.mjs +42 -42
- package/dist/es/DialogSession.mjs +121 -116
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/Session.mjs +306 -277
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +69 -69
- package/dist/es/builtinTools/platformSkills.mjs +85 -59
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
- package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +39 -34
- package/dist/es/localMcp/register.mjs +3 -3
- package/dist/es/package.json.mjs +28 -50
- package/dist/lib/index.js +44 -44
- package/dist/src/AgentSession.d.ts +1 -0
- package/dist/src/BotClient.d.ts +6 -1
- package/dist/src/Config.d.ts +2 -1
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/Session.d.ts +4 -2
- package/dist/src/builtinTools/platformSkills.d.ts +22 -1
- package/dist/src/constant.d.ts +1 -1
- package/package.json +3 -25
|
@@ -2,43 +2,43 @@ var W = Object.defineProperty, X = Object.defineProperties;
|
|
|
2
2
|
var Q = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var C = Object.getOwnPropertySymbols;
|
|
4
4
|
var Y = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var j = (e, t,
|
|
6
|
-
for (var
|
|
7
|
-
Y.call(t,
|
|
5
|
+
var j = (e, t, n) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, l = (e, t) => {
|
|
6
|
+
for (var n in t || (t = {}))
|
|
7
|
+
Y.call(t, n) && j(e, n, t[n]);
|
|
8
8
|
if (C)
|
|
9
|
-
for (var
|
|
10
|
-
Z.call(t,
|
|
9
|
+
for (var n of C(t))
|
|
10
|
+
Z.call(t, n) && j(e, n, t[n]);
|
|
11
11
|
return e;
|
|
12
12
|
}, _ = (e, t) => X(e, Q(t));
|
|
13
|
-
var H = (e, t,
|
|
13
|
+
var H = (e, t, n) => new Promise((o, m) => {
|
|
14
14
|
var d = (r) => {
|
|
15
15
|
try {
|
|
16
|
-
c(
|
|
16
|
+
c(n.next(r));
|
|
17
17
|
} catch (i) {
|
|
18
18
|
m(i);
|
|
19
19
|
}
|
|
20
20
|
}, f = (r) => {
|
|
21
21
|
try {
|
|
22
|
-
c(
|
|
22
|
+
c(n.throw(r));
|
|
23
23
|
} catch (i) {
|
|
24
24
|
m(i);
|
|
25
25
|
}
|
|
26
|
-
}, c = (r) => r.done ?
|
|
27
|
-
c((
|
|
26
|
+
}, c = (r) => r.done ? o(r.value) : Promise.resolve(r.value).then(d, f);
|
|
27
|
+
c((n = n.apply(e, t)).next());
|
|
28
28
|
});
|
|
29
29
|
import { v4 as ee } from "uuid";
|
|
30
30
|
import te from "../Logger.mjs";
|
|
31
31
|
import { HostBridgeAdapter as V } from "../localFiles/adapters/HostBridgeAdapter.mjs";
|
|
32
32
|
import { domError as $ } from "../localFiles/adapters/WorkspaceFileAdapter.mjs";
|
|
33
|
-
import { SANDBOX_PROTOCOL as
|
|
34
|
-
import { cancelledError as
|
|
33
|
+
import { SANDBOX_PROTOCOL as ne } from "../localFiles/host/protocol.mjs";
|
|
34
|
+
import { cancelledError as w, workspaceNotGranted as oe, ToolError as u, ToolCode as a, toToolError as re } from "../localFiles/errors.mjs";
|
|
35
35
|
import { validateToolInput as ie } from "../localFiles/validate.mjs";
|
|
36
36
|
import { BrowserCommandRunner as se } from "./browserRuntime/BrowserCommandRunner.mjs";
|
|
37
37
|
import { withOutputLimit as L } from "./command.mjs";
|
|
38
38
|
import { BUILTIN_FUNCTION_CODES as le, SHELL_CWD as ae } from "./constants.mjs";
|
|
39
39
|
import { BUILTIN_TOOL_SCHEMAS as de } from "./schemas.mjs";
|
|
40
|
-
import { shell as ce, readFile as me, writeFile as ue, appendFile as fe, runFile as ge, editFile as he, grep as _e, find as be, loadSkill as ye, readSkillResource as xe, listSkillFiles as
|
|
41
|
-
const
|
|
40
|
+
import { shell as ce, readFile as me, writeFile as ue, appendFile as fe, runFile as ge, editFile as he, grep as _e, find as be, loadSkill as ye, readSkillResource as xe, listSkillFiles as we, grepSkill as Te, runSkillScript as Ie } from "./tools.mjs";
|
|
41
|
+
const pe = {
|
|
42
42
|
shell: ce,
|
|
43
43
|
read_file: me,
|
|
44
44
|
write_file: ue,
|
|
@@ -49,21 +49,21 @@ const Ee = {
|
|
|
49
49
|
find: be,
|
|
50
50
|
load_skill: ye,
|
|
51
51
|
read_skill_resource: xe,
|
|
52
|
-
list_skill_files:
|
|
53
|
-
grep_skill:
|
|
52
|
+
list_skill_files: we,
|
|
53
|
+
grep_skill: Te,
|
|
54
54
|
run_skill_script: Ie
|
|
55
|
-
},
|
|
56
|
-
function
|
|
57
|
-
var
|
|
55
|
+
}, b = new te("[BuiltinTools] "), S = /* @__PURE__ */ new Set(["shell", "run_file", "run_skill_script"]);
|
|
56
|
+
function Ee(e, t, n) {
|
|
57
|
+
var o, m;
|
|
58
58
|
if (e.commandRunner)
|
|
59
59
|
return L(e.commandRunner);
|
|
60
60
|
if (t instanceof V) {
|
|
61
61
|
if (t.protocolMismatch) {
|
|
62
|
-
const d = `${(
|
|
63
|
-
|
|
62
|
+
const d = `${(o = t.sandboxVersion) != null ? o : ""}@${(m = t.sandboxProtocol) != null ? m : ""}`;
|
|
63
|
+
n.rejectedSandbox !== d && (n.rejectedSandbox = d, b.error("sandbox-protocol", {
|
|
64
64
|
sandboxVersion: t.sandboxVersion,
|
|
65
65
|
sandboxProtocol: t.sandboxProtocol,
|
|
66
|
-
supported:
|
|
66
|
+
supported: ne
|
|
67
67
|
}));
|
|
68
68
|
}
|
|
69
69
|
if (!t.canExec) {
|
|
@@ -77,25 +77,25 @@ function pe(e, t, o) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
if (e.browserRuntime.enabled)
|
|
80
|
-
return (
|
|
80
|
+
return (n.adapter !== t || !n.runner) && (n.adapter = t, n.runner = L(new se({
|
|
81
81
|
adapter: t,
|
|
82
82
|
sensitive: e.sensitive,
|
|
83
83
|
moduleURL: e.browserRuntime.bashModuleURL,
|
|
84
84
|
pyodideIndexURL: e.browserRuntime.pyodideIndexURL
|
|
85
|
-
}))),
|
|
85
|
+
}))), n.runner;
|
|
86
86
|
}
|
|
87
87
|
function Oe(e, t) {
|
|
88
88
|
if (e.commandRunner)
|
|
89
89
|
return L(e.commandRunner);
|
|
90
90
|
if (t instanceof V) {
|
|
91
91
|
if (!t.canExec) {
|
|
92
|
-
const
|
|
92
|
+
const n = t.unavailableMessage();
|
|
93
93
|
return {
|
|
94
|
-
exec: () => Promise.reject($("NotAllowedError",
|
|
94
|
+
exec: () => Promise.reject($("NotAllowedError", n))
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
return {
|
|
98
|
-
exec: (
|
|
98
|
+
exec: (n) => t.exec(n)
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -109,21 +109,21 @@ function Re(e) {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
function Se(e) {
|
|
112
|
-
const t = e instanceof DOMException ? e.name : "",
|
|
112
|
+
const t = e instanceof DOMException ? e.name : "", n = e instanceof Error ? e.message : "";
|
|
113
113
|
if (t === "NotFoundError")
|
|
114
114
|
return new u(a.NotFound, "脚本或目录不存在。");
|
|
115
115
|
if (t === "SecurityError")
|
|
116
116
|
return new u(a.Forbidden, "命令路径不在工作区内。");
|
|
117
117
|
if (t === "AbortError")
|
|
118
|
-
return
|
|
118
|
+
return n.includes("超时") ? new u(a.Timeout, "命令运行超时,已中止。") : n.includes("已有") || n.includes("上限") ? new u(a.TooManyRequests, n) : w();
|
|
119
119
|
if (t === "NotAllowedError") {
|
|
120
|
-
const
|
|
121
|
-
return
|
|
120
|
+
const o = n.trim();
|
|
121
|
+
return o && o !== "NotAllowedError" ? new u(a.NotImplemented, o) : new u(a.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
function Le(e) {
|
|
125
|
-
return new Promise((t,
|
|
126
|
-
e.aborted &&
|
|
125
|
+
return new Promise((t, n) => {
|
|
126
|
+
e.aborted && n(w()), e.addEventListener("abort", () => n(w()), {
|
|
127
127
|
once: !0
|
|
128
128
|
});
|
|
129
129
|
});
|
|
@@ -133,8 +133,8 @@ function k(e, t = 160) {
|
|
|
133
133
|
}
|
|
134
134
|
function Ne(e) {
|
|
135
135
|
const t = {};
|
|
136
|
-
for (const
|
|
137
|
-
typeof e[
|
|
136
|
+
for (const n of ["path", "skill_name", "resource_name", "script_name", "pattern", "name"])
|
|
137
|
+
typeof e[n] == "string" && (t[n] = e[n]);
|
|
138
138
|
return typeof e.command == "string" && (t.command = k(e.command)), typeof e.start_line == "number" && (t.start_line = e.start_line), typeof e.end_line == "number" && (t.end_line = e.end_line), typeof e.content == "string" && (t.contentLength = e.content.length), typeof e.old_text == "string" && (t.oldTextLength = e.old_text.length), typeof e.new_text == "string" && (t.newTextLength = e.new_text.length), Array.isArray(e.args) && (t.argCount = e.args.length), t;
|
|
139
139
|
}
|
|
140
140
|
function Me(e) {
|
|
@@ -149,17 +149,17 @@ function Je({
|
|
|
149
149
|
pluginCode: e,
|
|
150
150
|
workspace: t
|
|
151
151
|
}) {
|
|
152
|
-
const
|
|
152
|
+
const n = /* @__PURE__ */ new Map(), o = {}, m = {};
|
|
153
153
|
return le.forEach((d) => {
|
|
154
154
|
m[d] = (f, c, r) => {
|
|
155
155
|
let i = !1;
|
|
156
|
-
Fe(t,
|
|
156
|
+
Fe(t, n, o, d, f, (I) => {
|
|
157
157
|
if (!i) {
|
|
158
158
|
i = !0;
|
|
159
159
|
try {
|
|
160
160
|
c(I);
|
|
161
161
|
} catch (R) {
|
|
162
|
-
|
|
162
|
+
b.report("callback failed", R);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
}, _(l({}, r), {
|
|
@@ -170,49 +170,49 @@ function Je({
|
|
|
170
170
|
[e]: m
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
-
function Fe(e, t,
|
|
173
|
+
function Fe(e, t, n, o, m, d, f) {
|
|
174
174
|
return H(this, null, function* () {
|
|
175
|
-
var F, A, v, q,
|
|
175
|
+
var F, A, v, q, P;
|
|
176
176
|
const c = {
|
|
177
177
|
requestId: f.requestId || ee(),
|
|
178
178
|
applicationId: f.applicationId || e.applicationId,
|
|
179
179
|
sessionId: f.sessionId || "",
|
|
180
180
|
pluginCode: f.pluginCode,
|
|
181
|
-
functionCode:
|
|
181
|
+
functionCode: o,
|
|
182
182
|
signal: f.signal
|
|
183
183
|
}, r = {
|
|
184
184
|
requestId: c.requestId,
|
|
185
185
|
sessionId: c.sessionId,
|
|
186
|
-
functionCode:
|
|
186
|
+
functionCode: o
|
|
187
187
|
}, i = new AbortController();
|
|
188
|
-
let
|
|
189
|
-
const I = S.has(
|
|
190
|
-
|
|
188
|
+
let T = !1;
|
|
189
|
+
const I = S.has(o) ? e.limits.commandTimeoutMs : e.limits.toolTimeoutMs, R = setTimeout(() => {
|
|
190
|
+
T = !0, i.abort();
|
|
191
191
|
}, I), N = () => i.abort();
|
|
192
192
|
(F = c.signal) == null || F.addEventListener("abort", N, {
|
|
193
193
|
once: !0
|
|
194
194
|
}), (A = c.signal) != null && A.aborted && i.abort();
|
|
195
|
-
let
|
|
195
|
+
let y = null, x = null, p;
|
|
196
196
|
const M = Date.now();
|
|
197
197
|
try {
|
|
198
|
-
const
|
|
199
|
-
if (typeof s.path == "string" && (r.path = s.path),
|
|
200
|
-
throw
|
|
198
|
+
const E = Re(m), s = ie(E, de[o].parameters);
|
|
199
|
+
if (typeof s.path == "string" && (r.path = s.path), b.log("start", l(l({}, r), Ne(s))), yield e.ready, i.signal.aborted)
|
|
200
|
+
throw w();
|
|
201
201
|
const g = e.adapter;
|
|
202
202
|
if (!g)
|
|
203
|
-
throw
|
|
204
|
-
if (S.has(
|
|
205
|
-
if (
|
|
203
|
+
throw oe();
|
|
204
|
+
if (S.has(o)) {
|
|
205
|
+
if (x = e.acquireCommand(), !x)
|
|
206
206
|
throw new u(a.TooManyRequests, "已有一个命令在运行,请等它结束后再试。");
|
|
207
|
-
} else if (
|
|
207
|
+
} else if (y = e.acquireSlot(), !y)
|
|
208
208
|
throw new u(a.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
let h = t.get(
|
|
209
|
+
p = e.track(i), e.emit("tool:start", l({}, r));
|
|
210
|
+
const B = c.sessionId || "default";
|
|
211
|
+
let h = t.get(B);
|
|
212
212
|
h || (h = {
|
|
213
213
|
cwd: ae
|
|
214
|
-
}, t.set(
|
|
215
|
-
const J =
|
|
214
|
+
}, t.set(B, h));
|
|
215
|
+
const J = Ee(e, g, n), z = h.cwd, G = {
|
|
216
216
|
adapter: g,
|
|
217
217
|
runner: J,
|
|
218
218
|
signal: i.signal,
|
|
@@ -220,34 +220,34 @@ function Fe(e, t, o, n, m, d, f) {
|
|
|
220
220
|
shellCwd: h,
|
|
221
221
|
skills: e.platformSkills,
|
|
222
222
|
skillRunner: Oe(e, g)
|
|
223
|
-
}, O = yield Promise.race([
|
|
223
|
+
}, O = yield Promise.race([pe[o](s, G), Le(i.signal)]), D = {
|
|
224
224
|
code: a.Ok,
|
|
225
225
|
message: "ok",
|
|
226
226
|
data: O.data
|
|
227
227
|
};
|
|
228
228
|
O.truncated && (D.truncated = !0);
|
|
229
229
|
const K = Date.now() - M, U = O.data.exitCode;
|
|
230
|
-
|
|
230
|
+
b.log("finish", l(l(l(_(l({}, r), {
|
|
231
231
|
elapsedMs: K,
|
|
232
232
|
code: a.Ok
|
|
233
233
|
}), O.truncated ? {
|
|
234
234
|
truncated: !0
|
|
235
235
|
} : {}), typeof U == "number" ? {
|
|
236
236
|
exitCode: U
|
|
237
|
-
} : {}),
|
|
237
|
+
} : {}), o === "shell" ? {
|
|
238
238
|
cwd: h.cwd,
|
|
239
239
|
cwdChanged: h.cwd !== z
|
|
240
240
|
} : {})), e.emit("tool:finish", _(l({}, r), {
|
|
241
241
|
code: a.Ok
|
|
242
|
-
})), S.has(
|
|
243
|
-
} catch (
|
|
244
|
-
let s = (v = Se(
|
|
245
|
-
|
|
242
|
+
})), S.has(o) && e.notifyFilesChanged(), d(D);
|
|
243
|
+
} catch (E) {
|
|
244
|
+
let s = (v = Se(E)) != null ? v : re(E);
|
|
245
|
+
T ? s = new u(a.Timeout, "操作超时,已中止。") : i.signal.aborted && s.code !== a.Cancelled && (s = w());
|
|
246
246
|
const g = Date.now() - M;
|
|
247
|
-
s.code === a.Cancelled ? (
|
|
247
|
+
s.code === a.Cancelled ? (b.log("cancelled", _(l({}, r), {
|
|
248
248
|
elapsedMs: g,
|
|
249
|
-
timedOut:
|
|
250
|
-
})), e.emit("tool:cancelled", l({}, r))) : (
|
|
249
|
+
timedOut: T
|
|
250
|
+
})), e.emit("tool:cancelled", l({}, r))) : (b.error("error", _(l({}, r), {
|
|
251
251
|
elapsedMs: g,
|
|
252
252
|
code: s.code,
|
|
253
253
|
message: k(s.message, 300)
|
|
@@ -257,7 +257,7 @@ function Fe(e, t, o, n, m, d, f) {
|
|
|
257
257
|
reason: (q = s.data) == null ? void 0 : q.reason
|
|
258
258
|
}))), d(Me(s));
|
|
259
259
|
} finally {
|
|
260
|
-
clearTimeout(R), (
|
|
260
|
+
clearTimeout(R), (P = c.signal) == null || P.removeEventListener("abort", N), y == null || y(), x == null || x(), p == null || p();
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
}
|
|
@@ -1,48 +1,61 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var o = (
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var v = (e, t, n) => t in e ? b(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var y = (e, t, n) => (v(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
|
+
var o = (e, t, n) => new Promise((s, i) => {
|
|
5
5
|
var r = (a) => {
|
|
6
6
|
try {
|
|
7
7
|
d(n.next(a));
|
|
8
|
-
} catch (
|
|
9
|
-
|
|
8
|
+
} catch (h) {
|
|
9
|
+
i(h);
|
|
10
10
|
}
|
|
11
11
|
}, l = (a) => {
|
|
12
12
|
try {
|
|
13
13
|
d(n.throw(a));
|
|
14
|
-
} catch (
|
|
15
|
-
|
|
14
|
+
} catch (h) {
|
|
15
|
+
i(h);
|
|
16
16
|
}
|
|
17
17
|
}, d = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(r, l);
|
|
18
|
-
d((n = n.apply(
|
|
18
|
+
d((n = n.apply(e, t)).next());
|
|
19
19
|
});
|
|
20
|
+
import w from "../Logger.mjs";
|
|
20
21
|
import { ToolError as c, ToolCode as p } from "../localFiles/errors.mjs";
|
|
21
|
-
import { isExpired as
|
|
22
|
-
const w = 20 * 1024 * 1024,
|
|
23
|
-
function f(
|
|
24
|
-
const t =
|
|
22
|
+
import { isExpired as g } from "../utils.mjs";
|
|
23
|
+
const u = new w("[PlatformSkills] "), S = 20 * 1024 * 1024, k = /^[A-Za-z0-9._-]+$/;
|
|
24
|
+
function f(e) {
|
|
25
|
+
const t = e == null ? void 0 : e.skills;
|
|
25
26
|
return Array.isArray(t) ? t.filter((n) => n && typeof n == "object") : [];
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
28
|
+
function m(e, t) {
|
|
29
|
+
t && (e.skills = t.skills);
|
|
30
|
+
}
|
|
31
|
+
function P(e) {
|
|
32
|
+
return o(this, null, function* () {
|
|
33
|
+
var n;
|
|
34
|
+
if (!e.arrange)
|
|
35
|
+
return;
|
|
36
|
+
const t = yield e.fetchApplication();
|
|
37
|
+
e.stillCurrent && !e.stillCurrent() || m(e.arrange, (n = t == null ? void 0 : t.arrange) == null ? void 0 : n[0]);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function x(e) {
|
|
41
|
+
if (!e)
|
|
29
42
|
return !1;
|
|
30
43
|
try {
|
|
31
|
-
return !
|
|
44
|
+
return !g(e);
|
|
32
45
|
} catch (t) {
|
|
33
46
|
return !1;
|
|
34
47
|
}
|
|
35
48
|
}
|
|
36
|
-
function
|
|
37
|
-
if (!(typeof
|
|
49
|
+
function I(e) {
|
|
50
|
+
if (!(typeof e.skillId != "string" || !k.test(e.skillId)) && !(typeof e.name != "string" || !e.name || /[\\/\0]/.test(e.name) || e.name === "." || e.name === "..") && !(typeof e.version != "number" || !Number.isInteger(e.version) || e.version < 1))
|
|
38
51
|
return {
|
|
39
|
-
skillId:
|
|
40
|
-
name:
|
|
41
|
-
version:
|
|
52
|
+
skillId: e.skillId,
|
|
53
|
+
name: e.name,
|
|
54
|
+
version: e.version
|
|
42
55
|
};
|
|
43
56
|
}
|
|
44
|
-
function
|
|
45
|
-
return Array.isArray(
|
|
57
|
+
function $(e) {
|
|
58
|
+
return Array.isArray(e) ? e.flatMap((t) => {
|
|
46
59
|
if (!t || typeof t != "object")
|
|
47
60
|
return [];
|
|
48
61
|
const n = t;
|
|
@@ -53,33 +66,40 @@ function S(i) {
|
|
|
53
66
|
}];
|
|
54
67
|
}) : [];
|
|
55
68
|
}
|
|
56
|
-
class
|
|
69
|
+
class B {
|
|
57
70
|
constructor(t) {
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
y(this, "inflight", /* @__PURE__ */ new Map());
|
|
72
|
+
y(this, "busy", /* @__PURE__ */ new Set());
|
|
60
73
|
this.options = t;
|
|
61
74
|
}
|
|
62
75
|
/** 进入会话时调用。不阻塞历史,也不改沙箱就绪。 */
|
|
63
76
|
sync() {
|
|
64
|
-
|
|
77
|
+
const t = f({
|
|
78
|
+
skills: this.options.getSkills()
|
|
79
|
+
});
|
|
80
|
+
return u.log("sync", {
|
|
81
|
+
count: t.length,
|
|
82
|
+
sandbox: !!this.options.getSandbox()
|
|
83
|
+
}), this.reconcile().catch((n) => {
|
|
84
|
+
u.error("sync failed", n instanceof Error ? n.message : String(n));
|
|
65
85
|
});
|
|
66
86
|
}
|
|
67
87
|
read(t, n, s) {
|
|
68
88
|
return o(this, null, function* () {
|
|
69
|
-
const
|
|
70
|
-
return this.requireSandbox().skillRead(this.options.applicationId(),
|
|
89
|
+
const i = yield this.prepare(t, s);
|
|
90
|
+
return this.requireSandbox().skillRead(this.options.applicationId(), i.skillId, i.version, n, s);
|
|
71
91
|
});
|
|
72
92
|
}
|
|
73
93
|
list(t, n, s) {
|
|
74
94
|
return o(this, null, function* () {
|
|
75
|
-
const
|
|
76
|
-
return this.requireSandbox().skillList(this.options.applicationId(),
|
|
95
|
+
const i = yield this.prepare(t, s);
|
|
96
|
+
return this.requireSandbox().skillList(this.options.applicationId(), i.skillId, i.version, n, s);
|
|
77
97
|
});
|
|
78
98
|
}
|
|
79
|
-
grep(t, n, s,
|
|
99
|
+
grep(t, n, s, i) {
|
|
80
100
|
return o(this, null, function* () {
|
|
81
|
-
const r = yield this.prepare(t,
|
|
82
|
-
return this.requireSandbox().skillGrep(this.options.applicationId(), r.skillId, r.version, s, n,
|
|
101
|
+
const r = yield this.prepare(t, i);
|
|
102
|
+
return this.requireSandbox().skillGrep(this.options.applicationId(), r.skillId, r.version, s, n, i);
|
|
83
103
|
});
|
|
84
104
|
}
|
|
85
105
|
target(t, n) {
|
|
@@ -96,9 +116,9 @@ class R {
|
|
|
96
116
|
track(t, n) {
|
|
97
117
|
const s = `${t}/${n}`;
|
|
98
118
|
this.busy.add(s);
|
|
99
|
-
let
|
|
119
|
+
let i = !1;
|
|
100
120
|
return () => {
|
|
101
|
-
|
|
121
|
+
i || (i = !0, this.busy.delete(s), this.prune().catch(() => {
|
|
102
122
|
}));
|
|
103
123
|
};
|
|
104
124
|
}
|
|
@@ -117,12 +137,12 @@ class R {
|
|
|
117
137
|
});
|
|
118
138
|
}
|
|
119
139
|
bound(t) {
|
|
120
|
-
if (!
|
|
140
|
+
if (!k.test(this.options.applicationId()))
|
|
121
141
|
return;
|
|
122
142
|
const n = f({
|
|
123
143
|
skills: this.options.getSkills()
|
|
124
144
|
}).find((s) => s.name === t);
|
|
125
|
-
return n ?
|
|
145
|
+
return n ? I(n) : void 0;
|
|
126
146
|
}
|
|
127
147
|
reconcile() {
|
|
128
148
|
return o(this, null, function* () {
|
|
@@ -131,18 +151,19 @@ class R {
|
|
|
131
151
|
const n = f({
|
|
132
152
|
skills: this.options.getSkills()
|
|
133
153
|
}).flatMap((s) => {
|
|
134
|
-
const
|
|
135
|
-
return
|
|
154
|
+
const i = I(s);
|
|
155
|
+
return i ? [i] : [];
|
|
136
156
|
});
|
|
137
|
-
yield Promise.all(n.map((s) => this.ensure(s).catch(() => {
|
|
157
|
+
yield Promise.all(n.map((s) => this.ensure(s).catch((i) => {
|
|
158
|
+
u.error("install failed", s.name, i instanceof Error ? i.message : String(i));
|
|
138
159
|
}))), yield this.prune();
|
|
139
160
|
});
|
|
140
161
|
}
|
|
141
162
|
ensure(t, n) {
|
|
142
163
|
return o(this, null, function* () {
|
|
143
|
-
const s = `${this.options.applicationId()}/${t.skillId}/${t.version}`,
|
|
144
|
-
if (
|
|
145
|
-
return
|
|
164
|
+
const s = `${this.options.applicationId()}/${t.skillId}/${t.version}`, i = this.inflight.get(s);
|
|
165
|
+
if (i)
|
|
166
|
+
return i;
|
|
146
167
|
const r = this.installIfNeeded(t, n).finally(() => {
|
|
147
168
|
this.inflight.get(s) === r && this.inflight.delete(s);
|
|
148
169
|
});
|
|
@@ -153,21 +174,24 @@ class R {
|
|
|
153
174
|
return o(this, null, function* () {
|
|
154
175
|
var a;
|
|
155
176
|
const s = this.requireSandbox();
|
|
156
|
-
if (s.ready && (yield this.alreadyInstalled(s, t, n)))
|
|
177
|
+
if (s.ready && (yield this.alreadyInstalled(s, t, n))) {
|
|
178
|
+
u.log("installed", t.name, t.version);
|
|
157
179
|
return;
|
|
158
|
-
|
|
159
|
-
|
|
180
|
+
}
|
|
181
|
+
u.log("download", t.name, t.skillId, t.version);
|
|
182
|
+
const i = this.options.getToken();
|
|
183
|
+
if (!x(i))
|
|
160
184
|
throw new c(p.Forbidden, "技能下载令牌不可用。");
|
|
161
185
|
const r = this.options.apiRoot().replace(/\/$/, ""), l = yield ((a = this.options.fetch) != null ? a : fetch)(`${r}/skill/v1/skills/${encodeURIComponent(t.skillId)}/versions/${t.version}/download`, {
|
|
162
186
|
headers: {
|
|
163
|
-
Authorization: `Bearer ${
|
|
187
|
+
Authorization: `Bearer ${i}`
|
|
164
188
|
},
|
|
165
189
|
signal: n
|
|
166
190
|
});
|
|
167
191
|
if (!l.ok)
|
|
168
192
|
throw new c(p.BadRequest, `技能下载失败(${l.status})。`);
|
|
169
193
|
const d = new Uint8Array(yield l.arrayBuffer());
|
|
170
|
-
if (d.byteLength >
|
|
194
|
+
if (d.byteLength > S)
|
|
171
195
|
throw new c(p.BadRequest, "技能压缩包超过 20 MB。");
|
|
172
196
|
yield this.waitReady(s, n), !(yield this.alreadyInstalled(s, t, n)) && (yield s.installSkill({
|
|
173
197
|
applicationId: this.options.applicationId(),
|
|
@@ -179,7 +203,7 @@ class R {
|
|
|
179
203
|
}
|
|
180
204
|
alreadyInstalled(t, n, s) {
|
|
181
205
|
return o(this, null, function* () {
|
|
182
|
-
return
|
|
206
|
+
return $(yield t.skillStatus(this.options.applicationId(), s)).some((r) => r.skillId === n.skillId && r.version === n.version && r.name === n.name);
|
|
183
207
|
});
|
|
184
208
|
}
|
|
185
209
|
prune() {
|
|
@@ -189,11 +213,11 @@ class R {
|
|
|
189
213
|
return;
|
|
190
214
|
const n = f({
|
|
191
215
|
skills: this.options.getSkills()
|
|
192
|
-
}).flatMap((
|
|
193
|
-
skillId:
|
|
194
|
-
version:
|
|
195
|
-
}]), s = [...this.busy].map((
|
|
196
|
-
const [r, l] =
|
|
216
|
+
}).flatMap((i) => typeof i.skillId != "string" || typeof i.version != "number" || i.version < 1 ? [] : [{
|
|
217
|
+
skillId: i.skillId,
|
|
218
|
+
version: i.version
|
|
219
|
+
}]), s = [...this.busy].map((i) => {
|
|
220
|
+
const [r, l] = i.split("/");
|
|
197
221
|
return {
|
|
198
222
|
skillId: r,
|
|
199
223
|
version: Number(l)
|
|
@@ -204,10 +228,10 @@ class R {
|
|
|
204
228
|
}
|
|
205
229
|
waitReady(t, n) {
|
|
206
230
|
return o(this, null, function* () {
|
|
207
|
-
t.ready || (yield new Promise((s,
|
|
231
|
+
t.ready || (yield new Promise((s, i) => {
|
|
208
232
|
const r = setInterval(() => {
|
|
209
233
|
if (n != null && n.aborted) {
|
|
210
|
-
clearInterval(r),
|
|
234
|
+
clearInterval(r), i(new c(p.Cancelled, "已取消。"));
|
|
211
235
|
return;
|
|
212
236
|
}
|
|
213
237
|
t.ready && (clearInterval(r), s());
|
|
@@ -217,6 +241,8 @@ class R {
|
|
|
217
241
|
}
|
|
218
242
|
}
|
|
219
243
|
export {
|
|
220
|
-
|
|
221
|
-
|
|
244
|
+
B as PlatformSkillSync,
|
|
245
|
+
m as assignArrangeSkills,
|
|
246
|
+
f as listedSkills,
|
|
247
|
+
P as pullArrangeSkills
|
|
222
248
|
};
|