@saber2pr/ai-agent 0.0.31 → 0.0.32

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.
@@ -19,6 +19,7 @@ const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
19
19
  const builtin_1 = require("../tools/builtin");
20
20
  const convertToLangChainTool_1 = require("../utils/convertToLangChainTool");
21
21
  const jsonSchemaToZod_1 = require("../utils/jsonSchemaToZod");
22
+ const formatSchema_1 = require("../utils/formatSchema");
22
23
  exports.CONFIG_FILE = path_1.default.join(os_1.default.homedir(), ".saber2pr-agent.json");
23
24
  // ✅ 全局设置:修复 AbortSignal 监听器数量警告
24
25
  // LangChain 的 HTTP 客户端会创建多个 AbortSignal,需要增加默认限制
@@ -91,8 +92,7 @@ class McpGraphAgent {
91
92
  const schema = tool.schema;
92
93
  if (schema && schema.shape) {
93
94
  // 如果是 ZodObject,打印其内部 key
94
- const keys = Object.keys(schema.shape);
95
- console.log(` 参数结构: [ ${keys.join(", ")} ]`);
95
+ console.log(` 参数结构:\n${(0, formatSchema_1.formatSchema)(schema)}`);
96
96
  }
97
97
  else if (schema && schema._def) {
98
98
  // 兼容其他 Zod 类型
@@ -13,8 +13,8 @@ const lib_1 = require("./lib");
13
13
  // Schema definitions
14
14
  const ReadTextFileArgsSchema = zod_1.z.object({
15
15
  path: zod_1.z.string(),
16
- tail: zod_1.z.number().nullable().describe('If provided, returns only the last N lines of the file'),
17
- head: zod_1.z.number().nullable().describe('If provided, returns only the first N lines of the file')
16
+ tail: zod_1.z.number().optional().describe('If provided, returns only the last N lines of the file'),
17
+ head: zod_1.z.number().optional().describe('If provided, returns only the first N lines of the file')
18
18
  });
19
19
  const ReadMultipleFilesArgsSchema = zod_1.z.object({
20
20
  paths: zod_1.z
@@ -33,7 +33,7 @@ const EditOperation = zod_1.z.object({
33
33
  const EditFileArgsSchema = zod_1.z.object({
34
34
  path: zod_1.z.string(),
35
35
  edits: zod_1.z.array(EditOperation),
36
- dryRun: zod_1.z.boolean().nullable().default(false).describe('Preview changes using git-style diff format')
36
+ dryRun: zod_1.z.boolean().optional().default(false).describe('Preview changes using git-style diff format')
37
37
  });
38
38
  const CreateDirectoryArgsSchema = zod_1.z.object({
39
39
  path: zod_1.z.string(),
@@ -43,11 +43,11 @@ const ListDirectoryArgsSchema = zod_1.z.object({
43
43
  });
44
44
  const ListDirectoryWithSizesArgsSchema = zod_1.z.object({
45
45
  path: zod_1.z.string(),
46
- sortBy: zod_1.z.enum(['name', 'size']).nullable().default('name').describe('Sort entries by name or size'),
46
+ sortBy: zod_1.z.enum(['name', 'size']).optional().default('name').describe('Sort entries by name or size'),
47
47
  });
48
48
  const DirectoryTreeArgsSchema = zod_1.z.object({
49
49
  path: zod_1.z.string(),
50
- excludePatterns: zod_1.z.array(zod_1.z.string()).nullable().default([])
50
+ excludePatterns: zod_1.z.array(zod_1.z.string()).optional().default([])
51
51
  });
52
52
  const MoveFileArgsSchema = zod_1.z.object({
53
53
  source: zod_1.z.string(),
@@ -56,7 +56,7 @@ const MoveFileArgsSchema = zod_1.z.object({
56
56
  const SearchFilesArgsSchema = zod_1.z.object({
57
57
  path: zod_1.z.string(),
58
58
  pattern: zod_1.z.string(),
59
- excludePatterns: zod_1.z.array(zod_1.z.string()).nullable().default([])
59
+ excludePatterns: zod_1.z.array(zod_1.z.string()).optional().default([])
60
60
  });
61
61
  const GetFileInfoArgsSchema = zod_1.z.object({
62
62
  path: zod_1.z.string(),
@@ -0,0 +1,2 @@
1
+ import { z } from 'zod';
2
+ export declare function formatSchema(schema: z.ZodObject<any>): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatSchema = formatSchema;
7
+ const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
8
+ function formatSchema(schema) {
9
+ const res = (0, zod_to_json_schema_1.default)(schema);
10
+ if (typeof res.properties === 'object') {
11
+ const requiredKeys = res.required || [];
12
+ const lines = [];
13
+ for (const key in res.properties) {
14
+ lines.push(` - ${key}: ${res.properties[key].type}${requiredKeys.includes(key) ? " (required)" : ""}`);
15
+ }
16
+ if (lines.length > 0) {
17
+ return lines.join("\n");
18
+ }
19
+ return "No parameters";
20
+ }
21
+ const keys = Object.keys(schema.shape);
22
+ return keys.join(", ");
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saber2pr/ai-agent",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "description": "AI Assistant CLI.",
5
5
  "author": "saber2pr",
6
6
  "license": "ISC",