@saber2pr/ai-agent 0.0.56 → 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.
- package/lib/adapters/llm.d.ts +1 -3
- package/lib/adapters/llm.js +1 -6
- package/lib/index.d.ts +4 -4
- package/lib/index.js +4 -12
- package/lib/model/AgentGraphModel.d.ts +2 -0
- package/lib/model/AgentGraphModel.js +13 -2
- package/package.json +1 -1
package/lib/adapters/llm.d.ts
CHANGED
|
@@ -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)。
|
package/lib/adapters/llm.js
CHANGED
|
@@ -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
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './core/agent';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export * from './core/agent';
|
|
3
|
+
export * from './utils/createTool';
|
|
4
4
|
export * from './model/AgentGraphModel';
|
|
5
|
-
export
|
|
5
|
+
export * from './core/agent-graph';
|
|
6
6
|
export * from './types/type';
|
|
7
|
-
export
|
|
7
|
+
export * from './agent/createAgent';
|
package/lib/index.js
CHANGED
|
@@ -13,19 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.createAgent = exports.McpGraphAgent = exports.createTool = exports.default = void 0;
|
|
21
17
|
__exportStar(require("./core/agent"), exports);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var createTool_1 = require("./utils/createTool");
|
|
25
|
-
Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return createTool_1.createTool; } });
|
|
18
|
+
__exportStar(require("./core/agent"), exports);
|
|
19
|
+
__exportStar(require("./utils/createTool"), exports);
|
|
26
20
|
__exportStar(require("./model/AgentGraphModel"), exports);
|
|
27
|
-
|
|
28
|
-
Object.defineProperty(exports, "McpGraphAgent", { enumerable: true, get: function () { return __importDefault(agent_graph_1).default; } });
|
|
21
|
+
__exportStar(require("./core/agent-graph"), exports);
|
|
29
22
|
__exportStar(require("./types/type"), exports);
|
|
30
|
-
|
|
31
|
-
Object.defineProperty(exports, "createAgent", { enumerable: true, get: function () { return createAgent_1.createAgent; } });
|
|
23
|
+
__exportStar(require("./agent/createAgent"), exports);
|
|
@@ -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
|
-
|
|
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
|