@saber2pr/ai-agent 0.0.12 → 0.0.14

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.
@@ -11,6 +11,7 @@ export default class McpChainAgent {
11
11
  private apiModel?;
12
12
  private targetDir;
13
13
  private verbose;
14
+ private runningTokenCounter;
14
15
  constructor(options?: AgentOptions);
15
16
  /**
16
17
  * 工具处理器包装逻辑:增加日志打印和 Token 监控
@@ -52,6 +52,7 @@ class McpChainAgent {
52
52
  this.messages = [];
53
53
  this.encoder = (0, js_tiktoken_1.getEncoding)("cl100k_base");
54
54
  this.extraTools = [];
55
+ this.runningTokenCounter = 0; // 新增:用于追踪当前 Task 的动态消耗
55
56
  this.extraTools = (options === null || options === void 0 ? void 0 : options.tools) || [];
56
57
  this.maxTokens = (options === null || options === void 0 ? void 0 : options.maxTokens) || 100000;
57
58
  this.apiConfig = options === null || options === void 0 ? void 0 : options.apiConfig;
@@ -89,8 +90,15 @@ class McpChainAgent {
89
90
  const result = await handler(args);
90
91
  const content = typeof result === "string" ? result : JSON.stringify(result);
91
92
  // 3. 统计 Token 消耗
92
- const tokens = this.encoder.encode(content).length;
93
- console.log(` [输出长度]: ${tokens} tokens`);
93
+ const outputTokens = this.encoder.encode(content).length;
94
+ console.log(` [输出长度]: ${outputTokens} tokens`);
95
+ // 2. 更新动态计数器:
96
+ // 这里的逻辑是:当前基础 Context + 本次工具调用的输出
97
+ // 随着迭代增加,这个值会一直累加,直到任务结束存入 messages
98
+ const baseTokens = this.calculateTokens();
99
+ this.runningTokenCounter = baseTokens + outputTokens;
100
+ // 3. 打印正确且递增的状态
101
+ console.log(` 📊 状态: Context ${this.runningTokenCounter} / Limit ${this.maxTokens} tokens`);
94
102
  return content;
95
103
  };
96
104
  }
@@ -16,10 +16,6 @@ export default class McpAgent {
16
16
  */
17
17
  private calculateTokens;
18
18
  private initTools;
19
- /**
20
- * 核心功能:内置代码分析工具(基于 engine/targetDir,可被外部通过 createDefaultBuiltinTools 替代)
21
- */
22
- private registerBuiltinTools;
23
19
  private ensureApiConfig;
24
20
  private loadMcpConfigs;
25
21
  init(): Promise<void>;
package/lib/core/agent.js CHANGED
@@ -145,14 +145,6 @@ class McpAgent {
145
145
  this.allTools.push(...allTools);
146
146
  }
147
147
  }
148
- /**
149
- * 核心功能:内置代码分析工具(基于 engine/targetDir,可被外部通过 createDefaultBuiltinTools 替代)
150
- */
151
- registerBuiltinTools(options) {
152
- this.allTools.push(...(0, builtin_1.createDefaultBuiltinTools)({
153
- options,
154
- }));
155
- }
156
148
  // --- 初始化与环境准备 (API Config & MCP Servers) ---
157
149
  async ensureApiConfig() {
158
150
  if (this.apiConfig)
@@ -24,8 +24,8 @@ function createTool(options) {
24
24
  if (((_a = options.validateParams) === null || _a === void 0 ? void 0 : _a.length) > 0) {
25
25
  for (const arg in args) {
26
26
  if (options.validateParams.includes(arg)) {
27
- if (typeof args[arg] !== "string" || args[arg].trim() === "") {
28
- return `Error: 参数 '${arg}' 无效。收到的是: ${JSON.stringify(args[arg])}`;
27
+ if (typeof args[arg] === 'undefined') {
28
+ return `Error: 参数 '${arg}' 缺失`;
29
29
  }
30
30
  }
31
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saber2pr/ai-agent",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "AI Assistant CLI.",
5
5
  "author": "saber2pr",
6
6
  "license": "ISC",