@adminforth/agent 1.27.5 → 1.28.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/build.log +2 -2
- package/custom/ChatSurface.vue +1 -1
- package/custom/composables/useAgentStore.ts +10 -0
- package/dist/custom/ChatSurface.vue +1 -1
- package/dist/custom/composables/useAgentStore.ts +10 -0
- package/dist/index.js +30 -1
- package/index.ts +46 -2
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -38,5 +38,5 @@ custom/skills/fetch_data/SKILL.md
|
|
|
38
38
|
custom/skills/mutate_data/
|
|
39
39
|
custom/skills/mutate_data/SKILL.md
|
|
40
40
|
|
|
41
|
-
sent
|
|
42
|
-
total size is 205,
|
|
41
|
+
sent 208,100 bytes received 562 bytes 417,324.00 bytes/sec
|
|
42
|
+
total size is 205,786 speedup is 0.99
|
package/custom/ChatSurface.vue
CHANGED
|
@@ -219,7 +219,7 @@ const isModeMenuOpen = ref(false);
|
|
|
219
219
|
let startX = 0
|
|
220
220
|
let startWidth = 0
|
|
221
221
|
|
|
222
|
-
onClickOutside(chatSurface, () => {if (!agentStore.isTeleportedToBody) agentStore.setIsChatOpen(false);});
|
|
222
|
+
onClickOutside(chatSurface, () => {if (!agentStore.isTeleportedToBody && !agentStore.isFullScreen) agentStore.setIsChatOpen(false);});
|
|
223
223
|
onClickOutside(modeMenu, () => { isModeMenuOpen.value = false; });
|
|
224
224
|
|
|
225
225
|
onMounted(async () => {
|
|
@@ -14,6 +14,15 @@ type AgentMode = {
|
|
|
14
14
|
name: string;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
function getCurrentPageContext() {
|
|
18
|
+
return {
|
|
19
|
+
path: window.location.pathname,
|
|
20
|
+
fullPath: `${window.location.pathname}${window.location.search}${window.location.hash}`,
|
|
21
|
+
title: document.title,
|
|
22
|
+
url: window.location.href,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
const DEFAULT_TEXTAREA_PLACEHOLDER = 'Type a message...';
|
|
18
27
|
const PLACEHOLDER_TYPING_DELAY_MS = 60;
|
|
19
28
|
const PLACEHOLDER_DELETING_DELAY_MS = 35;
|
|
@@ -206,6 +215,7 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
206
215
|
sessionId,
|
|
207
216
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
208
217
|
mode: activeModeName.value,
|
|
218
|
+
currentPage: getCurrentPageContext(),
|
|
209
219
|
};
|
|
210
220
|
|
|
211
221
|
return {
|
|
@@ -219,7 +219,7 @@ const isModeMenuOpen = ref(false);
|
|
|
219
219
|
let startX = 0
|
|
220
220
|
let startWidth = 0
|
|
221
221
|
|
|
222
|
-
onClickOutside(chatSurface, () => {if (!agentStore.isTeleportedToBody) agentStore.setIsChatOpen(false);});
|
|
222
|
+
onClickOutside(chatSurface, () => {if (!agentStore.isTeleportedToBody && !agentStore.isFullScreen) agentStore.setIsChatOpen(false);});
|
|
223
223
|
onClickOutside(modeMenu, () => { isModeMenuOpen.value = false; });
|
|
224
224
|
|
|
225
225
|
onMounted(async () => {
|
|
@@ -14,6 +14,15 @@ type AgentMode = {
|
|
|
14
14
|
name: string;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
function getCurrentPageContext() {
|
|
18
|
+
return {
|
|
19
|
+
path: window.location.pathname,
|
|
20
|
+
fullPath: `${window.location.pathname}${window.location.search}${window.location.hash}`,
|
|
21
|
+
title: document.title,
|
|
22
|
+
url: window.location.href,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
const DEFAULT_TEXTAREA_PLACEHOLDER = 'Type a message...';
|
|
18
27
|
const PLACEHOLDER_TYPING_DELAY_MS = 60;
|
|
19
28
|
const PLACEHOLDER_DELETING_DELAY_MS = 35;
|
|
@@ -206,6 +215,7 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
206
215
|
sessionId,
|
|
207
216
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
208
217
|
mode: activeModeName.value,
|
|
218
|
+
currentPage: getCurrentPageContext(),
|
|
209
219
|
};
|
|
210
220
|
|
|
211
221
|
return {
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,29 @@ function formatAgentError(error) {
|
|
|
46
46
|
}
|
|
47
47
|
return String(error);
|
|
48
48
|
}
|
|
49
|
+
function formatAdminUserPrompt(adminUser, usernameField) {
|
|
50
|
+
const dbUser = adminUser.dbUser;
|
|
51
|
+
const adminUserContext = {
|
|
52
|
+
id: adminUser.pk,
|
|
53
|
+
email: dbUser[usernameField],
|
|
54
|
+
};
|
|
55
|
+
return [
|
|
56
|
+
"Current admin user context:",
|
|
57
|
+
JSON.stringify(adminUserContext, null, 2),
|
|
58
|
+
"Use this admin user email when the user asks to send information to themselves, the current admin, or the logged-in user.",
|
|
59
|
+
].join("\n");
|
|
60
|
+
}
|
|
61
|
+
function formatCurrentPagePrompt(currentPage) {
|
|
62
|
+
console.log("Current page context:", currentPage);
|
|
63
|
+
if (!currentPage) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return [
|
|
67
|
+
"Current user page context for the latest message:",
|
|
68
|
+
JSON.stringify(currentPage, null, 2),
|
|
69
|
+
"When the user says here, this page, current page, or opened page, treat it as this page.",
|
|
70
|
+
].join("\n");
|
|
71
|
+
}
|
|
49
72
|
function assertRequiredApiTool(apiBasedTools, toolName) {
|
|
50
73
|
if (toolName in apiBasedTools) {
|
|
51
74
|
return;
|
|
@@ -210,6 +233,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
210
233
|
const messageId = randomUUID();
|
|
211
234
|
const prompt = body.message;
|
|
212
235
|
const userTimeZone = (_e = body.timeZone) !== null && _e !== void 0 ? _e : 'UTC';
|
|
236
|
+
const currentPage = body.currentPage;
|
|
213
237
|
const sessionId = body.sessionId || (adminUser === null || adminUser === void 0 ? void 0 : adminUser.pk) || (adminUser === null || adminUser === void 0 ? void 0 : adminUser.username) || 'default';
|
|
214
238
|
const turnId = yield this.createNewTurn(sessionId, prompt);
|
|
215
239
|
yield this.updateSessionDate(sessionId);
|
|
@@ -282,13 +306,17 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
282
306
|
const maxTokens = (_f = this.options.maxTokens) !== null && _f !== void 0 ? _f : 10000;
|
|
283
307
|
const selectedMode = (_g = this.options.modes.find((mode) => mode.name === body.mode)) !== null && _g !== void 0 ? _g : this.options.modes[0];
|
|
284
308
|
const { model, summaryModel, modelMiddleware } = yield this.getModeModels(selectedMode, maxTokens);
|
|
285
|
-
const systemPrompt =
|
|
309
|
+
const systemPrompt = [
|
|
310
|
+
yield this.agentSystemPromptPromise,
|
|
311
|
+
formatAdminUserPrompt(adminUser, this.adminforth.config.auth.usernameField),
|
|
312
|
+
].join("\n\n");
|
|
286
313
|
const apiBasedTools = buildApiBasedTools(this.adminforth);
|
|
287
314
|
for (const toolName of ALWAYS_AVAILABLE_API_TOOL_NAMES) {
|
|
288
315
|
assertRequiredApiTool(apiBasedTools, toolName);
|
|
289
316
|
}
|
|
290
317
|
assertRequiredApiTool(apiBasedTools, "update_record");
|
|
291
318
|
this.apiBasedTools = apiBasedTools;
|
|
319
|
+
const currentPagePrompt = formatCurrentPagePrompt(currentPage);
|
|
292
320
|
const stream = yield callAgent({
|
|
293
321
|
name: `adminforth-agent-${this.pluginInstanceId}`,
|
|
294
322
|
model,
|
|
@@ -297,6 +325,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
297
325
|
checkpointer: this.getCheckpointer(),
|
|
298
326
|
messages: [
|
|
299
327
|
new SystemMessage(systemPrompt),
|
|
328
|
+
...(currentPagePrompt ? [new SystemMessage(currentPagePrompt)] : []),
|
|
300
329
|
new HumanMessage(prompt),
|
|
301
330
|
],
|
|
302
331
|
adminUser,
|
package/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
AdminUser,
|
|
2
3
|
AdminForthResource,
|
|
3
4
|
IAdminForth,
|
|
4
5
|
IHttpServer
|
|
@@ -14,7 +15,6 @@ import {
|
|
|
14
15
|
createAgentChatModel,
|
|
15
16
|
callAgent,
|
|
16
17
|
type AgentChatModel,
|
|
17
|
-
type AgentModeCompletionAdapter,
|
|
18
18
|
} from "./agent/simpleAgent.js";
|
|
19
19
|
import { AdminForthCheckpointSaver } from "./agent/checkpointer.js";
|
|
20
20
|
import { createSequenceDebugCollector } from "./agent/middleware/sequenceDebug.js";
|
|
@@ -30,6 +30,17 @@ import {
|
|
|
30
30
|
import { ALWAYS_AVAILABLE_API_TOOL_NAMES } from "./agent/tools/index.js";
|
|
31
31
|
import type { ToolCallEvent } from "./agent/toolCallEvents.js";
|
|
32
32
|
|
|
33
|
+
type CurrentPageRequestBody = {
|
|
34
|
+
currentPage?: CurrentPageContext;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type CurrentPageContext = {
|
|
38
|
+
path: string;
|
|
39
|
+
fullPath: string;
|
|
40
|
+
title: string;
|
|
41
|
+
url: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
33
44
|
function isAggregateErrorLike(
|
|
34
45
|
error: unknown,
|
|
35
46
|
): error is { errors: unknown[]; message?: string; stack?: string } {
|
|
@@ -58,6 +69,33 @@ function formatAgentError(error: unknown) {
|
|
|
58
69
|
return String(error);
|
|
59
70
|
}
|
|
60
71
|
|
|
72
|
+
function formatAdminUserPrompt(adminUser: AdminUser, usernameField: string) {
|
|
73
|
+
const dbUser = adminUser.dbUser as Record<string, unknown>;
|
|
74
|
+
const adminUserContext = {
|
|
75
|
+
id: adminUser.pk,
|
|
76
|
+
email: dbUser[usernameField],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return [
|
|
80
|
+
"Current admin user context:",
|
|
81
|
+
JSON.stringify(adminUserContext, null, 2),
|
|
82
|
+
"Use this admin user email when the user asks to send information to themselves, the current admin, or the logged-in user.",
|
|
83
|
+
].join("\n");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function formatCurrentPagePrompt(currentPage: CurrentPageContext | undefined) {
|
|
87
|
+
console.log("Current page context:", currentPage);
|
|
88
|
+
if (!currentPage) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return [
|
|
93
|
+
"Current user page context for the latest message:",
|
|
94
|
+
JSON.stringify(currentPage, null, 2),
|
|
95
|
+
"When the user says here, this page, current page, or opened page, treat it as this page.",
|
|
96
|
+
].join("\n");
|
|
97
|
+
}
|
|
98
|
+
|
|
61
99
|
function assertRequiredApiTool(
|
|
62
100
|
apiBasedTools: Record<string, ApiBasedTool>,
|
|
63
101
|
toolName: string,
|
|
@@ -248,6 +286,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
248
286
|
const messageId = randomUUID();
|
|
249
287
|
const prompt = body.message;
|
|
250
288
|
const userTimeZone = (body.timeZone as string | undefined) ?? 'UTC';
|
|
289
|
+
const currentPage = (body as CurrentPageRequestBody).currentPage;
|
|
251
290
|
const sessionId = body.sessionId || adminUser?.pk || adminUser?.username || 'default';
|
|
252
291
|
const turnId = await this.createNewTurn(sessionId, prompt);
|
|
253
292
|
await this.updateSessionDate(sessionId);
|
|
@@ -340,13 +379,17 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
340
379
|
const selectedMode = this.options.modes.find((mode) => mode.name === body.mode) ?? this.options.modes[0];
|
|
341
380
|
const { model, summaryModel, modelMiddleware } =
|
|
342
381
|
await this.getModeModels(selectedMode, maxTokens);
|
|
343
|
-
const systemPrompt =
|
|
382
|
+
const systemPrompt = [
|
|
383
|
+
await this.agentSystemPromptPromise,
|
|
384
|
+
formatAdminUserPrompt(adminUser, this.adminforth.config.auth.usernameField),
|
|
385
|
+
].join("\n\n");
|
|
344
386
|
const apiBasedTools = buildApiBasedTools(this.adminforth);
|
|
345
387
|
for (const toolName of ALWAYS_AVAILABLE_API_TOOL_NAMES) {
|
|
346
388
|
assertRequiredApiTool(apiBasedTools, toolName);
|
|
347
389
|
}
|
|
348
390
|
assertRequiredApiTool(apiBasedTools, "update_record");
|
|
349
391
|
this.apiBasedTools = apiBasedTools;
|
|
392
|
+
const currentPagePrompt = formatCurrentPagePrompt(currentPage);
|
|
350
393
|
const stream = await callAgent({
|
|
351
394
|
name: `adminforth-agent-${this.pluginInstanceId}`,
|
|
352
395
|
model,
|
|
@@ -355,6 +398,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
355
398
|
checkpointer: this.getCheckpointer(),
|
|
356
399
|
messages: [
|
|
357
400
|
new SystemMessage(systemPrompt),
|
|
401
|
+
...(currentPagePrompt ? [new SystemMessage(currentPagePrompt)] : []),
|
|
358
402
|
new HumanMessage(prompt),
|
|
359
403
|
],
|
|
360
404
|
adminUser,
|