@adminforth/agent 1.23.0 → 1.24.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 +31 -0
- package/agent/middleware/apiBasedTools.ts +27 -4
- package/agent/middleware/sequenceDebug.ts +39 -2
- package/agent/simpleAgent.ts +283 -52
- package/agent/toolCallEvents.ts +3 -0
- package/apiBasedTools.ts +98 -8
- package/build.log +2 -2
- package/custom/composables/useAgentStore.ts +3 -0
- package/custom/package.json +1 -1
- package/dist/agent/middleware/apiBasedTools.js +22 -3
- package/dist/agent/middleware/sequenceDebug.js +18 -2
- package/dist/agent/simpleAgent.js +167 -27
- package/dist/agent/toolCallEvents.js +1 -0
- package/dist/apiBasedTools.js +73 -6
- package/dist/custom/composables/useAgentStore.ts +3 -0
- package/dist/custom/package.json +1 -1
- package/dist/index.js +32 -18
- package/index.ts +33 -15
- package/package.json +16 -5
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { AdminForthPlugin, logger, Filters, Sorts } from "adminforth";
|
|
|
18
18
|
import { randomUUID } from 'crypto';
|
|
19
19
|
import { HumanMessage, SystemMessage } from "langchain";
|
|
20
20
|
import { MemorySaver } from "@langchain/langgraph";
|
|
21
|
-
import { createAgentChatModel, callAgent } from "./agent/simpleAgent.js";
|
|
21
|
+
import { createAgentChatModel, callAgent, } from "./agent/simpleAgent.js";
|
|
22
22
|
import { AdminForthCheckpointSaver } from "./agent/checkpointer.js";
|
|
23
23
|
import { createSequenceDebugCollector } from "./agent/middleware/sequenceDebug.js";
|
|
24
24
|
import { prepareApiBasedTools as buildApiBasedTools, } from './apiBasedTools.js';
|
|
@@ -91,22 +91,34 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
getModeModels(mode, maxTokens) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const cachedModels = this.modelsByModeName.get(mode.name);
|
|
96
|
+
if (cachedModels) {
|
|
97
|
+
return yield cachedModels;
|
|
98
|
+
}
|
|
99
|
+
const modelsPromise = Promise.all([
|
|
100
|
+
createAgentChatModel({
|
|
101
|
+
adapter: mode.completionAdapter,
|
|
102
|
+
maxTokens,
|
|
103
|
+
}),
|
|
104
|
+
createAgentChatModel({
|
|
105
|
+
adapter: mode.completionAdapter,
|
|
106
|
+
maxTokens,
|
|
107
|
+
}),
|
|
108
|
+
]).then(([primaryModel, summaryModel]) => ({
|
|
109
|
+
model: primaryModel.model,
|
|
110
|
+
summaryModel: summaryModel.model,
|
|
111
|
+
modelProvider: primaryModel.provider,
|
|
112
|
+
}));
|
|
113
|
+
this.modelsByModeName.set(mode.name, modelsPromise);
|
|
114
|
+
try {
|
|
115
|
+
return yield modelsPromise;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
this.modelsByModeName.delete(mode.name);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
110
122
|
}
|
|
111
123
|
getCheckpointer() {
|
|
112
124
|
if (this.checkpointer) {
|
|
@@ -272,18 +284,20 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
272
284
|
});
|
|
273
285
|
const maxTokens = (_f = this.options.maxTokens) !== null && _f !== void 0 ? _f : 10000;
|
|
274
286
|
const selectedMode = (_g = this.options.modes.find((mode) => mode.name === body.mode)) !== null && _g !== void 0 ? _g : this.options.modes[0];
|
|
275
|
-
const { model, summaryModel } = this.getModeModels(selectedMode, maxTokens);
|
|
287
|
+
const { model, summaryModel, modelProvider } = yield this.getModeModels(selectedMode, maxTokens);
|
|
276
288
|
const systemPrompt = yield this.agentSystemPromptPromise;
|
|
277
289
|
const stream = yield callAgent({
|
|
278
290
|
name: `adminforth-agent-${this.pluginInstanceId}`,
|
|
279
291
|
model,
|
|
280
292
|
summaryModel,
|
|
293
|
+
modelProvider,
|
|
281
294
|
checkpointer: this.getCheckpointer(),
|
|
282
295
|
messages: [
|
|
283
296
|
new SystemMessage(systemPrompt),
|
|
284
297
|
new HumanMessage(prompt),
|
|
285
298
|
],
|
|
286
299
|
adminUser,
|
|
300
|
+
adminforth: this.adminforth,
|
|
287
301
|
apiBasedTools: this.apiBasedTools,
|
|
288
302
|
customComponentsDir: this.adminforth.config.customization.customComponentsDir,
|
|
289
303
|
sessionId,
|
package/index.ts
CHANGED
|
@@ -10,7 +10,12 @@ import type { PluginOptions } from './types.js';
|
|
|
10
10
|
import { randomUUID } from 'crypto';
|
|
11
11
|
import { HumanMessage, SystemMessage } from "langchain";
|
|
12
12
|
import { MemorySaver, type BaseCheckpointSaver } from "@langchain/langgraph";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
createAgentChatModel,
|
|
15
|
+
callAgent,
|
|
16
|
+
type AgentChatModel,
|
|
17
|
+
type AgentModelProvider,
|
|
18
|
+
} from "./agent/simpleAgent.js";
|
|
14
19
|
import { AdminForthCheckpointSaver } from "./agent/checkpointer.js";
|
|
15
20
|
import { createSequenceDebugCollector } from "./agent/middleware/sequenceDebug.js";
|
|
16
21
|
import {
|
|
@@ -24,7 +29,6 @@ import {
|
|
|
24
29
|
} from "./agent/systemPrompt.js";
|
|
25
30
|
import { ALWAYS_AVAILABLE_API_TOOL_NAMES } from "./agent/tools/index.js";
|
|
26
31
|
import type { ToolCallEvent } from "./agent/toolCallEvents.js";
|
|
27
|
-
import type { ChatOpenAI } from "@langchain/openai";
|
|
28
32
|
|
|
29
33
|
function isAggregateErrorLike(
|
|
30
34
|
error: unknown,
|
|
@@ -75,10 +79,11 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
75
79
|
private checkpointer: BaseCheckpointSaver | null = null;
|
|
76
80
|
private readonly modelsByModeName = new Map<
|
|
77
81
|
string,
|
|
78
|
-
{
|
|
79
|
-
model:
|
|
80
|
-
summaryModel:
|
|
81
|
-
|
|
82
|
+
Promise<{
|
|
83
|
+
model: AgentChatModel;
|
|
84
|
+
summaryModel: AgentChatModel;
|
|
85
|
+
modelProvider: AgentModelProvider;
|
|
86
|
+
}>
|
|
82
87
|
>();
|
|
83
88
|
|
|
84
89
|
private async createNewTurn(sessionId: string, prompt: string, response?: string) {
|
|
@@ -118,29 +123,39 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
118
123
|
}));
|
|
119
124
|
}
|
|
120
125
|
|
|
121
|
-
private getModeModels(
|
|
126
|
+
private async getModeModels(
|
|
122
127
|
mode: PluginOptions["modes"][number],
|
|
123
128
|
maxTokens: number,
|
|
124
129
|
) {
|
|
125
130
|
const cachedModels = this.modelsByModeName.get(mode.name);
|
|
126
131
|
|
|
127
132
|
if (cachedModels) {
|
|
128
|
-
return cachedModels;
|
|
133
|
+
return await cachedModels;
|
|
129
134
|
}
|
|
130
135
|
|
|
131
|
-
const
|
|
132
|
-
|
|
136
|
+
const modelsPromise = Promise.all([
|
|
137
|
+
createAgentChatModel({
|
|
133
138
|
adapter: mode.completionAdapter,
|
|
134
139
|
maxTokens,
|
|
135
140
|
}),
|
|
136
|
-
|
|
141
|
+
createAgentChatModel({
|
|
137
142
|
adapter: mode.completionAdapter,
|
|
138
143
|
maxTokens,
|
|
139
144
|
}),
|
|
140
|
-
|
|
145
|
+
]).then(([primaryModel, summaryModel]) => ({
|
|
146
|
+
model: primaryModel.model,
|
|
147
|
+
summaryModel: summaryModel.model,
|
|
148
|
+
modelProvider: primaryModel.provider,
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
this.modelsByModeName.set(mode.name, modelsPromise);
|
|
141
152
|
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
try {
|
|
154
|
+
return await modelsPromise;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this.modelsByModeName.delete(mode.name);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
144
159
|
}
|
|
145
160
|
|
|
146
161
|
private getCheckpointer() {
|
|
@@ -326,18 +341,21 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
326
341
|
|
|
327
342
|
const maxTokens = this.options.maxTokens ?? 10000;
|
|
328
343
|
const selectedMode = this.options.modes.find((mode) => mode.name === body.mode) ?? this.options.modes[0];
|
|
329
|
-
const { model, summaryModel } =
|
|
344
|
+
const { model, summaryModel, modelProvider } =
|
|
345
|
+
await this.getModeModels(selectedMode, maxTokens);
|
|
330
346
|
const systemPrompt = await this.agentSystemPromptPromise;
|
|
331
347
|
const stream = await callAgent({
|
|
332
348
|
name: `adminforth-agent-${this.pluginInstanceId}`,
|
|
333
349
|
model,
|
|
334
350
|
summaryModel,
|
|
351
|
+
modelProvider,
|
|
335
352
|
checkpointer: this.getCheckpointer(),
|
|
336
353
|
messages: [
|
|
337
354
|
new SystemMessage(systemPrompt),
|
|
338
355
|
new HumanMessage(prompt),
|
|
339
356
|
],
|
|
340
357
|
adminUser,
|
|
358
|
+
adminforth: this.adminforth,
|
|
341
359
|
apiBasedTools: this.apiBasedTools,
|
|
342
360
|
customComponentsDir: this.adminforth.config.customization.customComponentsDir,
|
|
343
361
|
sessionId,
|
package/package.json
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/agent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"homepage": "https://adminforth.dev/docs/tutorial/Plugins/agent/",
|
|
7
8
|
"publishConfig": {
|
|
8
9
|
"access": "public"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
12
|
"build": "tsc && rsync -av --exclude 'node_modules' custom dist/"
|
|
12
13
|
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
|
|
14
|
+
"keywords": [
|
|
15
|
+
"adminforth",
|
|
16
|
+
"ai-agent",
|
|
17
|
+
"tool-calling",
|
|
18
|
+
"chat-ui",
|
|
19
|
+
"langgraph",
|
|
20
|
+
"llm",
|
|
21
|
+
"session-memory"
|
|
22
|
+
],
|
|
23
|
+
"author": "DevForth (https://devforth.io)",
|
|
15
24
|
"license": "ISC",
|
|
16
|
-
"description": "",
|
|
25
|
+
"description": "AI agent plugin for AdminForth with tool-based workflows and persistent chat sessions",
|
|
17
26
|
"devDependencies": {
|
|
18
27
|
"@types/node": "latest",
|
|
19
28
|
"semantic-release": "^24.2.1",
|
|
@@ -21,11 +30,13 @@
|
|
|
21
30
|
"typescript": "^5.7.3"
|
|
22
31
|
},
|
|
23
32
|
"dependencies": {
|
|
33
|
+
"@langchain/anthropic": "1.3.26",
|
|
24
34
|
"@langchain/core": "^1.1.40",
|
|
35
|
+
"@langchain/google-genai": "2.1.27",
|
|
25
36
|
"@langchain/langgraph": "^1.2.8",
|
|
26
37
|
"@langchain/langgraph-checkpoint": "^1.0.1",
|
|
27
38
|
"@langchain/openai": "^1.4.4",
|
|
28
|
-
"adminforth": "2.
|
|
39
|
+
"adminforth": "2.42.0",
|
|
29
40
|
"dayjs": "^1.11.20",
|
|
30
41
|
"langchain": "^1.3.3",
|
|
31
42
|
"yaml": "^2.8.3",
|