@cnbcool/cnb-api-generate 2.7.6 → 2.7.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.
|
@@ -84,9 +84,12 @@ function flattenToolOptions(toolInfo) {
|
|
|
84
84
|
? (0, clean_array_desc_1.cleanArrayDesc)((0, trim_summary_1.trimSummary)(prop.description || ''))
|
|
85
85
|
: (0, trim_summary_1.trimSummary)(prop.description || '');
|
|
86
86
|
const arrayHint = isArray ? ' (可多次传入)' : '';
|
|
87
|
+
const fileRefHint = !isArray && prop.type === 'string' && key === 'body'
|
|
88
|
+
? ' (支持 @file 引用)'
|
|
89
|
+
: '';
|
|
87
90
|
const desc = isRequired
|
|
88
|
-
? `[必填] ${rawDesc}${arrayHint}`
|
|
89
|
-
: `${rawDesc}${arrayHint}`;
|
|
91
|
+
? `[必填] ${rawDesc}${arrayHint}${fileRefHint}`
|
|
92
|
+
: `${rawDesc}${arrayHint}${fileRefHint}`;
|
|
90
93
|
const opt = {
|
|
91
94
|
optKey,
|
|
92
95
|
valuePlaceholder,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { helpData } from './help-data';
|
|
2
|
-
import { tryParseJSON } from './parsers';
|
|
2
|
+
import { tryParseJSON, tryReadFileRef } from './parsers';
|
|
3
3
|
import { buildNestedFieldMap } from '../utils/build-nested-field-map';
|
|
4
4
|
import type { NestedFieldMapping } from '../utils/build-nested-field-map';
|
|
5
5
|
import { restoreOriginalKeys } from '../utils/restore-original-keys';
|
|
@@ -182,7 +182,8 @@ export function formatParams(
|
|
|
182
182
|
} else if (bodyProps[key].type === 'string') {
|
|
183
183
|
// schema 定义为 string 类型时,保持原始字符串,不做 JSON 解析
|
|
184
184
|
// 避免纯数字字符串(如 "123")被转为 number
|
|
185
|
-
|
|
185
|
+
// 支持 @file 语法:从文件读取长文本内容(避免 shell 长参数截断)
|
|
186
|
+
formatted.data[key] = tryReadFileRef(value as string);
|
|
186
187
|
} else {
|
|
187
188
|
formatted.data[key] = tryParseJSON(value as string);
|
|
188
189
|
}
|
package/client/lib/parsers.ts
CHANGED
|
@@ -22,6 +22,10 @@ export function tryParseJSON(str: string | boolean | undefined): any {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* 尝试从文件引用或 stdin 读取内容(类似 curl 的 @file / @- 语法)
|
|
25
|
+
*
|
|
26
|
+
* 注意:一旦用户显式使用 @ 前缀,就表示其意图是读取文件/stdin。
|
|
27
|
+
* 此时若文件不存在或读取失败,应直接报错退出,避免把 "@/path/xxx"
|
|
28
|
+
* 字面量当作正文发送出去导致数据错误。
|
|
25
29
|
*/
|
|
26
30
|
export function tryReadFileRef(str: string | boolean | undefined) {
|
|
27
31
|
if (typeof str !== 'string' || !str.startsWith('@')) return str;
|
|
@@ -33,17 +37,23 @@ export function tryReadFileRef(str: string | boolean | undefined) {
|
|
|
33
37
|
try {
|
|
34
38
|
return fs.readFileSync(0, 'utf8').trim();
|
|
35
39
|
} catch (e) {
|
|
36
|
-
console.error(
|
|
37
|
-
|
|
40
|
+
console.error(`从 stdin 读取失败: ${e.message}`);
|
|
41
|
+
process.exit(1);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
// @/path/to/file 表示从文件读取
|
|
42
|
-
if (fs.existsSync(ref)) {
|
|
43
|
-
|
|
46
|
+
if (!fs.existsSync(ref)) {
|
|
47
|
+
console.error(`文件不存在: ${ref}`);
|
|
48
|
+
process.exit(1);
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
try {
|
|
52
|
+
return fs.readFileSync(ref, 'utf8').trim();
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error(`读取文件失败: ${ref} - ${e.message}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
/**
|