@saber2pr/ai-agent 0.0.57 → 0.0.58

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.
@@ -1,11 +1,9 @@
1
- import { AgentGraphLLMResponse, AgentGraphModel, StreamChunkCallback } from '../model/AgentGraphModel';
2
1
  import { BaseMessage } from '@langchain/core/messages';
2
+ import { AgentGraphLLMResponse, AgentGraphModel, StreamChunkCallback } from '../model/AgentGraphModel';
3
3
  import { CreateAgentOptions } from '../types/type';
4
4
  export declare class LLMModel extends AgentGraphModel {
5
- private chatId;
6
5
  private options;
7
6
  constructor(options: CreateAgentOptions);
8
- resetChat(): void;
9
7
  callApi(prompt: string): Promise<AgentGraphLLMResponse>;
10
8
  /**
11
9
  * 流式调用 API:发送 stream: true,自动适配多种响应格式(SSE / NDJSON / 普通 JSON)。
@@ -3,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LLMModel = void 0;
4
4
  const AgentGraphModel_1 = require("../model/AgentGraphModel");
5
5
  class LLMModel extends AgentGraphModel_1.AgentGraphModel {
6
- chatId;
7
6
  options;
8
7
  constructor(options) {
9
8
  super();
10
- this.chatId = '';
11
9
  this.options = options;
12
10
  }
13
- resetChat() {
14
- this.chatId = '';
15
- }
16
11
  async callApi(prompt) {
17
12
  const response = await fetch(this.options.apiUrl, {
18
13
  method: 'POST',
@@ -172,7 +167,7 @@ class LLMModel extends AgentGraphModel_1.AgentGraphModel {
172
167
  text: fullText,
173
168
  reasoning,
174
169
  token,
175
- duration
170
+ duration,
176
171
  };
177
172
  }
178
173
  }
@@ -13,6 +13,8 @@ export declare abstract class AgentGraphModel extends BaseChatModel {
13
13
  protected boundTools?: any[];
14
14
  private mcpEnabled?;
15
15
  private mcpTools?;
16
+ protected chatId: string;
17
+ resetChat(): void;
16
18
  setMcpTools(tools: any[]): void;
17
19
  setMcpEnabled(enabled?: boolean): void;
18
20
  getMcpEnabled(): boolean;
@@ -10,6 +10,10 @@ class AgentGraphModel extends chat_models_1.BaseChatModel {
10
10
  boundTools;
11
11
  mcpEnabled = true;
12
12
  mcpTools = [];
13
+ chatId = '';
14
+ resetChat() {
15
+ this.chatId = '';
16
+ }
13
17
  setMcpTools(tools) {
14
18
  this.mcpTools = tools;
15
19
  }
@@ -28,6 +32,9 @@ class AgentGraphModel extends chat_models_1.BaseChatModel {
28
32
  }
29
33
  constructor(fields) {
30
34
  super(fields || {});
35
+ this.chatId = '';
36
+ this.mcpTools = [];
37
+ this.mcpEnabled = true;
31
38
  }
32
39
  bindTools(tools) {
33
40
  this.boundTools = tools.map(t => (0, function_calling_1.convertToOpenAITool)(t));
@@ -170,6 +177,7 @@ class AgentGraphModel extends chat_models_1.BaseChatModel {
170
177
  serializeMessages(messages) {
171
178
  const systemMsg = messages.find(m => m._getType() === 'system');
172
179
  const lastMsg = messages[messages.length - 1];
180
+ const isFirstMessage = this.chatId === '';
173
181
  const format = (m) => {
174
182
  const content = typeof m.content === 'string' ? m.content : JSON.stringify(m.content, null, 2);
175
183
  return `${m._getType().toUpperCase()}: ${content}`;
@@ -178,9 +186,12 @@ class AgentGraphModel extends chat_models_1.BaseChatModel {
178
186
  const toolsContext = tools.length
179
187
  ? `${(0, generateToolMarkdown_1.generateToolMarkdown)(tools)}`
180
188
  : '';
181
- return `
182
- ${format(systemMsg)}
189
+ const systemContext = isFirstMessage ? `
190
+ ${isFirstMessage ? format(systemMsg) : ''}
183
191
  ${toolsContext}
192
+ `.trim() : '';
193
+ return `
194
+ ${systemContext}
184
195
  # Current Progress
185
196
  ${format(lastMsg)}
186
197
  # Output Requirement
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saber2pr/ai-agent",
3
- "version": "0.0.57",
3
+ "version": "0.0.58",
4
4
  "description": "AI Assistant CLI.",
5
5
  "author": "saber2pr",
6
6
  "license": "ISC",