@cnbcool/cnb-api-generate 2.11.6 → 2.11.7

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.
@@ -42,21 +42,31 @@ export function buildToolParams(formattedParams: {
42
42
 
43
43
  // 2) 按形态构造第 1 个参数
44
44
  let firstParam: Record<string, any> | string | null = null;
45
+ let hasFirstParam = false;
45
46
  if (isObjectShape) {
46
- // 对象形态:合并 path 与运行期 query;任一为空都允许,toolFunction 内部解构是可选的
47
- if (path || queryHasValue) {
48
- firstParam = { ...(path ?? {}), ...(query ?? {}) };
49
- }
47
+ // 对象形态:合并 path 与运行期 query
48
+ // 即便 path query 都为空,也必须传入 {}——生成代码的第 1 形参是无默认值的解构
49
+ // (如 `async function _default({ ...query }, ...)`),不给会触发
50
+ // `Cannot destructure 'undefined' as it is undefined`。
51
+ // 典型场景:`workspace/list-workspaces`——无 path、query 全部可选,用户不传任何参数。
52
+ firstParam = { ...(path ?? {}), ...(query ?? {}) };
53
+ hasFirstParam = true;
50
54
  } else if (path) {
51
55
  // 标量形态:仅当 path 恰好 1 个字段时拆出值;其它情形(含异常的多字段)不构造,
52
56
  // 避免悄悄把不该传的字段塞给 toolFunction
53
57
  const keys = Object.keys(path);
54
- if (keys.length === 1) firstParam = path[keys[0]];
58
+ if (keys.length === 1) {
59
+ firstParam = path[keys[0]];
60
+ hasFirstParam = true;
61
+ }
55
62
  }
56
63
 
57
- // 3) 组装最终位置参数列表(与历史行为一致:firstParam 真值才 push;data 真值才 push)
64
+ // 3) 组装最终位置参数列表
65
+ // - 对象形态:始终占位(即便为空对象),保证解构安全
66
+ // - 标量形态:仅当拿到实际值时 push
67
+ // - data:真值才 push(与历史行为一致)
58
68
  const toolsParam: any[] = [];
59
- if (firstParam) toolsParam.push(firstParam);
69
+ if (hasFirstParam) toolsParam.push(firstParam);
60
70
  if (data) toolsParam.push(data);
61
71
  return toolsParam;
62
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-api-generate",
3
- "version": "2.11.6",
3
+ "version": "2.11.7",
4
4
  "main": "./built/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.ts",