@nickyzj2023/ai 1.3.2 → 1.4.0
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/dist/cli.mjs +12 -3
- package/package.json +3 -2
package/dist/cli.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import readline from "node:readline";
|
|
|
4
4
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
|
+
import { MarkdownRenderer } from "@wterm/markdown";
|
|
7
8
|
//#region src/utils/config.ts
|
|
8
9
|
/**
|
|
9
10
|
* 获取全局配置文件路径(Windows/macOS/Linux通用)
|
|
@@ -82,6 +83,8 @@ async function runSetup() {
|
|
|
82
83
|
var TUI = class {
|
|
83
84
|
rl = null;
|
|
84
85
|
onPrompt = null;
|
|
86
|
+
/** content专用的markdown渲染器 */
|
|
87
|
+
md = null;
|
|
85
88
|
/** 是否允许输入 */
|
|
86
89
|
isBusy = false;
|
|
87
90
|
/** 上次打印内容所属的状态(reasoning/content/tool)
|
|
@@ -123,12 +126,17 @@ var TUI = class {
|
|
|
123
126
|
});
|
|
124
127
|
}
|
|
125
128
|
/**
|
|
126
|
-
* 所有print
|
|
127
|
-
*
|
|
129
|
+
* 所有print方法调用前:
|
|
130
|
+
* 状态切换时打印换行,并记录当前状态
|
|
128
131
|
* @returns 是否发生了状态切换
|
|
129
132
|
*/
|
|
130
133
|
preparePrint(type) {
|
|
131
134
|
if (this.prevPrintType === type) return false;
|
|
135
|
+
if (type === "content_delta" && this.md === null) this.md = new MarkdownRenderer();
|
|
136
|
+
if (this.prevPrintType === "content_delta") {
|
|
137
|
+
const remaining = this.md?.flush();
|
|
138
|
+
if (remaining) process.stdout.write(remaining);
|
|
139
|
+
}
|
|
132
140
|
process.stdout.write("\n");
|
|
133
141
|
this.prevPrintType = type;
|
|
134
142
|
return true;
|
|
@@ -150,7 +158,8 @@ var TUI = class {
|
|
|
150
158
|
/** 流式打印AI回复内容 */
|
|
151
159
|
printContent(delta) {
|
|
152
160
|
this.preparePrint("content_delta");
|
|
153
|
-
|
|
161
|
+
const rendered = this.md?.push(delta);
|
|
162
|
+
if (rendered) process.stdout.write(rendered);
|
|
154
163
|
}
|
|
155
164
|
/** 打印工具调用 */
|
|
156
165
|
printToolCall(name, args) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nickyzj2023/ai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "我的“pi”,参考了pi-from-scratch",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
36
|
-
"@nickyzj2023/utils": "link:../utils"
|
|
36
|
+
"@nickyzj2023/utils": "link:../utils",
|
|
37
|
+
"@wterm/markdown": "^0.5.0"
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
40
|
"build": "tsdown",
|