@qilin-agent/tools 3.1.5 → 3.1.6

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.
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Under `mode: 'ptc'` the native tool schemas are omitted from the request, so this generated
9
9
  * SDK is the model's ONLY source for each tool's argument names, required fields, types,
10
- * descriptions, and canonical output shapes. Object-shaped arguments and outputs therefore render as one
10
+ * descriptions, and canonical output types. Object-shaped arguments and outputs render as one
11
11
  * named `TypedDict` per tool (and per nested object), not an opaque `dict[str, Any]`, so the
12
12
  * shape survives into the program under the mode that has nothing else to carry it.
13
13
  * @module @qilin-agent/tools/src/py-types
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Under `mode: 'ptc'` the native tool schemas are omitted from the request, so this generated
9
9
  * SDK is the model's ONLY source for each tool's argument names, required fields, types,
10
- * descriptions, and canonical output shapes. Object-shaped arguments and outputs therefore render as one
10
+ * descriptions, and canonical output types. Object-shaped arguments and outputs render as one
11
11
  * named `TypedDict` per tool (and per nested object), not an opaque `dict[str, Any]`, so the
12
12
  * shape survives into the program under the mode that has nothing else to carry it.
13
13
  * @module @qilin-agent/tools/src/py-types
@@ -700,12 +700,12 @@ export function jsonSchemaToPy(schema) {
700
700
  /** The fixed model-facing usage contract rendered above the declarations. */
701
701
  const SDK_INSTRUCTIONS = `## Writing code for run_code
702
702
 
703
- \`run_code\` takes two required arguments: \`description\`, a short summary of what the program does, and \`code\` — the body of an async Python function (top-level \`await\` and \`return\` both work). At run time exactly two of the names declared below are bound: \`tools\` and \`ToolCallError\`. Everything else is a STATIC STUB describing argument and return types — in particular the \`TypedDict\` classes do NOT exist at run time, so build arguments as plain \`dict\`/\`list\` JSON values: \`await tools.name({"field": 1})\`, never \`FooArgs(field=1)\`, which raises \`NameError\`. Inside the program:
703
+ \`run_code\` takes two required arguments: \`description\`, a short summary of what the program does, and \`code\`, the program to execute. At run time exactly two of the names declared below are bound: \`tools\` and \`ToolCallError\`. Everything else is a STATIC STUB describing argument and return types — in particular the \`TypedDict\` classes do NOT exist at run time, so build arguments as plain \`dict\`/\`list\` JSON values: \`await tools.name({"field": 1})\`, never \`FooArgs(field=1)\`, which raises \`NameError\`. Inside the program:
704
704
 
705
705
  - Call tools as \`await tools.name(args)\` — subscript access for exotic, reserved, or underscore-leading names: \`await tools["my-tool"](args)\`. Every call resolves to the tool's typed canonical JSON value (each method's return type below). Tool arguments must be lossless JSON.
706
706
  - A FAILED tool call raises \`ToolCallError\`, whose \`toolName\` identifies the failed tool and whose message is human-readable — wrap in \`try/except\` to handle and continue.
707
707
  - Independent read-only calls MAY overlap under \`asyncio.gather\` (safe calls run concurrently; mutating calls run alone, in submission order). Sequence dependent work with \`await\`.
708
- - Emit the run's answer with \`print(...)\` and/or a top-level \`return <value>\`; the returned value must be lossless JSON. Only what you print and return is program output. A successful tool result containing an image is attached after the run so you can inspect it on the next step; every other intermediate result stays out of the conversation, so extract just what you need.
708
+ - Only values emitted as program output enter the conversation. A successful tool result containing an image is attached after the run so you can inspect it on the next step; every other intermediate result stays out of the conversation, so extract just what you need.
709
709
 
710
710
  The available tools:`;
711
711
  /**
@@ -31,7 +31,8 @@ export declare function jsonSchemaToTs(schema: unknown, indent?: number): string
31
31
  * by name, so the input never carries a duplicate.
32
32
  * @param schemas - the tool schemas to declare (the caller excludes
33
33
  * `run_code` itself).
34
+ * @param programFormat - Runtime syntax; function bodies support returning a result, REPLs print it.
34
35
  * @returns the complete section text.
35
36
  */
36
- export declare function renderToolsSdk(schemas: ToolSdkSchema[]): string;
37
+ export declare function renderToolsSdk(schemas: ToolSdkSchema[], programFormat?: 'function-body' | 'repl'): string;
37
38
  //# sourceMappingURL=ts-types.d.ts.map
@@ -218,18 +218,29 @@ export function jsonSchemaToTs(schema, indent = 0) {
218
218
  return 'unknown';
219
219
  }
220
220
  }
221
- /** The fixed model-facing usage contract rendered above the declarations (see the PTC mode Agent Note's "What the model sees"). */
222
- const SDK_INSTRUCTIONS = `## Writing code for run_code
221
+ /** Render the argument and call instructions for the selected execution syntax. */
222
+ function renderSdkInstructions(programFormat) {
223
+ const programDescription = programFormat === 'function-body'
224
+ ? 'the body of an async TypeScript function (erasable syntax only — no `enum` or namespaces; type annotations are advisory, the code runs type-stripped)'
225
+ : 'the program to execute';
226
+ return `## Writing code for run_code
223
227
 
224
- \`run_code\` takes two required arguments: \`description\`, a short summary of what the program does, and \`code\` — the body of an async TypeScript function (erasable syntax only — no \`enum\` or namespaces; type annotations are advisory, the code runs type-stripped). The declarations below are SDK bindings for this program. A declaration does not make its name a directly callable tool; only names supplied as separate tool schemas may be called directly.`;
225
- const SDK_PROGRAM_INSTRUCTIONS = `Inside the program:
228
+ \`run_code\` takes two required arguments: \`description\`, a short summary of what the program does, and \`code\`, ${programDescription}. The declarations below are SDK bindings for this program. A declaration does not make its name a directly callable tool; only names supplied as separate tool schemas may be called directly.`;
229
+ }
230
+ /** Render tool execution and output instructions for the selected execution syntax. */
231
+ function renderSdkProgramInstructions(programFormat) {
232
+ const outputInstruction = programFormat === 'function-body'
233
+ ? 'Emit results with `return` and/or `console.log(...)`. Only what you print or return is program output.'
234
+ : 'Only values emitted as program output enter the conversation.';
235
+ return `Inside the program:
226
236
 
227
237
  - Call tools as \`await tools.name(args)\` — quoted access for exotic names: \`tools["my-tool"](args)\`. Every call resolves to the tool's typed canonical JSON value. Tool arguments must be lossless JSON.
228
238
  - A FAILED tool call rejects with \`ToolCallError\`, whose \`toolName\` identifies the failed tool and whose \`message\` is human-readable — \`try/catch\` it to handle and continue.
229
239
  - Independent read-only calls MAY overlap under \`Promise.all\` (safe calls run concurrently; mutating calls run alone, in submission order). Sequence dependent work with \`await\`.
230
- - Emit results with \`return\` and/or \`console.log(...)\`. Only what you print or return is program output. A successful tool result containing an image is attached after the run so you can inspect it on the next step; every other intermediate result stays out of the conversation, so extract just what you need.
240
+ - ${outputInstruction} A successful tool result containing an image is attached after the run so you can inspect it on the next step; every other intermediate result stays out of the conversation, so extract just what you need.
231
241
 
232
242
  Program-only SDK bindings:`;
243
+ }
233
244
  /** Whether one string schema accepts the literal used by the bash example. */
234
245
  function acceptsExampleString(schema, value) {
235
246
  return schema?.type === 'string'
@@ -237,7 +248,7 @@ function acceptsExampleString(schema, value) {
237
248
  && (schema.enum === undefined || schema.enum.includes(value));
238
249
  }
239
250
  /** Render the bash example only when its literal arguments satisfy the current parameter schema. */
240
- function renderBashExample(schemas) {
251
+ function renderBashExample(schemas, programFormat) {
241
252
  const bash = schemas.find(schema => schema.name === 'bash');
242
253
  if (bash === undefined)
243
254
  return '';
@@ -253,7 +264,10 @@ function renderBashExample(schemas) {
253
264
  if (needsDescription && !acceptsExampleString(parameters.properties?.description, 'Show current directory'))
254
265
  return '';
255
266
  const description = needsDescription ? "description: 'Show current directory', " : '';
256
- return ` When no separate \`bash\` schema is supplied, invoke a declared \`bash\` binding inside \`run_code\`:\n\n\`run_code({ description: "Show current directory", code: "return await tools.bash({ ${description}command: 'pwd' })" })\``;
267
+ const program = programFormat === 'function-body'
268
+ ? `return await tools.bash({ ${description}command: 'pwd' })`
269
+ : `console.log(await tools.bash({ ${description}command: 'pwd' }))`;
270
+ return ` When no separate \`bash\` schema is supplied, invoke a declared \`bash\` binding inside \`run_code\`:\n\n\`run_code({ description: "Show current directory", code: "${program}" })\``;
257
271
  }
258
272
  /**
259
273
  * Render the full `tools:sdk` prompt section: the fixed usage instructions
@@ -265,9 +279,10 @@ function renderBashExample(schemas) {
265
279
  * by name, so the input never carries a duplicate.
266
280
  * @param schemas - the tool schemas to declare (the caller excludes
267
281
  * `run_code` itself).
282
+ * @param programFormat - Runtime syntax; function bodies support returning a result, REPLs print it.
268
283
  * @returns the complete section text.
269
284
  */
270
- export function renderToolsSdk(schemas) {
285
+ export function renderToolsSdk(schemas, programFormat = 'function-body') {
271
286
  const sorted = [...schemas].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
272
287
  const argsMembers = [];
273
288
  const outputMembers = [];
@@ -286,6 +301,8 @@ export function renderToolsSdk(schemas) {
286
301
  ['declare const tools: {', ' [K in ToolName]: (args: ToolArgsMap[K]) => Promise<ToolOutputMap[K]>;', '}'].join('\n'),
287
302
  ].join('\n\n');
288
303
  const jsonValue = 'type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue }';
289
- return `${SDK_INSTRUCTIONS}${renderBashExample(sorted)}\n\n${SDK_PROGRAM_INSTRUCTIONS}\n\n\`\`\`ts\n${jsonValue}\n\n${declaration}\n\`\`\``;
304
+ const instructions = renderSdkInstructions(programFormat);
305
+ const programInstructions = renderSdkProgramInstructions(programFormat);
306
+ return `${instructions}${renderBashExample(sorted, programFormat)}\n\n${programInstructions}\n\n\`\`\`ts\n${jsonValue}\n\n${declaration}\n\`\`\``;
290
307
  }
291
308
  //# sourceMappingURL=ts-types.js.map
package/locale/en.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "meta": {
3
+ "title": "tools"
4
+ }
5
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "工具注册与执行",
4
+ "description": "管理可用工具及其调用执行流程。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qilin-agent/tools",
3
3
  "description": "Tool registry and execution pipeline for the QiLin",
4
- "version": "3.1.5",
4
+ "version": "3.1.6",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -30,44 +30,46 @@
30
30
  "default": "./lib/types/presentation.js"
31
31
  },
32
32
  "./src/*": "./src/*",
33
- "./package.json": "./package.json"
33
+ "./package.json": "./package.json",
34
+ "./locale/*.json": "./locale/*.json"
34
35
  },
35
36
  "files": [
37
+ "locale/*.json",
36
38
  "lib/index.js",
37
39
  "lib/types/**/*.js",
38
40
  "lib/types/**/*.d.ts"
39
41
  ],
40
42
  "license": "MIT",
41
43
  "peerDependencies": {
42
- "@qilin-agent/kylin": "~4.0.3",
43
- "@qilin-agent/ptc-runtime": "3.1.5",
44
- "@qilin-agent/agent": "3.1.5",
45
- "@qilin-agent/llm": "3.1.5",
46
- "@qilin-agent/system-prompt": "3.1.5",
47
- "@qilin-agent/session": "3.1.5",
48
- "@qilin-agent/user-approval": "3.1.5",
49
- "@qilin-agent/sandbox": "3.1.5",
50
- "@qilin-agent/working-directory": "3.1.5",
51
- "@qilin-agent/scope": "3.1.5",
52
- "@qilin-agent/sandbox-policy": "3.1.5"
44
+ "@qilin-agent/kylin": "~4.0.5",
45
+ "@qilin-agent/agent": "3.1.6",
46
+ "@qilin-agent/ptc-runtime": "3.1.6",
47
+ "@qilin-agent/llm": "3.1.6",
48
+ "@qilin-agent/scope": "3.1.6",
49
+ "@qilin-agent/system-prompt": "3.1.6",
50
+ "@qilin-agent/session": "3.1.6",
51
+ "@qilin-agent/user-approval": "3.1.6",
52
+ "@qilin-agent/sandbox": "3.1.6",
53
+ "@qilin-agent/working-directory": "3.1.6",
54
+ "@qilin-agent/sandbox-policy": "3.1.6"
53
55
  },
54
56
  "dependencies": {
55
- "@qilin-agent/brand": "3.1.5",
56
- "@qilin-agent/util-values": "3.1.5",
57
- "@qilin-agent/schemastery": "~3.18.3"
57
+ "@qilin-agent/util-values": "3.1.6",
58
+ "@qilin-agent/schemastery": "~3.18.5",
59
+ "@qilin-agent/brand": "3.1.6"
58
60
  },
59
61
  "devDependencies": {
60
- "@qilin-agent/kylin": "~4.0.3",
61
- "@qilin-agent/agent": "3.1.5",
62
- "@qilin-agent/ptc-runtime": "3.1.5",
63
- "@qilin-agent/scope": "3.1.5",
64
- "@qilin-agent/llm": "3.1.5",
65
- "@qilin-agent/session-projection": "3.1.5",
66
- "@qilin-agent/system-prompt": "3.1.5",
67
- "@qilin-agent/sandbox": "3.1.5",
68
- "@qilin-agent/user-approval": "3.1.5",
69
- "@qilin-agent/working-directory": "3.1.5",
70
- "@qilin-agent/sandbox-policy": "3.1.5",
71
- "@qilin-agent/session": "3.1.5"
62
+ "@qilin-agent/kylin": "~4.0.5",
63
+ "@qilin-agent/agent": "3.1.6",
64
+ "@qilin-agent/ptc-runtime": "3.1.6",
65
+ "@qilin-agent/llm": "3.1.6",
66
+ "@qilin-agent/scope": "3.1.6",
67
+ "@qilin-agent/user-approval": "3.1.6",
68
+ "@qilin-agent/session": "3.1.6",
69
+ "@qilin-agent/system-prompt": "3.1.6",
70
+ "@qilin-agent/sandbox": "3.1.6",
71
+ "@qilin-agent/sandbox-policy": "3.1.6",
72
+ "@qilin-agent/working-directory": "3.1.6",
73
+ "@qilin-agent/session-projection": "3.1.6"
72
74
  }
73
75
  }