@glodon-aiot/bot-client-sdk 3.26.0-alpha.26 → 3.26.0-alpha.28

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.
@@ -1,48 +1,48 @@
1
1
  var k = Object.defineProperty;
2
- var v = (s, t, n) => t in s ? k(s, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : s[t] = n;
3
- var f = (s, t, n) => (v(s, typeof t != "symbol" ? t + "" : t, n), n);
4
- var a = (s, t, n) => new Promise((e, i) => {
5
- var r = (o) => {
2
+ var b = (i, t, n) => t in i ? k(i, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[t] = n;
3
+ var h = (i, t, n) => (b(i, typeof t != "symbol" ? t + "" : t, n), n);
4
+ var o = (i, t, n) => new Promise((s, e) => {
5
+ var r = (a) => {
6
6
  try {
7
- d(n.next(o));
7
+ d(n.next(a));
8
8
  } catch (u) {
9
- i(u);
9
+ e(u);
10
10
  }
11
- }, l = (o) => {
11
+ }, l = (a) => {
12
12
  try {
13
- d(n.throw(o));
13
+ d(n.throw(a));
14
14
  } catch (u) {
15
- i(u);
15
+ e(u);
16
16
  }
17
- }, d = (o) => o.done ? e(o.value) : Promise.resolve(o.value).then(r, l);
18
- d((n = n.apply(s, t)).next());
17
+ }, d = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(r, l);
18
+ d((n = n.apply(i, t)).next());
19
19
  });
20
20
  import { ToolError as c, ToolCode as p } from "../localFiles/errors.mjs";
21
- import { isExpired as w } from "../utils.mjs";
22
- const b = 20 * 1024 * 1024, I = /^[A-Za-z0-9._-]+$/;
23
- function h(s) {
24
- const t = s == null ? void 0 : s.skills;
21
+ import { isExpired as v } from "../utils.mjs";
22
+ const w = 20 * 1024 * 1024, I = /^[A-Za-z0-9._-]+$/;
23
+ function f(i) {
24
+ const t = i == null ? void 0 : i.skills;
25
25
  return Array.isArray(t) ? t.filter((n) => n && typeof n == "object") : [];
26
26
  }
27
- function m(s) {
28
- if (!s)
27
+ function x(i) {
28
+ if (!i)
29
29
  return !1;
30
30
  try {
31
- return !w(s);
31
+ return !v(i);
32
32
  } catch (t) {
33
33
  return !1;
34
34
  }
35
35
  }
36
- function y(s) {
37
- if (!(typeof s.skillId != "string" || !I.test(s.skillId)) && !(typeof s.name != "string" || !s.name || /[\\/\0]/.test(s.name) || s.name === "." || s.name === "..") && !(typeof s.version != "number" || !Number.isInteger(s.version) || s.version < 1))
36
+ function y(i) {
37
+ if (!(typeof i.skillId != "string" || !I.test(i.skillId)) && !(typeof i.name != "string" || !i.name || /[\\/\0]/.test(i.name) || i.name === "." || i.name === "..") && !(typeof i.version != "number" || !Number.isInteger(i.version) || i.version < 1))
38
38
  return {
39
- skillId: s.skillId,
40
- name: s.name,
41
- version: s.version
39
+ skillId: i.skillId,
40
+ name: i.name,
41
+ version: i.version
42
42
  };
43
43
  }
44
- function S(s) {
45
- return Array.isArray(s) ? s.flatMap((t) => {
44
+ function S(i) {
45
+ return Array.isArray(i) ? i.flatMap((t) => {
46
46
  if (!t || typeof t != "object")
47
47
  return [];
48
48
  const n = t;
@@ -55,8 +55,8 @@ function S(s) {
55
55
  }
56
56
  class R {
57
57
  constructor(t) {
58
- f(this, "inflight", /* @__PURE__ */ new Map());
59
- f(this, "busy", /* @__PURE__ */ new Set());
58
+ h(this, "inflight", /* @__PURE__ */ new Map());
59
+ h(this, "busy", /* @__PURE__ */ new Set());
60
60
  this.options = t;
61
61
  }
62
62
  /** 进入会话时调用。不阻塞历史,也不改沙箱就绪。 */
@@ -64,29 +64,41 @@ class R {
64
64
  return this.reconcile().catch(() => {
65
65
  });
66
66
  }
67
- read(t, n, e) {
68
- return a(this, null, function* () {
69
- const i = yield this.prepare(t, e);
70
- return this.requireSandbox().skillRead(this.options.applicationId(), i.skillId, i.version, n, e);
67
+ read(t, n, s) {
68
+ return o(this, null, function* () {
69
+ const e = yield this.prepare(t, s);
70
+ return this.requireSandbox().skillRead(this.options.applicationId(), e.skillId, e.version, n, s);
71
+ });
72
+ }
73
+ list(t, n, s) {
74
+ return o(this, null, function* () {
75
+ const e = yield this.prepare(t, s);
76
+ return this.requireSandbox().skillList(this.options.applicationId(), e.skillId, e.version, n, s);
77
+ });
78
+ }
79
+ grep(t, n, s, e) {
80
+ return o(this, null, function* () {
81
+ const r = yield this.prepare(t, e);
82
+ return this.requireSandbox().skillGrep(this.options.applicationId(), r.skillId, r.version, s, n, e);
71
83
  });
72
84
  }
73
85
  target(t, n) {
74
- return a(this, null, function* () {
75
- const e = yield this.prepare(t, n);
86
+ return o(this, null, function* () {
87
+ const s = yield this.prepare(t, n);
76
88
  return {
77
89
  applicationId: this.options.applicationId(),
78
- skillId: e.skillId,
79
- version: e.version,
80
- name: e.name
90
+ skillId: s.skillId,
91
+ version: s.version,
92
+ name: s.name
81
93
  };
82
94
  });
83
95
  }
84
96
  track(t, n) {
85
- const e = `${t}/${n}`;
86
- this.busy.add(e);
87
- let i = !1;
97
+ const s = `${t}/${n}`;
98
+ this.busy.add(s);
99
+ let e = !1;
88
100
  return () => {
89
- i || (i = !0, this.busy.delete(e), this.prune().catch(() => {
101
+ e || (e = !0, this.busy.delete(s), this.prune().catch(() => {
90
102
  }));
91
103
  };
92
104
  }
@@ -97,67 +109,67 @@ class R {
97
109
  return t;
98
110
  }
99
111
  prepare(t, n) {
100
- return a(this, null, function* () {
101
- const e = this.bound(t);
102
- if (!e)
112
+ return o(this, null, function* () {
113
+ const s = this.bound(t);
114
+ if (!s)
103
115
  throw new c(p.NotFound, "技能或资源不存在。");
104
- return yield this.ensure(e, n), e;
116
+ return yield this.ensure(s, n), s;
105
117
  });
106
118
  }
107
119
  bound(t) {
108
120
  if (!I.test(this.options.applicationId()))
109
121
  return;
110
- const n = h({
122
+ const n = f({
111
123
  skills: this.options.getSkills()
112
- }).find((e) => e.name === t);
124
+ }).find((s) => s.name === t);
113
125
  return n ? y(n) : void 0;
114
126
  }
115
127
  reconcile() {
116
- return a(this, null, function* () {
128
+ return o(this, null, function* () {
117
129
  if (!this.options.getSandbox())
118
130
  return;
119
- const n = h({
131
+ const n = f({
120
132
  skills: this.options.getSkills()
121
- }).flatMap((e) => {
122
- const i = y(e);
123
- return i ? [i] : [];
133
+ }).flatMap((s) => {
134
+ const e = y(s);
135
+ return e ? [e] : [];
124
136
  });
125
- yield Promise.all(n.map((e) => this.ensure(e).catch(() => {
137
+ yield Promise.all(n.map((s) => this.ensure(s).catch(() => {
126
138
  }))), yield this.prune();
127
139
  });
128
140
  }
129
141
  ensure(t, n) {
130
- return a(this, null, function* () {
131
- const e = `${this.options.applicationId()}/${t.skillId}/${t.version}`, i = this.inflight.get(e);
132
- if (i)
133
- return i;
142
+ return o(this, null, function* () {
143
+ const s = `${this.options.applicationId()}/${t.skillId}/${t.version}`, e = this.inflight.get(s);
144
+ if (e)
145
+ return e;
134
146
  const r = this.installIfNeeded(t, n).finally(() => {
135
- this.inflight.get(e) === r && this.inflight.delete(e);
147
+ this.inflight.get(s) === r && this.inflight.delete(s);
136
148
  });
137
- return this.inflight.set(e, r), r;
149
+ return this.inflight.set(s, r), r;
138
150
  });
139
151
  }
140
152
  installIfNeeded(t, n) {
141
- return a(this, null, function* () {
142
- var o;
143
- const e = this.requireSandbox();
144
- if (e.ready && (yield this.alreadyInstalled(e, t, n)))
153
+ return o(this, null, function* () {
154
+ var a;
155
+ const s = this.requireSandbox();
156
+ if (s.ready && (yield this.alreadyInstalled(s, t, n)))
145
157
  return;
146
- const i = this.options.getToken();
147
- if (!m(i))
158
+ const e = this.options.getToken();
159
+ if (!x(e))
148
160
  throw new c(p.Forbidden, "技能下载令牌不可用。");
149
- const r = this.options.apiRoot().replace(/\/$/, ""), l = yield ((o = this.options.fetch) != null ? o : fetch)(`${r}/skill/v1/skills/${encodeURIComponent(t.skillId)}/versions/${t.version}/download`, {
161
+ 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`, {
150
162
  headers: {
151
- Authorization: `Bearer ${i}`
163
+ Authorization: `Bearer ${e}`
152
164
  },
153
165
  signal: n
154
166
  });
155
167
  if (!l.ok)
156
168
  throw new c(p.BadRequest, `技能下载失败(${l.status})。`);
157
169
  const d = new Uint8Array(yield l.arrayBuffer());
158
- if (d.byteLength > b)
170
+ if (d.byteLength > w)
159
171
  throw new c(p.BadRequest, "技能压缩包超过 20 MB。");
160
- yield this.waitReady(e, n), !(yield this.alreadyInstalled(e, t, n)) && (yield e.installSkill({
172
+ yield this.waitReady(s, n), !(yield this.alreadyInstalled(s, t, n)) && (yield s.installSkill({
161
173
  applicationId: this.options.applicationId(),
162
174
  skillId: t.skillId,
163
175
  version: t.version,
@@ -165,40 +177,40 @@ class R {
165
177
  }, d, n));
166
178
  });
167
179
  }
168
- alreadyInstalled(t, n, e) {
169
- return a(this, null, function* () {
170
- return S(yield t.skillStatus(this.options.applicationId(), e)).some((r) => r.skillId === n.skillId && r.version === n.version && r.name === n.name);
180
+ alreadyInstalled(t, n, s) {
181
+ return o(this, null, function* () {
182
+ return S(yield t.skillStatus(this.options.applicationId(), s)).some((r) => r.skillId === n.skillId && r.version === n.version && r.name === n.name);
171
183
  });
172
184
  }
173
185
  prune() {
174
- return a(this, null, function* () {
186
+ return o(this, null, function* () {
175
187
  const t = this.options.getSandbox();
176
188
  if (!(t != null && t.ready))
177
189
  return;
178
- const n = h({
190
+ const n = f({
179
191
  skills: this.options.getSkills()
180
- }).flatMap((i) => typeof i.skillId != "string" || typeof i.version != "number" || i.version < 1 ? [] : [{
181
- skillId: i.skillId,
182
- version: i.version
183
- }]), e = [...this.busy].map((i) => {
184
- const [r, l] = i.split("/");
192
+ }).flatMap((e) => typeof e.skillId != "string" || typeof e.version != "number" || e.version < 1 ? [] : [{
193
+ skillId: e.skillId,
194
+ version: e.version
195
+ }]), s = [...this.busy].map((e) => {
196
+ const [r, l] = e.split("/");
185
197
  return {
186
198
  skillId: r,
187
199
  version: Number(l)
188
200
  };
189
201
  });
190
- yield t.skillPrune(this.options.applicationId(), n, e);
202
+ yield t.skillPrune(this.options.applicationId(), n, s);
191
203
  });
192
204
  }
193
205
  waitReady(t, n) {
194
- return a(this, null, function* () {
195
- t.ready || (yield new Promise((e, i) => {
206
+ return o(this, null, function* () {
207
+ t.ready || (yield new Promise((s, e) => {
196
208
  const r = setInterval(() => {
197
209
  if (n != null && n.aborted) {
198
- clearInterval(r), i(new c(p.Cancelled, "已取消。"));
210
+ clearInterval(r), e(new c(p.Cancelled, "已取消。"));
199
211
  return;
200
212
  }
201
- t.ready && (clearInterval(r), e());
213
+ t.ready && (clearInterval(r), s());
202
214
  }, 50);
203
215
  }));
204
216
  });
@@ -206,5 +218,5 @@ class R {
206
218
  }
207
219
  export {
208
220
  R as PlatformSkillSync,
209
- h as listedSkills
221
+ f as listedSkills
210
222
  };
@@ -78,12 +78,12 @@ const e = (i) => ({
78
78
  run_file: {
79
79
  functionCode: "run_file",
80
80
  name: "执行文件",
81
- description: `执行工作区里已经存在的 .py、.sh 或 .js 脚本文件。生成 SVG、HTML、JSON 等产物时优先使用:先用 write_file 写脚本,脚本自行读取工作区文件并写出产物,再调用本工具。脚本运行时当前目录是工作区根目录,脚本里访问工作区文件要写相对路径,例如 data.json、notes/a.py。不要使用或新建 input、output、uploads、tmp。需要查看文件正文时用 read_file,不要把整份文件打印到标准输出。${n}`,
81
+ description: `执行工作区里已经存在的 .py、.sh、.bash、.js、.mjs 或 .cjs 脚本文件。生成 SVG、HTML、JSON 等产物时优先使用:先用 write_file 写脚本,脚本自行读取工作区文件并写出产物,再调用本工具。脚本运行时当前目录是工作区根目录,脚本里访问工作区文件要写相对路径,例如 data.json、notes/a.py。不要使用或新建 input、output、uploads、tmp。需要查看文件正文时用 read_file,不要把整份文件打印到标准输出。${n}`,
82
82
  parameters: {
83
83
  type: "object",
84
84
  required: ["path"],
85
85
  properties: {
86
- path: e("必填。要执行的 .py、.sh 或 .js 文件,工作区内绝对路径,例如 /scripts/gen.py。")
86
+ path: e("必填。要执行的 .py、.sh、.bash、.js、.mjs 或 .cjs 文件,工作区内绝对路径,例如 /scripts/gen.py。")
87
87
  }
88
88
  }
89
89
  },
@@ -145,7 +145,7 @@ const e = (i) => ({
145
145
  load_skill: {
146
146
  functionCode: "load_skill",
147
147
  name: "加载技能",
148
- description: "按技能名称加载平台技能的完整说明(SKILL.md)。技能不在工程目录里。",
148
+ description: "按技能名称加载平台技能的完整说明(SKILL.md),并附上技能包内全部文件的相对路径。技能不在工程目录里。之后用 read_skill_resource 按这些路径读取,或用 grep_skill 搜索。",
149
149
  parameters: {
150
150
  type: "object",
151
151
  required: ["skill_name"],
@@ -161,7 +161,7 @@ const e = (i) => ({
161
161
  read_skill_resource: {
162
162
  functionCode: "read_skill_resource",
163
163
  name: "读取技能资源",
164
- description: "读取与指定技能关联的资源文件,例如参考资料、模板或附加说明。",
164
+ description: "读取技能包内的文本。resource_name 是相对技能根目录的路径。传目录则列出该目录下的文件;传 . 列出整个技能包;以 grep: 开头则按基本正则搜索,例如 grep:portrait。",
165
165
  parameters: {
166
166
  type: "object",
167
167
  required: ["skill_name", "resource_name"],
@@ -179,6 +179,51 @@ const e = (i) => ({
179
179
  }
180
180
  }
181
181
  },
182
+ list_skill_files: {
183
+ functionCode: "list_skill_files",
184
+ name: "列出技能文件",
185
+ description: "列出平台技能包内的文件和目录。不传 path 时列出整个技能包。技能不在工程目录里。",
186
+ parameters: {
187
+ type: "object",
188
+ required: ["skill_name"],
189
+ properties: {
190
+ skill_name: {
191
+ type: "string",
192
+ minLength: 1,
193
+ description: "必填。技能名称。"
194
+ },
195
+ path: {
196
+ type: "string",
197
+ description: "可选。技能包内的相对目录,例如 skills 或 tools/dwgkit。省略则从技能根目录列出。"
198
+ }
199
+ }
200
+ }
201
+ },
202
+ grep_skill: {
203
+ functionCode: "grep_skill",
204
+ name: "搜索技能内容",
205
+ description: "在平台技能包内按 grep 基本正则搜索文本,返回路径、行号和匹配行。",
206
+ parameters: {
207
+ type: "object",
208
+ required: ["skill_name", "pattern"],
209
+ properties: {
210
+ skill_name: {
211
+ type: "string",
212
+ minLength: 1,
213
+ description: "必填。技能名称。"
214
+ },
215
+ pattern: {
216
+ type: "string",
217
+ minLength: 1,
218
+ description: "必填。grep 基本正则,例如 portrait 或 def .*。"
219
+ },
220
+ path: {
221
+ type: "string",
222
+ description: "可选。只搜索该相对目录或文件,例如 skills/cad-drawing-understanding。"
223
+ }
224
+ }
225
+ }
226
+ },
182
227
  run_skill_script: {
183
228
  functionCode: "run_skill_script",
184
229
  name: "运行技能脚本",