@nickyzj2023/ai 1.4.0 → 1.4.1

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.
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # ai
2
2
 
3
- 男生自用MyPi Coding Agent
3
+ 男生自用Coding Agent,参考了[nanopi教学](https://pi-from-scratch.vercel.app/)
4
+
5
+ 不断学习+开发中,当前项目仍属于比nano还简陋的“bare-pi”,but one day...
6
+
7
+ ![demo](demo.gif)
4
8
 
5
9
  ## 安装
6
10
 
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as get_time_default, c as runAgent, i as get_weather_default, o as defineModel, r as loadMCPTools } from "./src-DEDOOez9.mjs";
1
+ import { a as get_time_default, c as runAgent, i as get_weather_default, o as defineModel, r as loadMCPTools } from "./src-izgP3Lfk.mjs";
2
2
  import { compactStr, extractErrorMessage } from "@nickyzj2023/utils";
3
3
  import readline from "node:readline";
4
4
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
@@ -188,6 +188,12 @@ var TUI = class {
188
188
  this.preparePrint("done");
189
189
  process.stdout.write(this.colorize(`[本轮结束:${finishReason}] ${usage ? `输入${this.format(usage.prompt_tokens)}token,输出${this.format(usage.completion_tokens)}token,总共${this.format(usage.total_tokens)}token` : ""}${finishReason === "stop" ? "\n\n" : "\n"}`, "90"));
190
190
  }
191
+ /**
192
+ * 打印一行黄色状态提示(如“等待MCP工具加载完成…”)
193
+ */
194
+ printStatus(message) {
195
+ process.stdout.write(this.colorize(message, "93"));
196
+ }
191
197
  };
192
198
  //#endregion
193
199
  //#region src/cli.ts
@@ -199,18 +205,24 @@ const startChat = async () => {
199
205
  process.exit(1);
200
206
  }
201
207
  const model = defineModel(config);
208
+ let mcpReady = false;
209
+ const mcpLoading = loadMCPTools(config.mcpServers).then((tools) => {
210
+ mcpReady = true;
211
+ return tools;
212
+ });
202
213
  const messages = [];
203
- const mcpTools = await loadMCPTools(config.mcpServers);
204
- const tools = [
205
- get_weather_default,
206
- get_time_default,
207
- ...mcpTools
208
- ];
214
+ let tools = null;
209
215
  const tui = new TUI(async (input) => {
210
216
  messages.push({
211
217
  role: "user",
212
218
  content: input
213
219
  });
220
+ if (!mcpReady) tui.printStatus("等待MCP工具加载完成…");
221
+ tools ??= [
222
+ get_weather_default,
223
+ get_time_default,
224
+ ...await mcpLoading
225
+ ];
214
226
  for await (const e of runAgent(model, messages, tools)) switch (e.type) {
215
227
  case "reasoning_delta":
216
228
  tui.printReasoning(e.delta);
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as get_time_default, c as runAgent, i as get_weather_default, n as MCPRouter, o as defineModel, r as loadMCPTools, s as defineTool, t as compact } from "./src-DEDOOez9.mjs";
1
+ import { a as get_time_default, c as runAgent, i as get_weather_default, n as MCPRouter, o as defineModel, r as loadMCPTools, s as defineTool, t as compact } from "./src-izgP3Lfk.mjs";
2
2
  export { MCPRouter, compact, defineModel, defineTool, get_time_default as getTime, get_weather_default as getWeather, loadMCPTools, runAgent };
@@ -278,9 +278,8 @@ const loadMCPTools = async (mcpServers) => {
278
278
  await Promise.allSettled(Object.entries(mcpServers).map(async ([name, server]) => {
279
279
  try {
280
280
  await router?.addClient(name, server.url, omit(server, ["type", "url"]));
281
- logger(`已激活MCP客户端:${name}`);
282
281
  } catch (e) {
283
- logger(`MCP服务器${name}连接失败,跳过:${extractErrorMessage(e)}`);
282
+ logger(`MCP服务器${name}加载失败:${extractErrorMessage(e)}`);
284
283
  }
285
284
  }));
286
285
  return router.getTools();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nickyzj2023/ai",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "我的“pi”,参考了pi-from-scratch",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",