zhitalk 0.0.8 → 0.0.9
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/agent/agent.js +8 -0
- package/dist/agent/cli.js +3 -1
- package/dist/agent/model.js +8 -4
- package/package.json +1 -1
package/dist/agent/agent.js
CHANGED
|
@@ -113,6 +113,14 @@ function createAgentGraph(toolList) {
|
|
|
113
113
|
modelMessages = modelMessages.slice(0, 300);
|
|
114
114
|
// 修复因中断/截断导致的未完成 tool_calls
|
|
115
115
|
modelMessages = ensureCompleteToolCalls(modelMessages);
|
|
116
|
+
// 清理异常消息:某些 API(如 GLM)可能在流式响应中产生 role 为 undefined 的 ChatMessage
|
|
117
|
+
modelMessages = modelMessages.filter((msg) => {
|
|
118
|
+
const msgType = msg._getType?.();
|
|
119
|
+
if (msgType === 'generic' && msg.role === undefined) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
});
|
|
116
124
|
const messages = [new SystemMessage(systemPrompt), ...modelMessages];
|
|
117
125
|
const response = await modelWithTheseTools.invoke(messages, config);
|
|
118
126
|
return { messages: [response] };
|
package/dist/agent/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import { getModelContextLimit } from './context.js';
|
|
|
7
7
|
import { color, formatToolLog } from './colors.js';
|
|
8
8
|
import { threadId, commands } from './commands.js';
|
|
9
9
|
import { runSessionStartHooks } from './hooks.js';
|
|
10
|
+
import { getModelConfig } from './config.js';
|
|
10
11
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
12
|
const pkg = JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf-8'));
|
|
12
13
|
function createInterface() {
|
|
@@ -22,6 +23,7 @@ async function printBanner() {
|
|
|
22
23
|
const info = [
|
|
23
24
|
`${color.gray('Description')}: ${pkg.description}`,
|
|
24
25
|
`${color.gray('Version')}: ${pkg.version}`,
|
|
26
|
+
`${color.gray('Model')}: ${getModelConfig().model}`,
|
|
25
27
|
`${color.gray('Author')}: ${pkg.author}`,
|
|
26
28
|
`${color.gray('Docs')}: ${pkg.docs}`,
|
|
27
29
|
].join('\n');
|
|
@@ -90,7 +92,7 @@ async function chat(userInput) {
|
|
|
90
92
|
const limit = getModelContextLimit();
|
|
91
93
|
const percentage = (usageMetadata.total_tokens / limit) * 100;
|
|
92
94
|
const percentageStr = percentage.toFixed(1);
|
|
93
|
-
const tokenText =
|
|
95
|
+
const tokenText = `${getModelConfig().model}, Tokens: ${usageMetadata.total_tokens.toLocaleString()} / ${limit.toLocaleString()} (${percentageStr}%)`;
|
|
94
96
|
if (percentage >= 80) {
|
|
95
97
|
process.stdout.write('\n' +
|
|
96
98
|
color.error(tokenText) +
|
package/dist/agent/model.js
CHANGED
|
@@ -2,16 +2,20 @@ import { ChatOpenAI } from '@langchain/openai';
|
|
|
2
2
|
import { getModelConfig } from './config.js';
|
|
3
3
|
const modelConfig = getModelConfig();
|
|
4
4
|
export function createModel(options) {
|
|
5
|
+
const modelKwargs = {};
|
|
6
|
+
if (modelConfig.model.startsWith('kimi')) {
|
|
7
|
+
modelKwargs.thinking = { type: 'disabled' };
|
|
8
|
+
}
|
|
9
|
+
// GLM 模型的流式 function calling 存在兼容性问题,禁用流式输出
|
|
10
|
+
const isGlm = modelConfig.model.toLowerCase().startsWith('glm');
|
|
5
11
|
return new ChatOpenAI({
|
|
6
12
|
model: modelConfig.model,
|
|
7
13
|
apiKey: modelConfig.apiKey,
|
|
8
14
|
configuration: {
|
|
9
15
|
baseURL: modelConfig.baseURL,
|
|
10
16
|
},
|
|
11
|
-
streaming: options?.streaming ?? true,
|
|
12
|
-
modelKwargs
|
|
13
|
-
thinking: { type: 'disabled' },
|
|
14
|
-
},
|
|
17
|
+
streaming: isGlm ? false : (options?.streaming ?? true),
|
|
18
|
+
modelKwargs,
|
|
15
19
|
});
|
|
16
20
|
}
|
|
17
21
|
export async function checkModel() {
|
package/package.json
CHANGED