@cnbcool/cnb-api-generate 2.11.5 → 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
  }
@@ -123,8 +123,6 @@ interface UploadErrorData {
123
123
  /** Issue 上传成功时的 data(asset_group_id 仅在创建 issue 流程下返回) */
124
124
  interface IssueUploadData {
125
125
  asset_link?: string;
126
- /** asset_link 的别名,语义更直观,方便 AI 理解这是一个可直接插入评论的 markdown 链接 */
127
- markdown?: string;
128
126
  name: string;
129
127
  path?: string;
130
128
  size: number;
@@ -133,9 +131,6 @@ interface IssueUploadData {
133
131
 
134
132
  /** Pull 上传成功时的 data */
135
133
  interface PullUploadData {
136
- /** asset_link 的别名,语义更直观,方便 AI 理解这是一个可直接插入评论的 markdown 链接 */
137
- asset_link?: string;
138
- markdown?: string;
139
134
  name: string;
140
135
  path?: string;
141
136
  size: number;
@@ -286,13 +281,10 @@ export async function handleIssueCreateUpload(
286
281
  if (putErr) return putErr;
287
282
 
288
283
  // 3. 返回结果(asset_link 拼入创建 issue 的 body,asset_group_id 备用)
289
- // markdown 作为 asset_link 的别名,方便 AI 理解使用
290
- const assetLink = firstEntry?.asset_link;
291
284
  return {
292
285
  status: 200,
293
286
  data: {
294
- asset_link: assetLink,
295
- markdown: assetLink,
287
+ asset_link: firstEntry?.asset_link,
296
288
  name: firstEntry?.name || fileName,
297
289
  path: firstEntry?.path,
298
290
  size: fileSize,
@@ -348,10 +340,8 @@ export async function handleUpload(
348
340
  const data = apiResponse?.data as IssueAssetUploadURLResponseData | undefined;
349
341
  uploadUrl = data?.upload_url;
350
342
  if (!uploadUrl) return apiResponse as unknown as UploadResult;
351
- const assetLink = data?.asset_link;
352
343
  successData = {
353
- asset_link: assetLink,
354
- markdown: assetLink,
344
+ asset_link: data?.asset_link,
355
345
  name: data?.name || fileName,
356
346
  path: data?.path,
357
347
  size: fileSize,
@@ -363,19 +353,9 @@ export async function handleUpload(
363
353
  const data = apiResponse?.data as PullUploadResponseData | undefined;
364
354
  uploadUrl = data?.upload_url;
365
355
  if (!uploadUrl) return apiResponse as unknown as UploadResult;
366
- // markdown 作为 asset_link 的别名,方便 AI 理解使用
367
- // Pull 上传不返回 asset_link,由 assets.path + name 构造 markdown 链接
368
- const assetPath = data?.assets?.path;
369
- const assetName = data?.assets?.name || fileName;
370
- const isImage = shortcut.kind === 'image';
371
- const assetLink = assetPath
372
- ? `${isImage ? '!' : ''}[${assetName}](${assetPath})`
373
- : undefined;
374
356
  successData = {
375
- asset_link: assetLink,
376
- markdown: assetLink,
377
- name: assetName,
378
- path: assetPath,
357
+ name: data?.assets?.name || fileName,
358
+ path: data?.assets?.path,
379
359
  size: fileSize,
380
360
  token: data?.token,
381
361
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-api-generate",
3
- "version": "2.11.5",
3
+ "version": "2.11.7",
4
4
  "main": "./built/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -27,8 +27,8 @@
27
27
  { "shortName": "check-status", "realTool": "list-pull-commit-statuses", "description": "查看 CI 状态" },
28
28
  { "shortName": "list-reviews", "realTool": "list-pull-reviews", "description": "查看评审列表" },
29
29
  { "shortName": "list-assignees", "realTool": "list-pull-assignees", "description": "查看处理人" },
30
- { "shortName": "upload-file", "realTool": "upload-files", "description": "上传文件", "repoOnly": true, "upload": true, "kind": "file", "dataTip": "--file 文件路径" },
31
- { "shortName": "upload-image", "realTool": "upload-imgs", "description": "上传图片", "repoOnly": true, "upload": true, "kind": "image", "dataTip": "--file 图片路径" },
30
+ { "shortName": "upload-file", "realTool": "upload-files", "description": "上传文件", "repoOnly": true, "upload": true, "dataTip": "--file 文件路径" },
31
+ { "shortName": "upload-image", "realTool": "upload-imgs", "description": "上传图片", "repoOnly": true, "upload": true, "dataTip": "--file 图片路径" },
32
32
  { "shortName": "get-ci-logs", "realTool": "__get-ci-logs__", "description": "获取 CI 失败日志", "repoOnly": true, "custom": true, "dataTip": "--sn 构建号(可选)" },
33
33
  { "shortName": "get-ci-timing", "realTool": "__get-ci-timing__", "description": "分析 CI 耗时瓶颈", "repoOnly": true, "custom": true, "dataTip": "--sn 构建号(可选)" },
34
34
  { "shortName": "get-imgs", "realTool": "get-pr-imgs", "description": "获取 PR 图片", "repoOnly": true, "dataTip": "--img-path 图片路径" },