@njuptlzf/agent-chat-server 0.5.0 → 0.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@njuptlzf/agent-chat-server",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "agentChat platform kernel: sessions, authz, billing, audit, model/MCP/persona config planes, and the product-directory loader.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,7 @@ import { createRequire } from "node:module";
20
20
  import { spawnSync } from "node:child_process";
21
21
  import process from "node:process";
22
22
 
23
- const CLI_VERSION = "0.5.0";
23
+ const CLI_VERSION = "0.5.1";
24
24
  const MIN_SERVER = "0.2.0";
25
25
  const PKG = {
26
26
  protocol: "@njuptlzf/agent-chat-protocol",
@@ -712,6 +712,45 @@ function checkTestScripts(add, dir, opts) {
712
712
  return runs;
713
713
  }
714
714
 
715
+ /**
716
+ * 工具 schema 的 TypeBox 越界构造子(启发式,只给 WARN)。
717
+ *
718
+ * pi 按 JSON Schema 校验工具参数(`@earendil-works/pi-schema`):`Refine` 静默不跑、
719
+ * `BigInt`/`Undefined`/`Void` 拒绝**每一个**参数(工具永远调不通)、`Codec` 不解码、
720
+ * `Format.Set` 不检查。四者都不报编译错,只在运行期让约束或工具本身失效——没有别的
721
+ * 门禁能抓到,所以在这里给一条建议。只 WARN:同一构造子也可能用在非工具 schema 上。
722
+ */
723
+ const TOOL_SCHEMA_TRAPS = [
724
+ [/Type\.Refine\s*\(/, "Type.Refine() 不跑,约束需挪进 execute() 自己校验"],
725
+ [/Type\.(?:BigInt|Undefined|Void)\s*\(/, "BigInt()/Undefined()/Void() 会拒绝每一个参数(工具永远调不通)"],
726
+ [/Type\.Codec\s*\(/, "Type.Codec() 不解码,execute() 收到的是 JSON 值"],
727
+ [/Format\.Set\s*\(/, "Format.Set() 注册的格式不检查"],
728
+ ];
729
+
730
+ function checkToolSchemas(add, dir) {
731
+ const hits = [];
732
+ for (const f of walkFiles(dir).filter((f) => /\.(ts|tsx)$/.test(f))) {
733
+ if (/[\\/](test|tests|e2e)[\\/]/.test(f)) continue; // 测试里造反例不算产品用法
734
+ const text = stripComments(readText(path.dirname(f), path.basename(f)));
735
+ if (!text) continue;
736
+ const rel = path.relative(dir, f).replace(/\\/g, "/");
737
+ for (const [re, why] of TOOL_SCHEMA_TRAPS) {
738
+ if (re.test(text)) hits.push(`${rel}:${why}`);
739
+ }
740
+ }
741
+ if (hits.length === 0) {
742
+ add("OK", "tool-schema", "未检出 pi 不支持的 TypeBox 构造子");
743
+ return;
744
+ }
745
+ add(
746
+ "WARN",
747
+ "tool-schema",
748
+ `检出 ${hits.length} 处 pi 工具参数校验不生效的 TypeBox 构造子`,
749
+ `${hits.join(";")}。工具 schema 改用 JSON Schema 子集(Object/String/Number/Boolean/Array/Optional/Union/Literal),` +
750
+ "表达不了的约束挪进 execute() 自己校验;若不是工具 schema 可忽略本条",
751
+ );
752
+ }
753
+
715
754
  function checkTooling(add, dir) {
716
755
  const wf = path.join(dir, ".github", "workflows");
717
756
  const wfFiles = fs.existsSync(wf) ? fs.readdirSync(wf).filter((f) => /\.ya?ml$/.test(f)) : [];
@@ -765,6 +804,7 @@ function check(opts, dir) {
765
804
  const caps = checkCapabilities(add, dir);
766
805
  const runs = checkTestScripts(add, dir, opts);
767
806
  checkTooling(add, dir);
807
+ checkToolSchemas(add, dir);
768
808
  if (opts.deep) checkDeep(add, dir);
769
809
 
770
810
  const failures = results.filter((r) => r.level === "FAIL");