@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
package/dist/es/api/index.mjs
CHANGED
|
@@ -2,49 +2,50 @@ var g = Object.defineProperty, d = Object.defineProperties;
|
|
|
2
2
|
var E = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var u = Object.getOwnPropertySymbols;
|
|
4
4
|
var x = Object.prototype.hasOwnProperty, v = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var f = (t, e
|
|
6
|
-
for (var
|
|
7
|
-
x.call(
|
|
5
|
+
var f = (r, t, e) => t in r ? g(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, m = (r, t) => {
|
|
6
|
+
for (var e in t || (t = {}))
|
|
7
|
+
x.call(t, e) && f(r, e, t[e]);
|
|
8
8
|
if (u)
|
|
9
|
-
for (var
|
|
10
|
-
v.call(
|
|
11
|
-
return
|
|
12
|
-
}, h = (
|
|
9
|
+
for (var e of u(t))
|
|
10
|
+
v.call(t, e) && f(r, e, t[e]);
|
|
11
|
+
return r;
|
|
12
|
+
}, h = (r, t) => d(r, E(t));
|
|
13
13
|
import I from "axios";
|
|
14
|
-
import { isExpired as
|
|
15
|
-
import { CVForceApi as
|
|
16
|
-
function
|
|
17
|
-
return new
|
|
14
|
+
import { isExpired as k } from "../utils.mjs";
|
|
15
|
+
import { CVForceApi as $, AIShopApi as w } from "@glodon-aiot/apis";
|
|
16
|
+
function V(r, t, e) {
|
|
17
|
+
return new $(A(r, "/data/v1", t, e), S(e));
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return new
|
|
19
|
+
function b(r, t, e) {
|
|
20
|
+
return new w(A(r, "/aishop", t, e), S(e));
|
|
21
21
|
}
|
|
22
|
-
function A(t, e,
|
|
23
|
-
const
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
function A(r, t, e, o) {
|
|
23
|
+
const s = (n) => {
|
|
24
|
+
var a;
|
|
25
|
+
const i = e();
|
|
26
|
+
return i && (k(i) && o(403, "aiotToken is timeout"), n.headers = (a = n.headers) != null ? a : {}, n.headers = h(m({}, n.headers), {
|
|
27
|
+
Authorization: i ? `Bearer ${i}` : ""
|
|
27
28
|
})), n;
|
|
28
29
|
};
|
|
29
|
-
function
|
|
30
|
-
const
|
|
31
|
-
baseURL:
|
|
30
|
+
function p(n, i = !0) {
|
|
31
|
+
const a = `${r}${n}`, c = I.create({
|
|
32
|
+
baseURL: a
|
|
32
33
|
});
|
|
33
|
-
return
|
|
34
|
+
return i && c.interceptors.request.use(s), c;
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return p(t);
|
|
36
37
|
}
|
|
37
|
-
function S(
|
|
38
|
+
function S(r) {
|
|
38
39
|
return {
|
|
39
|
-
onHttpStatusError: (o,
|
|
40
|
-
o === 401 &&
|
|
40
|
+
onHttpStatusError: (o, s) => {
|
|
41
|
+
o === 401 && r(o, "aiotToken is invalid");
|
|
41
42
|
},
|
|
42
|
-
onAppStatusError: (o,
|
|
43
|
-
o !== 10001 && o !== 10215 &&
|
|
43
|
+
onAppStatusError: (o, s) => {
|
|
44
|
+
o !== 10001 && o !== 10215 && r(o, s);
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
b as getAIShopService,
|
|
50
|
+
V as getCVForceService
|
|
50
51
|
};
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
const
|
|
1
|
+
const s = ["shell", "read_file", "write_file", "append_file", "run_file", "edit_file", "grep", "find", "load_skill", "read_skill_resource", "list_skill_files", "grep_skill", "run_skill_script"], _ = 81920, e = 81920, l = 2e4, i = ".", n = "/workspace", o = {
|
|
2
|
+
".py": "python3",
|
|
3
|
+
".sh": "sh",
|
|
4
|
+
".bash": "sh",
|
|
5
|
+
".js": "node",
|
|
6
|
+
".mjs": "node",
|
|
7
|
+
".cjs": "node"
|
|
8
|
+
};
|
|
2
9
|
export {
|
|
3
|
-
|
|
10
|
+
s as BUILTIN_FUNCTION_CODES,
|
|
4
11
|
l as MAX_COMMAND_CHARS,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
o as
|
|
12
|
+
_ as MAX_READ_BYTES,
|
|
13
|
+
e as MAX_WRITE_BYTES,
|
|
14
|
+
o as SCRIPT_PROGRAMS,
|
|
8
15
|
i as SHELL_CWD,
|
|
9
16
|
n as WORKSPACE_MOUNT
|
|
10
17
|
};
|
|
@@ -1,73 +1,75 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
1
|
+
var W = Object.defineProperty, X = Object.defineProperties;
|
|
2
|
+
var Q = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var C = Object.getOwnPropertySymbols;
|
|
4
|
+
var Y = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable;
|
|
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
|
+
if (C)
|
|
9
|
+
for (var n of C(t))
|
|
10
|
+
Z.call(t, n) && j(e, n, t[n]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var d = (
|
|
12
|
+
}, _ = (e, t) => X(e, Q(t));
|
|
13
|
+
var H = (e, t, n) => new Promise((o, m) => {
|
|
14
|
+
var d = (r) => {
|
|
15
15
|
try {
|
|
16
|
-
c(
|
|
17
|
-
} catch (
|
|
18
|
-
m(
|
|
16
|
+
c(n.next(r));
|
|
17
|
+
} catch (i) {
|
|
18
|
+
m(i);
|
|
19
19
|
}
|
|
20
|
-
}, f = (
|
|
20
|
+
}, f = (r) => {
|
|
21
21
|
try {
|
|
22
|
-
c(
|
|
23
|
-
} catch (
|
|
24
|
-
m(
|
|
22
|
+
c(n.throw(r));
|
|
23
|
+
} catch (i) {
|
|
24
|
+
m(i);
|
|
25
25
|
}
|
|
26
|
-
}, c = (
|
|
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
|
-
import { v4 as
|
|
30
|
-
import
|
|
31
|
-
import { HostBridgeAdapter as
|
|
32
|
-
import { domError as
|
|
33
|
-
import { SANDBOX_PROTOCOL as
|
|
34
|
-
import { cancelledError as
|
|
35
|
-
import { validateToolInput as
|
|
36
|
-
import { BrowserCommandRunner as
|
|
37
|
-
import { withOutputLimit as
|
|
38
|
-
import { BUILTIN_FUNCTION_CODES as
|
|
39
|
-
import { BUILTIN_TOOL_SCHEMAS as
|
|
40
|
-
import { shell as
|
|
41
|
-
const
|
|
42
|
-
shell:
|
|
43
|
-
read_file:
|
|
44
|
-
write_file:
|
|
45
|
-
append_file:
|
|
46
|
-
run_file:
|
|
47
|
-
edit_file:
|
|
48
|
-
grep:
|
|
49
|
-
find:
|
|
50
|
-
load_skill:
|
|
51
|
-
read_skill_resource:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
29
|
+
import { v4 as ee } from "uuid";
|
|
30
|
+
import te from "../Logger.mjs";
|
|
31
|
+
import { HostBridgeAdapter as V } from "../localFiles/adapters/HostBridgeAdapter.mjs";
|
|
32
|
+
import { domError as $ } from "../localFiles/adapters/WorkspaceFileAdapter.mjs";
|
|
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
|
+
import { validateToolInput as ie } from "../localFiles/validate.mjs";
|
|
36
|
+
import { BrowserCommandRunner as se } from "./browserRuntime/BrowserCommandRunner.mjs";
|
|
37
|
+
import { withOutputLimit as L } from "./command.mjs";
|
|
38
|
+
import { BUILTIN_FUNCTION_CODES as le, SHELL_CWD as ae } from "./constants.mjs";
|
|
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 we, grepSkill as Te, runSkillScript as Ie } from "./tools.mjs";
|
|
41
|
+
const pe = {
|
|
42
|
+
shell: ce,
|
|
43
|
+
read_file: me,
|
|
44
|
+
write_file: ue,
|
|
45
|
+
append_file: fe,
|
|
46
|
+
run_file: ge,
|
|
47
|
+
edit_file: he,
|
|
48
|
+
grep: _e,
|
|
49
|
+
find: be,
|
|
50
|
+
load_skill: ye,
|
|
51
|
+
read_skill_resource: xe,
|
|
52
|
+
list_skill_files: we,
|
|
53
|
+
grep_skill: Te,
|
|
54
|
+
run_skill_script: Ie
|
|
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;
|
|
56
58
|
if (e.commandRunner)
|
|
57
|
-
return
|
|
58
|
-
if (t instanceof
|
|
59
|
+
return L(e.commandRunner);
|
|
60
|
+
if (t instanceof V) {
|
|
59
61
|
if (t.protocolMismatch) {
|
|
60
|
-
const d = `${(
|
|
61
|
-
|
|
62
|
+
const d = `${(o = t.sandboxVersion) != null ? o : ""}@${(m = t.sandboxProtocol) != null ? m : ""}`;
|
|
63
|
+
n.rejectedSandbox !== d && (n.rejectedSandbox = d, b.error("sandbox-protocol", {
|
|
62
64
|
sandboxVersion: t.sandboxVersion,
|
|
63
65
|
sandboxProtocol: t.sandboxProtocol,
|
|
64
|
-
supported:
|
|
66
|
+
supported: ne
|
|
65
67
|
}));
|
|
66
68
|
}
|
|
67
69
|
if (!t.canExec) {
|
|
68
70
|
const d = t.unavailableMessage();
|
|
69
71
|
return {
|
|
70
|
-
exec: () => Promise.reject(
|
|
72
|
+
exec: () => Promise.reject($("NotAllowedError", d))
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
75
|
return {
|
|
@@ -75,75 +77,92 @@ function pe(e, t, o) {
|
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
if (e.browserRuntime.enabled)
|
|
78
|
-
return (
|
|
80
|
+
return (n.adapter !== t || !n.runner) && (n.adapter = t, n.runner = L(new se({
|
|
79
81
|
adapter: t,
|
|
80
82
|
sensitive: e.sensitive,
|
|
81
83
|
moduleURL: e.browserRuntime.bashModuleURL,
|
|
82
84
|
pyodideIndexURL: e.browserRuntime.pyodideIndexURL
|
|
83
|
-
}))),
|
|
85
|
+
}))), n.runner;
|
|
84
86
|
}
|
|
85
|
-
function
|
|
87
|
+
function Oe(e, t) {
|
|
88
|
+
if (e.commandRunner)
|
|
89
|
+
return L(e.commandRunner);
|
|
90
|
+
if (t instanceof V) {
|
|
91
|
+
if (!t.canExec) {
|
|
92
|
+
const n = t.unavailableMessage();
|
|
93
|
+
return {
|
|
94
|
+
exec: () => Promise.reject($("NotAllowedError", n))
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
exec: (n) => t.exec(n)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function Re(e) {
|
|
86
103
|
if (typeof e != "string")
|
|
87
104
|
return e;
|
|
88
105
|
try {
|
|
89
106
|
return JSON.parse(e);
|
|
90
107
|
} catch (t) {
|
|
91
|
-
throw new u(
|
|
108
|
+
throw new u(a.BadRequest, "参数不是合法的 JSON 对象。");
|
|
92
109
|
}
|
|
93
110
|
}
|
|
94
|
-
function
|
|
95
|
-
const t = e instanceof DOMException ? e.name : "",
|
|
111
|
+
function Se(e) {
|
|
112
|
+
const t = e instanceof DOMException ? e.name : "", n = e instanceof Error ? e.message : "";
|
|
96
113
|
if (t === "NotFoundError")
|
|
97
|
-
return new u(
|
|
114
|
+
return new u(a.NotFound, "脚本或目录不存在。");
|
|
98
115
|
if (t === "SecurityError")
|
|
99
|
-
return new u(
|
|
116
|
+
return new u(a.Forbidden, "命令路径不在工作区内。");
|
|
100
117
|
if (t === "AbortError")
|
|
101
|
-
return
|
|
102
|
-
if (t === "NotAllowedError")
|
|
103
|
-
|
|
118
|
+
return n.includes("超时") ? new u(a.Timeout, "命令运行超时,已中止。") : n.includes("已有") || n.includes("上限") ? new u(a.TooManyRequests, n) : w();
|
|
119
|
+
if (t === "NotAllowedError") {
|
|
120
|
+
const o = n.trim();
|
|
121
|
+
return o && o !== "NotAllowedError" ? new u(a.NotImplemented, o) : new u(a.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
|
|
122
|
+
}
|
|
104
123
|
}
|
|
105
|
-
function
|
|
106
|
-
return new Promise((t,
|
|
107
|
-
e.aborted &&
|
|
124
|
+
function Le(e) {
|
|
125
|
+
return new Promise((t, n) => {
|
|
126
|
+
e.aborted && n(w()), e.addEventListener("abort", () => n(w()), {
|
|
108
127
|
once: !0
|
|
109
128
|
});
|
|
110
129
|
});
|
|
111
130
|
}
|
|
112
|
-
function
|
|
131
|
+
function k(e, t = 160) {
|
|
113
132
|
return e.length > t ? `${e.slice(0, t)}…` : e;
|
|
114
133
|
}
|
|
115
|
-
function
|
|
134
|
+
function Ne(e) {
|
|
116
135
|
const t = {};
|
|
117
|
-
for (const
|
|
118
|
-
typeof e[
|
|
119
|
-
return typeof e.command == "string" && (t.command =
|
|
136
|
+
for (const n of ["path", "skill_name", "resource_name", "script_name", "pattern", "name"])
|
|
137
|
+
typeof e[n] == "string" && (t[n] = e[n]);
|
|
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;
|
|
120
139
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
140
|
+
function Me(e) {
|
|
141
|
+
return l({
|
|
123
142
|
code: e.code,
|
|
124
143
|
message: e.message
|
|
125
144
|
}, e.data ? {
|
|
126
145
|
data: e.data
|
|
127
146
|
} : {});
|
|
128
147
|
}
|
|
129
|
-
function
|
|
148
|
+
function Je({
|
|
130
149
|
pluginCode: e,
|
|
131
150
|
workspace: t
|
|
132
151
|
}) {
|
|
133
|
-
const
|
|
134
|
-
return
|
|
135
|
-
m[d] = (f, c,
|
|
136
|
-
let
|
|
137
|
-
|
|
138
|
-
if (!
|
|
139
|
-
|
|
152
|
+
const n = /* @__PURE__ */ new Map(), o = {}, m = {};
|
|
153
|
+
return le.forEach((d) => {
|
|
154
|
+
m[d] = (f, c, r) => {
|
|
155
|
+
let i = !1;
|
|
156
|
+
Fe(t, n, o, d, f, (I) => {
|
|
157
|
+
if (!i) {
|
|
158
|
+
i = !0;
|
|
140
159
|
try {
|
|
141
|
-
c(
|
|
142
|
-
} catch (
|
|
143
|
-
|
|
160
|
+
c(I);
|
|
161
|
+
} catch (R) {
|
|
162
|
+
b.report("callback failed", R);
|
|
144
163
|
}
|
|
145
164
|
}
|
|
146
|
-
},
|
|
165
|
+
}, _(l({}, r), {
|
|
147
166
|
pluginCode: e
|
|
148
167
|
}));
|
|
149
168
|
};
|
|
@@ -151,94 +170,97 @@ function He({
|
|
|
151
170
|
[e]: m
|
|
152
171
|
};
|
|
153
172
|
}
|
|
154
|
-
function
|
|
155
|
-
return
|
|
156
|
-
var
|
|
173
|
+
function Fe(e, t, n, o, m, d, f) {
|
|
174
|
+
return H(this, null, function* () {
|
|
175
|
+
var F, A, v, q, P;
|
|
157
176
|
const c = {
|
|
158
|
-
requestId: f.requestId ||
|
|
177
|
+
requestId: f.requestId || ee(),
|
|
159
178
|
applicationId: f.applicationId || e.applicationId,
|
|
160
179
|
sessionId: f.sessionId || "",
|
|
161
180
|
pluginCode: f.pluginCode,
|
|
162
|
-
functionCode:
|
|
181
|
+
functionCode: o,
|
|
163
182
|
signal: f.signal
|
|
164
|
-
},
|
|
183
|
+
}, r = {
|
|
165
184
|
requestId: c.requestId,
|
|
166
185
|
sessionId: c.sessionId,
|
|
167
|
-
functionCode:
|
|
168
|
-
},
|
|
169
|
-
let
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
(
|
|
186
|
+
functionCode: o
|
|
187
|
+
}, i = new AbortController();
|
|
188
|
+
let T = !1;
|
|
189
|
+
const I = S.has(o) ? e.limits.commandTimeoutMs : e.limits.toolTimeoutMs, R = setTimeout(() => {
|
|
190
|
+
T = !0, i.abort();
|
|
191
|
+
}, I), N = () => i.abort();
|
|
192
|
+
(F = c.signal) == null || F.addEventListener("abort", N, {
|
|
174
193
|
once: !0
|
|
175
|
-
}), (
|
|
176
|
-
let
|
|
177
|
-
const
|
|
194
|
+
}), (A = c.signal) != null && A.aborted && i.abort();
|
|
195
|
+
let y = null, x = null, p;
|
|
196
|
+
const M = Date.now();
|
|
178
197
|
try {
|
|
179
|
-
const
|
|
180
|
-
if (typeof
|
|
181
|
-
throw
|
|
182
|
-
const
|
|
183
|
-
if (!
|
|
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
|
+
const g = e.adapter;
|
|
202
|
+
if (!g)
|
|
184
203
|
throw oe();
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
204
|
+
if (S.has(o)) {
|
|
205
|
+
if (x = e.acquireCommand(), !x)
|
|
206
|
+
throw new u(a.TooManyRequests, "已有一个命令在运行,请等它结束后再试。");
|
|
207
|
+
} else if (y = e.acquireSlot(), !y)
|
|
208
|
+
throw new u(a.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
|
|
209
|
+
p = e.track(i), e.emit("tool:start", l({}, r));
|
|
210
|
+
const B = c.sessionId || "default";
|
|
211
|
+
let h = t.get(B);
|
|
212
|
+
h || (h = {
|
|
213
|
+
cwd: ae
|
|
214
|
+
}, t.set(B, h));
|
|
215
|
+
const J = Ee(e, g, n), z = h.cwd, G = {
|
|
216
|
+
adapter: g,
|
|
217
|
+
runner: J,
|
|
218
|
+
signal: i.signal,
|
|
219
|
+
timeoutMs: I,
|
|
220
|
+
shellCwd: h,
|
|
221
|
+
skills: e.platformSkills,
|
|
222
|
+
skillRunner: Oe(e, g)
|
|
223
|
+
}, O = yield Promise.race([pe[o](s, G), Le(i.signal)]), D = {
|
|
224
|
+
code: a.Ok,
|
|
203
225
|
message: "ok",
|
|
204
|
-
data:
|
|
226
|
+
data: O.data
|
|
205
227
|
};
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
elapsedMs:
|
|
210
|
-
code:
|
|
211
|
-
}),
|
|
228
|
+
O.truncated && (D.truncated = !0);
|
|
229
|
+
const K = Date.now() - M, U = O.data.exitCode;
|
|
230
|
+
b.log("finish", l(l(l(_(l({}, r), {
|
|
231
|
+
elapsedMs: K,
|
|
232
|
+
code: a.Ok
|
|
233
|
+
}), O.truncated ? {
|
|
212
234
|
truncated: !0
|
|
213
|
-
} : {}), typeof
|
|
214
|
-
exitCode:
|
|
215
|
-
} : {}),
|
|
216
|
-
cwd:
|
|
217
|
-
cwdChanged:
|
|
218
|
-
} : {})), e.emit("tool:finish",
|
|
219
|
-
code:
|
|
220
|
-
})),
|
|
221
|
-
} catch (
|
|
222
|
-
let
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
elapsedMs:
|
|
227
|
-
timedOut:
|
|
228
|
-
})), e.emit("tool:cancelled",
|
|
229
|
-
elapsedMs:
|
|
230
|
-
code:
|
|
231
|
-
message:
|
|
232
|
-
})), e.emit("tool:error",
|
|
233
|
-
code:
|
|
234
|
-
message:
|
|
235
|
-
reason: (
|
|
236
|
-
}))), d(
|
|
235
|
+
} : {}), typeof U == "number" ? {
|
|
236
|
+
exitCode: U
|
|
237
|
+
} : {}), o === "shell" ? {
|
|
238
|
+
cwd: h.cwd,
|
|
239
|
+
cwdChanged: h.cwd !== z
|
|
240
|
+
} : {})), e.emit("tool:finish", _(l({}, r), {
|
|
241
|
+
code: a.Ok
|
|
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
|
+
const g = Date.now() - M;
|
|
247
|
+
s.code === a.Cancelled ? (b.log("cancelled", _(l({}, r), {
|
|
248
|
+
elapsedMs: g,
|
|
249
|
+
timedOut: T
|
|
250
|
+
})), e.emit("tool:cancelled", l({}, r))) : (b.error("error", _(l({}, r), {
|
|
251
|
+
elapsedMs: g,
|
|
252
|
+
code: s.code,
|
|
253
|
+
message: k(s.message, 300)
|
|
254
|
+
})), e.emit("tool:error", _(l({}, r), {
|
|
255
|
+
code: s.code,
|
|
256
|
+
message: s.message,
|
|
257
|
+
reason: (q = s.data) == null ? void 0 : q.reason
|
|
258
|
+
}))), d(Me(s));
|
|
237
259
|
} finally {
|
|
238
|
-
clearTimeout(
|
|
260
|
+
clearTimeout(R), (P = c.signal) == null || P.removeEventListener("abort", N), y == null || y(), x == null || x(), p == null || p();
|
|
239
261
|
}
|
|
240
262
|
});
|
|
241
263
|
}
|
|
242
264
|
export {
|
|
243
|
-
|
|
265
|
+
Je as createBuiltinToolsPlugin
|
|
244
266
|
};
|
|
@@ -1,39 +1,45 @@
|
|
|
1
1
|
import { ToolError as o, ToolCode as i } from "../localFiles/errors.mjs";
|
|
2
|
-
const
|
|
3
|
-
function
|
|
4
|
-
return
|
|
2
|
+
const f = ["input", "output", "uploads", "tmp"], c = "不要使用 input、output、uploads、tmp,也不要新建这些目录。请把文件直接放在工作区已有位置或根目录。", h = /(?:^|[\s'"=;|&<>`:])\/?(?:input|output|uploads|tmp)(?=\/|[\s'"=;|&<>`:]|$)/, d = /(?:^|[\s'"=;|&<>`:])\/?skills(?=\/|[\s'"=;|&<>`:]|$)/;
|
|
3
|
+
function a(t) {
|
|
4
|
+
return d.test(t);
|
|
5
|
+
}
|
|
6
|
+
function w(t) {
|
|
7
|
+
return h.test(t);
|
|
5
8
|
}
|
|
6
9
|
function u(t) {
|
|
7
10
|
const n = t.split("/")[0];
|
|
8
|
-
return
|
|
11
|
+
return f.includes(n);
|
|
9
12
|
}
|
|
10
13
|
function r(t) {
|
|
11
14
|
throw new o(i.Forbidden, t, {
|
|
12
15
|
reason: "path_outside_workspace"
|
|
13
16
|
});
|
|
14
17
|
}
|
|
15
|
-
function
|
|
18
|
+
function l(t) {
|
|
16
19
|
if (typeof t != "string" || t.length === 0)
|
|
17
|
-
throw new o(i.BadRequest, "path
|
|
20
|
+
throw new o(i.BadRequest, "path 必须是工作区内路径。");
|
|
18
21
|
(t.includes("\0") || t.includes("\\")) && r("路径不能包含反斜杠。");
|
|
19
22
|
const n = t.normalize("NFC").trim();
|
|
20
|
-
if (!n
|
|
21
|
-
throw new o(i.BadRequest, "path
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (!n)
|
|
24
|
+
throw new o(i.BadRequest, "path 必须是工作区内路径。");
|
|
25
|
+
/^[a-zA-Z]:/.test(n) && r("路径不能包含盘符。");
|
|
26
|
+
const e = n.split("/").filter((s) => s.length > 0 && s !== ".");
|
|
27
|
+
if (e.some((s) => s === "..") && r("路径不能包含 .. 。"), e.length > 0 && u(e[0]))
|
|
28
|
+
throw new o(i.BadRequest, c);
|
|
29
|
+
if (e[0] === "skills")
|
|
30
|
+
throw new o(i.Forbidden, "技能文件只能通过技能工具访问。");
|
|
25
31
|
return e.join("/");
|
|
26
32
|
}
|
|
27
|
-
function
|
|
28
|
-
return
|
|
33
|
+
function R(t) {
|
|
34
|
+
return l(t);
|
|
29
35
|
}
|
|
30
|
-
function
|
|
31
|
-
return
|
|
36
|
+
function S(t) {
|
|
37
|
+
return l(t);
|
|
32
38
|
}
|
|
33
|
-
function
|
|
39
|
+
function g(t) {
|
|
34
40
|
return t ? `/${t}` : "/";
|
|
35
41
|
}
|
|
36
|
-
function
|
|
42
|
+
function I(t) {
|
|
37
43
|
if (t === ".")
|
|
38
44
|
return !0;
|
|
39
45
|
if (!t || t.startsWith("/") || t.includes("\\") || t.includes("\0"))
|
|
@@ -41,7 +47,7 @@ function S(t) {
|
|
|
41
47
|
const n = t.split("/").filter((e) => e.length > 0);
|
|
42
48
|
return n.length > 0 && n.every((e) => e !== "." && e !== "..") && !u(n[0]);
|
|
43
49
|
}
|
|
44
|
-
function
|
|
50
|
+
function T(t, n) {
|
|
45
51
|
if (!t || /[\\/\0]/.test(t) || t === "." || t === "..")
|
|
46
52
|
throw new o(i.BadRequest, "skill_name 必须是单个技能目录名。");
|
|
47
53
|
if (!n || n.startsWith("/") || n.includes("\\") || n.includes("\0"))
|
|
@@ -50,14 +56,15 @@ function g(t, n) {
|
|
|
50
56
|
return (e.length === 0 || e.some((s) => s === "." || s === "..")) && r("资源路径不能跳出技能目录。"), `skills/${t}/${e.join("/")}`;
|
|
51
57
|
}
|
|
52
58
|
export {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
f as SYNTHETIC_DIRS,
|
|
60
|
+
c as SYNTHETIC_DIR_MESSAGE,
|
|
61
|
+
I as isSafeCwd,
|
|
56
62
|
u as isSyntheticCwd,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
a as mentionsSkillDir,
|
|
64
|
+
w as mentionsSyntheticDir,
|
|
65
|
+
R as resolveFilePath,
|
|
66
|
+
S as resolveRunPath,
|
|
67
|
+
l as resolveWorkspacePath,
|
|
68
|
+
T as skillRelative,
|
|
69
|
+
g as toVirtualPath
|
|
63
70
|
};
|