deepfish-ai 2.0.7 → 2.0.8

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.
@@ -48,7 +48,7 @@ const descriptions = [
48
48
  {
49
49
  type: 'function',
50
50
  function: {
51
- name: 'my_function',
51
+ name: 'myFunction',
52
52
  description: '工具的功能描述,说明何时使用、做什么、返回什么',
53
53
  parameters: {
54
54
  type: 'object',
@@ -74,7 +74,7 @@ module.exports = { functions, descriptions };
74
74
  ## 规范
75
75
 
76
76
  1. **返回值**:必须是 `{ success: true, data: any }` 或 `{ success: false, error: string }`
77
- 2. **命名**:函数名用 camelCase,工具名用 snake_case
77
+ 2. **命名**:函数名用 camelCase,描述的function中的name必须和函数名称一致
78
78
  3. **描述**:每个工具和参数都要有清晰的中文描述
79
79
  4. **错误处理**:函数内部必须 try-catch,出错返回 `{ success: false, error: '...' }`
80
80
  5. **一个文件一个工具**:每个 index.js 只导出一个工具函数
@@ -85,4 +85,5 @@ module.exports = { functions, descriptions };
85
85
  1. 理解用户要生成的工具功能
86
86
  2. 在当前工作目录下创建 `deepfish-tool-{功能名}/` 目录
87
87
  3. 编写 `index.js`,导出 `functions` 和 `descriptions`
88
- 4. 确保代码语法正确、可以直接使用 `require`
88
+ 4. 对于需要Agent参与的复杂任务,可以直接使用 `this.createSubAgent(prompt: string)` 创建子 Agent 执行任务,并将任务说明作为 `prompt` 传入
89
+ 5. 需要引入第三方模块时,需要将该tool创建成NodeJs项目,在tool中引入模块
package/dist/index.js CHANGED
@@ -24613,33 +24613,54 @@ async function safeTool(handler) {
24613
24613
  return serializeToolResult(errorResult(error51));
24614
24614
  }
24615
24615
  }
24616
+ function jsonSchemaToZod(node) {
24617
+ if (!node || typeof node !== "object") {
24618
+ return external_exports.any();
24619
+ }
24620
+ const { type, description: desc, properties, items, required: required2, enum: enumValues } = node;
24621
+ const withDesc = (schema) => desc ? schema.describe(desc) : schema;
24622
+ if (Array.isArray(enumValues) && enumValues.length > 0) {
24623
+ const allStrings = enumValues.every((v) => typeof v === "string");
24624
+ if (allStrings) {
24625
+ return withDesc(external_exports.enum(enumValues));
24626
+ }
24627
+ }
24628
+ switch (type) {
24629
+ case "string":
24630
+ return withDesc(external_exports.string());
24631
+ case "number":
24632
+ case "integer":
24633
+ return withDesc(external_exports.number());
24634
+ case "boolean":
24635
+ return withDesc(external_exports.boolean());
24636
+ case "array": {
24637
+ const itemSchema = items ? jsonSchemaToZod(items) : external_exports.any();
24638
+ return withDesc(external_exports.array(itemSchema));
24639
+ }
24640
+ case "object": {
24641
+ const shape = {};
24642
+ if (properties && typeof properties === "object") {
24643
+ const requiredFields = Array.isArray(required2) ? required2 : [];
24644
+ for (const [key, value] of Object.entries(properties)) {
24645
+ let childSchema = jsonSchemaToZod(value);
24646
+ if (!requiredFields.includes(key)) {
24647
+ childSchema = childSchema.optional();
24648
+ }
24649
+ shape[key] = childSchema;
24650
+ }
24651
+ }
24652
+ return withDesc(external_exports.object(shape).passthrough());
24653
+ }
24654
+ default:
24655
+ return withDesc(external_exports.any());
24656
+ }
24657
+ }
24616
24658
  function toLangChainTool(func, description) {
24617
24659
  const { name, description: desc, parameters } = description.function;
24618
24660
  const { properties } = parameters;
24619
24661
  const zodProperties = {};
24620
24662
  for (const [key, value] of Object.entries(properties)) {
24621
- const { type, description: desc2 } = value;
24622
- let zodType;
24623
- switch (type) {
24624
- case "string":
24625
- zodType = desc2 ? external_exports.string().describe(desc2) : external_exports.string();
24626
- break;
24627
- case "number":
24628
- zodType = desc2 ? external_exports.number().describe(desc2) : external_exports.number();
24629
- break;
24630
- case "boolean":
24631
- zodType = desc2 ? external_exports.boolean().describe(desc2) : external_exports.boolean();
24632
- break;
24633
- case "object":
24634
- zodType = desc2 ? external_exports.object({}).describe(desc2) : external_exports.object({});
24635
- break;
24636
- case "array":
24637
- zodType = desc2 ? external_exports.array(external_exports.string()).describe(desc2) : external_exports.array(external_exports.string());
24638
- break;
24639
- default:
24640
- zodType = external_exports.any();
24641
- }
24642
- zodProperties[key] = zodType;
24663
+ zodProperties[key] = jsonSchemaToZod(value);
24643
24664
  }
24644
24665
  const schema = external_exports.object(zodProperties);
24645
24666
  const wrappedFunc = async (args, runtime) => {
@@ -25769,8 +25790,8 @@ var SubAIAgent = class _SubAIAgent extends import_eventemitter_super.EventEmitte
25769
25790
  this.on("USE_TOOL_BEFORE" /* USE_TOOL_BEFORE */, (_toolId, funcName, _funcArgs) => {
25770
25791
  log(`[Tool Call] ${funcName}`, "#c2a654");
25771
25792
  });
25772
- this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent) => {
25773
- logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
25793
+ this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent = "") => {
25794
+ logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent.length > 50 ? _toolContent.slice(0, 50) + "..." : _toolContent}`);
25774
25795
  });
25775
25796
  this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
25776
25797
  logError(`Error in tool ${_funcName}: ${_error instanceof Error ? _error.message : String(_error)}`);
@@ -25965,7 +25986,7 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25965
25986
  log(`[Tool Call] ${funcName}`, "#c2a654");
25966
25987
  });
25967
25988
  this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent = "") => {
25968
- logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent.length > 50 ? _toolContent.slice(0, 50) + "..." : _toolContent}`);
25989
+ logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
25969
25990
  });
25970
25991
  this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
25971
25992
  logError(`Error in tool ${_funcName}: ${_error instanceof Error ? _error.message : String(_error)}`);
@@ -27134,7 +27155,7 @@ Commands:
27134
27155
  function registerHelpCommand(program) {
27135
27156
  program.helpInformation = helpInformation;
27136
27157
  program.command("help").description("Displaying help information").action(() => {
27137
- console.log(helpInformation());
27158
+ logInfo(helpInformation());
27138
27159
  });
27139
27160
  }
27140
27161
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepfish-ai",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "private": false,
5
5
  "description": "An efficient AI-driven command-line tool designed to bridge the gap between natural language and operating system commands, file operations, and more. It enables non-developers to quickly generate executable instructions through simple natural language descriptions, significantly improving terminal operation efficiency.",
6
6
  "repository": {